Changeset 59
- Timestamp:
- 06/26/13 10:01:10 (11 years ago)
- Location:
- trunk
- Files:
-
- 2 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/main/java/omq/client/proxy/Proxymq.java
r58 r59 8 8 import java.util.Collection; 9 9 import java.util.HashMap; 10 import java.util.Hashtable;11 10 import java.util.Map; 12 11 import java.util.Properties; … … 25 24 import omq.common.util.ParameterQueue; 26 25 import omq.common.util.Serializer; 27 import omq.exception.NoContainsInstanceException;28 26 import omq.exception.OmqException; 29 27 import omq.exception.RetryException; … … 50 48 private static final Logger logger = Logger.getLogger(Proxymq.class.getName()); 51 49 private static final String multi = "multi#"; 52 private static Map<String, Object> proxies = new Hashtable<String, Object>();53 50 54 51 private String uid; … … 287 284 // Remove the corrId to receive new replies 288 285 resp = serializer.deserializeResponse(results.remove(corrId), actualType); 289 System.out.println("/n/n/n/n/nResult type: "+resp.getResult()+" /n/n/n/n/n");290 286 Array.set(array, i, resp.getResult()); 291 287 } … … 297 293 298 294 return array; 299 }300 301 /**302 *303 * @param reference304 * RemoteObject reference305 * @return true if the proxy has been created before or false in the other306 * case307 */308 public static boolean containsProxy(String reference) {309 return proxies.containsKey(reference);310 }311 312 /**313 *314 * @param reference315 * RemoteObject reference316 * @return a proxy instance317 * @throws NoContainsInstanceException318 */319 public static Object getInstance(String reference) throws NoContainsInstanceException {320 if (!containsProxy(reference)) {321 throw new NoContainsInstanceException(reference);322 }323 return proxies.get(reference);324 295 } 325 296 … … 341 312 */ 342 313 public static Object newProxyInstance(ClassLoader loader, Class<?>[] interfaces, Proxymq proxy) { 343 if (proxies.containsKey(proxy.getRef())) { 344 return proxies.get(proxy.getRef()); 345 } 346 Object value = Proxy.newProxyInstance(loader, interfaces, proxy); 347 proxies.put(proxy.getRef(), value); 348 return value; 314 return Proxy.newProxyInstance(loader, interfaces, proxy); 349 315 } 350 316 … … 359 325 } 360 326 361 public static void stopProxy() {362 proxies = new HashMap<String, Object>();363 }364 365 public static Map<String, Object> getProxies() {366 return proxies;367 }368 369 public static void setProxies(Map<String, Object> proxies) {370 Proxymq.proxies = proxies;371 }372 373 327 @Override 374 328 public String getRef() { -
trunk/src/main/java/omq/common/broker/Broker.java
r54 r59 4 4 import java.net.URL; 5 5 import java.util.HashMap; 6 import java.util.Hashtable; 6 7 import java.util.Map; 7 8 import java.util.Properties; … … 44 45 private Properties environment = null; 45 46 private Map<String, RemoteObject> remoteObjs; 47 private Map<String, Object> proxies = new Hashtable<String, Object>(); 46 48 47 49 public Broker(Properties env) throws Exception { … … 71 73 responseListener.kill(); 72 74 eventDispatcher.kill(); 73 Proxymq.stopProxy();75 //TODO proxies = null; ?? 74 76 } 75 77 // Stop all the remote objects working … … 123 125 124 126 @SuppressWarnings("unchecked") 125 public <T extends Remote> T lookup(String reference, Class<T> contract) throws RemoteException {127 public synchronized <T extends Remote> T lookup(String reference, Class<T> contract) throws RemoteException { 126 128 try { 127 129 … … 131 133 } 132 134 133 if (! Proxymq.containsProxy(reference)) {135 if (!proxies.containsKey(reference)) { 134 136 Proxymq proxy = new Proxymq(reference, contract, this); 135 137 Class<?>[] array = { contract }; 136 return (T) Proxymq.newProxyInstance(contract.getClassLoader(), array, proxy); 138 Object newProxy = Proxymq.newProxyInstance(contract.getClassLoader(), array, proxy); 139 proxies.put(reference, newProxy); 140 return (T) newProxy; 137 141 } 138 return (T) Proxymq.getInstance(reference);142 return (T) proxies.get(reference); 139 143 140 144 } catch (Exception e) {
Note: See TracChangeset
for help on using the changeset viewer.