Java Reference
In-Depth Information
whether they're engaged in a conversation or waiting to begin a conversation . Finally,
it maintains a list of clients and CSRs currently engaged in conversation . It also has a
method for either registering or disconnecting a CSR or a client . When an endpoint
onMessage is invoked, the endpoint calls the sendMessage , which dispatches
the message to both parties. If the server shuts down, detected via a ServletContex-
tListener , the shutdown method then terminates all outstanding conversations, letting
users know that the server is going down . The last method, performCommand
, utilizes the command pattern to perform an operation for either the client or CSR. Cur-
rently, the operation is usually to end the chat, which happens when the client feels their
question has been answered or the CSR gives up.
The sequence described here can be a little hard to fully conceptualize. Figure 14.2 illus-
trates the interaction between the various pieces. Although we haven't covered it yet, a
programmatic endpoint uses a MessageHandler to process the incoming messages. In
this sequence diagram, the client and CSR both initiate WebSocket instances that result in
an onOpen being invoked on their respective endpoints. Two different instances of the
same message handler class are instantiated. The message handler, shortened in the dia-
gram from CommandMessageHandler , forwards messages to the ChatServer . The
ChatServer then dispatches the message back to the client and also to the CSR. It should
be noted that messages from the client and messages sent from the server back to the client
are asynchronous. The client and server don't wait for their messages to be successfully
sent and acknowledged before continuing. If there are any failures, the onError method
(to be covered later) will be invoked.
Search WWH ::




Custom Search