package plgrid; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.LinkedBlockingQueue; import plgrid.event.GridEvent; /* * This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6. */ public abstract class PipelineGridPlugin { private static final long EVENT_SEND_INTERVAL_MS = 500; private final Map<String, String> preferences = new HashMap<String, String>(); private List<GridEventListener> registeredListeners = new LinkedList<GridEventListener>(); private EventSender eventSender; private Timer eventTimer; public static final String VERSION = "3.1"; public PipelineGridPlugin() { this.eventSender = new EventSender(); this.eventTimer = new Timer(); this.eventTimer.scheduleAtFixedRate((TimerTask)this.eventSender, 0, 500); } public final void registerEventListener(GridEventListener gel) { if (gel == null) { return; } this.registeredListeners.add(gel); } public final void unregisterEventListener(GridEventListener gel) { if (gel == null) { return; } if (this.registeredListeners.contains(gel)) { this.registeredListeners.remove(gel); } } public final void fireEvent(GridEvent ge) { this.eventSender.enqueueEvent(ge); } /* * WARNING - Removed try catching itself - possible behaviour change. */ public void setPreferences(Map<String, String> plPreferences) { if (plPreferences != null) { Map<String, String> map = this.preferences; synchronized (map) { this.preferences.putAll(plPreferences); } } } /* * WARNING - Removed try catching itself - possible behaviour change. */ public Map<String, String> getPreferences() { HashMap<String, String> prefs = new HashMap<String, String>(); Map<String, String> map = this.preferences; synchronized (map) { prefs.putAll(this.preferences); } return prefs; } public abstract String submitJob(GridJobSubmitInfo var1); public abstract void killJob(String var1, String var2, boolean var3); public abstract List<GridJobInfo> getJobList(String var1); public abstract GridJobInfo getJobInfo(String var1); public List<GridJobInfo> getBulkJobInfo(List<String> jobIdList) { LinkedList<GridJobInfo> gjiList = new LinkedList<GridJobInfo>(); if (jobIdList != null) { for (String jobId : jobIdList) { gjiList.add(this.getJobInfo(jobId)); } } return gjiList; } public static void main(String[] args) { System.out.println("PipelineGridPlugin version 3.1"); } /* * This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6. */ private class EventSender extends TimerTask { private LinkedBlockingQueue<GridEvent> eventQueue; public EventSender() { this.eventQueue = new LinkedBlockingQueue(); } @Override public void run() { if (PipelineGridPlugin.this.registeredListeners == null) { return; } List<GridEvent> events = this.getEvents(); if (events != null && !events.isEmpty()) { for (GridEventListener listener : PipelineGridPlugin.this.registeredListeners) { listener.eventOccurred(events); } } } public void enqueueEvent(GridEvent event) { try { this.eventQueue.put(event); } catch (Exception ex) { ex.printStackTrace(); } } private List<GridEvent> getEvents() { LinkedList<GridEvent> ret = new LinkedList<GridEvent>(); this.eventQueue.drainTo(ret); return ret; } } }