2.17.2: 2011-06-17

net.sf.basedb.core
Class JobAgent

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<D>
      extended by net.sf.basedb.core.OwnedItem<D>
          extended by net.sf.basedb.core.SharedItem<D>
              extended by net.sf.basedb.core.CommonItem<JobAgentData>
                  extended by net.sf.basedb.core.JobAgent
All Implemented Interfaces:
AccessControlled, Identifiable, Nameable, Ownable, Removable, Shareable

public class JobAgent
extends CommonItem<JobAgentData>

This class represents a job agent, which is a program running in another virtual machine on the same or a different server. The job agent is regularly checking the database for jobs that are waiting to be executed. It is not neccessary for a job agent to be registered in the database but if it is the core can provide services that are otherwise inaccesible.

Version:
2.0
Author:
nicklas
Last modified
$Date: 2010-09-13 12:36:49 +0200 (Mon, 13 Sep 2010) $

Field Summary
private static Map<Integer,JobAgentInfo> agentInfo
           
static int DEFAULT_PORT
          The default port (47822) where job agents are listening for connections.
private static Logger log
          Log events.
static int MAX_EXTERNAL_ID_LENGTH
          The maximum length of the external ID that can be stored in the database.
static int MAX_SERVER_LENGTH
          The maximum length of the server name that can be stored in the database.
static Item TYPE
          The type of item represented by this class.
 
Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
 
Constructor Summary
JobAgent(JobAgentData data)
           
 
Method Summary
private static JobAgentInfo getAgentInfo(JobAgent agent)
          Get a JobAgentInfo for a job agent.
static JobAgent getByExternalId(DbControl dc, String externalId)
          Get a JobAgent item when you know the external ID.
static JobAgent getById(DbControl dc, int id)
          Get a JobAgent object when you know the ID.
 JobAgentConnection getConnection(Integer timeout)
          Get a connection object for connecting to the job agent.
 Integer getCpuUsage()
          Get the current CPU usage in percent of the server where the job agent is running.
 String getExternalId()
          Get the external id for the job agent.
 JobAgentInfo getInfo()
          Get info about the running job agent.
static JobAgent getNew(DbControl dc, String externalId)
          Create a new JobAgent item.
 Integer getPort()
          Get the port the job agent is listening on.
static ItemQuery<JobAgent> getQuery()
          Get an ItemQuery that returns job agents.
 String getServer()
          Get the name or IP-adress of the server were the job agent is running.
 ItemQuery<JobAgentSettings> getSettings()
          Get a query that returns all plugin-specific settings for this job agent.
 JobAgentSettings getSettings(Job job)
          Get the settings for the plugin that is used for the specified job.
 JobAgentSettings getSettings(PluginDefinition plugin, boolean create)
          Get the settings for the specified plugin.
 Long getTotalMemory()
          Get the total memory in bytes of the server where the job agent is running.
 Item getType()
          Get the type of item represented by the object.
 Long getUsedMemory()
          Get the current memory usage in bytes of the server where the job agent is running.
 ItemQuery<Job> getWaitingJobs()
          Get a query that returns all jobs that are waiting to be executed sorted by their priority taking the priority boost into account.
 void setExternalId(String externalId)
          Set the external id for the job agent.
 void setPort(Integer port)
          Set the port the job agent is listening on.
 void setServer(String server)
          Set the name/IP of the server where the job agent is running.
 
Methods inherited from class net.sf.basedb.core.CommonItem
getDescription, getName, isRemoved, setDescription, setName, setRemoved, toTransferable
 
Methods inherited from class net.sf.basedb.core.SharedItem
getItemKey, getProjectKey, initPermissions, isShared, onBeforeCommit, setItemKey, setProjectKey, toTransferable
 
Methods inherited from class net.sf.basedb.core.OwnedItem
getOwner, isOwner, setOwner, takeOwnership, toTransferable
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getUsingItems, getVersion, hashCode, hasPermission, isDetached, isInDatabase, isUsed, onAfterCommit, onAfterInsert, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
 
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
 
Methods inherited from interface net.sf.basedb.core.Ownable
getOwner, isOwner, setOwner, takeOwnership
 

Field Detail

log

private static final Logger log
Log events.


TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.JOBAGENT, getType()

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port (47822) where job agents are listening for connections. If 47822 is converted to a hexadecimal number it becomes BACE!

See Also:
Constant Field Values

MAX_EXTERNAL_ID_LENGTH

public static final int MAX_EXTERNAL_ID_LENGTH
The maximum length of the external ID that can be stored in the database.

See Also:
setExternalId(String), Constant Field Values

MAX_SERVER_LENGTH

public static final int MAX_SERVER_LENGTH
The maximum length of the server name that can be stored in the database.

See Also:
setServer(String), Constant Field Values

agentInfo

private static final Map<Integer,JobAgentInfo> agentInfo
Constructor Detail

JobAgent

JobAgent(JobAgentData data)
Method Detail

getNew

public static JobAgent getNew(DbControl dc,
                              String externalId)
                       throws BaseException
Create a new JobAgent item.

Parameters:
dc - The DbControl which will be used for permission checking and database access
externalId - The external ID, which must be unique, for the job agent
Returns:
The new JobAgent item
Throws:
BaseException - If there is an error

getById

public static JobAgent getById(DbControl dc,
                               int id)
                        throws ItemNotFoundException,
                               PermissionDeniedException,
                               BaseException
Get a JobAgent object when you know the ID.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
id - The ID of the item to load
Returns:
The JobAgent item
Throws:
ItemNotFoundException - If an item with the specified ID is not found
PermissionDeniedException - If the logged in user doesn't have read permission to the item
BaseException - If there is another error

getByExternalId

public static JobAgent getByExternalId(DbControl dc,
                                       String externalId)
                                throws ItemNotFoundException,
                                       PermissionDeniedException,
                                       BaseException
Get a JobAgent item when you know the external ID.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
externalId - The external ID of the item to load
Returns:
The JobAgent item
Throws:
ItemNotFoundException - If an item with the specified ID is not found
PermissionDeniedException - If the logged in user doesn't have read permission for the item
BaseException - If there is another error

getQuery

public static ItemQuery<JobAgent> getQuery()
Get an ItemQuery that returns job agents.

Returns:
An ItemQuery object

getType

public Item getType()
Description copied from interface: Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.

Returns:
A value indicating the type of item

getExternalId

public String getExternalId()
Get the external id for the job agent. The external id is used to identify each job agent and must be unique.


setExternalId

public void setExternalId(String externalId)
                   throws PermissionDeniedException,
                          InvalidDataException,
                          BaseException
Set the external id for the job agent.

Parameters:
externalId - External id to be set.
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the new value is longer than MAX_EXTERNAL_ID_LENGTH
BaseException - If there is another error

getServer

public String getServer()
Get the name or IP-adress of the server were the job agent is running.

Returns:
The name or IP, or null if not known

setServer

public void setServer(String server)
               throws InvalidDataException,
                      PermissionDeniedException
Set the name/IP of the server where the job agent is running.

Parameters:
server - The name/IP or null if not known
Throws:
InvalidDataException - If the new value is longer than MAX_SERVER_LENGTH
PermissionDeniedException - If the logged in user doesn't have write permission

getPort

public Integer getPort()
Get the port the job agent is listening on.

Returns:
The port number or null if the job agent isn't listening

setPort

public void setPort(Integer port)
Set the port the job agent is listening on.

Parameters:
port - The new port number or null if the job agent isn't listening

getInfo

public JobAgentInfo getInfo()
Get info about the running job agent. For performance reasons the information is cached and only updated if older than specified by the agent.maxage configuration setting.

Returns:
A JobAgentInfo object

getConnection

public JobAgentConnection getConnection(Integer timeout)
                                 throws PermissionDeniedException
Get a connection object for connecting to the job agent. It is only possible to connect to job agents which has specified a server and port.

Parameters:
timeout - The timeout for the connection, null will use the default timeout as configued by the agent.connection.timeout setting in the base.config file
Returns:
The connection object or null if none could be created
Throws:
PermissionDeniedException - If the logged in user doesn't have WRITE permission on the job agent

getCpuUsage

public Integer getCpuUsage()
Get the current CPU usage in percent of the server where the job agent is running. The CPU usage is not available unless a server name/IP and port has been specified. For performance reasons the CPU usage is cached and only updated if older than specified by the agent.maxage configuration setting.

Returns:
The CPU usage of the job agent's server in percent, or null if not known

getUsedMemory

public Long getUsedMemory()
Get the current memory usage in bytes of the server where the job agent is running. The memory usage is not available unless a server name/IP and port has been specified. For performance reasons the memory usage is cached and only updated if older than specified by the agent.maxage configuration setting.

Returns:
The memory usage on the job agent's server, or null if not known

getTotalMemory

public Long getTotalMemory()
Get the total memory in bytes of the server where the job agent is running. The memory is not available unless a server name/IP and port has been specified. For performance reasons the memory is cached and only updated if older than specified by the agent.maxage configuration setting.

Returns:
The memory on the job agent's server, or null if not known

getSettings

public JobAgentSettings getSettings(PluginDefinition plugin,
                                    boolean create)
Get the settings for the specified plugin. If no settings exists a new JobAgentSettings item is created if the create parameter is true. You must call DbControl.saveItem(BasicItem) to save the new settings to the database.

Parameters:
plugin - The plugin to the settings for, or null if none exists and the create parameter is false
create - TRUE if new settings should be created if no one was found, FALSE otherwise.
Returns:
A JobAgentSettings object for the specified plugin

getSettings

public JobAgentSettings getSettings(Job job)
Get the settings for the plugin that is used for the specified job.

Parameters:
job - The job to get the settings for
Returns:
A JobAgentSettings object or null if not settings exist for the job

getSettings

public ItemQuery<JobAgentSettings> getSettings()
Get a query that returns all plugin-specific settings for this job agent.

Returns:
An ItemQuery object

getWaitingJobs

public ItemQuery<Job> getWaitingJobs()
Get a query that returns all jobs that are waiting to be executed sorted by their priority taking the priority boost into account.

Returns:
An ItemQuery object

getAgentInfo

private static JobAgentInfo getAgentInfo(JobAgent agent)
Get a JobAgentInfo for a job agent. If the job agent hasn't specified a server and port or if there is an error while connecting to the job agent an empty info object is returned.

Parameters:
agent - The job agent to get the info for
Returns:
A JobAgentInfo object

2.17.2: 2011-06-17