001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.transport.discovery;
018    
019    import java.io.IOException;
020    import java.net.URI;
021    import java.util.HashMap;
022    import java.util.Map;
023    
024    import org.apache.activemq.transport.Transport;
025    import org.apache.activemq.transport.TransportServer;
026    import org.apache.activemq.transport.failover.FailoverTransportFactory;
027    import org.apache.activemq.util.IntrospectionSupport;
028    import org.apache.activemq.util.URISupport.CompositeData;
029    
030    /**
031     * @version $Revision$
032     */
033    public class DiscoveryTransportFactory extends FailoverTransportFactory {
034            
035        public Transport createTransport(CompositeData compositData) throws IOException {
036            Map<String, String> parameters = new HashMap<String, String>(compositData.getParameters());
037            DiscoveryTransport transport = new DiscoveryTransport(createTransport(parameters));
038    
039            DiscoveryAgent discoveryAgent = DiscoveryAgentFactory.createDiscoveryAgent(compositData.getComponents()[0]);
040            transport.setDiscoveryAgent(discoveryAgent);
041            IntrospectionSupport.setProperties(transport, parameters);
042            transport.setParameters(parameters);
043            return transport;
044        }
045    
046        public TransportServer doBind(URI location) throws IOException {
047            throw new IOException("Invalid server URI: " + location);
048    // try{
049    //            CompositeData compositData=URISupport.parseComposite(location);
050    //            URI[] components=compositData.getComponents();
051    //            if(components.length!=1){
052    //                throw new IOException("Invalid location: "+location
053    //                                +", the location must have 1 and only 1 composite URI in it - components = "
054    //                                +components.length);
055    //            }
056    //            Map parameters=new HashMap(compositData.getParameters());
057    //            DiscoveryTransportServer server=new DiscoveryTransportServer(TransportFactory.bind(value,components[0]));
058    //            IntrospectionSupport.setProperties(server,parameters,"discovery");
059    //            DiscoveryAgent discoveryAgent=DiscoveryAgentFactory.createDiscoveryAgent(server.getDiscovery());
060    //            // Use the host name to configure the group of the discovery agent.
061    //            if(!parameters.containsKey("discovery.group")){
062    //                if(compositData.getHost()!=null){
063    //                    parameters.put("discovery.group",compositData.getHost());
064    //                }
065    //            }
066    //            if(!parameters.containsKey("discovery.brokerName")){
067    //                parameters.put("discovery.brokerName",value);
068    //            }
069    //            IntrospectionSupport.setProperties(discoveryAgent,parameters,"discovery.");
070    //            server.setDiscoveryAgent(discoveryAgent);
071    //            return server;
072    //        }catch(URISyntaxException e){
073    //            throw new IOException("Invalid location: "+location);
074    //        }
075        }
076    
077    }