Exports the specified remote object and returns a proxy for the remote object. This method cannot be called more than once to export a remote object or an
IllegalStateException
will be thrown.
A {@link BasicObjectEndpoint} instance is created with the objectidentifier of this exporter, the {@link Endpoint} obtained fromlistening on the server endpoint (see below), and the enableDGC
flag of this exporter.
The client Endpoint
for the BasicObjectEndpoint
is obtained by invoking {@link ServerEndpoint#enumerateListenEndpoints enumerateListenEndpoints} onthe server endpoint with a {@link ServerEndpoint.ListenContext}whose {@link ServerEndpoint.ListenContext#addListenEndpoint addListenEndpoint} method is implemented as follows:
- Invokes {@link ServerEndpoint.ListenEndpoint#checkPermissions checkPermissions} on the supplied listen endpoint.
- If the supplied listen endpoint has the same class and is equal to another listen endpoint that has already been listened on, returns the {@link ServerEndpoint.ListenCookie} corresponding to theprevious
listen
operation. Otherwise, it creates a {@link RequestDispatcher} to handle inbound requests dispatched bythe listen endpoint, invokes {@link ServerEndpoint.ListenEndpoint#listen listen} on the listen endpoint(passing the request dispatcher) within an action passed to the {@link Security#doPrivileged Security.doPrivileged} method, andreturns the ServerEndpoint.ListenCookie
obtained by invoking {@link ServerEndpoint.ListenHandle#getCookie getCookie} onthe {@link ServerEndpoint.ListenHandle} returned from thelisten
invocation.
A RequestDispatcher
for a listen endpoint handles a dispatched inbound request (when its {@link RequestDispatcher#dispatch dispatch} method is invoked) as follows.The request dispatcher reads the object identifer of the target object being invoked by invoking {@link UuidFactory#read UuidFactory.read} on the request input stream of the inboundrequest. If no exported object corresponds to the object identifier read, it closes the request input stream, writes 0x00
to the response output stream, and closes the response output stream. Otherwise, it writes 0x01
to the response output stream, and invokes the {@link InvocationDispatcher#dispatch dispatch} method on the invocation dispatcher passing the targetobject, the inbound request, and the server context collection (see below).
A proxy and an invocation dispatcher are created by calling the {@link InvocationLayerFactory#createInstances createInstances} method of this exporter's invocation layer factory,passing the remote object, the BasicObjectEndpoint
, and the server endpoint (as the {@link ServerCapabilities}). The proxy is returned by this method. The invocation dispatcher is called for each incoming remote call to this exporter's object identifier received from this exporter's server endpoint, passing the remote object and the {@link InboundRequest} received from the transportlayer.
Each call to the invocation dispatcher's {@link InvocationDispatcher#dispatch dispatch} method is invoked withthe following thread context:
dispatch
is invoked in a {@link PrivilegedAction} wrapped by a {@link SecurityContext}obtained when this method was invoked, with the {@link AccessControlContext} of that SecurityContext
in effect. - The context class loader is the context class loader in effect when this method was invoked.
- Each call to the dispatcher is made using {@link ServerContext#doWithServerContext ServerContext.doWithServerContext} with a server contextcollection that is an unmodifiable view of the context collection populated by invoking the {@link InboundRequest#populateContext populateContext} method on theinbound request passing a modifiable collection. The invocation dispatcher's {@link InvocationDispatcher#dispatch dispatch}method is invoked with the
impl
, the inbound request, and that modifiable server context collection.
There is no replacement of the proxy for the implementation object during marshalling; either the proxy must be passed explicitly in a remote call, or the implementation class must be serializable and have a writeReplace
method that returns the proxy.
@throws ExportException if an object is already exportedwith the same object identifier and server endpoint, or the invocation layer factory cannot create a proxy or invocation dispatcher, or some other problem occurs while exporting the object
@throws NullPointerException {@inheritDoc}
@throws IllegalStateException {@inheritDoc}
@throws SecurityException if invoking thecheckPermissions
method on any of the listen endpoints throws a SecurityException