public abstract class BasePlugin extends java.lang.Object implements AstManagerPlugin
Modifier and Type | Class and Description |
---|---|
protected static class |
BasePlugin.Pair
Simple container class to store the next available ID for a tree and
the associated tree name.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
dirty
Records if any changes have been made since the registry was read.
|
protected java.util.Map<java.lang.Long,BasePlugin.Pair> |
fids
Stores the ID to tree name mapping information.
|
protected java.util.Map<java.lang.String,java.lang.Long> |
fnames
Stores the tree name to ID mapping information.
|
protected static int |
HIGH_BITS
Number of bits to shift to make a file ID a normal int.
|
protected java.util.Map<java.lang.Long,java.util.concurrent.locks.ReentrantLock> |
locklist
Stores the tree name to lock mapping information.
|
protected static long |
MAX_POSSIBLE
Specifies the maximum possible number of files in the registry.
|
protected static long |
TREE_MASK
Allows easy removal of the node ID bits in an AST ID.
|
Constructor and Description |
---|
BasePlugin() |
Modifier and Type | Method and Description |
---|---|
long |
addTree(java.lang.String name)
Adds a mapping from the specified AST to a new ID.
|
long |
getNextNodeId(long id)
Access the next unassigned node ID for the specified tree.
|
long |
getTreeId(long id)
Returns the tree ID portion of a node ID.
|
long |
getTreeId(java.lang.String name)
Reverse lookup of the ID that corresponds to a given AST name.
|
java.lang.String |
getTreeName(long id)
Lookup the name associated with the tree specified by this ID.
|
protected boolean |
isInvalid(long id)
Detects if the given ID is invalid.
|
void |
lockTree(long id)
Obtains a process-wide lock on any processing related to the given tree.
|
boolean |
removeTree(long id)
Removes all mapping data referencing the specified tree.
|
void |
resetNextNodeId(long treeId)
Resets the next unassigned AST node ID for the specified tree to the
first possible value (tree ID + 1).
|
protected void |
setNextNodeId(long treeId,
long nodeId)
Set the next unassigned AST node ID for the specified tree.
|
void |
unlockTree(long id)
Releases the process-wide lock on any processing related to the given
tree.
|
boolean |
usesMemoryStorage()
Does this plug-in use memory as its primary storage medium? This method returns
false by default; subclasses should override as necessary. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isExistingAst, loadTree, save, saveTree
protected static final long TREE_MASK
protected static final int HIGH_BITS
protected static final long MAX_POSSIBLE
protected java.util.Map<java.lang.String,java.lang.Long> fnames
protected java.util.Map<java.lang.Long,BasePlugin.Pair> fids
protected java.util.Map<java.lang.Long,java.util.concurrent.locks.ReentrantLock> locklist
protected boolean dirty
public boolean usesMemoryStorage()
false
by default; subclasses should override as necessary.usesMemoryStorage
in interface AstManagerPlugin
false
.public java.lang.String getTreeName(long id)
getTreeName
in interface AstManagerPlugin
id
- The ID to use as a key in the lookup. This ID may be a tree ID
or a specific node ID.null
if no
such tree ID exists.public long getTreeId(java.lang.String name)
getTreeId
in interface AstManagerPlugin
name
- Tree name whose unique ID should be returned.AstManager.INVALID_ID
if the tree name doesn't exist or
is null
.public long getTreeId(long id)
getTreeId
in interface AstManagerPlugin
id
- The ID to use as a key in the lookup. This ID may be a tree ID
or a specific node ID.AstManager.INVALID_ID
if the ID is invalid.public void lockTree(long id) throws java.lang.InterruptedException, java.lang.IllegalArgumentException
unlockTree(long)
is called the same number of times
as this lock method. Thus the calls to this lock method and to
unlock
must always be balanced.
This locking has nothing to do with file system locks nor is there any non-Java locking backing this lock. Rather, this lock is a cooperative agreement between all callers (within the same JVM) that no use of the given tree will be made except when the caller holds this exclusive lock to the resource.
lockTree
in interface AstManagerPlugin
id
- Tree ID that is associated with the lock.java.lang.InterruptedException
- When an interruption occurs during blocking for the lock. If
this is thrown, the caller will NOT be holding the lock.java.lang.IllegalArgumentException
- If the ID is not a valid tree ID.public void unlockTree(long id) throws java.lang.IllegalMonitorStateException, java.lang.IllegalArgumentException
lockTree(long)
method. Thus the calls to this unlock method must always
be balanced with calls to this method.
This locking has nothing to do with file system locks nor is there any non-Java locking backing this lock. Rather, this lock is a cooperative agreement between all callers (within the same JVM) that no use of the given tree will be made except when the caller holds this exclusive lock to the resource.
unlockTree
in interface AstManagerPlugin
id
- Tree ID that is associated with the lock.java.lang.IllegalMonitorStateException
- If the calling thread does not own the lock.java.lang.IllegalArgumentException
- If the ID is not a valid tree ID.public long getNextNodeId(long id) throws AstException
getNextNodeId
in interface AstManagerPlugin
id
- The ID that specifies a tree.AstManager.INVALID_ID
if
no such tree exists.AstException
- If too many AST nodes exist.public void resetNextNodeId(long treeId) throws AstException
WARNING: there is no check on the current usage of node IDs for this file, so if AST nodes exist already they will have IDs at or above this value and duplicate IDs may (probably will) result!
resetNextNodeId
in interface AstManagerPlugin
treeId
- The ID that specifies a valid tree.AstException
- If the file ID is invalid.public long addTree(java.lang.String name) throws AstException
addTree
in interface AstManagerPlugin
name
- The tree name. Often this will be the name of a file.AstException
- If too many ASTs exist in the registry or if the input
name is null
.public boolean removeTree(long id) throws AstException
removeTree
in interface AstManagerPlugin
id
- The ID the tree to remove.true
if the tree existed in the registry (and
was removed), false
if the tree didn't exist.AstException
protected void setNextNodeId(long treeId, long nodeId) throws AstException
WARNING: there is no check on the validity of this new value, if AST nodes exist with IDs at or above this value, duplicate IDs may result!
treeId
- The ID that specifies a tree.nodeId
- The ID used for the next node ID.AstException
- If the any input is invalid.protected boolean isInvalid(long id)
AstManager.INVALID_ID
or if the tree portion does not match
a registered tree.id
- The tree or node ID to test.true
if the ID is not valid.