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;
018
019import org.apache.activemq.transport.Transport;
020
021import java.io.IOException;
022
023/**
024 * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
025 */
026public class TransportLoggerSupport {
027
028    public static String defaultLogWriterName = "default";
029
030    /**
031     * Default port to control the transport loggers through JMX
032     */
033    public static int defaultJmxPort = 1099;
034
035
036    public static interface SPI {
037        public Transport createTransportLogger(Transport transport) throws IOException;
038        public Transport createTransportLogger(Transport transport, String logWriterName, boolean dynamicManagement, boolean startLogging, int jmxPort) throws IOException;
039    }
040
041    final static public SPI spi;
042    static {
043        SPI temp;
044        try {
045            temp = (SPI) TransportLoggerSupport.class.getClassLoader().loadClass("org.apache.activemq.transport.TransportLoggerFactorySPI").newInstance();
046        } catch (Throwable e) {
047            temp = null;
048        }
049        spi = temp;
050    }
051
052    public static Transport createTransportLogger(Transport transport) throws IOException {
053        if( spi!=null ) {
054            return spi.createTransportLogger(transport);
055        } else {
056            return transport;
057        }
058    }
059
060    public static Transport createTransportLogger(Transport transport, String logWriterName, boolean dynamicManagement, boolean startLogging, int jmxPort) throws IOException {
061        if( spi!=null ) {
062            return spi.createTransportLogger(transport, logWriterName, dynamicManagement, startLogging, jmxPort);
063        } else {
064            return transport;
065        }
066    }
067
068}