Java Code Examples for java.rmi.registry.LocateRegistry.createRegistry()

The following are Jave code examples for showing how to use createRegistry() of the java.rmi.registry.LocateRegistry class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: JstatdTest.java   View Source Code Vote up 6 votes
private Registry startRegistry()
        throws InterruptedException, RemoteException {
    Registry registry = null;
    try {
        System.out.println("Start rmiregistry on port " + port);
        registry = LocateRegistry
                .createRegistry(Integer.parseInt(port));
    } catch (RemoteException e) {
        if (e.getMessage().contains("Port already in use")) {
            System.out.println("Port already in use. Trying to restart with a new one...");
            Thread.sleep(100);
            return null;
        } else {
            throw e;
        }
    }
    return registry;
}
 
Example 2
Project: Pogamut3   File: DefaultPogamutPlatform.java   View Source Code Vote up 6 votes
/**
 * Returns MBeans server for the Pogamut Platform. All MBeans connected from
 * the platform should be registered in this server. There is also default
 * RMI connector for this server running on service:jmx:rmi:///jndi/rmi://localhost:9999/server
 * @return
 * @throws cz.cuni.amis.utils.exception.PogamutException
 */
@Override
public synchronized MBeanServer getMBeanServer() throws PogamutException {
    try {
        if (!registryCreated) {
            if (log.isLoggable(Level.WARNING)) log.warning("Creating registry at " + getRMIPort() + " ...");
            LocateRegistry.createRegistry(getRMIPort());
            registryCreated = true;
        }
        if (mBeanServer == null) {
            if (log.isLoggable(Level.WARNING)) log.warning("Starting MBean server.");
            //start a RMI registry                
            mBeanServer = new PogamutMBeanServer();

            // also create connector for this server, server without connector
            // would be unreachable outside this JVM
            cs = JMXConnectorServerFactory.newJMXConnectorServer(getMBeanServerURL(), null, mBeanServer);
            cs.start();

        }
        return mBeanServer;
    } catch (Exception ex) {
        throw new PogamutException("Error during JMX initialization.", ex);
    }
}
 
Example 3
Project: jdk8u-jdk   File: AddrInUse.java   View Source Code Vote up 6 votes
public void run() {

        /*
         * Attempt to create (i.e. export) a registry on the port that
         * has already been bound, and record the result.
         */
        try {
            LocateRegistry.createRegistry(port);
            synchronized (this) {
                exportSucceeded = true;
                notifyAll();
            }
        } catch (Throwable t) {
            synchronized (this) {
                exportException = t;
                notifyAll();
            }
        }
    }
 
Example 4
Project: lams   File: RmiServiceExporter.java   View Source Code Vote up 6 votes
/**
 * Locate or create the RMI registry for this exporter.
 * @param registryPort the registry port to use
 * @return the RMI registry
 * @throws RemoteException if the registry couldn't be located or created
 */
protected Registry getRegistry(int registryPort) throws RemoteException {
	if (this.alwaysCreateRegistry) {
		logger.info("Creating new RMI registry");
		return LocateRegistry.createRegistry(registryPort);
	}
	if (logger.isInfoEnabled()) {
		logger.info("Looking for RMI registry at port '" + registryPort + "'");
	}
	synchronized (LocateRegistry.class) {
		try {
			// Retrieve existing registry.
			Registry reg = LocateRegistry.getRegistry(registryPort);
			testRegistry(reg);
			return reg;
		}
		catch (RemoteException ex) {
			logger.debug("RMI registry access threw exception", ex);
			logger.info("Could not detect RMI registry - creating new one");
			// Assume no registry found -> create new one.
			return LocateRegistry.createRegistry(registryPort);
		}
	}
}
 
Example 5
Project: otter-G   File: JmxConnectorServerFactoryBean.java   View Source Code Vote up 6 votes
private Registry getRegistry(int registryPort) throws RemoteException {
    if (this.alwaysCreateRegistry) {
        logger.info("Creating new RMI registry");
        return LocateRegistry.createRegistry(registryPort);
    }
    if (logger.isInfoEnabled()) {
        logger.info("Looking for RMI registry at port '" + registryPort + "'");
    }
    try {
        // Retrieve existing registry.
        Registry reg = LocateRegistry.getRegistry(registryPort);
        testRegistry(reg);
        return reg;
    } catch (RemoteException ex) {
        logger.debug("RMI registry access threw exception", ex);
        logger.info("Could not detect RMI registry - creating new one");
        // Assume no registry found -> create new one.
        return LocateRegistry.createRegistry(registryPort);
    }
}
 
Example 6
Project: Proyecto-DASI   File: ControlRMI.java   View Source Code Vote up 6 votes
public static boolean startRMI() {
    try {
        registroRMI = LocateRegistry.createRegistry(puertoRMI);
        System.err.println("Registro listo en " + puertoRMI);
  
        return true;
    } catch (Exception e) {
        System.err.println("No se ha podido crear el registro RMI");
        try {
            registroRMI = LocateRegistry.getRegistry(puertoRMI);
            System.err.println ("El registro ya existia (RMI listo)");
 
            return true;
        }
        catch (Exception ex) {
            System.err.println ("RMI no disponible!!\n" + ex.getMessage());
            return false;
        }
    }
}
 
Example 7
Project: DocIT   File: Server.java   View Source Code Vote up 5 votes
/**
 * Start the Server and wait for user termination by keyboard.
 * 
 * @param args
 *            This program does not accept command line parameters.
 */
public static void main(String args[]) {

	// Override the default security manager
	System.setSecurityManager(new SecurityManager());
	
	try {
		LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
	} catch (RemoteException remoteException) {
		remoteException.printStackTrace();
	}

	Server server = new Server();

	System.out.println("Server started.");
	System.out.println("Enter <CR> to end.");

	try {
		System.in.read(); // Wait for Enter ...
	} catch (IOException ioException) {
		ioException.printStackTrace();
	}

	try {
		Naming.unbind("//" + server.hostname + "/meganalysis");
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		System.exit(0);
	}
}
 
Example 8
Project: mage   File: MageServer.java   View Source Code Vote up 5 votes
private void init() {
    try {
        rmiRegistry = LocateRegistry.createRegistry(port);

        logger.info("mage server is running");

    } catch (RemoteException e) {

        logger.error("init mage server error");
        throw new RuntimeException(e);
    }
}
 
Example 9
Project: lams   File: RmiServiceExporter.java   View Source Code Vote up 5 votes
/**
 * Locate or create the RMI registry for this exporter.
 * @param registryPort the registry port to use
 * @param clientSocketFactory the RMI client socket factory for the registry (if any)
 * @param serverSocketFactory the RMI server socket factory for the registry (if any)
 * @return the RMI registry
 * @throws RemoteException if the registry couldn't be located or created
 */
protected Registry getRegistry(
		int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
		throws RemoteException {

	if (clientSocketFactory != null) {
		if (this.alwaysCreateRegistry) {
			logger.info("Creating new RMI registry");
			return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory);
		}
		if (logger.isInfoEnabled()) {
			logger.info("Looking for RMI registry at port '" + registryPort + "', using custom socket factory");
		}
		synchronized (LocateRegistry.class) {
			try {
				// Retrieve existing registry.
				Registry reg = LocateRegistry.getRegistry(null, registryPort, clientSocketFactory);
				testRegistry(reg);
				return reg;
			}
			catch (RemoteException ex) {
				logger.debug("RMI registry access threw exception", ex);
				logger.info("Could not detect RMI registry - creating new one");
				// Assume no registry found -> create new one.
				return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory);
			}
		}
	}

	else {
		return getRegistry(registryPort);
	}
}
 
Example 10
Project: openNaEF   File: RmiBinder.java   View Source Code Vote up 5 votes
private Registry getRegistry() throws RemoteException {
    Registry registry = LocateRegistry.getRegistry(this.registryPort);
    try {
        registry.list();
    } catch (RemoteException e) {
        registry = null;
    }
    if (registry == null) {
        registry = LocateRegistry.createRegistry(this.registryPort);
    }
    return registry;
}
 
Example 11
Project: jdk8u-jdk   File: Server.java   View Source Code Vote up 5 votes
public static String start() throws Exception {
    int serverPort = 12345;
    ObjectName name = new ObjectName("test", "foo", "bar");
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    SteMBean bean = new Ste();
    jmxServer.registerMBean(bean, name);
    boolean exported = false;
    Random rnd = new Random(System.currentTimeMillis());
    do {
        try {
            LocateRegistry.createRegistry(serverPort);
            exported = true;
        } catch (ExportException ee) {
            if (ee.getCause() instanceof BindException) {
                serverPort = rnd.nextInt(10000) + 4096;
            } else {
                throw ee;
            }
        }

    } while (!exported);
    JMXServiceURL serverUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + serverPort + "/test");
    JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serverUrl, null, jmxServer);
    jmxConnector.start();

    return serverUrl.toString();
}
 
Example 12
Project: openjdk-jdk10   File: Server.java   View Source Code Vote up 5 votes
public static String start() throws Exception {
    int serverPort = 12345;
    ObjectName name = new ObjectName("test", "foo", "bar");
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    SteMBean bean = new Ste();
    jmxServer.registerMBean(bean, name);
    boolean exported = false;
    Random rnd = new Random(System.currentTimeMillis());
    do {
        try {
            LocateRegistry.createRegistry(serverPort);
            exported = true;
        } catch (ExportException ee) {
            if (ee.getCause() instanceof BindException) {
                serverPort = rnd.nextInt(10000) + 4096;
            } else {
                throw ee;
            }
        }

    } while (!exported);
    JMXServiceURL serverUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + serverPort + "/test");
    JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serverUrl, null, jmxServer);
    jmxConnector.start();

    return serverUrl.toString();
}
 
Example 13
Project: Proyecto-DASI   File: AdaptadorRegRMI.java   View Source Code Vote up 5 votes
public static Registry getRegistroRMInodoLocal (){

   // Si no existe se crea el registro en el nodo local y en el puerto por defecto
       if (registroRMILocalCreado ) return registroRMILocal ;

         try {
 //          hostRMI =  getIPLocal();
             inicializar();
             hostRMI = InetAddress.getLocalHost().getHostName();
//             hostRMI = InetAddress.getByName("SERTORIUS").toString();
             puertoRMIOrganizacionconfigurado = configuracionOrganizacion.getPropiedadesGlobales().getProperty("PuertoRMI_Org");
             if (puertoRMIOrganizacionconfigurado != null)puertoRMI = Integer.parseInt (puertoRMIOrganizacionconfigurado);
             registroRMILocal = LocateRegistry.createRegistry(puertoRMI);
             registroRMILocalCreado = true;
            return registroRMILocal;

            } catch (Exception e) {

                logger.error("Error al localizar el registro RMI  en el nodo--: "+ hostRMI + " Es posible que no se haya creado: Revisar la descripcion de la organizacion" );
                trazas.aceptaNuevaTraza(new InfoTraza("AdaptadorRegRMI",
						"Error al localizar el registro RMI :  "+ hostRMI + "-- Es posible que no se haya creado: Revisar la descripcion de la organizacion" ,
						InfoTraza.NivelTraza.error));
//
                return null;
            }

    }
 
Example 14
Project: Progetto-M   File: RMIDatabaseServer.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
   /*
    MarioNOTE:
    creating a connection to the database
    */
   DatabaseConnection connection = new DatabaseConnection("java", "password");
   
   try{
       int port = 1099;
       /*
       MarioNOTE:
       creating a Registry that allows the server to
       publish a service and client to retrieve the proxy
       */
       Registry registry = LocateRegistry.createRegistry(port);
       DatabaseGestion DBGestor = new DatabaseGestion();
       registry.rebind("MyDatabase", DBGestor);
       
       System.out.println("\nServer is ready...");
       
   }catch(RemoteException ex){
       System.out.println("\nRMIDatabaseServer ERROR: " + ex);
   }
}
 
Example 15
Project: monarch   File: RMIRegistryService.java   View Source Code Vote up 5 votes
/**
 * Starts this MBean: rmiregistry can now accept incoming calls
 * 
 * @see #stop
 * @see #isRunning
 */
public synchronized void start() throws RemoteException {
  if (!isRunning()) {
    if (ssf != null) {
      registry = LocateRegistry.createRegistry(port, null, // RMIClientSocketFactory
          ssf); // RMIServerSocketFactory
    } else {
      registry = LocateRegistry.createRegistry(port);
    }

    isRunning = true;
  }
}
 
Example 16
Project: monarch   File: ReadOpFileAccessControllerJUnitTest.java   View Source Code Vote up 5 votes
private void createConnector(String accessFileName, String pwFile) throws IOException {
  registry = LocateRegistry.createRegistry(port);
  MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
  String serviceUrl = SERVICE_URLPREFIX + "//" + hostname + ":" + port + "/jmxconnector";
  System.out.println("Server service url " + serviceUrl);
  final JMXServiceURL jmxServiceUrl = new JMXServiceURL(serviceUrl);

  final HashMap<String, Object> env = new HashMap<String, Object>();
  env.put("jmx.remote.x.password.file", pwFile);

  ReadOpFileAccessController controller = new ReadOpFileAccessController(accessFileName);
  controller.setMBeanServer(mbs);
  rmiConnector = JMXConnectorServerFactory.newJMXConnectorServer(jmxServiceUrl, env, controller);
  rmiConnector.start();
}
 
Example 17
Project: openjdk-jdk10   File: MapNullValuesTest.java   View Source Code Vote up 4 votes
public static void main(String[] args) throws Exception {

        int errorCount = 0;

        MapNullValuesTest test = new MapNullValuesTest();

        // Create an RMI registry
        //
        echo("");
        echo(dashedMessage("Start RMI registry"));
        Registry reg = null;
        port = 7500;
        while (port++ < 7550) {
            try {
                reg = LocateRegistry.createRegistry(port);
                echo("\nRMI registry running on port " + port);
                break;
            } catch (RemoteException e) {
                // Failed to create RMI registry...
                //
                echo("\nFailed to create RMI registry on port " + port);
                e.printStackTrace(System.out);
            }
        }
        if (reg == null) {
            System.exit(1);
        }

        // Run tests
        //
        errorCount += test.mapToHashtableTests();
        errorCount += test.jmxConnectorServerFactoryTests();
        errorCount += test.jmxConnectorFactoryTests();
        errorCount += test.nullKeyFactoryTests();

        if (errorCount == 0) {
            echo("\nNull values for key/value pairs in Map Tests PASSED!");
        } else {
            echo("\nNull values for key/value pairs in Map Tests FAILED!");
            System.exit(1);
        }
    }
 
Example 18
Project: ysoserial-plus   File: RMIRegistryExploitTest.java   View Source Code Vote up 4 votes
public static void createRegistry(int port) throws RemoteException {
	Registry registry = LocateRegistry.createRegistry(port);
}
 
Example 19
Project: jdk8u-jdk   File: TestLibrary.java   View Source Code Vote up 2 votes
/**
 * Creates an RMI {@link Registry} on an ephemeral port.
 *
 * @returns an RMI Registry
 * @throws RemoteException if there was a problem creating a Registry.
 */
public static Registry createRegistryOnEphemeralPort() throws RemoteException {
    return LocateRegistry.createRegistry(0);
}
 
Example 20
Project: openjdk-jdk10   File: TestLibrary.java   View Source Code Vote up 2 votes
/**
 * Creates an RMI {@link Registry} on an ephemeral port.
 *
 * @returns an RMI Registry
 * @throws RemoteException if there was a problem creating a Registry.
 */
public static Registry createRegistryOnEphemeralPort() throws RemoteException {
    return LocateRegistry.createRegistry(0);
}