• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Promise类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: readyTransaction

import scala.concurrent.Promise; //导入依赖的package包/类
Future<ActorSelection> readyTransaction() {
    // avoid the creation of a promise and a TransactionOperation
    if (transactionContext != null) {
        return transactionContext.readyTransaction();
    }

    final Promise<ActorSelection> promise = Futures.promise();
    enqueueTransactionOperation(new TransactionOperation() {
        @Override
        public void invoke(TransactionContext newTransactionContext) {
            promise.completeWith(newTransactionContext.readyTransaction());
        }
    });

    return promise.future();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:TransactionContextWrapper.java


示例2: transform

import scala.concurrent.Promise; //导入依赖的package包/类
private <T> Future<T> transform(final Future<Object> future) {
    final Promise<T> promise = new scala.concurrent.impl.Promise.DefaultPromise<>();
    future.onComplete(new OnComplete<Object>() {
        @Override
        public void onComplete(final Throwable failure, final Object success) throws Throwable {
            if (success instanceof Throwable) {
                promise.failure((Throwable) success);
                return;
            }
            if (success == Void.TYPE) {
                promise.success(null);
                return;
            }
            promise.success((T) success);
        }
    }, context().dispatcher());
    return promise.future();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:19,代码来源:MockedSnapshotStore.java


示例3: init

import scala.concurrent.Promise; //导入依赖的package包/类
@Override
protected void init(Promise<Void> p) {
    log.info("[ARDRONE2 MODEL] Starting ARDrone 2.0 INIT");

    // Setup actor
    synchronized (lock) {
        if (initPromise == null) {
            initPromise = p;

            protocol = getContext().actorOf(Props.create(ArDrone2Protocol.class,
                    () -> new ArDrone2Protocol(new DroneConnectionDetails(ip, 5556, 5554), ArDrone2.this.self())));
        }
    }

    p.success(null);
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:17,代码来源:ArDrone2.java


示例4: init

import scala.concurrent.Promise; //导入依赖的package包/类
@Override
protected void init(Promise<Void> p) {
    // Discovery protocol + setup actor
    synchronized (lock) {
        if (connectionStatus == ConnectionStatus.NOT_INITIALIZED) {
            initPromise = p;

            connectionStatus = ConnectionStatus.CONNECTING;

            //TODO: dispose each time when udp bound is fixed
            protocol = getContext().actorOf(Props.create(ArDrone3.class,
                    () -> new ArDrone3(d2cPort, Bebop.this.self())), "protocol"); // Initialize listening already before broadcasting itself

            discoveryProtocol = getContext().actorOf(Props.create(ArDrone3Discovery.class,
                    () -> new ArDrone3Discovery(ip, Bebop.this.self(), d2cPort)), "discovery");
        }
    }
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:19,代码来源:Bebop.java


示例5: prematureExit

import scala.concurrent.Promise; //导入依赖的package包/类
private <T> boolean prematureExit(Promise<T> p) {
    if(connectionLost) {
        return true;
    }

    if(!initialized) {
        p.failure(new DroneException("Failed to send command. Not initialized yet."));
        return true;
    }

    if(crashed) {
        p.failure(new DroneException("Drone crashed, unable to execute commands"));
        return true;
    }
    return false;
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:17,代码来源:BepopSimulator.java


示例6: init

import scala.concurrent.Promise; //导入依赖的package包/类
@Override
protected void init(Promise<Void> p) {

    if(connectionLost) {
        return;
    }

    // Enable status updates
    eventBus.setPublishDisabled(false);

    // Schedule drones.simulation loop
    simulationTick = system.scheduler().schedule(
            simulationTimeStep,
            simulationTimeStep,
            self(),
            new StepSimulationMessage(simulationTimeStep),
            system.dispatcher(),
            self());

    initialized = true;
    p.success(null);
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:23,代码来源:BepopSimulator.java


示例7: takeOff

import scala.concurrent.Promise; //导入依赖的package包/类
@Override
protected void takeOff(Promise<Void> p) {

    if (prematureExit(p)) {
        return;
    }

    switch (state.getRawValue()) {
        case EMERGENCY:
            p.failure(new DroneException("Drone is in emergency status"));
            break;
        case LANDING:
            // Land drone before taking off again
            setFlyingState(FlyingState.LANDED);
            // Fall-through
        case LANDED:
            setFlyingState(FlyingState.TAKINGOFF);
            setAltitude(1);
            setFlyingState(FlyingState.HOVERING);
            // Fall-through
        default:
            p.success(null);
    }
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:25,代码来源:BepopSimulator.java


示例8: initInternal

import scala.concurrent.Promise; //导入依赖的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


示例9: moveToLocation

import scala.concurrent.Promise; //导入依赖的package包/类
@Override
final protected void moveToLocation(Promise<Void> v, double latitude, double longitude, double altitude) {
    synchronized (navigationLock) {
        if (navigationState.getRawValue() == NavigationState.IN_PROGRESS) {
            v.failure(new DroneException("Already navigating to " + getNavigator().getGoal() + ", abort this first."));
        } else if (navigationState.getRawValue() == NavigationState.UNAVAILABLE) {
            v.failure(new DroneException("Unable to navigate to goal"));
        } else if (!gpsFix.getRawValue()) {
            v.failure(new DroneException("No GPS fix yet."));
        } else {
            getNavigator().setCurrentLocation(location.getRawValue());
            getNavigator().setGoal(new Location(latitude, longitude, altitude));

            setNavigationState(NavigationState.IN_PROGRESS, NavigationStateReason.REQUESTED);
            v.success(null);
        }
    }
}
 
开发者ID:ugent-cros,项目名称:cros-core,代码行数:19,代码来源:NavigatedDroneActor.java


示例10: getDownload

import scala.concurrent.Promise; //导入依赖的package包/类
@Override
public F.Promise<Result> getDownload(String key, String name) {
    GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, key);
    ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides();
    responseHeaders.setContentDisposition("attachment; filename="+name);
    generatePresignedUrlRequest.setResponseHeaders(responseHeaders);

    AmazonS3 amazonS3 = new AmazonS3Client(credentials);

    try {
        URL url = amazonS3.generatePresignedUrl(generatePresignedUrlRequest);

        return F.Promise.pure(redirect(url.toString()));
    } catch (AmazonClientException ace) {
        logAmazonClientException (ace);
        return F.Promise.pure(internalServerError(error.render()));
    }
}
 
开发者ID:thunderbit,项目名称:thunderbit,代码行数:19,代码来源:AmazonS3Storage.java


示例11: setIfAlreadyComplete

import scala.concurrent.Promise; //导入依赖的package包/类
private void setIfAlreadyComplete(final String field, Future<?> source,
		final Promise<Object> wait, SetterFailure onFailure) {
	if (source.isCompleted() && !wait.isCompleted()){
		Object returnValue;
		try {
			returnValue = Await.result(source, Duration.create(0, TimeUnit.SECONDS));
			if (returnValue instanceof Null){
				BeanUtils.setProperty(getThis(), field, null);
			} else {
				BeanUtils.setProperty(getThis(), field, returnValue);
			}
		} catch (Exception exception) {
			handleCallbackException(field, onFailure, exception, wait);
		}
		try {
			wait.success(null);
		} catch (IllegalStateException e){}
	}
}
 
开发者ID:ranoble,项目名称:Megapode,代码行数:20,代码来源:WidgetBase.java


示例12: addIfAlreadyComplete

import scala.concurrent.Promise; //导入依赖的package包/类
private void addIfAlreadyComplete(final String field, Future<?> source,
		final Promise<Object> wait, SetterFailure onFailure) {
	if (source.isCompleted() && !wait.isCompleted()){
		Object returnValue;
		try {
			returnValue = Await.result(source, Duration.create(0, TimeUnit.SECONDS));
			if (!(returnValue instanceof Null)){
				((List)PropertyUtils.getProperty(getThis(), field)).add(returnValue);
			}
		} catch (Exception exception) {
			handleCallbackException(field, onFailure, exception, wait);
		}
		
		try {
			wait.success(null);
		} catch (IllegalStateException e){}
	}
}
 
开发者ID:ranoble,项目名称:Megapode,代码行数:19,代码来源:WidgetBase.java


示例13: add

import scala.concurrent.Promise; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public void add(final String field, Future<?> source, final Promise<Object> waiter, final SetterFailure onFailure){
	source.onComplete(new OnComplete(){
		@Override
		public void onComplete(Throwable exception, Object returnValue)
				throws Throwable {
			if (exception == null){
				try {
					if (!(returnValue instanceof Null)){
						((List)PropertyUtils.getProperty(getThis(), field)).add(returnValue);
					}
				} catch (IllegalAccessException | InvocationTargetException e){
					getLogger().error(exception, 
							String.format("Exception in add callback on widget / page [%s] field [%s]", 
									getThis().getClass().getCanonicalName(), field));
					exception = e;
				}
			} 
			if (exception != null){
				handleCallbackException(field, onFailure, exception, waiter);
			} else {
				waiter.success(null);
			}
		}	
	}, this.getActorContext().dispatcher());
}
 
开发者ID:ranoble,项目名称:Megapode,代码行数:27,代码来源:WidgetBase.java


示例14: createRoute

import scala.concurrent.Promise; //导入依赖的package包/类
private Route createRoute(ActorRef streamActor) {
    return route(
            path(segment("services").slash(longSegment()), id ->
                    get(() -> {
                        Promise<HttpResponse> promise = Futures.promise();
                        streamActor.tell(new Pair(id, promise), ActorRef.noSender());
                        return completeWithFuture(FutureConverters.toJava(promise.future()));
                    })));
}
 
开发者ID:henrikengstrom,项目名称:ujug2017,代码行数:10,代码来源:StreamMain.java


示例15: mapPromise

import scala.concurrent.Promise; //导入依赖的package包/类
@Benchmark
public String mapPromise() throws Exception {
  Promise<String> p = Promise.<String>apply();
  Future<String> f = p.future().map(mapF, ec);
  p.success(string);
  return Await.result(f, inf);
}
 
开发者ID:traneio,项目名称:future,代码行数:8,代码来源:ScalaFutureBenchmark.java


示例16: mapPromiseN

import scala.concurrent.Promise; //导入依赖的package包/类
@Benchmark
public String mapPromiseN() throws Exception {
  Promise<String> p = Promise.<String>apply();
  Future<String> f = p.future();
  for (int i = 0; i < N.n; i++)
    f = f.map(mapF, ec);
  p.success(string);
  return Await.result(f, inf);
}
 
开发者ID:traneio,项目名称:future,代码行数:10,代码来源:ScalaFutureBenchmark.java


示例17: flatMapPromise

import scala.concurrent.Promise; //导入依赖的package包/类
@Benchmark
public String flatMapPromise() throws Exception {
  Promise<String> p = Promise.<String>apply();
  Future<String> f = p.future().flatMap(flatMapF, ec);
  p.success(string);
  return Await.result(f, inf);
}
 
开发者ID:traneio,项目名称:future,代码行数:8,代码来源:ScalaFutureBenchmark.java


示例18: flatMapPromiseN

import scala.concurrent.Promise; //导入依赖的package包/类
@Benchmark
public String flatMapPromiseN() throws Exception {
  Promise<String> p = Promise.<String>apply();
  Future<String> f = p.future();
  for (int i = 0; i < N.n; i++)
    f = f.flatMap(flatMapF, ec);
  p.success(string);
  return Await.result(f, inf);
}
 
开发者ID:traneio,项目名称:future,代码行数:10,代码来源:ScalaFutureBenchmark.java


示例19: ensurePromise

import scala.concurrent.Promise; //导入依赖的package包/类
@Benchmark
public Void ensurePromise() throws Exception {
  Promise<Void> p = Promise.<Void>apply();
  Future<Void> f = p.future().transform(ensureF, ec);
  p.success(null);
  return Await.result(f, inf);
}
 
开发者ID:traneio,项目名称:future,代码行数:8,代码来源:ScalaFutureBenchmark.java


示例20: ensurePromiseN

import scala.concurrent.Promise; //导入依赖的package包/类
@Benchmark
public Void ensurePromiseN() throws Exception {
  Promise<Void> p = Promise.<Void>apply();
  Future<Void> f = p.future();
  for (int i = 0; i < N.n; i++)
    f = f.transform(ensureF, ec);
  p.success(null);
  return Await.result(f, inf);
}
 
开发者ID:traneio,项目名称:future,代码行数:10,代码来源:ScalaFutureBenchmark.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ClientRMService类代码示例发布时间:2022-05-21
下一篇:
Java Destination类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap