Permalink
Browse files

Getting rid of all Scala proprietary copies of JUC classes

  • Loading branch information...
1 parent 1a3d112 commit 3ee52649f422b252494d16bffcdb138d41150f3f @szegedi szegedi committed Sep 14, 2010
Showing with 247 additions and 10,304 deletions.
  1. +3 −0 .classpath
  2. +3 −7 src/main/java/com/twitter/actors/FJTaskRunner.java
  3. +6 −11 src/main/java/com/twitter/actors/FJTaskRunnerGroup.java
  4. +3 −1 src/main/java/com/twitter/actors/IFJTaskRunnerGroup.java
  5. +0 −25 src/main/java/com/twitter/actors/LinkedNode.java
  6. +0 −185 src/main/java/com/twitter/actors/LinkedQueue.java
  7. +0 −32 src/main/java/com/twitter/actors/threadpool/AbstractCollection.java
  8. +0 −293 src/main/java/com/twitter/actors/threadpool/AbstractExecutorService.java
  9. +0 −170 src/main/java/com/twitter/actors/threadpool/AbstractQueue.java
  10. +223 −0 src/main/java/com/twitter/actors/threadpool/ActorThreadPoolExecutor.java
  11. +0 −811 src/main/java/com/twitter/actors/threadpool/Arrays.java
  12. +0 −210 src/main/java/com/twitter/actors/threadpool/AtomicInteger.java
  13. +0 −35 src/main/java/com/twitter/actors/threadpool/Callable.java
  14. +0 −34 src/main/java/com/twitter/actors/threadpool/CancellationException.java
  15. +0 −98 src/main/java/com/twitter/actors/threadpool/CompletionService.java
  16. +0 −65 src/main/java/com/twitter/actors/threadpool/ExecutionException.java
  17. +0 −112 src/main/java/com/twitter/actors/threadpool/Executor.java
  18. +0 −178 src/main/java/com/twitter/actors/threadpool/ExecutorCompletionService.java
  19. +0 −331 src/main/java/com/twitter/actors/threadpool/ExecutorService.java
  20. +0 −667 src/main/java/com/twitter/actors/threadpool/Executors.java
  21. +0 −143 src/main/java/com/twitter/actors/threadpool/Future.java
  22. +0 −311 src/main/java/com/twitter/actors/threadpool/FutureTask.java
  23. +0 −28 src/main/java/com/twitter/actors/threadpool/Perf.java
  24. +0 −191 src/main/java/com/twitter/actors/threadpool/Queue.java
  25. +0 −62 src/main/java/com/twitter/actors/threadpool/RejectedExecutionException.java
  26. +0 −34 src/main/java/com/twitter/actors/threadpool/RejectedExecutionHandler.java
  27. +0 −24 src/main/java/com/twitter/actors/threadpool/RunnableFuture.java
  28. +0 −41 src/main/java/com/twitter/actors/threadpool/ThreadFactory.java
  29. +0 −1,968 src/main/java/com/twitter/actors/threadpool/ThreadPoolExecutor.java
  30. +0 −38 src/main/java/com/twitter/actors/threadpool/TimeoutException.java
  31. +0 −85 src/main/java/com/twitter/actors/threadpool/helpers/FIFOWaitQueue.java
  32. +0 −29 src/main/java/com/twitter/actors/threadpool/helpers/NanoTimer.java
  33. +0 −66 src/main/java/com/twitter/actors/threadpool/helpers/ThreadHelpers.java
  34. +0 −344 src/main/java/com/twitter/actors/threadpool/helpers/Utils.java
  35. +0 −147 src/main/java/com/twitter/actors/threadpool/helpers/WaitQueue.java
  36. +0 −191 src/main/java/com/twitter/actors/threadpool/locks/CondVar.java
  37. +0 −435 src/main/java/com/twitter/actors/threadpool/locks/Condition.java
  38. +0 −147 src/main/java/com/twitter/actors/threadpool/locks/FIFOCondVar.java
  39. +0 −328 src/main/java/com/twitter/actors/threadpool/locks/Lock.java
  40. +0 −104 src/main/java/com/twitter/actors/threadpool/locks/ReadWriteLock.java
  41. +0 −960 src/main/java/com/twitter/actors/threadpool/locks/ReentrantLock.java
  42. +0 −1,340 src/main/java/com/twitter/actors/threadpool/locks/ReentrantReadWriteLock.java
  43. +7 −22 src/main/scala/com/twitter/actors/FJTaskScheduler2.scala
  44. +2 −1 src/main/scala/com/twitter/actors/Scheduler.scala
View
@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/scala"/>
+ <classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="ch.epfl.lamp.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/JVM 1.6.0"/>
+ <classpathentry kind="lib" path="project/boot/scala-2.7.7/lib/scala-library.jar"/>
+ <classpathentry kind="lib" path="project/boot/scala-2.7.7/lib/scala-compiler.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -817,13 +817,9 @@ public void run() {
// move all local tasks to group-wide entry queue
for (int i = 0; i < deq.length; ++i) {
synchronized(group) {
- try {
- FJTask task = (FJTask)deq[i].take();
- if (task != null)
- group.getEntryQueue().put(task);
- } catch (InterruptedException ie) {
- System.err.println("Suspend: when transferring task to entryQueue: "+ie);
- }
+ FJTask task = (FJTask)deq[i].take();
+ if (task != null)
+ group.getEntryQueue().add(task);
}
}
}
@@ -18,6 +18,8 @@
package com.twitter.actors;
+import java.util.concurrent.*;
+
/**
* A stripped down analog of a ThreadGroup used for
* establishing and managing FJTaskRunner threads.
@@ -125,9 +127,9 @@
/*protected*/ /*final*/ FJTaskRunner[] threads;
/** Group-wide queue for tasks entered via execute() **/
- /*protected*/ final LinkedQueue entryQueue = new LinkedQueue();
+ /*protected*/ final BlockingQueue entryQueue = new LinkedBlockingQueue();
- public LinkedQueue getEntryQueue() {
+ public BlockingQueue getEntryQueue() {
return entryQueue;
}
@@ -161,7 +163,7 @@ public LinkedQueue getEntryQueue() {
/* -------- Suspending -------- */
- LinkedQueue snapshot() throws InterruptedException {
+ BlockingQueue snapshot() throws InterruptedException {
synchronized (this) {
for (int i = 0; i < threads.length; ++i) {
FJTaskRunner t = threads[i];
@@ -531,14 +533,7 @@ public void stats() {
**/
public FJTask pollEntryQueue() {
- try {
- FJTask t = (FJTask)(entryQueue.poll(0));
- return t;
- }
- catch(InterruptedException ex) { // ignore interrupts
- Thread.currentThread().interrupt();
- return null;
- }
+ return (FJTask)(entryQueue.poll());
}
@@ -1,6 +1,8 @@
package com.twitter.actors;
+import java.util.concurrent.BlockingQueue;
+
/**
* IFJTaskRunnerGroup
*
@@ -14,5 +16,5 @@
public void setActive(FJTaskRunner t);
public void checkActive(FJTaskRunner t, long scans);
public void setInactive(FJTaskRunner t);
- public LinkedQueue getEntryQueue();
+ public BlockingQueue getEntryQueue();
}
@@ -1,25 +0,0 @@
-/*
- File: LinkedNode.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 11Jun1998 dl Create public version
- 25may2000 dl Change class access to public
- 26nov2001 dl Added no-arg constructor, all public access.
-*/
-
-package com.twitter.actors;
-
-/** A standard linked list node used in various queue classes **/
-public class LinkedNode {
- public Object value;
- public LinkedNode next;
- public LinkedNode() {}
- public LinkedNode(Object x) { value = x; }
- public LinkedNode(Object x, LinkedNode n) { value = x; next = n; }
-}
@@ -1,185 +0,0 @@
-/*
- File: LinkedQueue.java
-
- Originally written by Doug Lea and released into the public domain.
- This may be used for any purposes whatsoever without acknowledgment.
- Thanks for the assistance and support of Sun Microsystems Labs,
- and everyone contributing, testing, and using this code.
-
- History:
- Date Who What
- 11Jun1998 dl Create public version
- 25aug1998 dl added peek
- 10dec1998 dl added isEmpty
- 10oct1999 dl lock on node object to ensure visibility
-*/
-
-package com.twitter.actors;
-
-/**
- * A linked list based channel implementation.
- * The algorithm avoids contention between puts
- * and takes when the queue is not empty.
- * Normally a put and a take can proceed simultaneously.
- * (Although it does not allow multiple concurrent puts or takes.)
- * This class tends to perform more efficently than
- * other Channel implementations in producer/consumer
- * applications.
- * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]
- **/
-
-public class LinkedQueue {
-
-
- /**
- * Dummy header node of list. The first actual node, if it exists, is always
- * at head_.next. After each take, the old first node becomes the head.
- **/
- protected LinkedNode head_;
-
- /**
- * Helper monitor for managing access to last node.
- **/
- protected final Object putLock_ = new Object();
-
- /**
- * The last node of list. Put() appends to list, so modifies last_
- **/
- protected LinkedNode last_;
-
- /**
- * The number of threads waiting for a take.
- * Notifications are provided in put only if greater than zero.
- * The bookkeeping is worth it here since in reasonably balanced
- * usages, the notifications will hardly ever be necessary, so
- * the call overhead to notify can be eliminated.
- **/
- protected int waitingForTake_ = 0;
-
- public LinkedQueue() {
- head_ = new LinkedNode(null);
- last_ = head_;
- }
-
- /** Main mechanics for put/offer **/
- protected void insert(Object x) {
- synchronized(putLock_) {
- LinkedNode p = new LinkedNode(x);
- synchronized(last_) {
- last_.next = p;
- last_ = p;
- }
- if (waitingForTake_ > 0)
- putLock_.notify();
- }
- }
-
- /** Main mechanics for take/poll **/
- protected synchronized Object extract() {
- synchronized(head_) {
- Object x = null;
- LinkedNode first = head_.next;
- if (first != null) {
- x = first.value;
- first.value = null;
- head_ = first;
- }
- return x;
- }
- }
-
-
- public void put(Object x) throws InterruptedException {
- if (x == null) throw new IllegalArgumentException();
- if (Thread.interrupted()) throw new InterruptedException();
- insert(x);
- }
-
- public boolean offer(Object x, long msecs) throws InterruptedException {
- if (x == null) throw new IllegalArgumentException();
- if (Thread.interrupted()) throw new InterruptedException();
- insert(x);
- return true;
- }
-
- public Object take() throws InterruptedException {
- if (Thread.interrupted()) throw new InterruptedException();
- // try to extract. If fail, then enter wait-based retry loop
- Object x = extract();
- if (x != null)
- return x;
- else {
- synchronized(putLock_) {
- try {
- ++waitingForTake_;
- for (;;) {
- x = extract();
- if (x != null) {
- --waitingForTake_;
- return x;
- }
- else {
- putLock_.wait();
- }
- }
- }
- catch(InterruptedException ex) {
- --waitingForTake_;
- putLock_.notify();
- throw ex;
- }
- }
- }
- }
-
- public Object peek() {
- synchronized(head_) {
- LinkedNode first = head_.next;
- if (first != null)
- return first.value;
- else
- return null;
- }
- }
-
-
- public boolean isEmpty() {
- synchronized(head_) {
- return head_.next == null;
- }
- }
-
- public Object poll(long msecs) throws InterruptedException {
- if (Thread.interrupted()) throw new InterruptedException();
- Object x = extract();
- if (x != null)
- return x;
- else {
- synchronized(putLock_) {
- try {
- long waitTime = msecs;
- long start = (msecs <= 0)? 0 : System.currentTimeMillis();
- ++waitingForTake_;
- for (;;) {
- x = extract();
- if (x != null || waitTime <= 0) {
- --waitingForTake_;
- return x;
- }
- else {
- putLock_.wait(waitTime);
- waitTime = msecs - (System.currentTimeMillis() - start);
- }
- }
- }
- catch(InterruptedException ex) {
- --waitingForTake_;
- putLock_.notify();
- throw ex;
- }
- }
- }
- }
-}
-
-
@@ -1,32 +0,0 @@
-/*
- * Written by Dawid Kurzyniec, based on public domain code written by Doug Lea
- * and publictly available documentation, and released to the public domain, as
- * explained at http://creativecommons.org/licenses/publicdomain
- */
-
-package com.twitter.actors.threadpool;
-import com.twitter.actors.threadpool.helpers.Utils;
-
-/**
- * Overrides toArray() and toArray(Object[]) in AbstractCollection to provide
- * implementations valid for concurrent collections.
- *
- * @author Doug Lea
- * @author Dawid Kurzyniec
- */
-public abstract class AbstractCollection extends java.util.AbstractCollection {
-
- /**
- * Sole constructor. (For invocation by subclass constructors, typically
- * implicit.)
- */
- protected AbstractCollection() { super(); }
-
- public Object[] toArray() {
- return Utils.collectionToArray(this);
- }
-
- public Object[] toArray(Object[] a) {
- return Utils.collectionToArray(this, a);
- }
-}
Oops, something went wrong.

0 comments on commit 3ee5264

Please sign in to comment.