Package com.zeroc.Ice

Class ObjectAdapter

java.lang.Object
com.zeroc.Ice.ObjectAdapter

public final class ObjectAdapter extends Object
An object adapter is the main server-side Ice API. It has two main purposes: - accept incoming connections from clients and dispatch requests received over these connections (see activate()); and - maintain a dispatch pipeline and servants that handle the requests (see add(com.zeroc.Ice.Object, com.zeroc.Ice.Identity), addDefaultServant(com.zeroc.Ice.Object, java.lang.String), and use(java.util.function.Function<com.zeroc.Ice.Object, com.zeroc.Ice.Object>)).

An object adapter can dispatch "bidirectional requests"--requests it receives over an outgoing connection instead of a more common incoming connection. It can also dispatch collocated requests (with no connection at all).

See Also:
  • Method Details

    • getName

      public String getName()
      Gets the name of this object adapter.
      Returns:
      This object adapter's name.
    • getCommunicator

      public Communicator getCommunicator()
      Gets the communicator that created this object adapter.
      Returns:
      This object adapter's communicator.
      See Also:
    • activate

      public void activate()
      Starts receiving and dispatching requests received over incoming connections.

      When this object adapter is an indirect object adapter configured with a locator proxy, this method also registers the object adapter's published endpoints with this locator.

      See Also:
    • hold

      public void hold()
      Stops reading requests from incoming connections. Outstanding dispatches are not affected. The object adapter can be reactivated with activate().

      This method is provided for backward compatibility with older versions of Ice. Don't use it in new applications.

      See Also:
    • waitForHold

      public void waitForHold()
      Waits until the object adapter is in the holding state (see hold()) and the dispatch of requests received over incoming connection has completed.

      This method is provided for backward compatibility with older versions of Ice. Don't use it in new applications.

      See Also:
    • deactivate

      public void deactivate()
      Deactivates this object adapter: stops accepting new connections from clients and closes gracefully all incoming connections created by this object adapter once all outstanding dispatches have completed. If this object adapter is indirect, this method also unregisters the object adapter from the locator (see activate()). This method does not cancel outstanding dispatches: it lets them execute until completion. A deactivated object adapter cannot be reactivated again; it can only be destroyed.
      See Also:
    • waitForDeactivate

      public void waitForDeactivate()
      Waits until deactivate() is called on this object adapter and all connections accepted by this object adapter are closed. A connection is closed only after all outstanding dispatches on this connection have completed.
      See Also:
    • isDeactivated

      public boolean isDeactivated()
      Checks whether or not deactivate() was called on this object adapter.
      Returns:
      true if deactivate() was called on this object adapter, false otherwise.
      See Also:
    • destroy

      public void destroy()
      Destroys this object adapter and cleans up all resources associated with it. Once this method has returned, you can recreate another object adapter with the same name.
      See Also:
    • use

      public ObjectAdapter use(Function<Object,Object> middleware)
      Adds a middleware to the dispatch pipeline of this object adapter.

      All middleware must be installed before the first dispatch.

      The middleware are executed in the order they are installed.

      Parameters:
      middleware - The middleware factory that creates the new middleware when this object adapter creates its dispatch pipeline. A middleware factory is a function that takes an Object (the next element in the dispatch pipeline) and returns a new Object (the middleware you want to install in the pipeline).
      Returns:
      This object adapter.
      Throws:
      IllegalStateException - Thrown if the object adapter's dispatch pipeline has already been created. This creation typically occurs the first time the object adapter dispatches an incoming request.
    • add

      public ObjectPrx add(Object servant, Identity identity)
      Adds a servant to this object adapter's Active Servant Map (ASM). The ASM is a map {identity, facet} -> servant.

      This method is equivalent to calling addFacet(com.zeroc.Ice.Object, com.zeroc.Ice.Identity, java.lang.String) with an empty facet.

      Parameters:
      servant - The servant to add.
      identity - The identity of the Ice object that is implemented by the servant.
      Returns:
      A proxy for the identity created by this object adapter.
      Throws:
      AlreadyRegisteredException - Thrown when a servant with the same identity is already registered.
      See Also:
    • addFacet

      public ObjectPrx addFacet(Object servant, Identity identity, String facet)
      Adds a servant to this object adapter's Active Servant Map (ASM), while specifying a facet. The ASM is a map {identity, facet} -> servant.
      Parameters:
      servant - The servant to add.
      identity - The identity of the Ice object that is implemented by the servant.
      facet - The facet of the Ice object that is implemented by the servant.
      Returns:
      A proxy for the identity and facet created by this object adapter.
      Throws:
      AlreadyRegisteredException - Thrown when a servant with the same identity and facet is already registered.
      See Also:
    • addWithUUID

      public ObjectPrx addWithUUID(Object servant)
      Adds a servant to this object adapter's Active Servant Map (ASM), using an automatically generated UUID as its identity.
      Parameters:
      servant - The servant to add.
      Returns:
      A proxy with the generated UUID identity created by this object adapter.
      See Also:
    • addFacetWithUUID

      public ObjectPrx addFacetWithUUID(Object servant, String facet)
      Adds a servant to this object adapter's Active Servant Map (ASM), using an automatically generated UUID as its identity. Also specifies a facet.
      Parameters:
      servant - The servant to add.
      facet - The facet of the Ice object that is implemented by the servant.
      Returns:
      A proxy with the generated UUID identity and the specified facet.
      See Also:
    • addDefaultServant

      public void addDefaultServant(Object servant, String category)
      Adds a default servant to handle requests for a specific category. When an object adapter dispatches an incoming request, it tries to find a servant for the identity and facet carried by the request in the following order: - The object adapter tries to find a servant for the identity and facet in the Active Servant Map. - If this fails, the object adapter tries to find a default servant for the category component of the identity. - If this fails, the object adapter tries to find a default servant for the empty category, regardless of the category contained in the identity. - If this fails, the object adapter tries to find a servant locator for the category component of the identity. If there is no such servant locator, the object adapter tries to find a servant locator for the empty category. - If a servant locator is found, the object adapter tries to find a servant using this servant locator. - If all the previous steps fail, the object adapter gives up and the caller receives an ObjectNotExistException or a FacetNotExistException.
      Parameters:
      servant - The default servant to add.
      category - The category for which the default servant is registered. The empty category means it handles all categories.
      Throws:
      AlreadyRegisteredException - Thrown when a default servant with the same category is already registered.
      See Also:
    • remove

      public Object remove(Identity identity)
      Removes a servant from the object adapter's Active Servant Map.
      Parameters:
      identity - The identity of the Ice object that is implemented by the servant.
      Returns:
      The removed servant.
      Throws:
      NotRegisteredException - Thrown when no servant with the given identity is registered.
      See Also:
    • removeFacet

      public Object removeFacet(Identity identity, String facet)
      Removes a servant from the object adapter's Active Servant Map, while specifying a facet.
      Parameters:
      identity - The identity of the Ice object that is implemented by the servant.
      facet - The facet. An empty facet means the default facet.
      Returns:
      The removed servant.
      Throws:
      NotRegisteredException - Thrown when no servant with the given identity and facet is registered.
      See Also:
    • removeAllFacets

      public Map<String,Object> removeAllFacets(Identity identity)
      Removes all facets with the given identity from the Active Servant Map. The method completely removes the Ice object, including its default facet.
      Parameters:
      identity - The identity of the Ice object to be removed.
      Returns:
      A collection containing all the facet names and servants of the removed Ice object.
      Throws:
      NotRegisteredException - Thrown when no servant with the given identity is registered.
      See Also:
    • removeDefaultServant

      public Object removeDefaultServant(String category)
      Removes the default servant for a specific category.
      Parameters:
      category - The category of the default servant to remove.
      Returns:
      The default servant.
      Throws:
      NotRegisteredException - Thrown when no default servant is registered for the given category.
      See Also:
    • find

      public Object find(Identity identity)
      Looks up a servant.

      This method only tries to find the servant in the ASM and among the default servants. It does not attempt to locate a servant using servant locators.

      Parameters:
      identity - The identity of an Ice object.
      Returns:
      The servant that implements the Ice object with the given identity, or null if no such servant has been found.
      See Also:
    • findFacet

      public Object findFacet(Identity identity, String facet)
      Looks up a servant with an identity and facet.

      This method only tries to find the servant in the ASM and among the default servants. It does not attempt to locate a servant using servant locators.

      Parameters:
      identity - The identity of an Ice object.
      facet - The facet of an Ice object. An empty facet means the default facet.
      Returns:
      The servant that implements the Ice object with the given identity and facet, or null if no such servant has been found.
      See Also:
    • findAllFacets

      public Map<String,Object> findAllFacets(Identity identity)
      Finds all facets for a given identity in the Active Servant Map.
      Parameters:
      identity - The identity.
      Returns:
      A collection containing all the facet names and servants that have been found. Can be empty.
      See Also:
    • findByProxy

      public Object findByProxy(ObjectPrx proxy)
      Looks up a servant with an identity and a facet. It's equivalent to calling findFacet(com.zeroc.Ice.Identity, java.lang.String).
      Parameters:
      proxy - The proxy that provides the identity and facet to search.
      Returns:
      The servant that matches the identity and facet carried by the proxy, or null if no such servant has been found.
      See Also:
    • addServantLocator

      public void addServantLocator(ServantLocator locator, String category)
      Adds a ServantLocator to this object adapter for a specific category.
      Parameters:
      locator - The servant locator to add.
      category - The category. The empty category means the locator handles all categories.
      Throws:
      AlreadyRegisteredException - Thrown when a servant locator with the same category is already registered.
      See Also:
    • removeServantLocator

      public ServantLocator removeServantLocator(String category)
      Removes a ServantLocator from this object adapter.
      Parameters:
      category - The category.
      Returns:
      The servant locator.
      Throws:
      NotRegisteredException - Thrown when no ServantLocator with the given category is registered.
      See Also:
    • findServantLocator

      public ServantLocator findServantLocator(String category)
      Finds a ServantLocator registered with this object adapter.
      Parameters:
      category - The category.
      Returns:
      The servant locator, or null if not found.
      See Also:
    • findDefaultServant

      public Object findDefaultServant(String category)
      Finds the default servant for a specific category.
      Parameters:
      category - The category.
      Returns:
      The default servant, or null if not found.
      See Also:
    • dispatchPipeline

      public Object dispatchPipeline()
      Gets the dispatch pipeline of this object adapter.
      Returns:
      The dispatch pipeline. The returned value is never null.
    • createProxy

      public ObjectPrx createProxy(Identity identity)
      Creates a proxy from an Ice identity. If this object adapter is configured with an adapter ID, the proxy is an indirect proxy that refers to this adapter ID. If a replica group ID is also defined, the proxy is an indirect proxy that refers to this replica group ID. Otherwise, the proxy is a direct proxy containing this object adapter's published endpoints.
      Parameters:
      identity - An Ice identity.
      Returns:
      A proxy with the given identity.
      See Also:
    • createDirectProxy

      public ObjectPrx createDirectProxy(Identity identity)
      Creates a direct proxy from an Ice identity.
      Parameters:
      identity - An Ice identity.
      Returns:
      A proxy with the given identity and this published endpoints of this object adapter.
      See Also:
    • createIndirectProxy

      public ObjectPrx createIndirectProxy(Identity identity)
      Creates an indirect proxy for an Ice identity.
      Parameters:
      identity - An Ice identity.
      Returns:
      An indirect proxy with the given identity. If this object adapter is not configured with an adapter ID or a replica group ID, the new proxy is a well-known proxy (i.e., an identity-only proxy).
      See Also:
    • setLocator

      public void setLocator(LocatorPrx locator)
      Sets an Ice locator on this object adapter.
      Parameters:
      locator - The locator used by this object adapter.
      See Also:
    • getLocator

      public LocatorPrx getLocator()
      Gets the Ice locator used by this object adapter.
      Returns:
      The locator used by this object adapter, or null if no locator is used by this object adapter.
      See Also:
    • getEndpoints

      public Endpoint[] getEndpoints()
      Gets the set of endpoints configured on this object adapter.

      This method remains usable after the object adapter has been deactivated.

      Returns:
      The set of endpoints.
      See Also:
    • getPublishedEndpoints

      public Endpoint[] getPublishedEndpoints()
      Gets the set of endpoints that proxies created by this object adapter will contain.

      This method remains usable after the object adapter has been deactivated.

      Returns:
      The set of published endpoints.
      See Also:
    • setPublishedEndpoints

      public void setPublishedEndpoints(Endpoint[] newEndpoints)
      Sets the endpoints that proxies created by this object adapter will contain.
      Parameters:
      newEndpoints - The new set of endpoints that the object adapter will embed in proxies.
      See Also:
    • isLocal

      public boolean isLocal(com.zeroc.Ice.Reference ref)
      Checks whether the specified reference refers to a local object.
      Parameters:
      ref - the reference to check
      Returns:
      true if the reference refers to a local object, false otherwise
    • flushAsyncBatchRequests

      public void flushAsyncBatchRequests(CompressBatch compressBatch, com.zeroc.Ice.CommunicatorFlushBatch outAsync)
      Flushes any pending batch requests for this object adapter.
      Parameters:
      compressBatch - indicates whether to compress the batch requests
      outAsync - the callback for the asynchronous flush operation
    • updateConnectionObservers

      public void updateConnectionObservers()
      Updates the connection observers for all incoming connection factories.
    • updateThreadObservers

      public void updateThreadObservers()
      Updates the thread observers for the thread pool.
    • incDirectCount

      public void incDirectCount()
      Increments the count of direct method calls using this object adapter.
    • decDirectCount

      public void decDirectCount()
      Decrements the count of direct method calls using this object adapter.
    • getThreadPool

      public com.zeroc.Ice.ThreadPool getThreadPool()
      Gets the thread pool used by this object adapter.
      Returns:
      the thread pool used by this object adapter
    • setAdapterOnConnection

      public void setAdapterOnConnection(com.zeroc.Ice.ConnectionI connection)
      Sets this object adapter on the specified connection.
      Parameters:
      connection - the connection to set the adapter on
    • messageSizeMax

      public int messageSizeMax()
      Gets the maximum message size for this object adapter.
      Returns:
      the maximum message size in bytes
    • getSSLEngineFactory

      public SSLEngineFactory getSSLEngineFactory()
      Gets the SSL engine factory used by this object adapter.
      Returns:
      the SSL engine factory
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable