public void init()

in services/minho-jmx/src/main/java/org/apache/karaf/minho/jmx/ConnectorServerFactory.java [64:137]


    public void init() throws Exception {
        JMXServiceURL url = new JMXServiceURL(this.serviceUrl);

        if (registry == null && locate) {
            try {
                Registry reg = LocateRegistry.getRegistry(host, port);
                reg.list();
                registry = reg;
            } catch (Exception e) {
                // ignore
            }
        }
        if (registry == null && create) {
            registry = new JmxRegistry(port, getBindingName(url));
            locallyCreated = true;
        }

        // TODO integrate the registry in the ServiceRegistry ?

        if (this.server == null) {
            throw new IllegalArgumentException("server must be set");
        }

        // TODO add SSL and secure

        setupRMIServerSocketFactory();

        rmiServer = new RMIJRMPServerImpl(url.getPort(),
                (RMIClientSocketFactory)environment.get(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE),
                (RMIServerSocketFactory)environment.get(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE), environment);

        // create the connector server now
        this.rmiConnectorServer = new RMIConnectorServer(url, environment, rmiServer, server);

        if (this.objectName != null) {
            this.server.registerMBean(this.rmiConnectorServer, this.objectName);
        }

        try {
            if (this.threaded) {
                Thread connectorThread = new Thread(() -> {
                    try {
                        Thread.currentThread().setContextClassLoader(ConnectorServerFactory.class.getClassLoader());
                        rmiConnectorServer.start();
                        remoteServerStub = rmiServer.toStub();
                    } catch (IOException ioe) {
                        if (ioe.getCause() instanceof BindException) {
                            // we want just the port message
                            int endIndex = ioe.getMessage().indexOf("nested exception is");
                            // check to make sure we do not get an index out of range
                            if (endIndex > ioe.getMessage().length() || endIndex < 0) {
                                endIndex = ioe.getMessage().length();
                            }
                            throw new RuntimeException("\n" + ioe.getMessage().substring(0, endIndex) +
                                    "\nYou may have started two containers. If you need to start a second container or the default ports are already in use " +
                                    "update the properties in the config service");
                        }
                        throw new RuntimeException("Could not start JMX connector server", ioe);
                    }
                });
                connectorThread.setName("JMX Connector Thread [" + this.serviceUrl + "]");
                connectorThread.setDaemon(this.daemon);
                connectorThread.start();
            } else {
                this.rmiConnectorServer.start();
                remoteServerStub = rmiServer.toStub();
            }
        } catch (Exception e) {
            if (this.objectName != null) {
                doUnregister(this.objectName);
            }
            throw e;
        }
    }