Lightweight Bartering Grid

lbg.peer.core.rms
Class ResourceTracker

java.lang.Object
  extended by lbg.peer.core.rms.ResourceTracker

public class ResourceTracker
extends java.lang.Object

A ResourceTracker tracks Resources for the ResourceManager that uses it.

Author:
Cyril Briquet

Constructor Summary
ResourceTracker(Peer managed_peer, ResourceDataTracker data_tracker)
           
 
Method Summary
 int countBusyLocalResources()
           
 int countBusySupplyingResources()
           
 int countIdleResources()
           
 int countResources()
           
 ResourceHandle getFirstBusyLocalResource()
          Deprecated.  
 ResourceHandle getFirstBusySupplyingResource()
          Deprecated.  
 ResourceHandle getFirstIdleResource()
          Deprecated.  
 java.util.Iterator<ResourceUsageData> getIdleResourcesIterator()
          Returns an Iterator over idle Resources usage data.
 ResourceHandle getRandomBusyLocalResource()
          Returns a random busy local Resource.
 ResourceHandle getRandomBusySupplyingResource()
          Returns a random busy supplying Resource.
 ResourceHandle getRandomIdleResource()
          Returns a random idle Resource.
 ResourceState getResourceState(ResourceHandle rh)
           
 ResourceUsageData getResourceUsageData(ResourceHandle rh)
           
 WorkingSet getWorkingSetOfIdleResource(ResourceHandle rh)
          Returns the WorkingSet of the target Resource, if target Resource is idle.
 boolean hasBusyLocalResource()
           
 boolean hasBusySupplyingResource()
           
 boolean hasIdleResource()
           
 java.lang.String toString()
           
 void trackResource(ResourceHandle rh)
          Starts the tracking of the target Resource.
 ResourceUsageData untrackResource(ResourceHandle rh)
          Stops the tracking of the target Resource.
 WorkingSet updateResourceStatusToBusy(ResourceHandle rh, ResourceState state, Task t)
          Updates target Resource status from idle to busy local or busy supplying, depending on the value of target state.
 WorkingSet updateResourceStatusToIdle(ResourceHandle rh, ResourceState state)
          Updates target Resource status from busy local or busy supplying, depending on the value of target state, to idle.
 double utilization()
          Returns the Peer utilization, i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceTracker

public ResourceTracker(Peer managed_peer,
                       ResourceDataTracker data_tracker)
                throws GridException
Throws:
GridException
Method Detail

toString

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

countResources

public int countResources()

countIdleResources

public int countIdleResources()

countBusyLocalResources

public int countBusyLocalResources()

countBusySupplyingResources

public int countBusySupplyingResources()

hasIdleResource

public boolean hasIdleResource()

hasBusyLocalResource

public boolean hasBusyLocalResource()

hasBusySupplyingResource

public boolean hasBusySupplyingResource()

utilization

public double utilization()
                   throws GridException
Returns the Peer utilization, i.e. total busy time of all currently registered Resources, divided by their total registration time.

Returns:
Peer utilization, in [0.0..1.0]
Throws:
GridException

getResourceState

public ResourceState getResourceState(ResourceHandle rh)
                               throws GridException
Throws:
GridException

getResourceUsageData

public ResourceUsageData getResourceUsageData(ResourceHandle rh)
                                       throws GridException
Throws:
GridException

trackResource

public void trackResource(ResourceHandle rh)
                   throws GridException
Starts the tracking of the target Resource.

Parameters:
rh - target Resource
Throws:
GridException - if a parameter is illegal

untrackResource

public ResourceUsageData untrackResource(ResourceHandle rh)
                                  throws GridException
Stops the tracking of the target Resource.

Parameters:
rh - target Resource
Returns:
Resource usage data)
Throws:
GridException - if a parameter is illegal

getIdleResourcesIterator

public java.util.Iterator<ResourceUsageData> getIdleResourcesIterator()
Returns an Iterator over idle Resources usage data.

Returns:
Iterator over idle Resources usage data

getWorkingSetOfIdleResource

public WorkingSet getWorkingSetOfIdleResource(ResourceHandle rh)
                                       throws GridException
Returns the WorkingSet of the target Resource, if target Resource is idle.

Note: does not assume that Resource is idle, but rather returns a WorkingSet only when it is idle.

Parameters:
rh - target Resource
Returns:
WorkingSet of target Resource if target Resource is idle, or null if target Resource is not idle
Throws:
GridException - if a parameter is illegal

getFirstIdleResource

@Deprecated
public ResourceHandle getFirstIdleResource()
Deprecated. 

Returns an arbitrary (i.e. the first) idle Resource.

Returns:
arbitrary idle Resource

getFirstBusyLocalResource

@Deprecated
public ResourceHandle getFirstBusyLocalResource()
Deprecated. 

Returns an arbitrary (i.e. the first) busy local Resource.

Returns:
arbitrary busy local Resource

getFirstBusySupplyingResource

@Deprecated
public ResourceHandle getFirstBusySupplyingResource()
Deprecated. 

Returns an arbitrary (i.e. the first) busy supplying Resource.

Returns:
arbitrary busy supplying Resource

getRandomIdleResource

public ResourceHandle getRandomIdleResource()
                                     throws GridException
Returns a random idle Resource.

Returns:
random idle Resource
Throws:
GridException

getRandomBusyLocalResource

public ResourceHandle getRandomBusyLocalResource()
                                          throws GridException
Returns a random busy local Resource.

Returns:
random busy local Resource
Throws:
GridException

getRandomBusySupplyingResource

public ResourceHandle getRandomBusySupplyingResource()
                                              throws GridException
Returns a random busy supplying Resource.

Returns:
random busy supplying Resource
Throws:
GridException

updateResourceStatusToBusy

public WorkingSet updateResourceStatusToBusy(ResourceHandle rh,
                                             ResourceState state,
                                             Task t)
                                      throws GridException
Updates target Resource status from idle to busy local or busy supplying, depending on the value of target state.

rs_idle = rs_idle \ { rh } ; rs_busy_x = rs_busy_x U { rh } ;

Parameters:
rh - target Resource
state - target state (legal values: BUSY_LOCAL, BUSY_SUPPLYING)
t - Task that is going to be run on target Resource
Returns:
Resource WorkingSet
Throws:
GridException - if a parameter is illegal

updateResourceStatusToIdle

public WorkingSet updateResourceStatusToIdle(ResourceHandle rh,
                                             ResourceState state)
                                      throws GridException
Updates target Resource status from busy local or busy supplying, depending on the value of target state, to idle.

rs_busy_x = rs_busy_x \ { rh } ; rs_idle = rs_idle U { rh } ;

Parameters:
rh - target Resource
state - target state (legal values: BUSY_LOCAL, BUSY_SUPPLYING)
Returns:
Resource WorkingSet
Throws:
GridException - if a parameter is illegal

Lightweight Bartering Grid

Copyright (c) 2005-2008, Cyril Briquet, parts Xavier Dalem.