live.cache
Class Cache

java.lang.Object
  extended bylive.cache.Cache

public class Cache
extends Object

Cache uses live's DTOs to cache data obtained from the z/VM server. Updates to the data within (e.g. calling #addGuest(Guest)) does not update anything on the server. This data is meant to be a model of what is on the z/VM instance being managed. This data should be updated to reflect successful changes made to the actual server. The cache is the source of data for the pages listing guests/group (except for marking active and inactive guests), networks, and (later) shared storage. Other pages, such as member lists for networks and information about guests, is queried live when those pages are loaded.

Author:
Jason J. Herne, Evan Driscoll (substantial changes/rewrites)

Field Summary
static int ERROR
           
(package private)  Map groupList
          Maps cached group names to a group DTO
(package private)  Map guestList
          Maps cached guest names to a guest DTO
(package private)  LinkedList networkList
          Stores the cached networks as network DTOs
(package private)  LinkedList sharedStorageList
           
private  int state
           
(package private)  ZVMTasks tasks
          This is the tasks object used when updating the cache from the server
static int UNSET
           
static int UPDATING
           
static int VALID
           
 
Constructor Summary
Cache(String hostName, int port, String userName, String password)
          Creates a new instance of Cache that will connect to hostName on port port with the specified userName and password.
 
Method Summary
private  void addGroupsToList(LinkedList groups)
          Adds all of the groups in groups to the cache, while at the same time updating all of the guests in each so that they know about what group they are in.
 void addGuest(String guestName)
          Adds a guest to the cache and leaves it ungrouped.
 void addGuest(String guestName, String groupName)
          Adds a guest to the cache and caches his group name as groupName.
private  void addGuestsToList(LinkedList guests)
          Adds everyone in guests to the cache.
 void addNetwork(Network net)
          Adds a network to the cache
 void addNetwork(String networkName, int networkType)
          Adds a network to the cache by name and type
 void addSavedSegment(String ssName)
          Add a saved segment to the cache
private  void addUngroupedGuestsToUngrouped()
          This function goes through the list of guests and adds any that do not belong to a group to the member list of the ungrouped list.
 void changeGuestsGroup(String guestName, String newGroupName)
          Change the group that a cached guest belongs to.
private  void clearCache()
          Removes all cached data from the cache.
private  void clearGuestList()
          Remove all guests and groups from the cache
private  void clearNetworks()
          Remove all the networks from the cache
 void clearSavedSegments()
          Remove all shared storage objects from the shared storage list.
 LinkedList getGroupNames()
          Returns a LinkedList holding names (as Strings) of all groups in the cache.
 LinkedList getGroups()
          Returns a list of Group objects corresponding to all groups in the cache.
 Guest getGuest(String name)
          Gets a specific Guest object
 LinkedList getGuestNamesInGroup(String groupName)
          Gets all guest names corresponding to the guests in a given group.
 ListIterator getGuests()
          Get an ListIterator that can be used to visit all guests in the cache.
 LinkedList getGuestsInGroup(String groupName)
          Gets all guest objects corresponding to the guests in a given group.
 ListIterator getNetworks()
          Returns an iterator that can be used to visit all of the networks in the cache.
 ListIterator getSavedSegments()
          Returns an iterator that can be used to see all the saved segments in the cache
 int getState()
           
 LinkedList getUngroupedGuests()
          Gets all guest objects that are not in a group.
 void removeGuest(Guest guest)
          Removes a guest from the cached list.
 void removeGuest(String guestName)
          Removes a guest (given by its name) from the cached list.
 void removeNetwork(String networkName)
          Removes the network with the given name from the cache.
 void removeSavedSegment(String ssName)
          Remove a saved segment from the cache
protected  void setState(int newState)
           
protected  void swap(Cache c)
          Swaps out the current cache for an updated one, updates with the new information puts the current cache into the old one, synchronized to avoid cache problems
 void updateCacheFromServer()
          Refreshes the cache so that it is consistent with the server
private  void updateGuestsGroupsFromServer()
          Refreshes the list of guests and groups from the server.
private  void updateNetworksFromServer()
          Refreshes the network list from the server
private  void updateSharedStorageFromServer()
          Refreshes the saved segment list from the server
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALID

public static final int VALID
See Also:
Constant Field Values

UPDATING

public static final int UPDATING
See Also:
Constant Field Values

ERROR

public static final int ERROR
See Also:
Constant Field Values

UNSET

public static final int UNSET
See Also:
Constant Field Values

state

private int state

groupList

Map groupList
Maps cached group names to a group DTO


guestList

Map guestList
Maps cached guest names to a guest DTO


networkList

LinkedList networkList
Stores the cached networks as network DTOs


sharedStorageList

LinkedList sharedStorageList

tasks

ZVMTasks tasks
This is the tasks object used when updating the cache from the server

Constructor Detail

Cache

public Cache(String hostName,
             int port,
             String userName,
             String password)
Creates a new instance of Cache that will connect to hostName on port port with the specified userName and password.

Method Detail

getState

public int getState()

setState

protected void setState(int newState)

addGuest

public void addGuest(String guestName,
                     String groupName)
Adds a guest to the cache and caches his group name as groupName. If groupName is null, adds the guest to ungrouped. If the guest is already present in the cache, throws a CacheException saying so.

Parameters:
guestName - The name of the new cached guest entry.
groupName - The group to associate with the guest in the new entry.

addGuest

public void addGuest(String guestName)
Adds a guest to the cache and leaves it ungrouped. This means the group entry for this guest will be null.

Parameters:
guestName - The name of the new cached guest entry.

removeGuest

public void removeGuest(Guest guest)
Removes a guest from the cached list. No checking that guest is actually in the cache.

Parameters:
guest - The guest object to remove from the cached lists.

removeGuest

public void removeGuest(String guestName)
Removes a guest (given by its name) from the cached list. If the guest is not found, nothing happens.

Parameters:
guestName - The name of the guest to remove from the cached lists.

changeGuestsGroup

public void changeGuestsGroup(String guestName,
                              String newGroupName)
Change the group that a cached guest belongs to. If we do not find that guest, nothing happens.

Parameters:
guestName - The name of the guest we wish to change.
newGroupName - The name we wish to set as this guests group.

getGuests

public ListIterator getGuests()
Get an ListIterator that can be used to visit all guests in the cache.

Returns:
ListIteratorthat can be used to visit all guests in the cache.

clearGuestList

private void clearGuestList()
Remove all guests and groups from the cache


getGroupNames

public LinkedList getGroupNames()
Returns a LinkedList holding names (as Strings) of all groups in the cache.

Returns:
The list of groups in the cache as Strings.

getGroups

public LinkedList getGroups()
Returns a list of Group objects corresponding to all groups in the cache. (The group objects will know about their group members.)

Returns:
List of groups in the cache, as Group objects.

getGuestsInGroup

public LinkedList getGuestsInGroup(String groupName)
Gets all guest objects corresponding to the guests in a given group. If groupName isn't found, returns an empty list.

Parameters:
groupName - The group to search for.
Returns:
List containing all guests in the given group (as DTO objects)

getGuestNamesInGroup

public LinkedList getGuestNamesInGroup(String groupName)
Gets all guest names corresponding to the guests in a given group. If groupName isn't found, returns an empty list.

Parameters:
groupName - The group to search for.
Returns:
List containing all guest names in the given group (as Strings)

getUngroupedGuests

public LinkedList getUngroupedGuests()
Gets all guest objects that are not in a group.

Returns:
List containing all guests in the given group (as DTO objecs).

getGuest

public Guest getGuest(String name)
Gets a specific Guest object

Parameters:
name - The name of the guest to return
Returns:
The Guest of that guest

addNetwork

public void addNetwork(String networkName,
                       int networkType)
Adds a network to the cache by name and type

Parameters:
networkName - The name of the network
networkType - The type of the network (see Network for constants you'll probably want to use)

addNetwork

public void addNetwork(Network net)
Adds a network to the cache

Parameters:
net - The network to add

removeNetwork

public void removeNetwork(String networkName)
Removes the network with the given name from the cache. If the network isn't found, nothing happens.

Parameters:
networkName - The name of the network to remove

getNetworks

public ListIterator getNetworks()
Returns an iterator that can be used to visit all of the networks in the cache.

Returns:
An iterator into the Cache's network collection

clearNetworks

private void clearNetworks()
Remove all the networks from the cache


addSavedSegment

public void addSavedSegment(String ssName)
Add a saved segment to the cache

Parameters:
ssName - Name of the saved segment to add

removeSavedSegment

public void removeSavedSegment(String ssName)
Remove a saved segment from the cache

Parameters:
ssName - Name of the saved segment to remove

getSavedSegments

public ListIterator getSavedSegments()
Returns an iterator that can be used to see all the saved segments in the cache

Returns:
ListIterator An iterator for the cache's saved segment collection

clearSavedSegments

public void clearSavedSegments()
Remove all shared storage objects from the shared storage list.


clearCache

private void clearCache()
Removes all cached data from the cache.


updateCacheFromServer

public void updateCacheFromServer()
                           throws CacheException
Refreshes the cache so that it is consistent with the server

Throws:
CacheException

updateGuestsGroupsFromServer

private void updateGuestsGroupsFromServer()
                                   throws CacheException
Refreshes the list of guests and groups from the server.

Throws:
CacheException

addGuestsToList

private void addGuestsToList(LinkedList guests)
Adds everyone in guests to the cache. All of the guests will be added as ungrouped.

Parameters:
guests - The list of guests to add to the cache

addGroupsToList

private void addGroupsToList(LinkedList groups)
Adds all of the groups in groups to the cache, while at the same time updating all of the guests in each so that they know about what group they are in. If there is a group with a member which the cache doesn't know about (i.e. it's not in the guest list), this assumes that you don't want it in the group and so tries to remove it server side in addition to not adding it here. This function takes ownership of each of the objects in groups.

Parameters:
groups - The groups to add to the cache (as Group s)

addUngroupedGuestsToUngrouped

private void addUngroupedGuestsToUngrouped()
This function goes through the list of guests and adds any that do not belong to a group to the member list of the ungrouped list.


updateNetworksFromServer

private void updateNetworksFromServer()
                               throws CacheException
Refreshes the network list from the server

Throws:
CacheException - If there's a problem. (Use getCause() to determine what the problem actually is.)

updateSharedStorageFromServer

private void updateSharedStorageFromServer()
                                    throws CacheException
Refreshes the saved segment list from the server

Throws:
CacheException - If there's a problem. (Use getCause() to determine what the problem actually is.)

swap

protected void swap(Cache c)
Swaps out the current cache for an updated one, updates with the new information puts the current cache into the old one, synchronized to avoid cache problems

Parameters:
c - New cache to swap in


Copyright © 2005