Skip to content

Instantly share code, notes, and snippets.

@Genzer
Created August 11, 2016 04:28
Show Gist options
  • Save Genzer/ec794804985f6c236af73781aa01314a to your computer and use it in GitHub Desktop.
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.
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
}
}
@frystalizer
Copy link

Awesome Genzer!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment