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); } }
void unregister(final CoordinationImpl c) { coordinations.remove(c.getId()); Stack<Coordination> stack = threadStacks.get(); if (stack != null) { stack.remove(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()}); }