org.sourceforge.jemm.client
Class SynchronousLockDecorator

java.lang.Object
  extended by org.sourceforge.jemm.client.DelegatingObjectDatabase
      extended by org.sourceforge.jemm.client.SynchronousLockDecorator
All Implemented Interfaces:
ObjectDatabase, ObjectSource, TypeRequestHandler, LockAcquiredListener

public class SynchronousLockDecorator
extends DelegatingObjectDatabase
implements LockAcquiredListener

An ObjectDatabase implementation that converts acquireLock calls into synchronous calls that wait for the lock to be acquired. Implementation notes -------------------- This implementation works by each thread registering itself in a Map with its clientThreadId pointing to a lock object on which the thread waits. Once the async listener calls for that particular ID then the lock is notified and the original thread is released. Since a clientThreadId is unique for each thread there is only ever one listener per lock. Note that if the clientThreadId is not unique by thread then acquireLock will return without acquiring the lock and threads could be locked indefinitely.

Author:
Paul Keeble

Constructor Summary
SynchronousLockDecorator(ClientId clientId, ObjectDatabase delegate)
           
 
Method Summary
 void acquireLock(ClientThreadId threadId, ID jemmId)
          Acquires a lock by calling onto the delegate database and waiting for an asynchronous response back.
 void lockAcquired(ClientThreadId threadId, ID object)
          A listener method implementation that gets the lock and notifies the waiting thread.
 void removeLockAcquiredListener(ClientId clientId)
          Attempts to change the LockAcquiredListener are ignored.
 void setClientLockAcquiredListener(ClientId clientId, LockAcquiredListener listener)
          Attempts to change the LockAcquiredListener are ignored.
 
Methods inherited from class org.sourceforge.jemm.client.DelegatingObjectDatabase
getClassInfo, getEnumInfo, getObject, getRefreshedObject, getRoot, newObject, processTypeRequest, refreshObject, registerClass, registerEnum, releaseLock, setRoot, setRootIfNull, synchroniseObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynchronousLockDecorator

public SynchronousLockDecorator(ClientId clientId,
                                ObjectDatabase delegate)
Method Detail

acquireLock

public void acquireLock(ClientThreadId threadId,
                        ID jemmId)
Acquires a lock by calling onto the delegate database and waiting for an asynchronous response back. Blocks until a response of some description is returned.

Specified by:
acquireLock in interface ObjectDatabase
Overrides:
acquireLock in class DelegatingObjectDatabase
Parameters:
threadId - a unique identifier for a Thread (and client). MUST BE UNIQUE PER THREAD.
jemmId - The ID to lock on

removeLockAcquiredListener

public void removeLockAcquiredListener(ClientId clientId)
Attempts to change the LockAcquiredListener are ignored.

Specified by:
removeLockAcquiredListener in interface ObjectDatabase
Overrides:
removeLockAcquiredListener in class DelegatingObjectDatabase
Parameters:
clientId - The id the the client who is no longer interested in lock events.

setClientLockAcquiredListener

public void setClientLockAcquiredListener(ClientId clientId,
                                          LockAcquiredListener listener)
Attempts to change the LockAcquiredListener are ignored.

Specified by:
setClientLockAcquiredListener in interface ObjectDatabase
Overrides:
setClientLockAcquiredListener in class DelegatingObjectDatabase
Parameters:
clientId - The client who is interested in their lock event notifications.
listener - The listener to register.

lockAcquired

public void lockAcquired(ClientThreadId threadId,
                         ID object)
A listener method implementation that gets the lock and notifies the waiting thread.

Specified by:
lockAcquired in interface LockAcquiredListener


Copyright © 2009. All Rights Reserved.