Package java.rmi.registry

Examples of java.rmi.registry.Registry


         */
    }

    public void registerService(String serviceName, int port, Remote serviceObject) throws RMIHostException,
        RMIHostRuntimeException {
        Registry registry;
        try {
            registry = rmiRegistries.get(Integer.toString(port));
            if (registry == null) {
                try {
                    registry = LocateRegistry.getRegistry(port);
                    registry.list();
                } catch (RemoteException e) {
                    registry = LocateRegistry.createRegistry(port);
                }
                rmiRegistries.put(Integer.toString(port), registry);
            }
            registry.bind(serviceName, serviceObject);
        } catch (AlreadyBoundException e) {
            throw new RMIHostException(e);
        } catch (RemoteException e) {
            RMIHostRuntimeException rmiExec = new RMIHostRuntimeException(e.getMessage());
            rmiExec.setStackTrace(e.getStackTrace());
View Full Code Here


        RMIHostRuntimeException {
        registerService(serviceName, RMI_DEFAULT_PORT, serviceObject);
    }

    public void unregisterService(String serviceName, int port) throws RMIHostException, RMIHostRuntimeException {
        Registry registry;

        try {
            registry = rmiRegistries.get(Integer.toString(port));
            if (registry == null) {
                registry = LocateRegistry.getRegistry(port);
                rmiRegistries.put(Integer.toString(port), registry);
            }
            registry.unbind(serviceName);
        } catch (RemoteException e) {
            RMIHostRuntimeException rmiExec = new RMIHostRuntimeException(e.getMessage());
            rmiExec.setStackTrace(e.getStackTrace());
            throw rmiExec;
        } catch (NotBoundException e) {
View Full Code Here

    }

    public Remote findService(String host, String port, String svcName) throws RMIHostException,
        RMIHostRuntimeException {
        Registry registry;
        Remote remoteService = null;
        host = (host == null || host.length() <= 0) ? "localhost" : host;
        int portNumber = (port == null || port.length() <= 0) ? RMI_DEFAULT_PORT : Integer.decode(port);

        try {
            registry = LocateRegistry.getRegistry(host, portNumber);

            if (registry != null) {
                remoteService = registry.lookup(svcName);
            }
        } catch (RemoteException e) {
            RMIHostRuntimeException rmiExec = new RMIHostRuntimeException(e.getMessage());
            rmiExec.setStackTrace(e.getStackTrace());
            throw rmiExec;
View Full Code Here

        endpoint.getRemoteInterfaces().toArray(interfaces);
        proxy = (Remote)Proxy.newProxyInstance(endpoint.getClassLoader(), interfaces, this);
        stub = UnicastRemoteObject.exportObject(proxy, endpoint.getPort());

        try {
            Registry registry = endpoint.getRegistry();
            String name = endpoint.getName();
            registry.bind(name, stub);

        } catch (Exception e) {
            // Registration might fail.. clean up..
            try {
                UnicastRemoteObject.unexportObject(stub, true);
View Full Code Here

    @Override
    protected void doStop() throws Exception {
        super.doStop();
        try {
            Registry registry = endpoint.getRegistry();
            registry.unbind(endpoint.getName());
        } catch (Throwable e) {
            // do our best to unregister
        }
        UnicastRemoteObject.unexportObject(proxy, true);
    }
View Full Code Here

                throw new ConfigurationException("Please check your RMI Registry settings!!!");
            }
        } else {
            // check if the specified rmi registry is running!
            try {
                Registry registry = LocateRegistry.getRegistry(this.rmiRegistryHost, this.rmiRegistryPort);
            } catch (RemoteException re) {
                getLogger().error("Couldn't find RMI Registry [" + this.rmiRegistryHost + ":" +
                                  this.rmiRegistryPort);
                throw new ConfigurationException("Please check your RMI Registry settings!!!");
            }
View Full Code Here

        return(mbeanServer);
    }

    private void startRMIRegistry() throws BrokerException {
  String regPortStr = null;
  Registry registry = null;
  boolean registryExists = false;
  int port;

  if (!startRmiRegistry())  {
      return;
  }

        port = getRmiRegistryPort();

  String jmxHostname = Globals.getJMXHostname();

  try  {
      if (jmxHostname != null && !jmxHostname.equals(Globals.HOSTNAME_ALL))  {
          registry = LocateRegistry.getRegistry(jmxHostname, port);
      } else  {
          registry = LocateRegistry.getRegistry(port);
      }

      /*
       * Call list() to force a remote call - this
       * confirms if the registry is up and running
       */
      String s[] = registry.list();
      registryExists = true;
  } catch(RemoteException re)  {
      /*
       * An exception will be caught if there is no registry running
       * at the specified port. Not a problem since we are about
       * to create a registry.
       */
  }

  if (registryExists)  {
      throw new BrokerException(rb.getString(rb.W_JMX_RMI_REGISTRY_EXISTS,
            Integer.toString(port)));
  }

  try  {
      if (jmxHostname != null && !jmxHostname.equals(Globals.HOSTNAME_ALL))  {
          MQRMIServerSocketFactory ssf =
        new MQRMIServerSocketFactory(jmxHostname, 0, false);

          registry = LocateRegistry.createRegistry(port, null, ssf);
      } else  {
          registry = LocateRegistry.createRegistry(port);
      }

      /*
       * Call list() to force a remote call - this
       * confirms if the registry is up and running
       */
      String s[] = registry.list();
            logger.log(Logger.INFO,
    rb.getString(rb.I_JMX_RMI_REGISTRY_STARTED, Integer.toString(port)));
  } catch(RemoteException re)  {
      throw new BrokerException(
    rb.getString(rb.W_JMX_RMI_REGISTRY_STARTED_EXCEPTION,
View Full Code Here

        MBeanServer mBeanServer = null;



        Registry reg=null;

       

        // TODO: use config to get the registry port, url, pass, user
View Full Code Here

      try
      {
         int serverId = getServerPeer(target).getServerPeerID();

         //First unregister from the RMI registry
         Registry registry = LocateRegistry.getRegistry(RMITestServer.DEFAULT_REGISTRY_PORT);

         String name = RMITestServer.RMI_SERVER_PREFIX + serverId;
         registry.unbind(name);
         log.info("unregistered " + name + " from registry");

         name = RMITestServer.NAMING_SERVER_PREFIX + serverId;
         registry.unbind(name);
         log.info("unregistered " + name + " from registry");

         log.info("#####");
         log.info("#####");
         log.info("##### Halting the server!");
View Full Code Here

      log.debug("RMI server " + serverIndex + " created");

      // let RMI know the bind address
      System.setProperty("java.rmi.server.hostname", host);

      Registry registry;

      // try to bind first
      try
      {
         registry = LocateRegistry.getRegistry(DEFAULT_REGISTRY_PORT);
         registry.bind(RMI_SERVER_PREFIX + serverIndex, testServer);
         registry.bind(NAMING_SERVER_PREFIX + serverIndex, testServer.getNamingDelegate());
      }
      catch(Exception e)
      {
         log.info("Failure using an existing registry, trying creating it");

         // try to create it
         registry = LocateRegistry.createRegistry(DEFAULT_REGISTRY_PORT);

         registry.bind(RMI_SERVER_PREFIX + serverIndex, testServer);
         registry.bind(NAMING_SERVER_PREFIX + serverIndex, testServer.getNamingDelegate());
      }

      log.info("RMI server " + serverIndex + " bound");    
   }
View Full Code Here

TOP

Related Classes of java.rmi.registry.Registry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.