Mirth provides several controllers to monitor and control channels. The Status controller allows you to check whether a channel is currently running, paused, etc, and allows you to change the state of the channel. The Statistics controller allows you to check the current error, sent, received, filtered, and queued counts and to set them.
In both cases, you must first get an instance of the controller.
These controllers can access all of your channels. Let's start off with the Statistics controller and its functionality.
Its important functions include
- ChannelStatistics getStatistics(String channelId)
- incrementReceivedCount(String channelId)
- incrementSentCount(String channelId)
- incrementErrorCount(String channelId)
- incrementFilteredCount(String channelId)
- incrementQueuedCount(String channelId)
- decrementReceivedCount(String channelId)
- decrementSentCount(String channelId)
- decrementErrorCount(String channelId)
- decrementFilteredCount(String channelId)
- decrementQueuedCount(String channelId)
Of these, 10 of them are fairly self-explanatory. They either increment or decrement a particular statistic for a particular channel. Since this can access all channels, a channelId must be specified. If called from a channel, you can use the variable channelId as the argument. It will already be defined in the channel. Here's an example of something you could put in your postprocessor:
None of these functions are particularly useful, especially considering what getStatistics can do, but in the event you do need to increment or decrement, these do it. It will not decrement below 0.
The function getStatistics is more useful. It returns a ChannelStatistics object based on the channelId passed in. The ChannelStatistics object can only be used to get and set data for the channelId that was specified in getStatistics. The ChannelStatistics object contains seven variables. It also has getters and setters for them, but you should be able to view and edit them without needing to use those functions. The only useful function it contains is toString(), which behaves as a toString() function typically would.
The top five variables correspond to the statistics on the dashboard. They can be get and set. The bottom two are exactly what their names imply, and can be read.
Alright, that wraps up the Statistics Controller. Now, onto the Status Controller.
Similarly to the Statistics Controller, the Status Controller can access all of your channels.
The functions I'll cover are as follows:
- void startChannel(int channelId)
- void stopChannel(int channelId)
- void resumeChannel(int channelId)
- void pauseChannel(int channelId)
- ChannelStatus.State getState(int channelId)
The first four change the channels state, and yet again require a channelId, since they can access all channels. The stopChannel function will call the resumeChannel function before running is the channel is currently paused. The fifth is used to read the current channel state.
By using both of these controllers, you can check and respond to channel states in your code. If, for instance, you have a channel with a filter to prevent certain types of messages coming through that aren't supposed to, you could check the number of filtered messages and stop the channel and create an error message if too many were appearing, because it would be a sign of something going wrong.