Java Reference
In-Depth Information
Listing 14.9. CommandMessage decoder
The code in this listing is relatively straightforward. The class is declared as a decoder
and parameterized with AbstractCommand —meaning that it'll convert the incom-
ing text into an AbstractCommand object (data type in ActionBazaar). There are two
lifecycle methods, init() and destroy() . The willDecode message will
be called first by the WebSocket implementation to find out if this decoder can handle the
message
. If it can, the decode method will be invoked
.
Encoders
Encoders are similar to decoders. The interface and subinterfaces are defined in
javax.websocket.Endcoder . The only difference is that the methods are named
encode and the return type and method parameters are swapped. The CommandMes-
sage encoder is shown in the following listing.
 
Search WWH ::




Custom Search