Class Client

java.lang.Object
net.targetr.rc.client.Client

public class Client extends Object
Represents a WebBrowser in a room. Facilitates communications.
Author:
Dr Michael Gardiner
  • Field Details

    • clientRequest

      public volatile ClientRequest clientRequest
      The current client request associated with this client.
  • Constructor Details

    • Client

      public Client()
      Constructs a new Client instance.
  • Method Details

    • setDirectSendHandler

      public void setDirectSendHandler(Client.DirectSendHandler handler)
      Sets a handler to attempt instantaneous delivery of a command.
      Parameters:
      handler - the functional handler
    • attachRequest

      public void attachRequest(ClientRequest request)
      Attaches a request, ending the previous request and waking its writer.
      Parameters:
      request - the new request for this client
    • endRequest

      public void endRequest(ClientRequest request)
      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 waiting
      timeoutMillis - 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

      public void sendCommand(ClientCommand cmd)
      Attempts direct delivery, falling back to the queue if unavailable or failed.
      Parameters:
      cmd - the command to send
    • enqueueCommand

      public void enqueueCommand(ClientCommand cmd)
      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

      public ClientCommand popCommand()
      Retrieves and removes the next command from the queue.
      Returns:
      the next command, or null if the queue is empty
    • getState

      public Map<String,Object> getState()
      Retrieves the current state of the client request as a map.
      Returns:
      a map containing the state details, or null if 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:
      true if the request is still active or ended after the given timestamp, false otherwise
    • matchesAppOrClient

      public boolean matchesAppOrClient(String value)
      Checks if the value matches the client or app.
      Parameters:
      value - the value string to check
      Returns:
      true if the value matches client or app, false otherwise
    • matchesAppOrClient

      public static boolean matchesAppOrClient(String search, String app, String clientId)
      Checks if the search string matches the app or client name.
      Parameters:
      search - the search string
      app - the app name
      clientId - the client ID
      Returns:
      true if the search string matches the app or client name, false otherwise