Class AbstractConnection
- java.lang.Object
-
- org.eclipse.jetty.io.AbstractConnection
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,Connection
- Direct Known Subclasses:
AbstractWebSocketConnection
,HTTP2Connection
,HttpConnection
,HttpConnectionOverFCGI
,HttpConnectionOverHTTP
,NegotiatingClientConnection
,NegotiatingServerConnection
,ProxyConnection
,ProxyProtocolClientConnectionFactory.ProxyProtocolConnection
,ServerFCGIConnection
,SslConnection
public abstract class AbstractConnection extends java.lang.Object implements Connection
A convenience base implementation of
Connection
.This class uses the capabilities of the
EndPoint
API to provide a more traditional style of async reading. A call tofillInterested()
will schedule a callback toonFillable()
oronFillInterestedFailed(Throwable)
as appropriate.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Connection
Connection.Listener, Connection.UpgradeFrom, Connection.UpgradeTo
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConnection(EndPoint endp, java.util.concurrent.Executor executor)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addListener(Connection.Listener listener)
Adds a listener of connection events.void
close()
Performs a logical close of this connection.protected void
failedCallback(Callback callback, java.lang.Throwable x)
void
fillInterested()
Utility method to be called to register read interest.long
getBytesIn()
long
getBytesOut()
long
getCreatedTimeStamp()
EndPoint
getEndPoint()
protected java.util.concurrent.Executor
getExecutor()
int
getInputBufferSize()
long
getMessagesIn()
long
getMessagesOut()
boolean
isFillInterested()
void
onClose()
Callback method invoked when this connection is closed.abstract void
onFillable()
Callback method invoked when the endpoint is ready to be read.protected void
onFillInterestedFailed(java.lang.Throwable cause)
Callback method invoked when the endpoint failed to be ready to be read.boolean
onIdleExpired()
Callback method invoked upon an idle timeout event.void
onOpen()
Callback method invoked when this connection is opened.protected boolean
onReadTimeout(java.lang.Throwable timeout)
Callback method invoked when the endpoint failed to be ready to be read after a timeoutvoid
removeListener(Connection.Listener listener)
Removes a listener of connection events.void
setInputBufferSize(int inputBufferSize)
java.lang.String
toConnectionString()
java.lang.String
toString()
void
tryFillInterested()
void
tryFillInterested(Callback callback)
-
-
-
Constructor Detail
-
AbstractConnection
protected AbstractConnection(EndPoint endp, java.util.concurrent.Executor executor)
-
-
Method Detail
-
addListener
public void addListener(Connection.Listener listener)
Description copied from interface:Connection
Adds a listener of connection events.
- Specified by:
addListener
in interfaceConnection
- Parameters:
listener
- the listener to add
-
removeListener
public void removeListener(Connection.Listener listener)
Description copied from interface:Connection
Removes a listener of connection events.
- Specified by:
removeListener
in interfaceConnection
- Parameters:
listener
- the listener to remove
-
getInputBufferSize
public int getInputBufferSize()
-
setInputBufferSize
public void setInputBufferSize(int inputBufferSize)
-
getExecutor
protected java.util.concurrent.Executor getExecutor()
-
failedCallback
protected void failedCallback(Callback callback, java.lang.Throwable x)
-
fillInterested
public void fillInterested()
Utility method to be called to register read interest.
After a call to this method,
onFillable()
oronFillInterestedFailed(Throwable)
will be called back as appropriate.- See Also:
onFillable()
-
tryFillInterested
public void tryFillInterested()
-
tryFillInterested
public void tryFillInterested(Callback callback)
-
isFillInterested
public boolean isFillInterested()
-
onFillable
public abstract void onFillable()
Callback method invoked when the endpoint is ready to be read.
- See Also:
fillInterested()
-
onFillInterestedFailed
protected void onFillInterestedFailed(java.lang.Throwable cause)
Callback method invoked when the endpoint failed to be ready to be read.
- Parameters:
cause
- the exception that caused the failure
-
onReadTimeout
protected boolean onReadTimeout(java.lang.Throwable timeout)
Callback method invoked when the endpoint failed to be ready to be read after a timeout
- Parameters:
timeout
- the cause of the read timeout- Returns:
- true to signal that the endpoint must be closed, false to keep the endpoint open
-
onOpen
public void onOpen()
Description copied from interface:Connection
Callback method invoked when this connection is opened.
Creators of the connection implementation are responsible for calling this method.
- Specified by:
onOpen
in interfaceConnection
-
onClose
public void onClose()
Description copied from interface:Connection
Callback method invoked when this connection is closed.
Creators of the connection implementation are responsible for calling this method.
- Specified by:
onClose
in interfaceConnection
-
getEndPoint
public EndPoint getEndPoint()
- Specified by:
getEndPoint
in interfaceConnection
- Returns:
- the
EndPoint
associated with this Connection.
-
close
public void close()
Description copied from interface:Connection
Performs a logical close of this connection.
For simple connections, this may just mean to delegate the close to the associated
EndPoint
but, for example, SSL connections should write the SSL close message before closing the associatedEndPoint
.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceConnection
-
onIdleExpired
public boolean onIdleExpired()
Description copied from interface:Connection
Callback method invoked upon an idle timeout event.
Implementations of this method may return true to indicate that the idle timeout handling should proceed normally, typically failing the EndPoint and causing it to be closed.
When false is returned, the handling of the idle timeout event is halted immediately and the EndPoint left in the state it was before the idle timeout event.
- Specified by:
onIdleExpired
in interfaceConnection
- Returns:
- true to let the EndPoint handle the idle timeout, false to tell the EndPoint to halt the handling of the idle timeout.
-
getMessagesIn
public long getMessagesIn()
- Specified by:
getMessagesIn
in interfaceConnection
-
getMessagesOut
public long getMessagesOut()
- Specified by:
getMessagesOut
in interfaceConnection
-
getBytesIn
public long getBytesIn()
- Specified by:
getBytesIn
in interfaceConnection
-
getBytesOut
public long getBytesOut()
- Specified by:
getBytesOut
in interfaceConnection
-
getCreatedTimeStamp
public long getCreatedTimeStamp()
- Specified by:
getCreatedTimeStamp
in interfaceConnection
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toConnectionString
public java.lang.String toConnectionString()
-
-