orca.shirako.common
Class ReservationSet

java.lang.Object
  extended by orca.shirako.common.ReservationSet
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<ResourceReservation>

public class ReservationSet
extends java.lang.Object
implements java.lang.Cloneable, java.lang.Iterable<ResourceReservation>

ReservationSet is a collection of reservations indexed by ReservationID, basically a HashMap wrapper with a few auxiliary methods.

ReservationSet is used primarily by resource managers and as an internal representation of the resources in a lease or slice.


Field Summary
protected  java.util.HashMap<ReservationID,ResourceReservation> reservations
          The internal hash map.
 
Constructor Summary
ReservationSet()
          Crates a new empty set.
 
Method Summary
 void add(ReservationSet set)
          Adds the given reservation set to the reservation set.
 void add(ResourceReservation reservation)
          Adds the reservation to the set.
 void clear()
          Removes all reservations from the set.
 ReservationSet clone()
           
 boolean contains(ReservationID rid)
          Checks if the set contains a reservation with the specified identifier.
 boolean contains(ResourceReservation reservation)
          Checks if the reservation is part of the set.
 void count(ResourceCount rc, java.util.Date when)
          Tally up resources in the ReservationSet.
 long forecast(java.util.Date when)
          Count the resources forecast to be held or needed by reservations in this set.
 ResourceReservation get(ReservationID rid)
          Retrieves a reservation from the set.
 ResourceReservation getException(ReservationID rid)
          Retrieves a reservation from the set.
 boolean isEmpty()
          Checks if the set is empty
 java.util.Iterator<ResourceReservation> iterator()
          Returns an iterator for the set.
 void remove(ResourceReservation reservation)
          Removes the specified reservation.
 int size()
          Returns the number of reservations in the set.
 java.lang.String toString()
           
 java.lang.String toStringByState(java.lang.String prefix, int state, java.util.Date when)
          Creates a string of all reservations in the set, which are in the given state
 java.lang.String toStringSummaryByState(java.lang.String prefix, java.util.Date when)
          Creates a string of all reservations in the set grouped by reservation state.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

reservations

protected java.util.HashMap<ReservationID,ResourceReservation> reservations
The internal hash map.

Constructor Detail

ReservationSet

public ReservationSet()
Crates a new empty set.

Method Detail

clone

public ReservationSet clone()
Overrides:
clone in class java.lang.Object

add

public void add(ResourceReservation reservation)
Adds the reservation to the set.

Parameters:
reservation - the reservation to add

add

public void add(ReservationSet set)
Adds the given reservation set to the reservation set.

Parameters:
set - the set to add

iterator

public java.util.Iterator<ResourceReservation> iterator()
Returns an iterator for the set.

Specified by:
iterator in interface java.lang.Iterable<ResourceReservation>
Returns:
an iterator for the set

remove

public void remove(ResourceReservation reservation)
Removes the specified reservation.

Parameters:
reservation -

getException

public ResourceReservation getException(ReservationID rid)
                                 throws java.lang.Exception
Retrieves a reservation from the set.

Parameters:
rid - the reservation identifier
Throws:
java.lang.Exception - if the requested reservation is not present in the set

get

public ResourceReservation get(ReservationID rid)
Retrieves a reservation from the set.

Parameters:
rid - reservation identifier

contains

public boolean contains(ReservationID rid)
Checks if the set contains a reservation with the specified identifier.

Parameters:
rid - reservation identifier

contains

public boolean contains(ResourceReservation reservation)
Checks if the reservation is part of the set.

Parameters:
reservation - reservation to check
Returns:

isEmpty

public boolean isEmpty()
Checks if the set is empty

Returns:
true if the set is empty

count

public void count(ResourceCount rc,
                  java.util.Date when)
Tally up resources in the ReservationSet. Note: "just a hint" unless kernel lock is held.

Parameters:
rc - holder for counts
when - date relative to which to do the counting

forecast

public long forecast(java.util.Date when)
Count the resources forecast to be held or needed by reservations in this set. The "forecast" is defined by Reservation.forecastUnits for the reservations. Note that this primitive is meaningful only when all reservations in the set are the same type: caller beware.

Parameters:
when - some time now or in the future
Returns:
total number of units
Throws:
java.lang.Exception

toStringSummaryByState

public java.lang.String toStringSummaryByState(java.lang.String prefix,
                                               java.util.Date when)
Creates a string of all reservations in the set grouped by reservation state.

Parameters:
prefix - prefix to prepend to each state summary
when - time instance
Returns:
a string representation of the reservations in the set

toStringByState

public java.lang.String toStringByState(java.lang.String prefix,
                                        int state,
                                        java.util.Date when)
Creates a string of all reservations in the set, which are in the given state

Parameters:
prefix - prefix to prepend
state - state reservation must be in
when - time instance
Returns:
a string representation of the reservations in the set, which are in the given state

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

size

public int size()
Returns the number of reservations in the set.

Returns:
the size of the reservation set

clear

public void clear()
Removes all reservations from the set.



Copyright © 2007 Network/Internet Computing Lab. All Rights Reserved.