当前位置: 首页>>代码示例>>Java>>正文


Java OnSuccess类代码示例

本文整理汇总了Java中akka.dispatch.OnSuccess的典型用法代码示例。如果您正苦于以下问题:Java OnSuccess类的具体用法?Java OnSuccess怎么用?Java OnSuccess使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


OnSuccess类属于akka.dispatch包,在下文中一共展示了OnSuccess类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onReceive

import akka.dispatch.OnSuccess; //导入依赖的package包/类
@Override
public void onReceive(Object message) throws Exception {
    if (message instanceof String) {
        Future<Event> f = future(() -> {
            Event event = new Event((String) message);
            eventMap.put(event.getUuId(), event);
            return event;
        }, getContext().system().dispatcher());
        f.onSuccess(new OnSuccess<Event>() {
            @Override public final void onSuccess(Event t) {
                log.debug("Processed String message: {}", t);
            }
        }, getContext().system().dispatcher());
    } else
        unhandled(message);
}
 
开发者ID:badalgeek,项目名称:EventStreamAnalytics,代码行数:17,代码来源:HazelcastEventActor.java

示例2: onReceive

import akka.dispatch.OnSuccess; //导入依赖的package包/类
@Override
public void onReceive(Object message) throws Exception {
    if (message instanceof String) {
        Future<Event> f = future(() -> {
            Event event = new Event((String) message);
            eventCollection.insertOne(event.getDbObject());
            return event;
        }, getContext().system().dispatcher());
        f.onSuccess(new OnSuccess<Event>() {
            @Override public final void onSuccess(Event t) {
                log.debug("Processed String message: {}", message);
            }
        }, getContext().system().dispatcher());
    }
    else
        unhandled(message);
}
 
开发者ID:badalgeek,项目名称:EventStreamAnalytics,代码行数:18,代码来源:MongoDBEventActor.java

示例3: handleMessage

import akka.dispatch.OnSuccess; //导入依赖的package包/类
protected <T> void handleMessage(final Future<T> value, final ActorRef sender, final ActorRef self) {
    final ExecutionContext ec = getContext().system().dispatcher();
    value.onSuccess(new OnSuccess<T>() {
        @Override
        public void onSuccess(T result) throws Throwable {
            sender.tell(new ExecutionResultMessage(result), self); // prevent message is null error
        }
    }, ec);
    value.onFailure(new OnFailure() {
        @Override
        public void onFailure(Throwable failure) throws Throwable {
            log.debug("Future failure: [{}]", failure.getMessage());
            sender.tell(new akka.actor.Status.Failure(failure), self);
        }
    }, ec);
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:17,代码来源:DroneActor.java

示例4: initInternal

import akka.dispatch.OnSuccess; //导入依赖的package包/类
private void initInternal(final ActorRef sender, final ActorRef self) {
    if (!loading && !loaded) {
        loading = true;
        final ExecutionContext ec = getContext().system().dispatcher();

        log.debug("Attempting init.");

        Promise<Void> p = Futures.promise();
        p.future().onFailure(new OnFailure() {
            @Override
            public void onFailure(Throwable failure) throws Throwable {
                loading = false;
                loaded = false;
            }
        }, ec);
        p.future().onSuccess(new OnSuccess<Void>() {
            @Override
            public void onSuccess(Void result) throws Throwable {
                loaded = true;
                loading = false;
            }
        }, ec);
        handleMessage(p.future(), sender, self);
        init(p);
    }
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:27,代码来源:DroneActor.java

示例5: onJob

import akka.dispatch.OnSuccess; //导入依赖的package包/类
private void onJob(final Master.Job job) {
    Cancellable abortLoop = getContext().system().scheduler().schedule(Duration.Zero(), Duration.create(60, TimeUnit.SECONDS),
            () -> {
                runCancelJob(job);
            }, getContext().system().dispatcher());
    ActorRef sender = getSender();
    ExecutorService pool = Executors.newFixedThreadPool(1);
    ExecutionContextExecutorService ctx = ExecutionContexts.fromExecutorService(pool);
    Future<Object> f = future(() -> runJob(job), ctx);
    f.onSuccess(new OnSuccess<Object>() {
        @Override
        public void onSuccess(Object result) throws Throwable {
            log.info("Notify Worker job status {}", result);
            sender.tell(result, getSelf());
            abortLoop.cancel();
        }
    }, ctx);
    f.onFailure(new OnFailure() {
        @Override
        public void onFailure(Throwable throwable) throws Throwable {
            log.error(throwable.toString());
            abortLoop.cancel();
            sender.tell(new Worker.WorkFailed(null), getSelf());
            unhandled(job);
        }
    }, ctx);
}
 
开发者ID:Abiy,项目名称:distGatling,代码行数:28,代码来源:JarExecutor.java

示例6: onJob

import akka.dispatch.OnSuccess; //导入依赖的package包/类
private void onJob(final Master.Job job) {
    Cancellable abortLoop = getContext().system().scheduler().schedule(Duration.Zero(), Duration.create(60, TimeUnit.SECONDS),
            () -> {
                runCancelJob(job);
            }, getContext().system().dispatcher());
    ActorRef sender = getSender();
    ExecutorService pool = Executors.newFixedThreadPool(1);
    ExecutionContextExecutorService ctx = ExecutionContexts.fromExecutorService(pool);
    Future<Object> f = future(() -> runJob(job), ctx);
    f.onSuccess(new OnSuccess<Object>() {
        @Override
        public void onSuccess(Object result) throws Throwable {
            log.info("Notify Worker job status {}", result);
            sender.tell(result, getSelf());
            abortLoop.cancel();
        }
    }, ctx);
    f.onFailure(new OnFailure() {
        @Override
        public void onFailure(Throwable throwable) throws Throwable {
            log.error(throwable.toString());
            abortLoop.cancel();
            unhandled(job);
        }
    }, ctx);
    //getSender().tell(runJob(message));
}
 
开发者ID:Abiy,项目名称:distGatling,代码行数:28,代码来源:ScriptExecutor.java

示例7: onSuccess

import akka.dispatch.OnSuccess; //导入依赖的package包/类
protected static <T> OnSuccess<T> onSuccess(Consumer<T> consumer) {
    return new OnSuccess<T>() {

        @Override
        public void onSuccess(T t) throws Throwable {
            consumer.accept(t);
        }

    };
}
 
开发者ID:nosceon,项目名称:tenorite,代码行数:11,代码来源:AbstractActor.java

示例8: create

import akka.dispatch.OnSuccess; //导入依赖的package包/类
@Authentication({User.Role.ADMIN})
@BodyParser.Of(BodyParser.Json.class)
public static F.Promise<Result> create() {
    JsonNode body = request().body().asJson();
    JsonNode strippedBody;
    try {
        strippedBody = JsonHelper.removeRootElement(body, Drone.class, false);
    } catch(JsonHelper.InvalidJSONException ex) {
        play.Logger.debug(ex.getMessage(), ex);
        return F.Promise.pure(badRequest(ex.getMessage()));
    }
    Form<Drone> form = Form.form(Drone.class).bind(strippedBody);

    if (form.hasErrors())
        return F.Promise.pure(badRequest(form.errorsAsJson()));

    Drone drone = form.get();
    drone.save();
    Fleet.getFleet().createCommanderForDrone(drone).onSuccess(new OnSuccess<DroneCommander>(){
        @Override
        public void onSuccess(DroneCommander result) throws Throwable {
            drone.refresh();
            if(drone.getStatus() == Drone.Status.AVAILABLE){
                Scheduler.scheduleDrone(drone.getId());
            }
        }
    }, Akka.system().dispatcher());

    return F.Promise.pure(created(JsonHelper.createJsonNode(drone, getAllLinks(drone.getId()), Drone.class)));
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:31,代码来源:DroneController.java

示例9: main

import akka.dispatch.OnSuccess; //导入依赖的package包/类
public static void main(String args[]) throws Exception {

		BebopDriver driver = new BebopDriver();
		ArDrone2Driver ar2Driver = new ArDrone2Driver();
		final DroneCommander commander = new DroneCommander("192.168.1.175", driver);

		ActorSystem system = ActorSystem.create();

		ActorRef logger = system.actorOf(Props.create(Logger.class));

		commander.subscribeTopics(logger, new Class[]{FlyingStateChangedMessage.class, LocationChangedMessage.class});
		Future<Void> init = commander.init();
		init.onSuccess(new OnSuccess<Void>() {
			@Override
			public void onSuccess(Void result) throws Throwable {
				commander.takeOff();
				sleep(5000);
				commander.flip(FlipType.FRONT);
				sleep(5000);
				commander.land();
			}
		}, system.dispatcher());


		System.in.read();
		commander.land();
	}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:28,代码来源:ArDrone2Example.java

示例10: testSuccessfulAsk

import akka.dispatch.OnSuccess; //导入依赖的package包/类
@Test
public void testSuccessfulAsk() {
    ActorRef hello = system().actorOf(HelloAkka.props());
    final Timeout timeout = new Timeout(Duration.create(5, TimeUnit.SECONDS));
    final Future<Object> future = ask(hello, "Akka", timeout);
    future.onSuccess(new OnSuccess<Object>() {
        public void onSuccess(Object result) {
            // Do something!
            testActor().tell("Success", testActor());
        }
    }, system().dispatcher());
    expectMsgEquals("Success");
}
 
开发者ID:jwcarman,项目名称:akka-introduction,代码行数:14,代码来源:AskTest.java

示例11: startupSharedJournal

import akka.dispatch.OnSuccess; //导入依赖的package包/类
public static void startupSharedJournal(final ActorSystem system, boolean startStore, final ActorPath path) {
  // Start the shared journal one one node (don't crash this SPOF)
  // This will not be needed with a distributed journal
  if (startStore) {
    system.actorOf(Props.create(SharedLeveldbStore.class), "store");
  }
  // register the shared journal

  Timeout timeout = new Timeout(15, TimeUnit.SECONDS );

  ActorSelection actorSelection = system.actorSelection(path);
  Future<Object> f = Patterns.ask(actorSelection, new Identify(null), timeout);

  f.onSuccess(new OnSuccess<Object>() {

    @Override
    public void onSuccess(Object arg0) throws Throwable {
      if (arg0 instanceof ActorIdentity && ((ActorIdentity) arg0).getRef() != null) {
        SharedLeveldbJournal.setStore(((ActorIdentity) arg0).getRef(), system);
      } else {
        system.log().error("Lookup of shared journal at {} timed out", path);
        System.exit(-1);
      }

    }}, system.dispatcher());

  f.onFailure(new OnFailure() {
    public void onFailure(Throwable ex) throws Throwable {
      system.log().error(ex, "Lookup of shared journal at {} timed out", path);
    }}, system.dispatcher());
}
 
开发者ID:typesafehub,项目名称:activator-akka-distributed-workers-java,代码行数:32,代码来源:Main.java

示例12: dispatch

import akka.dispatch.OnSuccess; //导入依赖的package包/类
protected void dispatch(Object msg, ActorRef sender, ActorRef target) {
    boolean telling = false;
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Dispatch message class {} from actor {} to actor Ref {}.", msg.getClass().getCanonicalName(), sender.toString(), target.toString());
    }
    if (msg instanceof EventBusOriginMessage && ((EventBusOriginMessage) msg).initialSenderIsEventBus()) {
        EventBusOriginMessage eventBusOriginMessage = (EventBusOriginMessage) msg;
        Event event = eventBusOriginMessage.originalEvent();
        if (LOGGER.isDebugEnabled()) {
            Gson gson = new GsonBuilder().registerTypeAdapter(Event.class, new GsonEventSerializer()).setPrettyPrinting().create();
            LOGGER.debug("Dispatch message contain following event :\n{}", gson.toJson(event));
        }
        if (StringUtils.isNotBlank(event.getReplyTo()) &&
                StringUtils.isNotBlank(event.getCorrelationId())) {
            if (eventBusOriginMessage.requireToBeCompleteBeforeAckEventBus()) {
                Future<Object> future = Patterns.ask(target, msg, eventBusOriginMessage.timeout());
                Patterns.pipe(future, getContext().dispatcher()).to(sender);
                future.onSuccess(new OnSuccess<Object>() {
                    @Override
                    public void onSuccess(Object result) throws Throwable {
                        if (result instanceof EventReplyableMessage) {
                            self().forward(msg, getContext());  //  Allow to process reply in eventbus...
                        }
                    }
                }, getContext().dispatcher());
            } else {
                sender.tell(Futures.successful(Boolean.TRUE), self());
                target.tell(msg, self());
            }
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("TELL following message to actor {} : {}", target.toString(), msg);
            }
            telling = true;
        }
    }
    if (!telling) {
        target.forward(msg, getContext());
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("FORWARDING following message to actor {} : {}", target.toString(), msg);
        }
    }
}
 
开发者ID:kodokojo,项目名称:kodokojo,代码行数:43,代码来源:AbstractEndpointActor.java


注:本文中的akka.dispatch.OnSuccess类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。