Example usage for java.rmi.registry LocateRegistry createRegistry

List of usage examples for java.rmi.registry LocateRegistry createRegistry

Introduction

In this page you can find the example usage for java.rmi.registry LocateRegistry createRegistry.

Prototype

public static Registry createRegistry(int port) throws RemoteException 

Source Link

Document

Creates and exports a Registry instance on the local host that accepts requests on the specified port.

Usage

From source file:org.apache.juddi.v3.tck.JUDDI_091_RMISubscriptionListenerIntegrationTest.java

@BeforeClass
public static void startManager() throws ConfigurationException {

    Assume.assumeTrue(TckPublisher.isEnabled());
    try {/*w ww.j av  a2 s.c  o  m*/
        //bring up the RMISubscriptionListener
        //random port
        randomPort = 19800 + new Random().nextInt(99);
        System.out.println("RMI Random port=" + randomPort);
        //bring up the RMISubscriptionListener
        URI rmiEndPoint = new URI("rmi://localhost:" + randomPort + "/tck/rmisubscriptionlistener");
        registry = LocateRegistry.createRegistry(rmiEndPoint.getPort());
        String path = rmiEndPoint.getPath();
        hostname = InetAddress.getLocalHost().getHostName();
        //starting the service
        rmiSubscriptionListenerService = new UDDISubscriptionListenerImpl(0);
        //binding to the RMI Registry
        registry.bind(path, rmiSubscriptionListenerService);

        //double check that the service is bound in the local Registry
        Registry registry2 = LocateRegistry.getRegistry(rmiEndPoint.getHost(), rmiEndPoint.getPort());
        registry2.lookup(rmiEndPoint.getPath());

    } catch (Exception e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
        Assert.fail();
    }

    manager = new UDDIClient();
    manager.start();

    logger.debug("Getting auth tokens..");
    try {

        Transport transport = manager.getTransport("uddiv3");
        UDDISecurityPortType security = transport.getUDDISecurityService();
        authInfoJoe = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(),
                TckPublisher.getJoePassword());

        UDDISubscriptionPortType subscription = transport.getUDDISubscriptionService();
        UDDIPublicationPortType publication = transport.getUDDIPublishService();
        UDDIInquiryPortType inquiry = transport.getUDDIInquiryService();

        tckTModel = new TckTModel(publication, inquiry);
        tckBusiness = new TckBusiness(publication, inquiry);
        tckBusinessService = new TckBusinessService(publication, inquiry);
        rmiSubscriptionListener = new TckSubscriptionListenerRMI(subscription, publication);

        if (!TckPublisher.isUDDIAuthMode()) {
            TckSecurity.setCredentials((BindingProvider) publication, TckPublisher.getRootPublisherId(),
                    TckPublisher.getRootPassword());
            TckSecurity.setCredentials((BindingProvider) subscription, TckPublisher.getRootPublisherId(),
                    TckPublisher.getRootPassword());
            TckSecurity.setCredentials((BindingProvider) inquiry, TckPublisher.getRootPublisherId(),
                    TckPublisher.getRootPassword());
        }

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail("Could not obtain authInfo token.");
    }
}

From source file:org.brixcms.rmiserver.workspacemanager.WorkspaceManagerExporterBean.java

public void afterPropertiesSet() throws Exception {
    try {//from  w w  w.ja  v a2s . co m
        registry = LocateRegistry.getRegistry(registryPort);
        registry.list();
    } catch (Exception e) {
        registry = LocateRegistry.createRegistry(registryPort);
        registry.list();
    }

    logger.info("Exporting Workspace Manager under: {}/{}", serviceName, registry);
    server = new ServerWorkspaceManager(workspaceManager);
    RemoteStub stub = UnicastRemoteObject.exportObject(server);
    registry.rebind(serviceName, stub);
    logger.info("Exported Workspace Manager: {}", stub);
}

From source file:com.xpn.xwiki.plugin.lucene.IndexSearchServer.java

public void run() {
    try {/*from  ww w . j  a v  a  2s .  c o  m*/
        this.searchables = createSearchers(this.indexDirs);

        LocateRegistry.createRegistry(Integer.parseInt(this.port));

        this.multiSearcher = new MultiSearcher(this.searchables);

        this.multiImpl = new RemoteSearchable(this.multiSearcher);

        Naming.rebind("//" + this.hostname + ":" + this.port + "/" + this.serviceName, this.multiImpl);

        System.out.println("Lucene Search Server started with the name " + this.serviceName);
    } catch (Exception e) {
        System.out.println(e.toString());
    }

}

From source file:org.opendaylight.infrautils.diagstatus.MBeanUtils.java

public static Pair<JMXConnectorServer, Registry> startRMIConnectorServer(MBeanServer mbeanServer,
        String selfAddress) throws IOException {
    JMXServiceURL url = getJMXUrl(requireNonNull(selfAddress, "selfAddress"));
    Registry registry = LocateRegistry.createRegistry(RMI_REGISTRY_PORT);
    JMXConnectorServer cs;/*from  w  w  w  .  j a va 2  s .  c  o  m*/
    try {
        cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null,
                requireNonNull(mbeanServer, "mbeanServer"));
        cs.start();
    } catch (IOException e) {
        LOG.error("Error while trying to create new JMX Connector for url {}", url, e);
        throw e;
    }
    LOG.info("JMX Connector Server started for url {}", url);
    return Pair.of(cs, registry);
}

From source file:org.skfiy.typhon.jmx.BuiltinJmxListener.java

@Override
public void execute(LifecycleEvent event) {
    if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getEvent())) {

        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        Registry.getRegistry(null, null).setMBeanServer(mbs);
    } else if (Lifecycle.AFTER_INIT_EVENT.equals(event.getEvent())) {
        // Ensure cryptographically strong random number generator used
        // to choose the object number - see java.rmi.server.ObjID
        ///*from  w  w w. j  a  v a2  s.co m*/
        System.setProperty("java.rmi.server.randomIDs", "true");

        // Start an RMI registry on port.
        try {
            LocateRegistry.createRegistry(port);
            LOG.info("Create RMI registry on port {}", port);
        } catch (RemoteException ex) {
            LOG.error("Create RMI registry error", ex);
            throw new TyphonException(ex);
        }

        Map<String, Object> env = new HashMap<>();

        // Provide the password file used by the connector server to
        // perform user authentication. The password file is a properties
        // based text file specifying username/password pairs.
        //
        // File file = new File(System.getProperty("typhon.home"), "bin/jmxremote.password");
        // env.put("com.sun.management.jmxremote.password.file", file.getAbsolutePath());

        try {
            jcs = JMXConnectorServerFactory.newJMXConnectorServer(newUrl(), env,
                    ManagementFactory.getPlatformMBeanServer());
            jcs.start();
        } catch (IOException ex) {
            LOG.error("start JMXConnectorServer...", ex);
            throw new TyphonException(ex);
        }
    } else if (Lifecycle.AFTER_DESTROY_EVENT.equals(event.getEvent())) {
        if (jcs != null) {
            try {
                jcs.stop();
            } catch (IOException ex) {
                LOG.error("stop JMXConnectorServer...", ex);
                throw new TyphonException(ex);
            }
        }
    }
}

From source file:org.mule.transport.rmi.RmiMessageReceiverTestCase.java

private void registerRmi() throws Exception {
    if (null == rmiRegistry) {
        rmiRegistry = LocateRegistry.createRegistry(11099);
        Naming.rebind("//localhost:11099/TestMatchingMethodsComponent",
                new SerializedMatchingMethodsComponent());

        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");

        Context context = new InitialContext(env);
        SerializedMatchingMethodsComponent obj = (SerializedMatchingMethodsComponent) context
                .lookup("rmi://localhost:11099/TestMatchingMethodsComponent");

        if (obj == null) {
            throw new RuntimeException("Could not start RMI properly");
        }/*ww w . ja v a2s  .c o  m*/
    }
}

From source file:org.apache.synapse.commons.util.RMIRegistryController.java

/**
 * Creates a RMI local registry with given port
 *
 * @param port The port of the RMI registry to be created
 *//* ww w  .  jav a2  s  .  c  o m*/
public void createLocalRegistry(int port) {

    try {

        String key = toKey(port);

        synchronized (registriesCache) {
            if (registriesCache.containsKey(key)) {
                if (log.isDebugEnabled()) {
                    log.debug("There is an RMI registry bound to given port :" + port);
                }
                return;
            }

            Registry locateRegistry = LocateRegistry.createRegistry(port);
            if (locateRegistry == null) {
                handleException("Unable to create a RMI registry with port : " + port);
            }

            registriesCache.put(key, locateRegistry);
        }

    } catch (RemoteException e) {
        String msg = "Couldn't create a local registry(RMI) : port " + port + " already in use.";
        handleException(msg, e);
    }
}

From source file:org.mule.module.management.agent.RmiRegistryAgent.java

public void start() throws MuleException {
    if (serverUri == null) {
        throw new InitialisationException(MessageFactory.createStaticMessage(
                "serverUri has not been set, this agent has not been initialized properly."), this);
    }/*from   w  w w  . j  a  va  2s. com*/

    URI uri;
    try {
        uri = new URI(serverUri);
    } catch (URISyntaxException e) {
        throw new InitialisationException(e, this);
    }

    if (rmiRegistry == null) {
        try {
            if (createRegistry) {
                try {
                    rmiRegistry = LocateRegistry.createRegistry(uri.getPort());
                } catch (ExportException e) {
                    logger.info("Registry on " + serverUri + " already bound. Attempting to use that instead");
                    rmiRegistry = LocateRegistry.getRegistry(uri.getHost(), uri.getPort());
                }
            } else {
                rmiRegistry = LocateRegistry.getRegistry(uri.getHost(), uri.getPort());
            }
        } catch (RemoteException e) {
            throw new InitialisationException(e, this);
        }
    }
}

From source file:org.ngrinder.monitor.agent.MonitorServer.java

/**
 * Initialize the monitor server./*from  w  ww . j  a  v  a 2 s.  co  m*/
 *
 * @param agentConfig agentConfig
 * @throws IOException IO error
 */
public void init(AgentConfig agentConfig) throws IOException {
    this.agentConfig = agentConfig;
    Set<String> systemDataCollector = new HashSet<String>();
    systemDataCollector.add(SYSTEM);
    MonitorContext.getInstance().setDataCollectors(systemDataCollector);
    int port = agentConfig.getMonitorProperties().getPropertyInt(PROP_MONITOR_BINDING_PORT);
    this.rmiRegistry = LocateRegistry.createRegistry(port);
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
    String hostname = agentConfig.getMonitorBindingIP();
    if (StringUtils.isBlank(hostname)) {
        hostname = NetworkUtils.getAllPBindingAddress();
    }
    final String jmxUrlString = String.format("service:jmx:rmi://%s:%d/jndi/rmi://%s:%d/jmxrmi", hostname, port,
            hostname, port);
    JMXServiceURL jmxUrl = new JMXServiceURL(jmxUrlString);
    this.jmxServer = JMXConnectorServerFactory.newJMXConnectorServer(jmxUrl, null, mBeanServer);
    RegisterMXBean.getInstance().addDefaultMXBean(mBeanServer);
    LOG.info("Service URL:{} is initiated.", jmxUrl);
}

From source file:org.brixcms.rmiserver.jackrabbit.RemoteRepositoryExporterBean.java

public void afterPropertiesSet() throws Exception {
    ServerAdapterFactory factory = new ServerAdapterFactory();
    remote = factory.getRemoteRepository(repository);

    registry = LocateRegistry.getRegistry(registryPort);
    try {/*from  w w  w.j ava 2  s  .co  m*/
        registry.list(); // test registry
    } catch (Exception e) {
        registry = LocateRegistry.createRegistry(registryPort);
        registry.list(); // test registry
    }

    logger.info("Registring JackRabbit remote repository with name: {} and registry: {} ", serviceName,
            registry);

    registry.rebind(serviceName, remote);

    logger.info("JackRabbit remote server registered: " + remote);
}