本文整理汇总了Java中akka.actor.ActorRef类的典型用法代码示例。如果您正苦于以下问题:Java ActorRef类的具体用法?Java ActorRef怎么用?Java ActorRef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActorRef类属于akka.actor包,在下文中一共展示了ActorRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import akka.actor.ActorRef; //导入依赖的package包/类
@Override
public void run() {
final Future<ActorRef> localShardFuture =
context.findLocalShardAsync(ClusterUtils.getCleanShardName(toLookup.getRootIdentifier()));
localShardFuture.onComplete(new OnComplete<ActorRef>() {
@Override
public void onComplete(Throwable throwable, ActorRef actorRef) throws Throwable {
if (throwable != null) {
tryReschedule(throwable);
} else {
LOG.debug("Local backend for shard[{}] lookup successful, starting leader lookup..", toLookup);
system.scheduler().scheduleOnce(
SHARD_LOOKUP_TASK_INTERVAL,
new ShardLeaderLookupTask(system, replyTo, context, clusterWrapper, actorRef,
shardingService, toLookup, lookupMaxRetries),
system.dispatcher());
}
}
}, system.dispatcher());
}
示例2: createRoom
import akka.actor.ActorRef; //导入依赖的package包/类
private void createRoom(ApiRequestForward forward) {
CREATE_ROOM_REQUEST request;
try {
request = CREATE_ROOM_REQUEST.parseFrom(forward.getArgs(0));
} catch (InvalidProtocolBufferException e) {
getLogger().error("Input args error {}", e);
return;
}
// fixme 加载用户信息
// 默认用户为在线
final ActorRef roomContext = getContext().actorOf(RoomContext.props(request.getRoomId(), null), "roomContext");
roomIdToRoomContextActor.put(request.getRoomId(), roomContext);
// 把当前用户加入 room Id 列表上
request.getUserIdsList().forEach(u -> usersToRoomId.put(u, request.getRoomId()));
}
示例3: getRecommendedContents
import akka.actor.ActorRef; //导入依赖的package包/类
@Test()
public void getRecommendedContents() {
TestKit probe = new TestKit(system);
ActorRef subject = system.actorOf(props);
Request reqObj = new Request();
reqObj.setRequestId("1");
reqObj.setOperation(ActorOperations.GET_RECOMMENDED_COURSES.getValue());
HashMap<String, Object> innerMap = new HashMap<>();
innerMap.put(JsonKey.REQUESTED_BY, "USR");
reqObj.setRequest(innerMap);
subject.tell(reqObj, probe.getRef());
probe.expectMsgClass(duration("100 second"),ProjectCommonException.class);
}
示例4: shouldSendCoffeePreparedWithRandomCoffeeForInaccurateResponse
import akka.actor.ActorRef; //导入依赖的package包/类
@Test
public void shouldSendCoffeePreparedWithRandomCoffeeForInaccurateResponse() {
new JavaTestKit(system) {{
Integer accuracy = 50;
Long runs = 1000L;
ActorRef guest = system.deadLetters();
ActorRef barista = system.actorOf(Barista.props(duration("0 milliseconds"), accuracy));
List<Coffee> coffees = new ArrayList<>();
for (int i = 0; i < runs; i++) {
barista.tell(new Barista.PrepareCoffee(new Coffee.Akkaccino(), guest), getRef());
Barista.CoffeePrepared cp = expectMsgClass(duration("50 milliseconds"), Barista.CoffeePrepared.class);
coffees.add(cp.coffee);
}
Long expectedCount = runs * accuracy / 100;
Long variation = expectedCount / 10;
Long numberOfCorrectCoffee = coffees.stream().filter(c -> c.equals(new Coffee.Akkaccino())).count();
assertThat(numberOfCorrectCoffee).isBetween(expectedCount - variation, expectedCount + variation);
}};
}
示例5: testCourseProgressWithInvalidBatchIdNull
import akka.actor.ActorRef; //导入依赖的package包/类
@Test
public void testCourseProgressWithInvalidBatchIdNull(){
TestKit probe = new TestKit(system);
ActorRef subject = system.actorOf(props);
Request actorMessage = new Request();
actorMessage.put(JsonKey.REQUESTED_BY , userId);
actorMessage.put(JsonKey.BATCH_ID , null);
actorMessage.put(JsonKey.PERIOD , "fromBegining");
actorMessage.setOperation(ActorOperations.COURSE_PROGRESS_METRICS.getValue());
subject.tell(actorMessage, probe.getRef());
ProjectCommonException res= probe.expectMsgClass(duration("100 second"),ProjectCommonException.class);
}
示例6: shouldRestartWaiterAndResendPrepareCoffeeToBaristaOnFailure
import akka.actor.ActorRef; //导入依赖的package包/类
@Test
public void shouldRestartWaiterAndResendPrepareCoffeeToBaristaOnFailure() {
new JavaTestKit(system) {{
createActor(CoffeeHouse.class, "resend-prepare-coffee", () -> new CoffeeHouse(Integer.MAX_VALUE) {
@Override
protected ActorRef createBarista() {
return getRef();
}
@Override
protected ActorRef createWaiter() { //stubbing out the waiter actor to always throw exception
return context().actorOf(Props.create(AbstractActor.class, () -> new AbstractActor() {
@Override
public Receive createReceive() {
return receiveBuilder().matchAny(o -> {
throw new Waiter.FrustratedException(new Coffee.Akkaccino(), system.deadLetters());
}).build();
}
}), "waiter");
}
});
ActorRef waiter = expectActor(this, "/user/resend-prepare-coffee/waiter");
waiter.tell("Blow up", ActorRef.noSender());
expectMsgEquals(new Barista.PrepareCoffee(new Coffee.Akkaccino(), system.deadLetters()));
}};
}
示例7: shouldLogResponseFromCoffeeHouse
import akka.actor.ActorRef; //导入依赖的package包/类
@Test
public void shouldLogResponseFromCoffeeHouse() {
new JavaTestKit(system) {{
interceptInfoLogMessage(this, "stub response", 1, () -> {
new CoffeeHouseApp(system) {
@Override
protected ActorRef createCoffeeHouse() {
return createStubActor("stub-coffee-house", () -> new AbstractLoggingActor() {
@Override
public Receive createReceive() {
return receiveBuilder().matchAny(o -> getSender().tell("stub response", getSelf())).build();
}
});
}
};
});
}};
}
示例8: tell
import akka.actor.ActorRef; //导入依赖的package包/类
public static void tell(Request request) {
if (null != BackgroundRequestRouterActor.routerMap
&& null != BackgroundRequestRouterActor.routerMap.get(request.getOperation())) {
BackgroundRequestRouterActor.routerMap.get(request.getOperation()).tell(request,
ActorRef.noSender());
} else if (null != RequestRouterActor.routerMap
&& null != RequestRouterActor.routerMap.get(request.getOperation())) {
RequestRouterActor.routerMap.get(request.getOperation()).tell(request, ActorRef.noSender());
} else {
Object obj =
ActorSystemFactory.getActorSystem().initializeActorSystem(request.getOperation());
if (obj instanceof ActorRef) {
ProjectLogger
.log("In ActorUtil(org.sunbird.learner.util) Actor ref is running " + ((ActorRef) obj));
((ActorRef) obj).tell(request, ActorRef.noSender());
} else {
ProjectLogger.log("In ActorUtil(org.sunbird.learner.util) Actor selection is running "
+ ((ActorSelection) obj));
((ActorSelection) obj).tell(request, ActorRef.noSender());
}
}
}
示例9: testUpdateTanentPreference
import akka.actor.ActorRef; //导入依赖的package包/类
@Test
public void testUpdateTanentPreference(){
TestKit probe = new TestKit(system);
ActorRef subject = system.actorOf(props);
Request actorMessage = new Request();
List<Map<String , Object>> reqList = new ArrayList<>();
Map<String , Object> map = new HashMap<>();
map.put(JsonKey.ROLE , "admin");
reqList.add(map);
actorMessage.getRequest().put(JsonKey.TENANT_PREFERENCE , reqList);
actorMessage.getRequest().put(JsonKey.ROOT_ORG_ID , orgId);
actorMessage.getRequest().put(JsonKey.REQUESTED_BY , USER_ID);
actorMessage.setOperation(ActorOperations.UPDATE_TENANT_PREFERENCE.getValue());
subject.tell(actorMessage, probe.getRef());
Response res= probe.expectMsgClass(duration("100 second"),Response.class);
}
示例10: handleCanCommit
import akka.actor.ActorRef; //导入依赖的package包/类
/**
* This method handles the canCommit phase for a transaction.
*
* @param transactionID the ID of the transaction to canCommit
* @param sender the actor to which to send the response
* @param shard the transaction's shard actor
*/
void handleCanCommit(final Identifier transactionID, final ActorRef sender, final Shard shard) {
// Lookup the cohort entry that was cached previously (or should have been) by
// transactionReady (via the ForwardedReadyTransaction message).
final CohortEntry cohortEntry = cohortCache.get(transactionID);
if (cohortEntry == null) {
// Either canCommit was invoked before ready (shouldn't happen) or a long time passed
// between canCommit and ready and the entry was expired from the cache or it was aborted.
IllegalStateException ex = new IllegalStateException(
String.format("%s: Cannot canCommit transaction %s - no cohort entry found", name, transactionID));
log.error(ex.getMessage());
sender.tell(new Failure(ex), shard.self());
return;
}
cohortEntry.setReplySender(sender);
cohortEntry.setShard(shard);
handleCanCommit(cohortEntry);
}
示例11: testOnReceiveFindLocalShardForNonExistentShard
import akka.actor.ActorRef; //导入依赖的package包/类
@Test
public void testOnReceiveFindLocalShardForNonExistentShard() throws Exception {
new JavaTestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new FindLocalShard("non-existent", false), getRef());
LocalShardNotFound notFound = expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
assertEquals("getShardName", "non-existent", notFound.getShardName());
}
};
}
示例12: test11joinUserOrganisationInvalidOrgId
import akka.actor.ActorRef; //导入依赖的package包/类
@Test
public void test11joinUserOrganisationInvalidOrgId(){
TestKit probe = new TestKit(system);
ActorRef subject = system.actorOf(props);
Request reqObj = new Request();
reqObj.setOperation(ActorOperations.JOIN_USER_ORGANISATION.getValue());
HashMap<String, Object> innerMap = new HashMap<>();
reqObj.getRequest().put(JsonKey.USER_ORG , innerMap);
innerMap.put(JsonKey.ORGANISATION_ID , orgId+"bjic3r9");
innerMap.put(JsonKey.USER_ID , USER_ID);
List<String> roles = new ArrayList<>();
roles.add("ADMIN");
innerMap.put(JsonKey.ROLES, roles);
subject.tell(reqObj, probe.getRef());
ProjectCommonException resp = probe.expectMsgClass(duration("200 second"),ProjectCommonException.class);
}
示例13: performRegistration
import akka.actor.ActorRef; //导入依赖的package包/类
private synchronized void performRegistration(ActorRef shard) {
if (isClosed()) {
return;
}
cohortRegistry = shard;
Future<Object> future =
Patterns.ask(shard, new DataTreeCohortActorRegistry.RegisterCohort(subtree, actor), TIMEOUT);
future.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(Throwable failure, Object val) {
if (failure != null) {
LOG.error("Unable to register {} as commit cohort", getInstance(), failure);
}
if (isClosed()) {
removeRegistration();
}
}
}, actorContext.getClientDispatcher());
}
示例14: testExecuteRemoteOperationAsync
import akka.actor.ActorRef; //导入依赖的package包/类
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testExecuteRemoteOperationAsync() {
new JavaTestKit(getSystem()) {
{
ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class));
ActorRef shardManagerActorRef = getSystem().actorOf(MockShardManager.props(true, shardActorRef));
ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef,
mock(ClusterWrapper.class), mock(Configuration.class));
ActorSelection actor = actorContext.actorSelection(shardActorRef.path());
Future<Object> future = actorContext.executeOperationAsync(actor, "hello");
try {
Object result = Await.result(future, Duration.create(3, TimeUnit.SECONDS));
assertEquals("Result", "hello", result);
} catch (Exception e) {
throw new AssertionError(e);
}
}
};
}
示例15: testUpdateUserTcStatus
import akka.actor.ActorRef; //导入依赖的package包/类
@Test
public void testUpdateUserTcStatus(){
TestKit probe = new TestKit(system);
ActorRef subject = system.actorOf(props);
Request actorMessage = new Request();
Map<String , Object> map = new HashMap<>();
map.put(JsonKey.TERM_AND_CONDITION_STATUS , "ACCEPTED");
actorMessage.getRequest().put(JsonKey.TENANT_PREFERENCE , map);
actorMessage.getRequest().put(JsonKey.ROOT_ORG_ID , orgId);
actorMessage.getRequest().put(JsonKey.REQUESTED_BY , USER_ID);
actorMessage.setOperation(ActorOperations.UPDATE_TC_STATUS_OF_USER.getValue());
subject.tell(actorMessage, probe.getRef());
Response res= probe.expectMsgClass(duration("100 second"),Response.class);
}