GridComputing
Job Management in Grid Computing
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
GridManager Class Reference

GridManager Class. More...

#include <gridmanager.h>

Inheritance diagram for GridManager:
ISave IUpdate

Public Types

typedef std::set< User
*, IdLess< User > > 
UserSet
 
typedef std::set< Machine
*, IdLess< Machine > > 
MachineSet
 
typedef std::set
< PriorityMachine *, IdLess
< PriorityMachine > > 
PriorityMachineSet
 

Public Member Functions

 GridManager ()
 Constructor.
 
 ~GridManager ()
 Destructor.
 
uint AddUser (User *user)
 Add a User.
 
uint AddMachine (Machine *machine)
 Add a Machine.
 
uint AddPriorityMachine (PriorityMachine *pMachine)
 Add a Priority Machine.
 
bool RemoveUser (const User *user)
 Removes the given user.
 
bool RemoveUser (uint id)
 Removes the user with the given ID.
 
bool RemoveMachine (const Machine *machine)
 Removes the given machine.
 
bool RemoveMachine (uint id)
 Removes the machine with the given ID.
 
bool RemovePriorityMachine (const PriorityMachine *machine)
 Removes the given priority machine.
 
bool RemovePriorityMachine (uint id)
 Removes the priority machine with the given ID.
 
UserGetUser (uint id) const
 Returns the user with the given ID.
 
uint GetNumberOfUsers () const
 Returns the number of existing users.
 
MachineGetMachine (uint id) const
 Returns the machine with the given ID.
 
PriorityMachineGetPriorityMachine (uint id) const
 Returns the priority machine with the given ID.
 
uint GetNumberOfMachines () const
 Returns the number of existing machines.
 
uint GetNumberOfPriorityMachines () const
 Returns the number of existing priority machines.
 
bool Save (ByteBuffer &bb) const override
 Saves the information of the instance of the class to the given ByteBuffer.
 
void Update (uint32 diff)
 Update function that updates all jobs and machine. It removes finished jobs and updates the respective machines.
 
bool AddJobByUser (int userId, Job *job)
 Adds the given job by the user with the given Id.
 
bool AddJobByUser (User *user, Job *job)
 Adds the given job to the given user.
 
bool RemoveMachineJob (Machine *machine, uint jobId)
 Removes the given job from the given machine.
 
uint GetNumberOfJobs () const
 Returns the number of existing jobs.
 
template<class T >
std::vector< const T * > ApplyPredicate (std::function< bool(const T *)> predicate) const
 Applies the given predicate to the containers of the instance of the class based in the type and returns a vector with the values that meet the requirements.
 
template<class T , class R >
std::vector< R > ApplySelector (std::function< R(const T *)> selector, std::function< bool(const T *)> predicate) const
 Uses ApplyPredicate with the given predicate and then selects a certain element of each object in the vector returned by ApplyPredicate.
 
template<class T , class R >
std::vector< R > ApplySelector (std::function< R(const T *)> selector) const
 Selects a certain element of each object in the vector of T*.
 
const IdleUserContainerGetIdleUsers () const
 
template<>
std::vector< const Job * > ApplyPredicate (std::function< bool(const Job *)> predicate) const
 
template<>
std::vector< const User * > ApplyPredicate (std::function< bool(const User *)> predicate) const
 
template<>
std::vector< const IdleUser * > ApplyPredicate (std::function< bool(const IdleUser *)> predicate) const
 
template<>
std::vector< const Machine * > ApplyPredicate (std::function< bool(const Machine *)> predicate) const
 
template<>
std::vector< const
PriorityMachine * > 
ApplyPredicate (std::function< bool(const PriorityMachine *)> predicate) const
 

Static Public Member Functions

static GridManagerLoad (ByteBuffer &bb)
 Returns a pointer to a GridManager loaded from the given ByteBuffer.
 
static MenuGetMenu ()
 Returns the menu for the GridManager class.
 

Private Member Functions

bool AddJob (Job *job)
 Searches for a available machine and adds the given job to it.
 
 GridManager (const GridManager &)
 Copy constructor. Private to avoid copies of a GridManager instance.
 
GridManageroperator= (GridManager const &)
 Assignment operator. Private to avoid copies of a GridManager instance.
 

Private Attributes

UserSet _users
 Container that saves users.
 
MachineSet _machines
 Container that saves machines.
 
PriorityMachineSet _priorityMachines
 Container that saves priority machines.
 
std::queue< Job * > _waitingJobs
 Container that stores waiting jobs.
 
IdleUserContainer _idleUsers
 Container used to store users that are removed.
 

Static Private Attributes

static uint _lastUserId = 0
 Last User Id added.
 
static uint _lastMachineId = 0
 Last Machine Id added.
 
static Menu_menu = Loader<Menu>("gridManagerMenu.txt").Load()
 Menu associated with the GridManager class.
 

Detailed Description

GridManager Class.

The GridManager class has information about users and machines. It enables the user of this class to Add, Remove and Get and Search Users and Machines, and has an interface to add Jobs to a User.

Member Typedef Documentation

typedef std::set<User*, IdLess<User> > GridManager::UserSet

Constructor & Destructor Documentation

GridManager::GridManager ( )

Constructor.

GridManager::~GridManager ( )

Destructor.

GridManager::GridManager ( const GridManager )
private

Copy constructor. Private to avoid copies of a GridManager instance.

Member Function Documentation

bool GridManager::AddJob ( Job job)
private

Searches for a available machine and adds the given job to it.

Parameters
jobto be added.
Returns
A boolean value that indicates whether the insertion was successful or not.
bool GridManager::AddJobByUser ( int  userId,
Job job 
)

Adds the given job by the user with the given Id.

Parameters
userIdId of the user that wants to create the job.
jobto be added.
Returns
A boolean value that indicates whether the insertion was successful or not.
bool GridManager::AddJobByUser ( User user,
Job job 
)

Adds the given job to the given user.

Parameters
userpointer to the user that created the job.
jobto be added.
Returns
A boolean value that indicates whether the insertion was successful or not.
uint GridManager::AddMachine ( Machine machine)

Add a Machine.

Parameters
machinea pointer to the machine to be added.
Returns
The ID of the added machine.
uint32 GridManager::AddPriorityMachine ( PriorityMachine pMachine)

Add a Priority Machine.

Parameters
pMachinea pointer to the priority machine to be added.
Returns
The ID of the added machine.
uint GridManager::AddUser ( User user)

Add a User.

Parameters
usera pointer to the user to be added.
Returns
The ID of the added user.
template<class T >
std::vector<const T*> GridManager::ApplyPredicate ( std::function< bool(const T *)>  predicate) const

Applies the given predicate to the containers of the instance of the class based in the type and returns a vector with the values that meet the requirements.

Parameters
predicateto evaluate the data: unary function that returns a bool and accepts a T* as argument.
Returns
A vector with the result of the search.
Remarks
Only defined for T = Job, User, IdleUser or Machine
template<>
std::vector<const Job*> GridManager::ApplyPredicate ( std::function< bool(const Job *)>  predicate) const
template<>
std::vector<const User*> GridManager::ApplyPredicate ( std::function< bool(const User *)>  predicate) const
template<>
std::vector<const IdleUser*> GridManager::ApplyPredicate ( std::function< bool(const IdleUser *)>  predicate) const
template<>
std::vector<const Machine*> GridManager::ApplyPredicate ( std::function< bool(const Machine *)>  predicate) const
template<>
std::vector<const PriorityMachine*> GridManager::ApplyPredicate ( std::function< bool(const PriorityMachine *)>  predicate) const
template<class T , class R >
std::vector< R > GridManager::ApplySelector ( std::function< R(const T *)>  selector,
std::function< bool(const T *)>  predicate 
) const

Uses ApplyPredicate with the given predicate and then selects a certain element of each object in the vector returned by ApplyPredicate.

Parameters
selectorto retrieve an element from the data: unary function that returns R and accepts a T* as argument.
predicateto evaluate the data: unary function that returns a bool and accepts a T* as argument. Default value applies no restrictions.
Returns
A vector with the result of the search.
Remarks
Only defined for T = Job, User, IdleUser or Machine
template<class T , class R >
std::vector< R > GridManager::ApplySelector ( std::function< R(const T *)>  selector) const

Selects a certain element of each object in the vector of T*.

Parameters
selectorto retrieve an element from the data: unary function that returns R and accepts a T* as argument.
Returns
A vector with the result of the search.
Remarks
Only defined for T = Job, User, IdleUser or Machine
const IdleUserContainer& GridManager::GetIdleUsers ( ) const
Machine * GridManager::GetMachine ( uint  id) const

Returns the machine with the given ID.

Parameters
idof the machine.
Returns
A pointer to the Machine, NULL if id doesn't corresponds to any Machine.
static Menu* GridManager::GetMenu ( )
static

Returns the menu for the GridManager class.

uint GridManager::GetNumberOfJobs ( ) const

Returns the number of existing jobs.

Returns
Number of existing jobs.
uint GridManager::GetNumberOfMachines ( ) const

Returns the number of existing machines.

Returns
Number of existing machines.
uint GridManager::GetNumberOfPriorityMachines ( ) const

Returns the number of existing priority machines.

Returns
Number of existing priority machines.
uint GridManager::GetNumberOfUsers ( ) const

Returns the number of existing users.

Returns
Number of existing users.
PriorityMachine * GridManager::GetPriorityMachine ( uint  id) const

Returns the priority machine with the given ID.

Parameters
idof the priority machine.
Returns
A pointer to the Priority Machine, NULL if id doesn't corresponds to any Machine.
User * GridManager::GetUser ( uint  id) const

Returns the user with the given ID.

Parameters
idof the user.
Returns
A pointer to the User, NULL if id doesn't corresponds to any user.
GridManager * GridManager::Load ( ByteBuffer bb)
static

Returns a pointer to a GridManager loaded from the given ByteBuffer.

Parameters
bbsource of the data.
Returns
A pointer to the loaded GridManager.
GridManager& GridManager::operator= ( GridManager const &  )
private

Assignment operator. Private to avoid copies of a GridManager instance.

bool GridManager::RemoveMachine ( const Machine machine)

Removes the given machine.

Parameters
machinea pointer to the machine to be removed.
Returns
A boolean value that indicates whether the removal was successful or not.
bool GridManager::RemoveMachine ( uint  id)

Removes the machine with the given ID.

Parameters
idof the machine to be removed.
Returns
A boolean value that indicates whether the removal was successful or not.
bool GridManager::RemoveMachineJob ( Machine machine,
uint  jobId 
)

Removes the given job from the given machine.

Parameters
machinepointer to the machine that contains the job.
jobIdid of the job to be removed.
Returns
A boolean value that indicates whether the removal was successful or not.
bool GridManager::RemovePriorityMachine ( const PriorityMachine machine)

Removes the given priority machine.

Parameters
machinea pointer to the priority machine to be removed.
Returns
A boolean value that indicates whether the removal was successful or not.
bool GridManager::RemovePriorityMachine ( uint  id)

Removes the priority machine with the given ID.

Parameters
idof the priority machine to be removed.
Returns
A boolean value that indicates whether the removal was successful or not.
bool GridManager::RemoveUser ( const User user)

Removes the given user.

Parameters
usera pointer to the user to be removed.
Returns
A boolean value that indicates whether the removal was successful or not.
bool GridManager::RemoveUser ( uint  id)

Removes the user with the given ID.

Parameters
idof the user to be removed.
Returns
A boolean value that indicates whether the removal was successful or not.
bool GridManager::Save ( ByteBuffer bb) const
overridevirtual

Saves the information of the instance of the class to the given ByteBuffer.

Parameters
bbdestination of the data.
Returns
A boolean value that indicates whether the save was successful or not.

Implements ISave.

void GridManager::Update ( uint32  diff)
virtual

Update function that updates all jobs and machine. It removes finished jobs and updates the respective machines.

Parameters
difftime that has passed since last update.

Implements IUpdate.

Member Data Documentation

IdleUserContainer GridManager::_idleUsers
private

Container used to store users that are removed.

uint GridManager::_lastMachineId = 0
staticprivate

Last Machine Id added.

uint GridManager::_lastUserId = 0
staticprivate

Last User Id added.

MachineSet GridManager::_machines
private

Container that saves machines.

Menu * GridManager::_menu = Loader<Menu>("gridManagerMenu.txt").Load()
staticprivate

Menu associated with the GridManager class.

PriorityMachineSet GridManager::_priorityMachines
private

Container that saves priority machines.

UserSet GridManager::_users
private

Container that saves users.

std::queue<Job*> GridManager::_waitingJobs
private

Container that stores waiting jobs.


The documentation for this class was generated from the following files: