/**
 * 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;

import java.io.IOException;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Thread safe Transport Filter that serializes calls to and from the Transport Stack.
 */
public class MutexTransport extends TransportFilter {

    private final ReentrantLock wreiteLock = new ReentrantLock();
    private boolean syncOnCommand;

    public MutexTransport(Transport next) {
        super(next);
        this.syncOnCommand = false;
    }

    public MutexTransport(Transport next, boolean syncOnCommand) {
        super(next);
        this.syncOnCommand = syncOnCommand;
    }

    @Override
    public void onCommand(Object command) {
        if (syncOnCommand) {
            wreiteLock.lock();
            try {
                transportListener.onCommand(command);
            } finally {
                wreiteLock.unlock();
            }
        } else {
            transportListener.onCommand(command);
        }
    }

    @Override
    public FutureResponse asyncRequest(Object command, ResponseCallback responseCallback) throws IOException {
        wreiteLock.lock();
        try {
            return next.asyncRequest(command, null);
        } finally {
            wreiteLock.unlock();
        }
    }

    @Override
    public void oneway(Object command) throws IOException {
        wreiteLock.lock();
        try {
            next.oneway(command);
        } finally {
            wreiteLock.unlock();
        }
    }

    @Override
    public Object request(Object command) throws IOException {
        wreiteLock.lock();
        try {
            return next.request(command);
        } finally {
            wreiteLock.unlock();
        }
    }

    @Override
    public Object request(Object command, int timeout) throws IOException {
        wreiteLock.lock();
        try {
            return next.request(command, timeout);
        } finally {
            wreiteLock.unlock();
        }
    }

    @Override
    public String toString() {
        return next.toString();
    }

    public boolean isSyncOnCommand() {
        return syncOnCommand;
    }

    public void setSyncOnCommand(boolean syncOnCommand) {
        this.syncOnCommand = syncOnCommand;
    }
}

@@ -1099,17 +1099,16 @@
 tLock wr
-e
 iteLock 
@@ -1126,24 +1126,24 @@
 rantLock();%0A
+
     private 
@@ -1506,33 +1506,32 @@
 %7B%0A            wr
-e
 iteLock.lock();%0A
@@ -1636,33 +1636,32 @@
               wr
-e
 iteLock.unlock()
@@ -1887,33 +1887,32 @@
 ion %7B%0A        wr
-e
 iteLock.lock();%0A
@@ -2004,33 +2004,32 @@
 %7B%0A            wr
-e
 iteLock.unlock()
@@ -2123,33 +2123,32 @@
 ion %7B%0A        wr
-e
 iteLock.lock();%0A
@@ -2221,33 +2221,32 @@
 %7B%0A            wr
-e
 iteLock.unlock()
@@ -2343,33 +2343,32 @@
 ion %7B%0A        wr
-e
 iteLock.lock();%0A
@@ -2449,33 +2449,32 @@
 %7B%0A            wr
-e
 iteLock.unlock()
@@ -2584,33 +2584,32 @@
 ion %7B%0A        wr
-e
 iteLock.lock();%0A
@@ -2685,32 +2685,32 @@
     %7D finally %7B%0A
+
             wrei
@@ -2707,17 +2707,16 @@
       wr
-e
 iteLock.

fix typo