|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.objectweb.fractal.rmi.stub.RmiStubFactory
A stub and skeleton factory based on ASM. This factory generates the stub
and skeleton classes dynamically, when they are needed. It is therefore not
necessary for the user to statically generate these classes with a tool such
as rmic or idlc.
The stubs and skeletons created by this factory marshall and unmarshall the
method invocations by using the following format: a method invocation message
contains a four bytes method index, which uniquely and unambiguously
identifies a method among the methods provided by a Java interface, followed
by the method's arguments, marshalled in the order of their declaration in
the method's signature.
Field Summary | |
protected Logger |
logger
The logger used to log messages. |
protected LoggerFactory |
loggerFactory
The optional logger factory used to get a logger for this component. |
protected MarshallerFactory |
marshallerFactory
The marshaller factory to be used by the stubs created by this factory. |
Constructor Summary | |
RmiStubFactory()
Constructs a new RmiStubFactory . |
Method Summary | |
void |
bindFc(String clientItfName,
Object serverItf)
Binds the client interface whose name is given to a server interface. |
protected void |
generateConstructor(ClassVisitor cv,
String superClass)
Generates an empty constructor for the given class. |
protected void |
generateSkeletonClass(ClassVisitor cv,
Class itf)
Generates a skeleton class for the given Java interface. |
protected void |
generateSkeletonMethod(ClassVisitor cv,
String name,
Class itf)
Generates a skeleton's send method. |
protected void |
generateStubClass(ClassVisitor cv,
Class itf)
Generates a stub class for the given Java interface. |
protected void |
generateStubMethod(ClassVisitor cv,
String name,
Method m,
int index)
Generates a stub method. |
protected boolean |
isClassParameter(Method m,
int p)
Returns true if the specified parameter contains the name of a class. |
String[] |
listFc()
Returns the names of the client interfaces of the component to which this interface belongs. |
Object |
lookupFc(String clientItfName)
Returns the interface to which the given client interface is bound. |
RequestSession |
newSkeleton(Object target)
Creates a new skeleton implementing the RequestSession interface. |
Object |
newStub(SessionIdentifier sessionId,
Identifier[] ids,
Context hints)
Creates a new stub. |
protected static void |
sort(Method[] methods)
Sorts the given methods. |
void |
unbindFc(String clientItfName)
Unbinds the given client interface. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected MarshallerFactory marshallerFactory
protected LoggerFactory loggerFactory
protected Logger logger
Constructor Detail |
public RmiStubFactory()
RmiStubFactory
.
Method Detail |
public String[] listFc()
BindingController
listFc
in interface BindingController
public Object lookupFc(String clientItfName)
BindingController
bindFc
).
lookupFc
in interface BindingController
clientItfName
- the name of a client interface of the component to
which this interface belongs.
public void bindFc(String clientItfName, Object serverItf)
BindingController
bindFc
in interface BindingController
clientItfName
- the name of a client interface of the component to
which this interface belongs.serverItf
- a server interface.public void unbindFc(String clientItfName)
BindingController
unbindFc
in interface BindingController
clientItfName
- the name of a client interface of the component to
which this interface belongs.public Object newStub(SessionIdentifier sessionId, Identifier[] ids, Context hints) throws JonathanException
newStub
in interface StubFactory
sessionId
- a session identifier, to be used to send marshalled
data to the object represented by the stub;ids
- the set of identifiers of the stub;hints
- other data possibly used to create the stub. This method
requires the fully qualified name of the Java interface to which the
stub will gives access. This name must be associated to the
"interface_type" key.
Stub
class.
JonathanException
- if something goes wrong.public RequestSession newSkeleton(Object target) throws JonathanException
SkeletonFactory
RequestSession
interface.
newSkeleton
in interface SkeletonFactory
target
- the remote object.
JonathanException
- if something goes wrong.protected void generateStubClass(ClassVisitor cv, Class itf)
Stub
class that implements the given
interface, by using the given class visitor.
cv
- the class visitor to be used to generate the stub class.itf
- the Java interface that the stub class must implement.protected void generateSkeletonClass(ClassVisitor cv, Class itf)
Skeleton
class whose target
is an object implementing the given interface,
by using the given class visitor.
cv
- the class visitor to be used to generate the stub class.itf
- the Java interface implemented by the skeleton's target.protected void generateConstructor(ClassVisitor cv, String superClass)
cv
- the class visitor to be used to generate the constructor.superClass
- the internal name of the super class of the generated
class. This name is used to generate a call to the super constructor.protected void generateStubMethod(ClassVisitor cv, String name, Method m, int index)
public T m (T0 arg0, ...) throws E0, ... { try { Marshaller marshaller = request(); ReplyInterface reply = prepareInvocation(marshaller); marshaller.writeInt(methodIndex); marshaller.writeXXX(arg0); ... invoke(marshaller); UnMarshaller unmarshaller = reply.listen(); T result = (T)unmarshaller.readXXX(); unmarshaller.close(); return result; } catch (Exception e) { e = handleException(e); if (e instanceof E0) throw (E0)e; ... if (e instanceof RuntimeException) throw (RuntimeException)e; throw new RemoteException("server side exception", e); } }
cv
- the class visitor to be used to generate the stub method.name
- the internal name of the generated stub class.m
- the signature of the method that must be generated.index
- the index of this method. This index will be marshalled by the
generated stub method in each invocation message, to specify the
method that must be called on the server side. This index is the index
of the method in the sorted
array of all the
methods implemented by the stub.protected void generateSkeletonMethod(ClassVisitor cv, String name, Class itf)
send
method. The generated
method is of the following form:
public void send (UnMarshaller unmarshaller, ReplySession session) throws JonathanException { int methodIndex = unmarshaller.readInt(); try { switch (methodIndex) { case 0: T0 arg0 = unmarshaller.readXXX(); ... unmarshaller.close(); T result = ((I)target).m0(arg0, ... ); Marshaller marshaller = session.prepareReply(); marshaller.writeXXX(result); session.send(marshaller); session.close(); return; ... default: handleInterfaceMethods(unmarshaller, session, methodIndex); } } catch (Exception e) { handleException(e, session); } }
cv
- the class visitor to be used to generate the stub method.name
- the internal name of the generated stub class.itf
- the target object's interface that must be exported by the
skeleton.protected boolean isClassParameter(Method m, int p)
m
- a method.p
- index of a parameter of this method, or -1 to designate
the return value.
protected static void sort(Method[] methods)
getMethods
cannot directly
be used for this purpose, since this method returns the methods in any
order).
methods
- the method array to be sorted.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |