Does anyone know of a java version of the python deferred library? Or maybe an idea on how to implement one?
EDIT: App engine has http://开发者_JS百科code.google.com/appengine/articles/deferred.html, but that library is only for python. I'm looking for something similar, but that works with GAE/Java
There has been work on a Java version of deferred, but nothing released. Searching the archives of the google-appengine-java group may reveal some user code that implements this. Bear in mind that it's not as neat as Python - you have to declare a serializable class that implements a particular interface, while in Python nearly any function or method will do fine.
The deferred library you link to relies on the Task Queue API in App Engine. The Task api is available in java. However, java as a language does not really let you pass functions/methods as arguments in the way that python does. Therefore, odds are that a java version of the deferred library will not look as nice as the python one.
If you were to make one (assuming someone doesn't point us to an existing one), you could define some interface like Deferrable
, and encapsulate the action you want to defer into an object that fulfills that interface. You would then have to implement a handler that could process these objects, and configure a Queue
to use that handler.
The tricky part here is making the Deferrable interface easy to use and syntactically sweet, given Java's relatively low level of dynamicness compared to python.
As a very limited implementation, you could say that a Deferrable is just a URL that needs to get run. Then your deferrable interface just needs one method that returns a string, and your handler can be very simple. OTOH, you have just pushed the complexity down to wherever you will implement that URL.
The SDK 1.4.3 has added Java support for Deferred Tasks.
Nah this is only for python , didnt reveal a way for implementing it
There's - JDeferred
JDeferred is a Java Deferred/Promise library similar to JQuery's Deferred Object.
// deferred object and promise
Deferred deferred = new DeferredObject();
Promise promise = deferred.promise();
promise.done(new DoneCallback() {
public void onDone(Object result) {
...
}
}).fail(new FailCallback() {
public void onFail(Object rejection) {
...
}
}).progress(new ProgressCallback() {
public void onProgress(Object progress) {
...
}
}).always(new AlwaysCallback() {
public void onAlways(State state, Object result, Object rejection) {
...
}
});
// with the reference to deferred object, you can then trigger actions/updates
deferred.resolve("done");
deferred.reject("oops");
deferred.progress("100%");
精彩评论