001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.system.thread;
020
021import icy.main.Icy;
022
023/**
024 * @deprecated Use {@link InstanceProcessor} instead.
025 */
026@Deprecated
027public class IdProcessor extends Processor
028{
029
030    /**
031     * Create an IdProcessor
032     * 
033     * @deprecated uses default constructor instead
034     */
035    @SuppressWarnings("unused")
036    @Deprecated
037    public IdProcessor(int maxProcess, int maxProcessPerId)
038    {
039        super();
040    }
041
042    /**
043     * Create an IdProcessor
044     */
045    public IdProcessor(int priority)
046    {
047        super(-1, 1, priority);
048        setThreadName("IdProcessor");
049    }
050
051    /**
052     * Create an IdProcessor
053     */
054    public IdProcessor()
055    {
056        this(Processor.NORM_PRIORITY);
057    }
058
059    /**
060     * Add a task to processor
061     */
062    @Override
063    public synchronized boolean addTask(Runnable task, boolean onAWTEventThread, int id)
064    {
065        if (task == null)
066            return false;
067
068        // we remove pending task if any
069        removeFirstWaitingTask(id);
070
071        if (!super.addTask(task, onAWTEventThread, id))
072        {
073            if (!Icy.isExiting())
074            {
075                // error while adding task
076                System.err.println("Cannot add task, ignore execution : " + task);
077                return false;
078            }
079        }
080
081        return true;
082    }
083}