Class StandardRetryingRequestResolver

java.lang.Object
com.minecolonies.core.colony.requestsystem.resolvers.StandardRetryingRequestResolver
All Implemented Interfaces:
IRequester, IQueuedRequestResolver<IRetryable>, IRequestResolver<IRetryable>, IRetryingRequestResolver, ITickable

public class StandardRetryingRequestResolver extends Object implements IRetryingRequestResolver
  • Constructor Details

    • StandardRetryingRequestResolver

      public StandardRetryingRequestResolver(IFactoryController factoryController, IRequestManager manager)
    • StandardRetryingRequestResolver

      public StandardRetryingRequestResolver(IToken<?> id, ILocation location)
  • Method Details

    • updateManager

      public void updateManager(IRequestManager manager)
      Description copied from interface: IRetryingRequestResolver
      Update the associated manager data that links this resolver to a manager.
      Specified by:
      updateManager in interface IRetryingRequestResolver
      Parameters:
      manager - the new associated manager.
    • getMaximalTries

      public int getMaximalTries()
      Description copied from interface: IRetryingRequestResolver
      Method to get the maximal amount of tries that is resolver attempts.
      Specified by:
      getMaximalTries in interface IRetryingRequestResolver
      Returns:
      The maximal amount of tries.
    • getMaximalDelayBetweenRetriesInTicks

      public int getMaximalDelayBetweenRetriesInTicks()
      Description copied from interface: IRetryingRequestResolver
      Method to get the maximal ticks between retries.
      Specified by:
      getMaximalDelayBetweenRetriesInTicks in interface IRetryingRequestResolver
      Returns:
      The maximal amount of ticks between retries.
    • getCurrentReassignmentAttempt

      public int getCurrentReassignmentAttempt()
      Description copied from interface: IRetryingRequestResolver
      The current attempt to be reassigned.
      Specified by:
      getCurrentReassignmentAttempt in interface IRetryingRequestResolver
      Returns:
      The current attempt of reassignment. -1 if none is undertaken.
    • getCurrentlyBeingReassignedRequest

      @Nullable public @Nullable IToken<?> getCurrentlyBeingReassignedRequest()
      Description copied from interface: IRetryingRequestResolver
      Method to get the token of the request that is currently being reassigned
      Specified by:
      getCurrentlyBeingReassignedRequest in interface IRetryingRequestResolver
      Returns:
      The token of the quest that is being reassigned, null if no reassignment is being performed.
    • getRequestType

      public com.google.common.reflect.TypeToken<? extends IRetryable> getRequestType()
      Description copied from interface: IRequestResolver
      Used to determine which type of requests can be resolved by this Resolver.
      Specified by:
      getRequestType in interface IRequestResolver<IRetryable>
      Returns:
      The class that represents this Type of Request this resolver can resolve.
    • canResolveRequest

      public boolean canResolveRequest(@NotNull @NotNull IRequestManager manager, IRequest<? extends IRetryable> requestToCheck)
      Description copied from interface: IRequestResolver
      A PreCheck used to determine if this request resolver is able to resolve a given request. Should quickly and cheaply check if this resolver COULD resolve this request.
      Specified by:
      canResolveRequest in interface IRequestResolver<IRetryable>
      Parameters:
      manager - The manager that is checking if this resolver could resolve that request.
      requestToCheck - The request to check.
      Returns:
      True when this resolver COULD resolve the given request, false when not.
    • attemptResolveRequest

      @Nullable public @Nullable List<IToken<?>> attemptResolveRequest(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends IRetryable> request)
      Description copied from interface: IRequestResolver
      Method used to attempt a resolving operation.

      When this attempt was successful a List with tokens of required requests is returned. This list maybe empty. The list should indicate all sub requests that should be fullfilled before the @code{resolve(IRequest request)} method is called.

      When this attempt was not successful, eg. this resolver could not schedule a crafting operation, a Null object should be returned. In that case the next resolver will be tried by the manager.

      IT IS VITAL THAT THE REQUEST RETURNED ARE NOT YET ASSIGNED. SIMULATION AND OTHER STRATEGIES WILL FAIL ELSE! THE MANAGER GIVEN WILL HANDLE ASSIGNING HIMSELF!

      Specified by:
      attemptResolveRequest in interface IRequestResolver<IRetryable>
      Parameters:
      manager - The manager that is attempting to resolve using this resolver.
      request - The request to resolve.
      Returns:
      The tokens of required requests if the attempt was successful (an empty list is allowed to indicate no requirements), null if the attempt failed.
    • resolveRequest

      public void resolveRequest(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends IRetryable> request) throws RuntimeException
      Description copied from interface: IRequestResolver
      Method used to resolve a given request. Is called the moment all Child requests are resolved.

      The resolver should update the state through the given manager.

      When this method is called all requirements need be fullfilled for this resolver. If this is not the case it will throw a RunTimeException

      Specified by:
      resolveRequest in interface IRequestResolver<IRetryable>
      Parameters:
      manager - The manager that is resolving this request, under normal conditions this is the colony manager.
      request - The request to resolve.
      Throws:
      RuntimeException - is thrown when the resolver could not resolve the request. Should never happen as attemptResolve should be called first, and all requirements should be available to this resolver at this point in time.
    • getFollowupRequestForCompletion

      @Nullable public @Nullable List<IRequest<?>> getFollowupRequestForCompletion(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends IRetryable> completedRequest)
      Specified by:
      getFollowupRequestForCompletion in interface IRequestResolver<IRetryable>
    • onAssignedRequestBeingCancelled

      @Nullable public void onAssignedRequestBeingCancelled(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends IRetryable> request)
      Description copied from interface: IRequestResolver
      Indicates that an assigned request has been cancelled. Is called before graph is updated.
      Specified by:
      onAssignedRequestBeingCancelled in interface IRequestResolver<IRetryable>
      Parameters:
      manager - The manager that indicates the cancelling
      request - The request that has been cancelled.
    • onAssignedRequestCancelled

      public void onAssignedRequestCancelled(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends IRetryable> request)
      Description copied from interface: IRequestResolver
      Indicates that an assigned request has been cancelled. Is called after the graph has been updated.
      Specified by:
      onAssignedRequestCancelled in interface IRequestResolver<IRetryable>
      Parameters:
      manager - The manager that indicates the cancelling
      request - The request that has been cancelled.
    • getPriority

      public int getPriority()
      Description copied from interface: IRequestResolver
      The priority of this resolver. The higher the priority the earlier this resolver is called.
      Specified by:
      getPriority in interface IRequestResolver<IRetryable>
      Returns:
      The priority of this resolver.
    • tick

      public void tick()
      Description copied from interface: ITickable
      Default parameterless ticking implementation.
      Specified by:
      tick in interface ITickable
    • getAllAssignedRequests

      public com.google.common.collect.ImmutableList<IToken<?>> getAllAssignedRequests()
      Description copied from interface: IQueuedRequestResolver
      Method to get a list of all assigned tokens to this resolver.
      Specified by:
      getAllAssignedRequests in interface IQueuedRequestResolver<IRetryable>
      Returns:
      A list of all assigned tokens.
    • onSystemReset

      public void onSystemReset()
      Description copied from interface: IQueuedRequestResolver
      Called when the request system this is part of gets reset.
      Specified by:
      onSystemReset in interface IQueuedRequestResolver<IRetryable>
    • setCurrent

      public void setCurrent(@Nullable @Nullable IToken<?> token)
    • getId

      public IToken<?> getId()
      Description copied from interface: IRequester
      Method to get the ID of a given requester.
      Specified by:
      getId in interface IRequester
      Returns:
      The id of this requester.
    • getLocation

      @NotNull public @NotNull ILocation getLocation()
      Description copied from interface: IRequester
      Method to get the location of this locatable.
      Specified by:
      getLocation in interface IRequester
      Returns:
      the location.
    • onRequestedRequestComplete

      public void onRequestedRequestComplete(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<?> request)
      Description copied from interface: IRequester
      Method called by the request system to notify this requester that a request is complete.
      Specified by:
      onRequestedRequestComplete in interface IRequester
      Parameters:
      manager - the request manager.
      request - the request.
    • onRequestedRequestCancelled

      public void onRequestedRequestCancelled(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<?> request)
      Description copied from interface: IRequester
      Method called by the request system to notify this requester that a request has been overruled.
      Specified by:
      onRequestedRequestCancelled in interface IRequester
      Parameters:
      manager - the request manager.
      request - the request.
    • getRequesterDisplayName

      @NotNull public @NotNull net.minecraft.network.chat.MutableComponent getRequesterDisplayName(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<?> request)
      Description copied from interface: IRequester
      Gets the name of the requester that requested the request given by the token.
      Specified by:
      getRequesterDisplayName in interface IRequester
      Parameters:
      manager - the request manager.
      request - the request for which the name of the requester is retrieved
      Returns:
      The display name of the requester.
    • updateData

      public void updateData(@NotNull @NotNull Map<IToken<?>,Integer> newAssignedRequests, @NotNull @NotNull Map<IToken<?>,Integer> newDelays)
    • getDelays

      public Map<IToken<?>,Integer> getDelays()
    • getAssignedRequests

      public Map<IToken<?>,Integer> getAssignedRequests()
    • onColonyUpdate

      public void onColonyUpdate(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull Predicate<IRequest<?>> shouldTriggerReassign)
      Description copied from interface: IRequestResolver
      Called by manager given to indicate that a colony has updated their available items.
      Specified by:
      onColonyUpdate in interface IRequestResolver<IRetryable>
      Parameters:
      manager - The systems manager.
      shouldTriggerReassign - The request assigned
    • isValid

      public boolean isValid()
      Description copied from interface: IRequestResolver
      If this resolver has valid data in it.
      Specified by:
      isValid in interface IRequestResolver<IRetryable>
      Returns:
      true if so.