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.http;
018
019import java.io.IOException;
020
021import org.apache.activemq.command.BrokerInfo;
022import org.apache.activemq.command.ConnectionInfo;
023import org.apache.activemq.transport.InactivityMonitor;
024import org.apache.activemq.transport.Transport;
025import org.slf4j.Logger;
026import org.slf4j.LoggerFactory;
027
028/**
029 * Inactivity Monitor specialization for use with HTTP based transports.
030 */
031public class HttpInactivityMonitor extends InactivityMonitor {
032
033    private static final Logger LOG = LoggerFactory.getLogger(HttpInactivityMonitor.class);
034
035    /**
036     * @param next
037     *      The next Transport in the filter chain.
038     */
039    public HttpInactivityMonitor(Transport next) {
040        super(next, null);
041    }
042
043    @Override
044    public void onCommand(Object command) {
045        if (command.getClass() == ConnectionInfo.class || command.getClass() == BrokerInfo.class) {
046            synchronized (this) {
047                try {
048                    LOG.trace("Connection {} attempted on HTTP based transport: {}", command, this);
049                    processInboundWireFormatInfo(null);
050                } catch (IOException e) {
051                    onException(e);
052                }
053            }
054        }
055
056        super.onCommand(command);
057    }
058}