KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.objectweb.jac.core.dist.RemoteContainer;
21 import org.objectweb.jac.core.dist.RemoteRef;
22
23 import java.rmi.RemoteException JavaDoc;
24 import java.rmi.server.UnicastRemoteObject JavaDoc;
25
26 /**
27  * RMIRemoteContainer is a container for remote objects that can be accessed
28  * with the RMI communication protocol.
29  *
30  * RMIRemoteContainer delegates most of his job to a RemoteContainer.
31  * RMIRemoteContainer instances are created by RMIDistd.
32  *
33  * @author <a HREF="http://www-src.lip6.fr/homepages/Lionel.Seinturier/index-eng.html">Lionel Seinturier</a>
34  */

35  
36 public class RMIRemoteContainer
37    extends UnicastRemoteObject JavaDoc implements RMIRemoteContainerInterf {
38
39    /** The remote container to which most of the job is delegated. */
40    protected RemoteContainer delegate;
41    
42    
43    /** Create a new container. */
44    
45    public RMIRemoteContainer() throws RemoteException JavaDoc {
46       super();
47    }
48    
49
50    /**
51     * Create a new container.
52     *
53     * @param verbose true if information messages are to be printed.
54     */

55    
56    public RMIRemoteContainer(boolean verbose) throws RemoteException JavaDoc {
57       this();
58       delegate = new RemoteContainer(verbose);
59    }
60    
61    
62    /**
63     * Create a new container.
64     *
65     * @param className the name of a class to instantiate
66     * @param verbose true if information messages are to be printed.
67     */

68    
69    public RMIRemoteContainer(String JavaDoc className, boolean verbose)
70       throws RemoteException JavaDoc
71    {
72       this();
73       delegate = new RemoteContainer(className,verbose);
74    }
75    
76    
77    /**
78     * Getter method for the delegate field.
79     *
80     * @return the delegate field value
81     */

82    
83    public RemoteContainer getDelegate() {
84       return delegate;
85    }
86    
87    
88    /**
89     * This method instantiates a className object.
90     * Clients call it to remotely instantiate an object.
91     * instantiates creates an object and returns its index.
92     * This method is part of the RMIRemoteContainerInterf interface.
93     *
94     * @param className the class name to instantiate
95     * @param args initialization arguments for the instantiation
96     * @param fields the object fields that are part of the state
97     * @param state the state to copy
98     * @param collaboration the collaboration of the client
99     * @return the index of the className object
100     */

101    
102    public int instantiates(String JavaDoc name, String JavaDoc className, Object JavaDoc[] args,
103                            String JavaDoc[] fields, byte[] state,
104                            byte[] collaboration)
105       throws RemoteException JavaDoc
106    {
107       return delegate.instantiates(name,
108                                    className,
109                                    args,
110                                    fields,
111                                    state,
112                                    collaboration);
113    }
114
115
116    /**
117     * Copy a state into a base object.
118     * This method is part of the RMIRemoteContainerInterf interface.
119     *
120     * @param index the base object index (see org.objectweb.jac.core.JacObject)
121     * @param fields the object fields that are part of the state
122     * @param state the state to copy
123     * @param collaboration the collaboration of the client
124     */

125     
126    public void copy(String JavaDoc name, int index, String JavaDoc[] fields, byte[] state,
127                     byte[] collaboration)
128       throws RemoteException JavaDoc {
129       delegate.copy(name, index, fields, state, collaboration);
130    }
131    
132    /**
133     * Invoke a method on a base object.
134     * The base object is the remote counterpart of a local object
135     * that has been remotely instantiated by a remote container.
136     * This method is part of the RMIRemoteContainerInterf interface.
137     *
138     * @param index the callee index (see org.objectweb.jac.core.JacObject)
139     * @param methodName the callee method name
140     * @param methodArgs the callee method arguments
141     * @return the result
142     */

143    
144    public byte[] invoke(int index, String JavaDoc methodName,
145                         byte[] methodArgs, byte[] collaboration)
146       throws RemoteException JavaDoc {
147
148       return delegate.invoke(index, methodName, methodArgs, collaboration);
149    }
150
151    public byte[] invokeRoleMethod(int index, String JavaDoc methodName,
152                                   byte[] methodArgs,
153                                   byte[] collaboration)
154       throws RemoteException JavaDoc {
155
156       return delegate.invokeRoleMethod(
157          index, methodName, methodArgs, collaboration );
158    }
159
160    public byte[] getByteCodeFor(String JavaDoc className) throws RemoteException JavaDoc {
161       return delegate.getByteCodeFor(className);
162    }
163
164
165    /**
166     * Returns a remote reference on the object corresponding to the
167     * given name. */

168
169    public RemoteRef bindTo (String JavaDoc name) throws RemoteException JavaDoc {
170       return delegate.bindTo(name);
171    }
172
173
174 // /**
175
// * Get a client stub wrapping chain for a given object.
176
// * This method is part of the RMIRemoteContainerInterf interface.
177
// *
178
// * This method is called whenever a daemon receives as a parameter
179
// * a reference to a remote object, to get the wrapping chain
180
// * (for instance an authentication wrapper, a verbose wrapper, ...)
181
// * needed to create a client stub for this remote reference.
182
// *
183
// * @param index the base object index (see org.objectweb.jac.core.JacObject)
184
// * @return the client stub wrapping chain as a serialized object
185
// */
186
//
187
// public Vector getClientStubWrappingChain( int index )
188
// throws RemoteException {
189
//
190
// return delegate.getClientStubWrappingChain(index);
191
// }
192

193 }
194
Popular Tags