Example #1
0
  @Override
  public synchronized void initializePlugins() {
    if (_initialized) {
      InitializationException ex = new InitializationException();
      ex.reason = "plug-ins already initialized";
      throw ex;
    }

    //
    // Invoke initialize() on the plug-ins, in the order they were loaded.
    //
    java.util.List<Plugin> initializedPlugins = new java.util.ArrayList<>();
    try {
      for (PluginInfo p : _plugins) {
        try {
          p.plugin.initialize();
        } catch (PluginInitializationException ex) {
          throw ex;
        } catch (RuntimeException ex) {
          PluginInitializationException e = new PluginInitializationException();
          e.reason = "plugin `" + p.name + "' initialization failed";
          e.initCause(ex);
          throw e;
        }
        initializedPlugins.add(p.plugin);
      }
    } catch (RuntimeException ex) {
      //
      // Destroy the plug-ins that have been successfully initialized, in the
      // reverse order.
      //
      java.util.ListIterator<Plugin> i = initializedPlugins.listIterator(initializedPlugins.size());
      while (i.hasPrevious()) {
        Plugin p = i.previous();
        try {
          p.destroy();
        } catch (RuntimeException e) {
          // Ignore.
        }
      }
      throw ex;
    }

    _initialized = true;
  }
Example #2
0
  //
  // Only for use by IceInternal.ObjectAdapterFactory
  //
  public ObjectAdapterI(
      IceInternal.Instance instance,
      Communicator communicator,
      IceInternal.ObjectAdapterFactory objectAdapterFactory,
      String name,
      RouterPrx router,
      boolean noConfig) {
    _instance = instance;
    _communicator = communicator;
    _objectAdapterFactory = objectAdapterFactory;
    _servantManager = new IceInternal.ServantManager(instance, name);
    _name = name;
    _directCount = 0;
    _noConfig = noConfig;

    if (_noConfig) {
      _id = "";
      _replicaGroupId = "";
      _reference = _instance.referenceFactory().create("dummy -t", "");
      _acm = _instance.serverACM();
      _messageSizeMax = _instance.messageSizeMax();
      return;
    }

    final Properties properties = _instance.initializationData().properties;
    List<String> unknownProps = new ArrayList<String>();
    boolean noProps = filterProperties(unknownProps);

    //
    // Warn about unknown object adapter properties.
    //
    if (unknownProps.size() != 0
        && properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) {
      StringBuffer message = new StringBuffer("found unknown properties for object adapter `");
      message.append(_name);
      message.append("':");
      for (String p : unknownProps) {
        message.append("\n    ");
        message.append(p);
      }
      _instance.initializationData().logger.warning(message.toString());
    }

    //
    // Make sure named adapter has some configuration.
    //
    if (router == null && noProps) {
      //
      // These need to be set to prevent finalizer from complaining.
      //
      _state = StateDestroyed;
      _instance = null;
      _incomingConnectionFactories = null;

      InitializationException ex = new InitializationException();
      ex.reason = "object adapter `" + _name + "' requires configuration";
      throw ex;
    }

    _id = properties.getProperty(_name + ".AdapterId");
    _replicaGroupId = properties.getProperty(_name + ".ReplicaGroupId");

    //
    // Setup a reference to be used to get the default proxy options
    // when creating new proxies. By default, create twoway proxies.
    //
    String proxyOptions = properties.getPropertyWithDefault(_name + ".ProxyOptions", "-t");
    try {
      _reference = _instance.referenceFactory().create("dummy " + proxyOptions, "");
    } catch (ProxyParseException e) {
      InitializationException ex = new InitializationException();
      ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'";
      throw ex;
    }

    _acm =
        new IceInternal.ACMConfig(
            properties, communicator.getLogger(), _name + ".ACM", instance.serverACM());

    {
      final int defaultMessageSizeMax = instance.messageSizeMax() / 1024;
      int num =
          properties.getPropertyAsIntWithDefault(_name + ".MessageSizeMax", defaultMessageSizeMax);
      if (num < 1 || num > 0x7fffffff / 1024) {
        _messageSizeMax = 0x7fffffff;
      } else {
        _messageSizeMax = num * 1024; // Property is in kilobytes, _messageSizeMax in bytes
      }
    }

    try {
      int threadPoolSize = properties.getPropertyAsInt(_name + ".ThreadPool.Size");
      int threadPoolSizeMax = properties.getPropertyAsInt(_name + ".ThreadPool.SizeMax");

      //
      // Create the per-adapter thread pool, if necessary.
      //
      if (threadPoolSize > 0 || threadPoolSizeMax > 0) {
        _threadPool = new IceInternal.ThreadPool(_instance, _name + ".ThreadPool", 0);
      }

      if (router == null) {
        router =
            RouterPrxHelper.uncheckedCast(
                _instance.proxyFactory().propertyToProxy(name + ".Router"));
      }
      if (router != null) {
        _routerInfo = _instance.routerManager().get(router);
        if (_routerInfo != null) {
          //
          // Make sure this router is not already registered with another adapter.
          //
          if (_routerInfo.getAdapter() != null) {
            throw new AlreadyRegisteredException(
                "object adapter with router", _instance.identityToString(router.ice_getIdentity()));
          }

          //
          // Add the router's server proxy endpoints to this object
          // adapter.
          //
          IceInternal.EndpointI[] endpoints = _routerInfo.getServerEndpoints();
          for (IceInternal.EndpointI endpoint : endpoints) {
            _routerEndpoints.add(endpoint);
          }
          java.util.Collections.sort(_routerEndpoints); // Must be sorted.

          //
          // Remove duplicate endpoints, so we have a list of unique
          // endpoints.
          //
          for (int i = 0; i < _routerEndpoints.size() - 1; ) {
            IceInternal.EndpointI e1 = _routerEndpoints.get(i);
            IceInternal.EndpointI e2 = _routerEndpoints.get(i + 1);
            if (e1.equals(e2)) {
              _routerEndpoints.remove(i);
            } else {
              ++i;
            }
          }

          //
          // Associate this object adapter with the router. This way,
          // new outgoing connections to the router's client proxy will
          // use this object adapter for callbacks.
          //
          _routerInfo.setAdapter(this);

          //
          // Also modify all existing outgoing connections to the
          // router's client proxy to use this object adapter for
          // callbacks.
          //
          _instance.outgoingConnectionFactory().setRouterInfo(_routerInfo);
        }
      } else {
        //
        // Parse the endpoints, but don't store them in the adapter. The connection
        // factory might change it, for example, to fill in the real port number.
        //
        List<IceInternal.EndpointI> endpoints =
            parseEndpoints(properties.getProperty(_name + ".Endpoints"), true);
        for (IceInternal.EndpointI endp : endpoints) {
          IncomingConnectionFactory factory =
              new IncomingConnectionFactory(instance, endp, this, _name);
          _incomingConnectionFactories.add(factory);
        }
        if (endpoints.size() == 0) {
          IceInternal.TraceLevels tl = _instance.traceLevels();
          if (tl.network >= 2) {
            _instance
                .initializationData()
                .logger
                .trace(tl.networkCat, "created adapter `" + name + "' without endpoints");
          }
        }

        //
        // Parse the publsihed endpoints.
        //
        _publishedEndpoints = parsePublishedEndpoints();
      }

      if (properties.getProperty(_name + ".Locator").length() > 0) {
        setLocator(
            LocatorPrxHelper.uncheckedCast(
                _instance.proxyFactory().propertyToProxy(_name + ".Locator")));
      } else {
        setLocator(_instance.referenceFactory().getDefaultLocator());
      }
    } catch (LocalException ex) {
      destroy();
      throw ex;
    }
  }