uka.karmi.rmi
Class ThreadInfo

java.lang.Object
  extended byuka.karmi.rmi.ThreadInfo

public class ThreadInfo
extends java.lang.Object

Manages transparent distributed threads in KaRMI. Each thread that calls or services remote methods is associated with a ThreadInfo object. The ThreadInfo object assigns a thread ID to its owner thread. KaRMI server threads change their thread ID according to the thread ID of the remote method invocation they currently service.

ThreadInfo can be used to find a thread that is associated to a given thread ID and send an interrupt to that thread.

See Also:
getThreadID(), interrupt(long)

Field Summary
private static java.util.WeakHashMap allThreadInfos
          Keeps weak references to all ThreadInfo objects for all active threads.
private static int count
           
private static java.lang.Object DUMMY
           
private static java.lang.ThreadLocal localThreadInfo
           
 java.lang.Thread owner
          The thread this thread info belongs to.
 long tid
          The thread ID associated to the owning thread.
 
Constructor Summary
protected ThreadInfo()
          A ThreadInfo object is created automatically for a thread, if this thread calls getThreadID() the first time.
 
Method Summary
private static long createID()
          Creates a new globally unique identifier that can be used as thread ID.
protected  long getID()
           
static long getThreadID()
          Returns the thread ID of the current thread.
static boolean interrupt(long tid)
          Sends an interrupt signal to the thread with the given thread ID.
protected  long setID(long tid)
           
static long setThreadID(long tid)
          Assigns a new thread ID to the current thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

owner

public final java.lang.Thread owner
The thread this thread info belongs to.


tid

public long tid
The thread ID associated to the owning thread.


localThreadInfo

private static final java.lang.ThreadLocal localThreadInfo

allThreadInfos

private static java.util.WeakHashMap allThreadInfos

Keeps weak references to all ThreadInfo objects for all active threads. Keys in this hash table are the ThreadInfo objects. The associated value for all key is the object DUMMY.

This data structure enables finding a thread for a given thread ID without registering a thread in a hash table each time a new thread ID is assigned to that thread. Therefore assigning a thread ID to a thread has no extra cost, but finding a thread for a given thread ID slower, because a linear search over all threads is required. This timing property is important, because assigning a thread ID to a thread is a frequent operation (each remote method invocation assigns the current thread ID to its server thread), but finding a thread for a given thread ID is only necessary during remote interrupt forwarding.

See Also:
DUMMY

DUMMY

private static java.lang.Object DUMMY
See Also:
allThreadInfos

count

private static int count
Constructor Detail

ThreadInfo

protected ThreadInfo()
A ThreadInfo object is created automatically for a thread, if this thread calls getThreadID() the first time.

See Also:
getThreadID()
Method Detail

getID

protected final long getID()

setID

protected final long setID(long tid)

getThreadID

public static long getThreadID()
Returns the thread ID of the current thread.

Returns:
the thread ID of Thread.currentThread().

setThreadID

public static long setThreadID(long tid)
Assigns a new thread ID to the current thread. Application code should never call this method.


interrupt

public static boolean interrupt(long tid)
Sends an interrupt signal to the thread with the given thread ID.

Returns:
true, if a thread with the given thread ID was found, false, otherwise.

createID

private static long createID()
Creates a new globally unique identifier that can be used as thread ID.