/** * Schedules the given Runnable object for a later invocation, and * returns. The given runnable preempts any runnable that is not * currently executing (ie the next runnable started will be the * one given). An exception is thrown if the RunnableQueue was * not started. * @throws IllegalStateException if getThread() is null. */ public void preemptLater(Runnable r) { if (runnableQueueThread == null) { throw new IllegalStateException ("RunnableQueue not started or has exited"); } synchronized (list) { list.add(preemptCount, new Link(r)); preemptCount++; list.notify(); } }
/** * Schedules the given Runnable object for a later invocation, and * returns. The given runnable preempts any runnable that is not * currently executing (ie the next runnable started will be the * one given). An exception is thrown if the RunnableQueue was * not started. * @throws IllegalStateException if getThread() is null. */ public void preemptLater(Runnable r) { if (runnableQueueThread == null) { throw new IllegalStateException ("RunnableQueue not started or has exited"); } synchronized (list) { list.add(preemptCount, new Link(r)); preemptCount++; list.notify(); } }
/** * Schedules the given Runnable object for a later invocation, and * returns. The given runnable preempts any runnable that is not * currently executing (ie the next runnable started will be the * one given). An exception is thrown if the RunnableQueue was * not started. * @throws IllegalStateException if getThread() is null. */ public void preemptLater(Runnable r) { if (runnableQueueThread == null) { throw new IllegalStateException ("RunnableQueue not started or has exited"); } synchronized (list) { list.add(preemptCount, new Link(r)); preemptCount++; list.notify(); } }
/** * Waits until the given Runnable's <code>run()</code> has returned. * The given runnable preempts any runnable that is not currently * executing (ie the next runnable started will be the one given). * <em>Note: <code>preemptAndWait()</code> must not be called from the * current thread (for example from the <code>run()</code> method of the * argument).</em> * @throws IllegalStateException if getThread() is null or if the * thread returned by getThread() is the current one. */ public void preemptAndWait(Runnable r) throws InterruptedException { if (runnableQueueThread == null) { throw new IllegalStateException ("RunnableQueue not started or has exited"); } if (runnableQueueThread == Thread.currentThread()) { throw new IllegalStateException ("Cannot be called from the RunnableQueue thread"); } LockableLink l = new LockableLink(r); synchronized (list) { list.add(preemptCount, l); preemptCount++; list.notify(); } l.lock(); // todo: the 'other side' of list may retrieve the l before it is locked... }
/** * Waits until the given Runnable's <code>run()</code> has returned. * The given runnable preempts any runnable that is not currently * executing (ie the next runnable started will be the one given). * <em>Note: <code>preemptAndWait()</code> must not be called from the * current thread (for example from the <code>run()</code> method of the * argument).</em> * @throws IllegalStateException if getThread() is null or if the * thread returned by getThread() is the current one. */ public void preemptAndWait(Runnable r) throws InterruptedException { if (runnableQueueThread == null) { throw new IllegalStateException ("RunnableQueue not started or has exited"); } if (runnableQueueThread == Thread.currentThread()) { throw new IllegalStateException ("Cannot be called from the RunnableQueue thread"); } LockableLink l = new LockableLink(r); synchronized (list) { list.add(preemptCount, l); preemptCount++; list.notify(); } l.lock(); // todo: the 'other side' of list may retrieve the l before it is locked... }
public synchronized void remove(LRUObj obj) { LRUNode nde = obj.lruGet(); if (nde == null) return; used.remove(nde); nde.setObj(null); free.add(nde); }
public synchronized void flush() { while (used.getSize() > 0) { LRUNode nde = (LRUNode)used.pop(); nde.setObj(null); free.add(nde); } }
public LRUCache(int size) { if (size <= 0) size=1; maxSize = size; free = new DoublyLinkedList(); used = new DoublyLinkedList(); while (size > 0) { free.add(new LRUNode()); size--; } }
public synchronized void remove(LRUObj obj) { LRUNode nde = obj.lruGet(); if (nde == null) return; used.remove(nde); nde.setObj(null); free.add(nde); }
public LRUCache(int size) { if (size <= 0) size=1; maxSize = size; free = new DoublyLinkedList(); used = new DoublyLinkedList(); while (size > 0) { free.add(new LRUNode()); size--; } }
public synchronized void remove(LRUObj obj) { LRUNode nde = obj.lruGet(); if (nde == null) return; used.remove(nde); nde.setObj(null); free.add(nde); }
public synchronized void flush() { while (used.getSize() > 0) { LRUNode nde = (LRUNode)used.pop(); nde.setObj(null); free.add(nde); } }
public LRUCache(int size) { if (size <= 0) size=1; maxSize = size; free = new DoublyLinkedList(); used = new DoublyLinkedList(); while (size > 0) { free.add(new LRUNode()); size--; } }
public synchronized void flush() { while (used.getSize() > 0) { LRUNode nde = (LRUNode)used.pop(); nde.setObj(null); free.add(nde); } }
public synchronized void setSize(int newSz) { if (maxSize < newSz) { // list grew... for (int i=maxSize; i<newSz; i++) free.add(new LRUNode()); } else if (maxSize > newSz) { for (int i=used.getSize(); i>newSz; i--) { LRUNode nde = (LRUNode)used.getTail(); used.remove(nde); nde.setObj(null); } } maxSize = newSz; }
public synchronized void setSize(int newSz) { if (maxSize < newSz) { // list grew... for (int i=maxSize; i<newSz; i++) free.add(new LRUNode()); } else if (maxSize > newSz) { for (int i=used.getSize(); i>newSz; i--) { LRUNode nde = (LRUNode)used.getTail(); used.remove(nde); nde.setObj(null); } } maxSize = newSz; }
public synchronized void setSize(int newSz) { if (maxSize < newSz) { // list grew... for (int i=maxSize; i<newSz; i++) free.add(new LRUNode()); } else if (maxSize > newSz) { for (int i=used.getSize(); i>newSz; i--) { LRUNode nde = (LRUNode)used.getTail(); used.remove(nde); nde.setObj(null); } } maxSize = newSz; }
public synchronized void add(LRUObj obj) { LRUNode nde = obj.lruGet(); // already linked in... if (nde != null) { used.touch(nde); return; } if (free.getSize() > 0) { nde = (LRUNode)free.pop(); nde.setObj(obj); used.add(nde); } else { nde = (LRUNode)used.getTail(); nde.setObj(obj); used.touch(nde); } }
public synchronized void add(LRUObj obj) { LRUNode nde = obj.lruGet(); // already linked in... if (nde != null) { used.touch(nde); return; } if (free.getSize() > 0) { nde = (LRUNode)free.pop(); nde.setObj(obj); used.add(nde); } else { nde = (LRUNode)used.getTail(); nde.setObj(obj); used.touch(nde); } }
public synchronized void add(LRUObj obj) { LRUNode nde = obj.lruGet(); // already linked in... if (nde != null) { used.touch(nde); return; } if (free.getSize() > 0) { nde = (LRUNode)free.pop(); nde.setObj(obj); used.add(nde); } else { nde = (LRUNode)used.getTail(); nde.setObj(obj); used.touch(nde); } }