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.SslTransportFactory;
027import org.apache.activemq.util.IntrospectionSupport;
028import org.apache.activemq.wireformat.WireFormat;
029
030/**
031 * A <a href="http://amqp.org/">AMQP</a> over SSL transport factory
032 */
033public class AmqpSslTransportFactory extends SslTransportFactory 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    @SuppressWarnings("rawtypes")
056    @Override
057    public Transport serverConfigure(Transport transport, WireFormat format, HashMap options) throws Exception {
058        transport = super.serverConfigure(transport, format, options);
059
060        // strip off the mutex transport.
061        if (transport instanceof MutexTransport) {
062            transport = ((MutexTransport) transport).getNext();
063        }
064
065        return transport;
066    }
067
068    @Override
069    public void setBrokerService(BrokerService brokerService) {
070        this.brokerService = brokerService;
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}