KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > server > transport > MarshalOutputStream


1 package org.sapia.ubik.rmi.server.transport;
2 import java.io.IOException JavaDoc;
3 import java.io.ObjectOutputStream JavaDoc;
4 import java.io.OutputStream JavaDoc;
5
6 import org.sapia.ubik.rmi.server.Hub;
7 import org.sapia.ubik.rmi.server.VmId;
8 import org.sapia.ubik.rmi.server.perf.PerfAnalyzer;
9
10
11 /**
12  * This class is used to marshal outgoing requests.
13  *
14  * @see org.sapia.ubik.rmi.server.Server
15  * @see org.sapia.ubik.rmi.server.transport.RmiConnection
16  * @see org.sapia.ubik.rmi.server.transport.TransportProvider
17  *
18  * @author Yanick Duchesne
19  * <dl>
20  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
21  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
22  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
23  * </dl>
24  */

25 public class MarshalOutputStream extends ObjectOutputStream JavaDoc {
26   private VmId _id;
27   private String JavaDoc _transportType;
28   private PerfAnalyzer _perf = PerfAnalyzer.getInstance();
29
30   /**
31    * Constructor for RmiOutputStream.
32    */

33   public MarshalOutputStream(OutputStream JavaDoc os) throws IOException JavaDoc {
34     super(os);
35     super.enableReplaceObject(true);
36   }
37
38   public void setUp(VmId id, String JavaDoc transportType) {
39     _id = id;
40     _transportType = transportType;
41   }
42
43   /**
44    * @see java.io.ObjectOutputStream#replaceObject(Object)
45    */

46   protected Object JavaDoc replaceObject(Object JavaDoc obj) throws IOException JavaDoc {
47     if (obj instanceof java.rmi.Remote JavaDoc) {
48       if (_id == null) {
49         throw new IllegalStateException JavaDoc("VmId not set on " +
50           getClass().getName());
51       }
52
53       if (_perf.isEnabled()) {
54         _perf.getTopic(getClass().getName() + ".StubOutput").start();
55       }
56
57       Object JavaDoc remote = Hub.asRemote(obj, _id, _transportType);
58
59       if (_perf.isEnabled()) {
60         _perf.getTopic(getClass().getName() + ".StubOutput").end();
61       }
62
63       return remote;
64     } else {
65       return obj;
66     }
67   }
68 }
69
Popular Tags