org.jboss.cache
Class Node

java.lang.Object
  extended byorg.jboss.cache.Node
All Implemented Interfaces:
Externalizable, Serializable

public class Node
extends Object
implements Externalizable

Represents a node in the tree. Has a relative name and a Fqn. Maintains a hashmap. If the node is created in a replicated cache, the relative and fully qualified name, and the keys and values of the hashmap have to be serializable.

Note that current version supports different levels of transaction locking such as simple locking (TreeCache.SERIALIZABLE, or R/W lock with upgrade ( REPEATABLE_READ) --that is the read lock will be automatically upgraded to write lock when the same owner intends to modify the data after read.

This class is not synchronized, so access to instances of Node need to be run under an isolation level > NONE.

Version:
$Revision: 1.39.2.4 $
Author:
Bela Ban March 25 2003, Ben Wang
See Also:
Serialized Form

Field Summary
protected static int INDENT
           
static int LOCK_TYPE_READ
          Declare locking type with the intention to read or write data
static int LOCK_TYPE_WRITE
           
static boolean PRINT_LOCK_DETAILS
           
 
Constructor Summary
Node()
           
Node(Object child_name, Fqn fqn, Node parent, Map data, TreeCache cache)
           
Node(Object child_name, Fqn fqn, Node parent, Object key, Object value, TreeCache cache)
           
 
Method Summary
 boolean acquire(Object caller, long timeout, int lock_type)
          Acquire a node object by locking it first.
 Set acquireAll(Object caller, long timeout, int lock_type)
          Acquires locks for the entire subtree
protected  boolean acquireReadLock(Object caller, long timeout)
           
protected  boolean acquireWriteLock(Object caller, long timeout)
           
 boolean childExists(Object child_name)
           
protected  Map children()
           
 void clear()
           
 Object clone()
           
 boolean containsKey(Object key)
           
 Node createChild(Object child_name, Fqn fqn, Node parent)
           
 Node createChild(Object child_name, Fqn fqn, Node parent, Map data)
           
 Node createChild(Object child_name, Fqn fqn, Node parent, Object key, Object value)
           
protected  Map data()
           
 Object get(Object key)
           
 Node getChild(Object child_name)
           
 Map getChildren()
           
 Map getData()
          Returns a copy of the attributes
 Set getDataKeys()
           
 Fqn getFqn()
           
 IdentityLock getImmutableLock()
          Deprecated. Use getLock() instead
 IdentityLock getLock()
           
 Object getName()
           
 Node getParent()
           
 boolean hasChild()
          Deprecated. Use hasChildren() instead
 boolean hasChildren()
           
protected  void init()
           
protected  void init(Object child_name, Fqn fqn, Node parent, TreeCache cache)
           
protected  Map initChildren()
           
protected  Map initData()
           
 int numAttributes()
           
 void print(StringBuffer sb, int indent)
           
 void printDetails(StringBuffer sb, int indent)
           
 void printIndent(StringBuffer sb, int indent)
           
 void printLockInfo(StringBuffer sb, int indent)
           
 void put(Map data)
           
 void put(Map data, boolean erase)
           
 Object put(Object key, Object value)
           
 void readExternal(ObjectInput in)
           
 void release(Object caller)
           
 void releaseAll(Object owner)
          Releases locks for the entire subtree
 void releaseAllForce()
          Releases locks for the entire subtree.
 void releaseForce()
           
 Object remove(Object key)
           
 void removeAllChildren()
           
 void removeChild(Object child_name)
           
 String toString()
           
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOCK_TYPE_READ

public static final int LOCK_TYPE_READ
Declare locking type with the intention to read or write data

See Also:
Constant Field Values

LOCK_TYPE_WRITE

public static final int LOCK_TYPE_WRITE
See Also:
Constant Field Values

INDENT

protected static final int INDENT
See Also:
Constant Field Values

PRINT_LOCK_DETAILS

public static final transient boolean PRINT_LOCK_DETAILS
Constructor Detail

Node

public Node()

Node

public Node(Object child_name,
            Fqn fqn,
            Node parent,
            Map data,
            TreeCache cache)

Node

public Node(Object child_name,
            Fqn fqn,
            Node parent,
            Object key,
            Object value,
            TreeCache cache)
Method Detail

init

protected void init(Object child_name,
                    Fqn fqn,
                    Node parent,
                    TreeCache cache)

init

protected void init()

initChildren

protected Map initChildren()

initData

protected Map initData()

children

protected Map children()

data

protected Map data()

getName

public Object getName()

getFqn

public Fqn getFqn()

get

public Object get(Object key)

containsKey

public boolean containsKey(Object key)

getChild

public Node getChild(Object child_name)

getParent

public Node getParent()

getDataKeys

public Set getDataKeys()

childExists

public boolean childExists(Object child_name)

getImmutableLock

public IdentityLock getImmutableLock()
Deprecated. Use getLock() instead

Returns:

getLock

public IdentityLock getLock()

getChildren

public Map getChildren()
Returns:
Map

getData

public Map getData()
Returns a copy of the attributes


numAttributes

public int numAttributes()

hasChild

public boolean hasChild()
Deprecated. Use hasChildren() instead

Returns:

hasChildren

public boolean hasChildren()

put

public void put(Map data,
                boolean erase)

put

public void put(Map data)

put

public Object put(Object key,
                  Object value)

createChild

public Node createChild(Object child_name,
                        Fqn fqn,
                        Node parent)

createChild

public Node createChild(Object child_name,
                        Fqn fqn,
                        Node parent,
                        Map data)

createChild

public Node createChild(Object child_name,
                        Fqn fqn,
                        Node parent,
                        Object key,
                        Object value)

remove

public Object remove(Object key)

clear

public void clear()

removeChild

public void removeChild(Object child_name)

removeAllChildren

public void removeAllChildren()

print

public void print(StringBuffer sb,
                  int indent)

printDetails

public void printDetails(StringBuffer sb,
                         int indent)

printLockInfo

public void printLockInfo(StringBuffer sb,
                          int indent)

printIndent

public void printIndent(StringBuffer sb,
                        int indent)

toString

public String toString()

clone

public Object clone()
             throws CloneNotSupportedException
Throws:
CloneNotSupportedException

acquire

public boolean acquire(Object caller,
                       long timeout,
                       int lock_type)
                throws LockingException,
                       TimeoutException,
                       InterruptedException
Acquire a node object by locking it first. The lock type is specified via lock_type.

Parameters:
caller - Tansaction context owner.
timeout - Timeout in milliseconds
lock_type - @see Node
Returns:
boolean True if node could be acquired, false if owner already held the lock. An exception is thrown if the owner didn't already hold the lock, but it couldn't be acquired
Throws:
LockingException
TimeoutException
InterruptedException

acquireReadLock

protected boolean acquireReadLock(Object caller,
                                  long timeout)
                           throws LockingException,
                                  TimeoutException,
                                  InterruptedException
Throws:
LockingException
TimeoutException
InterruptedException

acquireWriteLock

protected boolean acquireWriteLock(Object caller,
                                   long timeout)
                            throws LockingException,
                                   TimeoutException,
                                   InterruptedException
Throws:
LockingException
TimeoutException
InterruptedException

acquireAll

public Set acquireAll(Object caller,
                      long timeout,
                      int lock_type)
               throws LockingException,
                      TimeoutException,
                      InterruptedException
Acquires locks for the entire subtree

Throws:
LockingException
TimeoutException
InterruptedException

release

public void release(Object caller)

releaseForce

public void releaseForce()

releaseAll

public void releaseAll(Object owner)
Releases locks for the entire subtree


releaseAllForce

public void releaseAllForce()
Releases locks for the entire subtree. Forces release regardless of owner


writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.