Exemplo n.º 1
0
  public synchronized Ice.ObjectPrx createAdmin(
      Ice.ObjectAdapter adminAdapter, Ice.Identity adminIdentity) {
    if (Thread.interrupted()) {
      throw new Ice.OperationInterruptedException();
    }

    boolean createAdapter = (adminAdapter == null);

    synchronized (this) {
      if (_state == StateDestroyed) {
        throw new Ice.CommunicatorDestroyedException();
      }

      if (adminIdentity == null || adminIdentity.name == null || adminIdentity.name.isEmpty()) {
        throw new Ice.IllegalIdentityException(adminIdentity);
      }

      if (_adminAdapter != null) {
        throw new Ice.InitializationException("Admin already created");
      }

      if (!_adminEnabled) {
        throw new Ice.InitializationException("Admin is disabled");
      }

      if (createAdapter) {
        if (!_initData.properties.getProperty("Ice.Admin.Endpoints").isEmpty()) {
          adminAdapter = _objectAdapterFactory.createObjectAdapter("Ice.Admin", null);
        } else {
          throw new Ice.InitializationException("Ice.Admin.Endpoints is not set");
        }
      }

      _adminIdentity = adminIdentity;
      _adminAdapter = adminAdapter;
      addAllAdminFacets();
    }

    if (createAdapter) {
      try {
        adminAdapter.activate();
      } catch (Ice.LocalException ex) {
        //
        // We cleanup _adminAdapter, however this error is not recoverable
        // (can't call again getAdmin() after fixing the problem)
        // since all the facets (servants) in the adapter are lost
        //
        adminAdapter.destroy();
        synchronized (this) {
          _adminAdapter = null;
        }
        throw ex;
      }
    }
    setServerProcessProxy(adminAdapter, adminIdentity);
    return adminAdapter.createProxy(adminIdentity);
  }
Exemplo n.º 2
0
  public Ice.ObjectPrx getAdmin() {
    if (Thread.interrupted()) {
      throw new Ice.OperationInterruptedException();
    }

    Ice.ObjectAdapter adminAdapter;
    Ice.Identity adminIdentity;

    synchronized (this) {
      if (_state == StateDestroyed) {
        throw new Ice.CommunicatorDestroyedException();
      }

      if (_adminAdapter != null) {
        return _adminAdapter.createProxy(_adminIdentity);
      } else if (_adminEnabled) {
        if (!_initData.properties.getProperty("Ice.Admin.Endpoints").isEmpty()) {
          adminAdapter = _objectAdapterFactory.createObjectAdapter("Ice.Admin", null);
        } else {
          return null;
        }
        adminIdentity =
            new Ice.Identity("admin", _initData.properties.getProperty("Ice.Admin.InstanceName"));
        if (adminIdentity.category.isEmpty()) {
          adminIdentity.category = java.util.UUID.randomUUID().toString();
        }

        _adminIdentity = adminIdentity;
        _adminAdapter = adminAdapter;
        addAllAdminFacets();
        // continue below outside synchronization
      } else {
        return null;
      }
    }

    try {
      adminAdapter.activate();
    } catch (Ice.LocalException ex) {
      //
      // We cleanup _adminAdapter, however this error is not recoverable
      // (can't call again getAdmin() after fixing the problem)
      // since all the facets (servants) in the adapter are lost
      //
      adminAdapter.destroy();
      synchronized (this) {
        _adminAdapter = null;
      }
      throw ex;
    }

    setServerProcessProxy(adminAdapter, adminIdentity);
    return adminAdapter.createProxy(adminIdentity);
  }
Exemplo n.º 3
0
  private void setServerProcessProxy(Ice.ObjectAdapter adminAdapter, Ice.Identity adminIdentity) {
    Ice.ObjectPrx admin = adminAdapter.createProxy(adminIdentity);
    Ice.LocatorPrx locator = adminAdapter.getLocator();
    String serverId = _initData.properties.getProperty("Ice.Admin.ServerId");

    if (locator != null && !serverId.isEmpty()) {
      Ice.ProcessPrx process = Ice.ProcessPrxHelper.uncheckedCast(admin.ice_facet("Process"));
      try {
        //
        // Note that as soon as the process proxy is registered, the communicator might be
        // shutdown by a remote client and admin facets might start receiving calls.
        //
        locator.getRegistry().setServerProcessProxy(serverId, process);
      } catch (Ice.ServerNotFoundException ex) {
        if (_traceLevels.location >= 1) {
          StringBuilder s = new StringBuilder(128);
          s.append("couldn't register server `");
          s.append(serverId);
          s.append("' with the locator registry:\n");
          s.append("the server is not known to the locator registry");
          _initData.logger.trace(_traceLevels.locationCat, s.toString());
        }

        throw new Ice.InitializationException(
            "Locator knows nothing about server `" + serverId + "'");
      } catch (Ice.LocalException ex) {
        if (_traceLevels.location >= 1) {
          StringBuilder s = new StringBuilder(128);
          s.append("couldn't register server `");
          s.append(serverId);
          s.append("' with the locator registry:\n");
          s.append(ex.toString());
          _initData.logger.trace(_traceLevels.locationCat, s.toString());
        }
        throw ex;
      }

      if (_traceLevels.location >= 1) {
        StringBuilder s = new StringBuilder(128);
        s.append("registered server `");
        s.append(serverId);
        s.append("' with the locator registry");
        _initData.logger.trace(_traceLevels.locationCat, s.toString());
      }
    }
  }
Exemplo n.º 4
0
 private BookPrx isbnToBook(String isbn, Ice.ObjectAdapter adapter) {
   return BookPrxHelper.uncheckedCast(adapter.createProxy(createBookIdentity(isbn)));
 }