summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-11-14 00:51:52 (EST)
committerEike Stepper2006-11-14 00:51:52 (EST)
commit2964c077221f87b95cc1586865cee95498d8fe19 (patch)
treecde544a384fc1c603a92e41a8da7a17db3afcdcb
parentd8da00be865b74905725fd8c95b50edca443c874 (diff)
downloadcdo-2964c077221f87b95cc1586865cee95498d8fe19.zip
cdo-2964c077221f87b95cc1586865cee95498d8fe19.tar.gz
cdo-2964c077221f87b95cc1586865cee95498d8fe19.tar.bz2
Made IRegistry transactional
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/AbstractRegistry.java69
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistry.java6
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegating/AbstractCachingRegistry.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegator/AbstractCachingRegistry.java)2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegating/DelegatingRegistry.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegator/DelegatingRegistry.java)2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegating/HashCacheRegistry.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegator/HashCacheRegistry.java)2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/resolver/IResolveable.java21
6 files changed, 68 insertions, 34 deletions
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/AbstractRegistry.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/AbstractRegistry.java
index f9f6711..bf91e17 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/AbstractRegistry.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/AbstractRegistry.java
@@ -36,10 +36,18 @@ public abstract class AbstractRegistry<K, V> implements IRegistry<K, V>
*/
private Queue<IRegistryListener> listeners = new ConcurrentLinkedQueue();
+ private boolean autoCommit;
+
private Transaction transaction;
+ protected AbstractRegistry(boolean autoCommit)
+ {
+ this.autoCommit = autoCommit;
+ }
+
protected AbstractRegistry()
{
+ this(true);
}
public void addRegistryListener(IRegistryListener<K, V> listener)
@@ -93,15 +101,23 @@ public abstract class AbstractRegistry<K, V> implements IRegistry<K, V>
}
/**
- * Requires {@link #commit()} to be called later.
+ * Requires {@link #commit()} to be called later if not
+ * {@link #isAutoCommit()}.
*/
public synchronized V put(K key, V value)
{
- return getTransaction().put(key, value);
+ V result = getTransaction().put(key, value);
+ if (autoCommit)
+ {
+ commit();
+ }
+
+ return result;
}
/**
- * Requires {@link #commit()} to be called later.
+ * Requires {@link #commit()} to be called later if not
+ * {@link #isAutoCommit()}.
*/
public synchronized void putAll(Map<? extends K, ? extends V> t)
{
@@ -114,19 +130,32 @@ public abstract class AbstractRegistry<K, V> implements IRegistry<K, V>
Entry<? extends K, ? extends V> e = i.next();
transaction.put(e.getKey(), e.getValue());
}
+
+ if (autoCommit)
+ {
+ commit();
+ }
}
}
/**
- * Requires {@link #commit()} to be called later.
+ * Requires {@link #commit()} to be called later if not
+ * {@link #isAutoCommit()}.
*/
public synchronized V remove(Object key)
{
- return getTransaction().remove(key);
+ V result = getTransaction().remove(key);
+ if (autoCommit)
+ {
+ commit();
+ }
+
+ return result;
}
/**
- * Requires {@link #commit()} to be called later.
+ * Requires {@link #commit()} to be called later if not
+ * {@link #isAutoCommit()}.
*/
public synchronized void clear()
{
@@ -138,10 +167,25 @@ public abstract class AbstractRegistry<K, V> implements IRegistry<K, V>
{
transaction.remove(key);
}
+
+ if (autoCommit)
+ {
+ commit();
+ }
}
}
- public synchronized void commit()
+ public boolean isAutoCommit()
+ {
+ return autoCommit;
+ }
+
+ public void setAutoCommit(boolean autoCommit)
+ {
+ this.autoCommit = autoCommit;
+ }
+
+ public synchronized void commit(boolean notifications)
{
if (transaction != null)
{
@@ -150,12 +194,17 @@ public abstract class AbstractRegistry<K, V> implements IRegistry<K, V>
Net4j.LOG.warn("Committing thread is not owner of transaction: " + Thread.currentThread());
}
- transaction.commit();
+ transaction.commit(notifications);
transaction = null;
notifyAll();
}
}
+ public void commit()
+ {
+ commit(true);
+ }
+
public synchronized void dispose()
{
listeners.clear();
@@ -275,11 +324,11 @@ public abstract class AbstractRegistry<K, V> implements IRegistry<K, V>
return value;
}
- public void commit()
+ public void commit(boolean notifications)
{
if (--nesting == 0)
{
- if (!deltas.isEmpty())
+ if (notifications && !deltas.isEmpty())
{
fireRegistryEvent(new RegistryEvent<K, V>(AbstractRegistry.this, deltas));
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistry.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistry.java
index b0550c4..b4ac6cf 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistry.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistry.java
@@ -21,6 +21,12 @@ public interface IRegistry<K, V> extends Map<K, V>
public void removeRegistryListener(IRegistryListener<K, V> listener);
+ public boolean isAutoCommit();
+
+ public void setAutoCommit(boolean on);
+
+ public void commit(boolean notifications);
+
public void commit();
public void dispose();
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegator/AbstractCachingRegistry.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegating/AbstractCachingRegistry.java
index b364fc9..7ea2c84 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegator/AbstractCachingRegistry.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegating/AbstractCachingRegistry.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.util.registry.delegator;
+package org.eclipse.net4j.util.registry.delegating;
import org.eclipse.net4j.util.registry.IRegistry;
import org.eclipse.net4j.util.registry.IRegistryElement.Descriptor;
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegator/DelegatingRegistry.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegating/DelegatingRegistry.java
index a6ff49d..4ef308a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegator/DelegatingRegistry.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegating/DelegatingRegistry.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.util.registry.delegator;
+package org.eclipse.net4j.util.registry.delegating;
import org.eclipse.net4j.util.registry.AbstractRegistry;
import org.eclipse.net4j.util.registry.IRegistry;
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegator/HashCacheRegistry.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegating/HashCacheRegistry.java
index 96b3b11..88ec562 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegator/HashCacheRegistry.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/delegating/HashCacheRegistry.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.util.registry.delegator;
+package org.eclipse.net4j.util.registry.delegating;
import org.eclipse.net4j.util.registry.IRegistry;
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/resolver/IResolveable.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/resolver/IResolveable.java
deleted file mode 100644
index a138adc..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/resolver/IResolveable.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004, 2005, 2006 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:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.net4j.util.registry.resolver;
-
-/**
- * @author Eike Stepper
- */
-public interface IResolveable<V>
-{
- public V resolve();
-
- public boolean deresolve();
-}