org.jboss.invocation.jrmp.interfaces
public class: JRMPInvokerProxy [javadoc |
source]
java.lang.Object
org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy
All Implemented Interfaces:
Invoker, Externalizable
Direct Known Subclasses:
JRMPInvokerProxyHA
JRMPInvokerProxy, local to the proxy and is capable of delegating to
the JRMP implementations
- author:
< - a href="mailto:marc.fleury@jboss.org">Marc Fleury
- author:
< - a href="mailto:scott.stark@jboss.org">Scott Stark
- version:
$ - Revision: 37459 $
| Field Summary |
|---|
| protected Invoker | remoteInvoker | |
| public static int | MAX_RETRIES | max retries on a ConnectException. |
| Method from org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy Detail: |
public String getServerHostName() throws Exception {
return remoteInvoker.getServerHostName();
}
The name of of the server. |
public Object getTransactionPropagationContext() throws SystemException {
TransactionPropagationContextFactory tpcFactory = TransactionPropagationContextUtil.getTPCFactoryClientSide();
return (tpcFactory == null) ? null : tpcFactory.getTransactionPropagationContext();
}
|
public Object invoke(Invocation invocation) throws Exception {
// We are going to go through a Remote invocation, switch to a Marshalled Invocation
MarshalledInvocation mi = new MarshalledInvocation(invocation);
// Set the transaction propagation context
// @todo: MOVE TO TRANSACTION
mi.setTransactionPropagationContext(getTransactionPropagationContext());
// RMI seems to make a connection per invocation.
// If too many clients are making an invocation
// at same time, ConnectionExceptions happen
for (int i = 0; i < MAX_RETRIES; i++)
{
try
{
MarshalledObject result = (MarshalledObject) remoteInvoker.invoke(mi);
return result.get();
}
catch (ConnectException ce)
{
if (i + 1 < MAX_RETRIES)
{
Thread.sleep(1);
continue;
}
throw ce;
}
catch (ServerException ex)
{
// Suns RMI implementation wraps NoSuchObjectException in
// a ServerException. We cannot have that if we want
// to comply with the spec, so we unwrap here.
if (ex.detail instanceof NoSuchObjectException)
{
throw (NoSuchObjectException) ex.detail;
}
if (ex.detail instanceof TransactionRolledbackException)
{
throw (TransactionRolledbackException) ex.detail;
}
if (ex.detail instanceof RemoteException)
{
throw (RemoteException) ex.detail;
}
throw ex;
}
}
throw new Exception("Unreachable statement");
}
The invocation on the delegate, calls the right invoker. Remote if we are remote,
local if we are local. |
public void readExternal(ObjectInput in) throws ClassNotFoundException, IOException {
remoteInvoker = (Invoker) in.readObject();
}
Un-externalize this instance. |
public void writeExternal(ObjectOutput out) throws IOException {
/** We need to handle obtaining the RemoteStub for the remoteInvoker
* since this proxy may be serialized in contexts that are not JRMP
* aware.
*/
if( remoteInvoker instanceof RemoteStub )
{
out.writeObject(remoteInvoker);
}
else
{
Object replacement = RemoteObject.toStub(remoteInvoker);
out.writeObject(replacement);
}
}
Externalize this instance and handle obtaining the remoteInvoker stub |