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.transport.amqp; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.apache.activemq.broker.BrokerService; 023import org.apache.activemq.broker.BrokerServiceAware; 024import org.apache.activemq.transport.MutexTransport; 025import org.apache.activemq.transport.Transport; 026import org.apache.activemq.transport.tcp.TcpTransportFactory; 027import org.apache.activemq.util.IntrospectionSupport; 028import org.apache.activemq.wireformat.WireFormat; 029 030/** 031 * A <a href="http://amqp.org/">AMQP</a> transport factory 032 */ 033public class AmqpTransportFactory extends TcpTransportFactory implements BrokerServiceAware { 034 035 private BrokerService brokerService = null; 036 037 @Override 038 protected String getDefaultWireFormatType() { 039 return "amqp"; 040 } 041 042 @Override 043 @SuppressWarnings("rawtypes") 044 public Transport compositeConfigure(Transport transport, WireFormat format, Map options) { 045 AmqpTransportFilter amqpTransport = new AmqpTransportFilter(transport, format, brokerService); 046 047 Map<String, Object> wireFormatOptions = IntrospectionSupport.extractProperties(options, "wireFormat."); 048 049 IntrospectionSupport.setProperties(amqpTransport, options); 050 IntrospectionSupport.setProperties(amqpTransport.getWireFormat(), wireFormatOptions); 051 052 return super.compositeConfigure(amqpTransport, format, options); 053 } 054 055 @Override 056 public void setBrokerService(BrokerService brokerService) { 057 this.brokerService = brokerService; 058 } 059 060 @SuppressWarnings("rawtypes") 061 @Override 062 public Transport serverConfigure(Transport transport, WireFormat format, HashMap options) throws Exception { 063 transport = super.serverConfigure(transport, format, options); 064 065 // strip off the mutex transport. 066 if (transport instanceof MutexTransport) { 067 transport = ((MutexTransport) transport).getNext(); 068 } 069 070 return transport; 071 } 072 073 @Override 074 protected Transport createInactivityMonitor(Transport transport, WireFormat format) { 075 AmqpInactivityMonitor monitor = new AmqpInactivityMonitor(transport, format); 076 AmqpTransportFilter filter = transport.narrow(AmqpTransportFilter.class); 077 filter.setInactivityMonitor(monitor); 078 return monitor; 079 } 080}