Lightweight Bartering Grid

lbg.peer.core.rms
Class ResourceManager

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

public class ResourceManager
extends java.lang.Object

Author:
Cyril Briquet

Constructor Summary
ResourceManager(Peer managed_peer, boolean data_present_enabled, boolean data_replication_enabled, float idle_replication_ratio, boolean psufferage_enabled)
           
 
Method Summary
 void addResource(ResourceHandle rh, int power)
           
 int countBusyLocalResources()
           
 int countBusyResources()
           
 int countBusySupplyingResources()
           
 int countIdleResources()
           
 int countTotalResources()
           
 ConsumptionDataTracker dataTracker()
           
 long freeBusyLocalResource(Task t)
          Clears the state of the target Resource.
 long freeBusySupplyingResource(Task t)
          Clears the state of the target Resource.
 double getCachedUtilizationValue()
          Returns the most cached value of Peer utilization, i.e.
 Task getRunningTask(ResourceHandle rh)
          Returns the Task running on target Busy Resource.
 WorkingSet getWorkingSetOfIdleResource(ResourceHandle rh)
          Returns the WorkingSet of the target Resource, if target Resource is idle.
 boolean hasBusyLocalResource()
           
 boolean hasBusySupplyingResource()
           
 boolean hasIdleResource()
           
 ResourceHandle locateResource(ResourceState state, Task t)
          Locates a Resource currentlty in target state with maximum Storage Affinity with target Task.
 double meanNominalResourcePower()
           
 long preemptBusyLocalResource(Task t)
          Clears the state of the target Resource.
 long preemptBusySupplyingResource(Task t)
          Clears the state of the target Resource.
 long preemptBusySupplyingResource(Task t, ResourceHandle rh)
          Clears the state of the target Resource.
 void removeResource(ResourceHandle rh)
          Removes a Resource from the Peer.
 void replicateSupplyingData()
          Replicates Supplying data to Resources.
 boolean runLocalTask(ResourceHandle rh, Task t)
          Runs target Task on target Resource.
 boolean runSupplyingTask(ResourceHandle rh, Task t)
          Runs target Task on target Resource.
 java.lang.String toString()
           
 void updateUtilizationValue()
           
 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

ResourceManager

public ResourceManager(Peer managed_peer,
                       boolean data_present_enabled,
                       boolean data_replication_enabled,
                       float idle_replication_ratio,
                       boolean psufferage_enabled)
                throws GridException
Throws:
GridException
Method Detail

toString

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

meanNominalResourcePower

public double meanNominalResourcePower()

addResource

public void addResource(ResourceHandle rh,
                        int power)
                 throws GridException
Throws:
GridException

removeResource

public void removeResource(ResourceHandle rh)
                    throws GridException
Removes a Resource from the Peer. If a Task was running on this Resource: (1) the ResourceManager informs the other managers, and (2) the Resource is supposed to actually cancel the Task.

Throws:
GridException

countTotalResources

public int countTotalResources()

countIdleResources

public int countIdleResources()

countBusyResources

public int countBusyResources()

countBusyLocalResources

public int countBusyLocalResources()

countBusySupplyingResources

public int countBusySupplyingResources()

hasIdleResource

public boolean hasIdleResource()

hasBusyLocalResource

public boolean hasBusyLocalResource()
                             throws GridException
Throws:
GridException

hasBusySupplyingResource

public boolean hasBusySupplyingResource()
                                 throws GridException
Throws:
GridException

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 - if Resource usage data is corrupted

getCachedUtilizationValue

public double getCachedUtilizationValue()
Returns the most cached value of Peer utilization, i.e. total busy time of all currently registered Resources, divided by their total registration time. This value may at most 5 seconds stale.

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

updateUtilizationValue

public void updateUtilizationValue()
                            throws GridException
Throws:
GridException

dataTracker

public ConsumptionDataTracker dataTracker()

locateResource

public ResourceHandle locateResource(ResourceState state,
                                     Task t)
                              throws GridException
Locates a Resource currentlty in target state with maximum Storage Affinity with target Task.

Parameters:
state - target state
t - target Task
Returns:
Resource in target state with maximum Storage Affinity with target Task, or null if no such Task can be found
Throws:
GridException

runLocalTask

public boolean runLocalTask(ResourceHandle rh,
                            Task t)
                     throws GridException
Runs target Task on target Resource.

Parameters:
rh - target Resource
t - target Task
Returns:
true if the target Resource can run the target Task, or false if the target Resource cannot run the target Task (e.g. typically because the WorkingSet is too large for the Resource, which would be caused by uncareful scheduling)
Throws:
GridException

runSupplyingTask

public boolean runSupplyingTask(ResourceHandle rh,
                                Task t)
                         throws GridException
Runs target Task on target Resource.

Parameters:
rh - target Resource
t - target Task
Returns:
true if the target Resource can run the target Task, or false if the target Resource cannot run the target Task (e.g. typically because the WorkingSet is too large for the Resource, which would be caused by uncareful scheduling)
Throws:
GridException

freeBusyLocalResource

public long freeBusyLocalResource(Task t)
                           throws GridException
Clears the state of the target Resource.

It is expected that the Resource is idle and has already completed the target Task, because freeResource() will not perform Task completion on the Resource.

Parameters:
t - target Local Task
Returns:
target Resource state change time (i.e. the time at which the Resource became busy), or -1 if is_resource_alive is false
Throws:
GridException - if a parameter is illegal

freeBusySupplyingResource

public long freeBusySupplyingResource(Task t)
                               throws GridException
Clears the state of the target Resource.

It is expected that the Resource is idle and has already completed the target Task, because freeResource() will not perform Task completion on the Resource.

Parameters:
t - target Supplying Task
Returns:
target Resource state change time (i.e. the time at which the Resource became busy), or -1 if is_resource_alive is false
Throws:
GridException - if a parameter is illegal

preemptBusyLocalResource

public long preemptBusyLocalResource(Task t)
                              throws GridException
Clears the state of the target Resource.

It is expected that the Resource is busy and the target Task has not been cancelled yet, because preemptResource() will perform Task cancellation on the Resource.

Parameters:
t - target Task
Returns:
target Resource state change time (i.e. the time at which the Resource became busy), or -1 if is_resource_alive is false
Throws:
GridException - if a parameter is illegal

preemptBusySupplyingResource

public long preemptBusySupplyingResource(Task t)
                                  throws GridException
Clears the state of the target Resource.

It is expected that the Resource is busy and the target Task has not been cancelled yet, because clearResource() will perform Task cancellation on the Resource.

Parameters:
t - target Supplying Task
Returns:
target Resource state change time (i.e. the time at which the Resource became busy), or -1 if is_resource_alive is false
Throws:
GridException - if a parameter is illegal

preemptBusySupplyingResource

public long preemptBusySupplyingResource(Task t,
                                         ResourceHandle rh)
                                  throws GridException
Clears the state of the target Resource.

It is expected that the Resource is busy and the target Task has not been cancelled yet, because clearResource() will perform Task cancellation on the Resource.

Parameters:
t - target Supplying Task
rh - target ResourceHandle
Returns:
target Resource state change time (i.e. the time at which the Resource became busy), or -1 if is_resource_alive is false
Throws:
GridException - if a parameter is illegal

getRunningTask

public Task getRunningTask(ResourceHandle rh)
                    throws GridException
Returns the Task running on target Busy Resource.

Parameters:
rh - target Busy Resource
Returns:
Task running on target Busy Resource
Throws:
GridException

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.

Throws:
GridException

replicateSupplyingData

public void replicateSupplyingData()
                            throws GridException
Replicates Supplying data to Resources.

Note: only a subset of idle Resources is targeted by the replication process.

Throws:
GridException

Lightweight Bartering Grid

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