class LimitTrialCountStrategy implements ITaskProcessStrategy {

    @Override
    public void process(final ITaskExecutionState state)
            throws TaskExecutionException, InvalidArgumentException, TaskProcessException {
        IShutdownAwareTask shutdownAwareTask = state.getTaskAs(IShutdownAwareTask.class);

        TrialCounter counter = (TrialCounter) shutdownAwareTask.getShutdownStatus();

        if (null == counter) {
            counter = new TrialCounter();
            shutdownAwareTask.setShutdownStatus(counter);
        }

        int counterState = counter.increment();

        try {
            if (counterState > maxTrials) {
                shutdownAwareTask.notifyIgnored();
            } else {
                if (counterState > silentTrials) {
                    shutdownAwareTask.notifyShuttingDown();
                }

                state.execute();
            }
        } catch (ShutdownAwareTaskNotificationException e) {
            throw new TaskProcessException(e);
        }
    }

    public  LimitTrialCountStrategy(final int maxTrials, final int silentTrials);

}