001/*
002 * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 */
017package org.nuxeo.ecm.platform.importer.queue;
018
019/**
020 * @since 8.3
021 */
022public abstract class AbstractTaskRunner implements TaskRunner {
023
024    protected boolean completed = false;
025
026    protected Exception error;
027
028    protected long nbProcessed = 0;
029
030    protected boolean mustStop;
031
032    protected boolean canStop;
033
034    protected boolean started = false;
035
036
037    protected void incrementProcessed() {
038        nbProcessed++;
039    }
040
041    @Override
042    public boolean isCompleted() {
043        return completed;
044    }
045
046    @Override
047    public boolean isTerminated() {
048        return !started || (completed || getError()!=null);
049    }
050
051    @Override
052    public Exception getError() {
053        return error;
054    }
055
056    @Override
057    public long getNbProcessed() {
058        return nbProcessed;
059    }
060
061    @Override
062    public void mustStop() {
063        mustStop = true;
064        started = false;
065    }
066
067    @Override
068    public void canStop() {
069        canStop = true;
070    }
071
072}