Class EntityBatchPollingTask<E extends IEntity>

    • Field Detail

      • BATCH_SIZE

        public static final int BATCH_SIZE
        The maximum expected size of nextIds(). Doesn't mean that this many entities will be processed in a single transaction, as they are processed one at a time (in separated transactions).
        See Also:
        Constant Field Values
      • entityType

        protected final Class<E extends IEntity> entityType
    • Constructor Detail

      • EntityBatchPollingTask

        public EntityBatchPollingTask​(Class<E> entityType)
    • Method Detail

      • find

        protected E find​(Long id)
      • finish

        protected abstract void finish​(E entity,
                                       Throwable error)
                                throws Throwable
        Must be implemented in order to mark the given entity as finished. Even when {@link #process(IEntity))} fails, this method is invoked. Runs in another transaction, passing the error if process(IEntity) yielded an error.
        Throws:
        Throwable
      • generateErrorLog

        protected final void generateErrorLog​(Long networkId,
                                              String stackTrace)
        Generates an error log which is bound to network with the given id. May be overridden to no-op if subclasses don't want an error log
      • generateErrorLog

        protected final void generateErrorLog​(Long networkId,
                                              Throwable error)
      • logProcessingErrors

        protected boolean logProcessingErrors​(E entity)
        Returns whether a log should be generated when an entity processing fails
      • nextIds

        protected abstract Collection<Long> nextIds()
                                             throws Throwable
        Must be implemented in order to return the ids of the next entities to be processed, without actually processing them. Returning null or an empty list means there is no more data for now, and will make this task sleep
        Throws:
        Throwable
      • onFinish

        protected void onFinish()
        Callback invoked when the task has finished
      • process

        protected abstract void process​(E entity)
                                 throws Throwable
        Must be implemented in order to actually process the given entity, without change it's state to already processed
        Throws:
        Throwable
      • resolveNetwork

        protected Network resolveNetwork​(E entity)
        May be overridden in order to resolve the correct network for the given entity. By default, if the entity is a BaseEntity, return its network, otherwise, null
      • shouldGenerateErrorLog

        protected boolean shouldGenerateErrorLog​(Long networkId,
                                                 Throwable error)
      • shouldSkipFinish

        protected boolean shouldSkipFinish​(Long id,
                                           Throwable error)
        Returns whether the entity with the given id, having the given error when process(IEntity) was executed, needs or not the finish(IEntity, Throwable) method. If this method returns true, finish() is not executed