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