Class SpallocClient
java.lang.Object
uk.ac.manchester.spinnaker.spalloc.SpallocConnection
uk.ac.manchester.spinnaker.spalloc.SpallocClient
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- SpallocAPI
A simple (blocking) client implementation of the
 
 spalloc-server protocol.
 
 This minimal implementation is intended to serve both simple applications and
 as an example implementation of the protocol for other applications. This
 implementation simply implements the protocol, presenting an RPC-like
 interface to the server. For a higher-level interface built on top of this
 client, see SpallocJob.
- 
Field SummaryFields inherited from class uk.ac.manchester.spinnaker.spalloc.SpallocConnectionnotifications
- 
Constructor SummaryConstructorsConstructorDescriptionSpallocClient(String hostname) Define a new connection using the default spalloc port.SpallocClient(String hostname, int port) Define a new connection.SpallocClient(String hostname, Integer timeout) Define a new connection using the default spalloc port.SpallocClient(String hostname, Integer port, Integer timeout) Define a new connection.
- 
Method SummaryModifier and TypeMethodDescriptionintDeprecated, for removal: This API element is subject to removal in a future version.intCreate a job.static ObjectMapperStatic method to create the object mapper.voiddestroyJob(int jobID, String reason, Integer timeout) Destroy a job.protected StringformatRequest(Command<?> command) Format a request as a line of newline-free JSON, suitable for sending to the spalloc server.getBoardPosition(String machineName, PhysicalCoords coords, Integer timeout) Get the logical location of a board.getBoardPosition(String machineName, TriadCoords coords, Integer timeout) Get the physical location of a board.getJobMachineInfo(int jobID, Integer timeout) Get information about a job's allocated machine.getJobState(int jobID, Integer timeout) Get the state of a job.voidjobKeepAlive(int jobID, Integer timeout) Keep a job alive.List all jobs.listMachines(Integer timeout) List all known machines.voidEnable or disable notifications of changes in job state.voidnotifyMachine(String machineName, boolean enable, Integer timeout) Enable or disable notifications of changes in machine state.protected ResponseparseResponse(String line) Parse a line of response from the spalloc server, which should be a complete JSON object.voidpowerOffJobBoards(int jobID, Integer timeout) Turn off a job's allocated boards.voidpowerOnJobBoards(int jobID, Integer timeout) Turn on a job's allocated boards.Request the version of the spalloc server.waitForNotification(Integer timeout) Return the next notification to arrive.whereIs(int jobID, HasChipLocation chip, Integer timeout) Locate a chip within a job's allocation.whereIs(String machine, PhysicalCoords coords, Integer timeout) Locate a board within a machine.whereIs(String machine, TriadCoords coords, Integer timeout) Locate a board within a machine.whereIs(String machine, HasChipLocation chip, Integer timeout) Locate a chip within a machine.Methods inherited from class uk.ac.manchester.spinnaker.spalloc.SpallocConnectioncall, close, connect, connect, receiveResponse, sendCommand, toString, withConnectionMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface uk.ac.manchester.spinnaker.spalloc.SpallocAPIcreateJob, createJob, destroyJob, getBoardPosition, getBoardPosition, getBoardPosition, getBoardPosition, getBoardPosition, getBoardPosition, getJobMachineInfo, getJobState, jobKeepAlive, listJobs, listMachines, notifyJob, notifyMachine, powerOffJobBoards, powerOnJobBoards, version, waitForNotification, whereIs, whereIs, whereIs, whereIs, whereIs, whereIs, whereIs, whereIs
- 
Constructor Details- 
SpallocClientDefine a new connection using the default spalloc port. NB: Does not connect to the server untilSpallocConnection.connect()is called.- Parameters:
- hostname- The hostname of the server.
 
- 
SpallocClientDefine a new connection using the default spalloc port. NB: Does not connect to the server untilSpallocConnection.connect()is called.- Parameters:
- hostname- The hostname of the server.
- timeout- The default timeout.
 
- 
SpallocClientDefine a new connection. NB: Does not connect to the server untilSpallocConnection.connect()is called.- Parameters:
- hostname- The hostname of the server.
- port- The port to use.
 
- 
SpallocClientDefine a new connection. NB: Does not connect to the server untilSpallocConnection.connect()is called.- Parameters:
- hostname- The hostname of the server.
- port- The port to use.
- timeout- The default timeout.
 
 
- 
- 
Method Details- 
createMapperStatic method to create the object mapper.This method makes sure that all JSON unmarshallers use the same Mapper set up the exact same way. - Returns:
- The Object Mapper used by the Spalloc client,
 
- 
waitForNotificationpublic Notification waitForNotification(Integer timeout) throws SpallocProtocolException, SpallocProtocolTimeoutException, InterruptedException Description copied from interface:SpallocAPIReturn the next notification to arrive.- Specified by:
- waitForNotificationin interface- SpallocAPI
- Parameters:
- timeout- The number of seconds to wait before timing out or- nullif this function should try again forever.- If negative, only responses already-received will be returned; if no responses are available, in this case the function does not raise a - SpallocProtocolTimeoutExceptionbut returns- nullinstead.
- Returns:
- The notification sent by the server.
- Throws:
- SpallocProtocolException- If the socket is unusable or becomes disconnected.
- SpallocProtocolTimeoutException- If a timeout occurs (implying- timeoutis not negative).
- InterruptedException- If interrupted while waiting.
- See Also:
 
- 
versionpublic Version version(Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPIRequest the version of the spalloc server.- Specified by:
- versionin interface- SpallocAPI
- Parameters:
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- the server's version.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
createJobpublic int createJob(CreateJob builder, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPICreate a job.- Specified by:
- createJobin interface- SpallocAPI
- Parameters:
- builder- The builder saying what sort of job to create.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- the ID of the created job.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
createJob@Deprecated(forRemoval=true) public int createJob(List<Integer> args, Map<String, Object> kwargs, Integer timeout) throws IOException, SpallocServerException, InterruptedExceptionDeprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:SpallocAPICreate a job.- Specified by:
- createJobin interface- SpallocAPI
- Parameters:
- args- The arguments, describing default (empty), the number of boards (one arg), the triad size (two args) or the board location (three args).
- kwargs- Additional arguments required. Must include the key- owner. Values can be boxed primitive types or strings.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- the ID of the created job.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
jobKeepAlivepublic void jobKeepAlive(int jobID, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPIKeep a job alive. Needs to be regularly called.- Specified by:
- jobKeepAlivein interface- SpallocAPI
- Parameters:
- jobID- The job to ask about.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
getJobStatepublic JobState getJobState(int jobID, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPIGet the state of a job.- Specified by:
- getJobStatein interface- SpallocAPI
- Parameters:
- jobID- The job to get the state of.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- a description of the job's state.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
getJobMachineInfopublic JobMachineInfo getJobMachineInfo(int jobID, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPIGet information about a job's allocated machine.- Specified by:
- getJobMachineInfoin interface- SpallocAPI
- Parameters:
- jobID- The job whose machine you want to ask about.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- a description of the machine.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
powerOnJobBoardspublic void powerOnJobBoards(int jobID, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPITurn on a job's allocated boards.- Specified by:
- powerOnJobBoardsin interface- SpallocAPI
- Parameters:
- jobID- The job to request about.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
powerOffJobBoardspublic void powerOffJobBoards(int jobID, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPITurn off a job's allocated boards.- Specified by:
- powerOffJobBoardsin interface- SpallocAPI
- Parameters:
- jobID- The job to request about.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
destroyJobpublic void destroyJob(int jobID, String reason, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPIDestroy a job.- Specified by:
- destroyJobin interface- SpallocAPI
- Parameters:
- jobID- The ID of the job.
- reason- Why the job is to be destroyed.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
notifyJobpublic void notifyJob(Integer jobID, boolean enable, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPIEnable or disable notifications of changes in job state.- Specified by:
- notifyJobin interface- SpallocAPI
- Parameters:
- jobID- The job to request (or cancel requests) about, or- nullto be notified/not notified about all jobs.
- enable- True to enable notifications, false to disable them.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
- See Also:
 
- 
notifyMachinepublic void notifyMachine(String machineName, boolean enable, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPIEnable or disable notifications of changes in machine state.- Specified by:
- notifyMachinein interface- SpallocAPI
- Parameters:
- machineName- The machine to request (or cancel requests) about, or- nullto be notified/not notified about all machines (known to spalloc).
- enable- True to enable notifications, false to disable them.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
- See Also:
 
- 
listJobspublic List<JobDescription> listJobs(Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPIList all jobs.- Specified by:
- listJobsin interface- SpallocAPI
- Parameters:
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- A list of allocated/queued jobs in order of creation from oldest (first) to newest (last). This is unmodifiable.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
listMachinespublic List<Machine> listMachines(Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPIList all known machines.- Specified by:
- listMachinesin interface- SpallocAPI
- Parameters:
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- The list of machines known to the system in order of priority from highest (first) to lowest (last). This is unmodifiable.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
getBoardPositionpublic BoardPhysicalCoordinates getBoardPosition(String machineName, TriadCoords coords, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPIGet the physical location of a board.- Specified by:
- getBoardPositionin interface- SpallocAPI
- Parameters:
- machineName- the name of the machine containing the board.
- coords- the logical location of the board.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- the physical location, or nullif the logical location doesn't map to a real board.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
getBoardPositionpublic BoardCoordinates getBoardPosition(String machineName, PhysicalCoords coords, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPIGet the logical location of a board.- Specified by:
- getBoardPositionin interface- SpallocAPI
- Parameters:
- machineName- the name of the machine containing the board.
- coords- the physical location of the board.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- the logical location, or nullif the physical location doesn't map to a real board.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
whereIspublic WhereIs whereIs(int jobID, HasChipLocation chip, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPILocate a chip within a job's allocation.- Specified by:
- whereIsin interface- SpallocAPI
- Parameters:
- jobID- The job to ask about.
- chip- The coordinates of the chip to ask about.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- A description of the chip's location, or nullif it can't be found.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
whereIspublic WhereIs whereIs(String machine, HasChipLocation chip, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPILocate a chip within a machine.- Specified by:
- whereIsin interface- SpallocAPI
- Parameters:
- machine- The machine to ask about.
- chip- The coordinates of the chip to ask about.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- A description of the chip's location, or nullif it can't be found.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
whereIspublic WhereIs whereIs(String machine, PhysicalCoords coords, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPILocate a board within a machine.- Specified by:
- whereIsin interface- SpallocAPI
- Parameters:
- machine- The machine to ask about.
- coords- The physical coordinates of the board to ask about.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- A description of the board's location, or nullif it can't be found.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
whereIspublic WhereIs whereIs(String machine, TriadCoords coords, Integer timeout) throws IOException, SpallocServerException, InterruptedException Description copied from interface:SpallocAPILocate a board within a machine.- Specified by:
- whereIsin interface- SpallocAPI
- Parameters:
- machine- The machine to ask about.
- coords- The logical coordinates of the board to ask about.
- timeout- How long to wait for the request to complete, in milliseconds, or- nullto wait forever.
- Returns:
- A description of the board's location, or nullif it can't be found.
- Throws:
- SpallocProtocolTimeoutException- if the request times out.
- IOException- if network communications fail.
- SpallocServerException- if the server returns an exception response.
- InterruptedException- If interrupted while waiting.
 
- 
formatRequestFormat a request as a line of newline-free JSON, suitable for sending to the spalloc server.- Specified by:
- formatRequestin class- SpallocConnection
- Parameters:
- command- The request to format for sending. Not- null.
- Returns:
- The text to send to the server. Will have a newline added.
- Throws:
- IOException- If formatting goes wrong.
 
- 
parseResponseParse a line of response from the spalloc server, which should be a complete JSON object.- Specified by:
- parseResponsein class- SpallocConnection
- Parameters:
- line- The line to parse. Not- null. Has the terminating newline removed.
- Returns:
- The parsed response.
- Throws:
- IOException- If parsing completely fails.
- SpallocProtocolException- If an unexpected valid JSON message is returned (e.g.,- null).
 
 
-