KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > failover > FailoverTransportFactory


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

60     public Transport createTransport(CompositeData compositData) throws IOException JavaDoc {
61         FailoverTransport transport = createTransport(compositData.getParameters());
62         transport.add(compositData.getComponents());
63         return transport;
64     }
65
66     public FailoverTransport createTransport(Map JavaDoc parameters) throws IOException JavaDoc {
67         FailoverTransport transport = new FailoverTransport();
68         IntrospectionSupport.setProperties(transport, parameters);
69         return transport;
70     }
71
72     public TransportServer doBind(String JavaDoc brokerId,URI JavaDoc location) throws IOException JavaDoc {
73         throw new IOException JavaDoc("Invalid server URI: "+location);
74     }
75
76 }
77
Popular Tags