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 */
017 package org.apache.activemq.transport;
018
019 import java.io.IOException;
020 import java.net.URI;
021 import org.apache.activemq.Service;
022
023 /**
024 * Represents the client side of a transport allowing messages to be sent
025 * synchronously, asynchronously and consumed.
026 */
027 public interface Transport extends Service {
028
029 /**
030 * A one way asynchronous send
031 *
032 * @param command
033 * @throws IOException
034 */
035 void oneway(Object command) throws IOException;
036
037 /**
038 * An asynchronous request response where the Receipt will be returned in
039 * the future. If responseCallback is not null, then it will be called when
040 * the response has been completed.
041 *
042 * @param command
043 * @param responseCallback TODO
044 * @return the FutureResponse
045 * @throws IOException
046 */
047 FutureResponse asyncRequest(Object command, ResponseCallback responseCallback) throws IOException;
048
049 /**
050 * A synchronous request response
051 *
052 * @param command
053 * @return the response
054 * @throws IOException
055 */
056 Object request(Object command) throws IOException;
057
058 /**
059 * A synchronous request response
060 *
061 * @param command
062 * @param timeout
063 * @return the repsonse or null if timeout
064 * @throws IOException
065 */
066 Object request(Object command, int timeout) throws IOException;
067
068 /**
069 * Returns the current transport listener
070 *
071 * @return
072 */
073 TransportListener getTransportListener();
074
075 /**
076 * Registers an inbound command listener
077 *
078 * @param commandListener
079 */
080 void setTransportListener(TransportListener commandListener);
081
082 /**
083 * @param target
084 * @return the target
085 */
086 <T> T narrow(Class<T> target);
087
088 /**
089 * @return the remote address for this connection
090 */
091 String getRemoteAddress();
092
093 /**
094 * Indicates if the transport can handle faults
095 *
096 * @return true if fault tolerant
097 */
098 boolean isFaultTolerant();
099
100 /**
101 * @return true if the transport is disposed
102 */
103 boolean isDisposed();
104
105 /**
106 * @return true if the transport is connected
107 */
108 boolean isConnected();
109
110 /**
111 * @return true if reconnect is supported
112 */
113 boolean isReconnectSupported();
114
115 /**
116 * @return true if updating uris is supported
117 */
118 boolean isUpdateURIsSupported();
119 /**
120 * reconnect to another location
121 * @param uri
122 * @throws IOException on failure of if not supported
123 */
124 void reconnect(URI uri) throws IOException;
125
126 /**
127 * Provide a list of available alternative locations
128 * @param rebalance
129 * @param uris
130 * @throws IOException
131 */
132 void updateURIs(boolean rebalance,URI[] uris) throws IOException;
133
134 /**
135 * Returns a counter which gets incremented as data is read from the transport.
136 * It should only be used to determine if there is progress being made in reading the next command from the transport.
137 * The value may wrap into the negative numbers.
138 *
139 * @return a counter which gets incremented as data is read from the transport.
140 */
141 int getReceiveCounter();
142 }