本文整理汇总了Java中play.libs.Akka类的典型用法代码示例。如果您正苦于以下问题:Java Akka类的具体用法?Java Akka怎么用?Java Akka使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Akka类属于play.libs包,在下文中一共展示了Akka类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: asyncResult
import play.libs.Akka; //导入依赖的package包/类
public static Result asyncResult() {
return async(Akka.future(new Callable<String>() {
@Override
public String call() {
return "success";
}
}).map(new Function<String, Result>() {
@Override
public Result apply(String a) {
response().setHeader("header_test", "header_val");
response().setCookie("cookie_test", "cookie_val");
session("session_test", "session_val");
flash("flash_test", "flash_val");
return ok(a);
};
}));
}
示例2: onStart
import play.libs.Akka; //导入依赖的package包/类
@Override
public void onStart(Application app) {
Logger.info("Application " + app.toString() + " has started");
ActorRef dispatcher = Akka.system().actorOf(new Props(Dispatcher.class));
Akka.system().scheduler().schedule(
Duration.create(200,TimeUnit.MICROSECONDS),
Duration.create(2,TimeUnit.SECONDS),
dispatcher,
"run",
Akka.system().dispatcher(),
null
);
}
示例3: onStart
import play.libs.Akka; //导入依赖的package包/类
@Override
public void onStart(Application app) {
Logger.info("Application startup...");
String tmpDir = Play.application().configuration().getString("w3act.cache.tmp.dir", defaultTmpDir);
// Set up the cache DB:
db = DBMaker.fileDB(new File(tmpDir, "ukwa-cache.mapdb"))
.closeOnJvmShutdown()
.checksumEnable()
.make();
// Initialise the W3ACT caches:
controllers.Application.w3act.init(db);
// Check for updates periodically
cacheChecker = Akka.system().scheduler().schedule(
Duration.create(0, TimeUnit.MILLISECONDS), //Initial delay 0 milliseconds
Duration.create(3, TimeUnit.HOURS),
new Runnable() {
@Override
public void run() {
controllers.Application.w3act.checkForUpdate();
}
},
Akka.system().dispatcher()
);
}
示例4: isReachable
import play.libs.Akka; //导入依赖的package包/类
public Future<PingResult> isReachable(Drone droneEntity) {
// If the entity has no commander, fail immediately
if(!hasCommander(droneEntity)){
return Futures.failed(new IllegalArgumentException("Drone is not initialized yet."));
}
// If the drone is simulated, pretend to succeed immediately
if(SimulatorDriver.SIMULATOR_TYPE.equals(droneEntity.getDroneType())){
return Futures.successful(PingResult.OK);
}
// Lazy load the ping class
if (pinger == null) {
pinger = Akka.system().actorOf(Props.create(ICMPPing.class), "pinger");
}
return Patterns.ask(pinger, new PingMessage(droneEntity.getAddress()),
new Timeout(Duration.create(ICMPPing.PING_TIMEOUT + 1000, TimeUnit.MILLISECONDS)))
.map(new Mapper<Object, PingResult>() {
public PingResult apply(Object s) {
return (PingResult) s;
}
}, Akka.system().dispatcher());
}
示例5: createCommanderForDrone
import play.libs.Akka; //导入依赖的package包/类
public Future<DroneCommander> createCommanderForDrone(Drone droneEntity) {
DroneDriver driver = getDriver(droneEntity.getDroneType());
if (driver == null)
return null;
// Create commander
ActorRef droneActor = Akka.system().actorOf(
Props.create(driver.getActorClass(),
() -> driver.createActor(droneEntity.getAddress())), String.format("droneactor-%d", droneEntity.getId()));
DroneCommander commander = new DroneCommander(droneActor);
Future<Void> f = commander.init();
f.onFailure(new OnFailure() {
@Override
public void onFailure(Throwable failure) throws Throwable {
commander.stop(); // Stop commander when init fails
}
}, Akka.system().dispatcher());
return f.map(new Mapper<Void, DroneCommander>() {
public DroneCommander apply(Void s) {
registerFleetBus(commander);
drones.put(droneEntity.getId(), commander);
return commander;
}
}, Akka.system().dispatcher());
}
示例6: onStart
import play.libs.Akka; //导入依赖的package包/类
@Override
public void onStart(Application app) {
super.onStart(app);
//Using Play default ActorSystem
ActorRef testActor = Akka.system().actorOf(Props.create(actors.HelloWorldActor.class), "testActor");
//Using your own ActorSystem
//ActorSystem system = ActorSystem.create("ActorSystem");
//ActorRef testActor = system.actorOf(Props.create(actors.HelloWorldActor.class), "testActor");
Akka.system().scheduler().schedule(
Duration.create(0, TimeUnit.MILLISECONDS),
Duration.create(5, TimeUnit.SECONDS),
testActor,
"Hello World",
Akka.system().dispatcher(),
null
);
}
示例7: refreshAllScoreboard
import play.libs.Akka; //导入依赖的package包/类
@Transactional
public Result refreshAllScoreboard(long contestId) throws ContestNotFoundException {
Contest contest = contestService.findContestById(contestId);
if (contest.isLocked() || !contest.containsModule(ContestModules.SCOREBOARD) || !isAllowedToSuperviseScoreboard(contest)) {
return ContestControllerUtils.getInstance().tryEnteringContest(contest, IdentityUtils.getUserJid());
}
if (ScoreboardUpdaterDispatcher.updaterExists(contest.getJid())) {
flashInfo(Messages.get("scoreboard.isUpdating"));
return redirect(routes.ContestScoreboardController.viewOfficialScoreboard(contest.getId()));
}
ScoreboardUpdaterDispatcher.updateScoreboard(Akka.system().scheduler(), Akka.system().dispatcher(), contest, contestService, contestScoreboardService, contestContestantService, programmingSubmissionService);
flashInfo(Messages.get("scoreboard.updateRequestAccepted"));
UrielControllerUtils.getInstance().addActivityLog(UrielActivityKeys.REFRESH.construct(CONTEST, contest.getJid(), contest.getName(), SCOREBOARD, null, ""));
return redirect(routes.ContestScoreboardController.viewOfficialScoreboard(contest.getId()));
}
示例8: Start
import play.libs.Akka; //导入依赖的package包/类
public static void Start(Injector injector) {
Injector = injector;
if(!config.getBoolean(statsEnabled)) return;
if(!config.getBoolean(checksEnabled)) return;
long initialDelay = 60000;
long interval = 300000;
if(config.getString(initialDelayKey) != null) {
initialDelay = config.getMilliseconds(initialDelayKey);
}
if(config.getString(intervalKey) != null) {
interval = config.getMilliseconds(intervalKey);
}
ActorRef healthCheckActor = injector.getInstance(Key.get(ActorRef.class, Names.named("PlayGuiceStatsD-HealthCheckActor")));
Akka.system().scheduler().schedule(
Duration.apply(initialDelay, TimeUnit.MILLISECONDS),
Duration.apply(interval, TimeUnit.MILLISECONDS),
healthCheckActor,
new HealthCheckTimedRequest(),
Akka.system().dispatcher(),
null);
}
示例9: invokeActor
import play.libs.Akka; //导入依赖的package包/类
/**
* 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)));
}
示例10: sourceDataset
import play.libs.Akka; //导入依赖的package包/类
public static Promise<Result> sourceDataset(final String sourceDatasetId) {
final ActorSelection database = Akka.system().actorSelection (databaseRef);
return from(database)
.query(new GetMetadata(sourceDatasetId))
.execute(metadata -> {
if(metadata == null) {
return notFound();
}
String stylesheet = null;
Boolean noStyle = Boolean.parseBoolean(request().getQueryString("noStyle"));
if(!noStyle) {
stylesheet = datasetStylesheet;
}
return ok(setStylesheet(metadata.content(), stylesheet)).as("application/xml");
});
}
示例11: listStylesJson
import play.libs.Akka; //导入依赖的package包/类
public static Promise<Result> listStylesJson (final long page, final String styletype, final String query) {
final ActorSelection database = Akka.system().actorSelection (databaseRef);
return from (database)
.query (new ListStyles (page, query, styletype))
.execute (new Function<Page<Style>, Result> () {
@Override
public Result apply (final Page<Style> styles) throws Throwable {
final ObjectNode result = Json.newObject ();
result.put ("header", stylePagerHeader.render (styles, query).toString ());
result.put ("body", stylePagerBody.render (styles).toString ());
result.put ("footer", stylePagerFooter.render (styles).toString ());
return ok (result);
}
});
}
示例12: edit
import play.libs.Akka; //导入依赖的package包/类
public static Promise<Result> edit (final String styleId) {
Logger.debug ("edit Style: " + styleId);
final ActorSelection database = Akka.system().actorSelection (databaseRef);
return from (database)
.get (Style.class, styleId)
.query(new GetStyleParentLayers(styleId))
.query(new GetStyleParentGroups(styleId))
.execute (new Function3<Style, Page<Layer>, Page<LayerGroup>, Result> () {
@Override
public Result apply (final Style style, final Page<Layer> layers, final Page<LayerGroup> groups) throws Throwable {
final Form<StyleForm> styleForm = Form
.form (StyleForm.class)
.fill (new StyleForm (style));
Logger.debug ("Edit styleForm: " + styleForm);
Logger.debug ("Style is in layers: " + layers.values().toString());
return ok (form.render (styleForm, layers, groups, false, Optional.empty (), Optional.empty ()));
}
});
}
示例13: discardHarvestNotification
import play.libs.Akka; //导入依赖的package包/类
public static Promise<Result> discardHarvestNotification(final String sourceDatasetId, final String notificationId) {
final ActorSelection database = Akka.system().actorSelection (databaseRef);
return from(database)
.query(new DiscardHarvestNotification(sourceDatasetId, notificationId))
.execute(new Function<Boolean, Result>() {
@Override
public Result apply(Boolean succeeded) throws Throwable {
if(succeeded) {
return redirect(controllers.routes.DataSources.get(sourceDatasetId));
} else {
return internalServerError();
}
}
});
}
示例14: refreshDatasource
import play.libs.Akka; //导入依赖的package包/类
public static Promise<Result> refreshDatasource (final String datasourceId) {
final ActorSelection database = Akka.system().actorSelection (databaseRef);
return from (database)
.query (new HarvestDatasources (datasourceId))
.execute (new Function<Boolean, Result> () {
@Override
public Result apply (final Boolean result) throws Throwable {
final ObjectNode response = Json.newObject ();
response.put ("success", result);
if (result) {
return ok (response);
} else {
return internalServerError (response);
}
}
});
}
示例15: edit
import play.libs.Akka; //导入依赖的package包/类
public static Promise<Result> edit () {
Logger.debug ("edit Constants");
final ActorSelection database = Akka.system().actorSelection (databaseRef);
return from (database)
.list (Constant.class)
.execute (new Function<Page<Constant>, Result> () {
@Override
public Result apply (final Page<Constant> constant) throws Throwable {
final Form<ConstantsForm> constantsForm = Form
.form (ConstantsForm.class)
.fill (new ConstantsForm (constant));
Logger.debug ("Edit constantsForm: " + constantsForm);
return ok (form.render (constantsForm));
}
});
}