KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > TR > Connector > TR2InOutRMISkel


1 /**
2  * TR2InOutRMISkel.java is a part of the SOFA project.
3  * This file was created by pepan on 19.3.2003.
4  */

5 package SOFA.SOFAnode.TR.Connector;
6
7 import java.io.IOException JavaDoc;
8 import java.rmi.RemoteException JavaDoc;
9 import java.rmi.server.UnicastRemoteObject JavaDoc;
10
11 import SOFA.Connector.ConnectorTransportException;
12 import SOFA.Connector.Linkable;
13 import SOFA.SOFAnode.TR.ComponentInfo;
14 import SOFA.SOFAnode.TR.TRException;
15 import SOFA.SOFAnode.TR.Impl.BundleImpl;
16
17 /**
18  * @author Petr Panuska
19  */

20 public class TR2InOutRMISkel extends UnicastRemoteObject JavaDoc implements CNTR2InOutRemote, Linkable {
21   private CNTR2InOut target;
22
23   public TR2InOutRMISkel (String JavaDoc url) throws java.rmi.RemoteException JavaDoc, java.net.MalformedURLException JavaDoc, java.rmi.NotBoundException JavaDoc {
24     super();
25     String JavaDoc rmihost = System.getProperty("sofa.rmihost", "localhost");
26     String JavaDoc rmiport = System.getProperty("sofa.rmiport", "1099");
27     // because of remote registering of services
28
// don't be confused with the name '.DeplDockRegistry.RgRMIDock', it has nothing to do with a Depl. Dock
29
// for more info contact Petr Hnetynka
30
SOFA.SOFAnode.Run.DeplDockRegistry.RgRMIDock rg = (SOFA.SOFAnode.Run.DeplDockRegistry.RgRMIDock) java.rmi.Naming.lookup("//" + rmihost + ":" + rmiport + "/RgRMIDock");
31     rg.rebind(url, this);
32   }
33
34   public void link (Object JavaDoc target) {
35     this.target = (CNTR2InOut) target;
36   }
37
38   public void storeBundle (byte[] bundleData) throws RemoteException JavaDoc, TRException {
39     BundleImpl bundle = new BundleImpl();
40     try {
41       bundle._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(bundleData));
42     } catch (IOException JavaDoc e) {
43       throw new ConnectorTransportException("Can't serialize in the 'storeBundle'.", e);
44     }
45     target.storeBundle(bundle);
46   }
47
48   public byte[] getBundle (ComponentInfo[] descs, ComponentInfo[] comps, boolean inferiors) throws RemoteException JavaDoc, TRException {
49     BundleImpl bundle = (BundleImpl) target.getBundle(descs, comps, inferiors);
50     byte[] ret = null;
51     try {
52       cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
53       bundle._write(os);
54       os.close();
55       ret = os.toByteArray();
56     } catch (IOException JavaDoc e) {
57       throw new ConnectorTransportException("Can't serialize in the 'getBundle'.", e);
58     }
59     return ret;
60   }
61
62 /*
63   public byte[] getMetaBundle (ComponentInfo[] descs) throws RemoteException, TRException {
64     return getBundle(descs, null); // uses the getBundle method
65   }
66
67 */

68   public boolean contains (ComponentInfo descrs) throws RemoteException JavaDoc {
69     return target.contains(descrs);
70   }
71
72   public byte[] list () {
73     BundleImpl bundle = (BundleImpl) target.list();
74     byte[] ret = null;
75     try {
76       cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream();
77       bundle._write(os);
78       os.close();
79       ret = os.toByteArray();
80     } catch (IOException JavaDoc e) {
81       throw new ConnectorTransportException("Can't serialize in the 'list'.", e);
82     }
83     return ret;
84   }
85 }
86
Popular Tags