Class ClientsManager


  • public class ClientsManager
    extends java.lang.Object
    • Method Detail

      • getClientData

        public ClientData getClientData​(int clientId)
        We are assuming that no more than one thread will access the same clientData during creation.
        Parameters:
        clientId -
        Returns:
        the ClientData stored on the manager
      • getPendingRequests

        public RequestList getPendingRequests()
        Get pending requests in a fair way (one request from each client queue until the max number of requests is obtained).
        Returns:
        the set of all pending requests of this system
      • havePendingRequests

        public boolean havePendingRequests()
        We've implemented some protection for individual client data, but the clients table can change during the operation.
        Returns:
        true if there are some pending requests and false otherwise
      • isNextBatchReady

        public boolean isNextBatchReady()
        Retrieves the number of pending requests and their sizes and checks if there are enough to fill the next batch completely.
        Returns:
        true if there are enough requests and false otherwise
      • isPending

        public boolean isPending​(int reqId)
        Verifies if some reqId is pending.
        Parameters:
        reqId - the request identifier
        Returns:
        true if the request is pending
      • getPending

        public TOMMessage getPending​(int reqId)
        Get some reqId that is pending.
        Parameters:
        reqId - the request identifier
        Returns:
        the pending request, or null
      • requestReceived

        public boolean requestReceived​(TOMMessage request,
                                       boolean fromClient)
      • requestReceived

        public boolean requestReceived​(TOMMessage request,
                                       boolean fromClient,
                                       ServerCommunicationSystem cs)
        Notifies the ClientsManager that a new request from a client arrived. This method updates the ClientData of the client request.getSender().
        Parameters:
        request - the received request
        fromClient - the message was received from client or not?
        cs - server com. system to be able to send replies to already processed requests
        Returns:
        true if the request is ok and is added to the pending messages for this client, false if there is some problem and the message was not accounted
      • requestsOrdered

        public void requestsOrdered​(TOMMessage[] requests)
        Notifies the ClientsManager that these requests were already executed.
        Parameters:
        requests - the array of requests to account as ordered
      • requestsExecuted

        public void requestsExecuted​(TOMMessage[] requests)
        Notifies the ClientManager that these requests now have replies (computed by the application) attached to them
        Parameters:
        requests - the array of requests to account as executed
      • getClientsLock

        public java.util.concurrent.locks.ReentrantLock getClientsLock()
      • clear

        public void clear()
      • numClients

        public int numClients()
      • getLastReplyOfEachClient

        public java.util.TreeMap<java.lang.Integer,​TOMMessage> getLastReplyOfEachClient()
        Collects the last ordered request and their associated replies of each client in a HashMap (clientID -> TOMMessage)
        Returns:
        hashmap of last request and replies
      • manageLastReplyOfEachClientAfterRecovery

        public void manageLastReplyOfEachClientAfterRecovery​(java.util.TreeMap<java.lang.Integer,​TOMMessage> repliesToClients)
        Sets the reply store of each client in a HashMap (clientID -> TOMMessage). This method is called during recovery of a replica
        Parameters:
        repliesToClients - TreeMap of last reply for each client (clientID -> last reply)
      • getLastRepliesOfEachClient

        public java.util.TreeMap<java.lang.Integer,​RequestList> getLastRepliesOfEachClient()
        Collects the max number of last ordered requests of each client in a HashMap (clientID -> RequestList)
        Returns:
        hashmap of lists of last request and replies per client
      • thisReplicaWasRecovered

        public boolean thisReplicaWasRecovered()
        Used to indicate a reboot, relevant to give more details in warning messages
        Returns:
        boolean IF the replica has been re-booted within the last 20 seconds