io.vlingo.actors.ActorInstantiator Java Examples

The following examples show how to use io.vlingo.actors.ActorInstantiator. 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: SseStreamResource.java    From vlingo-http with Mozilla Public License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public SsePublisherActor(final String streamName, final Class<? extends Actor> feedClass, final int feedPayload, final int feedInterval, final String feedDefaultId) {
  this.streamName = streamName;
  this.subscribers = new HashMap<>();

  final ActorInstantiator<?> instantiator = ActorInstantiatorRegistry.instantiatorFor(feedClass);
  if(instantiator==null)throw new IllegalArgumentException("No ActorInstantiator registred for feedClass="+feedClass.toString());
  instantiator.set("feedClass", feedClass);
  instantiator.set("streamName", streamName);
  instantiator.set("feedPayload", feedPayload);
  instantiator.set("feedDefaultId", feedDefaultId);

  this.feed = stage().actorFor(SseFeed.class, Definition.has(feedClass, instantiator));

  this.cancellable = stage().scheduler().schedule(selfAs(Scheduled.class), null, 10, feedInterval);

  logger().info("SsePublisher started for: " + this.streamName);
}
 
Example #2
Source File: SseStreamResourceTest.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatFeedWithInstantiatorFeeds() {
  final MockCompletesEventuallyResponse completes = new MockCompletesEventuallyResponse();
  final AccessSafely respondWithSafely = context.channel.expectRespondWith(1);

  // NOTE: Any reference to AllSseFeedActor automatically
  // causes the AllSseFeedInstantiator to be registered

  // somehow the static initializer doesn't work for (this) JUnit tests
  @SuppressWarnings({ "unused", "rawtypes" })
  final Class c = AllSseFeedActor.class;  // not registered
  AllSseFeedActor.registerInstantiator(); // registered

  final Request request =
          Request
            .method(Method.GET)
            .uri("/eventstreams/all")
            .and(RequestHeader.host("StreamsRUs.co"))
            .and(RequestHeader.accept("text/event-stream"));

  final SseStreamResource sseStreamResource = new SseStreamResource(world);
  final Context requestContext = new Context(context, request, completes);
  sseStreamResource.__internal__test_set_up(requestContext, world.stage());

  final ActorInstantiator<?> instantiator = ActorInstantiatorRegistry.instantiatorFor(AllSseFeedActor.class);
  instantiator.set("feedClass", AllSseFeedActor.class);
  instantiator.set("streamName", "all");
  instantiator.set("feedPayload", 1);
  instantiator.set("feedDefaultId", "123");

  sseStreamResource.subscribeToStream("all", AllSseFeedActor.class, 1, 100, "123");

  final int completedCount = respondWithSafely.readFrom("count");
  assertEquals(1, completedCount);
}
 
Example #3
Source File: StateStore.java    From vlingo-symbio with Mozilla Public License 2.0 votes vote down vote up
default <A extends Actor> ActorInstantiator<A> instantiator() { return null; }