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.broker;
018    
019    import java.io.IOException;
020    
021    import org.apache.activemq.Service;
022    import org.apache.activemq.broker.region.ConnectionStatistics;
023    import org.apache.activemq.command.Command;
024    import org.apache.activemq.command.Response;
025    
026    /**
027     * @version $Revision: 1.5 $
028     */
029    public 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         */
055        Response service(Command command);
056    
057        /**
058         * Handles an unexpected error associated with a connection.
059         * 
060         * @param error
061         */
062        void serviceException(Throwable error);
063    
064        /**
065         * @return true if the Connection is slow
066         */
067        boolean isSlow();
068    
069        /**
070         * @return if after being marked, the Connection is still writing
071         */
072        boolean isBlocked();
073    
074        /**
075         * @return true if the Connection is connected
076         */
077        boolean isConnected();
078    
079        /**
080         * @return true if the Connection is active
081         */
082        boolean isActive();
083    
084        /**
085         * Returns the number of messages to be dispatched to this connection
086         */
087        int getDispatchQueueSize();
088    
089        /**
090         * Returns the statistics for this connection
091         */
092        ConnectionStatistics getStatistics();
093    
094        /**
095         * @return true if the Connection will process control commands
096         */
097        boolean isManageable();
098    
099        /**
100         * @return the source address for this connection
101         */
102        String getRemoteAddress();
103    
104        void serviceExceptionAsync(IOException e);
105    
106        String getConnectionId();
107        
108        /**
109         * return true if a network connection
110         * @return
111         */
112        boolean isNetworkConnection();
113    
114    }