001 /* 002 * Copyright 2009 Red Hat, Inc. 003 * Red Hat licenses this file to you under the Apache License, version 004 * 2.0 (the "License"); you may not use this file except in compliance 005 * with the License. You may obtain a copy of the License at 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * Unless required by applicable law or agreed to in writing, software 008 * distributed under the License is distributed on an "AS IS" BASIS, 009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 010 * implied. See the License for the specific language governing 011 * permissions and limitations under the License. 012 */ 013 014 package org.hornetq.spi.core.protocol; 015 016 import java.util.List; 017 018 import org.hornetq.api.core.HornetQBuffer; 019 import org.hornetq.api.core.HornetQException; 020 import org.hornetq.core.remoting.CloseListener; 021 import org.hornetq.core.remoting.FailureListener; 022 import org.hornetq.spi.core.remoting.BufferHandler; 023 import org.hornetq.spi.core.remoting.Connection; 024 025 /** 026 * A RemotingConnection is a connection between a client and a server. 027 * 028 * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a> 029 * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a> 030 */ 031 public interface RemotingConnection extends BufferHandler 032 { 033 /** 034 * returns the unique id of the Remoting Connection 035 * 036 * @return the id 037 */ 038 Object getID(); 039 040 /** 041 * returns a string representation of the remote address of this connection 042 * 043 * @return the remote address 044 */ 045 String getRemoteAddress(); 046 047 /** 048 * add a failure listener. 049 * <p/> 050 * The listener will be called in the event of connection failure. 051 * 052 * @param listener the listener 053 */ 054 void addFailureListener(FailureListener listener); 055 056 /** 057 * remove the failure listener 058 * 059 * @param listener the lister to remove 060 * @return true if removed 061 */ 062 boolean removeFailureListener(FailureListener listener); 063 064 /** 065 * add a CloseListener. 066 * <p/> 067 * This will be called in the event of the connection being closed. 068 * 069 * @param listener the listener to add 070 */ 071 void addCloseListener(CloseListener listener); 072 073 /** 074 * remove a Close Listener 075 * 076 * @param listener the listener to remove 077 * @return true if removed 078 */ 079 boolean removeCloseListener(CloseListener listener); 080 081 /** 082 * return all the failure listeners 083 * 084 * @return the listeners 085 */ 086 List<FailureListener> getFailureListeners(); 087 088 /** 089 * set the failure listeners. 090 * <p/> 091 * These will be called in the event of the connection being closed. Any previosuly added listeners will be removed. 092 * 093 * @param listeners the listeners to add. 094 */ 095 void setFailureListeners(List<FailureListener> listeners); 096 097 /** 098 * creates a new HornetQBuffer of the specified size. 099 * 100 * @param size the size of buffer required 101 * @return the buffer 102 */ 103 HornetQBuffer createBuffer(int size); 104 105 /** 106 * called when the underlying connection fails. 107 * 108 * @param me the exception that caused the failure 109 */ 110 void fail(HornetQException me); 111 112 /** 113 * destroys this connection. 114 */ 115 void destroy(); 116 117 /** 118 * return the underlying Connection. 119 * 120 * @return the connection 121 */ 122 Connection getTransportConnection(); 123 124 /** 125 * returns whether or not the Remoting Connection is a client 126 * 127 * @return true if client, false if a server 128 */ 129 boolean isClient(); 130 131 /** 132 * returns true if this Remoting Connection has been destroyed. 133 * 134 * @return true if destroyed, otherwise false 135 */ 136 boolean isDestroyed(); 137 138 /** 139 * Disconnect the connection, closing all channels 140 */ 141 void disconnect(); 142 143 /** 144 * returns true if any data has been received since the last time this method was called. 145 * 146 * @return true if data has been received. 147 */ 148 boolean checkDataReceived(); 149 150 /** 151 * flush all outstanding data from the connection. 152 */ 153 void flush(); 154 155 }