1 6 7 package SOFA.SOFAnet.Transport.RMI; 8 9 import java.rmi.*; 10 import java.util.*; 11 import SOFA.SOFAnet.Core.NetOps; 12 import SOFA.SOFAnet.Core.ShareOps; 13 import SOFA.SOFAnet.Transport.*; 14 import SOFA.SOFAnet.Repository.NodeInfo; 15 16 26 public class RMITransportClient implements TransportInterface 27 { 28 private Map nodeMap; 29 private NetOps netOps; 30 private ShareOps shareOps; 31 32 33 public RMITransportClient() 34 { 35 System.setSecurityManager(new RMISecurityManager()); 36 nodeMap = Collections.synchronizedMap(new HashMap()); 37 netOps = null; 38 shareOps = null; 39 } 40 41 public void testPush(IOParams params) throws TransportException 42 { 43 RMITransportNodeConnection nodeConnection; 44 45 nodeConnection = getNodeConnection(params.getNodeName()); 46 nodeConnection.testPush(params); 47 48 List otherNodes = params.getOtherNodes(); 49 if (otherNodes != null && otherNodes.size() != 0) 50 { 51 IOParams ioParams = new IOParams(); 52 ioParams.setBundleName(params.getBundleName()); 53 ioParams.setOffer(params.isOffer()); 54 55 Iterator it = otherNodes.iterator(); 56 while (it.hasNext()) 57 { 58 IOParams.OtherNode otherNode = (IOParams.OtherNode)it.next(); 59 60 nodeConnection = getNodeConnection(otherNode.nodeName); 61 nodeConnection.testPush(ioParams); 62 otherNode.errCode = ioParams.getErrCode(); 63 } 64 65 ioParams = null; 66 } 67 } 68 69 public void push(IOParams params) throws TransportException 70 { 71 RMITransportNodeConnection nodeConnection; 72 73 for (;;) 74 { 75 nodeConnection = getNodeConnection(params.getNodeName()); 76 if (nodeConnection.push(params)) break; 77 } 78 79 List otherNodes = params.getOtherNodes(); 80 if (otherNodes != null && otherNodes.size() != 0) 81 { 82 Iterator it = otherNodes.iterator(); 83 while (it.hasNext()) 84 { 85 IOParams.OtherNode otherNode = (IOParams.OtherNode)it.next(); 86 87 IOParams ioParams = new IOParams(); 88 ioParams.setBundleName(params.getBundleName()); 89 ioParams.setBundleData(params.getBundleData()); 90 ioParams.setOffer(params.isOffer()); 91 ioParams.setPriority(params.getPriority()); 92 ioParams.setLicence(otherNode.licence); 93 94 for (;;) 95 { 96 nodeConnection = getNodeConnection(otherNode.nodeName); 97 if (nodeConnection.push(params)) break; 98 } 99 100 ioParams = null; 101 } 102 } 103 } 104 105 public void testPull(IOParams params) throws TransportException 106 { 107 RMITransportNodeConnection nodeConnection = getNodeConnection(params.getNodeName()); 108 nodeConnection.testPull(params); 109 } 110 111 public void pull(IOParams params) throws TransportException 112 { 113 for (;;) 114 { 115 RMITransportNodeConnection nodeConnection = getNodeConnection(params.getNodeName()); 116 if (nodeConnection.pull(params)) break; 117 } 118 } 119 120 public void synchroPull(IOParams params) throws TransportException 121 { 122 RMITransportNodeConnection nodeConnection = getNodeConnection(params.getNodeName()); 123 nodeConnection.synchroPull(params); 124 } 125 126 public void testAcquireShared(IOParams params) throws TransportException 127 { 128 RMITransportNodeConnection nodeConnection = getNodeConnection(params.getNodeName()); 129 nodeConnection.testAcquireShared(params); 130 } 131 132 public void acquireShared(IOParams params) throws TransportException 133 { 134 RMITransportNodeConnection nodeConnection = getNodeConnection(params.getNodeName()); 135 nodeConnection.acquireShared(params); 136 } 137 138 public void canReturnShared(IOParams params) throws TransportException 139 { 140 RMITransportNodeConnection nodeConnection = getNodeConnection(params.getNodeName()); 141 nodeConnection.canReturnShared(params); 142 } 143 144 public void returnShared(IOParams params) throws TransportException 145 { 146 RMITransportNodeConnection nodeConnection = getNodeConnection(params.getNodeName()); 147 nodeConnection.returnShared(params); 148 } 149 150 public void manualReturnShared(IOParams params) throws TransportException 151 { 152 RMITransportNodeConnection nodeConnection = getNodeConnection(params.getNodeName()); 153 nodeConnection.manualReturnShared(params); 154 } 155 156 public void setNetOps(NetOps netOps) 157 { 158 this.netOps = netOps; 159 } 160 161 public void setShareOps(ShareOps shareOps) 162 { 163 this.shareOps = shareOps; 164 } 165 166 NetOps getNetOps() 167 { 168 return netOps; 169 } 170 171 ShareOps getShareOps() 172 { 173 return shareOps; 174 } 175 176 private synchronized RMITransportNodeConnection getNodeConnection(String nodeName) throws TransportException 177 { 178 NodeInfo nodeInfo = new NodeInfo(); 179 try 180 { 181 nodeInfo.setNodeName(nodeName); 182 } 183 catch (NodeInfo.InvalidNodeNameException e) 184 { 185 throw new TransportException("Invalid name of SOFA node: " + nodeName, e); 186 } 187 188 String addrPortString = nodeInfo.getAddressAndPort(); 189 RMITransportNodeConnection nodeConnection = (RMITransportNodeConnection)nodeMap.get(addrPortString); 190 191 if (nodeConnection == null) 192 { 193 nodeConnection = new RMITransportNodeConnection(nodeInfo, this); 194 195 nodeMap.put(addrPortString, nodeConnection); 196 return nodeConnection; 197 } 198 else return nodeConnection; 199 } 200 201 synchronized void removeFromMap(String addrPortString, RMITransportNodeConnection nodeConnection) 202 { 203 RMITransportNodeConnection myNodeConnection = (RMITransportNodeConnection)nodeMap.get(addrPortString); 204 if (myNodeConnection == nodeConnection) nodeMap.remove(addrPortString); 205 } 206 } 207
| Popular Tags
|