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.broker;
018
019import java.io.IOException;
020import org.apache.activemq.Service;
021import org.apache.activemq.broker.region.ConnectionStatistics;
022import org.apache.activemq.command.Command;
023import org.apache.activemq.command.ConnectionControl;
024import org.apache.activemq.command.Response;
025
026/**
027 * 
028 */
029public interface Connection extends Service {
030
031    /**
032     * @return the connector that created this connection.
033     */
034    Connector getConnector();
035
036    /**
037     * Sends a message to the client.
038     * 
039     * @param message the message to send to the client.
040     */
041    void dispatchSync(Command message);
042
043    /**
044     * Sends a message to the client.
045     * 
046     * @param command
047     */
048    void dispatchAsync(Command command);
049
050    /**
051     * Services a client command and submits it to the broker.
052     * 
053     * @param command
054     * @return Response
055     */
056    Response service(Command command);
057
058    /**
059     * Handles an unexpected error associated with a connection.
060     * 
061     * @param error
062     */
063    void serviceException(Throwable error);
064
065    /**
066     * @return true if the Connection is slow
067     */
068    boolean isSlow();
069
070    /**
071     * @return if after being marked, the Connection is still writing
072     */
073    boolean isBlocked();
074
075    /**
076     * @return true if the Connection is connected
077     */
078    boolean isConnected();
079
080    /**
081     * @return true if the Connection is active
082     */
083    boolean isActive();
084
085    /**
086     * Returns the number of messages to be dispatched to this connection
087     */
088    int getDispatchQueueSize();
089
090    /**
091     * Returns the statistics for this connection
092     */
093    ConnectionStatistics getStatistics();
094
095    /**
096     * @return true if the Connection will process control commands
097     */
098    boolean isManageable();
099
100    /**
101     * @return the source address for this connection
102     */
103    String getRemoteAddress();
104
105    void serviceExceptionAsync(IOException e);
106
107    String getConnectionId();
108    
109    /**
110     * return true if a network connection
111     * @return
112     */
113    boolean isNetworkConnection();
114    
115    /**
116     * @return true if a fault tolerant connection
117     */
118    boolean isFaultTolerantConnection();
119    
120    void updateClient(ConnectionControl control);
121
122}