Lightweight Bartering Grid

lbg.peer.service
Class LivePeerHandle

java.lang.Object
  extended by lbg.peer.service.LivePeerHandle
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<PeerHandle>, AbstractExternalPeerHandle, AbstractInternalPeerHandle, AbstractUserPeerHandle, ExternalPeerHandle, InternalPeerHandle, PeerHandle, UserPeerHandle

public class LivePeerHandle
extends java.lang.Object
implements ExternalPeerHandle, InternalPeerHandle, UserPeerHandle

A peer handle grouping everything needed by other peers, resources and user

Author:
Xavier Dalem
See Also:
Serialized Form

Constructor Summary
LivePeerHandle(java.lang.String id, java.lang.String hostname, int peer_port, int resource_port, int user_port)
          Create a handle to a peer
 
Method Summary
 void addResource(ResourceHandle rh, int power)
          Register a resource as part of this Peer
 void cancelJob(int job_id)
          Cancels a Job from the Peer
 void cancelLocalTaskOnSupplyingResource(java.lang.String supplier_id, Task t)
          Cancel a task from this Peer running on another Peer
 void cancelSupplyingTaskOnLocalResource(java.lang.String consumer_id, Task t)
          Cancel a task from another Peer running on this Peer
 int compareTo(PeerHandle other)
           
 ConsumptionTaskID computeSupplyingTask(java.lang.String consumer_id, Task t)
          Compute a task.
 boolean equals(java.lang.Object obj)
           
 void grantConsumption(java.lang.String supplier_id, int granted_count)
          Grant a consumption for a number of tasks
 int hashCode()
           
 java.lang.String hostname()
           
 java.lang.String id()
           
 boolean isAlive()
          Checks if this peer is alive (i.e.
 int peerPort()
           
 void preemptLocalTaskOnLocalResource(Task t, byte[] logs)
          Cancels a task from this Peer running on this Resource
 void preemptSupplyingTaskOnLocalResource(java.lang.String consumer_id, Task t, byte[] logs)
          Preempts a task from another Peer running on this Peer
 int queryJobStatus(int job_id)
          Queries Job status from the Peer
 void removeResource(ResourceHandle rh)
          Remove a resource from this Peer
 void requestSupplying(java.lang.String consumer_id, int tasks_count)
          Request this peer to supply power for a number of tasks
 int resourcePort()
           
 int submitJob(UserHandle uh, JobDescriptor jd)
          Submit a job to peer
 java.lang.String toString()
           
 void uploadBySupplyingCompletedTask(java.lang.String supplier_id, Task t)
           
 void uploadLocallyCompletedTask(Task t)
          Upload a task completed by a resource to this Peer
 int userPort()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LivePeerHandle

public LivePeerHandle(java.lang.String id,
                      java.lang.String hostname,
                      int peer_port,
                      int resource_port,
                      int user_port)
               throws GridException
Create a handle to a peer

Parameters:
id - Peer ID
hostname - Peer hostname
peer_port - Peer-to-Peer communication port
resource_port - Resource-to-Peer communication port
user_port - User-to-Peer communication port
Throws:
GridException
Method Detail

toString

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

compareTo

public int compareTo(PeerHandle other)
Specified by:
compareTo in interface java.lang.Comparable<PeerHandle>

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

id

public java.lang.String id()
Specified by:
id in interface PeerHandle

hostname

public java.lang.String hostname()
Specified by:
hostname in interface PeerHandle

peerPort

public int peerPort()
Specified by:
peerPort in interface AbstractExternalPeerHandle

requestSupplying

public void requestSupplying(java.lang.String consumer_id,
                             int tasks_count)
                      throws GridException
Request this peer to supply power for a number of tasks

Specified by:
requestSupplying in interface AbstractExternalPeerHandle
Parameters:
consumer_id - The ID of the Peer that asks
tasks_count - The number of tasks consumers wished the Peer to handle
Throws:
GridException

grantConsumption

public void grantConsumption(java.lang.String supplier_id,
                             int granted_count)
                      throws GridException
Grant a consumption for a number of tasks

Specified by:
grantConsumption in interface AbstractExternalPeerHandle
Parameters:
supplier_id - The ID of the Peer that provides
granted_count - The number of tasks the provider agreed to run
Throws:
GridException

computeSupplyingTask

public ConsumptionTaskID computeSupplyingTask(java.lang.String consumer_id,
                                              Task t)
                                       throws GridException
Compute a task.

Specified by:
computeSupplyingTask in interface AbstractExternalPeerHandle
Parameters:
consumer_id - The task owner
t - The task to run
Throws:
GridException

preemptSupplyingTaskOnLocalResource

public void preemptSupplyingTaskOnLocalResource(java.lang.String consumer_id,
                                                Task t,
                                                byte[] logs)
                                         throws GridException
Preempts a task from another Peer running on this Peer

Specified by:
preemptSupplyingTaskOnLocalResource in interface AbstractInternalPeerHandle
Throws:
GridException

cancelSupplyingTaskOnLocalResource

public void cancelSupplyingTaskOnLocalResource(java.lang.String consumer_id,
                                               Task t)
                                        throws GridException
Cancel a task from another Peer running on this Peer

Specified by:
cancelSupplyingTaskOnLocalResource in interface AbstractExternalPeerHandle
Throws:
GridException

cancelLocalTaskOnSupplyingResource

public void cancelLocalTaskOnSupplyingResource(java.lang.String supplier_id,
                                               Task t)
                                        throws GridException
Cancel a task from this Peer running on another Peer

Specified by:
cancelLocalTaskOnSupplyingResource in interface AbstractExternalPeerHandle
Throws:
GridException

uploadBySupplyingCompletedTask

public void uploadBySupplyingCompletedTask(java.lang.String supplier_id,
                                           Task t)
                                    throws GridException
Specified by:
uploadBySupplyingCompletedTask in interface AbstractExternalPeerHandle
Throws:
GridException

resourcePort

public int resourcePort()
Specified by:
resourcePort in interface AbstractInternalPeerHandle

addResource

public void addResource(ResourceHandle rh,
                        int power)
                 throws GridException
Register a resource as part of this Peer

Specified by:
addResource in interface AbstractInternalPeerHandle
Parameters:
rh - A handle to the concerned resource
Throws:
GridException

removeResource

public void removeResource(ResourceHandle rh)
                    throws GridException
Remove a resource from this Peer

Specified by:
removeResource in interface AbstractInternalPeerHandle
Parameters:
rh - A handle to the concerned resource
Throws:
GridException

preemptLocalTaskOnLocalResource

public void preemptLocalTaskOnLocalResource(Task t,
                                            byte[] logs)
                                     throws GridException
Cancels a task from this Peer running on this Resource

Specified by:
preemptLocalTaskOnLocalResource in interface AbstractInternalPeerHandle
Parameters:
t - The task to cancel
Throws:
GridException

uploadLocallyCompletedTask

public void uploadLocallyCompletedTask(Task t)
                                throws GridException
Upload a task completed by a resource to this Peer

Specified by:
uploadLocallyCompletedTask in interface AbstractInternalPeerHandle
Parameters:
t - The completed task
Throws:
GridException

userPort

public int userPort()
Specified by:
userPort in interface AbstractUserPeerHandle

submitJob

public int submitJob(UserHandle uh,
                     JobDescriptor jd)
              throws GridException
Submit a job to peer

Specified by:
submitJob in interface AbstractUserPeerHandle
Parameters:
uh - A handle to contact the user
jd - A description of the job to submit
Returns:
the job ID
Throws:
GridException - if the submitting fails

cancelJob

public void cancelJob(int job_id)
               throws GridException
Cancels a Job from the Peer

Specified by:
cancelJob in interface AbstractUserPeerHandle
Parameters:
job_id - job id
Throws:
GridException - if the cancellation fails

queryJobStatus

public int queryJobStatus(int job_id)
                   throws GridException
Queries Job status from the Peer

Specified by:
queryJobStatus in interface AbstractUserPeerHandle
Parameters:
job_id - job id
Throws:
GridException - if the status query

isAlive

public boolean isAlive()
Checks if this peer is alive (i.e. can be reached).

Specified by:
isAlive in interface AbstractExternalPeerHandle
Returns:
true if the peer is alive.

Lightweight Bartering Grid

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