001    /*
002      Copyright (C) 2001 Lionel Seinturier
003    
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful,
010      but WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012      GNU Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser Generaly Public License
015      along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
017    
018    package org.objectweb.jac.core.dist.rmi;
019    
020    import org.objectweb.jac.core.dist.RemoteContainer;
021    import org.objectweb.jac.core.dist.RemoteRef;
022    
023    import java.rmi.RemoteException;
024    import java.rmi.server.UnicastRemoteObject;
025    
026    /**
027     * RMIRemoteContainer is a container for remote objects that can be accessed
028     * with the RMI communication protocol.
029     *
030     * RMIRemoteContainer delegates most of his job to a RemoteContainer.
031     * RMIRemoteContainer instances are created by RMIDistd.
032     *
033     * @author <a href="http://www-src.lip6.fr/homepages/Lionel.Seinturier/index-eng.html">Lionel Seinturier</a>
034     */
035     
036    public class RMIRemoteContainer
037       extends UnicastRemoteObject implements RMIRemoteContainerInterf {
038    
039       /** The remote container to which most of the job is delegated. */
040       protected RemoteContainer delegate;
041       
042       
043       /** Create a new container. */
044       
045       public RMIRemoteContainer() throws RemoteException { 
046          super(); 
047       }
048       
049    
050       /**
051        * Create a new container.
052        *
053        * @param verbose  true if information messages are to be printed.
054        */
055       
056       public RMIRemoteContainer(boolean verbose) throws RemoteException {
057          this();
058          delegate = new RemoteContainer(verbose);
059       }
060       
061       
062       /**
063        * Create a new container.
064        *
065        * @param className  the name of a class to instantiate
066        * @param verbose    true if information messages are to be printed.
067        */
068       
069       public RMIRemoteContainer(String className, boolean verbose)
070          throws RemoteException 
071       {
072          this();
073          delegate = new RemoteContainer(className,verbose);
074       }
075       
076       
077       /**
078        * Getter method for the delegate field.
079        *
080        * @return  the delegate field value
081        */
082       
083       public RemoteContainer getDelegate() { 
084          return delegate; 
085       }
086       
087       
088       /**
089        * This method instantiates a className object.
090        * Clients call it to remotely instantiate an object.
091        * instantiates creates an object and returns its index.
092        * This method is part of the RMIRemoteContainerInterf interface.
093        *
094        * @param className     the class name to instantiate
095        * @param args          initialization arguments for the instantiation
096        * @param fields        the object fields that are part of the state
097        * @param state         the state to copy
098        * @param collaboration the collaboration of the client
099        * @return              the index of the className object
100        */
101       
102       public int instantiates(String name, String className, Object[] args,
103                               String[] fields, byte[] state,
104                               byte[] collaboration)
105          throws RemoteException 
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 name, int index, String[] fields, byte[] state,
127                        byte[] collaboration)
128          throws RemoteException {
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 methodName, 
145                            byte[] methodArgs, byte[] collaboration)
146          throws RemoteException {
147    
148          return delegate.invoke(index, methodName, methodArgs, collaboration);
149       }
150    
151       public byte[] invokeRoleMethod(int index, String methodName, 
152                                      byte[] methodArgs, 
153                                      byte[] collaboration)
154          throws RemoteException {
155    
156          return delegate.invokeRoleMethod(
157             index, methodName, methodArgs, collaboration );
158       }
159    
160       public byte[] getByteCodeFor(String className) throws RemoteException {
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 name) throws RemoteException {
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    }