/*
 * Filename: RemoteNotifier.java
 *
 * Author: Joe Wang
 *
 * Copyright (c) 2003-2005 
 * The Trustees of Columbia University in the City of New York
 * Columbia University Information Technology
 *
 * This file is part of NINJa.
 *
 * NINJa is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * NINJa is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with NINJa; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Created on December 12, 2002, 1:36 PM
 */

package edu.columbia.print.ninja.core.service;

import java.util.*;
import com.millipad.util.*;
import net.jini.core.event.*;

/**
 *
 * @author  joe
 */
class RemoteNotifier {
    BlockingQueue threads;
    
    RemoteNotifier(int threadCount) {
        threads = new BlockingQueue();
        for(int i=threadCount; i>0; i--) {
            threads.push(new Timer());
        }
    }

    public void notify(RemoteEventListener l, RemoteEvent evt) {
        Timer t = (Timer )threads.pop();
        threads.push(t);
        t.schedule(new Notifier(l, evt), 0);
    }

    class Notifier extends TimerTask {
        RemoteEventListener l;
        RemoteEvent evt;
        Notifier(RemoteEventListener l, RemoteEvent evt) {
            this.l = l;
            this.evt = evt;
        }
        public void run() {
            try {
                l.notify(evt);
            }
            catch(Exception e) {
                e.printStackTrace();
            }
        }
    }
}
