KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > dist > rmi > RMIRemoteContainerStub


1 /*
2   Copyright (C) 2001 Lionel Seinturier
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser Generaly Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.core.dist.rmi;
19
20 import java.io.Serializable JavaDoc;
21 import java.rmi.RemoteException JavaDoc;
22 import org.apache.log4j.Logger;
23 import org.objectweb.jac.core.dist.RemoteContainer;
24 import org.objectweb.jac.core.dist.RemoteRef;
25
26 /**
27  * RMIRemoteContainerStub acts as a client stub to access a remote container.
28  *
29  * RMIRemoteContainerStub holds a RMIRemoteContainer_Stub instance.
30  * This is the client stub of the remote RMIRemoteContainer object that owns as
31  * a delegate the container that is to be accessed.
32  *
33  * Note: what we need is an instance of something that extends RemoteContainer.
34  * But we can't have an object that is both a client stub for a remote RMI
35  * object and a RemoteContainer (no multiple inheritance in Java).
36  * So we implemented this delegating scheme where:
37  * <ul>
38  * <li> RMIRemoteContainerStub (which is a RemoteContainer) delegates its job
39  * to a RMIRemoteContainer client stub (generated by rmic) </li>
40  * <li> which itself transmits it to a remote RMIRemoteContainer object, </li>
41  * <li> which itself delegates it to a final RemoteContainer object. </li>
42  * </ul>
43  *
44  * @see org.objectweb.jac.core.dist.rmi.RMIRemoteContainer
45  *
46  * @author <a HREF="http://www-src.lip6.fr/homepages/Lionel.Seinturier/index-eng.html">Lionel Seinturier</a>
47  */

48  
49 public class RMIRemoteContainerStub
50     extends RemoteContainer implements Serializable JavaDoc
51 {
52     static Logger logger = Logger.getLogger("dist.rmi");
53
54     /**
55      * The RMI stub where the job is to be delegated.
56      */

57    
58     protected RMIRemoteContainerInterf delegate;
59    
60
61     /**
62      * Create a new remote container stub.
63      *
64      * @param delegate the stub where the job is to be delegated
65      * @param name the name of the remote container
66      */

67    
68     public RMIRemoteContainerStub(RMIRemoteContainerInterf delegate,
69                                   String JavaDoc name)
70     {
71         this.delegate = delegate;
72         this.name = name;
73     }
74    
75
76     /**
77      * This method instantiates a className object.
78      * Clients call it to remotely instantiate an object.
79      * instantiates creates an object and returns its index.
80      *
81      * @param className the class name to instantiate
82      * @param args initialization arguments for the instantiation
83      * @param fields the object fields that are part of the state
84      * @param state the state to copy
85      * @param collaboration the collaboration of the client
86      * @return the index of the className object
87      */

88    
89     public int instantiates(String JavaDoc name, String JavaDoc className, Object JavaDoc[] args,
90                             String JavaDoc[] fields, byte[] state,
91                             byte[] collaboration)
92     {
93         logger.debug(this.name+".instantiates("+name+")");
94         try {
95             return delegate.instantiates(name, className, args, fields, state,
96                                          collaboration);
97         } catch (RemoteException JavaDoc e) {
98             e.printStackTrace();
99         }
100       
101         return 0;
102     }
103
104
105     /**
106      * Copy a state into a base object.
107      *
108      * @param index the callee index (see org.objectweb.jac.core.JacObject)
109      * @param fields the object fields that are part of the state
110      * @param state the state to copy
111      * @param collaboration the collaboration of the client
112      */

113     
114     public void copy(String JavaDoc name, int index, String JavaDoc[] fields, byte[] state,
115                      byte[] collaboration) {
116
117         try {
118             delegate.copy( name, index, fields, state, collaboration );
119         } catch(RemoteException JavaDoc e) {
120             e.printStackTrace();
121         }
122     }
123    
124    
125     /**
126      * Invoke a method on a base object.
127      *
128      * The base object is the remote counterpart of a local object
129      * that has been remotely instantiated by the org.objectweb.jac.dist.Distd daemon.
130      *
131      * @param index the callee index (see org.objectweb.jac.core.JacObject)
132      * @param methodName the callee method name
133      * @param methodArgs the callee method arguments
134      * @return the result
135      */

136    
137     public byte[] invoke(int index, String JavaDoc methodName,
138                          byte[] methodArgs, byte[] collaboration) {
139       
140         try {
141             return delegate.invoke(index, methodName, methodArgs, collaboration);
142         } catch(RemoteException JavaDoc e) {
143             e.printStackTrace();
144         }
145       
146         return null;
147     }
148
149     public byte[] invokeRoleMethod(int index,
150                                    String JavaDoc methodName,
151                                    byte[] methodArgs,
152                                    byte[] collaboration)
153     {
154         try {
155             return delegate.invokeRoleMethod(index,methodName,
156                                              methodArgs,collaboration);
157         } catch(RemoteException JavaDoc e) {
158             e.printStackTrace();
159         }
160         return null;
161     }
162
163     public byte[] getByteCodeFor(String JavaDoc className) {
164         try {
165             return delegate.getByteCodeFor(className);
166         } catch(RemoteException JavaDoc e) {
167             e.printStackTrace();
168         }
169         return null;
170     }
171
172     /**
173      * Returns a remote reference on the object corresponding to the
174      * given name. */

175
176     public RemoteRef bindTo(String JavaDoc name) {
177         RemoteRef result=null;
178         try {
179             logger.debug("binding to "+name+" (delegate="+delegate+")");
180             result=delegate.bindTo( name );
181             logger.debug("result is "+result);
182         } catch(RemoteException JavaDoc e) {
183             e.printStackTrace();
184         }
185         return result;
186     }
187
188
189     // /**
190
// * Get a client stub wrapping chain for a given object.
191
// *
192
// * This method is called whenever a daemon receives as a parameter
193
// * a reference to a remote object, to get the wrapping chain
194
// * (for instance an authentication wrapper, a verbose wrapper, ...)
195
// * needed to create a client stub for this remote reference.
196
// *
197
// * @param index the base object index (see org.objectweb.jac.core.JacObject)
198
// * @return the client stub wrapping chain as a serialized object
199
// */
200
//
201
// public Vector getClientStubWrappingChain( int index ) {
202
//
203
// try {
204
// return delegate.getClientStubWrappingChain( index );
205
// }
206
// catch( RemoteException e ) { e.printStackTrace(); }
207
//
208
// return null;
209
// }
210

211 }
212
Popular Tags