Exemple #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;
  }
Exemple #2
0
 @Override
 public synchronized Endpoint[] getEndpoints() {
   List<Endpoint> endpoints = new ArrayList<Endpoint>();
   for (IncomingConnectionFactory factory : _incomingConnectionFactories) {
     endpoints.add(factory.endpoint());
   }
   return endpoints.toArray(new Endpoint[0]);
 }
Exemple #3
0
 @Override
 public synchronized void hold() {
   checkForDeactivation();
   _state = StateHeld;
   for (IncomingConnectionFactory factory : _incomingConnectionFactories) {
     factory.hold();
   }
 }
Exemple #4
0
 public void updateConnectionObservers() {
   List<IncomingConnectionFactory> f;
   synchronized (this) {
     f = new ArrayList<IncomingConnectionFactory>(_incomingConnectionFactories);
   }
   for (IncomingConnectionFactory p : f) {
     p.updateConnectionObservers();
   }
 }
Exemple #5
0
 public void flushAsyncBatchRequests(IceInternal.CommunicatorFlushBatch outAsync) {
   List<IncomingConnectionFactory> f;
   synchronized (this) {
     f = new ArrayList<IncomingConnectionFactory>(_incomingConnectionFactories);
   }
   for (IncomingConnectionFactory p : f) {
     p.flushAsyncBatchRequests(outAsync);
   }
 }
Exemple #6
0
  @Override
  public void waitForHold() {
    if (Thread.interrupted()) {
      throw new Ice.OperationInterruptedException();
    }

    List<IncomingConnectionFactory> incomingConnectionFactories;
    synchronized (this) {
      checkForDeactivation();
      incomingConnectionFactories =
          new ArrayList<IncomingConnectionFactory>(_incomingConnectionFactories);
    }

    for (IncomingConnectionFactory factory : incomingConnectionFactories) {
      try {
        factory.waitUntilHolding();
      } catch (InterruptedException ex) {
        throw new Ice.OperationInterruptedException();
      }
    }
  }
Exemple #7
0
  @Override
  public void waitForDeactivate() {
    if (Thread.interrupted()) {
      throw new Ice.OperationInterruptedException();
    }

    try {
      List<IncomingConnectionFactory> incomingConnectionFactories;
      synchronized (this) {
        //
        // Wait for deactivation of the adapter itself, and
        // for the return of all direct method calls using
        // this adapter.
        //
        while ((_state < StateDeactivated) || _directCount > 0) {
          wait();
        }
        if (_state > StateDeactivated) {
          return;
        }
        incomingConnectionFactories =
            new ArrayList<IncomingConnectionFactory>(_incomingConnectionFactories);
      }

      //
      // Now we wait for until all incoming connection factories are
      // finished (the incoming connection factory list is immutable
      // at this point).
      //
      for (IncomingConnectionFactory f : incomingConnectionFactories) {
        f.waitUntilFinished();
      }
    } catch (InterruptedException e) {
      throw new Ice.OperationInterruptedException();
    }
  }
Exemple #8
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;
  }
Exemple #9
0
  @Override
  public void activate() {
    IceInternal.LocatorInfo locatorInfo = null;
    boolean registerProcess = false;
    boolean printAdapterReady = false;

    synchronized (this) {
      checkForDeactivation();

      //
      // If we've previously been initialized we just need to activate the
      // incoming connection factories and we're done.
      //
      if (_state != StateUninitialized) {
        for (IncomingConnectionFactory factory : _incomingConnectionFactories) {
          factory.activate();
        }
        return;
      }

      //
      // One off initializations of the adapter: update the
      // locator registry and print the "adapter ready"
      // message. We set set state to StateActivating to prevent
      // deactivation from other threads while these one off
      // initializations are done.
      //
      _state = StateActivating;

      locatorInfo = _locatorInfo;
      if (!_noConfig) {
        final Properties properties = _instance.initializationData().properties;
        registerProcess = properties.getPropertyAsInt(_name + ".RegisterProcess") > 0;
        printAdapterReady = properties.getPropertyAsInt("Ice.PrintAdapterReady") > 0;
      }
    }

    try {
      Ice.Identity dummy = new Ice.Identity();
      dummy.name = "dummy";
      updateLocatorRegistry(locatorInfo, createDirectProxy(dummy), registerProcess);
    } catch (Ice.LocalException ex) {
      //
      // If we couldn't update the locator registry, we let the
      // exception go through and don't activate the adapter to
      // allow to user code to retry activating the adapter
      // later.
      //
      synchronized (this) {
        _state = StateUninitialized;
        notifyAll();
      }
      throw ex;
    }

    if (printAdapterReady) {
      System.out.println(_name + " ready");
    }

    synchronized (this) {
      assert (_state == StateActivating);

      //
      // Signal threads waiting for the activation.
      //
      _state = StateActive;
      notifyAll();

      for (IncomingConnectionFactory factory : _incomingConnectionFactories) {
        factory.activate();
      }
    }
  }
Exemple #10
0
  @Override
  public void deactivate() {
    if (Thread.interrupted()) {
      throw new Ice.OperationInterruptedException();
    }

    synchronized (this) {
      //
      // Wait for activation to complete. This is necessary to
      // not get out of order locator updates.
      //
      while (_state == StateActivating) {
        try {
          wait();
        } catch (InterruptedException ex) {
          throw new Ice.OperationInterruptedException();
        }
      }
      if (_state > StateDeactivating) {
        return;
      }
      _state = StateDeactivating;
    }

    //
    // NOTE: the router/locator infos and incoming connection
    // facatory list are immutable at this point.
    //

    if (_routerInfo != null) {
      //
      // Remove entry from the router manager.
      //
      _instance.routerManager().erase(_routerInfo.getRouter());

      //
      //  Clear this object adapter with the router.
      //
      _routerInfo.setAdapter(null);
    }

    try {
      updateLocatorRegistry(_locatorInfo, null, false);
    } catch (Ice.LocalException ex) {
      //
      // We can't throw exceptions in deactivate so we ignore
      // failures to update the locator registry.
      //
    }

    //
    // Must be called outside the thread synchronization, because
    // Connection::destroy() might block when sending a
    // CloseConnection message.
    //
    for (IncomingConnectionFactory factory : _incomingConnectionFactories) {
      factory.destroy();
    }

    //
    // Must be called outside the thread synchronization, because
    // changing the object adapter might block if there are still
    // requests being dispatched.
    //
    _instance.outgoingConnectionFactory().removeAdapter(this);

    synchronized (this) {
      _state = StateDeactivated;
      notifyAll();
    }
  }