Ejemplo n.º 1
0
  void register(String hostName, final int rmiPort, final int serverPort) {

    try {
      final ManagementImpl impl = (ManagementImpl) _persistit.getManagement();
      if (hostName == null && rmiPort != -1) {
        try {
          if (hostName == null) {
            final InetAddress addr = InetAddress.getLocalHost();
            try {
              hostName = addr.getHostName() + ":" + rmiPort;
            } catch (final Exception e) {
              hostName = addr.getHostAddress() + ":" + rmiPort;
            }
          }
        } catch (final NumberFormatException nfe) {
        }
      }
      if (rmiPort != -1 && _localRegistryPort != rmiPort) {
        LocateRegistry.createRegistry(rmiPort);
        _localRegistryPort = rmiPort;
      }

      if (hostName != null && hostName.length() > 0) {
        final String name = "//" + hostName + "/PersistitManagementServer";
        UnicastRemoteObject.exportObject(impl, serverPort);
        Naming.rebind(name, impl);
        impl._registered = true;
        impl._registeredHostName = hostName;
        _persistit.getLogBase().rmiServerRegistered.log(hostName);
      }
    } catch (final Exception exception) {
      _persistit.getLogBase().rmiRegisterException.log(hostName, exception);
    }
  }
Ejemplo n.º 2
0
  void unregister() {
    if (_registered) {
      try {
        final ManagementImpl impl = (ManagementImpl) _persistit.getManagement();

        UnicastRemoteObject.unexportObject(impl, true);
        _registered = false;
        _persistit.getLogBase().rmiServerUnregister.log(_registeredHostName);
      } catch (final Exception exception) {
        _persistit.getLogBase().rmiUnregisterException.log(_registeredHostName, exception);
      }
    }
  }