akka.actor.Actor Java Examples

The following examples show how to use akka.actor.Actor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DownloadMaster.java    From occurrence with Apache License 2.0 6 votes vote down vote up
@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.");
  }
}
 
Example #2
Source File: RabbitMQClientActorTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@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()
            );
}
 
Example #3
Source File: ActorFactoryBean.java    From akka-java-springfactory with MIT License 5 votes vote down vote up
@Override
public Actor create() throws Exception {
	Actor actor = (Actor) ConstructorUtils.invokeConstructor(clazz, args);
	if(actor != null) {
		ctx.getAutowireCapableBeanFactory().autowireBean(actor);
	}
	return actor;
}
 
Example #4
Source File: OperationWorker.java    From restcommander with Apache License 2.0 4 votes vote down vote up
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());

	}
 
Example #5
Source File: GuiceActorProducer.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
public Actor produce() {
    return INJECTOR.getInstance( actorClass );
}
 
Example #6
Source File: GuiceActorProducer.java    From usergrid with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends Actor> actorClass() {
    return actorClass;
}
 
Example #7
Source File: GuiceActorProducer.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public GuiceActorProducer(Class<? extends Actor> actorClass) {
    this.actorClass = actorClass;
}
 
Example #8
Source File: SpringActorProducer.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public Class<? extends Actor> actorClass() {
    return (Class<? extends Actor>) applicationContext.getType(beanActorName);
}
 
Example #9
Source File: SpringActorProducer.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public Actor produce() {
    return (Actor) applicationContext.getBean(beanActorName);
}
 
Example #10
Source File: SpringActorProducer.java    From akka-java-springfactory with MIT License 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Class<? extends Actor> actorClass() {
	return (Class<? extends Actor>) (requiredType != null ? requiredType : applicationContext.getType(actorBeanName));
}
 
Example #11
Source File: SpringActorProducer.java    From spring-boot-akka-event-sourcing-starter with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Class<? extends Actor> actorClass() {
	return (Class<? extends Actor>) (requiredType != null ? requiredType : applicationContext.getType(actorBeanName));
}
 
Example #12
Source File: SimpleStateLogger.java    From amcgala with Educational Community License v2.0 4 votes vote down vote up
@Override
public Actor create() throws Exception {
    return new SimpleStateLogger();
}
 
Example #13
Source File: AkkaSpringActorProducer.java    From odata with Apache License 2.0 4 votes vote down vote up
@Override
public Class<? extends Actor> actorClass() {
    return applicationContext.getType(beanName).asSubclass(Actor.class);
}
 
Example #14
Source File: AkkaSpringActorProducer.java    From odata with Apache License 2.0 4 votes vote down vote up
@Override
public Actor produce() {
    return (Actor) applicationContext.getBean(beanName);
}
 
Example #15
Source File: PolicyPersistenceActorTest.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@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));
        }
    };
}
 
Example #16
Source File: LogUtil.java    From ditto with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example #17
Source File: DittoLoggerFactory.java    From ditto with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * 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")));
}