Java源码示例:akka.actor.Actor

示例1
@Test
public void invalidTargetFormatThrowsConnectionConfigurationInvalidException() {
    final Connection connection = ConnectivityModelFactory.newConnectionBuilder(CONNECTION_ID,
            ConnectionType.AMQP_091, ConnectivityStatus.OPEN, TestConstants.getUriOfNewMockServer())
            .targets(Collections.singletonList(ConnectivityModelFactory.newTargetBuilder()
                    .address("exchangeOnly")
                    .authorizationContext(TestConstants.Authorization.AUTHORIZATION_CONTEXT)
                    .topics(Topic.TWIN_EVENTS)
                    .build()))
            .build();

    final ThrowableAssert.ThrowingCallable props1 =
            () -> RabbitMQClientActor.propsForTests(connection, Actor.noSender(), Actor.noSender(), null);
    final ThrowableAssert.ThrowingCallable props2 =
            () -> RabbitMQClientActor.propsForTests(connection, Actor.noSender(), Actor.noSender(),
                    rabbitConnectionFactoryFactory
            );
    Stream.of(props1, props2)
            .forEach(throwingCallable ->
                    assertThatExceptionOfType(ConnectionConfigurationInvalidException.class)
                            .isThrownBy(throwingCallable)
                            .withMessageContaining("exchangeOnly")
                            .withNoCause()
            );
}
 
示例2
@Override
public Actor create() throws Exception {
  switch (downloadFormat) {
    case SIMPLE_CSV:
      return new SimpleCsvDownloadActor();

    case DWCA:
      return new DownloadDwcaActor();

    case SPECIES_LIST:
      return new SpeciesListDownloadActor();

    default:
      throw new IllegalStateException("Download format '"+downloadFormat+"' unknown or not supported for small downloads.");
  }
}
 
示例3
@Override
public Actor create() throws Exception {
	Actor actor = (Actor) ConstructorUtils.invokeConstructor(clazz, args);
	if(actor != null) {
		ctx.getAutowireCapableBeanFactory().autowireBean(actor);
	}
	return actor;
}
 
示例4
@Override
@SuppressWarnings("unchecked")
public Class<? extends Actor> actorClass() {
	return (Class<? extends Actor>) (requiredType != null ? requiredType : applicationContext.getType(actorBeanName));
}
 
示例5
@Test
public void checkForActivityOfNonexistentPolicy() {
    new TestKit(actorSystem) {
        {
            // GIVEN: a PolicyPersistenceActor is created in a parent that forwards all messages to us
            final PolicyId policyId = PolicyId.of("test.ns", "nonexistent.policy");
            final Props persistentActorProps =
                    PolicyPersistenceActor.props(policyId, new PolicyMongoSnapshotAdapter(), pubSubMediator);

            final TestProbe errorsProbe = TestProbe.apply(actorSystem);

            final Props parentProps = Props.create(Actor.class, () -> new AbstractActor() {

                @Override
                public void preStart() {
                    getContext().actorOf(persistentActorProps);
                }

                @Override
                public SupervisorStrategy supervisorStrategy() {
                    return new OneForOneStrategy(true,
                            DeciderBuilder.matchAny(throwable -> {
                                errorsProbe.ref().tell(throwable, getSelf());
                                return SupervisorStrategy.restart();
                            }).build());
                }

                @Override
                public Receive createReceive() {
                    return ReceiveBuilder.create()
                            .matchAny(message -> {
                                if (getTestActor().equals(getSender())) {
                                    getContext().actorSelection(getSelf().path().child("*"))
                                            .forward(message, getContext());
                                } else {
                                    getTestActor().forward(message, getContext());
                                }
                            })
                            .build();
                }
            });

            // WHEN: CheckForActivity is sent to a persistence actor of nonexistent policy after startup
            final ActorRef underTest = actorSystem.actorOf(parentProps);

            final Object checkForActivity = AbstractShardedPersistenceActor.checkForActivity(1L);
            underTest.tell(checkForActivity, getRef());
            underTest.tell(checkForActivity, getRef());
            underTest.tell(checkForActivity, getRef());

            // THEN: persistence actor requests shutdown
            expectMsg(PolicySupervisorActor.Control.PASSIVATE);

            // THEN: persistence actor should not throw anything.
            errorsProbe.expectNoMessage(scala.concurrent.duration.Duration.create(3, TimeUnit.SECONDS));
        }
    };
}
 
示例6
@Override
public Actor produce() {
    return (Actor) applicationContext.getBean(beanName);
}
 
示例7
@Override
public Class<? extends Actor> actorClass() {
    return applicationContext.getType(beanName).asSubclass(Actor.class);
}
 
示例8
@Override
public Actor create() throws Exception {
    return new SimpleStateLogger();
}
 
示例9
private final void processRequest() {

		// the first time dont count. the first time will delay
		if (!hasBeenDelayed) {

			// jeff only the first time will pause

			sender = getSender();
			startTimeMillis = System.currentTimeMillis();

			validateRequest(request);
			timeoutDuration = Duration.create(
					request.getMaxOperationTimeSeconds(), TimeUnit.SECONDS);

			hasBeenDelayed = true;
			/**
			 * 20131013 if it is 0; no need to schedule another message.
			 */
			if (this.request.getPauseIntervalBeforeSendMillis() != 0L) {
				long MAX_PAUSE_INTERVAL_MILLIS = 600000L; // 600 sec
				long pauseIntervalWorkerMillis = Math.min(
						MAX_PAUSE_INTERVAL_MILLIS,
						this.request.getPauseIntervalBeforeSendMillis());
				getContext()
						.system()
						.scheduler()
						.scheduleOnce(
								Duration.create(pauseIntervalWorkerMillis,
										TimeUnit.MILLISECONDS),
								getSelf(),
								OperationWorker.MessageType.PROCESS_REQUEST,
								getContext().system().dispatcher());

				return;

			}
		}

		/**
		 * 20130917: change to add uniform target node capability
		 */

		final String trueTargetNode = (hostUniform == null) ? host
				: hostUniform;

		asyncWorker = getContext().actorOf(new Props(new UntypedActorFactory() {
			private static final long serialVersionUID = 1L;

			public Actor create() {
				final String requestUrl = String.format("%s://%s:%d%s",
						protocol.toString(), trueTargetNode, agentPort,
						request.getResourcePath());

				return new HttpWorker(client, protocol, requestUrl,
						request.getHttpMethod(), request.getPostData(),
						CONTENT_TYPE_JSON, HTTP_MAX_RETRIES,
						HTTP_RETRY_INTERVAL_MILLIS, httpHeaderType);
			}
		}));
		asyncWorker.tell(HttpWorker.MessageType.PROCESS_REQUEST,
				getSelf());

		// To handle cases where this operation takes extremely long, schedule a
		// 'timeout' message to be sent to us
		timeoutMessageCancellable = getContext()
				.system()
				.scheduler()
				.scheduleOnce(timeoutDuration, getSelf(),
						InternalMessageType.OPERATION_TIMEOUT,
						getContext().system().dispatcher());

	}
 
示例10
@Override
@SuppressWarnings("unchecked")
public Class<? extends Actor> actorClass() {
	return (Class<? extends Actor>) (requiredType != null ? requiredType : applicationContext.getType(actorBeanName));
}
 
示例11
@Override
public Actor produce() {
    return (Actor) applicationContext.getBean(beanActorName);
}
 
示例12
@Override
public Class<? extends Actor> actorClass() {
    return (Class<? extends Actor>) applicationContext.getType(beanActorName);
}
 
示例13
public GuiceActorProducer(Class<? extends Actor> actorClass) {
    this.actorClass = actorClass;
}
 
示例14
@Override
public Class<? extends Actor> actorClass() {
    return actorClass;
}
 
示例15
@Override
public Actor produce() {
    return INJECTOR.getInstance( actorClass );
}
 
示例16
/**
 * Returns a LoggingAdapter with MDC support for the given actor.
 *
 * @param logSource the Actor used as logSource
 * @return the logging adapter.
 * @throws NullPointerException if {@code logSource} is {@code null}.
 */
public static DittoDiagnosticLoggingAdapter getDiagnosticLoggingAdapter(final Actor logSource) {
    return DefaultDittoDiagnosticLoggingAdapter.of(LogUtil.obtain(checkNotNull(logSource, "logSource")));
}
 
示例17
/**
 * Obtain LoggingAdapter with MDC support for the given actor.
 *
 * @param logSource the Actor used as logSource
 * @return the created DiagnosticLoggingAdapter.
 */
public static DiagnosticLoggingAdapter obtain(final Actor logSource) {
    return Logging.apply(logSource);
}