1 2 package SOFA.Connector.Boot; 3 4 import SOFA.Connector.ConnectorTransportException; 5 6 10 public class DeplDockRMISkel extends java.rmi.server.UnicastRemoteObject implements CNDeplDockRemote, SOFA.Connector.Linkable { 11 12 private CNDeplDock tgt = null; 13 14 public DeplDockRMISkel(String url) throws java.rmi.RemoteException , java.net.MalformedURLException , java.rmi.NotBoundException { 15 super(); 16 String rmihost = System.getProperty("sofa.rmihost", "localhost"); 17 String rmiport = System.getProperty("sofa.rmiport", "1099"); 18 SOFA.SOFAnode.Run.DeplDockRegistry.RgRMIDock rg = (SOFA.SOFAnode.Run.DeplDockRegistry.RgRMIDock) java.rmi.Naming.lookup("//"+rmihost+":"+rmiport+"/RgRMIDock"); 19 rg.rebind("/SOFA/Connectors/Boot/DeplDockRMISkel/"+url, this); 20 } 22 23 public void link(Object target) { 24 tgt = (CNDeplDock) target; 25 } 26 27 public byte[][] describeUnderlyingEnvironment() throws java.rmi.RemoteException { 28 SOFA.SOFAnode.Run.Deployment.TechnologyDescriptor[] td = tgt.describeUnderlyingEnvironment(); 29 byte[][] ret = new byte [td.length] []; 30 try { 31 for (int i=0; i<td.length; i++) { 32 cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream(); 33 td[i]._write(os); 34 ret[i] = os.toByteArray(); 35 } 36 } catch (java.io.IOException e) { 37 throw new ConnectorTransportException("Can't serialize in the describeUnderlyingEnvironment.", e); 38 } 39 return ret; 40 } 41 42 public byte[] instantiate(byte[] dd, String name) throws SOFA.SOFAnode.Run.Deployment.DeploymentException, java.rmi.RemoteException { 43 SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl ddr = new SOFA.SOFAnode.Run.Deployment.DeploymentDescriptorImpl(); 44 try { 45 ddr._read(new cz.cuni.sofa.lib.Impl.ByteArrayInputStream(dd)); 46 } catch (java.io.IOException e) { 47 throw new ConnectorTransportException("Can't serialize in the instantiate.", e); 48 } 49 50 SOFA.Connector.Reference ref = tgt.instantiate(ddr, name); 51 52 ref = removeLocal(ref); 53 cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = null; 54 try { 55 os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream(); 56 ref._write(os); 57 } catch (java.io.IOException e) { 58 throw new ConnectorTransportException("Can't serialize in the instantiate.", e); 59 } 60 return os.toByteArray(); 61 } 62 63 public byte[] getReference(String name) throws SOFA.SOFAnode.Run.Deployment.DeploymentException, java.rmi.RemoteException { 64 65 SOFA.Connector.Reference ref = tgt.getReference(name); 66 67 ref = removeLocal(ref); 68 cz.cuni.sofa.lib.Impl.ByteArrayOutputStream os = null; 69 try { 70 os = new cz.cuni.sofa.lib.Impl.ByteArrayOutputStream(); 71 ref._write(os); 72 } catch (java.io.IOException e) { 73 throw new ConnectorTransportException("Can't serialize in the getReference.", e); 74 } 75 return os.toByteArray(); 76 } 77 78 79 public String [] namesOfAllRunningComponents() { 80 return tgt.namesOfAllRunningComponents(); 81 } 82 83 public String [] namesOfAllRunningApplications() { 84 return tgt.namesOfAllRunningApplications(); 85 } 86 87 public void removeComponent(String name) throws SOFA.SOFAnode.Run.Deployment.DeploymentException, java.rmi.RemoteException { 88 tgt.removeComponent(name); 89 } 90 91 92 public static SOFA.Connector.Reference removeLocal(SOFA.Connector.Reference ref) { 93 boolean b = false; 94 for(int i=0; i<ref.profiles.length; i++) { 95 if (ref.profiles[i] instanceof SOFA.Connector.ECG.Profiles.LocalProfile) { 96 b = true; 97 } 98 } 99 if (b) { 100 SOFA.Connector.TaggedProfile[] p = new SOFA.Connector.TaggedProfile [ref.profiles.length]; 101 int j = 0; 102 for (int i=0; i<ref.profiles.length; i++) { 103 if (!(ref.profiles[i] instanceof SOFA.Connector.ECG.Profiles.LocalProfile)) { 104 p[j] = ref.profiles[i]; 105 j++; 106 } 107 } 108 ref.profiles = p; 109 } 110 return ref; 111 } 112 } 113 | Popular Tags |