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
EndPointAPI 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 protectedAbstractConnection(EndPoint endp, java.util.concurrent.Executor executor)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddListener(Connection.Listener listener)Adds a listener of connection events.voidclose()Performs a logical close of this connection.protected voidfailedCallback(Callback callback, java.lang.Throwable x)voidfillInterested()Utility method to be called to register read interest.longgetBytesIn()longgetBytesOut()longgetCreatedTimeStamp()EndPointgetEndPoint()protected java.util.concurrent.ExecutorgetExecutor()intgetInputBufferSize()longgetMessagesIn()longgetMessagesOut()booleanisFillInterested()voidonClose()Callback method invoked when this connection is closed.abstract voidonFillable()Callback method invoked when the endpoint is ready to be read.protected voidonFillInterestedFailed(java.lang.Throwable cause)Callback method invoked when the endpoint failed to be ready to be read.booleanonIdleExpired()Callback method invoked upon an idle timeout event.voidonOpen()Callback method invoked when this connection is opened.protected booleanonReadTimeout(java.lang.Throwable timeout)Callback method invoked when the endpoint failed to be ready to be read after a timeoutvoidremoveListener(Connection.Listener listener)Removes a listener of connection events.voidsetInputBufferSize(int inputBufferSize)java.lang.StringtoConnectionString()java.lang.StringtoString()voidtryFillInterested()voidtryFillInterested(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:ConnectionAdds a listener of connection events.
- Specified by:
addListenerin interfaceConnection- Parameters:
listener- the listener to add
-
removeListener
public void removeListener(Connection.Listener listener)
Description copied from interface:ConnectionRemoves a listener of connection events.
- Specified by:
removeListenerin 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:ConnectionCallback method invoked when this connection is opened.
Creators of the connection implementation are responsible for calling this method.
- Specified by:
onOpenin interfaceConnection
-
onClose
public void onClose()
Description copied from interface:ConnectionCallback method invoked when this connection is closed.
Creators of the connection implementation are responsible for calling this method.
- Specified by:
onClosein interfaceConnection
-
getEndPoint
public EndPoint getEndPoint()
- Specified by:
getEndPointin interfaceConnection- Returns:
- the
EndPointassociated with this Connection.
-
close
public void close()
Description copied from interface:ConnectionPerforms a logical close of this connection.
For simple connections, this may just mean to delegate the close to the associated
EndPointbut, for example, SSL connections should write the SSL close message before closing the associatedEndPoint.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceConnection
-
onIdleExpired
public boolean onIdleExpired()
Description copied from interface:ConnectionCallback 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:
onIdleExpiredin 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:
getMessagesInin interfaceConnection
-
getMessagesOut
public long getMessagesOut()
- Specified by:
getMessagesOutin interfaceConnection
-
getBytesIn
public long getBytesIn()
- Specified by:
getBytesInin interfaceConnection
-
getBytesOut
public long getBytesOut()
- Specified by:
getBytesOutin interfaceConnection
-
getCreatedTimeStamp
public long getCreatedTimeStamp()
- Specified by:
getCreatedTimeStampin interfaceConnection
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toConnectionString
public java.lang.String toConnectionString()
-
-