List of usage examples for java.rmi.server UnicastRemoteObject exportObject
private static Remote exportObject(Remote obj, UnicastServerRef sref) throws RemoteException
From source file:org.apache.jcs.auxiliary.remote.RemoteCacheListener.java
/** * Only need one since it does work for all regions, just reference by multiple region names. * <p>//from ww w . j av a 2 s . c o m * The constructor exports this object, making it available to receive incoming calls. The * calback port is anonymous unless a local port vlaue was specified in the configurtion. * @param irca * @param cacheMgr */ public RemoteCacheListener(IRemoteCacheAttributes irca, ICompositeCacheManager cacheMgr) { this.irca = irca; this.cacheMgr = cacheMgr; // Export this remote object to make it available to receive incoming // calls, using an anonymous port unless the local port is specified. try { if (irca.getLocalPort() != 0) { UnicastRemoteObject.exportObject(this, irca.getLocalPort()); } else { UnicastRemoteObject.exportObject(this); } } catch (RemoteException ex) { log.error("Problem exporting object.", ex); throw new IllegalStateException(ex.getMessage()); } }
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 ww.j a v a2 s . co m*/ _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.apache.ode.jca.server.rmi.RmiTransportServerImpl.java
public synchronized OdeTransportPipeRemote newPipe() throws RemoteException { RmiPipeServerImpl pipe = new RmiPipeServerImpl(this, _connProvider.createConnectionObject(), _connProvider.getConnectionIntefaces()); OdeTransportPipeRemote remote = (OdeTransportPipeRemote) UnicastRemoteObject.exportObject(pipe, 0); pipe.remote = remote;/*from w w w. j a v a2 s. c o m*/ _pipes.add(pipe); return remote; }
From source file:org.gtdfree.GTDFree.java
private void exportRemote() { if (stub != null) { return;//from ww w . ja v a2 s .co m } ObjectOutputStream oos = null; try { stub = (GTDFreeOperations) UnicastRemoteObject.exportObject(this, 0); File f = new File(ApplicationHelper.getDataFolder(), STUB_FILE_NAME); f.delete(); oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(f))); oos.writeObject(stub); logger.debug("Remote connection exported."); //$NON-NLS-1$ } catch (Exception e) { e.printStackTrace(); } finally { if (oos != null) { try { oos.close(); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:org.ops4j.pax.exam.rbc.internal.Activator.java
/** * {@inheritDoc}/*from w ww.ja v a 2s . co m*/ */ public void start(final BundleContext bundleContext) throws Exception { //!! Absolutely necessary for RMIClassLoading to work ContextClassLoaderUtils.doWithClassLoader(null, // getClass().getClassLoader() new Callable<Object>() { public Object call() throws Exception { try { // try to find port from property int port = getPort(); m_registry = LocateRegistry.getRegistry(port); LOG.debug("Binding " + RemoteBundleContext.class.getSimpleName() + " to RMI registry"); m_registry.bind(RemoteBundleContext.class.getName(), UnicastRemoteObject.exportObject( m_remoteBundleContext = new RemoteBundleContextImpl(bundleContext), 0)); LOG.info("Remote Bundle Context started"); } catch (Exception e) { throw new BundleException("Cannot bind RBC to RMI registry", e); } return null; } }); }
From source file:org.quartz.core.QuartzScheduler.java
/** * <p>//from ww w. j a v a 2s . co m * 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:puma.central.pdp.EmptyCentralPUMAPDP.java
public static void main(String[] args) { // initialize log4j BasicConfigurator.configure();/* ww w . j a v a 2s .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(); }