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

Java Recover类代码示例

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

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



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

示例1: receiveHandler

import akka.dispatch.Recover; //导入依赖的package包/类
public void receiveHandler(Object message) {
  log.debug("Master client received: {}",message);
  Timeout timeout = new Timeout(120, TimeUnit.SECONDS);
  Future<Object> future = ask(masterProxy, message, timeout);
  final ExecutionContext ec = getContext().system().dispatcher();

  Future<Object> res = future.map(new Mapper<Object, Object>() {
    @Override
    public Object apply(Object msg) {
        return new Ok(msg);
    }
  }, ec).recover(new Recover<Object>() {
    @Override
    public Object recover(Throwable failure) throws Throwable {
      return new NotOk(null);
    }
  }, ec);

  pipe(res, ec).to(getSender());
}
 
开发者ID:Abiy,项目名称:distGatling,代码行数:21,代码来源:MasterClientActor.java


示例2: queryStateFutureWithFailover

import akka.dispatch.Recover; //导入依赖的package包/类
public Future<Object> queryStateFutureWithFailover(final int tries, final QueryState<K> queryState) {
	@SuppressWarnings("unchecked")
	Future<Object> result = queryStateFuture(queryState).recoverWith(new Recover<Future<Object>>() {
		@Override
		public Future<Object> recover(Throwable failure) throws Throwable {
			if (tries > 0) {
				LOG.debug("Query state failed with {}. Try to recover. #{} left.", failure, tries - 1);
				return queryStateFutureWithFailover(tries - 1, queryState);
			} else {
				return Futures.failed(failure);
			}
		}
	}, executor);

	return result;
}
 
开发者ID:dataArtisans,项目名称:query-window-example,代码行数:17,代码来源:QueryActor.java


示例3: onReceive

import akka.dispatch.Recover; //导入依赖的package包/类
public void onReceive(Object message) {

    Timeout timeout = new Timeout(5, TimeUnit.SECONDS);
    Future<Object> f = ask(masterProxy, message, timeout);


    final ExecutionContext ec = getContext().system().dispatcher();

    Future<Object> res = f.map(new Mapper<Object, Object>() {
      @Override
      public Object apply(Object msg) {
        if (msg instanceof Master.Ack)
          return Ok.getInstance();
        else
          return super.apply(msg);
      }
    }, ec).recover(new Recover<Object>() {
      @Override
      public Object recover(Throwable failure) throws Throwable {
        return NotOk.getInstance();
      }
    }, ec);

    pipe(res, ec).to(getSender());
  }
 
开发者ID:typesafehub,项目名称:activator-akka-distributed-workers-java,代码行数:26,代码来源:Frontend.java


示例4: getKvState

import akka.dispatch.Recover; //导入依赖的package包/类
/**
 * Returns a future holding the serialized request result.
 *
 * <p>If the server does not serve a KvState instance with the given ID,
 * the Future will be failed with a {@link UnknownKvStateID}.
 *
 * <p>If the KvState instance does not hold any data for the given key
 * and namespace, the Future will be failed with a {@link UnknownKeyOrNamespace}.
 *
 * <p>All other failures are forwarded to the Future.
 *
 * @param jobId                     JobID of the job the queryable state
 *                                  belongs to
 * @param queryableStateName        Name under which the state is queryable
 * @param keyHashCode               Integer hash code of the key (result of
 *                                  a call to {@link Object#hashCode()}
 * @param serializedKeyAndNamespace Serialized key and namespace to query
 *                                  KvState instance with
 * @return Future holding the serialized result
 */
@SuppressWarnings("unchecked")
public Future<byte[]> getKvState(
		final JobID jobId,
		final String queryableStateName,
		final int keyHashCode,
		final byte[] serializedKeyAndNamespace) {

	return getKvState(jobId, queryableStateName, keyHashCode, serializedKeyAndNamespace, false)
			.recoverWith(new Recover<Future<byte[]>>() {
				@Override
				public Future<byte[]> recover(Throwable failure) throws Throwable {
					if (failure instanceof UnknownKvStateID ||
							failure instanceof UnknownKvStateKeyGroupLocation ||
							failure instanceof UnknownKvStateLocation ||
							failure instanceof ConnectException) {
						// These failures are likely to be caused by out-of-sync
						// KvStateLocation. Therefore we retry this query and
						// force look up the location.
						return getKvState(
								jobId,
								queryableStateName,
								keyHashCode,
								serializedKeyAndNamespace,
								true);
					} else {
						return Futures.failed(failure);
					}
				}
			}, executionContext);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:51,代码来源:QueryableStateClient.java


示例5: exceptionallyAsync

import akka.dispatch.Recover; //导入依赖的package包/类
@Override
public <R> Future<R> exceptionallyAsync(final ApplyFunction<Throwable, ? extends R> exceptionallyFunction, Executor executor) {
	Preconditions.checkNotNull(scalaFuture);
	Preconditions.checkNotNull(exceptionallyFunction);
	Preconditions.checkNotNull(executor);

	scala.concurrent.Future<R> recoveredFuture = scalaFuture.recover(new Recover<R>() {
		@Override
		public R recover(Throwable failure) throws Throwable {
			return exceptionallyFunction.apply(failure);
		}
	}, createExecutionContext(executor));

	return new FlinkFuture<>(recoveredFuture);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:16,代码来源:FlinkFuture.java


示例6: getKvStateWithRetries

import akka.dispatch.Recover; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static Future<byte[]> getKvStateWithRetries(
		final QueryableStateClient client,
		final JobID jobId,
		final String queryName,
		final int key,
		final byte[] serializedKey,
		final FiniteDuration retryDelay,
		final boolean failForUknownKeyOrNamespace) {

	return client.getKvState(jobId, queryName, key, serializedKey)
			.recoverWith(new Recover<Future<byte[]>>() {
				@Override
				public Future<byte[]> recover(Throwable failure) throws Throwable {
					if (failure instanceof AssertionError) {
						return Futures.failed(failure);
					} else if (failForUknownKeyOrNamespace &&
							(failure instanceof UnknownKeyOrNamespace)) {
						return Futures.failed(failure);
					} else {
						// At startup some failures are expected
						// due to races. Make sure that they don't
						// fail this test.
						return Patterns.after(
								retryDelay,
								TEST_ACTOR_SYSTEM.scheduler(),
								TEST_ACTOR_SYSTEM.dispatcher(),
								new Callable<Future<byte[]>>() {
									@Override
									public Future<byte[]> call() throws Exception {
										return getKvStateWithRetries(
												client,
												jobId,
												queryName,
												key,
												serializedKey,
												retryDelay,
												failForUknownKeyOrNamespace);
									}
								});
					}
				}
			}, TEST_ACTOR_SYSTEM.dispatcher());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:45,代码来源:QueryableStateITCase.java


示例7: getKvStateLookupInfo

import akka.dispatch.Recover; //导入依赖的package包/类
/**
 * Returns a future holding the {@link KvStateLocation} for the given job
 * and KvState registration name.
 *
 * <p>If there is currently no JobManager registered with the service, the
 * request is retried. The retry behaviour is specified by the
 * {@link LookupRetryStrategy} of the lookup service.
 *
 * @param jobId               JobID the KvState instance belongs to
 * @param registrationName    Name under which the KvState has been registered
 * @param lookupRetryStrategy Retry strategy to use for retries on UnknownJobManager failures.
 * @return Future holding the {@link KvStateLocation}
 */
@SuppressWarnings("unchecked")
private Future<KvStateLocation> getKvStateLookupInfo(
		final JobID jobId,
		final String registrationName,
		final LookupRetryStrategy lookupRetryStrategy) {

	return jobManagerFuture
			.flatMap(new Mapper<ActorGateway, Future<Object>>() {
				@Override
				public Future<Object> apply(ActorGateway jobManager) {
					// Lookup the KvStateLocation
					Object msg = new KvStateMessage.LookupKvStateLocation(jobId, registrationName);
					return jobManager.ask(msg, askTimeout);
				}
			}, actorSystem.dispatcher())
			.mapTo(ClassTag$.MODULE$.<KvStateLocation>apply(KvStateLocation.class))
			.recoverWith(new Recover<Future<KvStateLocation>>() {
				@Override
				public Future<KvStateLocation> recover(Throwable failure) throws Throwable {
					// If the Future fails with UnknownJobManager, retry
					// the request. Otherwise all Futures will be failed
					// during the start up phase, when the JobManager did
					// not notify this service yet or leadership is lost
					// intermittently.
					if (failure instanceof UnknownJobManager && lookupRetryStrategy.tryRetry()) {
						return Patterns.after(
								lookupRetryStrategy.getRetryDelay(),
								actorSystem.scheduler(),
								actorSystem.dispatcher(),
								new Callable<Future<KvStateLocation>>() {
									@Override
									public Future<KvStateLocation> call() throws Exception {
										return getKvStateLookupInfo(
												jobId,
												registrationName,
												lookupRetryStrategy);
									}
								});
					} else {
						return Futures.failed(failure);
					}
				}
			}, actorSystem.dispatcher());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:58,代码来源:AkkaKvStateLocationLookupService.java


示例8: queryStateFuture

import akka.dispatch.Recover; //导入依赖的package包/类
public Future<Object> queryStateFuture(final QueryState<K> queryState) {
	LOG.debug("Try to get ActorRef future for key {}.", queryState.getKey());

	Future<ActorRef> actorRefFuture = getActorRefFuture(queryState.getKey());

	@SuppressWarnings("unchecked")
	Future<Object> result =  actorRefFuture.flatMap(new Mapper<ActorRef, Future<Object>>() {
		public Future<Object> apply(ActorRef actorRef) {
			LOG.debug("Ask response actor for state for key {}.", queryState.getKey());
			return Patterns.ask(actorRef, queryState, new Timeout(askTimeout));
		}
	}, executor).recoverWith(new Recover<Future<Object>>() {
		@Override
		public Future<Object> recover(final Throwable failure) throws Throwable {
			if (failure instanceof WrongKeyPartitionException || failure instanceof ActorNotFound) {
				// wait askTimeout because we communicated with the wrong actor. This usually
				// indicates that not all actors have registered at the registry.
				return Patterns.after(
					askTimeout,
					getContext().system().scheduler(),
					executor,
					new Callable<Future<Object>>() {
						@Override
						public Future<Object> call() throws Exception {
							refreshCache();
							return Futures.failed(failure);
						}
					});
			} else if (failure instanceof AskTimeoutException) {
				LOG.debug("Ask timed out.", failure);
				handleAskTimeout();
				return Futures.failed(failure);
			} else {
				LOG.debug("State query failed with.", failure);
				refreshCache();
				return Futures.failed(failure);
			}
		}
	}, executor);

	return result;
}
 
开发者ID:dataArtisans,项目名称:query-window-example,代码行数:43,代码来源:QueryActor.java


示例9: recoverF

import akka.dispatch.Recover; //导入依赖的package包/类
public static <T> Recover<T> recoverF( Function<Throwable, T> f ){		
	
	return new Recover<T>() {

		@Override
		public T recover(Throwable t ) throws Throwable {
			
			return f.apply( t );
			
		}
	};
	
}
 
开发者ID:logicaalternativa,项目名称:monad-transformer-and-more,代码行数:14,代码来源:Java8.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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