1 18 package org.apache.activemq.transport.mock; 19 20 import java.io.IOException ; 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 33 public class MockTransport extends DefaultTransportListener implements Transport { 34 35 protected Transport next; 36 protected TransportListener transportListener; 37 38 public MockTransport(Transport next) { 39 this.next = next; 40 } 41 42 44 synchronized public void setTransportListener(TransportListener channelListener) { 45 this.transportListener = channelListener; 46 if (channelListener == null) 47 getNext().setTransportListener(null); 48 else 49 getNext().setTransportListener(this); 50 } 51 52 53 57 public void start() throws Exception { 58 if( getNext() == null ) 59 throw new IOException ("The next channel has not been set."); 60 if( transportListener == null ) 61 throw new IOException ("The command listener has not been set."); 62 getNext().start(); 63 } 64 65 68 public void stop() throws Exception { 69 getNext().stop(); 70 } 71 72 public void onCommand(Object command) { 73 getTransportListener().onCommand(command); 74 } 75 76 79 synchronized public Transport getNext() { 80 return next; 81 } 82 83 86 synchronized public TransportListener getTransportListener() { 87 return transportListener; 88 } 89 90 public String toString() { 91 return getNext().toString(); 92 } 93 94 public void oneway(Object command) throws IOException { 95 getNext().oneway(command); 96 } 97 98 public FutureResponse asyncRequest(Object command, ResponseCallback responseCallback) throws IOException { 99 return getNext().asyncRequest(command, null); 100 } 101 102 public Object request(Object command) throws IOException { 103 return getNext().request(command); 104 } 105 106 public Object request(Object command,int timeout) throws IOException { 107 return getNext().request(command, timeout); 108 } 109 110 public void onException(IOException error) { 111 getTransportListener().onException(error); 112 } 113 114 public Object narrow(Class target) { 115 if( target.isAssignableFrom(getClass()) ) { 116 return this; 117 } 118 return getNext().narrow(target); 119 } 120 121 synchronized public void setNext(Transport next) { 122 this.next = next; 123 } 124 125 public void install(TransportFilter filter) { 126 filter.setTransportListener(this); 127 getNext().setTransportListener(filter); 128 setNext(filter); 129 } 130 131 public String getRemoteAddress() { 132 return getNext().getRemoteAddress(); 133 } 134 135 } 136 | Popular Tags |