Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PropertyChanged.java')
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PropertyChanged.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PropertyChanged.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PropertyChanged.java
new file mode 100644
index 0000000000..332af6c9e8
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/PropertyChanged.java
@@ -0,0 +1,90 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.common.util;
+
+
+/**
+ * @author Simon McDuff
+ */
+public class PropertyChanged<T>
+{
+ Object notifier = new Object();
+
+ T value;
+
+ RuntimeException exception = null;
+
+ public PropertyChanged(T value)
+ {
+ this.value = value;
+ }
+
+ public T get()
+ {
+ return value;
+ }
+
+ public void set(T newValue)
+ {
+ synchronized(notifier)
+ {
+ value = newValue;
+ notifier.notifyAll();
+ }
+ }
+
+ public void setException(RuntimeException exception)
+ {
+ synchronized(notifier)
+ {
+ this.exception = exception;
+ notifier.notifyAll();
+ }
+ }
+
+ public void acquire(Object accept, Object refuse)
+ {
+ acquire(accept, refuse, 0);
+ }
+
+ public void acquire(Object accept, Object refuse, long timeout)
+ {
+ synchronized(notifier)
+ {
+ while (!equalToOneElement(accept, refuse))
+ {
+ try
+ {
+ notifier.wait(timeout);
+ }
+ catch (InterruptedException ex)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ }
+
+ private boolean equalToOneElement(Object accept, Object refuse)
+ {
+ if (this.exception != null)
+ throw this.exception;
+
+ if (accept != null && accept.equals(value))
+ return true;
+
+ if (refuse != null && refuse.equals(value))
+ throw new IllegalStateException();
+
+ return false;
+ }
+
+}

Back to the top