diff options
Diffstat (limited to 'plugins/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/message/mock/SequenceHandle.java')
-rw-r--r-- | plugins/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/message/mock/SequenceHandle.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/message/mock/SequenceHandle.java b/plugins/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/message/mock/SequenceHandle.java new file mode 100644 index 00000000000..4b510086ad7 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/message/mock/SequenceHandle.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.message.mock; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.ReentrantLock; + +/** + * @author Ken J. Aguilar + */ +class SequenceHandle implements ISequenceHandle { + + private final ReentrantLock lock = new ReentrantLock(); + private final Condition endSequenceCondition = lock.newCondition(); + private boolean endSequence = false; + + @Override + public boolean waitForEndSequence(long timeout, TimeUnit timeUnit) throws InterruptedException { + lock.lock(); + long nanos = timeUnit.toNanos(timeout); + try { + while (!endSequence) { + if (nanos > 0) { + nanos = endSequenceCondition.awaitNanos(nanos); + } else { + return false; + } + } + return true; + } finally { + lock.unlock(); + } + } + + void signalEndSequence() { + lock.lock(); + try { + endSequence = true; + endSequenceCondition.signalAll(); + } finally { + lock.unlock(); + } + } +} |