Example usage for java.rmi Naming rebind

List of usage examples for java.rmi Naming rebind

Introduction

In this page you can find the example usage for java.rmi Naming rebind.

Prototype

public static void rebind(String name, Remote obj) throws RemoteException, java.net.MalformedURLException 

Source Link

Document

Rebinds the specified name to a new remote object.

Usage

From source file:com.vmware.identity.idm.server.IdmServer.java

/**
 * Initialize the IDM service./*from  w ww.  j  a  v a  2 s . c  o m*/
 *
 * @throws Exception when something goes wrong with initialization.
 */
private static void initialize() throws Exception {
    try (IDiagnosticsContextScope diagCtxt = DiagnosticsContextFactory.createContext("IDM Startup", "")) {
        logger.info("Starting IDM Server...");
        logger.debug("Creating RMI registry on port {}", Tenant.RMI_PORT);

        boolean allowRemoteConnections = Boolean
                .parseBoolean(System.getProperty(ALLOW_REMOTE_PROPERTY, "false"));

        if (allowRemoteConnections) {
            logger.warn("RMI registry is allowing remote connections!");
            registry = LocateRegistry.createRegistry(Tenant.RMI_PORT);
        } else {
            logger.debug("RMI registry is restricted to the localhost");
            RMIClientSocketFactory csf = RMISocketFactory.getDefaultSocketFactory();
            RMIServerSocketFactory ssf = new LocalRMIServerSocketFactory();
            registry = LocateRegistry.createRegistry(Tenant.RMI_PORT, csf, ssf);
        }

        // Assign a security manager, in the event that dynamic classes are loaded
        if (System.getSecurityManager() == null) {
            logger.debug("Creating RMI Security Manager...");
            System.setSecurityManager(new RMISecurityManager());
        }

        logger.debug("Creating Config Store factory...");
        IConfigStoreFactory cfgStoreFactory = new ConfigStoreFactory();

        logger.debug("Creating Identity Provider factory...");
        IProviderFactory providerFactory = new ProviderFactory();

        logger.debug("Checking VMware Directory Service...");
        ServerUtils.check_directory_service();

        logger.debug("Setting system properties...");
        System.setProperties(new ThreadLocalProperties(System.getProperties()));

        logger.debug("Creating Identity Manager instance...");
        manager = new IdentityManager(cfgStoreFactory, providerFactory);

        String rmiAddress = String.format("rmi://localhost:%d/%s", Tenant.RMI_PORT, IDENTITY_MANAGER_BIND_NAME);
        logger.debug("Binding to RMI address '{}'", rmiAddress);
        loginManager = new IdmLoginManager(manager);
        ILoginManager stub = (ILoginManager) UnicastRemoteObject.exportObject(loginManager, 0);
        Naming.rebind(rmiAddress, stub);

        startHeartbeat();

        logger.info(VmEvent.SERVER_STARTED, "IDM Server has started");
    } catch (Throwable t) {
        logger.error(VmEvent.SERVER_FAILED_TOSTART, "IDM Server has failed to start", t);
        throw t;
    }
}

From source file:net.sf.ehcache.distribution.RMICacheManagerPeerListener.java

/**
 * Bind a cache peer//from  w w w  . j  a  v  a 2  s  . c  om
 *
 * @param rmiCachePeer
 */
protected void bind(String peerName, RMICachePeer rmiCachePeer) throws Exception {
    Naming.rebind(peerName, rmiCachePeer);
}

From source file:edu.clemson.cs.nestbed.server.Server.java

private final void bindRemoteObjects() throws RemoteException, MalformedURLException {

    Naming.rebind(RMI_BASE_URL + "TestbedManager", testbedManger);
    log.debug("TestbedManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "MoteTestbedAssignmentManager", moteTbAssignManager);
    log.debug("MoteTestbedAssignmentManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "MoteManager", moteManager);
    log.debug("MoteManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "MoteTypeManager", moteTypeManager);
    log.debug("MoteTypeManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "ProjectManager", projectManager);
    log.debug("ProjectManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "ProjectDeploymentConfigurationManager", projDepConfigManager);
    log.debug("ProjectDeploymentConfigurationManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "MoteDeploymentConfigurationManager", moteDepConfigManager);
    log.debug("MoteDeploymentConfigurationManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "ProgramManager", programManager);
    log.debug("ProgramManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "ProgramProfilingSymbolManager", progProfSymbolManager);
    log.debug("ProgramProfilingSymbolManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "ProgramSymbolManager", programSymbolManager);
    log.debug("ProgramSymbolManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "ProgramMessageSymbolManager", progMsgSymbolManager);
    log.debug("ProgramMessageSymbolManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "ProgramProfilingMessageSymbolManager", progProfMsgSymbolMgnr);
    log.debug("ProgramProfilingMessageSymbolManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "MessageManager", messageManager);
    log.debug("MessageManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "ProgramDeploymentManager", programDeploymentManager);
    log.debug("ProgramDeploymentManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "ProgramCompileManager", programCompileManager);
    log.debug("ProgramCompileManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "ProgramWeaverManager", programWeaverManager);
    log.debug("ProgramCompileManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "ProgramProbeManager", programProbeManager);
    log.debug("ProgramProbeManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "NucleusManager", nucleusManager);
    log.debug("NucleusManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "SerialForwarderManager", sfManager);
    log.debug("SerialForwarderManager successfully bound.");

    Naming.rebind(RMI_BASE_URL + "MotePowerManager", motePowerManager);
    log.debug("MotePowerManager successfully bound.");
}

From source file:je3.rmi.MudClient.java

/**
 * This main() method defines the standalone program that starts up a MUD
 * server.  If invoked with a single argument, it treats that argument as
 * the name of a file containing the serialized and compressed state of an
 * existing MUD, and recreates it.  Otherwise, it expects four command-line
 * arguments: the name of the MUD, the password, the name of the entrance
 * place for the MUD, and a description of that entrance place.
 * Besides creating the MudServer object, this program sets an appropriate
 * security manager, and uses the default rmiregistry to register the
 * the MudServer under its given name.// w ww  .  j ava 2  s  .  c  o m
 **/
public static void main(String[] args) {
    try {
        MudServer server;
        if (args.length == 1) {
            // Read the MUD state in from a file
            FileInputStream f = new FileInputStream(args[0]);
            ObjectInputStream in =
      new ObjectInputStream(new GZIPInputStream(f));
            server = (MudServer) in.readObject();
        }
        // Otherwise, create an initial MUD from scratch
        else server = new MudServer(args[0], args[1], args[2], args[3]);
       
        Naming.rebind(Mud.mudPrefix + server.mudname, server);
    }
    // Display an error message if anything goes wrong.
    catch (Exception e) {
        System.out.println(e);
        System.out.println("Usage: java MudServer <savefile>\n" +
            "   or: java MudServer <mudname> <password> " + 
            "<placename> <description>");
        System.exit(1);
    }
}

From source file:je3.rmi.MudClient.java

/**
 * This main() method is the standalone program that figures out what
 * database to connect to with what driver, connects to the database,
 * creates a PersistentBankServer object, and registers it with the registry,
 * making it available for client use/*  ww w .  j ava2  s . c  om*/
 **/
public static void main(String[] args) {
    try {
        // Create a new Properties object.  Attempt to initialize it from
        // the BankDB.props file or the file optionally specified on the 
        // command line, ignoring errors.
        Properties p = new Properties();
        try { p.load(new FileInputStream(args[0])); }
        catch (Exception e) {
            try { p.load(new FileInputStream("BankDB.props")); }
            catch (Exception e2) {}
        }
       
        // The BankDB.props file (or file specified on the command line)
        // must contain properties "driver" and "database", and may
        // optionally contain properties "user" and "password".
        String driver = p.getProperty("driver");
        String database = p.getProperty("database");
        String user = p.getProperty("user", "");
        String password = p.getProperty("password", "");
       
        // Load the database driver class
        Class.forName(driver);
       
        // Connect to the database that stores our accounts
        Connection db = DriverManager.getConnection(database,
                 user, password);
       
        // Configure the database to allow multiple queries and updates
        // to be grouped into atomic transactions
        db.setAutoCommit(false);
        db.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
       
        // Create a server object that uses our database connection
        PersistentBankServer bank = new PersistentBankServer(db);
       
        // Read a system property to figure out how to name this server.
        // Use "SecondRemote" as the default.
        String name = System.getProperty("bankname", "SecondRemote");
       
        // Register the server with the name
        Naming.rebind(name, bank);
       
        // And tell everyone that we're up and running.
        System.out.println(name + " is open and ready for customers.");
    }
    catch (Exception e) {
        System.err.println(e);
        if (e instanceof SQLException) 
            System.err.println("SQL State: " +
           ((SQLException)e).getSQLState());
        System.err.println("Usage: java [-Dbankname=<name>] " +
          "je3.rmi.PersistentBankServer " +
            "[<dbpropsfile>]");
        System.exit(1);
    }
}

From source file:je3.rmi.MudClient.java

/**
 * The main program that runs this RemoteBankServer.
 * Create a RemoteBankServer object and give it a name in the registry.
 * Read a system property to determine the name, but use "FirstRemote"
 * as the default name.  This is all that is necessary to set up the
 * service.  RMI takes care of the rest.
 **///from  ww w .  java  2s  . c om
public static void main(String[] args) {
    try {
        // Create a bank server object
        RemoteBankServer bank = new RemoteBankServer();
        // Figure out what to name it
        String name = System.getProperty("bankname", "FirstRemote");
        // Name it that
        Naming.rebind(name, bank);
        // Tell the world we're up and running
        System.out.println(name + " is open and ready for customers.");
    }
    catch (Exception e) {
        System.err.println(e);
        System.err.println("Usage: java [-Dbankname=<name>] " +
              "je3.rmi.RemoteBankServer");
        System.exit(1); // Force exit because there may be RMI threads
    }
}

From source file:net.sqs2.omr.app.MarkReaderControllerImpl.java

private void exportSessionService() {
    try {//w w  w.jav  a2  s  .c o  m
        SessionServiceImpl sessionService = SessionServiceImpl.getInstance();
        if (sessionService != null) {
            sessionService.close();
            Naming.rebind(MarkReaderConstants.SESSION_SERVICE_PATH, sessionService);
        }
    } catch (IOException ignore) {
    }
}

From source file:org.act.index.server.MetaService.java

@Override
public int createCore(int coreId) {
    // TODO Auto-generated method stub
    try {/*w w w .  j  a  v  a  2 s .co  m*/
        if (indexServer.getSolrServers().containsKey(coreId))
            return GlobalMessage.ISS_ERROR;
        String dir = indexServer.getUrl() + "/core" + String.valueOf(coreId);
        //LOG.debug("dir:" + dir);
        indexServer.addSolrServer(coreId);
        FileUtils.forceMkdir(new File(dir));
        FileUtils.forceMkdir(new File(dir + "/conf"));
        String configPath = dir + "/conf/solrconfig.xml";
        String schemaPath = dir + "/conf/schema.xml";
        createSolrConfig(configPath);
        createSchema(schemaPath, coreId);
        //indexServer.addSolrServer(coreId);
        //CoreAdminRequest.createCore(String.valueOf(coreId), "core"
        //      + String.valueOf(coreId), indexServer.getSolrServer());
        CoreAdminRequest.createCore(String.valueOf(coreId), "core" + String.valueOf(coreId),
                indexServer.getSolrServer());
        //CoreAdminRequest.createCore("10", "core10", server, configPath, schemaPath);
        FileUtils.forceMkdir(new File(dir + "/data"));
        FileUtils.forceMkdir(new File(dir + "/data/index"));
        SolrService service = new SolrService(indexServer.getSolrServer(coreId));
        //solrServices.put(coreId, service);
        //int port = ServerParam.LOCAL_SERVER_PORT + serverId * ServerParam.MAX_CORE_COUNT_PER_SERVER + coreId + 1;
        int serverId = indexServer.getServerInfo().getServerId();
        String ip = Inet4Address.getLocalHost().getHostAddress();
        int port = indexServer.getServerAddr().getPort() + coreId + 1;
        LocateRegistry.createRegistry(port);
        String name = "rmi://" + ip + ":" + port + "/core" + coreId + "@server" + serverId;
        Naming.rebind(name, service);
        LOG.info("rmi:solrserver( " + name + ") is ready!");
    } catch (SolrServerException e) {
        // TODO: handle exception
        e.printStackTrace();
    } catch (IOException e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    return GlobalMessage.ISS_SUCCESS;
}

From source file:org.act.index.server.MetaService.java

public int createCoreWithNoSegment(int coreId) {
    // TODO Auto-generated method stub
    try {//from  w w  w  . j  a v  a2 s  . com
        if (indexServer.getSolrServers().containsKey(coreId))
            return GlobalMessage.ISS_ERROR;
        String dir = indexServer.getUrl() + "/core" + String.valueOf(coreId);
        //LOG.debug("dir:" + dir);
        indexServer.addSolrServer(coreId);
        FileUtils.forceMkdir(new File(dir));
        FileUtils.forceMkdir(new File(dir + "/conf"));
        String configPath = dir + "/conf/solrconfig.xml";
        String schemaPath = dir + "/conf/schema.xml";
        createSolrConfig(configPath);
        createSchema(schemaPath, coreId);
        //indexServer.addSolrServer(coreId);
        //CoreAdminRequest.createCore(String.valueOf(coreId), "core"
        //      + String.valueOf(coreId), indexServer.getSolrServer());
        CoreAdminRequest.createCore(String.valueOf(coreId), "core" + String.valueOf(coreId),
                indexServer.getSolrServer());
        //CoreAdminRequest.createCore("10", "core10", server, configPath, schemaPath);
        //FileUtils.forceMkdir(new File(dir + "/data"));
        //FileUtils.forceMkdir(new File(dir + "/data/index"));
        FileUtils.cleanDirectory(new File(dir + "/data/index"));
        SolrService service = new SolrService(indexServer.getSolrServer(coreId));
        //solrServices.put(coreId, service);
        //int port = ServerParam.LOCAL_SERVER_PORT + serverId * ServerParam.MAX_CORE_COUNT_PER_SERVER + coreId + 1;
        int serverId = indexServer.getServerInfo().getServerId();
        String ip = Inet4Address.getLocalHost().getHostAddress();
        int port = indexServer.getServerAddr().getPort() + coreId + 1;
        LocateRegistry.createRegistry(port);
        String name = "rmi://" + ip + ":" + port + "/core" + coreId + "@server" + serverId;
        Naming.rebind(name, service);
        LOG.info("rmi:solrserver( " + name + ") is ready!");
    } catch (SolrServerException e) {
        // TODO: handle exception
        e.printStackTrace();
    } catch (IOException e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    return GlobalMessage.ISS_SUCCESS;
}

From source file:org.apache.jcs.auxiliary.remote.server.RemoteCacheServerFactory.java

/**
 * Starts up the remote cache server on this JVM, and binds it to the registry on the given host
 * and port.//w  w  w  .java  2 s.co m
 * A remote cache is either a local cache or a cluster cache
 * @param host
 * @param port
 * @param propFile
 * @throws IOException
 */
public static void startup(String host, int port, String propFile) throws IOException {
    if (remoteCacheServer != null) {
        throw new IllegalArgumentException("Server already started.");
    }

    synchronized (RemoteCacheServer.class) {
        if (remoteCacheServer != null) {
            return;
        }

        if (log.isInfoEnabled()) {
            log.info("ConfigFileName = [" + propFile + "]");
        }

        try {
            // TODO make configurable.
            // use this socket factory to add a timeout.
            RMISocketFactory.setSocketFactory(new RMISocketFactory() {
                public Socket createSocket(String host, int port) throws IOException {
                    Socket socket = new Socket(host, port);
                    socket.setSoTimeout(DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MS);
                    socket.setSoLinger(false, 0);
                    return socket;
                }

                public ServerSocket createServerSocket(int port) throws IOException {
                    return new ServerSocket(port);
                }
            });
        } catch (Exception e) {
            log.error("Problem setting custom RMI Socket Factory.", e);
        }

        // TODO: make automatic
        RemoteCacheServerAttributes rcsa = new RemoteCacheServerAttributes();
        rcsa.setConfigFileName(propFile);

        Properties prop = RemoteUtils.loadProps(propFile);
        // Properties prop = PropertyLoader.loadProperties( propFile );

        String servicePortStr = prop.getProperty(REMOTE_CACHE_SERVICE_PORT);
        int servicePort = -1;
        try {
            servicePort = Integer.parseInt(servicePortStr);

            rcsa.setServicePort(servicePort);
            log.debug("Remote cache service uses port number " + servicePort + ".");
        } catch (NumberFormatException ignore) {
            log.debug("Remote cache service port property " + REMOTE_CACHE_SERVICE_PORT
                    + " not specified.  An anonymous port will be used.");
        }

        String lccStr = prop.getProperty(REMOTE_LOCAL_CLUSTER_CONSISTENCY);
        if (lccStr == null) {
            lccStr = "true";
        }
        boolean lcc = Boolean.valueOf(lccStr).booleanValue();
        rcsa.setLocalClusterConsistency(lcc);

        String acgStr = prop.getProperty(REMOTE_ALLOW_CLUSTER_GET);
        if (acgStr == null) {
            acgStr = "true";
        }
        boolean acg = Boolean.valueOf(acgStr).booleanValue();
        rcsa.setAllowClusterGet(acg);

        if (log.isInfoEnabled()) {
            log.info("Creating server with these attributes " + rcsa);
        }

        // CREATE SERVER
        remoteCacheServer = new RemoteCacheServer(rcsa);

        if (host == null) {
            host = "";
        }
        // Register the RemoteCacheServer remote object in the registry.
        serviceName = prop.getProperty(REMOTE_CACHE_SERVICE_NAME, REMOTE_CACHE_SERVICE_VAL).trim();

        if (log.isInfoEnabled()) {
            log.info("Binding server to " + host + ":" + port + " with the name " + serviceName);
        }
        try {
            Naming.rebind("//" + host + ":" + port + "/" + serviceName, remoteCacheServer);
        } catch (MalformedURLException ex) {
            // impossible case.
            throw new IllegalArgumentException(ex.getMessage() + "; host=" + host + ", port=" + port);
        }
    }
}