jsr356-experts@websocket-spec.java.net

[jsr356-experts] Singleton ContainerProvider.getClientContainer()

From: Joe Walnes <joe_at_walnes.com>
Date: Sat, 12 Jan 2013 20:19:24 -0600

The ContainerProvider.getClientContainer() method provides a singleton
WebSocketContainer implementation.

Issues:

1. This means you can only have one configuration of WebSocketContainer per
application. It's likely that an application may connect to many servers
and would want different configuration paramaters for each of these.

2. Multiple parts of the application can be running on different threads -
they would have to coordinate access to the singleton instance.

3. It is likely that third party libraries will build clients based on top
of the WebSocket protocol and the singleton WebSocketContainer
implementation. These libraries may have conflicting requirements of
optimal settings on the WebSocketContainer, and even override your own
applications settings without it being obvious.


Proposal:

ContainerProvider.getClientContainer() should always return a new instance
rather than a shared singleton.

This allows isolated instances to be used my multiple parts on the
applications, in different threads and even by third party libraries,
without the risk of conflict. If applications really do wish to use a
singleton, they can share the instance themselves.

Should probably rename it to newClientContainer().

-Joe