1 18 package org.apache.activemq.transport.discovery; 19 20 import java.io.IOException ; 21 import java.net.URI ; 22 23 import org.apache.activemq.util.FactoryFinder; 24 import org.apache.activemq.util.IOExceptionSupport; 25 26 import java.util.concurrent.ConcurrentHashMap ; 27 28 public abstract class DiscoveryAgentFactory { 29 30 static final private FactoryFinder discoveryAgentFinder = new FactoryFinder("META-INF/services/org/apache/activemq/transport/discoveryagent/"); 31 static final private ConcurrentHashMap discoveryAgentFactorys = new ConcurrentHashMap (); 32 33 38 private static DiscoveryAgentFactory findDiscoveryAgentFactory(URI uri) throws IOException { 39 String scheme = uri.getScheme(); 40 if( scheme == null ) 41 throw new IOException ("DiscoveryAgent scheme not specified: [" + uri + "]"); 42 DiscoveryAgentFactory daf = (DiscoveryAgentFactory) discoveryAgentFactorys.get(scheme); 43 if (daf == null) { 44 try { 46 daf = (DiscoveryAgentFactory) discoveryAgentFinder.newInstance(scheme); 47 discoveryAgentFactorys.put(scheme, daf); 48 } 49 catch (Throwable e) { 50 throw IOExceptionSupport.create("DiscoveryAgent scheme NOT recognized: [" + scheme + "]", e); 51 } 52 } 53 return daf; 54 } 55 56 public static DiscoveryAgent createDiscoveryAgent(URI uri) throws IOException { 57 DiscoveryAgentFactory tf = findDiscoveryAgentFactory(uri); 58 return tf.doCreateDiscoveryAgent(uri); 59 60 } 61 62 abstract protected DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException ; 63 } 79 | Popular Tags |