<commit_before>/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.activemq.transport.stomp;

import java.io.IOException;

import javax.jms.JMSException;

import org.apache.activemq.command.Command;
import org.apache.activemq.transport.Transport;
import org.apache.activemq.transport.TransportFilter;
import org.apache.activemq.util.IOExceptionSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;

/**
 * The StompTransportFilter normally sits on top of a TcpTransport that has been
 * configured with the StompWireFormat and is used to convert STOMP commands to
 * ActiveMQ commands. All of the conversion work is done by delegating to the
 * ProtocolConverter.
 * 
 * @author <a href="http://hiramchirino.com">chirino</a>
 */
public class StompTransportFilter extends TransportFilter {
    private static final Log LOG = LogFactory.getLog(StompTransportFilter.class);
    private final ProtocolConverter protocolConverter;

    private final Object sendToActiveMQMutex = new Object();
    private final Object sendToStompMutex = new Object();

    private final FrameTranslator frameTranslator;

    private boolean trace;

    public StompTransportFilter(Transport next, FrameTranslator translator, ApplicationContext applicationContext) {
        super(next);
        this.frameTranslator = translator;
        this.protocolConverter = new ProtocolConverter(this, translator, applicationContext);
    }

    public void oneway(Object o) throws IOException {
        try {
            final Command command = (Command)o;
            protocolConverter.onActiveMQCommad(command);
        } catch (JMSException e) {
            throw IOExceptionSupport.create(e);
        }
    }

    public void onCommand(Object command) {
        try {
            if (trace) {
                LOG.trace("Received: \n" + command);
            }
            protocolConverter.onStompCommad((StompFrame)command);
        } catch (IOException e) {
            onException(e);
        } catch (JMSException e) {
            onException(IOExceptionSupport.create(e));
        }
    }

    public void sendToActiveMQ(Command command) {
        synchronized (sendToActiveMQMutex) {
            transportListener.onCommand(command);
        }
    }

    public void sendToStomp(StompFrame command) throws IOException {
        if (trace) {
            LOG.trace("Sending: \n" + command);
        }
        synchronized (sendToStompMutex) {
            next.oneway(command);<commit_msg>removed mutexes - as they are handled at the transport level - Fix for https://issues.apache.org/activemq/browse/AMQ-1818<commit_after>/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.activemq.transport.stomp;

import java.io.IOException;

import javax.jms.JMSException;

import org.apache.activemq.command.Command;
import org.apache.activemq.transport.Transport;
import org.apache.activemq.transport.TransportFilter;
import org.apache.activemq.transport.TransportListener;
import org.apache.activemq.util.IOExceptionSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;

/**
 * The StompTransportFilter normally sits on top of a TcpTransport that has been
 * configured with the StompWireFormat and is used to convert STOMP commands to
 * ActiveMQ commands. All of the conversion work is done by delegating to the
 * ProtocolConverter.
 * 
 * @author <a href="http://hiramchirino.com">chirino</a>
 */
public class StompTransportFilter extends TransportFilter {
    private static final Log LOG = LogFactory.getLog(StompTransportFilter.class);
    private final ProtocolConverter protocolConverter;
    private final FrameTranslator frameTranslator;

    private boolean trace;

    public StompTransportFilter(Transport next, FrameTranslator translator, ApplicationContext applicationContext) {
        super(next);
        this.frameTranslator = translator;
        this.protocolConverter = new ProtocolConverter(this, translator, applicationContext);
    }

    public void oneway(Object o) throws IOException {
        try {
            final Command command = (Command)o;
            protocolConverter.onActiveMQCommad(command);
        } catch (JMSException e) {
            throw IOExceptionSupport.create(e);
        }
    }

    public void onCommand(Object command) {
        try {
            if (trace) {
                LOG.trace("Received: \n" + command);
            }
            protocolConverter.onStompCommad((StompFrame)command);
        } catch (IOException e) {
            onException(e);
        } catch (JMSException e) {
            onException(IOExceptionSupport.create(e));
        }
    }

    public void sendToActiveMQ(Command command) {
        TransportListener l = transportListener;
        if (l!=null) {
            l.onCommand(command);
        }
    }

    public void sendToStomp(StompFrame command) throws IOException {
        if (trace) {
            LOG.trace("Sending: \n" + command);
        }
        Transport n = next;
        if (n!=null) {
            n.oneway(command);
{'fraction_non_alphanumeric': 0.07886904761904762, 'fraction_numerical': 0.0017857142857142857, 'mean_word_length': 3.22438717787555, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4674433', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1692, 'n_words': 567}