/** * Dequeue an element. * @return The element. When queue is empty * the methods blocks until an element is added. */ public T dequeue() throws ClosedException { return dequeue(-1); }
final BlockingQueue bq = new BlockingQueue(); final IComponentIdentifier fcid = cid; Thread rescuethread = new Thread(new Runnable()
/** * Schedule a rescue step. * @param cid The id of a component of the platform. * @param run The runnable to execute. */ public synchronized static void scheduleRescueStep(IComponentIdentifier cid, Runnable run) { Tuple2<BlockingQueue, Thread> tup = rescuethreads!=null ? rescuethreads.get(cid.getRoot()) : null; if(tup!=null) { tup.getFirstEntity().enqueue(run); } else { // Rescue thread after platform shutdown -> just execute run.run(); } }
/** * Shutdown the rescue thread of a platform. */ public static synchronized void shutdownRescueThread(IComponentIdentifier cid) { assert cid.getParent()==null : cid; Tuple2<BlockingQueue, Thread> tup = rescuethreads==null? null: rescuethreads.remove(cid.getRoot()); if(tup!=null) { List<Runnable> steps = tup.getFirstEntity().setClosed(true); for(Runnable next: steps) { try { next.run(); } catch(Exception e) { Logger.getLogger(cid.getLocalName()).severe("Exception during step on rescue thread: "+e); } } } } }
final int[] stat = new int[3]; final IBlockingQueue queue = new BlockingQueue();
/** * Schedule a rescue step. * @param cid The id of a component of the platform. * @param run The runnable to execute. */ public synchronized static void scheduleRescueStep(IComponentIdentifier cid, Runnable run) { Tuple2<BlockingQueue, Thread> tup = rescuethreads!=null ? rescuethreads.get(cid.getRoot()) : null; if(tup!=null) { tup.getFirstEntity().enqueue(run); } else { // Rescue thread after platform shutdown -> just execute run.run(); } }
/** * Shutdown the rescue thread of a platform. */ public static synchronized void shutdownRescueThread(IComponentIdentifier cid) { assert cid.getParent()==null : cid; Tuple2<BlockingQueue, Thread> tup = rescuethreads==null? null: rescuethreads.remove(cid.getRoot()); if(tup!=null) { List<Runnable> steps = tup.getFirstEntity().setClosed(true); for(Runnable next: steps) { try { next.run(); } catch(Exception e) { Logger.getLogger(cid.getLocalName()).severe("Exception during step on rescue thread: "+e); } } } }
waits = new BlockingQueue<ExecutionThread>(); Thread[] threads = new Thread[3]; MyMonitor[] monitors = new MyMonitor[threads.length];
public void run() { try { while(true) { Runnable next = (Runnable)bq.dequeue(); try { next.run(); } catch(Exception e) { Logger.getLogger(fcid.getLocalName()).severe("Exception during step on rescue thread: "+e); } } } catch(IBlockingQueue.ClosedException bqce) { } } }, "rescue_thread_"+cid.getName());
final BlockingQueue bq = new BlockingQueue(); final IComponentIdentifier fcid = cid; Runnable run = new Runnable()
public void run() { try { while(true) { Runnable next = (Runnable)bq.dequeue(); try { next.run(); } catch(Exception e) { Logger.getLogger(fcid.getLocalName()).severe("Exception during step on rescue thread: "+e); } } } catch(IBlockingQueue.ClosedException bqce) { } } };