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 */ 017package org.apache.activemq.network; 018 019import java.net.URI; 020import java.util.HashMap; 021import org.apache.activemq.broker.Broker; 022import org.apache.activemq.transport.Transport; 023import org.apache.activemq.transport.TransportFactory; 024import org.apache.activemq.util.URISupport; 025 026/** 027 * Factory for network bridges 028 * 029 * 030 */ 031public final class NetworkBridgeFactory { 032 033 private NetworkBridgeFactory() { 034 } 035 036 /** 037 * create a network bridge 038 * 039 * @param configuration 040 * @param localTransport 041 * @param remoteTransport 042 * @param listener 043 * @return the NetworkBridge 044 */ 045 public static DemandForwardingBridge createBridge(NetworkBridgeConfiguration configuration, 046 Transport localTransport, Transport remoteTransport, 047 final NetworkBridgeListener listener) { 048 DemandForwardingBridge result = null; 049 if (configuration.isConduitSubscriptions()) { 050 // dynamicOnly determines whether durables are auto bridged 051 result = new DurableConduitBridge(configuration, localTransport, remoteTransport); 052 } else { 053 result = new DemandForwardingBridge(configuration, localTransport, remoteTransport); 054 } 055 if (listener != null) { 056 result.setNetworkBridgeListener(listener); 057 } 058 return result; 059 } 060 061 public static Transport createLocalTransport(Broker broker) throws Exception { 062 URI uri = broker.getVmConnectorURI(); 063 HashMap<String, String> map = new HashMap<String, String>(URISupport.parseParameters(uri)); 064 map.put("async", "true"); 065 map.put("create", "false"); // we don't want a vm connect during shutdown to trigger a broker create 066 uri = URISupport.createURIWithQuery(uri, URISupport.createQueryString(map)); 067 return TransportFactory.connect(uri); 068 } 069}