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; 020 021import org.apache.activemq.Service; 022import org.apache.activemq.broker.region.ConnectionStatistics; 023import org.apache.activemq.command.Command; 024import org.apache.activemq.command.ConnectionControl; 025import org.apache.activemq.command.Response; 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 * 113 * @return if this is a network connection 114 */ 115 boolean isNetworkConnection(); 116 117 /** 118 * @return true if a fault tolerant connection 119 */ 120 boolean isFaultTolerantConnection(); 121 122 void updateClient(ConnectionControl control); 123 124 125 /** 126 * Returns the number of active transactions established on this Connection. 127 * 128 * @return the number of active transactions established on this Connection.. 129 */ 130 public int getActiveTransactionCount(); 131 132 /** 133 * Returns the number of active transactions established on this Connection. 134 * 135 * @return the number of active transactions established on this Connection.. 136 */ 137 public Long getOldestActiveTransactionDuration(); 138 139}