1 45 package org.exolab.jms.net.orb; 46 47 import java.io.IOException ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutputStream ; 50 import java.io.Serializable ; 51 import java.lang.reflect.Method ; 52 import java.rmi.server.ObjID ; 53 54 import org.exolab.jms.net.connector.Connection; 55 import org.exolab.jms.net.connector.ConnectionContext; 56 import org.exolab.jms.net.connector.ConnectionFactory; 57 import org.exolab.jms.net.connector.Request; 58 import org.exolab.jms.net.connector.ResourceException; 59 import org.exolab.jms.net.connector.Response; 60 import org.exolab.jms.net.proxy.Delegate; 61 import org.exolab.jms.net.uri.InvalidURIException; 62 import org.exolab.jms.net.uri.URIHelper; 63 64 65 72 public class UnicastDelegate implements Delegate, Serializable { 73 74 77 private ObjID _objID; 78 79 82 private String _uri; 83 84 87 private transient Connection _connection; 88 89 92 private transient ConnectionFactory _factory; 93 94 95 98 protected UnicastDelegate() { 99 } 100 101 108 public UnicastDelegate(ObjID objID, String uri, 109 ConnectionFactory factory) { 110 _objID = objID; 111 _uri = uri; 112 _factory = factory; 113 } 114 115 121 public UnicastDelegate(ObjID objID, Connection connection) { 122 _objID = objID; 123 _connection = connection; 124 } 125 126 135 public Object invoke(Method method, Object [] args, long methodID) 136 throws Throwable { 137 Request request = new Request(_objID, method, args, methodID); 138 Response response = getConnection().invoke(request); 139 if (response.isException()) { 140 throw response.getException(); 141 } 142 return response.getObject(); 143 } 144 145 152 protected synchronized Connection getConnection() 153 throws InvalidURIException, ResourceException { 154 if (_connection == null) { 155 _connection = _factory.getConnection(null, URIHelper.parse(_uri)); 156 } 157 return _connection; 158 } 159 160 166 private void writeObject(ObjectOutputStream out) throws IOException { 167 out.defaultWriteObject(); 168 } 169 170 177 private void readObject(ObjectInputStream in) 178 throws ClassNotFoundException , IOException { 179 in.defaultReadObject(); 180 _factory = ConnectionContext.getConnectionFactory(); 181 _connection = ConnectionContext.getConnection(URIHelper.parse(_uri)); 182 } 183 184 } 185 | Popular Tags |