net.sf.farrago.test
Class FarragoObjectCacheTest.RentalCarAgency

java.lang.Object
  extended by net.sf.farrago.test.FarragoObjectCacheTest.RentalCarAgency
All Implemented Interfaces:
FarragoObjectCache.CachedObjectFactory
Enclosing class:
FarragoObjectCacheTest

private class FarragoObjectCacheTest.RentalCarAgency
extends Object
implements FarragoObjectCache.CachedObjectFactory

RentalCarAgency exemplifies a cache of reusable objects.


Field Summary
private  boolean exclusiveRentals
           
private  FarragoObjectCache fleet
           
private  FarragoCompoundAllocation owner
           
 
Constructor Summary
FarragoObjectCacheTest.RentalCarAgency(boolean exclusiveRentals, long maxTires)
          Creates a new agency.
 
Method Summary
 void decommissionEntireFleet()
          Decommissions all cars in the fleet; subsequent requests will require creation of new cars.
 long getTiresInFleet()
           
 void initializeEntry(Object key, FarragoObjectCache.UninitializedEntry entry)
          Initializes a cache entry.
 boolean isExclusive()
           
 boolean isStale(Object value)
          Tests a cached object for staleness.
(package private)  FarragoObjectCacheTest.RentalCarAgreement rentCar(String description)
          Rents out a car of a given description.
(package private)  void returnCar(FarragoObjectCacheTest.RentalCarAgreement agreement)
          Records that a customer has returned a car, terminating the agreement.
 void shutDown()
          Shuts down this agency and verifies that its business affairs were cleanly terminated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

owner

private FarragoCompoundAllocation owner

fleet

private FarragoObjectCache fleet

exclusiveRentals

private boolean exclusiveRentals
Constructor Detail

FarragoObjectCacheTest.RentalCarAgency

FarragoObjectCacheTest.RentalCarAgency(boolean exclusiveRentals,
                                       long maxTires)
Creates a new agency.

Parameters:
exclusiveRentals - if true, cars are rented out exclusively; if false, cars can be shared by customers as long as the description of the car is the same (more like hailing a cab and sharing the ride)
maxTires - maximum number of tires which can exist in fleet at any one time
Method Detail

rentCar

FarragoObjectCacheTest.RentalCarAgreement rentCar(String description)
Rents out a car of a given description.

Parameters:
description - of car to rent
Returns:
rental agreement

returnCar

void returnCar(FarragoObjectCacheTest.RentalCarAgreement agreement)
Records that a customer has returned a car, terminating the agreement.

Parameters:
agreement - agreement to be terminated

initializeEntry

public void initializeEntry(Object key,
                            FarragoObjectCache.UninitializedEntry entry)
Description copied from interface: FarragoObjectCache.CachedObjectFactory
Initializes a cache entry.

Specified by:
initializeEntry in interface FarragoObjectCache.CachedObjectFactory
Parameters:
key - key of the object to be constructed
entry - to initialize by calling its FarragoObjectCache.UninitializedEntry.initialize(java.lang.Object, long, boolean) method; failing to call initialize will lead to a subsequent assertion (unless an exception is thrown to indicate initialization failure)

isStale

public boolean isStale(Object value)
Description copied from interface: FarragoObjectCache.CachedObjectFactory
Tests a cached object for staleness.

Specified by:
isStale in interface FarragoObjectCache.CachedObjectFactory
Returns:
true if object is stale, meaning it must not be returned from a pin call, and should be discarded from the cache when detected

getTiresInFleet

public long getTiresInFleet()
Returns:
current number of tires on all cars in fleet (regardless of whether those cars are currently rented out)

decommissionEntireFleet

public void decommissionEntireFleet()
Decommissions all cars in the fleet; subsequent requests will require creation of new cars. May only be called when no cars are currently rented out.


isExclusive

public boolean isExclusive()
Returns:
whether this agency rents cars exclusively

shutDown

public void shutDown()
Shuts down this agency and verifies that its business affairs were cleanly terminated. May only be called when no cars are currently rented out.