java.lang.Object
com.minecolonies.core.colony.requestsystem.management.handlers.RequestHandler
All Implemented Interfaces:
IRequestHandler

public class RequestHandler extends Object implements IRequestHandler
Class used to handle the inner workings of the request system with regards to requests.
  • Constructor Details

  • Method Details

    • getManager

      public IRequestManager getManager()
      Specified by:
      getManager in interface IRequestHandler
    • createRequest

      public <Request extends IRequestable> IRequest<Request> createRequest(IRequester requester, Request request)
      Specified by:
      createRequest in interface IRequestHandler
    • registerRequest

      public void registerRequest(IRequest<?> request)
      Specified by:
      registerRequest in interface IRequestHandler
    • assignRequest

      public void assignRequest(IRequest<?> request)
      Method used to assign a given request to a resolver. Does not take any blacklist into account.
      Specified by:
      assignRequest in interface IRequestHandler
      Parameters:
      request - The request to assign
      Throws:
      IllegalArgumentException - when the request is already assigned
    • assignRequest

      public IToken<?> assignRequest(IRequest<?> request, Collection<IToken<?>> resolverTokenBlackList)
      Method used to assign a given request to a resolver. Does take a given blacklist of resolvers into account.
      Specified by:
      assignRequest in interface IRequestHandler
      Parameters:
      request - The request to assign.
      resolverTokenBlackList - Each resolver that has its token in this blacklist will be skipped when checking for a possible resolver.
      Returns:
      The token of the resolver that has gotten the request assigned, null if none was found.
      Throws:
      IllegalArgumentException - is thrown when the request is unknown to this manager.
    • assignRequestDefault

      public IToken<?> assignRequestDefault(IRequest<?> request, Collection<IToken<?>> resolverTokenBlackList)
      Method used to assign a given request to a resolver. Does take a given blacklist of resolvers into account. Uses the default assigning strategy: AssigningStrategy.PRIORITY_BASED
      Specified by:
      assignRequestDefault in interface IRequestHandler
      Parameters:
      request - The request to assign.
      resolverTokenBlackList - Each resolver that has its token in this blacklist will be skipped when checking for a possible resolver.
      Returns:
      The token of the resolver that has gotten the request assigned, null if none was found.
      Throws:
      IllegalArgumentException - is thrown when the request is unknown to this manager.
    • reassignRequest

      public IToken<?> reassignRequest(IRequest<?> request, Collection<IToken<?>> resolverTokenBlackList)
      Method used to reassign the request to a resolver that is not in the given blacklist. Cancels the request internally without notify the requester, and attempts a reassign. If the reassignment failed, it is assigned back to the orignal resolver.
      Specified by:
      reassignRequest in interface IRequestHandler
      Parameters:
      request - The request that is being reassigned.
      resolverTokenBlackList - The blacklist to which not to assign the request.
      Returns:
      The token of the resolver that has gotten the request assigned, null if none was found.
      Throws:
      IllegalArgumentException - Thrown when something went wrong.
    • isAssigned

      public boolean isAssigned(IToken<?> token)
      Method used to check if a given request token is assigned to a resolver.
      Specified by:
      isAssigned in interface IRequestHandler
      Parameters:
      token - The request token to check for.
      Returns:
      True when the request token has been assigned, false when not.
    • onRequestResolved

      public void onRequestResolved(IToken<?> token)
      Description copied from interface: IRequestHandler
      Method used to handle the successful resolving of a request and the completion of its children.
      Specified by:
      onRequestResolved in interface IRequestHandler
      Parameters:
      token - The token of the requests that finished resolving.
    • onRequestCompleted

      public void onRequestCompleted(IToken<?> token)
      Method used to handle the successful resolving of a request.
      Specified by:
      onRequestCompleted in interface IRequestHandler
      Parameters:
      token - The token of the request that got finished successfully.
    • onRequestOverruled

      public void onRequestOverruled(IToken<?> token)
      Method used to handle requests that were overruled or cancelled. Cancels all children first, handles the creation of clean up requests.
      Specified by:
      onRequestOverruled in interface IRequestHandler
      Parameters:
      token - The token of the request that got cancelled or overruled
    • onRequestCancelled

      public void onRequestCancelled(IToken<?> token)
      Method used to handle requests that were overruled or cancelled. Cancels all children first, handles the creation of clean up requests.
      Specified by:
      onRequestCancelled in interface IRequestHandler
      Parameters:
      token - The token of the request that got cancelled or overruled
    • onChildRequestCancelled

      public void onChildRequestCancelled(IToken<?> token)
      Specified by:
      onChildRequestCancelled in interface IRequestHandler
    • onRequestCancelledDirectly

      public void onRequestCancelledDirectly(IToken<?> token)
      Specified by:
      onRequestCancelledDirectly in interface IRequestHandler
    • processDirectCancellationAndNotifyRequesterOf

      public void processDirectCancellationAndNotifyRequesterOf(IRequest<?> request)
      Specified by:
      processDirectCancellationAndNotifyRequesterOf in interface IRequestHandler
    • processDirectCancellationOf

      public void processDirectCancellationOf(IRequest<?> request)
      Specified by:
      processDirectCancellationOf in interface IRequestHandler
    • resolveRequest

      public void resolveRequest(IRequest<?> request)
      Method used to resolve a request. When this method is called the given request has to be assigned.
      Specified by:
      resolveRequest in interface IRequestHandler
      Parameters:
      request - The request about to be resolved.
      Throws:
      IllegalArgumentException - when the request is unknown, not resolved, or cannot be resolved.
    • cleanRequestData

      public void cleanRequestData(IToken<?> token)
      Method called when the given manager gets notified of the receiving of a given task by its requester. All communication with the resolver should be aborted by this time, so overrullings and cancelations need to be processed, before this method is called.
      Specified by:
      cleanRequestData in interface IRequestHandler
      Parameters:
      token - The token of the request.
      Throws:
      IllegalArgumentException - Thrown when the token is unknown.
    • removeRequester

      public void removeRequester(IRequester requester)
      Description copied from interface: IRequestHandler
      Remove a specific requester and all assigned requests from the manager.
      Specified by:
      removeRequester in interface IRequestHandler
      Parameters:
      requester - the requester.
    • getRequest

      public IRequest<?> getRequest(IToken<?> token)
      Method used to get a registered request from a given token.
      Specified by:
      getRequest in interface IRequestHandler
      Parameters:
      token - The token to query
      Returns:
      the request.
      Throws:
      IllegalArgumentException - when the token is unknown to the given manager.
    • getRequestOrNull

      public IRequest<?> getRequestOrNull(IToken<?> token)
      Method used to get a registered request fora given token.
      Specified by:
      getRequestOrNull in interface IRequestHandler
      Parameters:
      token - The token to get the request for.
      Returns:
      The request or null when no request with that token exists.
    • getRequestsMadeByRequester

      public Collection<IRequest<?>> getRequestsMadeByRequester(IRequester requester)
      Returns all requests made by a given requester.
      Specified by:
      getRequestsMadeByRequester in interface IRequestHandler
      Parameters:
      requester - The requester in question.
      Returns:
      A collection with request instances that are made by the given requester.