Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jac/core/dist/rmi/RMIRemoteContainer.java


1   /*
2   
3     Copyright (C) 2001 Lionel Seinturier
4   
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU Lesser General Public License as
7     published by the Free Software Foundation; either version 2 of the
8     License, or (at your option) any later version.
9   
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU Lesser General Public License for more details.
14  
15    You should have received a copy of the GNU Lesser Generaly Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
18  
19  package jac.core.dist.rmi;
20  
21  import jac.core.dist.RemoteContainer;
22  import jac.core.dist.RemoteRef;
23  
24  import java.rmi.Naming;
25  import java.rmi.RemoteException;
26  import java.rmi.server.UnicastRemoteObject;
27  import java.util.Vector;
28  import jac.core.Collaboration;
29  
30  /**
31   * RMIRemoteContainer is a container for remote objects that can be accessed
32   * with the RMI communication protocol.
33   *
34   * RMIRemoteContainer delegates most of his job to a RemoteContainer.
35   * RMIRemoteContainer instances are created by RMIDistd.
36   *
37   * @version 0.8.1
38   * @author <a href="http://www-src.lip6.fr/homepages/Lionel.Seinturier/index-eng.html">Lionel Seinturier</a>
39   */
40   
41  public class RMIRemoteContainer
42     extends UnicastRemoteObject implements RMIRemoteContainerInterf {
43  
44     /** The remote container to which most of the job is delegated. */
45     protected RemoteContainer delegate;
46     
47     
48     /** Create a new container. */
49     
50     public RMIRemoteContainer() throws RemoteException { super(); }
51     
52  
53     /**
54      * Create a new container.
55      *
56      * @param verbose  true if information messages are to be printed.
57      */
58     
59     public RMIRemoteContainer( boolean verbose ) throws RemoteException {
60     
61        this();
62        delegate = new RemoteContainer(verbose);
63     }
64     
65     
66     /**
67      * Create a new container.
68      *
69      * @param className  the name of a class to instantiate
70      * @param verbose    true if information messages are to be printed.
71      */
72     
73     public RMIRemoteContainer( String className, boolean verbose )
74        throws RemoteException {
75        
76        this();
77        delegate = new RemoteContainer(className,verbose);
78     }
79     
80     
81     /**
82      * Getter method for the delegate field.
83      *
84      * @return  the delegate field value
85      */
86     
87     public RemoteContainer getDelegate() { return delegate; }
88     
89     
90     /**
91      * This method instantiates a className object.
92      * Clients call it to remotely instantiate an object.
93      * instantiates creates an object and returns its index.
94      * This method is part of the RMIRemoteContainerInterf interface.
95      *
96      * @param className     the class name to instantiate
97      * @param args          initialization arguments for the instantiation
98      * @param fields        the object fields that are part of the state
99      * @param state         the state to copy
100     * @param collaboration the collaboration of the client
101     * @return              the index of the className object
102     */
103    
104    public int
105       instantiates(
106          String name, String className, Object[] args,
107          String[] fields, byte[] state,
108          Collaboration collaboration
109       )
110       throws RemoteException {
111 
112       return delegate.instantiates( name, 
113                                     className, 
114                                     args, 
115                                     fields, 
116                                     state, 
117                                     collaboration );
118    }
119 
120 
121    /**
122     * Copy a state into a base object.
123     * This method is part of the RMIRemoteContainerInterf interface.
124     *
125     * @param index         the base object index (see jac.core.JacObject)
126     * @param fields        the object fields that are part of the state
127     * @param state         the state to copy
128     * @param collaboration the collaboration of the client
129     */
130     
131    public void copy( String name, int index, String[] fields, byte[] state,
132                      Collaboration collaboration )
133       throws RemoteException {
134       delegate.copy( name, index, fields, state, collaboration );
135    }
136    
137    /**
138     * Invoke a method on a base object.
139     * The base object is the remote counterpart of a local object
140     * that has been remotely instantiated by a remote container.
141     * This method is part of the RMIRemoteContainerInterf interface.
142     *
143     * @param index       the callee index (see jac.core.JacObject)
144     * @param methodName  the callee method name
145     * @param methodArgs  the callee method arguments
146     * @return            the result
147     */
148    
149    public byte[] invoke( int index, String methodName, byte[] methodArgs, Collaboration collaboration )
150       throws RemoteException {
151 
152       return delegate.invoke( index, methodName, methodArgs, collaboration );
153    }
154 
155 
156    public byte[] getByteCodeFor ( String className ) throws RemoteException {
157       return delegate.getByteCodeFor( className );
158    }
159 
160 
161    /**
162     * Returns a remote reference on the object corresponding to the
163     * given name. */
164 
165    public RemoteRef bindTo ( String name ) throws RemoteException {
166       return delegate.bindTo( name );
167    }
168 
169 
170 //    /**
171 //     * Get a client stub wrapping chain for a given object.
172 //     * This method is part of the RMIRemoteContainerInterf interface.
173 //     *
174 //     * This method is called whenever a daemon receives as a parameter
175 //     * a reference to a remote object, to get the wrapping chain
176 //     * (for instance an authentication wrapper, a verbose wrapper, ...)
177 //     * needed to create a client stub for this remote reference.
178 //     *
179 //     * @param index  the base object index (see jac.core.JacObject)
180 //     * @return       the client stub wrapping chain as a serialized object
181 //     */
182 //    
183 //    public Vector getClientStubWrappingChain( int index )
184 //       throws RemoteException {
185 //    
186 //       return delegate.getClientStubWrappingChain(index);
187 //    }
188 
189 }