Skip to content

Commit

Permalink
extension methods javafication
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Nov 29, 2013
1 parent fb89fc4 commit 4c76648
Show file tree
Hide file tree
Showing 23 changed files with 1,977 additions and 1,591 deletions.
13 changes: 13 additions & 0 deletions core/src/main/groovyx/gaelyk/RetryingFuture.groovy
Expand Up @@ -45,6 +45,19 @@ class RetryingFuture<R> implements Future<R> {
}
new RetryingFuture(retries, factory)
}

/**
* Creates new retry future which retries particular times before failing
* @param retries number of retries
* @param factory closure to construct the future
* @return future which retries particular times before failing
*/
static <R> Future<R> retry(int retries, Callable<Future<R>> factory){
if(retries <= 0){
return factory()
}
new RetryingFuture(retries, factory)
}

@Override public boolean cancel(boolean mayInterruptIfRunning) {

Expand Down
Expand Up @@ -13,19 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package groovyx.gaelyk.extensions
package groovyx.gaelyk.extensions;

import groovy.transform.CompileStatic
import com.google.appengine.api.LifecycleManager
import com.google.appengine.api.backends.BackendService
import com.google.appengine.api.ThreadManager
import org.codehaus.groovy.runtime.DefaultGroovyMethods;

import groovy.lang.Closure;
import groovy.lang.DelegatesTo;

import com.google.appengine.api.LifecycleManager;
import com.google.appengine.api.ThreadManager;
import com.google.appengine.api.backends.BackendService;

/**
* Backend service extension methods
* Backend service extension methods.
*
* @author Guillaume Laforge
* @author Guillaume Laforge, Vladmir Orany
*/
class BackendExtensions {
public class BackendExtensions {

/**
* Shortcut to use closures as shutdown hooks.
Expand All @@ -36,19 +40,18 @@ class BackendExtensions {
* @param manager the lifecycle manager
* @param c the closure as shutdown hook
*/
static void shutdownHook(LifecycleManager manager, @DelegatesTo(LifecycleManager.ShutdownHook) Closure c) {
manager.setShutdownHook(c as LifecycleManager.ShutdownHook)
public static void shutdownHook(LifecycleManager manager, @DelegatesTo(LifecycleManager.ShutdownHook.class) Closure<?> c) {
manager.setShutdownHook(DefaultGroovyMethods.asType(c, LifecycleManager.ShutdownHook.class));
}

/**
* Runs code in the background thread.
*
* @param the code supposed to run in background thread
*/
@CompileStatic
static Thread run(BackendService backends, Runnable code){
public static Thread run(BackendService backends, Runnable code){
Thread thread = ThreadManager.createBackgroundThread(code);
thread.start()
thread
thread.start();
return thread;
}
}

0 comments on commit 4c76648

Please sign in to comment.