KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > fanout > FanoutTransportFactory


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.fanout;
19
20 import java.io.IOException JavaDoc;
21 import java.net.URI JavaDoc;
22 import java.net.URISyntaxException JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.apache.activemq.transport.MutexTransport;
27 import org.apache.activemq.transport.ResponseCorrelator;
28 import org.apache.activemq.transport.Transport;
29 import org.apache.activemq.transport.TransportFactory;
30 import org.apache.activemq.transport.TransportServer;
31 import org.apache.activemq.transport.discovery.DiscoveryAgent;
32 import org.apache.activemq.transport.discovery.DiscoveryAgentFactory;
33 import org.apache.activemq.transport.discovery.DiscoveryTransport;
34 import org.apache.activemq.util.IntrospectionSupport;
35 import org.apache.activemq.util.URISupport;
36 import org.apache.activemq.util.URISupport.CompositeData;
37
38 public class FanoutTransportFactory extends TransportFactory {
39
40     public Transport doConnect(URI JavaDoc location) throws IOException JavaDoc {
41         try {
42             Transport transport = createTransport(location);
43             transport = new MutexTransport(transport);
44             transport = new ResponseCorrelator(transport);
45             return transport;
46         } catch (URISyntaxException JavaDoc e) {
47             throw new IOException JavaDoc("Invalid location: "+location);
48         }
49     }
50     
51     public Transport doCompositeConnect(URI JavaDoc location) throws IOException JavaDoc {
52         try {
53             return createTransport(location);
54         } catch (URISyntaxException JavaDoc e) {
55             throw new IOException JavaDoc("Invalid location: "+location);
56         }
57     }
58
59     /**
60      * @param location
61      * @return
62      * @throws IOException
63      * @throws URISyntaxException
64      */

65     public Transport createTransport(URI JavaDoc location) throws IOException JavaDoc, URISyntaxException JavaDoc {
66         
67         CompositeData compositData = URISupport.parseComposite(location);
68         Map JavaDoc parameters = new HashMap JavaDoc(compositData.getParameters());
69         DiscoveryTransport transport = new DiscoveryTransport(createTransport(parameters));
70         
71         DiscoveryAgent discoveryAgent = DiscoveryAgentFactory.createDiscoveryAgent(compositData.getComponents()[0]);
72         transport.setDiscoveryAgent(discoveryAgent);
73         
74         return transport;
75
76     }
77
78     public FanoutTransport createTransport(Map JavaDoc parameters) throws IOException JavaDoc {
79         FanoutTransport transport = new FanoutTransport();
80         IntrospectionSupport.setProperties(transport, parameters);
81         return transport;
82     }
83
84     public TransportServer doBind(String JavaDoc brokerId,URI JavaDoc location) throws IOException JavaDoc {
85         throw new IOException JavaDoc("Invalid server URI: "+location);
86     }
87
88 }
89
Popular Tags