Created
August 11, 2016 04:28
-
-
Save Genzer/ec794804985f6c236af73781aa01314a to your computer and use it in GitHub Desktop.
How to implement a background job which starts only ONCE on Axon.ivy Engine PMV starts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import ch.ivyteam.ivy.process.eventstart.*; | |
import ch.ivyteam.ivy.request.RequestException; | |
import ch.soreco.alag.exception.OperationFailedException; | |
/** | |
* The {@code RunOnceOnServerStartEventBean} is an Ivy start event bean | |
* {@linkplain IProcessStartEventBean}. It's is designed to start a process only | |
* <strong>ONCE</strong> on the server startup. | |
*/ | |
public class RunOnceOnServerStartEventBean extends AbstractProcessStartEventBean { | |
public RunOnceOnServerStartEventBean() { | |
super("RunOnceOnServerStartEventBean", "Run to start process"); | |
} | |
public RunOnceOnServerStartEventBean(String name, String description) { | |
super(name, description); | |
} | |
@Override | |
public void initialize(IProcessStartEventBeanRuntime eventRuntime, String configuration) { | |
super.initialize(eventRuntime, configuration); | |
fireEventToStartProcess(); | |
turnOff(); | |
} | |
/** | |
* Fires an event to start the process using this event bean. | |
*/ | |
private void fireEventToStartProcess() { | |
try { | |
Map<String, Object> params = Collections.emptyMap(); | |
getEventBeanRuntime().fireProcessStartEventRequest(null, "", params); | |
} catch (RequestException e) { | |
throw new OperationFailedException( | |
"Cannot fire event to run process. The application may be not working as expected", e); | |
} | |
} | |
/** | |
* Disable this event bean by setting polling time to 0 | |
*/ | |
private void turnOff() { | |
getEventBeanRuntime().setPollTimeInterval(0); | |
} | |
public void poll() { | |
// Do nothing | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome Genzer!!!