play.libs.Akka Java Examples

The following examples show how to use play.libs.Akka. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RMBController.java    From NationStatesPlusPlus with MIT License 6 votes vote down vote up
private static Function<JsonNode, Promise<Result>> getAsyncResult(final Request request, final Response response, final String cacheLen) {
	return new Function<JsonNode, Promise<Result>>() {
		@Override
		public Promise<Result> apply(final JsonNode node) throws Throwable {
			return Promise.wrap(akka.dispatch.Futures.future((new Callable<Result>() {
				@Override
				public Result call() throws Exception {
					Result result = Utils.handleDefaultGetHeaders(request, response, String.valueOf(node.hashCode()), cacheLen);
					if (result != null) {
						return result;
					}
					return Results.ok(node).as("application/json");
				}
				
			}), Akka.system().dispatcher()));
		}
	};
}
 
Example #2
Source File: RMBController.java    From NationStatesPlusPlus with MIT License 6 votes vote down vote up
public Promise<Result> getPostRatings(final int rmbPost, final int rmbCache) throws SQLException {
	Promise<JsonNode> promise = Promise.wrap(akka.dispatch.Futures.future((new Callable<JsonNode>() {
		@Override
		public JsonNode call() throws Exception {
			Connection conn = null;
			try {
				conn = getConnection();
				JsonNode ratings = calculatePostRatings(conn, rmbPost);
				return ratings;
			} finally {
				DbUtils.closeQuietly(conn);
			}
		}
	}), Akka.system().dispatcher()));
	Promise<Result> result = promise.flatMap(getAsyncResult(request(), response(), rmbCache == -1 ? "10" : "86400"));
	return result;
}
 
Example #3
Source File: WebSocketService.java    From htwplus with MIT License 5 votes vote down vote up
/**
 * Invokes a new ActorRef instance of type WebSocketActor for an account ID.
 *
 * @param account Account
 * @param in WebSocket input stream
 * @param out WebSocket output stream
 */
public void invokeActor(final Account account, WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out) {
    if (this.getActorForAccount(account) != null) {
        return;
    }

    this.accountActor.put(account.id, Akka.system().actorOf(Props.create(WebSocketActor.class, account, in, out)));
}
 
Example #4
Source File: WebSocketService.java    From htwplus with MIT License 5 votes vote down vote up
/**
 * Stops an ActorRef for an account ID.
 *
 * @param account Account
 */
public void stopActor(Account account) {
    if (this.getActorForAccount(account) == null) {
        return;
    }

    ActorRef stoppingActorRef = this.accountActor.remove(account.id);
    Akka.system().stop(stoppingActorRef);
}
 
Example #5
Source File: AsyncController.java    From glowroot with Apache License 2.0 5 votes vote down vote up
public static Result message() {
    return Results.async(Akka.future(new Callable<Result>() {
        @Override
        public Result call() {
            try {
                SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            new CreateTraceEntry().traceEntryMarker();
            return Results.ok("Hi!");
        }
    }));
}
 
Example #6
Source File: AsyncController.java    From glowroot with Apache License 2.0 5 votes vote down vote up
public static Promise<Result> message() {
    final RedeemablePromise<Result> promise = RedeemablePromise.empty();
    Akka.system().scheduler().scheduleOnce(
            Duration.create(1, SECONDS),
            new Runnable() {
                public void run() {
                    new CreateTraceEntry().traceEntryMarker();
                    promise.success(Results.ok("Hi!"));
                }
            },
            ExecutionContexts.global());
    return promise;
}
 
Example #7
Source File: AsyncController.java    From glowroot with Apache License 2.0 5 votes vote down vote up
public static Result message() {
    return Results.async(Akka.future(new Callable<Result>() {
        @Override
        public Result call() {
            try {
                SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            new CreateTraceEntry().traceEntryMarker();
            return Results.ok("Hi!");
        }
    }));
}
 
Example #8
Source File: AsyncController.java    From glowroot with Apache License 2.0 5 votes vote down vote up
public static Result message() {
    return Results.async(Akka.future(new Callable<Result>() {
        @Override
        public Result call() {
            try {
                SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            new CreateTraceEntry().traceEntryMarker();
            return Results.ok("Hi!");
        }
    }));
}
 
Example #9
Source File: SitemapJob.java    From play-sitemap-module.edulify.com with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated Use com.edulify.modules.sitemap.SitemapModule instead.
 */
@Deprecated
public static void startSitemapGenerator() {
    Application application = Play.application();
    ActorSystem actorSystem = Akka.system();
    SitemapConfig sitemapConfig = application.injector().instanceOf(SitemapConfig.class);
    SitemapTask task = application.injector().instanceOf(SitemapTask.class);
    new SitemapJob(actorSystem, sitemapConfig, task).init();
}