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    public static interface SPI {
031        public Transport createTransportLogger(Transport transport) throws IOException;
032        public Transport createTransportLogger(Transport transport, String logWriterName, boolean dynamicManagement, boolean startLogging, int jmxPort) throws IOException;
033    }
034
035    final static public SPI spi;
036    static {
037        SPI temp;
038        try {
039            temp = (SPI) TransportLoggerSupport.class.getClassLoader().loadClass("org.apache.activemq.transport.TransportLoggerFactorySPI").newInstance();
040        } catch (Throwable e) {
041            temp = null;
042        }
043        spi = temp;
044    }
045
046    public static Transport createTransportLogger(Transport transport) throws IOException {
047        if( spi!=null ) {
048            return spi.createTransportLogger(transport);
049        } else {
050            return transport;
051        }
052    }
053
054    public static Transport createTransportLogger(Transport transport, String logWriterName, boolean dynamicManagement, boolean startLogging, int jmxPort) throws IOException {
055        if( spi!=null ) {
056            return spi.createTransportLogger(transport, logWriterName, dynamicManagement, startLogging, jmxPort);
057        } else {
058            return transport;
059        }
060    }
061
062}