Server side Plug-Ins

This section describes how server side plug-ins in jWebSocket work in general. How to create your own jWebSocket Server extensions by creating your own plug-ins is described here.

In jWebSocket almost all higher level functionality is implemented in plug-ins. Therefor the jWebSocket Server provides the required managing capabilities. One of these capabilities is the plug-in chain. In this chain multiple plug-ins are arranged in a certain order. The order of the plug-ins can be arbitrarily changed and new plug-ins can easily be appended or inserted. Basically a plug-in can process an almost unlimited number of client commands by interpreting the various dynamic data fields of the tokens. A complex plug-in can consist of multiple classes in a separate package which can either be embedded or dynamically linked at run-time as a separate and even distributable .jar file.

This concept allows you to easily implement and distribute new WebSocket services according to your and your customers needs based on what jWebSocket already provides.

The jWebSocket plug-in chain

Way of the Tokens

On jWebSocket startup the server constructor instantiates the plug-in chain. In case of the TokenServer to which we refer to in the following section this is an instance of the TokenPlugInChainclass (a descendant of the abstract BasePlugInChain class which implements the PlugInChain interface). The TokenServer implements one single plug-in chain only.

When the client sends a packet or token it first reaches a connector on the server side. The connector forwards the paket or token through his engine to the server as shown in the diagram above. The server then forwards the token to the plug-in chain which iterates through all plug-ins in the chain until the target plug-in finally processes it. Usually the plug-in aborts the chain after it processed a token. It's up to the plug-in to send an answer or result back to client or not.

Processing Tokens

Each plug-in comes with a unique namespace. The plug-in usually checks if the incoming token comes with the same namespace and if so checks the type field of the token. The type here can be associated as a command from the client to the server.

Further documentation pending...

The included jWebSocket SystemPlugIn demonstrates how to implement own plug-ins and it already provides a couple of nice-to-have functions for your WebSocket work. We will extend the System plug-in on demand or provide further plug-ins like the Remote Procedure Call (RPC) plug-in or e.g. for the future clustering options.

TokenPlugIn usually implements the following methods (beside the specific methods to implement its functionality):

Method Description
processToken Called from the TokenPlugInChain every time when a client sends a message to the server.
The data is passed to method as object. It can be casted according to whatever the underlying protocol requires.
processPaket Called from the BasePlugInChain every time when a client sends a message to the server.
The data is passed to method as object. It can be casted according to whatever the underlying protocol requires.
engineStarted Called by the server when the engine has been started. This method is appropriate e.g. to initialize a plug-in.
For the rare case that you use more than one engine, please consider to not accidentally initialize a plug-in twice.
engineStopped Called by the server when the engine has been stopped.
This method is appropriate e.g. to clean-up a plug-in.
For the rare case that you use more than one engine, please consider to not accidentally clean-up a plug-in twice.
connectorStarted Called from the plug-in chain when a new client connects to the jWebSocket server.
If a client for instance should be automatically registered at a certain data stream this would be the right place to do this.
connectorStopped Called from the plug-in chain when a client was disconnected from the jWebSocket server.
If a client for instance is registered at a data stream this is the right place to unregister its connector from these stream.
Publications

Learn more about WebSockets in general, get background information and gain deeper insight!

Join jWebSocket

Wether developer, designer or translator – join the jWebSocket team and grow together with our success!

Copyright © 2013 Innotrade GmbH. All rights reserved.