Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » transport » mock » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.activemq.transport.mock;
   18   
   19   import java.io.IOException;
   20   import java.net.URI;
   21   
   22   import org.apache.activemq.transport.DefaultTransportListener;
   23   import org.apache.activemq.transport.FutureResponse;
   24   import org.apache.activemq.transport.ResponseCallback;
   25   import org.apache.activemq.transport.Transport;
   26   import org.apache.activemq.transport.TransportFilter;
   27   import org.apache.activemq.transport.TransportListener;
   28   
   29   /**
   30    * @version $Revision: 1.5 $
   31    */
   32   public class MockTransport extends DefaultTransportListener implements Transport {
   33   
   34       protected Transport next;
   35       protected TransportListener transportListener;
   36   
   37       public MockTransport(Transport next) {
   38           this.next = next;
   39       }
   40   
   41       /**
   42        */
   43       public synchronized void setTransportListener(TransportListener channelListener) {
   44           this.transportListener = channelListener;
   45           if (channelListener == null) {
   46               getNext().setTransportListener(null);
   47           } else {
   48               getNext().setTransportListener(this);
   49           }
   50       }
   51   
   52       /**
   53        * @see org.apache.activemq.Service#start()
   54        * @throws IOException if the next channel has not been set.
   55        */
   56       public void start() throws Exception {
   57           if (getNext() == null) {
   58               throw new IOException("The next channel has not been set.");
   59           }
   60           if (transportListener == null) {
   61               throw new IOException("The command listener has not been set.");
   62           }
   63           getNext().start();
   64       }
   65   
   66       /**
   67        * @see org.apache.activemq.Service#stop()
   68        */
   69       public void stop() throws Exception {
   70           getNext().stop();
   71       }
   72   
   73       public void onCommand(Object command) {
   74           getTransportListener().onCommand(command);
   75       }
   76   
   77       /**
   78        * @return Returns the getNext().
   79        */
   80       public synchronized Transport getNext() {
   81           return next;
   82       }
   83   
   84       /**
   85        * @return Returns the packetListener.
   86        */
   87       public synchronized TransportListener getTransportListener() {
   88           return transportListener;
   89       }
   90   
   91       public String toString() {
   92           return getNext().toString();
   93       }
   94   
   95       public void oneway(Object command) throws IOException {
   96           getNext().oneway(command);
   97       }
   98   
   99       public FutureResponse asyncRequest(Object command, ResponseCallback responseCallback) throws IOException {
  100           return getNext().asyncRequest(command, null);
  101       }
  102   
  103       public Object request(Object command) throws IOException {
  104           return getNext().request(command);
  105       }
  106   
  107       public Object request(Object command, int timeout) throws IOException {
  108           return getNext().request(command, timeout);
  109       }
  110   
  111       public void onException(IOException error) {
  112           getTransportListener().onException(error);
  113       }
  114   
  115       public <T> T narrow(Class<T> target) {
  116           if (target.isAssignableFrom(getClass())) {
  117               return target.cast(this);
  118           }
  119           return getNext().narrow(target);
  120       }
  121   
  122       public synchronized void setNext(Transport next) {
  123           this.next = next;
  124       }
  125   
  126       public void install(TransportFilter filter) {
  127           filter.setTransportListener(this);
  128           getNext().setTransportListener(filter);
  129           setNext(filter);
  130       }
  131   
  132       public String getRemoteAddress() {
  133           return getNext().getRemoteAddress();
  134       }
  135   
  136       /**
  137        * @see org.apache.activemq.transport.Transport#isFaultTolerant()
  138        */
  139       public boolean isFaultTolerant() {
  140           return getNext().isFaultTolerant();
  141       }
  142   
  143   	public boolean isDisposed() {
  144   		return getNext().isDisposed();
  145   	}
  146   	
  147   	public boolean isConnected() {
  148          return getNext().isConnected();
  149       }
  150   
  151   	public void reconnect(URI uri) throws IOException {
  152   		getNext().reconnect(uri);
  153   	}
  154   
  155       public int getReceiveCounter() {
  156           return getNext().getReceiveCounter();
  157       }
  158   }

Save This Page
Home » activemq-parent-5.3.1-source-release » org.apache » activemq » transport » mock » [javadoc | source]