Permalink
Browse files

Cleaned up compiler warnings.

	modified:   bench/kilim/bench/Jetlang.java
	modified:   examples/kilim/examples/SimpleTask.java
	modified:   src/kilim/Mailbox.java
	modified:   src/kilim/NotPausable.java
	modified:   src/kilim/Pausable.java
	modified:   src/kilim/ReentrantLock.java
	modified:   src/kilim/RingQueue.java
	modified:   src/kilim/ShutdownException.java
	modified:   src/kilim/Task.java
	modified:   src/kilim/http/HttpRequestParser.java
	modified:   src/kilim/http/HttpRequestParser.rl
	modified:   test/kilim/test/Base.java
	modified:   test/kilim/test/TaskTestClassLoader.java
	modified:   test/kilim/test/TestRing.java
	modified:   test/kilim/test/TestTypeDesc.java
	modified:   test/kilim/test/ex/ExYieldConstants.java
  • Loading branch information...
1 parent c49a8ce commit bf6da331c4c9b3c1e3872e4299c1a3d73bbc29e4 @kilim committed Apr 26, 2010
View
@@ -4,7 +4,7 @@
<classpathentry kind="src" path="examples"/>
<classpathentry excluding="scala/" kind="src" path="bench"/>
<classpathentry kind="src" path="test"/>
- <classpathentry kind="lib" path="libs/asm-all-2.2.3.jar"/>
+ <classpathentry kind="lib" path="libs/asm-all-2.2.3.jar" sourcepath="/Users/s/sw/asm-2.2.3/src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="libs/junit.jar"/>
<classpathentry kind="output" path="classes"/>
@@ -13,7 +13,6 @@
* See http://code.google.com/p/jetlang/
*/
public class Jetlang extends Task {
- @SuppressWarnings("unchecked")
/* limit number of msgs in mailbox */
static Mailbox<Integer> mb = new Mailbox<Integer>(1000,1000);
@@ -27,11 +27,11 @@
static Mailbox<String> mb = new Mailbox<String>();
public static void main(String[] args) throws Exception {
- Task t = new SimpleTask().start();
+ new SimpleTask().start();
Thread.sleep(10);
mb.putnb("Hello ");
mb.putnb("World\n");
-// mb.putnb("done");
+ mb.putnb("done");
}
/**
@@ -17,7 +17,8 @@
*
* We use the term "block" to mean thread block, and "pause" to mean
* fiber pausing. The suffix "nb" on some methods (such as getnb())
- * stands for non-blocking.
+ * stands for non-blocking. Both put() and get() have blocking and
+ * non-blocking variants in the form of putb(), putnb
*/
public class Mailbox<T> implements PauseReason, EventPublisher {
@@ -99,8 +100,11 @@ public T get(EventSubscriber eo) {
* Non-blocking, nonpausing put.
* @param eo. If non-null, registers this observer and calls it with an SpaceAvailable event
* when there's space.
- * @return buffered message if there's one, or null
+ * @return buffered message if there's one, or null
+ * @see #putnb(Object)
+ * @see #putb(Object)
*/
+ @SuppressWarnings("unchecked")
public boolean put(T msg, EventSubscriber eo) {
boolean ret = true; // assume we will be able to enqueue
EventSubscriber subscriber;
@@ -173,7 +177,7 @@ public T get() throws Pausable{
/**
- * @return non-null message.
+ * @return non-null message, or null if timed out.
* @throws Pausable
*/
public T get(long timeoutMillis) throws Pausable {
@@ -208,6 +212,8 @@ public void run() {
* that has a message. It is possible that because of race conditions, an
* earlier mailbox in the list may also have received a message.
*/
+ // TODO: need timeout variant
+ @SuppressWarnings("unchecked")
public static int select(Mailbox... mboxes) throws Pausable {
while (true) {
for (int i = 0; i < mboxes.length; i++) {
@@ -252,17 +258,31 @@ public synchronized void removeMsgAvailableListener(EventSubscriber msgSub) {
}
}
+ /**
+ * Attempt to put a message, and return true if successful. The thread is not blocked, nor is the task
+ * paused under any circumstance.
+ */
public boolean putnb(T msg) {
return put(msg, null);
}
+ /**
+ * put a non-null message in the mailbox, and pause the calling task until the
+ * mailbox has space
+ */
+
public void put(T msg) throws Pausable {
Task t = Task.getCurrentTask();
while (!put(msg, t)) {
Task.pause(this);
}
}
+ /**
+ * put a non-null message in the mailbox, and pause the calling task for timeoutMillis
+ * if the mailbox is full.
+ */
+
public boolean put(T msg, int timeoutMillis) throws Pausable {
final Task t = Task.getCurrentTask();
long begin = System.currentTimeMillis();
@@ -310,6 +330,11 @@ public void blockingWait(final long timeoutMillis) {
}
}
+
+ /**
+ * put a non-null message in the mailbox, and block the calling thread for timeoutMillis
+ * if the mailbox is full.
+ */
public void putb(T msg, final long timeoutMillis) {
BlockingSubscriber evs = new BlockingSubscriber();
if (!put(msg, evs)) {
@@ -345,8 +370,7 @@ public T getb() {
/**
* retrieve a msg, and block the Java thread for the time given.
*
- * @param millis.
- * max wait time
+ * @param millis. max wait time
* @return null if timed out.
*/
public T getb(final long timeoutMillis) {
@@ -385,34 +409,34 @@ public boolean isValid(Task t) {
class EmptySet_MsgAvListener implements PauseReason, EventSubscriber {
final Task task;
- final Mailbox[] mbxs;
+ final Mailbox<?>[] mbxs;
- EmptySet_MsgAvListener(Task t, Mailbox[] mbs) {
+ EmptySet_MsgAvListener(Task t, Mailbox<?>[] mbs) {
task = t;
mbxs = mbs;
}
public boolean isValid(Task t) {
// The pauseReason is true (there is valid reason to continue
// pausing) if none of the mboxes have any elements
- for (Mailbox mb : mbxs) {
+ for (Mailbox<?> mb : mbxs) {
if (mb.hasMessage())
return false;
}
return true;
}
public void onEvent(EventPublisher ep, Event e) {
- for (Mailbox m : mbxs) {
+ for (Mailbox<?> m : mbxs) {
if (m != ep) {
- ((Mailbox)ep).removeMsgAvailableListener(this);
+ ((Mailbox<?>)ep).removeMsgAvailableListener(this);
}
}
task.resume();
}
public void cancel() {
- for (Mailbox mb : mbxs) {
+ for (Mailbox<?> mb : mbxs) {
mb.removeMsgAvailableListener(this);
}
}
@@ -1,5 +1,5 @@
package kilim;
public class NotPausable extends RuntimeException {
-
+ private static final long serialVersionUID = 1L;
}
@@ -7,6 +7,7 @@
package kilim;
public class Pausable extends Exception {
+ private static final long serialVersionUID = 1L;
private Pausable() {}
private Pausable(String msg) {}
}
@@ -3,6 +3,7 @@
import java.util.concurrent.TimeUnit;
public class ReentrantLock extends java.util.concurrent.locks.ReentrantLock {
+ private static final long serialVersionUID = 1L;
public ReentrantLock() {
super(false);
}
@@ -10,7 +10,8 @@
public RingQueue(int initialSize) {
this(initialSize, Integer.MAX_VALUE);
}
-
+
+ @SuppressWarnings("unchecked")
public RingQueue(int initialSize, int maxSize) {
elements = (T[]) new Object[initialSize];
size = 0;
@@ -38,6 +39,7 @@ public T get() {
return elem;
}
+ @SuppressWarnings("unchecked")
public boolean put(T elem) {
boolean ret = true;
if (elem == null) {
@@ -1,6 +1,7 @@
package kilim;
public class ShutdownException extends Exception {
+ private static final long serialVersionUID = 1L;
public ShutdownException() {
// TODO Auto-generated constructor stub
View
@@ -295,7 +295,7 @@ public static Object invoke(Method mthd, Object target, Object ... args)
// Given a method corresp. to "f(int)", return the equivalent woven method for "f(int, kilim.Fiber)"
private static Method getWovenMethod(Method m) {
- Class[] ptypes = m.getParameterTypes();
+ Class<?>[] ptypes = m.getParameterTypes();
if (!(ptypes.length > 0 && ptypes[ptypes.length-1].getName().equals("kilim.Fiber"))) {
// The last param is not "Fiber", so m is not woven.
// Get the woven method corresponding to m(..., Fiber)
@@ -304,7 +304,7 @@ private static Method getWovenMethod(Method m) {
for (Method wm: m.getDeclaringClass().getDeclaredMethods()) {
if (wm != m && wm.getName().equals(m.getName()) ) {
// names match. Check if the wm has the exact parameter types as m, plus a fiber.
- Class[] wptypes = wm.getParameterTypes();
+ Class<?>[] wptypes = wm.getParameterTypes();
if (wptypes.length != ptypes.length + 1 ||
!(wptypes[wptypes.length-1].getName().equals("kilim.Fiber"))) continue LOOP;
for (int i = 0; i < ptypes.length; i++) {
Oops, something went wrong.

0 comments on commit bf6da33

Please sign in to comment.