1 |
779 |
jeremybenn |
/* ActivationSystemImpl.java -- implementation of the activation system.
|
2 |
|
|
Copyright (c) 2006 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
5 |
|
|
|
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)
|
9 |
|
|
any later version.
|
10 |
|
|
|
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.
|
15 |
|
|
|
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
|
19 |
|
|
02110-1301 USA.
|
20 |
|
|
|
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
|
24 |
|
|
combination.
|
25 |
|
|
|
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. */
|
37 |
|
|
|
38 |
|
|
package gnu.classpath.tools.rmid;
|
39 |
|
|
|
40 |
|
|
import gnu.classpath.tools.common.Persistent;
|
41 |
|
|
import gnu.java.rmi.activation.ActivationSystemTransient;
|
42 |
|
|
|
43 |
|
|
import java.io.File;
|
44 |
|
|
import java.io.IOException;
|
45 |
|
|
import java.io.ObjectInputStream;
|
46 |
|
|
import java.io.ObjectOutputStream;
|
47 |
|
|
import java.io.Serializable;
|
48 |
|
|
import java.rmi.MarshalledObject;
|
49 |
|
|
import java.rmi.RemoteException;
|
50 |
|
|
import java.rmi.activation.ActivationDesc;
|
51 |
|
|
import java.rmi.activation.ActivationException;
|
52 |
|
|
import java.rmi.activation.ActivationGroupDesc;
|
53 |
|
|
import java.rmi.activation.ActivationGroupID;
|
54 |
|
|
import java.rmi.activation.ActivationID;
|
55 |
|
|
import java.rmi.activation.ActivationInstantiator;
|
56 |
|
|
import java.rmi.activation.ActivationMonitor;
|
57 |
|
|
import java.rmi.activation.ActivationSystem;
|
58 |
|
|
import java.rmi.activation.Activator;
|
59 |
|
|
import java.rmi.activation.UnknownGroupException;
|
60 |
|
|
import java.rmi.activation.UnknownObjectException;
|
61 |
|
|
|
62 |
|
|
/**
|
63 |
|
|
* Implements the rmid activation system.
|
64 |
|
|
*
|
65 |
|
|
* @author Audrius Meskauskas (audriusa@bioinformatics.org)
|
66 |
|
|
*/
|
67 |
|
|
public class ActivationSystemImpl extends ActivationSystemTransient implements
|
68 |
|
|
ActivationSystem, Activator, ActivationMonitor, Serializable
|
69 |
|
|
{
|
70 |
|
|
/**
|
71 |
|
|
* Use for interoperability.
|
72 |
|
|
*/
|
73 |
|
|
private static final long serialVersionUID = 1;
|
74 |
|
|
|
75 |
|
|
/**
|
76 |
|
|
* The singleton instance of this class.
|
77 |
|
|
*/
|
78 |
|
|
public static ActivationSystemImpl singleton2;
|
79 |
|
|
|
80 |
|
|
/**
|
81 |
|
|
* Obtain the singleton instance of this class.
|
82 |
|
|
*
|
83 |
|
|
* @param folder the folder, where the activation system will keep its files.
|
84 |
|
|
* @param cold do the cold start if true, hot (usual) if false.
|
85 |
|
|
*/
|
86 |
|
|
public static ActivationSystem getInstance(File folder, boolean cold)
|
87 |
|
|
{
|
88 |
|
|
if (singleton2 == null)
|
89 |
|
|
singleton2 = new ActivationSystemImpl(folder, cold);
|
90 |
|
|
return singleton2;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
/**
|
94 |
|
|
* Creates the group with transient maps.
|
95 |
|
|
*
|
96 |
|
|
* @param folder
|
97 |
|
|
* the folder, where the activation system will keep its files.
|
98 |
|
|
* @param cold
|
99 |
|
|
* do the cold start if true, hot (usual) if false.
|
100 |
|
|
*/
|
101 |
|
|
protected ActivationSystemImpl(File folder, boolean cold)
|
102 |
|
|
{
|
103 |
|
|
super(new PersistentBidiHashTable(), new PersistentBidiHashTable());
|
104 |
|
|
singleton2 = this;
|
105 |
|
|
((PersistentBidiHashTable) groupDescs).init(
|
106 |
|
|
new File(folder, "asi_objects.data"), cold);
|
107 |
|
|
((PersistentBidiHashTable) descriptions).init(
|
108 |
|
|
new File(folder, "asi_groups.data"), cold);
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
/** @inheritDoc */
|
112 |
|
|
public MarshalledObject activate(ActivationID id, boolean force)
|
113 |
|
|
throws ActivationException, UnknownObjectException, RemoteException
|
114 |
|
|
{
|
115 |
|
|
return super.activate(id, force);
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
/** @inheritDoc */
|
119 |
|
|
public ActivationMonitor activeGroup(ActivationGroupID id,
|
120 |
|
|
ActivationInstantiator group,
|
121 |
|
|
long incarnation)
|
122 |
|
|
throws UnknownGroupException, ActivationException, RemoteException
|
123 |
|
|
{
|
124 |
|
|
return super.activeGroup(id, group, incarnation);
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
/** @inheritDoc */
|
128 |
|
|
public void activeObject(ActivationID id, MarshalledObject obj)
|
129 |
|
|
throws UnknownObjectException, RemoteException
|
130 |
|
|
{
|
131 |
|
|
super.activeObject(id, obj);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
/** @inheritDoc */
|
135 |
|
|
public ActivationDesc getActivationDesc(ActivationID id)
|
136 |
|
|
throws ActivationException, UnknownObjectException, RemoteException
|
137 |
|
|
{
|
138 |
|
|
return super.getActivationDesc(id);
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
public ActivationGroupDesc getActivationGroupDesc(ActivationGroupID groupId)
|
142 |
|
|
throws ActivationException, UnknownGroupException, RemoteException
|
143 |
|
|
{
|
144 |
|
|
return super.getActivationGroupDesc(groupId);
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
/** @inheritDoc */
|
148 |
|
|
public void inactiveGroup(ActivationGroupID groupId, long incarnation)
|
149 |
|
|
throws UnknownGroupException, RemoteException
|
150 |
|
|
{
|
151 |
|
|
super.inactiveGroup(groupId, incarnation);
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
/** @inheritDoc */
|
155 |
|
|
public void inactiveObject(ActivationID id) throws UnknownObjectException,
|
156 |
|
|
RemoteException
|
157 |
|
|
{
|
158 |
|
|
super.inactiveObject(id);
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
/** @inheritDoc */
|
162 |
|
|
public ActivationGroupID registerGroup(ActivationGroupDesc groupDesc)
|
163 |
|
|
throws ActivationException, RemoteException
|
164 |
|
|
{
|
165 |
|
|
return super.registerGroup(groupDesc);
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
/** @inheritDoc */
|
169 |
|
|
public ActivationID registerObject(ActivationDesc desc)
|
170 |
|
|
throws ActivationException, UnknownGroupException, RemoteException
|
171 |
|
|
{
|
172 |
|
|
return super.registerObject(desc);
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
/** @inheritDoc */
|
176 |
|
|
public ActivationDesc setActivationDesc(ActivationID id, ActivationDesc desc)
|
177 |
|
|
throws ActivationException, UnknownObjectException,
|
178 |
|
|
UnknownGroupException, RemoteException
|
179 |
|
|
{
|
180 |
|
|
return super.setActivationDesc(id, desc);
|
181 |
|
|
}
|
182 |
|
|
|
183 |
|
|
/** @inheritDoc */
|
184 |
|
|
public ActivationGroupDesc setActivationGroupDesc(
|
185 |
|
|
ActivationGroupID groupId, ActivationGroupDesc groupDesc)
|
186 |
|
|
throws ActivationException, UnknownGroupException, RemoteException
|
187 |
|
|
{
|
188 |
|
|
return super.setActivationGroupDesc(groupId, groupDesc);
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
/**
|
192 |
|
|
* This method saves the state of the activation system and then
|
193 |
|
|
* terminates in 10 seconds.
|
194 |
|
|
*/
|
195 |
|
|
public void shutdown() throws RemoteException
|
196 |
|
|
{
|
197 |
|
|
super.shutdown();
|
198 |
|
|
System.out.println("Shutdown command received. Will terminate in 10 s");
|
199 |
|
|
Persistent.timer.schedule(new Persistent.ExitTask(), 10000);
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
/** @inheritDoc */
|
203 |
|
|
public void unregisterGroup(ActivationGroupID groupId)
|
204 |
|
|
throws ActivationException, UnknownGroupException, RemoteException
|
205 |
|
|
{
|
206 |
|
|
super.unregisterGroup(groupId);
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
/** @inheritDoc */
|
210 |
|
|
public void unregisterObject(ActivationID id) throws ActivationException,
|
211 |
|
|
UnknownObjectException, RemoteException
|
212 |
|
|
{
|
213 |
|
|
super.unregisterObject(id);
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
/**
|
217 |
|
|
* Read the object from the input stream.
|
218 |
|
|
*
|
219 |
|
|
* @param in the stream to read from
|
220 |
|
|
*
|
221 |
|
|
* @throws IOException if thrown by the stream
|
222 |
|
|
* @throws ClassNotFoundException
|
223 |
|
|
*/
|
224 |
|
|
private void readObject(ObjectInputStream in) throws IOException,
|
225 |
|
|
ClassNotFoundException
|
226 |
|
|
{
|
227 |
|
|
// Read no fields.
|
228 |
|
|
}
|
229 |
|
|
|
230 |
|
|
/**
|
231 |
|
|
* Write the object to the output stream.
|
232 |
|
|
*
|
233 |
|
|
* @param out the stream to write int
|
234 |
|
|
* @throws IOException if thrown by the stream
|
235 |
|
|
* @throws ClassNotFoundException
|
236 |
|
|
*/
|
237 |
|
|
private void writeObject(ObjectOutputStream out) throws IOException,
|
238 |
|
|
ClassNotFoundException
|
239 |
|
|
{
|
240 |
|
|
// Write no fields.
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
}
|