Class MasterSlotManager
java.lang.Object
net.sf.basedb.clients.jobagent.slotmanager.InternalSlotManager
net.sf.basedb.clients.jobagent.slotmanager.MasterSlotManager
- All Implemented Interfaces:
SlotManager
An extension to the internal slot manager which also accepts
slot assignment from remote job agents. A custom request
handler (
MasterSlotManager.RemoteSlotRequestHandler
) is installed to take care
of the communication. Remotely assigned slots has a time-out (30 seconds)
associated with them. This means that if the connection with
the remote host is lost, the assigned slots are re-cycled.
The requst handler uses a simple protocol with the following actions:
slotmanager://host:port/get-slot?TIME
: Get a new slot for the TIME estimated execution time. TIME is a name from theJob.ExecutionTime
enumeration. If succcessful, the request handler answers withOK
on the first line and thenId:slot-id
andSlot:TIME
on the following lines. It is recommended that the answer is parsed withJobAgentConnection.parseSimpleAnswer(String)
.slotmanger://slot-id@host:port/release-slot
: Release the slot with the given id.slotmanager://slot-id@host:port/ping-slot
: Ping the slot with the given id to indicate that the job is still running on the remote job agent. A remote slot has a timeout of 30 seconds so the remote job agent has to send a ping at least at that interval or the slot will be returned to the pool.
FAILED
followed with an
explanation.- Since:
- 2.16
- Author:
- Nicklas
- Last modified
- $Date: 2014-04-09 14:21:20 +0200 (on, 09 apr 2014) $
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
A remote slot is a slot with some information about when it was created and last updated.(package private) static class
Request handler implementation that accepts requests for slots from remote hosts.(package private) static class
Task that is scheduled at regular intervals to check for timed out slots. -
Field Summary
Modifier and TypeFieldDescriptionprivate static final org.slf4j.Logger
private Map<String,
MasterSlotManager.RemoteSlot> private TimerTask
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription(package private) int
Check the remote slots to see if they have timed out.void
close()
This method is called when the job agent is shutting down.(package private) MasterSlotManager.RemoteSlot
getRemoteSlot
(String slotId) Get the remote slot with the given id.(package private) MasterSlotManager.RemoteSlot
getRemoteSlot
(Job.ExecutionTime estimated) Create a slot for a job on a remote job agent with the specified estimated execution time.void
Initialize the slot manager.(package private) MasterSlotManager.RemoteSlot
releaseRemoteSlot
(String slotId) Release the remote slot with the given id.Methods inherited from class net.sf.basedb.clients.jobagent.slotmanager.InternalSlotManager
getAgent, getSlot, getSlot, releaseSlot
-
Field Details
-
log
private static final org.slf4j.Logger log -
remoteSlots
-
remoteRequestHandler
-
timeoutChecker
-
-
Constructor Details
-
MasterSlotManager
public MasterSlotManager()
-
-
Method Details
-
init
Description copied from interface:SlotManager
Initialize the slot manager. This method is called once when the job agent is starting up. The slot manager may read configuration settings, and intialize local resources.- Specified by:
init
in interfaceSlotManager
- Overrides:
init
in classInternalSlotManager
- Parameters:
agent
- The job agent
-
close
public void close()Description copied from interface:SlotManager
This method is called when the job agent is shutting down. The slot manager should clean up any resources it is using.- Specified by:
close
in interfaceSlotManager
- Overrides:
close
in classInternalSlotManager
-
getRemoteSlot
Create a slot for a job on a remote job agent with the specified estimated execution time. This method will call theInternalSlotManager.getSlot(net.sf.basedb.core.Job.ExecutionTime)
and then wrap the slot in aMasterSlotManager.RemoteSlot
instance.- Returns:
- A remote slot, or null if not slot is available
-
getRemoteSlot
Get the remote slot with the given id.- Parameters:
slotId
- The id of the slot- Returns:
- A remote slot or null if no slot with the given id exists
-
releaseRemoteSlot
Release the remote slot with the given id.- Parameters:
slotId
- The id of the slot- Returns:
- A remote slot or null if no slot with the given id exists
-
checkTimeoutOnRemoteSlots
int checkTimeoutOnRemoteSlots()Check the remote slots to see if they have timed out. If so, release them.- Returns:
- The number of timed out slots
-