001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: package java.rmi.activation;
020:
021: import java.rmi.MarshalledObject;
022: import java.rmi.NoSuchObjectException;
023: import java.rmi.Remote;
024: import java.rmi.RemoteException;
025: import java.rmi.server.RMIClientSocketFactory;
026: import java.rmi.server.RMIServerSocketFactory;
027: import java.rmi.server.RemoteObject;
028: import java.rmi.server.RemoteServer;
029: import org.apache.harmony.rmi.common.RMILog;
030: import org.apache.harmony.rmi.internal.nls.Messages;
031: import org.apache.harmony.rmi.remoteref.ActivatableServerRef;
032: import org.apache.harmony.rmi.server.ExportManager;
033:
034: public abstract class Activatable extends RemoteServer {
035: private static final long serialVersionUID = -3120617863591563455L;
036:
037: private static final RMILog rlog = RMILog.getActivationLog();
038:
039: private ActivationID id;
040:
041: protected Activatable(String codebase, MarshalledObject data,
042: boolean restart, int port) throws ActivationException,
043: RemoteException {
044: super ();
045: id = exportObject(this , codebase, data, restart, port);
046: }
047:
048: protected Activatable(String codebase, MarshalledObject data,
049: boolean restart, int port, RMIClientSocketFactory csf,
050: RMIServerSocketFactory ssf) throws ActivationException,
051: RemoteException {
052: super ();
053: id = exportObject(this , codebase, data, restart, port, csf, ssf);
054: }
055:
056: protected Activatable(ActivationID id, int port)
057: throws RemoteException {
058: super ();
059: // rmi.log.05=Activatable.<init>[{0}, {1}]
060: rlog.log(RMILog.VERBOSE, Messages.getString(
061: "rmi.log.05", id, port)); //$NON-NLS-1$
062: this .id = id;
063: // rmi.log.0E=Activatable >>> Ready to export object:
064: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.0E")); //$NON-NLS-1$
065: exportObject(this , id, port);
066: }
067:
068: protected Activatable(ActivationID id, int port,
069: RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
070: throws RemoteException {
071: super ();
072: this .id = id;
073: exportObject(this , id, port, csf, ssf);
074: }
075:
076: protected ActivationID getID() {
077: return id;
078: }
079:
080: public static Remote register(ActivationDesc desc)
081: throws UnknownGroupException, ActivationException,
082: RemoteException {
083: ActivationSystem as = ActivationGroup.getSystem();
084: ActivationID aid = as.registerObject(desc);
085: // rmi.log.0F=aid = {0}
086: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.0F", aid)); //$NON-NLS-1$
087: return org.apache.harmony.rmi.remoteref.ActivatableRef.getStub(
088: desc, aid);
089: }
090:
091: public static ActivationID exportObject(Remote obj,
092: String location, MarshalledObject data, boolean restart,
093: int port, RMIClientSocketFactory csf,
094: RMIServerSocketFactory ssf) throws ActivationException,
095: RemoteException {
096: ActivationDesc adesc = new ActivationDesc(obj.getClass()
097: .getName(), location, data, restart);
098: ActivationID aid = ActivationGroup.getSystem().registerObject(
099: adesc);
100: exportObject(obj, aid, port, csf, ssf);
101: return aid;
102: }
103:
104: public static Remote exportObject(Remote robj, ActivationID aid,
105: int port, RMIClientSocketFactory csf,
106: RMIServerSocketFactory ssf) throws RemoteException {
107: ActivatableServerRef asr = new ActivatableServerRef(aid, port,
108: csf, ssf);
109: return ExportManager.exportObject(robj, asr, false); //asr.exportObject(robj, null, false, true, true);
110: }
111:
112: public static ActivationID exportObject(Remote robj,
113: String location, MarshalledObject data, boolean restart,
114: int port) throws ActivationException, RemoteException {
115: ActivationDesc adesc = new ActivationDesc(robj.getClass()
116: .getName(), location, data, restart);
117: ActivationID aid = ActivationGroup.getSystem().registerObject(
118: adesc);
119: exportObject(robj, aid, port);
120: ActivationGroup curAG = ActivationGroup.getCurrentAG();
121: // rmi.console.00=CurAG = {0}
122: System.out.println(Messages.getString("rmi.console.00", curAG)); //$NON-NLS-1$
123: curAG.activeObject(aid, robj);
124: return aid;
125: }
126:
127: public static Remote exportObject(Remote robj, ActivationID aid,
128: int port) throws RemoteException {
129: // rmi.log.10=Activatable >>> exportObject
130: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.10")); //$NON-NLS-1$
131: ActivatableServerRef asr = new ActivatableServerRef(aid, port);
132: if (robj instanceof Activatable) {
133: ((Activatable) robj).ref = asr;
134: }
135: // rmi.log.11=Activatable >>> ActivatableServerRef={0}
136: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.11", asr)); //$NON-NLS-1$
137: ExportManager.exportObject(robj, asr, false, true, true);
138: // rmi.log.12=Activatable >>> asr after export: {0}
139: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.12", asr)); //$NON-NLS-1$
140: Remote rmt = RemoteObject.toStub(robj);
141: // rmi.log.13=Activatable.exportObject: stub = {0}
142: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.13", rmt)); //$NON-NLS-1$
143: return rmt;
144: }
145:
146: public static boolean inactive(ActivationID aid)
147: throws UnknownObjectException, ActivationException,
148: RemoteException {
149: return ActivationGroup.getCurrentAG().inactiveObject(aid);
150: }
151:
152: public static void unregister(ActivationID aid)
153: throws UnknownObjectException, ActivationException,
154: RemoteException {
155: ActivationGroup.getSystem().unregisterObject(aid);
156: }
157:
158: public static boolean unexportObject(Remote obj, boolean force)
159: throws NoSuchObjectException {
160: return ExportManager.unexportObject(obj, force);
161: }
162:
163: @Override
164: public String toString() {
165: return this .getClass()
166: + ": [ActivationID =" + id + "; Ref =" + ref + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
167: }
168: }
|