Initializing and Monitoring the Solace .NET API

This section describes how to initialize the Solace .NET API and provides information for using API logging and session statistics.

Initializing the API

To work with the Solace .NET API, it must first be initialized.

Call the method below to initialize the Solace .NET API. When the API is initialized, you can optionally set the initial log level filter for all log categories so that only logs at a specified level and more severe are emitted. (For more information on logging levels, see Configuring Logging.)

You can also set the global buffer sizes for the memory pools that are used to temporarily save messages in the application space (see Modifying the Global Pool Buffer Sizes).

In the Solace .NET API, use:

ContextFactory.Instance.Init(...)

Related Samples

For an example of how to initialize the Solace .NET API, see the SampleApp sample.

Cleanup

When the client application is finished using the Solace .NET API, it should perform a global clean-up, which automatically frees all allocated resources, including those allocated for contexts and sessions that have been previously created but are not destroyed.

In the Solace .NET API, use:

ContextFactory.Instance.Cleanup()

  • Contexts and sessions should always be destroyed or disposed before a cleanup is performed. If ContextFactory.Cleanup() is called while sessions are connected, any messages buffered for transmission are discarded and not sent.

    Note that invocations of "initialize" and "cleanup" are reference counted. For example, if "initialize" is called twice, "cleanup" must be called twice to properly free the resources.

  • In the .NET environment, the .NET garbage collector may attempt to release IMessage containers after the application has called ContextFactory.Cleanup(). This will cause warnings like "2012-08-07 19:11:50Z - Warn - Sdk:Bad msg_p pointer (0000000004000FE1) in solClient_msg_free". These warnings may be disregarded because they indicate that the API has detected and avoided a double-free.
    However, if the same application calls ContextFactory.Init() subsequent to ContextFactory.Cleanup(), the garbage collector may release messages that have been re-assigned to the newly initialized ContextFactory, and this will lead to an application crash. Therefore, it is recommended that you only call ContextFactory.Init()/ContextFactory.Cleanup() once.

Related Samples

For an example of how to perform a global cleanup for the Solace .NET API, see SampleUtils.cs included with the sample files.