Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » transport » discovery » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.activemq.transport.discovery;
   18   
   19   import java.io.IOException;
   20   import java.net.URI;
   21   import java.util.concurrent.ConcurrentHashMap;
   22   
   23   import org.apache.activemq.util.FactoryFinder;
   24   import org.apache.activemq.util.IOExceptionSupport;
   25   
   26   public abstract class DiscoveryAgentFactory {
   27   
   28       private static final FactoryFinder DISCOVERY_AGENT_FINDER = new FactoryFinder("META-INF/services/org/apache/activemq/transport/discoveryagent/");
   29       private static final ConcurrentHashMap<String, DiscoveryAgentFactory> DISCOVERY_AGENT_FACTORYS = new ConcurrentHashMap<String, DiscoveryAgentFactory>();
   30   
   31       /**
   32        * @param uri
   33        * @return
   34        * @throws IOException
   35        */
   36       private static DiscoveryAgentFactory findDiscoveryAgentFactory(URI uri) throws IOException {
   37           String scheme = uri.getScheme();
   38           if (scheme == null) {
   39               throw new IOException("DiscoveryAgent scheme not specified: [" + uri + "]");
   40           }
   41           DiscoveryAgentFactory daf = DISCOVERY_AGENT_FACTORYS.get(scheme);
   42           if (daf == null) {
   43               // Try to load if from a META-INF property.
   44               try {
   45                   daf = (DiscoveryAgentFactory)DISCOVERY_AGENT_FINDER.newInstance(scheme);
   46                   DISCOVERY_AGENT_FACTORYS.put(scheme, daf);
   47               } catch (Throwable e) {
   48                   throw IOExceptionSupport.create("DiscoveryAgent scheme NOT recognized: [" + scheme + "]", e);
   49               }
   50           }
   51           return daf;
   52       }
   53   
   54       public static DiscoveryAgent createDiscoveryAgent(URI uri) throws IOException {
   55           DiscoveryAgentFactory tf = findDiscoveryAgentFactory(uri);
   56           return tf.doCreateDiscoveryAgent(uri);
   57   
   58       }
   59   
   60       protected abstract DiscoveryAgent doCreateDiscoveryAgent(URI uri) throws IOException;
   61       // {
   62       // try {
   63       // String type = ( uri.getScheme() == null ) ? uri.getPath() :
   64       // uri.getScheme();
   65       // DiscoveryAgent rc = (DiscoveryAgent)
   66       // discoveryAgentFinder.newInstance(type);
   67       // Map options = URISupport.parseParamters(uri);
   68       // IntrospectionSupport.setProperties(rc, options);
   69       // if( rc.getClass() == SimpleDiscoveryAgent.class ) {
   70       // CompositeData data = URISupport.parseComposite(uri);
   71       // ((SimpleDiscoveryAgent)rc).setServices(data.getComponents());
   72       // }
   73       // return rc;
   74       // } catch (Throwable e) {
   75       // throw IOExceptionSupport.create("Could not create discovery agent: "+uri,
   76       // e);
   77       // }
   78       // }
   79   }

Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » transport » discovery » [javadoc | source]