Skip to content

Instantly share code, notes, and snippets.

@rinrinne
Last active January 3, 2016 16:39
Show Gist options
  • Save rinrinne/8491225 to your computer and use it in GitHub Desktop.
Save rinrinne/8491225 to your computer and use it in GitHub Desktop.
public static final class GerritController {
private static PluginImpl getActivePlugin() {
PluginImpl plugin = Jenkins.getInstance().getPlugin(PluginImpl.class);
if (plugin != null && plugin.isActive()) {
return plugin;
}
return null;
}
public static void postEvent(String event) {
PluginImpl plugin = getActivePlugin();
if (plugin != null) {
plugin.getHandler().post(event);
}
}
public class GerritControlTask inplements Runnable {
abstract void exec();
@Override
protected void run() {
exec();
}
}
public final class GerritPostEventTask extends GerritControlTask {
private final String event;
public GerritPostEventTask(String event) {
this.event = event;
}
@Override
public void exec() {
GerritController.postEvent(event);
}
}
public class PluginImpl extends Plugin {
private final ExecutorService controlService = Executors.newSingleThreadExecutor();
public commitTask(ControlTask task) {
controlServie.submit(task);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment