1
/* ActivatableServerRef.java -- The activatable server reference
2
Copyright (C) 2006 Free Software Foundation, Inc.
4
This file is part of GNU Classpath.
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING. If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library. Thus, the terms and
23
conditions of the GNU General Public License cover the whole
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module. An independent module is a module which is not derived from
33
or based on this library. If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so. If you do not wish to do so, delete this
36
exception statement from your version. */
39
package gnu.java.rmi.server;
41
import java.io.IOException;
42
import java.io.ObjectInput;
43
import java.io.ObjectOutput;
44
import java.rmi.Remote;
45
import java.rmi.RemoteException;
46
import java.rmi.activation.ActivationID;
47
import java.rmi.server.ObjID;
48
import java.rmi.server.RMIServerSocketFactory;
49
import java.rmi.server.RemoteStub;
50
import java.rmi.server.Skeleton;
53
* The activatable server reference works like UnicastServerReference, but it
54
* additionally activates the associated object on demand, during the first
55
* incoming call. When UnicastServerReference takes the working reference,
56
* the ActivatableServerRef takes the activation id instead.
58
* @author Audrius Meskauskas (Audriusa@Bioinformatics.org)
60
public class ActivatableServerRef extends UnicastServerRef
63
* Use SVUID for interoperability
65
private static final long serialVersionUID = 1;
68
* The object activation id.
70
public ActivationID actId;
73
* Used by serialization only
75
public ActivatableServerRef()
81
* Create the new activatable server reference that will activate object on
82
* the first call using the given activation id.
84
public ActivatableServerRef(ObjID id, ActivationID anId, int aPort,
85
RMIServerSocketFactory ssFactory)
86
throws RemoteException
88
super(id, aPort, ssFactory);
91
// The object ID will be placed in the object map and should deliver
92
// incoming call to {@link #incommingMessageCall}. The object itself
94
UnicastServer.exportActivatableObject(this);
98
* Inactivate the object (stop the server).
100
public void inactivate()
102
manager.stopServer();
106
* Activate the object (normally during the first call).
108
protected void activate() throws RemoteException
112
Remote self = actId.activate(false);
114
// This will call UnicastServer.exportObject, replacing null by
115
// the activated object (self) in the object map.
118
catch (RemoteException rex)
122
catch (Exception exc)
124
RemoteException rx = new RemoteException("Activation failed.");
131
* If the object is not active, activate it first.
133
public Object incomingMessageCall(UnicastConnection conn, int method,
134
long hash) throws Exception
138
return super.incomingMessageCall(conn, method, hash);
142
* Export object and ensure it is present in the server activation table
145
public Remote exportObject(Remote obj) throws RemoteException
147
Remote r = super.exportObject(obj);
148
UnicastServer.registerActivatable(this);
153
* Export object and ensure it is present in the server activation table as
156
* @param aClass the class being exported, must implement Remote.
158
public Remote exportClass(Class aClass) throws RemoteException
160
if (!Remote.class.isAssignableFrom(aClass))
161
throw new InternalError(aClass.getName()+" must implement Remote");
165
ClassLoader loader =aClass.getClassLoader();
167
// Stubs are always searched for the bootstrap classes that may have
168
// obsolete pattern and may still need also skeletons.
170
ignoreStubs = "false";
172
ignoreStubs = System.getProperty("java.rmi.server.ignoreStubClasses",
175
if (! ignoreStubs.equals("true"))
177
// Find and install the stub
180
// where ist the _Stub? (check superclasses also)
181
Class expCls = expCls = findStubSkelClass(cls);
185
stub = (RemoteStub) getHelperClass(expCls, "_Stub");
186
// Find and install the skeleton (if there is one)
187
skel = (Skeleton) getHelperClass(expCls, "_Skel");
192
stub = createProxyStub(aClass, this);
194
// Build hash of methods which may be called.
195
buildMethodHash(aClass, true);
197
UnicastServer.registerActivatable(this);
202
* Get the referencing class.
204
public String getRefClass(ObjectOutput out)
206
return "ActivatableRef";
210
* Read the content from the input stream.
212
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
214
super.readExternal(in);
215
actId = (ActivationID) in.readObject();
219
* Write the content to the output stream.
221
public void writeExternal(ObjectOutput out) throws IOException
223
super.writeExternal(out);
224
out.writeObject(actId);