List of usage examples for java.rmi.registry Registry bind
public void bind(String name, Remote obj) throws RemoteException, AlreadyBoundException, AccessException;
name
in this registry. From source file:puma.central.pdp.CentralPUMAPDP.java
public static void main(String[] args) { // initialize log4j BasicConfigurator.configure();/*from w ww.j av a 2 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:de.clusteval.framework.ClustevalBackendServer.java
/** * A helper method for {@link #ClusteringEvalFramework(Repository)}, which * registers the new backend server instance in the RMI registry. * /*from w w w. j a va 2 s . c om*/ * @param framework * The backend server to register. * @return True, if the server has been registered successfully */ protected static boolean registerServer(ClustevalBackendServer framework) { Logger log = LoggerFactory.getLogger(ClustevalBackendServer.class); try { LocateRegistry.createRegistry(port); IBackendServer stub = (IBackendServer) UnicastRemoteObject.exportObject(framework, port); Registry registry = LocateRegistry.getRegistry(port); registry.bind("EvalServer", stub); log.info("Framework up and listening on port " + port); log.info("Used number of processors: " + config.numberOfThreads); return true; } catch (AlreadyBoundException e) { log.error("Another instance is already running..."); return false; } catch (RemoteException e) { log.error("Another instance is already running..."); return false; } }
From source file:org.apache.hadoop.distributedloadsimulator.sls.SLSRunner.java
public static void main(String args[]) throws Exception { Options options = new Options(); options.addOption("inputsls", true, "input sls files"); options.addOption("nodes", true, "input topology"); options.addOption("output", true, "output directory"); options.addOption("trackjobs", true, "jobs to be tracked during simulating"); options.addOption("printsimulation", false, "print out simulation information"); options.addOption("yarnnode", false, "taking boolean to enable rt mode"); options.addOption("distributedmode", false, "taking boolean to enable scheduler mode"); options.addOption("loadsimulatormode", false, "taking boolean to enable load simulator mode"); options.addOption("rtaddress", true, "Resourcetracker address"); options.addOption("rmaddress", true, "Resourcemanager address for appmaster"); options.addOption("parallelsimulator", false, "this is a boolean value to check whether to enable parallel simulator or not"); options.addOption("rmiaddress", true, "Run a simulator on distributed mode, so we need rmi address"); options.addOption("stopappsimulation", false, "we can stop the application simulation"); options.addOption("isLeader", false, "leading slsRunner for the measurer"); options.addOption("simulationDuration", true, "duration of the simulation only needed by the leader"); options.addOption("rmiport", true, "port for the rmi server"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); String inputSLS = cmd.getOptionValue("inputsls"); String output = cmd.getOptionValue("output"); String rtAddress = cmd.getOptionValue("rtaddress"); // we are expecting the multiple rt, so input should be comma seperated String rmAddress = cmd.getOptionValue("rmaddress"); String rmiAddress = "127.0.0.1"; boolean isLeader = cmd.hasOption("isLeader"); System.out.println(isLeader); long simulationDuration = 0; int rmiPort = 0; if (isLeader) { System.out.println(cmd.getOptionValue("simulationDuration")); simulationDuration = Long.parseLong(cmd.getOptionValue("simulationDuration")) * 1000; }/*from w ww .j av a 2s.c om*/ if ((inputSLS == null) || output == null) { System.err.println(); System.err.println("ERROR: Missing input or output file"); System.err.println(); System.err.println( "Options: -inputsls FILE,FILE... " + "-output FILE [-nodes FILE] [-trackjobs JobId,JobId...] " + "[-printsimulation]" + "[-distributedrt]"); System.err.println(); System.exit(1); } File outputFile = new File(output); if (!outputFile.exists() && !outputFile.mkdirs()) { System.err.println("ERROR: Cannot create output directory " + outputFile.getAbsolutePath()); System.exit(1); } Set<String> trackedJobSet = new HashSet<String>(); if (cmd.hasOption("trackjobs")) { String trackjobs = cmd.getOptionValue("trackjobs"); String jobIds[] = trackjobs.split(","); trackedJobSet.addAll(Arrays.asList(jobIds)); } String nodeFile = cmd.hasOption("nodes") ? cmd.getOptionValue("nodes") : ""; String inputFiles[] = inputSLS.split(","); if (cmd.hasOption("stopappsimulation")) { stopAppSimulation = true; LOG.warn("Application simulation is disabled!!!!!!"); } if (cmd.hasOption("parallelsimulator")) { // then we need rmi address rmiAddress = cmd.getOptionValue("rmiaddress"); // currently we support only two simulator in parallel } if (cmd.hasOption("rmiport")) { rmiPort = Integer.parseInt(cmd.getOptionValue("rmiport")); } SLSRunner sls = new SLSRunner(inputFiles, nodeFile, output, trackedJobSet, cmd.hasOption("printsimulation"), cmd.hasOption("yarnnode"), cmd.hasOption("distributedmode"), cmd.hasOption("loadsimulatormode"), rtAddress, rmAddress, rmiAddress, rmiPort, isLeader, simulationDuration); if (!cmd.hasOption("distributedmode")) { try { AMNMCommonObject stub = (AMNMCommonObject) UnicastRemoteObject.exportObject(sls, 0); // Bind the remote object's stub in the registry Registry registry = LocateRegistry.getRegistry(rmiPort); registry.bind("AMNMCommonObject", stub); LOG.info("HOP :: SLS RMI Server ready on port " + rmiPort); sls.start(); } catch (Exception e) { System.err.println("Server exception: " + e.toString()); e.printStackTrace(); } } else { sls.start(); } }
From source file:org.apache.jackrabbit.j2ee.RepositoryStartupServlet.java
/** * Registers the repository to an RMI registry configured in the web * application. See <a href="#registerAlgo">Registration with RMI</a> in the * class documentation for a description of the algorithms used to register * the repository with an RMI registry.//from w w w . ja va2s . c o m * @throws ServletException if an error occurs. */ private void registerRMI() { RMIConfig rc = config.getRmiConfig(); if (!rc.isValid() || !rc.enabled()) { return; } // try to create remote repository Remote remote; try { Class<?> clazz = Class.forName(getRemoteFactoryDelegaterClass()); RemoteFactoryDelegater rmf = (RemoteFactoryDelegater) clazz.newInstance(); remote = rmf.createRemoteRepository(repository); } catch (RemoteException e) { log.warn("Unable to create RMI repository.", e); return; } catch (Throwable t) { log.warn("Unable to create RMI repository." + " The jcr-rmi jar might be missing.", t); return; } try { System.setProperty("java.rmi.server.useCodebaseOnly", "true"); Registry reg = null; // first try to create the registry, which will fail if another // application is already running on the configured host/port // or if the rmiHost is not local try { // find the server socket factory: use the default if the // rmiHost is not configured RMIServerSocketFactory sf; if (rc.getRmiHost().length() > 0) { log.debug("Creating RMIServerSocketFactory for host " + rc.getRmiHost()); InetAddress hostAddress = InetAddress.getByName(rc.getRmiHost()); sf = getRMIServerSocketFactory(hostAddress); } else { // have the RMI implementation decide which factory is the // default actually log.debug("Using default RMIServerSocketFactory"); sf = null; } // create a registry using the default client socket factory // and the server socket factory retrieved above. This also // binds to the server socket to the rmiHost:rmiPort. reg = LocateRegistry.createRegistry(rc.rmiPort(), null, sf); rmiRegistry = reg; } catch (UnknownHostException uhe) { // thrown if the rmiHost cannot be resolved into an IP-Address // by getRMIServerSocketFactory log.info("Cannot create Registry", uhe); } catch (RemoteException e) { // thrown by createRegistry if binding to the rmiHost:rmiPort // fails, for example due to rmiHost being remote or another // application already being bound to the port log.info("Cannot create Registry", e); } // if creation of the registry failed, we try to access an // potentially active registry. We do not check yet, whether the // registry is actually accessible. if (reg == null) { log.debug("Trying to access existing registry at " + rc.getRmiHost() + ":" + rc.getRmiPort()); try { reg = LocateRegistry.getRegistry(rc.getRmiHost(), rc.rmiPort()); } catch (RemoteException re) { log.warn("Cannot create the reference to the registry at " + rc.getRmiHost() + ":" + rc.getRmiPort(), re); } } // if we finally have a registry, register the repository with the // rmiName if (reg != null) { log.debug("Registering repository as " + rc.getRmiName() + " to registry " + reg); reg.bind(rc.getRmiName(), remote); // when successfull, keep references this.rmiRepository = remote; log.info("Repository bound via RMI with name: " + rc.getRmiUri()); } else { log.info("RMI registry missing, cannot bind repository via RMI"); } } catch (RemoteException e) { log.warn("Unable to bind repository via RMI: " + rc.getRmiUri(), e); } catch (AlreadyBoundException e) { log.warn("Unable to bind repository via RMI: " + rc.getRmiUri(), e); } }
From source file:org.globus.workspace.remoting.RemotingServer.java
public void initialize() throws RemoteException, AlreadyBoundException { if (this.socketDirectory == null) { throw new IllegalStateException("socketDirectory must be specified"); }/*from w w w . j a v a 2s .co m*/ if (!this.socketDirectory.isDirectory()) { throw new IllegalStateException( "socketDirectory must be an existing directory: " + this.socketDirectory.getAbsolutePath()); } if (this.bindings == null || this.bindings.isEmpty()) { throw new IllegalStateException("at least one binding must be specified"); } final AFUNIXNaming naming = AFUNIXNaming.getInstance(this.socketDirectory); logger.debug("Socket directory: " + naming.getSocketFactory().getSocketDir()); // this trick allows repeated initializations within the same JVM. (like during test runs) Registry registry; try { registry = naming.createRegistry(); } catch (RemoteException e) { registry = naming.getRegistry(); } final StringBuilder logMessage = new StringBuilder(); logMessage.append("Nimbus remoting server listening on domain socket: \"") .append(this.socketDirectory.getAbsolutePath()).append("\". Bindings:"); boolean first = true; for (final String bindingName : bindings.keySet()) { final Remote obj = bindings.get(bindingName); if (obj == null) { throw new IllegalStateException("Binding object " + bindingName + "' is null"); } logger.debug("Binding " + obj.toString() + " to name '" + bindingName + "'"); final Remote remote = UnicastRemoteObject.exportObject(obj, 0, naming.getSocketFactory(), naming.getSocketFactory()); try { registry.bind(bindingName, remote); } catch (AlreadyBoundException e) { logger.warn("RMI binding '" + bindingName + "' is already bound. Proceeding."); } if (first) { first = false; } else { logMessage.append(","); } logMessage.append(" ").append(bindingName).append(" (").append(obj.getClass().getCanonicalName()) .append(")"); } logger.info(logMessage.toString()); }
From source file:org.kchine.rpf.ManagedServantAbstract.java
public ManagedServantAbstract(String name, String prefix, Registry registry, int port) throws RemoteException { super(port);//from w ww . j ava 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 ww w . j ava2s.c o m*/ 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:puma.central.pdp.EmptyCentralPUMAPDP.java
public static void main(String[] args) { // initialize log4j BasicConfigurator.configure();/* ww w. j a v a 2 s . c om*/ 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(); }