Package net.targetr.rc.client
Class Client
java.lang.Object
net.targetr.rc.client.Client
Represents a WebBrowser in a room. Facilitates communications.
- Author:
- Dr Michael Gardiner
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHandler invoked for direct, real-time command dispatch omitting the queue. -
Field Summary
FieldsModifier and TypeFieldDescriptionThe current client request associated with this client. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidattachRequest(ClientRequest request) Attaches a request, ending the previous request and waking its writer.awaitCommand(ClientRequest request, long timeoutMillis) Waits for and removes the next command while the supplied request is current.voidendRequest(ClientRequest request) Ends a specific request and wakes waiting writers without ending a replacement.voidQueues a command for the client writer without attempting direct delivery.getState()Retrieves the current state of the client request as a map.booleanChecks if the client has commands pending in the queue.booleanisActive(long recent) Checks if the client is currently active or has recently ended.booleanmatchesAppOrClient(String value) Checks if the value matches the client or app.static booleanmatchesAppOrClient(String search, String app, String clientId) Checks if the search string matches the app or client name.Retrieves and removes the next command from the queue.voidsendCommand(ClientCommand cmd) Attempts direct delivery, falling back to the queue if unavailable or failed.voidSets a handler to attempt instantaneous delivery of a command.
-
Field Details
-
clientRequest
The current client request associated with this client.
-
-
Constructor Details
-
Client
public Client()Constructs a new Client instance.
-
-
Method Details
-
setDirectSendHandler
Sets a handler to attempt instantaneous delivery of a command.- Parameters:
handler- the functional handler
-
attachRequest
Attaches a request, ending the previous request and waking its writer.- Parameters:
request- the new request for this client
-
endRequest
Ends a specific request and wakes waiting writers without ending a replacement.- Parameters:
request- the request that has finished or failed
-
awaitCommand
public ClientCommand awaitCommand(ClientRequest request, long timeoutMillis) throws InterruptedException Waits for and removes the next command while the supplied request is current. Socket writes must happen after this method returns and releases the lock.- Parameters:
request- the request whose writer is waitingtimeoutMillis- maximum time to wait, or zero to poll without waiting- Returns:
- the next command, or null if timed out, ended, or replaced
- Throws:
InterruptedException- if interrupted while acquiring the lock or waiting
-
sendCommand
Attempts direct delivery, falling back to the queue if unavailable or failed.- Parameters:
cmd- the command to send
-
enqueueCommand
Queues a command for the client writer without attempting direct delivery. Notifies any waiting writer threads.- Parameters:
cmd- the command to enqueue
-
hasCommands
public boolean hasCommands()Checks if the client has commands pending in the queue.- Returns:
- true if commands are backlogged
-
popCommand
Retrieves and removes the next command from the queue.- Returns:
- the next command, or
nullif the queue is empty
-
getState
Retrieves the current state of the client request as a map.- Returns:
- a map containing the state details, or
nullif there is no client request
-
isActive
public boolean isActive(long recent) Checks if the client is currently active or has recently ended.- Parameters:
recent- the timestamp to check against if the request recently ended- Returns:
trueif the request is still active or ended after the given timestamp,falseotherwise
-
matchesAppOrClient
Checks if the value matches the client or app.- Parameters:
value- the value string to check- Returns:
trueif the value matches client or app,falseotherwise
-
matchesAppOrClient
Checks if the search string matches the app or client name.- Parameters:
search- the search stringapp- the app nameclientId- the client ID- Returns:
trueif the search string matches the app or client name,falseotherwise
-