diff options
author | Simon McDuff | 2008-11-09 19:43:28 +0000 |
---|---|---|
committer | Simon McDuff | 2008-11-09 19:43:28 +0000 |
commit | 5565dc604f87abcdda90faab90d40077c6d1feb9 (patch) | |
tree | 4dbda2ce9b137d98d7edccbb113d85419a18b6f7 /plugins/org.eclipse.emf.cdo | |
parent | f6a61fa4e90ac8bae599d1147d772b5b2a9e9b69 (diff) | |
download | cdo-5565dc604f87abcdda90faab90d40077c6d1feb9.tar.gz cdo-5565dc604f87abcdda90faab90d40077c6d1feb9.tar.xz cdo-5565dc604f87abcdda90faab90d40077c6d1feb9.zip |
[247427] Explicit locking
https://bugs.eclipse.org/bugs/show_bug.cgi?id=247427
Diffstat (limited to 'plugins/org.eclipse.emf.cdo')
13 files changed, 668 insertions, 2 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java new file mode 100644 index 0000000000..a02c8c95c4 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOLock.java @@ -0,0 +1,33 @@ +/*************************************************************************** + * 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; + +import org.eclipse.net4j.util.concurrent.RWLockManager; + +import java.util.concurrent.locks.Lock; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public interface CDOLock extends Lock +{ + public static final int WAIT = RWLockManager.WAIT; + + public static final int NO_WAIT = RWLockManager.NO_WAIT; + + /** + * Return true if it is currently lock. + */ + public boolean isLocked(); + + public RWLockManager.LockType getType(); +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java index 0f199e8b6e..91eabaa7d9 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOObject.java @@ -39,5 +39,19 @@ public interface CDOObject extends EObject */ public CDOResource cdoDirectResource(); + /** + * Returns read lock associate with this object. + * + * @since 2.0 + */ + public CDOLock cdoReadLock(); + + /** + * Returns write lock associate with this object. + * + * @since 2.0 + */ + public CDOLock cdoWriteLock(); + public void cdoReload(); } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransaction.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransaction.java index dd17d2c8bc..d47cd76ff4 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransaction.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransaction.java @@ -39,6 +39,28 @@ public interface CDOTransaction extends CDOView, CDOUserTransaction public void setCommitTimeout(long timeout); /** + * Specifies whether locks in this view will be removed when {@link CDOTransaction#commit()} or + * {@link CDOTransaction#rollback()} is called. + * <p> + * If false all locks are kept. + * <p> + * Default value is true. + * + * @since 2.0 + */ + public boolean setAutoReleaseLocksEnabled(boolean on); + + /** + * Returns true if locks in this view will be removes when {@link CDOTransaction#commit()} or + * {@link CDOTransaction#rollback()} is called. + * <p> + * Default value is true. + * + * @since 2.0 + */ + public boolean isAutoReleaseLocksEnabled(); + + /** * @since 2.0 */ public long getLastCommitTime(); diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java index ae4e013213..5e8514b5dc 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java @@ -20,6 +20,7 @@ import org.eclipse.emf.cdo.eresource.CDOResourceNode; import org.eclipse.emf.cdo.util.ReadOnlyException; import org.eclipse.net4j.util.collection.CloseableIterator; +import org.eclipse.net4j.util.concurrent.RWLockManager; import org.eclipse.net4j.util.event.INotifier; import org.eclipse.emf.common.util.URI; @@ -27,6 +28,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.URIHandler; +import java.util.Collection; import java.util.List; import java.util.concurrent.locks.ReentrantLock; @@ -337,5 +339,25 @@ public interface CDOView extends CDOProtocolView, INotifier /** * @since 2.0 */ + public void lockObjects(Collection<? extends CDOObject> objects, RWLockManager.LockType lockType, long timeout) + throws InterruptedException; + + /** + * Unlocks the given locked objects of this view. + * + * @since 2.0 + */ + public void unlockObjects(Collection<? extends CDOObject> objects, RWLockManager.LockType lockType); + + /** + * Unlocks all locked objects of this view. + * + * @since 2.0 + */ + public void unlockObjects(); + + /** + * @since 2.0 + */ public CDOQuery createQuery(String language, String queryString); } diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java index bd266242e5..61b7e3a735 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java @@ -11,6 +11,7 @@ **************************************************************************/ package org.eclipse.emf.internal.cdo; +import org.eclipse.emf.cdo.CDOLock; import org.eclipse.emf.cdo.CDOState; import org.eclipse.emf.cdo.CDOView; import org.eclipse.emf.cdo.common.id.CDOID; @@ -29,6 +30,9 @@ import org.eclipse.emf.internal.cdo.util.GenUtil; import org.eclipse.emf.internal.cdo.util.ModelUtil; import org.eclipse.net4j.util.ImplementationError; +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.concurrent.RWLockManager; +import org.eclipse.net4j.util.concurrent.TimeoutRuntimeException; import org.eclipse.net4j.util.om.trace.ContextTracer; import org.eclipse.emf.common.notify.Adapter; @@ -58,9 +62,12 @@ import org.eclipse.emf.ecore.util.FeatureMap; import org.eclipse.emf.ecore.util.InternalEList; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.ListIterator; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; /** * @author Eike Stepper @@ -78,7 +85,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec private InternalCDORevision revision; /** - * CDO used this list instead of eSettings for transient objects. EMF used eSettings as cache. CDO deactivated the + * CDO used this list instead of eSettings for transient objects. EMF used eSettings as cache. CDO deactivates the * cache but EMF still used eSettings to store list wrappers. CDO needs another place to store the real list with the * actual data (transient mode) and accessible through EStore. This allows CDO to always use the same instance of the * list wrapper. @@ -297,6 +304,34 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec cdoSettings = null; } + /** + * @since 2.0 + */ + public CDOLock cdoReadLock() + { + if (FSMUtil.isTransient(this) || FSMUtil.isNew(this)) + { + return NOOPLockImpl.INSTANCE; + } + + // Should we cache the locks ? + return new CDOLockImpl(RWLockManager.LockType.READ); + } + + /** + * @since 2.0 + */ + public CDOLock cdoWriteLock() + { + if (FSMUtil.isTransient(this) || FSMUtil.isNew(this)) + { + return NOOPLockImpl.INSTANCE; + } + + // Should we cache the locks ? + return new CDOLockImpl(RWLockManager.LockType.WRITE); + } + @SuppressWarnings("unchecked") private void populateRevisionFeature(CDOViewImpl view, InternalCDORevision revision, EStructuralFeature eFeature, Object[] eSettings, int i) @@ -976,7 +1011,92 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec } /** - * @author Eike Stepper + * @author Simon McDuff + * @since 2.0 + */ + private final class CDOLockImpl implements CDOLock + { + private RWLockManager.LockType type; + + public CDOLockImpl(RWLockManager.LockType type) + { + this.type = type; + } + + public RWLockManager.LockType getType() + { + return type; + } + + public boolean isLocked() + { + return cdoView().isLocked(CDOObjectImpl.this, type); + } + + public void lock() + { + try + { + cdoView().lockObjects(Collections.singletonList(CDOObjectImpl.this), type, CDOLock.WAIT); + } + catch (InterruptedException ex) + { + throw WrappedException.wrap(ex); + } + } + + public void lockInterruptibly() throws InterruptedException + { + lock(); + } + + public Condition newCondition() + { + throw new UnsupportedOperationException(); + } + + public boolean tryLock() + { + try + { + cdoView().lockObjects(Collections.singletonList(CDOObjectImpl.this), type, CDOLock.NO_WAIT); + return true; + } + catch (TimeoutRuntimeException ex) + { + return false; + } + catch (InterruptedException ex) + { + return false; + } + } + + /** + * @throws will + * throw an exception if timeout is reached. + */ + public boolean tryLock(long time, TimeUnit unit) throws InterruptedException + { + try + { + cdoView().lockObjects(Collections.singletonList(CDOObjectImpl.this), type, unit.toMillis(time)); + return true; + } + catch (TimeoutRuntimeException ex) + { + return false; + } + } + + public void unlock() + { + cdoView().unlockObjects(Collections.singletonList(CDOObjectImpl.this), type); + } + } + + /** + * @author Simon McDuff * @since 2.0 */ public static class CDOStoreSettingsImpl implements InternalEObject.EStore diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java index 78441c6506..699451eac6 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectWrapper.java @@ -11,6 +11,7 @@ package org.eclipse.emf.internal.cdo; import org.eclipse.emf.cdo.CDOView; +import org.eclipse.emf.cdo.CDOLock; import org.eclipse.emf.cdo.common.id.CDOID; import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl; @@ -125,6 +126,22 @@ public abstract class CDOObjectWrapper implements InternalCDOObject /** * @since 2.0 */ + public CDOLock cdoReadLock() + { + throw new UnsupportedOperationException(); + } + + /** + * @since 2.0 + */ + public CDOLock cdoWriteLock() + { + throw new UnsupportedOperationException(); + } + + /** + * @since 2.0 + */ public void eFireRead(int featureID) { // Do nothing diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java index fdf07f55f7..456e9f9f56 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java @@ -95,6 +95,8 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa private CDOTransactionStrategy transactionStrategy; + private boolean autoReleaseLocksEnabled = true; + public CDOTransactionImpl(int id, CDOSessionImpl session) { super(session, id); @@ -168,6 +170,29 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa /** * @since 2.0 */ + synchronized public boolean setAutoReleaseLocksEnabled(boolean on) + { + try + { + return autoReleaseLocksEnabled; + } + finally + { + autoReleaseLocksEnabled = on; + } + } + + /** + * @since 2.0 + */ + public boolean isAutoReleaseLocksEnabled() + { + return autoReleaseLocksEnabled; + } + + /** + * @since 2.0 + */ public long getLastCommitTime() { return lastCommitTime; @@ -718,6 +743,12 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa // Load from first savepoint up to current savepoint loadSavepoint(lastSavepoint, idsOfNewObjectWithDeltas); + if (lastSavepoint == firstSavepoint && isAutoReleaseLocksEnabled()) + { + // Unlock all objects + unlockObjects(null, null); + } + Map<CDOIDTemp, CDOID> idMappings = Collections.emptyMap(); fireEvent(new FinishedEvent(CDOTransactionFinishedEvent.Type.ROLLED_BACK, idMappings)); for (CDOTransactionHandler handler : getHandlers()) @@ -1158,6 +1189,14 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa throw new TransactionException(ex); } } + else + { + // Removes locks even if no one touch the transaction + if (isAutoReleaseLocksEnabled()) + { + unlockObjects(null, null); + } + } } @SuppressWarnings("unchecked") diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java index aaf101509d..01048a54eb 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java @@ -51,14 +51,20 @@ import org.eclipse.emf.cdo.util.ReadOnlyException; import org.eclipse.emf.internal.cdo.bundle.OM; import org.eclipse.emf.internal.cdo.protocol.ChangeSubscriptionRequest; +import org.eclipse.emf.internal.cdo.protocol.LockObjectsRequest; +import org.eclipse.emf.internal.cdo.protocol.ObjectLockedRequest; +import org.eclipse.emf.internal.cdo.protocol.UnlockObjectsRequest; import org.eclipse.emf.internal.cdo.query.CDOQueryImpl; import org.eclipse.emf.internal.cdo.util.FSMUtil; import org.eclipse.emf.internal.cdo.util.ModelUtil; +import org.eclipse.net4j.signal.SignalRemoteException; import org.eclipse.net4j.util.ImplementationError; import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.WrappedException; import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; import org.eclipse.net4j.util.collection.CloseableIterator; +import org.eclipse.net4j.util.concurrent.RWLockManager; import org.eclipse.net4j.util.om.trace.ContextTracer; import org.eclipse.net4j.util.ref.ReferenceValueMap; import org.eclipse.net4j.util.transaction.TransactionException; @@ -215,6 +221,89 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement return lock; } + /** + * @throws InterruptedException + * @since 2.0 + */ + public void lockObjects(Collection<? extends CDOObject> objects, RWLockManager.LockType lockType, long timeout) + throws InterruptedException + { + InterruptedException interruptedException = null; + RuntimeException runtimeException = null; + + try + { + LockObjectsRequest request = new LockObjectsRequest(getSession().getProtocol(), this, objects, timeout, lockType); + getSession().getFailOverStrategy().send(request); + } + catch (SignalRemoteException ex) + { + if (ex.getCause() instanceof RuntimeException) + { + runtimeException = (RuntimeException)ex.getCause(); + } + else if (ex.getCause() instanceof InterruptedException) + { + interruptedException = (InterruptedException)ex.getCause(); + } + } + catch (Exception ex) + { + throw WrappedException.wrap(ex); + } + + if (interruptedException != null) + { + throw interruptedException; + } + + if (runtimeException != null) + { + throw runtimeException; + } + } + + /** + * @since 2.0 + */ + public void unlockObjects(Collection<? extends CDOObject> objects, RWLockManager.LockType lockType) + { + try + { + UnlockObjectsRequest request = new UnlockObjectsRequest(getSession().getProtocol(), this, objects, lockType); + getSession().getFailOverStrategy().send(request); + } + catch (Exception ex) + { + throw WrappedException.wrap(ex); + } + } + + /** + * @since 2.0 + */ + public void unlockObjects() + { + unlockObjects(null, null); + } + + /** + * @throws InterruptedException + * @since 2.0 + */ + public boolean isLocked(CDOObject object, RWLockManager.LockType lockType) + { + try + { + ObjectLockedRequest request = new ObjectLockedRequest(getSession().getProtocol(), this, object, lockType); + return getSession().getFailOverStrategy().send(request); + } + catch (Exception ex) + { + throw WrappedException.wrap(ex); + } + } + public boolean isDirty() { return false; diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/NOOPLockImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/NOOPLockImpl.java new file mode 100644 index 0000000000..4debb2dc0a --- /dev/null +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/NOOPLockImpl.java @@ -0,0 +1,71 @@ +/*************************************************************************** + * 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.internal.cdo; + +import org.eclipse.emf.cdo.CDOLock; + +import org.eclipse.net4j.util.concurrent.RWLockManager; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; + +/** + * @author Simon McDuff + * @since 2.0 + */ +public class NOOPLockImpl implements CDOLock +{ + public static final NOOPLockImpl INSTANCE = new NOOPLockImpl(); + + private NOOPLockImpl() + { + } + + public boolean isLocked() + { + return false; + } + + public void lock() + { + throw new UnsupportedOperationException(); + } + + public void lockInterruptibly() throws InterruptedException + { + throw new UnsupportedOperationException(); + } + + public Condition newCondition() + { + return null; + } + + public boolean tryLock() + { + return false; + } + + public boolean tryLock(long time, TimeUnit unit) throws InterruptedException + { + return false; + } + + public void unlock() + { + throw new UnsupportedOperationException(); + } + + public RWLockManager.LockType getType() + { + return null; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/CommitTransactionRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/CommitTransactionRequest.java index 7648b20f9d..45e51ae26e 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/CommitTransactionRequest.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/CommitTransactionRequest.java @@ -106,6 +106,7 @@ public class CommitTransactionRequest extends CDOClientRequest<CommitTransaction Collection<CDORevisionDelta> revisionDeltas = commitContext.getRevisionDeltas().values(); Collection<CDOID> detachedObjects = commitContext.getDetachedObjects().keySet(); + out.writeBoolean(commitContext.getTransaction().isAutoReleaseLocksEnabled()); out.writeInt(newPackages.size()); out.writeInt(newResources.size() + newObjects.size()); out.writeInt(revisionDeltas.size()); diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LockObjectsRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LockObjectsRequest.java new file mode 100644 index 0000000000..a0fde6d651 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/LockObjectsRequest.java @@ -0,0 +1,83 @@ +/*************************************************************************** + * 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.internal.cdo.protocol; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.CDOView; +import org.eclipse.emf.cdo.common.CDODataInput; +import org.eclipse.emf.cdo.common.CDODataOutput; +import org.eclipse.emf.cdo.common.CDOProtocolConstants; + +import org.eclipse.emf.internal.cdo.bundle.OM; + +import org.eclipse.net4j.util.concurrent.RWLockManager; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import java.io.IOException; +import java.util.Collection; + +/** + * @author Simon McDuff + */ +public class LockObjectsRequest extends CDOClientRequest<Object> +{ + private static final ContextTracer PROTOCOL_TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, LockObjectsRequest.class); + + private CDOView view; + + private RWLockManager.LockType lockType; + + private Collection<? extends CDOObject> objects; + + private long timeout; + + public LockObjectsRequest(CDOClientProtocol protocol, CDOView view, Collection<? extends CDOObject> objects, + long timeout, RWLockManager.LockType lockType) + { + super(protocol, CDOProtocolConstants.SIGNAL_LOCK_OBJECTS); + this.view = view; + this.objects = objects; + this.timeout = timeout; + this.lockType = lockType; + } + + @Override + protected void requesting(CDODataOutput out) throws IOException + { + out.writeInt(view.getViewID()); + out.writeCDOLockType(lockType); + out.writeLong(timeout); + + if (PROTOCOL_TRACER.isEnabled()) + { + PROTOCOL_TRACER.format("Locking of type {0} requested for view {1} with timeout {2}", + lockType == RWLockManager.LockType.READ ? "read" : "write", view.getViewID(), timeout); + } + + out.writeInt(objects.size()); + for (CDOObject object : objects) + { + if (PROTOCOL_TRACER.isEnabled()) + { + PROTOCOL_TRACER.format("Locking requested for objects {0}", object.cdoID()); + } + + out.writeCDOID(object.cdoID()); + } + } + + @Override + protected Object confirming(CDODataInput in) throws IOException + { + in.readBoolean(); + return null; + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/ObjectLockedRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/ObjectLockedRequest.java new file mode 100644 index 0000000000..7de2be3cf6 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/ObjectLockedRequest.java @@ -0,0 +1,66 @@ +/*************************************************************************** + * 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.internal.cdo.protocol; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.CDOView; +import org.eclipse.emf.cdo.common.CDODataInput; +import org.eclipse.emf.cdo.common.CDODataOutput; +import org.eclipse.emf.cdo.common.CDOProtocolConstants; + +import org.eclipse.emf.internal.cdo.bundle.OM; + +import org.eclipse.net4j.util.concurrent.RWLockManager; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import java.io.IOException; + +/** + * @author Simon McDuff + */ +public class ObjectLockedRequest extends CDOClientRequest<Boolean> +{ + private static final ContextTracer PROTOCOL_TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, ObjectLockedRequest.class); + + private CDOView view; + + private CDOObject object; + + private RWLockManager.LockType lockType; + + public ObjectLockedRequest(CDOClientProtocol protocol, CDOView view, CDOObject object, RWLockManager.LockType lockType) + { + super(protocol, CDOProtocolConstants.SIGNAL_OBJECT_LOCKED); + this.view = view; + this.object = object; + this.lockType = lockType; + } + + @Override + protected void requesting(CDODataOutput out) throws IOException + { + if (PROTOCOL_TRACER.isEnabled()) + { + PROTOCOL_TRACER.format("Requesting if object {0} has of lock for object {1}", object.cdoID(), + lockType == RWLockManager.LockType.READ ? "read" : "write"); + } + + out.writeInt(view.getViewID()); + out.writeCDOLockType(lockType); + out.writeCDOID(object.cdoID()); + } + + @Override + protected Boolean confirming(CDODataInput in) throws IOException + { + return in.readBoolean(); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/UnlockObjectsRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/UnlockObjectsRequest.java new file mode 100644 index 0000000000..294f8f229d --- /dev/null +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/UnlockObjectsRequest.java @@ -0,0 +1,89 @@ +/*************************************************************************** + * 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.internal.cdo.protocol; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.CDOView; +import org.eclipse.emf.cdo.common.CDODataInput; +import org.eclipse.emf.cdo.common.CDODataOutput; +import org.eclipse.emf.cdo.common.CDOProtocolConstants; + +import org.eclipse.emf.internal.cdo.bundle.OM; + +import org.eclipse.net4j.util.concurrent.RWLockManager; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import java.io.IOException; +import java.util.Collection; + +/** + * @author Simon McDuff + */ +public class UnlockObjectsRequest extends CDOClientRequest<Boolean> +{ + private static final ContextTracer PROTOCOL_TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, UnlockObjectsRequest.class); + + private CDOView view; + + private Collection<? extends CDOObject> objects; + + private RWLockManager.LockType lockType; + + public UnlockObjectsRequest(CDOClientProtocol protocol, CDOView view, Collection<? extends CDOObject> objects, + RWLockManager.LockType lockType) + { + super(protocol, CDOProtocolConstants.SIGNAL_UNLOCK_OBJECTS); + this.view = view; + this.objects = objects; + this.lockType = lockType; + } + + @Override + protected void requesting(CDODataOutput out) throws IOException + { + out.writeInt(view.getViewID()); + out.writeCDOLockType(lockType); + if (objects == null) + { + if (PROTOCOL_TRACER.isEnabled()) + { + PROTOCOL_TRACER.format("Unlocking all objects for view {0}", view.getViewID()); + } + + out.writeInt(CDOProtocolConstants.RELEASE_ALL_LOCKS); + } + else + { + if (PROTOCOL_TRACER.isEnabled()) + { + PROTOCOL_TRACER.format("Unlocking of type {0} requested for view {1}", + lockType == RWLockManager.LockType.READ ? "read" : "write", view.getViewID()); + } + + out.writeInt(objects.size()); + for (CDOObject object : objects) + { + if (PROTOCOL_TRACER.isEnabled()) + { + PROTOCOL_TRACER.format("Unlocking requested for objects {0}", object.cdoID()); + } + + out.writeCDOID(object.cdoID()); + } + } + } + + @Override + protected Boolean confirming(CDODataInput in) throws IOException + { + return in.readBoolean(); + } +} |