public TabularData listCoordinations(String regexFilter) { Pattern p = Pattern.compile(regexFilter); TabularData td = new TabularDataSupport(COORDINATIONS_TYPE); for (CoordinationImpl c : coordinations.values()) { if (p.matcher(c.getName()).matches()) { try { td.put(fromCoordination(c)); } catch (OpenDataException e) { // TODO: log } } } return td; }
void unregister(final CoordinationImpl c) { coordinations.remove(c.getId()); Stack<Coordination> stack = threadStacks.get(); if (stack != null) { stack.remove(c); } }
void lockParticipant(final Participant p, final CoordinationImpl c) { synchronized (participants) { // wait for participant to be released long cutOff = System.currentTimeMillis() + participationTimeOut; long waitTime = (participationTimeOut > 500) ? participationTimeOut / 500 : participationTimeOut; CoordinationImpl current = participants.get(p); while (current != null && current != c) { if (current.getThread() == c.getThread()) { throw new CoordinationException( "Participant " + p + " already participating in Coordination " + current.getId() + "/" + current.getName() + " in this thread", c, CoordinationException.DEADLOCK_DETECTED); } try { participants.wait(waitTime); } catch (InterruptedException ie) { throw new CoordinationException( "Interrupted waiting to add Participant " + p + " currently participating in Coordination " + current.getId() + "/" + current.getName() + " in this thread", c, CoordinationException.LOCK_INTERRUPTED); } // timeout waiting for participation if (System.currentTimeMillis() > cutOff) { throw new CoordinationException( "Timed out waiting to join coordinaton", c, CoordinationException.UNKNOWN); } // check again current = participants.get(p); } // lock participant into coordination participants.put(p, c); } }
private CompositeData fromCoordination(final CoordinationImpl c) throws OpenDataException { return new CompositeDataSupport( COORDINATION_TYPE, new String[] {ID, NAME, TIMEOUT}, new Object[] {c.getId(), c.getName(), c.getDeadLine()}); }
Coordination getCoordinationById(final long id) { CoordinationImpl c = coordinations.get(id); return (c == null || c.isTerminated()) ? null : c; }