Changeset 59 for trunk


Ignore:
Timestamp:
06/26/13 10:01:10 (11 years ago)
Author:
stoda
Message:

private static proxies in Proxymq deleted -> non static proxies moved to Broker

Location:
trunk
Files:
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/main/java/omq/client/proxy/Proxymq.java

    r58 r59  
    88import java.util.Collection;
    99import java.util.HashMap;
    10 import java.util.Hashtable;
    1110import java.util.Map;
    1211import java.util.Properties;
     
    2524import omq.common.util.ParameterQueue;
    2625import omq.common.util.Serializer;
    27 import omq.exception.NoContainsInstanceException;
    2826import omq.exception.OmqException;
    2927import omq.exception.RetryException;
     
    5048        private static final Logger logger = Logger.getLogger(Proxymq.class.getName());
    5149        private static final String multi = "multi#";
    52         private static Map<String, Object> proxies = new Hashtable<String, Object>();
    5350
    5451        private String uid;
     
    287284                                // Remove the corrId to receive new replies
    288285                                resp = serializer.deserializeResponse(results.remove(corrId), actualType);
    289                                 System.out.println("/n/n/n/n/nResult type: "+resp.getResult()+" /n/n/n/n/n");
    290286                                Array.set(array, i, resp.getResult());
    291287                        }
     
    297293
    298294                return array;
    299         }
    300 
    301         /**
    302          *
    303          * @param reference
    304          *            RemoteObject reference
    305          * @return true if the proxy has been created before or false in the other
    306          *         case
    307          */
    308         public static boolean containsProxy(String reference) {
    309                 return proxies.containsKey(reference);
    310         }
    311 
    312         /**
    313          *
    314          * @param reference
    315          *            RemoteObject reference
    316          * @return a proxy instance
    317          * @throws NoContainsInstanceException
    318          */
    319         public static Object getInstance(String reference) throws NoContainsInstanceException {
    320                 if (!containsProxy(reference)) {
    321                         throw new NoContainsInstanceException(reference);
    322                 }
    323                 return proxies.get(reference);
    324295        }
    325296
     
    341312         */
    342313        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);
    349315        }
    350316
     
    359325        }
    360326
    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 
    373327        @Override
    374328        public String getRef() {
  • trunk/src/main/java/omq/common/broker/Broker.java

    r54 r59  
    44import java.net.URL;
    55import java.util.HashMap;
     6import java.util.Hashtable;
    67import java.util.Map;
    78import java.util.Properties;
     
    4445        private Properties environment = null;
    4546        private Map<String, RemoteObject> remoteObjs;
     47        private Map<String, Object> proxies = new Hashtable<String, Object>();
    4648
    4749        public Broker(Properties env) throws Exception {
     
    7173                        responseListener.kill();
    7274                        eventDispatcher.kill();
    73                         Proxymq.stopProxy();
     75                        //TODO proxies = null; ??
    7476                }
    7577                // Stop all the remote objects working
     
    123125
    124126        @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 {
    126128                try {
    127129
     
    131133                        }
    132134
    133                         if (!Proxymq.containsProxy(reference)) {
     135                        if (!proxies.containsKey(reference)) {
    134136                                Proxymq proxy = new Proxymq(reference, contract, this);
    135137                                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;
    137141                        }
    138                         return (T) Proxymq.getInstance(reference);
     142                        return (T) proxies.get(reference);
    139143
    140144                } catch (Exception e) {
Note: See TracChangeset for help on using the changeset viewer.