KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > server > RemoteRefEx


1 package org.sapia.ubik.rmi.server;
2
3 import java.lang.reflect.Method JavaDoc;
4
5 import org.sapia.ubik.net.ServerAddress;
6 import org.sapia.ubik.rmi.server.invocation.CallBackInvokeCommand;
7 import org.sapia.ubik.rmi.server.invocation.InvokeCommand;
8
9
10 /**
11  * This class implements a basic stub handler (no fail over,
12  * no load balancing, no replication).
13  *
14  * @author Yanick Duchesne
15  * <dl>
16  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
17  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
18  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
19  * </dl>
20  */

21 public class RemoteRefEx extends RemoteRef {
22   static final long serialVersionUID = 1L;
23
24   public RemoteRefEx() {
25   }
26
27   /**
28    * Creates an instance of this class, with the given object and host
29    * identifiers.
30    *
31    * @param oid an <code>OID</code>
32    * @param serverAddress a <code>ServerAddress</code>
33    *
34    */

35   public RemoteRefEx(OID oid, ServerAddress serverAddress) {
36     super(oid, serverAddress);
37   }
38
39   /**
40    * @see java.lang.reflect.InvocationHandler#invoke(Object, Method, Object[])
41    */

42   public Object JavaDoc invoke(Object JavaDoc proxy, Method JavaDoc toCall, Object JavaDoc[] params)
43     throws Throwable JavaDoc {
44     Object JavaDoc toReturn = null;
45
46     if (_callBack &&
47           Hub.clientRuntime.isCallback(_serverAddress.getTransportType())) {
48       if (Log.isDebug()) {
49         Log.debug(getClass(), "invoking (callback): " + toCall);
50       }
51
52       if (_pool == null) {
53         super.initPool(false);
54       }
55
56       toReturn = ClientRuntime.invoker.dispatchInvocation(_vmId, _pool,
57           new CallBackInvokeCommand(_oid, toCall.getName(), params,
58             toCall.getParameterTypes(), _serverAddress.getTransportType()));
59     } else {
60       if (Log.isDebug()) {
61         Log.debug(getClass(), "invoking (no callback): " + toCall);
62       }
63
64       if (_pool == null) {
65         super.initPool(false);
66       }
67
68       toReturn = ClientRuntime.invoker.dispatchInvocation(_vmId, _pool,
69           new InvokeCommand(_oid, toCall.getName(), params,
70             toCall.getParameterTypes(), _serverAddress.getTransportType()));
71     }
72
73     if (toReturn == null) {
74       return toReturn;
75     } else if (toReturn instanceof Throwable JavaDoc) {
76       if (toReturn instanceof ShutdownException) {
77         onShutdown(proxy, toCall, params);
78       }
79
80       Throwable JavaDoc err = (Throwable JavaDoc) toReturn;
81       err.fillInStackTrace();
82       throw err;
83     }
84
85     return toReturn;
86   }
87
88   protected Object JavaDoc onShutdown(Object JavaDoc proxy, Method JavaDoc toCall, Object JavaDoc[] params)
89     throws Throwable JavaDoc {
90     throw new ShutdownException();
91   }
92 }
93
Popular Tags