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.stomp;
018
019import java.io.IOException;
020import java.net.Socket;
021import java.net.URI;
022import java.net.URISyntaxException;
023import java.net.UnknownHostException;
024import java.util.Map;
025
026import javax.net.ServerSocketFactory;
027import javax.net.SocketFactory;
028
029import org.apache.activemq.broker.BrokerContext;
030import org.apache.activemq.broker.BrokerService;
031import org.apache.activemq.broker.BrokerServiceAware;
032import org.apache.activemq.transport.Transport;
033import org.apache.activemq.transport.nio.NIOTransportFactory;
034import org.apache.activemq.transport.tcp.TcpTransport;
035import org.apache.activemq.transport.tcp.TcpTransportServer;
036import org.apache.activemq.util.IntrospectionSupport;
037import org.apache.activemq.wireformat.WireFormat;
038import org.apache.activemq.xbean.XBeanBrokerService;
039
040/**
041 * A <a href="http://stomp.codehaus.org/">STOMP</a> over NIO transport factory
042 * 
043 * 
044 */
045public class StompNIOTransportFactory extends NIOTransportFactory implements BrokerServiceAware {
046
047    private BrokerContext brokerContext = null;
048
049    protected String getDefaultWireFormatType() {
050        return "stomp";
051    }
052
053    protected TcpTransportServer createTcpTransportServer(URI location, ServerSocketFactory serverSocketFactory) throws IOException, URISyntaxException {
054        return new TcpTransportServer(this, location, serverSocketFactory) {
055            protected Transport createTransport(Socket socket, WireFormat format) throws IOException {
056                return new StompNIOTransport(format, socket);
057            }
058        };
059    }
060
061    protected TcpTransport createTcpTransport(WireFormat wf, SocketFactory socketFactory, URI location, URI localLocation) throws UnknownHostException, IOException {
062        return new StompNIOTransport(wf, socketFactory, location, localLocation);
063    }  
064
065    public Transport compositeConfigure(Transport transport, WireFormat format, Map options) {
066        transport = new StompTransportFilter(transport, new LegacyFrameTranslator(), brokerContext);
067        IntrospectionSupport.setProperties(transport, options);
068        return super.compositeConfigure(transport, format, options);
069    }
070
071    protected boolean isUseInactivityMonitor(Transport transport) {
072        // lets disable the inactivity monitor as stomp does not use keep alive
073        // packets
074        return false;
075    }
076    
077    public void setBrokerService(BrokerService brokerService) {
078        this.brokerContext = brokerService.getBrokerContext();
079    }
080
081}
082