Creating Contexts
Contexts are used for organizing communications between applications and a Solace 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 API Developer Online Reference documentation for the Solace Java RTO API.
Callbacks and Delegates
All callbacks or delegate invocations (for example, message receive callbacks, event callback, and timer callbacks) from the API to the application run from the context thread. For optimal performance, the following rules should be followed when developing your applications for use with Solace event brokers:
- 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.
To create a context, call a method listed below. Once created, a context is automatically started.
To Create a Context
In the Solace Java RTO API, use Solclient.createContextForHandle(...)
For an example of how to create a context for the Solace Java RTO API, see the DirectPubSub sample.
To Destroy a Context
In the Solace Java RTO API, use ContextHandle.destroy()
Context Timers
The Solace Java RTO API does not support context timers.
Contexts, sessions, flows, or timers cannot be disposed in a callback.