autohit.vm
Class VMCore

java.lang.Object
  extended byautohit.vm.VMCore
All Implemented Interfaces:
java.io.Serializable

public class VMCore
extends java.lang.Object
implements java.io.Serializable

There are four storage mechanisms.

1- A UNIVERSE: A persistent store accessible by everyone and addressable by name.

2- ENVIRONMENT core: A shared store accessible by everyone containing name/value pairs. There is only one per system, so all references point to a single static instance.

 set(String name, Object o)
 read(String name)
 test(String name)
 lock(String name)
 unlock(String name)
 waitingLock(String name)
 

3- PERSISTANT core: An owned store per VM that contains name/object pairs. It is not subject to scope rules. There can only be one instance of any named object. It is implemented as a HashMap. This primarily meant to move object data between services, executables, and calls. This is NOT syncronized and threadsafe.

 persist(String name, Object o)
 free(String name)
 has(String name)
 get(String name)
 

4- STORAGE code: An owned store per VM that contains name/value pairs. It is subject to scope rules. Within the reference of a single scope, there is only one valid instance of a new instance is created, it will supercede the previous. The storage system uses Stacks on Hashmaps to maintain scope rules. When the scope is discarded, it will take all instances with it. Of course, any instances created in the prior scope(s) will still be there. This is NOT syncronized and threadsafe.

 store(String name, Object o) 
 remove(String name)
 exists(String name)
 fetch(String name)
 replace(String name, Object o)
 getStorageNameSet()
 

You should not access the scope stack directly.

Version:
1.0 Version History EPG - Rewrite - 5Mayt03
Author:
Erich P. Gatejen
See Also:
set(String name, Object o), read(String name), test(String name), lock(String name), unlock(String name), waitingLock(String name), persist(String name, Object o), free(String name), has(String name), get(String name), store(String name, Object o), remove(String name), exists(String name), fetch(String name), replace(String name, Object o), Serialized Form

Field Summary
 java.util.HashMap callcache
          Call cache.
 java.util.Hashtable environment
          Environment.
protected  java.util.HashMap persists
          Persistant storage space.
protected  boolean scDirty
          Scope stack cache dirty flag.
protected  java.util.Stack scope
          Scope stack.
protected  java.util.HashMap storage
          Storage space.
 
Constructor Summary
VMCore()
          Default constructor.
VMCore(java.util.Hashtable env)
          Constructor.
 
Method Summary
 void discardScopeFrame()
          Discard scope frame.
 boolean exists(java.lang.String name)
          Check for an object in storage.
 java.lang.Object fetch(java.lang.String name)
          Fetch an object reference in storage.
 void free(java.lang.String name)
          Free an item from persistant storage.
 java.lang.Object get(java.lang.String name)
          Get an object in persistant storage.
 java.util.Set getStorageNameSet()
          Get a Set of variables in scope in storage.
 boolean has(java.lang.String name)
          Check persistant storage for an object.
 boolean isDirty()
          Check to see if the stack is dirty.
 java.lang.Object lock(java.lang.String name)
          Lock an item in the environment.
 void markScope()
          Marks a scope on the scope stack
 java.lang.Object peek()
          Peek into the scope stack.
 void persist(java.lang.String name, java.lang.Object o)
          Persist an item.
 java.lang.Object pop()
          Pop an object off the stack.
 void push(java.lang.Object o)
          Push an object onto the scope stack.
 java.lang.Object read(java.lang.String name)
          Read an environment item if we can.
 void remove(java.lang.String name)
          Removes an object from a store.
 void replace(java.lang.String name, java.lang.Object o)
          Replace an object in storage.
 java.lang.Object set(java.lang.String name, java.lang.Object o)
          Set an environment item if we can.
 void store(java.lang.String name, java.lang.Object o)
          Store an item.
 boolean test(java.lang.String name)
          Test if environment item is accessable.
 java.lang.String toString()
          Dump the core to a string.
 void unlock(java.lang.String name)
          Unlock an environment item if we can.
 java.lang.Object waitingLock(java.lang.String name)
          Wait for a lock on an environment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

storage

protected java.util.HashMap storage
Storage space. It is subject to scope rules. If more than one item is stored in the same name, it is converted to a stack bucket and items are stacked.

See Also:
store(String name, Object o), remove(String name), exists(String name), fetch(String name), replace(String name, Object o)

persists

protected java.util.HashMap persists
Persistant storage space. It is NOT subject to scope rules. There cannot be more than one instance of an item.

See Also:
persist(String name, Object o), free(String name), has(String name), get(String name)

scope

protected java.util.Stack scope
Scope stack. Do NOT use scope.pop() or scope.push() yourself! We must maintain the scope cache dirty flag. However, you can use peek(), empty(), and search() at your leasure().


scDirty

protected boolean scDirty
Scope stack cache dirty flag. Will be automatically set when any scope stack methods are used.


environment

public java.util.Hashtable environment
Environment. System wide store. Set by the factory.

See Also:
set(String name, Object o), read(String name), test(String name), lock(String name), unlock(String name), waitingLock(String name)

callcache

public java.util.HashMap callcache
Call cache.

Constructor Detail

VMCore

public VMCore()
Default constructor. Use this if you want a private environment. Of course, that might be pointless.


VMCore

public VMCore(java.util.Hashtable env)
Constructor. Gets a reference to the environment.

Method Detail

push

public void push(java.lang.Object o)
Push an object onto the scope stack.

Parameters:
o - the object

isDirty

public boolean isDirty()
Check to see if the stack is dirty. This is not thread safe.

Returns:
true is the stack is dirty

pop

public java.lang.Object pop()
                     throws java.lang.Exception
Pop an object off the stack. USE THIS instead of scope.pop()!!! Have to dirty the cache flag...

It'll throw any exception it encounters--most likely a EmptyStackException.

Returns:
an object reference
Throws:
java.lang.Exception

peek

public java.lang.Object peek()
Peek into the scope stack.

Returns:
a reference to the object or NULL if the stack is empty

store

public void store(java.lang.String name,
                  java.lang.Object o)
           throws VMException
Store an item. It is subject to scope rules. It will overload a prior instance with the same name, but not overwrite it.

Parameters:
name - object name as a string
o - the object
Throws:
VMException
See Also:
VMException

remove

public void remove(java.lang.String name)
            throws VMException
Removes an object from a store. No real reasion to use this. It will throw an exception only if something realy bad happened. This will not remove the item from the scope stack!

Parameters:
name - object name as a string
Throws:
VMException
See Also:
VMException

exists

public boolean exists(java.lang.String name)
               throws VMException
Check for an object in storage.

Parameters:
name - object name as a string
Throws:
VMException
See Also:
VMException

fetch

public java.lang.Object fetch(java.lang.String name)
                       throws VMException
Fetch an object reference in storage.

Parameters:
name - object name as a string
Returns:
the object or null if it can't be found
Throws:
VMException
See Also:
VMException

getStorageNameSet

public java.util.Set getStorageNameSet()
                                throws VMException
Get a Set of variables in scope in storage.

Returns:
A Set of Strings that are the variable names.
Throws:
VMException
See Also:
VMException

replace

public void replace(java.lang.String name,
                    java.lang.Object o)
             throws VMException
Replace an object in storage. Obviously it will replace the nearest in scope. If the object doesn't exist, it will throw an exception.

Parameters:
name - object name as a string
o - object reference
Throws:
VMException
See Also:
VMException

persist

public void persist(java.lang.String name,
                    java.lang.Object o)
             throws VMException
Persist an item. It is NOT subject to scope rules. It will overwrite a prior instance of it.

Parameters:
name - object name as a string
o - the object
Throws:
VMException
See Also:
VMException

free

public void free(java.lang.String name)
          throws VMException
Free an item from persistant storage.

Parameters:
name - object name as a string
Throws:
VMException
See Also:
VMException

get

public java.lang.Object get(java.lang.String name)
                     throws VMException
Get an object in persistant storage.

Parameters:
name - object name as a string
Returns:
the object or null if it doesn't exist.
Throws:
VMException
See Also:
VMException

has

public boolean has(java.lang.String name)
            throws VMException
Check persistant storage for an object.

Parameters:
name - object name as a string
Returns:
if the object exists
Throws:
VMException
See Also:
VMException

markScope

public void markScope()
Marks a scope on the scope stack


discardScopeFrame

public void discardScopeFrame()
                       throws VMException
Discard scope frame. This will remove all items on the scope to and including the top-most recent VMIScope object. It will pop the whole damned stack if it doesn't find one...

Throws:
any - VMException
VMException

lock

public java.lang.Object lock(java.lang.String name)
                      throws VMException
Lock an item in the environment. It will get a reference to the object.

Parameters:
name - object name as a string
Returns:
an vmobject reference or null if it is already locked
Throws:
VMException - for en error or if the item doesn't exist.
See Also:
VMException

unlock

public void unlock(java.lang.String name)
            throws VMException
Unlock an environment item if we can. Ignore errors except if the item doesn't exist or it is owned by someone else.

Parameters:
name - object name as a string
Throws:
VMException - for en error or if the item doesn't exist.
See Also:
VMException

read

public java.lang.Object read(java.lang.String name)
                      throws VMException
Read an environment item if we can. Ignore errors except if the item doesn't exist or it is owned by someone else.

Parameters:
name - object name as a string
Returns:
the item or null if it is empty
Throws:
VMException - for en error or if the item doesn't exist.
See Also:
VMException

set

public java.lang.Object set(java.lang.String name,
                            java.lang.Object o)
                     throws VMException
Set an environment item if we can. This will throw an exception if the item exists and is locked. If it doesn't exist, this will create it.

Parameters:
name - object name as a string
Returns:
the item or null if it is empty
Throws:
VMException - for en error or if the item doesn't exist.
See Also:
VMException

waitingLock

public java.lang.Object waitingLock(java.lang.String name)
                             throws VMException
Wait for a lock on an environment. It will get a reference to the object.

Parameters:
name - object name as a string
Returns:
an vmobject reference or null if it is already locked
Throws:
VMException - for en error or if the item doesn't exist.
See Also:
VMException

test

public boolean test(java.lang.String name)
             throws VMException
Test if environment item is accessable.

Parameters:
name - object name as a string
Returns:
true if it is available, otherwise false.
Throws:
VMException - for en error or if the item doesn't exist.
See Also:
VMException

toString

public java.lang.String toString()
Dump the core to a string.

Returns:
an empty string for now. this will be dangerous. TODO implement toString for VMCore


Test.