web stats
Stop & Start Channel based on Certain Conditions - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-12-2017, 06:32 AM
mikko mikko is offline
Mirth Newb
 
Join Date: May 2016
Posts: 10
mikko is on a distinguished road
Default Stop & Start Channel based on Certain Conditions

Hi,

Can anyone suggest the best way to stop and start a channel based on a condition.

In my case, I need to stop and start a channel if the queue message is > 0. The function will trigger once a message is received. So here's what I've tried:

Here's what I have in the postprocessor of my channel:
Code:
var cid = 'channel ID';

if (ChannelUtil.getQueuedCount(cid) > 0) {
     logger.info('Stopping channel "' + ChannelUtil.getChannelName(cid) + '" due to queue count > 0');
     ChannelUtil.stopChannel(cid);
     logger.info('start channel func');
     
	ChannelUtil.startChannel(cid);
}
Problem with this is that I don't know if channel was actually stopped before it was started again.

I was looking for a delay, wait or pause function. So far I found the java.lang.Thread.sleep() function. But this holds the actual process which mean when the stop function triggers and you set a sleep after it, the channel status will sleep to "Stopping".

Basically, to have an accurate trigger of events, I need to wait for the channels to have a state of "Stopped" before I trigger the start function. I searched for this again and found the "Future" java class. Below are some links about it:
http://javadocs.mirthcorp.com/connec...il/Future.html

https://docs.oracle.com/javase/7/doc...nt/Future.html


Unfortunately, I am not that familiar on the Java language. Does this Java class need to be compiled just like what is mentioned in this guide: http://www.mirthcorp.com/community/w...Mirth+Connect?

I hope you can help me on this.
Thanks.
Reply With Quote
  #2  
Old 07-12-2017, 07:58 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,125
narupley is on a distinguished road
Default

Nope, you don't need to compile anything yourself to use ChannelUtil. You can call get() to wait until the operation finishes:

Code:
ChannelUtil.stopChannel(cid).get();
ChannelUtil.startChannel(cid);
If you need to have a channel restart itself, then do it inside a separate thread:

Code:
new java.lang.Thread({
    run:function() {
        ChannelUtil.stopChannel(cid).get();
        ChannelUtil.startChannel(cid);
    }
}).start();
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.

Last edited by narupley; 07-12-2017 at 08:00 AM.
Reply With Quote
  #3  
Old 07-12-2017, 08:03 AM
mikko mikko is offline
Mirth Newb
 
Join Date: May 2016
Posts: 10
mikko is on a distinguished road
Default

Thank you! Looks like you put me on the right track
Reply With Quote
Reply

Tags
mirth channel, restart, start, stop

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 12:56 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation