List of usage examples for java.rmi.registry Registry rebind
public void rebind(String name, Remote obj) throws RemoteException, AccessException;
name
in this registry with the supplied remote reference. From source file:engine.ComputeEngine.java
public static void main(String[] args) { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); }//from www .j av a 2s . co m try { String name = "Compute"; Compute engine = new ComputeEngine(); Compute stub = (Compute) UnicastRemoteObject.exportObject(engine, 0); Registry registry = LocateRegistry.getRegistry(); registry.rebind(name, stub); System.out.println("ComputeEngine bound"); } catch (Exception e) { System.err.println("ComputeEngine exception:"); e.printStackTrace(); } }
From source file:edu.cornell.med.icb.R.RConfigurationServer.java
public static void main(final String[] args) throws RemoteException { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); }/*from w w w . ja va 2 s . c o m*/ final String name = "RConfiguration"; final RConfiguration engine = new RConfigurationServer(); final RConfiguration stub = (RConfiguration) UnicastRemoteObject.exportObject(engine, 0); final Registry registry = LocateRegistry.getRegistry(); System.out.println(ArrayUtils.toString(registry.list())); registry.rebind(name, stub); System.out.println("RConfiguration bound"); }
From source file:engine.Pi.java
public static void main(String[] args) { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); }// www .j a va 2s . c o m try { String name = "Compute"; Compute engine = new ComputeEngine(); Compute stub = (Compute) UnicastRemoteObject.exportObject(engine, 0); Registry registry = LocateRegistry.getRegistry(); registry.rebind(name, stub); System.out.println("ComputeEngine bound"); } catch (Exception e) { System.err.println("ComputeEngine exception:"); e.printStackTrace(); } }
From source file:edu.mines.acmX.exhibit.runner.ModuleManagerRunner.java
private static void publicizeRmiInterface(ModuleManager m, int registry_port) throws RemoteException { ModuleManagerRemote remote = (ModuleManagerRemote) UnicastRemoteObject.exportObject(m, 0); Registry reg = LocateRegistry.createRegistry(registry_port); logger.info("java RMI registry created."); reg.rebind(RMI_SERVER_NAME, remote); }
From source file:org.apache.ode.jca.server.rmi.RmiTransportServerImpl.java
public synchronized void start() throws RemoteException { if (_id == null) throw new IllegalStateException("Must set id!"); if (_connProvider == null) throw new IllegalStateException("Must set connection provider."); _remote = UnicastRemoteObject.exportObject(this, 0); // Bind the RMI-server to the registry, creating one if necessary try {/*from w w w . j ava 2 s .com*/ _registry = LocateRegistry.createRegistry(_port); __log.debug("Created registry on port " + _port); } catch (Exception ex) { __log.debug("Could not create registry on port " + _port + " (perhaps it's already there)"); /* ignore */ } Registry registry = LocateRegistry.getRegistry(_port); registry.rebind(_id, _remote); __log.debug("Bound JCA server as \"" + _id + "\" on registry port " + _port); }
From source file:org.kchine.rpf.ManagedServantAbstract.java
public ManagedServantAbstract(String name, String prefix, Registry registry, int port) throws RemoteException { super(port);/*from www .j a v a 2 s . c o m*/ _registry = registry; try { registry.list(); log.info("ping registry:ok"); } catch (ConnectException ce) { String message = "can't connect to the naming server, make sure an instance of rmiregistry is running"; log.info(message); throw new RemoteException(message); } catch (Exception e) { e.printStackTrace(); } String newname = null; if (name == null) { while (true) { newname = makeName(prefix, registry); try { registry.bind(newname, java.rmi.server.RemoteObject.toStub(this)); break; } catch (AlreadyBoundException e) { } } } else { // if (!name.startsWith(prefix)) throw new // RemoteException("The server name must start with :" + prefix); ManagedServant oldServant = null; try { oldServant = ((ManagedServant) registry.lookup(name)); } catch (NotBoundException e) { } if (oldServant != null) { log.info("Found an old servant with this name. Killing old servant."); try { PoolUtils.die(oldServant); } catch (RemoteException re) { log.info("Old servant wouldn't die! "); } } registry.rebind(name, java.rmi.server.RemoteObject.toStub(this)); } _servantName = name == null ? newname : name; final Registry reg = registry; Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { try { log.info("Shutting Down"); reg.unbind(_servantName); } catch (Exception e) { e.printStackTrace(); } } })); }
From source file:org.kchine.rpf.ManagedServantAbstract.java
public String export(Properties namingRegistryProperties, String prefixOrName, boolean autoName) throws RemoteException { try {//from w w w. ja v a 2s . c om Registry registry = ServerDefaults.getRegistry(namingRegistryProperties); if (autoName) { String newname = null; while (true) { newname = makeName(prefixOrName, registry); try { registry.bind(newname, java.rmi.server.RemoteObject.toStub(this)); break; } catch (AlreadyBoundException e) { } } return newname; } else { registry.rebind(prefixOrName, java.rmi.server.RemoteObject.toStub(this)); return prefixOrName; } } catch (Exception e) { throw new RemoteException("", e); } }
From source file:org.quartz.core.QuartzScheduler.java
/** * <p>// w ww . j a v a 2s .c om * Bind the scheduler to an RMI registry. * </p> */ private void bind() throws RemoteException { String host = resources.getRMIRegistryHost(); // don't export if we're not configured to do so... if (host == null || host.length() == 0) { return; } RemotableQuartzScheduler exportable = null; if (resources.getRMIServerPort() > 0) { exportable = (RemotableQuartzScheduler) UnicastRemoteObject.exportObject(this, resources.getRMIServerPort()); } else { exportable = (RemotableQuartzScheduler) UnicastRemoteObject.exportObject(this); } Registry registry = null; if (resources.getRMICreateRegistryStrategy().equals(QuartzSchedulerResources.CREATE_REGISTRY_AS_NEEDED)) { try { // First try to get an existing one, instead of creating it, // since if // we're in a web-app being 'hot' re-depoloyed, then the JVM // still // has the registry that we created above the first time... registry = LocateRegistry.getRegistry(resources.getRMIRegistryPort()); registry.list(); } catch (Exception e) { registry = LocateRegistry.createRegistry(resources.getRMIRegistryPort()); } } else if (resources.getRMICreateRegistryStrategy() .equals(QuartzSchedulerResources.CREATE_REGISTRY_ALWAYS)) { try { registry = LocateRegistry.createRegistry(resources.getRMIRegistryPort()); } catch (Exception e) { // Fall back to an existing one, instead of creating it, since // if // we're in a web-app being 'hot' re-depoloyed, then the JVM // still // has the registry that we created above the first time... registry = LocateRegistry.getRegistry(resources.getRMIRegistryPort()); } } else { registry = LocateRegistry.getRegistry(resources.getRMIRegistryHost(), resources.getRMIRegistryPort()); } String bindName = resources.getRMIBindName(); registry.rebind(bindName, exportable); getLog().info("Scheduler bound to RMI registry under name '" + bindName + "'"); }
From source file:org.speechforge.cairo.server.resource.ResourceServerImpl.java
/** * TODOC/* w w w. ja va2s. co 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.springframework.remoting.rmi.RmiServiceExporter.java
/** * Register the service as RMI object./*from w w w .ja va2 s . c om*/ * Creates an RMI registry on the specified port if none exists. */ public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); if (this.serviceName == null) { throw new IllegalArgumentException("serviceName is required"); } if (this.clientSocketFactory instanceof RMIServerSocketFactory) { this.serverSocketFactory = (RMIServerSocketFactory) this.clientSocketFactory; } if ((this.clientSocketFactory != null && this.serverSocketFactory == null) || (this.clientSocketFactory == null && this.serverSocketFactory != null)) { throw new IllegalArgumentException( "Both RMIClientSocketFactory and RMIServerSocketFactory or none required"); } Registry registry = null; logger.info("Looking for RMI registry at port '" + this.registryPort + "'"); try { // retrieve registry registry = LocateRegistry.getRegistry(this.registryPort); registry.list(); } catch (RemoteException ex) { logger.debug("RMI registry access threw exception", ex); logger.warn("Could not detect RMI registry - creating new one"); // assume no registry found -> create new one registry = LocateRegistry.createRegistry(this.registryPort); } // determine remote object if (getService() instanceof Remote) { // conventional RMI service this.exportedObject = (Remote) getService(); } else { // RMI invoker logger.info("RMI object '" + this.serviceName + "' is an RMI invoker"); this.exportedObject = new RmiInvocationWrapper(getProxyForService(), this); } // export remote object and bind it to registry logger.info( "Binding RMI service '" + this.serviceName + "' to registry at port '" + this.registryPort + "'"); if (this.clientSocketFactory != null) { UnicastRemoteObject.exportObject(this.exportedObject, this.servicePort, this.clientSocketFactory, this.serverSocketFactory); } else { UnicastRemoteObject.exportObject(this.exportedObject, this.servicePort); } registry.rebind(this.serviceName, this.exportedObject); }