KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > discovery > DiscoveryTransportFactory


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.transport.discovery;
19
20 import java.io.IOException JavaDoc;
21 import java.net.URI JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.apache.activemq.transport.Transport;
26 import org.apache.activemq.transport.TransportServer;
27 import org.apache.activemq.transport.failover.FailoverTransportFactory;
28 import org.apache.activemq.util.IntrospectionSupport;
29 import org.apache.activemq.util.URISupport.CompositeData;
30
31 /**
32  * @version $Revision$
33  */

34 public class DiscoveryTransportFactory extends FailoverTransportFactory {
35         
36     public Transport createTransport(CompositeData compositData) throws IOException JavaDoc {
37         Map JavaDoc parameters = new HashMap JavaDoc(compositData.getParameters());
38         DiscoveryTransport transport = new DiscoveryTransport(createTransport(parameters));
39         
40         DiscoveryAgent discoveryAgent = DiscoveryAgentFactory.createDiscoveryAgent(compositData.getComponents()[0]);
41         transport.setDiscoveryAgent(discoveryAgent);
42         IntrospectionSupport.setProperties(transport,parameters);
43
44         return transport;
45     }
46
47     public TransportServer doBind(String JavaDoc brokerId,URI JavaDoc location) throws IOException JavaDoc{
48         throw new IOException JavaDoc("Invalid server URI: "+location);
49 // try{
50
// CompositeData compositData=URISupport.parseComposite(location);
51
// URI[] components=compositData.getComponents();
52
// if(components.length!=1){
53
// throw new IOException("Invalid location: "+location
54
// +", the location must have 1 and only 1 composite URI in it - components = "
55
// +components.length);
56
// }
57
// Map parameters=new HashMap(compositData.getParameters());
58
// DiscoveryTransportServer server=new DiscoveryTransportServer(TransportFactory.bind(value,components[0]));
59
// IntrospectionSupport.setProperties(server,parameters,"discovery");
60
// DiscoveryAgent discoveryAgent=DiscoveryAgentFactory.createDiscoveryAgent(server.getDiscovery());
61
// // Use the host name to configure the group of the discovery agent.
62
// if(!parameters.containsKey("discovery.group")){
63
// if(compositData.getHost()!=null){
64
// parameters.put("discovery.group",compositData.getHost());
65
// }
66
// }
67
// if(!parameters.containsKey("discovery.brokerName")){
68
// parameters.put("discovery.brokerName",value);
69
// }
70
// IntrospectionSupport.setProperties(discoveryAgent,parameters,"discovery.");
71
// server.setDiscoveryAgent(discoveryAgent);
72
// return server;
73
// }catch(URISyntaxException e){
74
// throw new IOException("Invalid location: "+location);
75
// }
76
}
77
78 }
79
Popular Tags