structures
Class DBImplementation

java.lang.Object
  |
  +--structures.DBImplementation

public class DBImplementation
extends Object
implements DBInterface

Implements DBInterface using files. The information in the files are structured in Hashtables.

See Also:
DBInterface, ObjectInputStream, Stream, Hashtable

Constructor Summary
DBImplementation()
           
 
Method Summary
 void associate(String threadName, String groupName, String agentName)
          Associates a thread with an agent and its group.
 void createGroup(String groupName, long time)
          Creates a new group and specifies the lifetime of the agents that will belong to the group.
 void createRoot(String rootName)
          Creates an empty root in the database.
 void deleteGroup(String groupName)
          Deletes an existing group from the database.
 void deleteRoot(String rootName)
          Deletes an existing group from the database.
 Object get(String rootName)
          Retrieves a root content from the database.
 String getAgentName(String threadName)
          Retrieves from the database the name of the agent associated to the specified thread.
 String getGroup(String threadName)
          Retrieves from the database the name of the group associated to the specified thread.
 String[] getGroups()
          Retrieves the names of all the groups stored in the database.
 String[] getGroupsToRead(String rootName)
          Retrieves from the database the names of the groups with read permission to a specific root.
 String[] getGroupsToWrite(String rootName)
          Retrieves from the database the names of the groups with write and delete permissions to a specific root.
 String[] getRoots()
          Retrieves the names of all the roots stored in the database.
 String[] getRootsToRead(String groupName)
          Retrieves from the database the names of the roots that this group has permission to read.
 String[] getRootsToWrite(String groupName)
          Retrieves from the database the names of the roots that this group has permission to write and delete.
 long getTime(String groupName)
          Retrieves from the database the lifetime of the agents that belongs to this group.
 void initialize()
          Initializes the database with the firsts groups.
 boolean isGroup(String groupName)
          Tests if this group name already exists in the database.
 boolean isReadable(String rootName, String groupName)
          Tests if a group has permission to read a root.
 boolean isRoot(String rootName)
          Tests if a root exists in the database.
 boolean isWriteable(String rootName, String groupName)
          Tests if a group has permission to write and delete a root.
 void removeAssociation(String threadName)
          Removes the association between an agent and a thread.
 void set(String rootName, Object root)
          Updates a root content.
 void setGroupToRead(String rootName, String groupToRead)
          Gives permission for a group to read a specified root.
 void setGroupToWrite(String rootName, String groupToWrite)
          Gives permission for a group to read a specified root.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBImplementation

public DBImplementation()
Method Detail

initialize

public void initialize()
Initializes the database with the firsts groups. Starts the groups database by creating the superusers and commonusers groups. The superusers group have all permissions and its aplications can run forever. The commonusers group have limited permissions and its applications have 1 hour to run.
Specified by:
initialize in interface DBInterface

createGroup

public void createGroup(String groupName,
                        long time)
Creates a new group and specifies the lifetime of the agents that will belong to the group. The superusers time is set to 0 Only the superusers group has permission to access this method.
Specified by:
createGroup in interface DBInterface
Parameters:
groupName - the name of the group to be created
time - the lifetime of the agents that belongs to this group in milliseconds.
Throws:
SecurityException - trown by the SecurityManager if the group trying to acess this method in not the superusers group.
GroupException - If the group already exists in the database

deleteGroup

public void deleteGroup(String groupName)
Deletes an existing group from the database. Only the superusers group has permission to access this method.
Specified by:
deleteGroup in interface DBInterface
Parameters:
groupName - the name of the group to be deleted
Throws:
SecurityException - trown by the SecurityManager if the group trying to acess this method in not the superusers group.
GroupException - If the group does not exist in the database

getRootsToRead

public String[] getRootsToRead(String groupName)
Retrieves from the database the names of the roots that this group has permission to read.
Specified by:
getRootsToRead in interface DBInterface
Parameters:
groupName - the group name
Returns:
the names of the roots this group has permission to read.

getRootsToWrite

public String[] getRootsToWrite(String groupName)
Retrieves from the database the names of the roots that this group has permission to write and delete.
Specified by:
getRootsToWrite in interface DBInterface
Parameters:
groupName - the group name
Returns:
the names of the roots this group has permission to write and delete.

getTime

public long getTime(String groupName)
Retrieves from the database the lifetime of the agents that belongs to this group.
Specified by:
getTime in interface DBInterface
Parameters:
groupName - the group name
Returns:
the lifetime of this group's agents
Throws:
GroupException - If the group does not exist in the database.

isGroup

public boolean isGroup(String groupName)
Tests if this group name already exists in the database.
Specified by:
isGroup in interface DBInterface
Parameters:
groupName - the group name
Returns:
true if the group already exists, false otherwise.

getGroups

public String[] getGroups()
Retrieves the names of all the groups stored in the database.
Specified by:
getGroups in interface DBInterface
Returns:
the names of the stored groups.

createRoot

public void createRoot(String rootName)
Creates an empty root in the database.
Specified by:
createRoot in interface DBInterface
Parameters:
rootName - the name of the root to be created
Throws:
RootException - If the root already exists in the database.

get

public Object get(String rootName)
Retrieves a root content from the database. Only the groups that have read permission can access the specified root.
Specified by:
get in interface DBInterface
Parameters:
rootName - the root name
Returns:
the contents of this root stored in the database
Throws:
RootException - thrown if the root is not stored in the database.
SecurityException - trown by the SecurityManager if the group does not have read permission to this root.

deleteRoot

public void deleteRoot(String rootName)
Deletes an existing group from the database. Only the groups that have write permission can access the specified root.
Specified by:
deleteRoot in interface DBInterface
Parameters:
rootName - the name of the root to be deleted
Throws:
RootException - thrown if the root does not exist in the database.
SecurityException - trown by the SecurityManager if the group does not have write permission to this root.

set

public void set(String rootName,
                Object root)
Updates a root content. Only the groups that have write permission can update the specified root.
Specified by:
set in interface DBInterface
Parameters:
rootName - the name of the root to be updated.
root - the contents to be stored.
Throws:
RootException - thrown if the root does not exist in the database.
SecurityException - trown by the SecurityManager if the group does not have write permission to this root.

setGroupToRead

public void setGroupToRead(String rootName,
                           String groupToRead)
Gives permission for a group to read a specified root.
Specified by:
setGroupToRead in interface DBInterface
Parameters:
rootName - the root name
groupToRead - the group name
Throws:
RootException - thrown if the root does not exist in the database.
GroupException - thrown if the group does not exist in the database.

setGroupToWrite

public void setGroupToWrite(String rootName,
                            String groupToWrite)
Gives permission for a group to read a specified root.
Specified by:
setGroupToWrite in interface DBInterface
Parameters:
rootName - the root name
groupToRead - the group name
Throws:
RootException - thrown if the root does not exist in the database.
GroupException - thrown if the group does not exist in the database.

getRoots

public String[] getRoots()
Retrieves the names of all the roots stored in the database.
Specified by:
getRoots in interface DBInterface
Returns:
the roots names

isRoot

public boolean isRoot(String rootName)
Tests if a root exists in the database.
Specified by:
isRoot in interface DBInterface
Parameters:
rootName - the root name
Returns:
true if the roor already exists, false otherwise.

getGroupsToRead

public String[] getGroupsToRead(String rootName)
Retrieves from the database the names of the groups with read permission to a specific root.
Specified by:
getGroupsToRead in interface DBInterface
Parameters:
rootName - the root name
Returns:
the names of the groups that can read this root

getGroupsToWrite

public String[] getGroupsToWrite(String rootName)
Retrieves from the database the names of the groups with write and delete permissions to a specific root.
Specified by:
getGroupsToWrite in interface DBInterface
Parameters:
rootName - the root name
Returns:
the names of the groups that can write and delete this root

isReadable

public boolean isReadable(String rootName,
                          String groupName)
Tests if a group has permission to read a root.
Specified by:
isReadable in interface DBInterface
Parameters:
rootName - the root name
groupName - the group name
Returns:
true if the group has permission to read the root, false otherwise.
Throws:
RootException - if the root does not exist in the database.

isWriteable

public boolean isWriteable(String rootName,
                           String groupName)
Tests if a group has permission to write and delete a root.
Specified by:
isWriteable in interface DBInterface
Parameters:
rootName - the root name
groupName - the group name
Returns:
true if the group has permission to write and delete the root, false otherwise.
Throws:
RootException - if the root does not exist in the database.

associate

public void associate(String threadName,
                      String groupName,
                      String agentName)
Associates a thread with an agent and its group. It is necessary when a new agent starts running. If each agent is executed in a thread its possible to know to which group the thread belongs to.
Specified by:
associate in interface DBInterface
Parameters:
threadName - the thread name
groupName - the group name
agentName - the agent name

getGroup

public String getGroup(String threadName)
Retrieves from the database the name of the group associated to the specified thread.
Specified by:
getGroup in interface DBInterface
Parameters:
threadName - the thread name
Returns:
the group name

getAgentName

public String getAgentName(String threadName)
Retrieves from the database the name of the agent associated to the specified thread.
Specified by:
getAgentName in interface DBInterface
Parameters:
threadName - the thread name
Returns:
the agent name

removeAssociation

public void removeAssociation(String threadName)
Removes the association between an agent and a thread. It is necessary when an agent finishes its execution or when its lifetime ends.
Specified by:
removeAssociation in interface DBInterface
Parameters:
threadName - the name of the thread to be excluded