pt.ua.concurrent
Class CObject

java.lang.Object
  extended by pt.ua.concurrent.CObject
All Implemented Interfaces:
InterruptibleAwaitingThreads, SyncCV
Direct Known Subclasses:
DynamicBarrier, Event, Exchanger, FixedBarrier, GroupMutex, GroupMutexComposedCV, GroupMutexCV, Mutex, MutexCV, PersistentSignal, RWEx, RWExCV, Semaphore, TransientSignal

public abstract class CObject
extends java.lang.Object
implements SyncCV

A replacement for Object to ease and augment the usage of concurrent related methods.

This class is only usable by extension.

This class follows DbC(tm) methodology (Wikipedia). Where possible, contracts are implement with native's Java assert.

Version:
0.5, October 2013
Author:
Miguel Oliveira e Silva (mos@ua.pt)

Constructor Summary
CObject()
          Constructor of an object without registering waiting threads in await service.
CObject(boolean registerAwaitingThreads)
          Constructor of an object.
 
Method Summary
 void await()
          Object's wait replacement, in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException;
- supports the registration of waiting threads for interrupt purposes.
 void await(long millis)
          Object's wait replacement, in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException;
- supports the registration of waiting threads for interrupt purposes.
 void await(long millis, int nanos)
          Object's wait replacement, in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException;
- supports the registration of waiting threads for interrupt purposes.
 void broadcast()
          Object's nofifyAll replacement.
 void interruptWaitingThreads()
          Requests the interruption all threads blocked on current lock and/or related condition variables.
 boolean lockIsMine()
          Is lock owned by me?
 boolean registerAwaitingThreads()
          Are threads registered when waiting (in await)?
 void signal()
          Object's nofify replacement.
 boolean syncronizedLockIsMine()
          Is native (synchronized) lock owned by me?
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CObject

public CObject()
Constructor of an object without registering waiting threads in await service.


CObject

public CObject(boolean registerAwaitingThreads)
Constructor of an object.

Parameters:
registerAwaitingThreads - if true, threads are registered when waiting
Method Detail

registerAwaitingThreads

public boolean registerAwaitingThreads()
Are threads registered when waiting (in await)?

Specified by:
registerAwaitingThreads in interface InterruptibleAwaitingThreads
Returns:
true, if threads are registered

lockIsMine

public boolean lockIsMine()
Is lock owned by me?

Specified by:
lockIsMine in interface SyncCV
Returns:
true, if lock is mine

syncronizedLockIsMine

public final boolean syncronizedLockIsMine()
Is native (synchronized) lock owned by me?

Returns:
true, if native lock is mine

await

public void await()
           throws ThreadInterruptedException
Object's wait replacement, in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException;
- supports the registration of waiting threads for interrupt purposes.

Precondition:
syncronizedLockIsMine() - native lock owned by me

Specified by:
await in interface SyncCV
Throws:
ThreadInterruptedException

await

public void await(long millis)
           throws ThreadInterruptedException
Object's wait replacement, in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException;
- supports the registration of waiting threads for interrupt purposes.

Precondition:
millis >= 0 - non negative timeout
syncronizedLockIsMine() - native lock owned by me

Parameters:
millis - timeout (in milliseconds)
Throws:
ThreadInterruptedException

await

public void await(long millis,
                  int nanos)
           throws ThreadInterruptedException
Object's wait replacement, in which:
- the checked exception InterruptedException, is replaced by the unchecked exception ThreadInterruptedException;
- supports the registration of waiting threads for interrupt purposes.

Precondition:
millis >= 0 - non negative timeout
nanos >= 0 - non negative timeout
syncronizedLockIsMine() - native lock owned by me

Parameters:
millis - timeout (in milliseconds)
nanos - timeout (in nanoseconds)
Throws:
ThreadInterruptedException

signal

public void signal()
Object's nofify replacement.

Precondition:
syncronizedLockIsMine() - native lock owned by me

Specified by:
signal in interface SyncCV

broadcast

public void broadcast()
Object's nofifyAll replacement.

Precondition:
syncronizedLockIsMine() - native lock owned by me

Specified by:
broadcast in interface SyncCV

interruptWaitingThreads

public void interruptWaitingThreads()
Requests the interruption all threads blocked on current lock and/or related condition variables.

Precondition:
registerAwaitingThreads() - registering of waiting threads activated

Specified by:
interruptWaitingThreads in interface InterruptibleAwaitingThreads