• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package software.amazon.awssdk.crt.eventstream;
2 
3 /**
4  * Handler interface for processing incoming event-stream-rpc connections and their lifetimes.
5  */
6 public abstract class ServerListenerHandler {
7     /**
8      * Invoked upon receiving a new connection, or if an error happened upon connection
9      * creation. If errorCode is non-zero, onConnectionShutdown() will never be invoked.
10      *
11      * @param serverConnection The new server connection to use for communications. Is non-null
12      *                         when errorCode is 0.
13      * @param errorCode represents any error that occurred during connection establishment
14      * @return Return an instance of ServerConnectionHandler, for processing connection specific events.
15      */
onNewConnection(final ServerConnection serverConnection, int errorCode)16     protected abstract ServerConnectionHandler onNewConnection(final ServerConnection serverConnection, int errorCode);
17 
18     /**
19      * Invoked upon connection shutdown. serverConnection will never be null. This function is
20      * only invoked if onNewConnection() was invoked with a zero errorCode.
21      * @param serverConnection connection the shutdown occurred on.
22      * @param errorCode shutdown reason. 0 means clean shutdown.
23      */
onConnectionShutdown(final ServerConnection serverConnection, int errorCode)24     protected abstract void onConnectionShutdown(final ServerConnection serverConnection, int errorCode);
25 
26     /**
27      * Invoked from JNI. Completes the closure future and invokes onConnectionShutdown()
28      */
onConnectionShutdownShim(final ServerConnection serverConnection, int errorCode)29     void onConnectionShutdownShim(final ServerConnection serverConnection, int errorCode) {
30         onConnectionShutdown(serverConnection, errorCode);
31         serverConnection.closedFuture.complete(errorCode);
32     }
33 }
34