Bisocket implementation details
Using the bisocket transport certainly does not require understanding its implementation details, but some further information is presented in this section for those who might be interested. In the following discussion, the client side client invoker and the server side server invoker will be referred to simply as "client invoker" and "server invoker." The callback client invoker and callback server invoker will be explicitly identified as such. The following sequence of events occurs in the course of creating a control connection. For simplicity it is assumed that the Client and Connector have already been created, and that the callback server is created implicitly by the Client. These events are illustrated in Figure 5.1. The application calls Client.addListener(). The Client creates a callback Connector and the callback server invoker registers itself in a static map. The Client sends an "addListener" message to the server invoker by way of the client invoker. The client invoker intercepts the "addListener" message, which tells it that a callback server is being created. It retrieves the callback server invoker from the static map and tells it to create a control connection for the callback connection that is being constructed. The callback server invoker sends an internal message to the server invoker requesting the address and port of the secondary ServerSocket The callback server invoker connects to the secondary ServerSocket to create a Socket for the control connection. If it has not already done so, the callback server invoker creates a TimerTask which will monitor the state of all of its control connections. (Note that if the callback Connector is created explicitly, it could have multiple InvokerCallbackHandlers registered with it.) On the server side, the Socket just created by the secondary ServerSocket is stored in a static map, awaiting the creation of the callback client invoker. The client invoker transmits the "addListener" message to the server invoker. The server invoker creates a callback client invoker. The callback client invoker retrieves the waiting socket and uses it for the control connection. The callback client invoker begins pinging on the control connection. Figure 5.1. Creating a control connection. The following sequence of events occurs in the course of creating a connection for the callback client invoker to use for sending callbacks. It is illustrated in Figure 5.2. The ServerInvocationHandler calls InvokerCallbackHandler.handleCallback(). The InvocationCallbackHandler calls invoke() on the callback Client. The Client calls invoke() on the callback client invoker. If there are no connections in its connection pool, the callback client invoker sends a message on the control connection asking the callback server invoker to connect to the server side secondary ServerSocket. It then waits for the Socket to appear in a static map. The callback server invoker receives the request and calls upon either a Socket constructor or a SocketFactory to create a new Socket. It passes the new Socket to a worker thread to process subsequent callback invocations. The secondary ServerSocket creates a new Socket, which is placed in a static map. The callback client invoker retrieves the new Socket The callback client uses the new Socket to transmit a callback, and adds the new connection to its connection pool for later use. Figure 5.2. Creating a callback connection. The following sequence of events occurs when a control connection fails. It is illustrated in Figure 5.3. The callback server invoker notices that a ping has not been received during the control connection's current window. The callback server invoker reacquires the host and port of the secondary ServerSocket, just in case it has changed. The callback server invoker calls on a Socket constructor or SocketFactory to create a new Socket. The callback server invoker sends an internal message on the new connection directing the server to replace the current control connection with the new connection. After the secondary ServerSocket creates a new Socket, the Socket is passed directly to the client invoker in a method that replaces the old control connection with a new one. Figure 5.3. Replacing a failed control connection. 5.4.18. SSL Bisocket transport The SSL bisocket transport has the same relation to the bisocket transport as the SSL socket transport has to the socket transport. That is, it uses an SSLServerSocket and creates SSLSockets by default. See Section Socket factories and server socket factories for more information. SSL bisocket transport supports all the configuration attributes supported by the bisocket transport.