Esempio n. 1
0
  private List<IceInternal.EndpointI> parsePublishedEndpoints() {
    //
    // Parse published endpoints. If set, these are used in proxies
    // instead of the connection factory Endpoints.
    //
    String endpts =
        _instance.initializationData().properties.getProperty(_name + ".PublishedEndpoints");
    List<IceInternal.EndpointI> endpoints = parseEndpoints(endpts, false);
    if (endpoints.isEmpty()) {
      //
      // If the PublishedEndpoints property isn't set, we compute the published enpdoints
      // from the OA endpoints, expanding any endpoints that may be listening on INADDR_ANY
      // to include actual addresses in the published endpoints.
      //
      for (IncomingConnectionFactory factory : _incomingConnectionFactories) {
        endpoints.addAll(factory.endpoint().expand());
      }
    }

    if (_instance.traceLevels().network >= 1 && !endpoints.isEmpty()) {
      StringBuffer s = new StringBuffer("published endpoints for object adapter `");
      s.append(_name);
      s.append("':\n");
      boolean first = true;
      for (IceInternal.EndpointI endpoint : endpoints) {
        if (!first) {
          s.append(":");
        }
        s.append(endpoint.toString());
        first = false;
      }
      _instance.initializationData().logger.trace(_instance.traceLevels().networkCat, s.toString());
    }
    return endpoints;
  }
Esempio n. 2
0
  @Override
  public int compareTo(IceInternal.EndpointI obj) // From java.lang.Comparable
      {
    EndpointI p = null;

    try {
      p = (EndpointI) obj;
    } catch (ClassCastException ex) {
      return type() < obj.type() ? -1 : 1;
    }

    if (this == p) {
      return 0;
    }

    return _endpoint.compareTo(p._endpoint);
  }
Esempio n. 3
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;
    }
  }
Esempio n. 4
0
  public boolean isLocal(ObjectPrx proxy) {
    //
    // NOTE: it's important that isLocal() doesn't perform any blocking operations as
    // it can be called for AMI invocations if the proxy has no delegate set yet.
    //

    IceInternal.Reference ref = ((ObjectPrxHelperBase) proxy).__reference();
    if (ref.isWellKnown()) {
      //
      // Check the active servant map to see if the well-known
      // proxy is for a local object.
      //
      return _servantManager.hasServant(ref.getIdentity());
    } else if (ref.isIndirect()) {
      //
      // Proxy is local if the reference adapter id matches this
      // adapter id or replica group id.
      //
      return ref.getAdapterId().equals(_id) || ref.getAdapterId().equals(_replicaGroupId);
    } else {
      IceInternal.EndpointI[] endpoints = ref.getEndpoints();

      synchronized (this) {
        checkForDeactivation();

        //
        // Proxies which have at least one endpoint in common with the
        // endpoints used by this object adapter's incoming connection
        // factories are considered local.
        //
        for (IceInternal.EndpointI endpoint : endpoints) {
          for (IceInternal.EndpointI p : _publishedEndpoints) {
            if (endpoint.equivalent(p)) {
              return true;
            }
          }
          for (IncomingConnectionFactory p : _incomingConnectionFactories) {
            if (endpoint.equivalent(p.endpoint())) {
              return true;
            }
          }
        }

        //
        // Proxies which have at least one endpoint in common with the
        // router's server proxy endpoints (if any), are also considered
        // local.
        //
        if (_routerInfo != null && _routerInfo.getRouter().equals(proxy.ice_getRouter())) {
          for (IceInternal.EndpointI endpoint : endpoints) {
            for (IceInternal.EndpointI p : _routerEndpoints) {
              if (endpoint.equivalent(p)) {
                return true;
              }
            }
          }
        }
      }
    }

    return false;
  }