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 */
017package org.apache.activemq.transport;
018
019import java.io.IOException;
020import java.net.URI;
021import java.security.cert.X509Certificate;
022
023import org.apache.activemq.Service;
024import org.apache.activemq.wireformat.WireFormat;
025
026/**
027 * Represents the client side of a transport allowing messages to be sent
028 * synchronously, asynchronously and consumed.
029 */
030public 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     * Returns the current transport listener
073     *
074     * @return
075     */
076    TransportListener getTransportListener();
077
078    /**
079     * Registers an inbound command listener
080     *
081     * @param commandListener
082     */
083    void setTransportListener(TransportListener commandListener);
084
085    /**
086     * @param target
087     * @return the target
088     */
089    <T> T narrow(Class<T> target);
090
091    /**
092     * @return the remote address for this connection
093     */
094    String getRemoteAddress();
095
096    /**
097     * Indicates if the transport can handle faults
098     *
099     * @return true if fault tolerant
100     */
101    boolean isFaultTolerant();
102
103    /**
104     * @return true if the transport is disposed
105     */
106    boolean isDisposed();
107
108    /**
109     * @return true if the transport is connected
110     */
111    boolean isConnected();
112
113    /**
114     * @return true if reconnect is supported
115     */
116    boolean isReconnectSupported();
117
118    /**
119     * @return true if updating uris is supported
120     */
121    boolean isUpdateURIsSupported();
122
123    /**
124     * reconnect to another location
125     * @param uri
126     * @throws IOException on failure of if not supported
127     */
128    void reconnect(URI uri) throws IOException;
129
130    /**
131     * Provide a list of available alternative locations
132     * @param rebalance
133     * @param uris
134     * @throws IOException
135     */
136    void updateURIs(boolean rebalance,URI[] uris) throws IOException;
137
138    /**
139     * Returns a counter which gets incremented as data is read from the transport.
140     * It should only be used to determine if there is progress being made in reading the next command from the transport.
141     * The value may wrap into the negative numbers.
142     *
143     * @return a counter which gets incremented as data is read from the transport.
144     */
145    int getReceiveCounter();
146
147    /**
148     * @return the Certificates provided by the peer, or null if not a secure channel.
149     */
150    X509Certificate[] getPeerCertificates();
151
152    /**
153     * Sets the certificates provided by the connected peer.
154     *
155     * @param certificates
156     *      the Certificates provided by the peer.
157     */
158    void setPeerCertificates(X509Certificate[] certificates);
159
160    /**
161     * Retrieves the WireFormat instance associated with this Transport instance.
162     *
163     * @return the WireFormat in use.
164     */
165    WireFormat getWireFormat();
166
167}