List of usage examples for java.rmi.registry LocateRegistry createRegistry
public static Registry createRegistry(int port) throws RemoteException
Registry
instance on the local host that accepts requests on the specified port
. From source file:com.vmware.identity.idm.server.IdmServer.java
/** * Initialize the IDM service.//w w w . j a v a 2 s . co m * * @throws Exception when something goes wrong with initialization. */ private static void initialize() throws Exception { try (IDiagnosticsContextScope diagCtxt = DiagnosticsContextFactory.createContext("IDM Startup", "")) { logger.info("Starting IDM Server..."); logger.debug("Creating RMI registry on port {}", Tenant.RMI_PORT); boolean allowRemoteConnections = Boolean .parseBoolean(System.getProperty(ALLOW_REMOTE_PROPERTY, "false")); if (allowRemoteConnections) { logger.warn("RMI registry is allowing remote connections!"); registry = LocateRegistry.createRegistry(Tenant.RMI_PORT); } else { logger.debug("RMI registry is restricted to the localhost"); RMIClientSocketFactory csf = RMISocketFactory.getDefaultSocketFactory(); RMIServerSocketFactory ssf = new LocalRMIServerSocketFactory(); registry = LocateRegistry.createRegistry(Tenant.RMI_PORT, csf, ssf); } // Assign a security manager, in the event that dynamic classes are loaded if (System.getSecurityManager() == null) { logger.debug("Creating RMI Security Manager..."); System.setSecurityManager(new RMISecurityManager()); } logger.debug("Creating Config Store factory..."); IConfigStoreFactory cfgStoreFactory = new ConfigStoreFactory(); logger.debug("Creating Identity Provider factory..."); IProviderFactory providerFactory = new ProviderFactory(); logger.debug("Checking VMware Directory Service..."); ServerUtils.check_directory_service(); logger.debug("Setting system properties..."); System.setProperties(new ThreadLocalProperties(System.getProperties())); logger.debug("Creating Identity Manager instance..."); manager = new IdentityManager(cfgStoreFactory, providerFactory); String rmiAddress = String.format("rmi://localhost:%d/%s", Tenant.RMI_PORT, IDENTITY_MANAGER_BIND_NAME); logger.debug("Binding to RMI address '{}'", rmiAddress); loginManager = new IdmLoginManager(manager); ILoginManager stub = (ILoginManager) UnicastRemoteObject.exportObject(loginManager, 0); Naming.rebind(rmiAddress, stub); startHeartbeat(); logger.info(VmEvent.SERVER_STARTED, "IDM Server has started"); } catch (Throwable t) { logger.error(VmEvent.SERVER_FAILED_TOSTART, "IDM Server has failed to start", t); throw t; } }
From source file:org.apereo.portal.jmx.JavaManagementServerBean.java
/** * Starts the RMI server and JMX connector server *///from w w w .j ava 2 s . c o m public void startServer() { if (!System.getProperties().containsKey(JMX_ENABLED_PROPERTY)) { this.logger.info("System Property '" + JMX_ENABLED_PROPERTY + "' is not set, skipping initialization."); return; } try { //Get the base rmi port final int portOne = this.getPortOne(); //Get the second rmi port or calculate it final int portTwo = this.calculatePortTwo(portOne); //Create the RMI registry on the base port try { LocateRegistry.createRegistry(portOne); if (this.logger.isDebugEnabled()) { this.logger.debug("Started RMI Registry on port " + portOne); } } catch (RemoteException re) { throw new IllegalStateException("Could not create RMI Registry on port " + portOne, re); } //Generate the JMX Service URL final JMXServiceURL jmxServiceUrl = this.getServiceUrl(portOne, portTwo); //Map for the JMX environment configuration final Map<String, Object> jmxEnv = this.getJmxServerEnvironment(); //Create the MBean Server final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); //Create the JMX Connector try { this.jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(jmxServiceUrl, jmxEnv, mbeanServer); if (this.logger.isDebugEnabled()) { this.logger.debug("Created JMXConnectorServer for JMXServiceURL='" + jmxServiceUrl + "', jmxEnv='" + jmxEnv + "' MBeanServer='" + mbeanServer + "'"); } } catch (IOException ioe) { throw new IllegalStateException("Failed to create a new JMXConnectorServer for JMXServiceURL='" + jmxServiceUrl + "', jmxEnv='" + jmxEnv + "' MBeanServer='" + mbeanServer + "'", ioe); } //Start the JMX Connector try { this.jmxConnectorServer.start(); this.logger.info("Started JMXConnectorServer. Listening on '" + jmxServiceUrl + "'"); } catch (IOException ioe) { throw new IllegalStateException("Failed to start the JMXConnectorServer", ioe); } } catch (RuntimeException re) { if (this.failOnException) { throw re; } this.logger.error("Failed to initialize the JMX Server", re); } }
From source file:com.app.server.EJBDeployer.java
public void init(Vector serviceList, ServerConfig serverConfig, MBeanServer mbeanServer) { this.serviceList = serviceList; this.serverConfig = serverConfig; this.mbeanServer = mbeanServer; this.serviceRegistryPort = Integer.parseInt(serverConfig.getServicesregistryport()); //System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); //System.setProperty(Context.PROVIDER_URL, "rmi://localhost:"+serverConfig.getServicesregistryport());; try {/* www. j av a 2 s . c om*/ fsManager = new StandardFileSystemManager(); System.setProperty("java.io.tmpdir", serverConfig.getCachedir()); /*DefaultFileReplicator replicator = new DefaultFileReplicator(new File(cacheDir)); //fsManager.setReplicator(new PrivilegedFileReplicator(replicator)); fsManager.setTemporaryFileStore(replicator);*/ fsManager.init(); registry = LocateRegistry.createRegistry(Integer.parseInt(serverConfig.getServicesregistryport())); try { ic = new InitialContext(); Context subctx = null; try { subctx = (Context) ic.lookup("java:"); } catch (Exception ex) { log.error("Error in getting the java context", ex); //ex.printStackTrace(); } if (subctx == null) { ic.createSubcontext("java:"); } remoteBindingInterface = new RemoteBindingObject(ic); Object jndilookupobj = UnicastRemoteObject.exportObject((Remote) remoteBindingInterface, this.serviceRegistryPort); //registry.rebind("RemoteBindingObject", (Remote) jndilookupobj); } catch (Exception ex) { log.error("error in registring to the remote binding object", ex); //e1.printStackTrace(); } this.jms = new EmbeddedJMS(); this.jms.start(); } catch (Exception e) { log.error("error in initialization", e); // TODO Auto-generated catch block //e.printStackTrace(); } connectionFactory = (ConnectionFactory) jms.lookup("java:/ConnectionFactory"); log.info("initialized"); }
From source file:org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer.java
@Override public synchronized TestContainer start() { try {/* w w w. j av a2s. c o m*/ String name = system.createID(KARAF_TEST_CONTAINER); Option invokerConfiguration = getInvokerConfiguration(); //registry.selectGracefully(); FreePort freePort = new FreePort(21000, 21099); int port = freePort.getPort(); LOGGER.debug("using RMI registry at port {}", port); rgstry = LocateRegistry.createRegistry(port); String host = InetAddress.getLocalHost().getHostName(); ExamSystem subsystem = system.fork(options(systemProperty(RMI_HOST_PROPERTY).value(host), systemProperty(RMI_PORT_PROPERTY).value(Integer.toString(port)), systemProperty(RMI_NAME_PROPERTY).value(name), invokerConfiguration, systemProperty(EXAM_INJECT_PROPERTY).value("true"), editConfigurationFileExtend("etc/system.properties", "jline.shutdownhook", "true"))); target = new RBCRemoteTarget(name, port, subsystem.getTimeout()); System.setProperty("java.protocol.handler.pkgs", "org.ops4j.pax.url"); URL sourceDistribution = new URL(framework.getFrameworkURL()); targetFolder = retrieveFinalTargetFolder(subsystem); ArchiveExtractor.extract(sourceDistribution, targetFolder); File karafBase = searchKarafBase(targetFolder); File karafHome = karafBase; versionAdaptions = createVersionAdapter(karafBase); DependenciesDeployer deployer = new DependenciesDeployer(subsystem, karafBase, karafHome); deployer.copyBootClasspathLibraries(); updateLogProperties(karafHome, subsystem); setupSystemProperties(karafHome, subsystem); List<KarafDistributionConfigurationFileOption> options = new ArrayList<KarafDistributionConfigurationFileOption>( Arrays.asList(subsystem.getOptions(KarafDistributionConfigurationFileOption.class))); options.addAll(fromFeatureOptions(subsystem.getOptions(KarafFeaturesOption.class))); options.addAll(fromFeatureOptions(KarafDistributionOption.features(EXAM_REPO_URL, "exam"))); if (framework.isUseDeployFolder()) { deployer.copyReferencedArtifactsToDeployFolder(); } else { options.addAll(fromFeatureOptions(deployer.getDependenciesFeature())); } options.addAll(configureBootDelegation(subsystem)); options.addAll(configureSystemPackages(subsystem)); updateUserSetProperties(karafHome, options); startKaraf(subsystem, karafBase, karafHome); started = true; } catch (IOException e) { throw new RuntimeException("Problem starting container", e); } return this; }
From source file:org.jgentleframework.integration.remoting.rmi.support.RmiExecutor.java
/** * Gets the registry.//w ww . ja v a2s . co m * * @param registryPort * the registry port * @param autoCreateRegistry * the auto create registry * @return Registry * @throws RemoteException * the remote exception */ public static Registry getRegistry(boolean autoCreateRegistry, int registryPort) throws RemoteException { if (autoCreateRegistry) { return LocateRegistry.createRegistry(registryPort); } try { Registry reg = LocateRegistry.getRegistry(registryPort); // Kim tra Registry. testRegistry(reg); return reg; } catch (RemoteException ex) { return LocateRegistry.createRegistry(registryPort); } }
From source file:org.jcommon.com.util.jmx.RmiAdptor.java
public void setCserver(MBeanServer server) throws MalformedURLException, IOException { if (port == 0 || name == null || addr == null) { throw new NullPointerException("data not be ready"); }//w w w . j a v a 2 s.com try { registry = LocateRegistry.createRegistry(port); } catch (RemoteException e) { } HashMap<String, Object> prop = new HashMap<String, Object>(); if (CREDENTIALS != null) { authenticator = new JMXAuthenticator() { public Subject authenticate(Object credentials) { logger.info(credentials.getClass().getName() + " is trying connect..."); if (credentials instanceof String) { if (credentials.equals(CREDENTIALS)) { return new Subject(); } } else if (credentials instanceof String[]) { String[] copy = (String[]) credentials; String username = copy.length > 0 ? copy[0] : null; String passwd = copy.length > 1 ? copy[1] : null; logger.info(username + " is trying connect..."); if (passwd.equals(CREDENTIALS) && username.equals(user)) { return new Subject(); } } throw new SecurityException("not authicated"); } }; prop.put(JMXConnectorServer.AUTHENTICATOR, authenticator); } String url = "service:jmx:rmi:///jndi/rmi://" + addr + ":" + port + "/" + name; this.cserver = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL(url), prop, server); }
From source file:org.act.index.server.MetaService.java
@Override public int createCore(int coreId) { // TODO Auto-generated method stub try {/* w w w .j a v a2 s.com*/ if (indexServer.getSolrServers().containsKey(coreId)) return GlobalMessage.ISS_ERROR; String dir = indexServer.getUrl() + "/core" + String.valueOf(coreId); //LOG.debug("dir:" + dir); indexServer.addSolrServer(coreId); FileUtils.forceMkdir(new File(dir)); FileUtils.forceMkdir(new File(dir + "/conf")); String configPath = dir + "/conf/solrconfig.xml"; String schemaPath = dir + "/conf/schema.xml"; createSolrConfig(configPath); createSchema(schemaPath, coreId); //indexServer.addSolrServer(coreId); //CoreAdminRequest.createCore(String.valueOf(coreId), "core" // + String.valueOf(coreId), indexServer.getSolrServer()); CoreAdminRequest.createCore(String.valueOf(coreId), "core" + String.valueOf(coreId), indexServer.getSolrServer()); //CoreAdminRequest.createCore("10", "core10", server, configPath, schemaPath); FileUtils.forceMkdir(new File(dir + "/data")); FileUtils.forceMkdir(new File(dir + "/data/index")); SolrService service = new SolrService(indexServer.getSolrServer(coreId)); //solrServices.put(coreId, service); //int port = ServerParam.LOCAL_SERVER_PORT + serverId * ServerParam.MAX_CORE_COUNT_PER_SERVER + coreId + 1; int serverId = indexServer.getServerInfo().getServerId(); String ip = Inet4Address.getLocalHost().getHostAddress(); int port = indexServer.getServerAddr().getPort() + coreId + 1; LocateRegistry.createRegistry(port); String name = "rmi://" + ip + ":" + port + "/core" + coreId + "@server" + serverId; Naming.rebind(name, service); LOG.info("rmi:solrserver( " + name + ") is ready!"); } catch (SolrServerException e) { // TODO: handle exception e.printStackTrace(); } catch (IOException e) { // TODO: handle exception e.printStackTrace(); } return GlobalMessage.ISS_SUCCESS; }
From source file:org.alfresco.reporting.test.TestReporting.java
private static Registry startRegistry() throws RemoteException { System.out.println("enter startRegistry"); Registry registry = null;//from w w w .ja v a 2s.c o m try { registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); System.out.println("exit startRegistry: RMI registry created."); } catch (ExportException e) { System.out.println("exit startRegistry: RMI registry already existed."); } return registry; }
From source file:com.continuent.tungsten.common.jmx.JmxManager.java
/** * Starts the rmi registry.// w ww. j ava2s. co m */ protected void createRegistry(int port) { // Create a registry if we don't already have one. if (rmiRegistry == null) { try { if (logger.isDebugEnabled()) { logger.debug("Starting RMI registry on registryPort: " + port); } rmiRegistry = LocateRegistry.createRegistry(port); } catch (Throwable e) { throw new ServerRuntimeException("Unable to start rmi registry on registryPort: " + port, e); } } }
From source file:edu.clemson.cs.nestbed.server.Server.java
public Server() throws MalformedURLException, RemoteException { System.setOut(//from ww w . j av a 2 s . c o m new PrintStream(new BufferedOutputStream(new LogOutputStream(System.class, Level.WARN)), true)); System.setErr( new PrintStream(new BufferedOutputStream(new LogOutputStream(System.class, Level.ERROR)), true)); log.info("******************************************************\n" + "** NESTbed Server Starting\n" + "******************************************************"); log.info("Version: " + Version.VERSION); ParentClassLoader.setParent(Server.class.getClassLoader()); // Create the RMI registry LocateRegistry.createRegistry(1099); moteManager = MoteManagerImpl.getInstance(); shutdownTrigger = new ShutdownTrigger(); programSymbolManager = ProgramSymbolManagerImpl.getInstance(); progProfSymbolManager = ProgramProfilingSymbolManagerImpl.getInstance(); programManager = ProgramManagerImpl.getInstance(); moteDepConfigManager = MoteDeploymentConfigurationManagerImpl.getInstance(); projDepConfigManager = ProjectDeploymentConfigurationManagerImpl.getInstance(); projectManager = ProjectManagerImpl.getInstance(); moteTypeManager = MoteTypeManagerImpl.getInstance(); moteTbAssignManager = MoteTestbedAssignmentManagerImpl.getInstance(); testbedManger = TestbedManagerImpl.getInstance(); progMsgSymbolManager = ProgramMessageSymbolManagerImpl.getInstance(); progProfMsgSymbolMgnr = ProgramProfilingMessageSymbolManagerImpl.getInstance(); messageManager = MessageManagerImpl.getInstance(); programDeploymentManager = ProgramDeploymentManagerImpl.getInstance(); programCompileManager = ProgramCompileManagerImpl.getInstance(); programWeaverManager = ProgramWeaverManagerImpl.getInstance(); programProbeManager = ProgramProbeManagerImpl.getInstance(); nucleusManager = NucleusManagerImpl.getInstance(); sfManager = SerialForwarderManagerImpl.getInstance(); motePowerManager = MotePowerManagerImpl.getInstance(); bindRemoteObjects(); }