本文整理汇总了Java中akka.dispatch.Mapper类的典型用法代码示例。如果您正苦于以下问题:Java Mapper类的具体用法?Java Mapper怎么用?Java Mapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Mapper类属于akka.dispatch包,在下文中一共展示了Mapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findLocalShardAsync
import akka.dispatch.Mapper; //导入依赖的package包/类
/**
* Finds a local shard async given its shard name and return a Future from which to obtain the
* ActorRef.
*
* @param shardName the name of the local shard that needs to be found
*/
public Future<ActorRef> findLocalShardAsync(final String shardName) {
Future<Object> future = executeOperationAsync(shardManager,
new FindLocalShard(shardName, true), shardInitializationTimeout);
return future.map(new Mapper<Object, ActorRef>() {
@Override
public ActorRef checkedApply(Object response) throws Throwable {
if (response instanceof LocalShardFound) {
LocalShardFound found = (LocalShardFound)response;
LOG.debug("Local shard found {}", found.getPath());
return found.getPath();
} else if (response instanceof NotInitializedException) {
throw (NotInitializedException)response;
} else if (response instanceof LocalShardNotFound) {
throw new LocalShardNotFoundException(
String.format("Local shard for %s does not exist.", shardName));
}
throw new UnknownMessageException(String.format(
"FindLocalShard returned unkown response: %s", response));
}
}, getClientDispatcher());
}
示例2: close
import akka.dispatch.Mapper; //导入依赖的package包/类
@Override
public CompletionStage<Void> close() {
// first despawn on the local node
distributedShardedDOMDataTree.despawnShardFrontend(prefix);
// update the config so the remote nodes are updated
final Future<Object> ask =
Patterns.ask(shardedDataTreeActor, new PrefixShardRemovalLookup(prefix), SHARD_FUTURE_TIMEOUT);
final Future<Void> closeFuture = ask.transform(
new Mapper<Object, Void>() {
@Override
public Void apply(final Object parameter) {
return null;
}
},
new Mapper<Throwable, Throwable>() {
@Override
public Throwable apply(final Throwable throwable) {
return throwable;
}
}, actorSystem.dispatcher());
return FutureConverters.toJava(closeFuture);
}
示例3: receiveHandler
import akka.dispatch.Mapper; //导入依赖的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());
}
示例4: getKvState
import akka.dispatch.Mapper; //导入依赖的package包/类
/**
* Returns a future holding the serialized request result.
*
* @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
* @param forceLookup Flag to force lookup of the {@link KvStateLocation}
* @return Future holding the serialized result
*/
private Future<byte[]> getKvState(
final JobID jobId,
final String queryableStateName,
final int keyHashCode,
final byte[] serializedKeyAndNamespace,
boolean forceLookup) {
return getKvStateLookupInfo(jobId, queryableStateName, forceLookup)
.flatMap(new Mapper<KvStateLocation, Future<byte[]>>() {
@Override
public Future<byte[]> apply(KvStateLocation lookup) {
int keyGroupIndex = KeyGroupRangeAssignment.computeKeyGroupForKeyHash(keyHashCode, lookup.getNumKeyGroups());
KvStateServerAddress serverAddress = lookup.getKvStateServerAddress(keyGroupIndex);
if (serverAddress == null) {
return Futures.failed(new UnknownKvStateKeyGroupLocation());
} else {
// Query server
KvStateID kvStateId = lookup.getKvStateID(keyGroupIndex);
return kvStateClient.getKvState(serverAddress, kvStateId, serializedKeyAndNamespace);
}
}
}, executionContext);
}
示例5: notifyLeaderAddress
import akka.dispatch.Mapper; //导入依赖的package包/类
@Override
public void notifyLeaderAddress(String leaderAddress, final UUID leaderSessionID) {
if (LOG.isDebugEnabled()) {
LOG.debug("Received leader address notification {}:{}", leaderAddress, leaderSessionID);
}
if (leaderAddress == null) {
jobManagerFuture = UNKNOWN_JOB_MANAGER;
} else {
jobManagerFuture = AkkaUtils.getActorRefFuture(leaderAddress, actorSystem, askTimeout)
.map(new Mapper<ActorRef, ActorGateway>() {
@Override
public ActorGateway apply(ActorRef actorRef) {
return new AkkaActorGateway(actorRef, leaderSessionID);
}
}, actorSystem.dispatcher());
}
}
示例6: thenAcceptAsync
import akka.dispatch.Mapper; //导入依赖的package包/类
@Override
public Future<Void> thenAcceptAsync(final AcceptFunction<? super T> acceptFunction, Executor executor) {
Preconditions.checkNotNull(scalaFuture);
Preconditions.checkNotNull(acceptFunction);
Preconditions.checkNotNull(executor);
scala.concurrent.Future<Void> acceptedFuture = scalaFuture.map(new Mapper<T, Void>() {
@Override
public Void apply(T value) {
acceptFunction.accept(value);
return null;
}
}, createExecutionContext(executor));
return new FlinkFuture<>(acceptedFuture);
}
示例7: notifyLeaderAddress
import akka.dispatch.Mapper; //导入依赖的package包/类
@Override
public void notifyLeaderAddress(final String leaderAddress, final UUID leaderSessionID) {
if(leaderAddress != null && !leaderAddress.equals("") && !futureActorGateway.isCompleted()) {
AkkaUtils.getActorRefFuture(leaderAddress, actorSystem, timeout)
.map(new Mapper<ActorRef, ActorGateway>() {
public ActorGateway apply(ActorRef ref) {
return new AkkaActorGateway(ref, leaderSessionID);
}
}, actorSystem.dispatcher())
.onComplete(new OnComplete<ActorGateway>() {
@Override
public void onComplete(Throwable failure, ActorGateway success) throws Throwable {
if (failure == null) {
completePromise(success);
} else {
LOG.debug("Could not retrieve the leader for address " + leaderAddress + ".", failure);
}
}
}, actorSystem.dispatcher());
}
}
示例8: isReachable
import akka.dispatch.Mapper; //导入依赖的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());
}
示例9: createCommanderForDrone
import akka.dispatch.Mapper; //导入依赖的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());
}
示例10: isoDateAndDateTime
import akka.dispatch.Mapper; //导入依赖的package包/类
public static Mapper<String, Date> isoDateAndDateTime() {
final Mapper<String, Date> dateTime = isoDateTime();
final Mapper<String, Date> date = isoDate();
return new Mapper<String, Date>() {
@Override
public Date apply(String parameter) {
Date result = dateTime.apply(parameter);
if(result == null) {
return date.apply(parameter);
} else {
return result;
}
}
};
}
示例11: testScalaFuture
import akka.dispatch.Mapper; //导入依赖的package包/类
@Test(expected=IllegalArgumentException.class)
public void testScalaFuture() throws Exception {
Future<String> future =
Futures.successful("Hello, world!").map(new Mapper<String, Integer>() {
@Override
public Integer apply(String s) {
try {
return Integer.parseInt(s);
} catch(Exception e) {
throw new IllegalArgumentException("Not an integer", e);
}
}
}, actorSystem.dispatcher()).map(new Mapper<Integer, String>() {
@Override
public String apply(Integer i) {
return i.toString();
}
}, actorSystem.dispatcher());
Await.result(future, Duration.apply(5, TimeUnit.SECONDS));
}
示例12: onReceive
import akka.dispatch.Mapper; //导入依赖的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());
}
示例13: mapper
import akka.dispatch.Mapper; //导入依赖的package包/类
protected static <T, R> Mapper<T, R> mapper(Function<T, R> func) {
return new Mapper<T, R>() {
@Override
public R apply(T parameter) {
return func.apply(parameter);
}
};
}
示例14: thenApplyAsync
import akka.dispatch.Mapper; //导入依赖的package包/类
@Override
public <R> Future<R> thenApplyAsync(final ApplyFunction<? super T, ? extends R> applyFunction, Executor executor) {
Preconditions.checkNotNull(scalaFuture);
Preconditions.checkNotNull(applyFunction);
Preconditions.checkNotNull(executor);
scala.concurrent.Future<R> mappedFuture = scalaFuture.map(new Mapper<T, R>() {
@Override
public R apply(T value) {
return applyFunction.apply(value);
}
}, createExecutionContext(executor));
return new FlinkFuture<>(mappedFuture);
}
示例15: thenComposeAsync
import akka.dispatch.Mapper; //导入依赖的package包/类
@Override
public <R> Future<R> thenComposeAsync(final ApplyFunction<? super T, ? extends Future<R>> applyFunction, Executor executor) {
Preconditions.checkNotNull(scalaFuture);
Preconditions.checkNotNull(applyFunction);
Preconditions.checkNotNull(executor);
final ExecutionContext executionContext = createExecutionContext(executor);
scala.concurrent.Future<R> flatMappedFuture = scalaFuture.flatMap(new Mapper<T, scala.concurrent.Future<R>>() {
@Override
public scala.concurrent.Future<R> apply(T value) {
final Future<? extends R> future = applyFunction.apply(value);
if (future instanceof FlinkFuture) {
@SuppressWarnings("unchecked")
FlinkFuture<R> flinkFuture = (FlinkFuture<R>) future;
return flinkFuture.scalaFuture;
} else {
return Futures.future(new Callable<R>() {
@Override
public R call() throws Exception {
try {
return future.get();
} catch (ExecutionException e) {
// unwrap the execution exception if it's not a throwable
if (e.getCause() instanceof Exception) {
throw (Exception) e.getCause();
} else {
throw new FlinkFuture.ThrowableWrapperException(e.getCause());
}
}
}
}, executionContext);
}
}
}, executionContext);
return new FlinkFuture<>(flatMappedFuture);
}