net.jini.jeri
Class AbstractILFactory

java.lang.Object
  extended by net.jini.jeri.AbstractILFactory
All Implemented Interfaces:
InvocationLayerFactory
Direct Known Subclasses:
BasicILFactory

public abstract class AbstractILFactory
extends Object
implements InvocationLayerFactory

An abstract implementation of InvocationLayerFactory that provides a convenient way for subclasses to create proxies and invocation dispatchers for remote objects. A subclass must provide an implementation for at least the createInvocationHandler and createInvocationDispatcher methods. A subclass can override the getProxyInterfaces method if its proxies need to implement a different set of interfaces than the default set (all remote interfaces of the remote object).

Since:
2.0
Author:
Sun Microsystems, Inc.

Nested Class Summary
 
Nested classes/interfaces inherited from interface net.jini.jeri.InvocationLayerFactory
InvocationLayerFactory.Instances
 
Constructor Summary
protected AbstractILFactory()
          Constructs an AbstractILFactory instance with a null class loader.
protected AbstractILFactory(ClassLoader loader)
          Constructs an AbstractILFactory instance with the specified class loader.
 
Method Summary
 InvocationLayerFactory.Instances createInstances(Remote impl, ObjectEndpoint oe, ServerCapabilities caps)
          Returns a compatible proxy and invocation dispatcher for a remote object being exported.
protected abstract  InvocationDispatcher createInvocationDispatcher(Collection methods, Remote impl, ServerCapabilities caps)
          Returns an invocation dispatcher to receive incoming remote calls for the specified methods to the specified remote object, for a server and transport with the specified capabilities.
protected abstract  InvocationHandler createInvocationHandler(Class[] interfaces, Remote impl, ObjectEndpoint oe)
          Returns an invocation handler to use with a Proxy instance implementing the specified interfaces, communicating with the specified remote object using the specified object endpoint.
 boolean equals(Object obj)
          Compares the specified object with this invocation layer factory for equality.
protected  ClassLoader getClassLoader()
          Returns the class loader specified during construction.
protected  Class[] getExtraProxyInterfaces(Remote impl)
          Returns a new array containing any additional interfaces that the proxy should implement, beyond the interfaces obtained by passing impl to the getRemoteInterfaces method.
protected  Collection getInvocationDispatcherMethods(Remote impl)
          Returns a new, modifiable collection of Method objects, containing all remote methods for which the invocation dispatcher should accept incoming remote calls.
protected  Class[] getProxyInterfaces(Remote impl)
          Returns a new array containing the interfaces for the proxy to implement.
protected  Class[] getRemoteInterfaces(Remote impl)
          Returns a new array containing the remote interfaces that should be implemented by the proxy.
 int hashCode()
          Returns a hash code value for this factory.
 String toString()
          Returns a string representation for this factory.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractILFactory

protected AbstractILFactory()
Constructs an AbstractILFactory instance with a null class loader.


AbstractILFactory

protected AbstractILFactory(ClassLoader loader)
Constructs an AbstractILFactory instance with the specified class loader. The createInstances method uses the specified loader to define a proxy class.

Parameters:
loader - the class loader, or null
Method Detail

getClassLoader

protected final ClassLoader getClassLoader()
Returns the class loader specified during construction.

Returns:
the class loader

getProxyInterfaces

protected Class[] getProxyInterfaces(Remote impl)
                              throws ExportException
Returns a new array containing the interfaces for the proxy to implement.

AbstractILFactory implements this method to return an array containing all of the interfaces obtained by passing impl to the getRemoteInterfaces method plus the interfaces obtained by calling the getExtraProxyInterfaces method, in that order, with duplicate interfaces (that is, duplicates after the first occurrence of an interface) eliminated.

A subclass can override this method if its proxies need to implement a different set of interfaces than the default.

Parameters:
impl - the remote object
Returns:
the proxy interfaces
Throws:
ExportException - if there is a problem obtaining the proxy interfaces or if impl does not satisfy the requirements of this factory
NullPointerException - if impl is null

getRemoteInterfaces

protected Class[] getRemoteInterfaces(Remote impl)
                               throws ExportException
Returns a new array containing the remote interfaces that should be implemented by the proxy. All of the methods of a remote interface are implemented as remote invocations, so all of the methods must declare RemoteException or one of its superclasses in their throws clauses.

AbstractILFactory implements this method to return an array containing the following ordered list of interfaces:

and throws an ExportException if any method of those interfaces does not have a conforming throws clause.

A subclass can override this method if its proxies need a set of remote interfaces other than the default.

Parameters:
impl - the remote object
Returns:
the remote interfaces implemented by impl
Throws:
NullPointerException - if impl is null
ExportException - if there is a problem obtaining the remote interfaces or if impl does not satisfy the requirements of this factory

getExtraProxyInterfaces

protected Class[] getExtraProxyInterfaces(Remote impl)
                                   throws ExportException
Returns a new array containing any additional interfaces that the proxy should implement, beyond the interfaces obtained by passing impl to the getRemoteInterfaces method.

AbstractILFactory implements this method to return an array containing the RemoteMethodControl interface.

A subclass can override this method if its proxies need to implement a different set of extra interfaces than the default.

Parameters:
impl - the remote object
Returns:
the extra proxy interfaces
Throws:
NullPointerException - if impl is null
ExportException - if there is a problem obtaining the additional interfaces or if impl does not satisfy the requirements of this factory

getInvocationDispatcherMethods

protected Collection getInvocationDispatcherMethods(Remote impl)
                                             throws ExportException
Returns a new, modifiable collection of Method objects, containing all remote methods for which the invocation dispatcher should accept incoming remote calls.

AbstractILFactory implements this method to return a Set containing all of the methods of the interfaces obtained by passing impl to the getRemoteInterfaces method and satisfying the following requirements:

A subclass can override this method if it needs to control the selection of the set of methods for the dispatcher to handle, or if it needs to control the implementation of the collection returned.

Parameters:
impl - the remote object
Returns:
the remote methods
Throws:
NullPointerException - if impl is null
ExportException - if there is a problem obtaining the remote methods or if impl does not satisfy the requirements of this factory

createInvocationHandler

protected abstract InvocationHandler createInvocationHandler(Class[] interfaces,
                                                             Remote impl,
                                                             ObjectEndpoint oe)
                                                      throws ExportException
Returns an invocation handler to use with a Proxy instance implementing the specified interfaces, communicating with the specified remote object using the specified object endpoint.

A subclass must override this method to create an InvocationHandler for the specified interfaces, remote object, and object endpoint.

Parameters:
interfaces - an array of proxy interfaces
impl - a remote object this invocation handler is being created for
oe - an object endpoint used to communicate with the remote object
Returns:
the invocation handler for the remote object's proxy
Throws:
ExportException - if there is a problem creating the invocation handler
NullPointerException - if any argument is null, or if interfaces contains a null element

createInvocationDispatcher

protected abstract InvocationDispatcher createInvocationDispatcher(Collection methods,
                                                                   Remote impl,
                                                                   ServerCapabilities caps)
                                                            throws ExportException
Returns an invocation dispatcher to receive incoming remote calls for the specified methods to the specified remote object, for a server and transport with the specified capabilities.

A subclass must override this method to create an InvocationDispatcher for the specified methods, remote object, and server capabilities.

Parameters:
methods - a collection of Method instances for the remote methods
impl - a remote object that the dispatcher is being created for
caps - the transport capabilities of the server
Returns:
the invocation dispatcher for the remote object
Throws:
ExportException - if there is a problem creating the dispatcher
IllegalArgumentException - if methods contains an element that is not a Method instance
NullPointerException - if any argument is null, or if methods contains a null element

createInstances

public InvocationLayerFactory.Instances createInstances(Remote impl,
                                                        ObjectEndpoint oe,
                                                        ServerCapabilities caps)
                                                 throws ExportException
Returns a compatible proxy and invocation dispatcher for a remote object being exported. The proxy and invocation dispatcher are returned in an InvocationLayerFactory.Instances container object. The proxy sends calls to the remote object using the supplied ObjectEndpoint.

The returned proxy implements an implementation-specific set of remote interfaces of impl and may implement additional implementation-specific interfaces.

A given Exporter implementation should only call this method once per export. An invocation dispatcher constructed for a previous export should not be reused.

AbstractILFactory implements this method to return a Proxy instance where:

The returned invocation dispatcher is obtained by calling the createInvocationDispatcher method, passing a collection of methods, impl, and caps as arguments. The collection of methods is obtained by calling the getInvocationDispatcherMethods method, passing impl as the argument.

Specified by:
createInstances in interface InvocationLayerFactory
Parameters:
impl - the remote object that the proxy is being created for
oe - the object endpoint used to communicate with the remote object
caps - the transport capabilities of the server
Returns:
a proxy and invocation dispatcher contained in an Instances object
Throws:
NullPointerException - if any argument is null
ExportException - if there is a problem creating the proxy or dispatcher

hashCode

public int hashCode()
Returns a hash code value for this factory.

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Compares the specified object with this invocation layer factory for equality.

AbstractILFactory implements this method to return true if and only if the specified object has the same class as this object and the loader in the specified object is equal to the loader in this object.

A subclass should override this method if it adds instance state that affects equality.

Overrides:
equals in class Object

toString

public String toString()
Returns a string representation for this factory.

Overrides:
toString in class Object


Copyright 2007, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.