update(misoRequestManager.getPoolById(poolId));
}
private void update(Pool p) throws IOException {
if (enabled) {
Pool clone = pools.get(p.getId());
if (clone == null) {
log.debug("Update: no clone - pushing");
//new run - add all PoolWatchers!
for (User u : securityManager.listUsersByGroupName("PoolWatchers")) {
p.addWatcher(u);
}
push(p);
}
else {
log.debug("Update: got clone of " + clone.getId());
//TODO EVIL EVIL EVIL FIX UPON PAIN OF DEATH
if (clone.getReadyToRun()) {
try {
//fire event if pool has been saved initially to ready to run
Method m = AbstractPool.class.getDeclaredMethod("firePoolReadyEvent");
m.setAccessible(true);
m.invoke(clone);
}
catch (Exception e) {
log.error("Cannot fire pool ready event: " + e.getMessage());
e.printStackTrace();
}
}
else {
log.debug("Updating Pool " + clone.getId() + " ...");
//find any watchable setters on the clone and call the respective getter from the clone parent
//i.e. clone.setFoo(parent.getFoo()); where @WatchableSetter Class.setFoo(T t);
/*
for (Method setter : clone.getClass().getMethods()) {
if (setter.getAnnotation(WatchableSetter.class)) {
try {
Method getter = clone.getClass().getMethod(setter.getName().replaceFirst("set", "get"));
setter.invoke(clone, getter.invoke(p));
}
catch (NoSuchMethodException e) {
e.printStackTrace();
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
*/
//TODO the above will get rid of this necessity to call each method explicitly
clone.setReadyToRun(p.getReadyToRun());
}
pop(clone);
push(p);
}