Methods Summary |
---|
public void | close()
this.writeLock.lock();
try{
if(this.isClosed.get())
throw new IllegalStateException("Lock has been closed");
this.isClosed.set(true);
this.locks.clear();
this.threads.clear();
INSTANCE = new SingleHostConcurrentStorageLock();
}finally{
this.writeLock.unlock();
}
|
protected void | forceClear()
this.writeLock.lock();
try{
if(this.isClosed.get())
throw new IllegalStateException("Lock has been closed");
this.locks.clear();
this.threads.clear();
}finally{
this.writeLock.unlock();
}
|
protected static synchronized ConcurrentStorageLock | getConcurrentStorageLock()
if(INSTANCE == null)
INSTANCE = new SingleHostConcurrentStorageLock();
return INSTANCE;
|
public boolean | isKeyLocked(java.lang.String key)
this.readLock.lock();
try{
if(this.isClosed.get())
throw new IllegalStateException("Lock has been closed");
return this.locks.containsKey(key);
}finally{
this.readLock.unlock();
}
|
public boolean | releaseLock(java.lang.String key)
this.writeLock.lock();
try{
if(this.isClosed.get())
throw new IllegalStateException("Lock has been closed");
Thread t = Thread.currentThread();
if(!this.threads.containsKey(t))
return false;
if(!this.locks.containsKey(key))
return false;
if(t != this.locks.get(key))
throw new ConcurrencyException("Illegal lock access -- current thread is not owner");
this.locks.remove(key);
this.threads.remove(t);
return true;
}finally{
this.writeLock.unlock();
}
|
public boolean | releaseThreadLocks()
this.writeLock.lock();
try{
if(this.isClosed.get())
throw new IllegalStateException("Lock has been closed");
Thread t = Thread.currentThread();
if(!this.threads.containsKey(t))
return false;
String key = this.threads.get(t);
this.threads.remove(t);
if(!this.locks.containsKey(key))
return false;
this.locks.remove(key);
return true;
}finally{
this.writeLock.unlock();
}
|
public boolean | setLock(java.lang.String key)
this.writeLock.lock();
try{
if(this.isClosed.get())
throw new IllegalStateException("Lock has been closed");
Thread t = Thread.currentThread();
if(this.threads.containsKey(t))
throw new ConcurrencyException("one thread must not obtain more than one lock -- single thread can not modify more than one resource");
if(this.locks.containsKey(key)){
return false;
}
this.locks.put(key, t);
this.threads.put(t,key);
return true;
}finally{
this.writeLock.unlock();
}
|