<commit_before>package brooklyn.test

import brooklyn.entity.Entity;
import brooklyn.entity.basic.Attributes;
import javax.management.MBeanNotificationInfo
import javax.management.MBeanServer
import javax.management.MBeanServerFactory
import javax.management.MBeanServerInvocationHandler
import javax.management.Notification
import javax.management.NotificationBroadcasterSupport
import javax.management.NotificationEmitter
import javax.management.ObjectName
import javax.management.StandardEmitterMBean
import javax.management.remote.JMXConnectorServer
import javax.management.remote.JMXConnectorServerFactory
import javax.management.remote.JMXServiceURL

import mx4j.tools.naming.NamingService
import mx4j.tools.naming.NamingServiceMBean

import org.slf4j.Logger
import org.slf4j.LoggerFactory

import com.google.common.base.Preconditions;

import brooklyn.event.adapter.JmxHelper

/**
 * Set up a JMX service ready for clients to connect. This consists of an MBean server, a connector server and a naming
 * service.
 */
class JmxService {
    private static final Logger logger = LoggerFactory.getLogger(JmxService.class)

    private MBeanServer server
    private NamingServiceMBean namingServiceMBean
    private JMXConnectorServer connectorServer
    private String jmxHost;
    private int jmxPort;
    private String url;
    
    public JmxService() {
        this("localhost", 28000 + Math.floor(new Random().nextDouble() * 1000));
        logger.warn("use of deprecated default host and port in JmxService");
    }
    public JmxService(Entity e) {
        this(e.getAttribute(Attributes.HOSTNAME)?:"localhost", e.getAttribute(Attributes.JMX_PORT)?:null);
    }
    public JmxService(String jmxHost, Integer jmxPort) {
        this.jmxHost = jmxHost;
        Preconditions.checkNotNull(jmxPort, "JMX_PORT must be set when starting JmxService"); 
        this.jmxPort = jmxPort;
        url = JmxHelper.toConnectorUrl(jmxHost, jmxPort, null, "jmxrmi")

        JMXServiceURL address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + jmxPort + "/jmxrmi");
        connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(address, null, null)<commit_msg>Use jmxHost given to JmxService<commit_after>package brooklyn.test

import brooklyn.entity.Entity;
import brooklyn.entity.basic.Attributes;
import javax.management.MBeanNotificationInfo
import javax.management.MBeanServer
import javax.management.MBeanServerFactory
import javax.management.MBeanServerInvocationHandler
import javax.management.Notification
import javax.management.NotificationBroadcasterSupport
import javax.management.NotificationEmitter
import javax.management.ObjectName
import javax.management.StandardEmitterMBean
import javax.management.remote.JMXConnectorServer
import javax.management.remote.JMXConnectorServerFactory
import javax.management.remote.JMXServiceURL

import mx4j.tools.naming.NamingService
import mx4j.tools.naming.NamingServiceMBean

import org.slf4j.Logger
import org.slf4j.LoggerFactory

import com.google.common.base.Preconditions;

import brooklyn.event.adapter.JmxHelper

/**
 * Set up a JMX service ready for clients to connect. This consists of an MBean server, a connector server and a naming
 * service.
 */
class JmxService {
    private static final Logger logger = LoggerFactory.getLogger(JmxService.class)

    private MBeanServer server
    private NamingServiceMBean namingServiceMBean
    private JMXConnectorServer connectorServer
    private String jmxHost;
    private int jmxPort;
    private String url;
    
    public JmxService() {
        this("localhost", 28000 + Math.floor(new Random().nextDouble() * 1000));
        logger.warn("use of deprecated default host and port in JmxService");
    }
    public JmxService(Entity e) {
        this(e.getAttribute(Attributes.HOSTNAME)?:"localhost", e.getAttribute(Attributes.JMX_PORT)?:null);
    }
    public JmxService(String jmxHost, Integer jmxPort) {
        this.jmxHost = jmxHost;
        Preconditions.checkNotNull(jmxPort, "JMX_PORT must be set when starting JmxService"); 
        this.jmxPort = jmxPort;
        url = JmxHelper.toConnectorUrl(jmxHost, jmxPort, null, "jmxrmi")

        JMXServiceURL address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + jmxHost + ":" + jmxPort + "/jmxrmi");
        connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(address, null, null)
{'fraction_non_alphanumeric': 0.08136363636363636, 'fraction_numerical': 0.005909090909090909, 'mean_word_length': 4.798418972332016, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1364403', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1259, 'n_words': 292}