Creating Contexts in the PubSub+ JCSMP API

Contexts are used for organizing communications between PubSub+ JCSMP API applications and a PubSub+ event broker. Each client application must use a minimum of one context. A context acts as a container in which one or more sessions can be configured and session‑related events can be handled. It encapsulates threads that drive network I/O and message delivery notification for the sessions and session components associated with that context.

Context properties are used to dictate the behavior of a context. If no specific context properties are specified, the default values are used. For information on the context properties, see the PubSub+ Messaging API for JCSMP reference.

Callbacks and Delegates

For optimal performance, the following rules should be followed when developing your applications for use with PubSub+ APIs:

  • The context thread must run to detect relief from flow control and unblock waiting application threads.
  • The context thread must run to complete the Session connection sequence and unblock applications waiting for the connection to complete.
  • The context thread must run to unblock applications waiting for confirmation of subscription requests.

Consequently, applications must not block in callback/delegate routines because it can deadlock the application or at a minimum severely degrade receive performance. Deferring SolClient processing by running for excessively long periods of time in the callback routines prevents the API from unblocking other application threads that might be waiting for confirmation of sent messages, or be blocked in flow-control situations.

A default context is created by the PubSub+ JCSMP API implicitly; however, it also provides the ability to create new contexts. To create a context, call the JCSMPFactory.createContext(...) method. Once created, a context is automatically started. To destroy a context, call Context.destroy().