solar.service.rpc
Class Block

java.lang.Object
  |
  +--solar.service.rpc.Block

class Block
extends java.lang.Object

A blocking object that other objects can wait on till time out or a reply is ready.

Version:
$Id: Block.java,v 1.3 2003/07/18 02:10:19 glchen Exp $
Author:
Guanling Chen

Field Summary
protected static java.util.Hashtable _blocks
           
protected static java.lang.Object _nullobj
           
 
Constructor Summary
private Block()
          Prevent object initialization.
 
Method Summary
static java.lang.Object getBlock(java.lang.Object key)
          Get the block EQUALS to specified key from repository.
static void putBlock(java.lang.Object key)
          Add one block into repository.
static void removeBlock(java.lang.Object key)
          Remove one block from repository.
static java.lang.Object waitBlock(java.lang.Object key, long timeout)
          Wait for reply with specified timeout.
static void wakeBlock(java.lang.Object key, java.lang.Object obj)
          Wake up the blocks waiting for replies.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_blocks

protected static java.util.Hashtable _blocks

_nullobj

protected static final java.lang.Object _nullobj
Constructor Detail

Block

private Block()
Prevent object initialization.

Method Detail

putBlock

public static void putBlock(java.lang.Object key)
Add one block into repository.


getBlock

public static java.lang.Object getBlock(java.lang.Object key)
                                 throws java.lang.IllegalArgumentException
Get the block EQUALS to specified key from repository.

java.lang.IllegalArgumentException

removeBlock

public static void removeBlock(java.lang.Object key)
Remove one block from repository.


waitBlock

public static java.lang.Object waitBlock(java.lang.Object key,
                                         long timeout)
Wait for reply with specified timeout. This method must be called within synchronization of the key as follows:

Block.putBlock(origianlKey);

synchronized(origianlKey)
{
// do some action such as network transmission
reply = Block.waitBlock(origianlKey, timeout);
}


wakeBlock

public static void wakeBlock(java.lang.Object key,
                             java.lang.Object obj)
Wake up the blocks waiting for replies. This method must be called within synchronization of the key and the key must be the original waiting block retrieved by calling getBlock as follows:

Object originalKey = Block.getBlock(receivedKey);

synchronized(originalKey)
{
Block.wakeBlock(originalKey, result);
}