From fd7c4d98ebe87b2db91cd404daa289213dd4451e Mon Sep 17 00:00:00 2001 From: mdb Date: Wed, 12 Jul 2006 23:22:52 +0000 Subject: [PATCH] Type safety, formatting. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1874 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/net/HttpPostUtil.java | 7 ++-- src/java/com/samskivert/util/HashIntMap.java | 2 +- .../com/samskivert/util/ServiceWaiter.java | 32 ++++++++++++------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/java/com/samskivert/net/HttpPostUtil.java b/src/java/com/samskivert/net/HttpPostUtil.java index 08bc631e..faf90548 100644 --- a/src/java/com/samskivert/net/HttpPostUtil.java +++ b/src/java/com/samskivert/net/HttpPostUtil.java @@ -32,7 +32,7 @@ public class HttpPostUtil int timeout) throws IOException, ServiceWaiter.TimeoutException { - final ServiceWaiter waiter = new ServiceWaiter( + final ServiceWaiter waiter = new ServiceWaiter( (timeout < 0) ? ServiceWaiter.NO_TIMEOUT : timeout); Thread tt = new Thread() { public void run () { @@ -71,10 +71,9 @@ public class HttpPostUtil tt.start(); if (waiter.waitForResponse()) { - return (String) waiter.getArgument(); - + return waiter.getArgument(); } else { - throw (IOException) waiter.getArgument(); + throw (IOException) waiter.getError(); } } } diff --git a/src/java/com/samskivert/util/HashIntMap.java b/src/java/com/samskivert/util/HashIntMap.java index e2cc2030..58ac0659 100644 --- a/src/java/com/samskivert/util/HashIntMap.java +++ b/src/java/com/samskivert/util/HashIntMap.java @@ -307,7 +307,7 @@ public class HashIntMap extends AbstractMap } // documentation inherited - public Set> intEntrySet() + public Set> intEntrySet () { return new AbstractSet>() { public int size () { diff --git a/src/java/com/samskivert/util/ServiceWaiter.java b/src/java/com/samskivert/util/ServiceWaiter.java index ffa3e81f..21aa8ef0 100644 --- a/src/java/com/samskivert/util/ServiceWaiter.java +++ b/src/java/com/samskivert/util/ServiceWaiter.java @@ -28,8 +28,8 @@ import com.samskivert.Log; * instruct the Java compiler to give public scope to an anonymous inner * class rather than default scope. Sigh. */ -public class ServiceWaiter - implements ResultListener +public class ServiceWaiter + implements ResultListener { /** Timeout to specify when you don't want a timeout. Use at your own * risk. */ @@ -83,7 +83,7 @@ public class ServiceWaiter * Marks the request as successful and posts the supplied response * argument for perusal by the caller. */ - public synchronized void postSuccess (Object arg) + public synchronized void postSuccess (T arg) { _success = 1; _argument = arg; @@ -91,13 +91,12 @@ public class ServiceWaiter } /** - * Marks the request as failed and posts the supplied response - * argument for perusal by the caller. + * Marks the request as failed. */ - public synchronized void postFailure (Object arg) + public synchronized void postFailure (Exception error) { _success = -1; - _argument = arg; + _error = error; notify(); } @@ -105,11 +104,19 @@ public class ServiceWaiter * Returns the argument posted by the waiter when the response * arrived. */ - public Object getArgument () + public T getArgument () { return _argument; } + /** + * Returns the exception posted in the event of failure. + */ + public Exception getError () + { + return _error; + } + /** * Blocks waiting for the response. * @@ -148,7 +155,7 @@ public class ServiceWaiter } // documentation inherited from interface ResultListener - public void requestCompleted (Object result) + public void requestCompleted (T result) { postSuccess(result); } @@ -156,7 +163,7 @@ public class ServiceWaiter // documentation inherited from interface ResultListener public void requestFailed (Exception cause) { - postFailure((cause != null) ? cause.getMessage() : null); + postFailure(cause); } /** Whether or not the response succeeded; positive for success, @@ -165,7 +172,10 @@ public class ServiceWaiter protected int _success = 0; /** The argument posted by the waiter upon receipt of the response. */ - protected Object _argument; + protected T _argument; + + /** The exception posted by the waiter upon failure. */ + protected Exception _error; /** How many seconds to wait before giving up the ghost. */ protected int _timeout;