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:org.vintsie.jcobweb.framework.RmiFrameWork.java
/** * <p>/*from w ww.ja va2s. c o m*/ * Server can be started by running this main function. The * Rmi Server's port is reset to 9090, instead of the default * value 1099.</p> * <p/> * <p>The Rmi Server Port should be set by the configuration * file. This is the continuing work rest.</p> * * @param args arguments * @throws Exception */ public static void main(String[] args) throws Exception { if (log.isInfoEnabled()) { log.info(I18nFactory.getI18nInfo("set_sys_srv_ivk", ServiceFactory.getServiceInvoke().getClass().getName())); } Registry registry = LocateRegistry.createRegistry(9090); registry.rebind(IServiceStub.class.getName(), new RmiServiceStub()); if (log.isInfoEnabled()) { log.info(I18nFactory.getI18nInfo("rmi_server_is_ready")); } }
From source file:com.feedzai.fos.server.Runner.java
/** * Launches the server./* w w w .ja v a2 s. co m*/ * See @{link StartupConfiguration} for command line switches. * <p/> Will start an embedded RMI registry if "-s" was specified. * * @param args the command line switches * @throws ConfigurationException */ public static void main(String... args) throws ConfigurationException { long time = System.currentTimeMillis(); StartupConfiguration parameters = new StartupConfiguration(); JCommander jCommander = new JCommander(parameters); FosServer fosServer; try { jCommander.parse(args); logger.info("Starting fos server using configuration from {}", parameters.getConfiguration()); FosConfig serverConfig = new FosConfig(new PropertiesConfiguration(parameters.getConfiguration())); if (serverConfig.isEmbeddedRegistry()) { LocateRegistry.createRegistry(serverConfig.getRegistryPort()); logger.debug("RMI registry started in port {}", serverConfig.getRegistryPort()); } fosServer = new FosServer(serverConfig); fosServer.bind(); logger.info("FOS Server started in {}ms", (System.currentTimeMillis() - time)); } catch (ParameterException e) { jCommander.usage(); } catch (Exception e) { logger.error("Could not launch RMI service", e); } }
From source file:puma.central.pdp.EmptyCentralPUMAPDP.java
public static void main(String[] args) { // initialize log4j BasicConfigurator.configure();// w w w . j av a2s.c o m CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("ph", "policy-home", true, "The folder where to find the policy file given with the given policy id. " + "For default operation, this folder should contain the central PUMA policy (called " + CENTRAL_PUMA_POLICY_FILENAME + ")"); options.addOption("pid", "policy-id", true, "The id of the policy to be evaluated on decision requests. Default value: " + GLOBAL_PUMA_POLICY_ID + ")"); options.addOption("s", "log-disabled", true, "Verbose mode (true/false)"); String policyHome = ""; String policyId = ""; // read command line try { CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Simple PDP Test", options); return; } if (line.hasOption("policy-home")) { policyHome = line.getOptionValue("policy-home"); } else { logger.log(Level.WARNING, "Incorrect arguments given."); return; } if (line.hasOption("log-disabled") && Boolean.parseBoolean(line.getOptionValue("log-disabled"))) { logger.log(Level.INFO, "Now switching to silent mode"); LogManager.getLogManager().getLogger("").setLevel(Level.WARNING); //LogManager.getLogManager().reset(); } if (line.hasOption("policy-id")) { policyId = line.getOptionValue("policy-id"); } else { logger.log(Level.INFO, "Using default policy id: " + GLOBAL_PUMA_POLICY_ID); policyId = GLOBAL_PUMA_POLICY_ID; } } catch (ParseException e) { logger.log(Level.WARNING, "Incorrect arguments given.", e); return; } // // STARTUP THE RMI SERVER // // if (System.getSecurityManager() == null) { // System.setSecurityManager(new SecurityManager()); // } EmptyCentralPUMAPDP pdp; try { pdp = new EmptyCentralPUMAPDP(policyHome, policyId); } catch (IOException e) { logger.log(Level.SEVERE, "FAILED to set up the CentralPUMAPDP. Quitting.", e); return; } try { Registry registry; try { registry = LocateRegistry.createRegistry(RMI_REGISITRY_PORT); logger.info("Created new RMI registry"); } catch (RemoteException e) { // MDC: I hope this means the registry already existed. registry = LocateRegistry.getRegistry(RMI_REGISITRY_PORT); logger.info("Reusing existing RMI registry"); } CentralPUMAPDPRemote stub = (CentralPUMAPDPRemote) UnicastRemoteObject.exportObject(pdp, 0); registry.bind(CENTRAL_PUMA_PDP_RMI_NAME, stub); logger.info( "Central PUMA PDP up and running (available using RMI with name \"central-puma-pdp\" on RMI registry port " + RMI_REGISITRY_PORT + ")"); Thread.sleep(100); // MDC: vroeger eindigde de Thread om n of andere reden, dit lijkt te werken... } catch (Exception e) { logger.log(Level.SEVERE, "FAILED to set up PDP as RMI server", e); } // // STARTUP THE THRIFT PEP SERVER // //logger.log(Level.INFO, "Not setting up the Thrift server"); // set up server // PEPServer handler = new PEPServer(new CentralPUMAPEP(pdp)); // RemotePEPService.Processor<PEPServer> processor = new RemotePEPService.Processor<PEPServer>(handler); // TServerTransport serverTransport; // try { // serverTransport = new TServerSocket(THRIFT_PEP_PORT); // } catch (TTransportException e) { // e.printStackTrace(); // return; // } // TServer server = new TSimpleServer(new TServer.Args(serverTransport).processor(processor)); // System.out.println("Setting up the Thrift PEP server on port " + THRIFT_PEP_PORT); // server.serve(); // // STARTUP THE THRIFT PEP SERVER // //logger.log(Level.INFO, "Not setting up the Thrift server"); // set up server RemotePDPService.Processor<EmptyCentralPUMAPDP> pdpProcessor = new RemotePDPService.Processor<EmptyCentralPUMAPDP>( pdp); TServerTransport pdpServerTransport; try { pdpServerTransport = new TServerSocket(THRIFT_PDP_PORT); } catch (TTransportException e) { e.printStackTrace(); return; } TServer pdpServer = new TSimpleServer(new TServer.Args(pdpServerTransport).processor(pdpProcessor)); System.out.println("Setting up the Thrift PDP server on port " + THRIFT_PDP_PORT); pdpServer.serve(); }
From source file:puma.central.pdp.CentralPUMAPDP.java
public static void main(String[] args) { // initialize log4j BasicConfigurator.configure();// www . j a v a2 s. com CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("ph", "policy-home", true, "The folder where to find the policy file given with the given policy id. " + "For default operation, this folder should contain the central PUMA policy (called " + CENTRAL_PUMA_POLICY_FILENAME + ")"); options.addOption("pid", "policy-id", true, "The id of the policy to be evaluated on decision requests. Default value: " + GLOBAL_PUMA_POLICY_ID + ")"); options.addOption("s", "log-disabled", true, "Verbose mode (true/false)"); String policyHome = ""; String policyId = ""; // read command line try { CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Simple PDP Test", options); return; } if (line.hasOption("policy-home")) { policyHome = line.getOptionValue("policy-home"); } else { logger.log(Level.WARNING, "Incorrect arguments given."); return; } if (line.hasOption("log-disabled") && Boolean.parseBoolean(line.getOptionValue("log-disabled"))) { logger.log(Level.INFO, "Now switching to silent mode"); LogManager.getLogManager().getLogger("").setLevel(Level.WARNING); //LogManager.getLogManager().reset(); } if (line.hasOption("policy-id")) { policyId = line.getOptionValue("policy-id"); } else { logger.log(Level.INFO, "Using default policy id: " + GLOBAL_PUMA_POLICY_ID); policyId = GLOBAL_PUMA_POLICY_ID; } } catch (ParseException e) { logger.log(Level.WARNING, "Incorrect arguments given.", e); return; } // // STARTUP THE RMI SERVER // // if (System.getSecurityManager() == null) { // System.setSecurityManager(new SecurityManager()); // } final CentralPUMAPDP pdp; try { pdp = new CentralPUMAPDP(policyHome, policyId); } catch (IOException e) { logger.log(Level.SEVERE, "FAILED to set up the CentralPUMAPDP. Quitting.", e); return; } try { Registry registry; try { registry = LocateRegistry.createRegistry(RMI_REGISITRY_PORT); logger.info("Created new RMI registry"); } catch (RemoteException e) { // MDC: I hope this means the registry already existed. registry = LocateRegistry.getRegistry(RMI_REGISITRY_PORT); logger.info("Reusing existing RMI registry"); } CentralPUMAPDPRemote stub = (CentralPUMAPDPRemote) UnicastRemoteObject.exportObject(pdp, 0); registry.bind(CENTRAL_PUMA_PDP_RMI_NAME, stub); logger.info( "Central PUMA PDP up and running (available using RMI with name \"central-puma-pdp\" on RMI registry port " + RMI_REGISITRY_PORT + ")"); Thread.sleep(100); // MDC: vroeger eindigde de Thread om n of andere reden, dit lijkt te werken... } catch (Exception e) { logger.log(Level.SEVERE, "FAILED to set up PDP as RMI server", e); } // // STARTUP THE THRIFT PEP SERVER // //logger.log(Level.INFO, "Not setting up the Thrift server"); // set up server // PEPServer handler = new PEPServer(new CentralPUMAPEP(pdp)); // RemotePEPService.Processor<PEPServer> processor = new RemotePEPService.Processor<PEPServer>(handler); // TServerTransport serverTransport; // try { // serverTransport = new TServerSocket(THRIFT_PEP_PORT); // } catch (TTransportException e) { // e.printStackTrace(); // return; // } // TServer server = new TSimpleServer(new TServer.Args(serverTransport).processor(processor)); // System.out.println("Setting up the Thrift PEP server on port " + THRIFT_PEP_PORT); // server.serve(); // // STARTUP THE THRIFT PEP SERVER // //logger.log(Level.INFO, "Not setting up the Thrift server"); // set up server // do this in another thread not to block the main thread new Thread(new Runnable() { @Override public void run() { RemotePDPService.Processor<CentralPUMAPDP> pdpProcessor = new RemotePDPService.Processor<CentralPUMAPDP>( pdp); TServerTransport pdpServerTransport; try { pdpServerTransport = new TServerSocket(THRIFT_PDP_PORT); } catch (TTransportException e) { e.printStackTrace(); return; } TServer pdpServer = new TThreadPoolServer( new TThreadPoolServer.Args(pdpServerTransport).processor(pdpProcessor)); logger.info("Setting up the Thrift PDP server on port " + THRIFT_PDP_PORT); pdpServer.serve(); } }).start(); }
From source file:SetupJNDIDataSource.java
private static void startRegistry() throws RemoteException { LocateRegistry.createRegistry(1099); System.out.println("RMI registry ready."); }
From source file:org.speechforge.cairo.server.resource.ResourceServerImpl.java
/** * TODOC//from w w w .java2 s .c o m * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { CommandLineParser parser = new GnuParser(); Options options = getOptions(); CommandLine line = parser.parse(options, args, true); args = line.getArgs(); /*if (args.length < 3 || args.length > 5 || line.hasOption(ResourceImpl.HELP_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ResourceServerImpl [options] ", options); return; }*/ int sipPort = 0; String sipTransport = null; String publicAddress = null; if (line.hasOption(SIPPORT_OPTION)) { String tmp = line.getOptionValue(SIPPORT_OPTION); sipPort = Integer.valueOf(tmp); } if (line.hasOption(SIPTRANSPORT_OPTION)) { sipTransport = line.getOptionValue(SIPTRANSPORT_OPTION); } if (line.hasOption(SIPPUBLICADDRESS_OPTION)) { publicAddress = line.getOptionValue(SIPPUBLICADDRESS_OPTION); } String hostName = null; if (line.hasOption(LOCALADDRESS_OPTION)) { hostName = line.getOptionValue(LOCALADDRESS_OPTION); } _logger.debug("Command line specified sip port: " + sipPort + " and sip transport: " + sipTransport); ResourceRegistryImpl rr = new ResourceRegistryImpl(); ResourceServerImpl rs = new ResourceServerImpl(rr, sipPort, sipTransport, hostName, publicAddress); Registry registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); registry.rebind(ResourceRegistry.NAME, rr); // registry.rebind(ResourceServer.NAME, rs); _logger.info("Server and registry bound and waiting..."); }
From source file:org.apache.jcs.auxiliary.remote.RemoteUtils.java
/** * Creates and exports a registry on the specified port of the local host. * <p>//from w ww . ja v a 2 s.c om * @param port * @return the port the registry was started on * @throws RemoteException */ public static int createRegistry(int port) throws RemoteException { if (log.isInfoEnabled()) { log.info("createRegistry> setting security manager"); } System.setSecurityManager(new RMISecurityManager()); if (port < 1024) { if (log.isInfoEnabled()) { log.info("Port chosen was less than 1024, will use default [" + Registry.REGISTRY_PORT + "] instead."); } port = Registry.REGISTRY_PORT; } if (log.isInfoEnabled()) { log.info("createRegistry> creating registry on port [" + port + "]"); } LocateRegistry.createRegistry(port); return port; }
From source file:org.apache.juddi.v3.tck.UDDI_090_RMIIntegrationTest.java
@BeforeClass public static void startup() throws Exception { if (!TckPublisher.isEnabled()) { return;//from ww w . j a va2 s. c o m } startManager(); int count = 0; rmiSubscriptionListenerService = new UDDISubscriptionListenerImpl(0); UDDISubscriptionListenerImpl.notifcationMap.clear(); UDDISubscriptionListenerImpl.notificationCount = 0; while (true && count < 5) { try { count++; 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 //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()); break; } catch (Exception ex) { logger.warn("trouble starting rmi endpoint " + ex.getMessage()); } } Assert.assertNotNull(registry); Assert.assertNotNull(hostname); }
From source file:org.brixcms.rmiserver.AbstractRmiExporterBean.java
public void afterPropertiesSet() throws Exception { try {//w ww . j a va2 s. c o m registry = LocateRegistry.getRegistry(registryPort); registry.list(); } catch (Exception e) { registry = LocateRegistry.createRegistry(registryPort); registry.list(); } server = createServiceInstance(); logger.info("Exporting " + server.getClass().getName() + " under: {}/{}", serviceName, registry); RemoteStub stub = UnicastRemoteObject.exportObject(server); registry.rebind(serviceName, stub); logger.info("Exported " + server.getClass().getName() + ": {}", stub); }
From source file:org.apache.jcs.auxiliary.remote.server.RemoteCacheServerStartupUtil.java
/** * Starts the registry on port "registry.port" * <p>//ww w . j a v a 2 s. c om * @param propsFileName * @return RemoteCacheServer */ public static RemoteCacheServer startServerUsingProperties(String propsFileName) { // TODO load from props file or get as init param or get from jndi, or // all three int registryPort = DEFAULT_REGISTRY_PORT; try { Properties props = PropertyLoader.loadProperties(propsFileName); if (props != null) { String portS = props.getProperty("registry.port", String.valueOf(DEFAULT_REGISTRY_PORT)); try { registryPort = Integer.parseInt(portS); } catch (NumberFormatException e) { log.error("Problem converting port to an int.", e); } } } catch (Exception e) { log.error("Problem loading props.", e); } catch (Throwable t) { log.error("Problem loading props.", t); } // we will always use the local machine for the registry String registryHost; try { registryHost = InetAddress.getLocalHost().getHostAddress(); if (log.isDebugEnabled()) { log.debug("registryHost = [" + registryHost + "]"); } if ("localhost".equals(registryHost) || "127.0.0.1".equals(registryHost)) { log.warn("The local address [" + registryHost + "] is INVALID. Other machines must be able to use the address to reach this server."); } try { LocateRegistry.createRegistry(registryPort); } catch (RemoteException e) { log.error("Problem creating registry. It may already be started. " + e.getMessage()); } catch (Throwable t) { log.error("Problem creating registry.", t); } try { RemoteCacheServerFactory.startup(registryHost, registryPort, "/" + propsFileName); } catch (IOException e) { log.error("Problem starting remote cache server.", e); } catch (Throwable t) { log.error("Problem starting remote cache server.", t); } } catch (UnknownHostException e) { log.error("Could not get local address to use for the registry!", e); } return RemoteCacheServerFactory.getRemoteCacheServer(); }