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