Type safety, formatting.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@1874 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -32,7 +32,7 @@ public class HttpPostUtil
|
||||
int timeout)
|
||||
throws IOException, ServiceWaiter.TimeoutException
|
||||
{
|
||||
final ServiceWaiter waiter = new ServiceWaiter(
|
||||
final ServiceWaiter<String> waiter = new ServiceWaiter<String>(
|
||||
(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ public class HashIntMap<V> extends AbstractMap<Integer,V>
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public Set<IntEntry<V>> intEntrySet()
|
||||
public Set<IntEntry<V>> intEntrySet ()
|
||||
{
|
||||
return new AbstractSet<IntEntry<V>>() {
|
||||
public int size () {
|
||||
|
||||
@@ -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<T>
|
||||
implements ResultListener<T>
|
||||
{
|
||||
/** 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;
|
||||
|
||||
Reference in New Issue
Block a user