io.vlingo.actors.World Java Examples

The following examples show how to use io.vlingo.actors.World. 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: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
private Bootstrap() {
  this.world = World.startWithDefaults("backservice");
  
  TokensSseFeedActor.registerInstantiator();
  
  this.server = Server.startWith(world.stage());
  
  EventJournal.startWith(this.world.stage());

  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      bootStrap.server.stop();
      System.out.println("\n");
      System.out.println("======================");
      System.out.println("Stopping backservice.");
      System.out.println("======================");
      pause();
    }
  });
}
 
Example #2
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
private Bootstrap()
{
    this.world = World.startWithDefaults( "authservice" );
    this.server = Server.startWith( world.stage() );
    
    Runtime.getRuntime().addShutdownHook( new Thread() 
    {
        /* @see java.lang.Thread#run() */
        @Override
        public void run()
        {
            if ( instance != null )
            {
                instance.server.stop();
                
                System.out.println( "=====================" );
                System.out.println( "Stopping authservice." );
                System.out.println( "=====================" );
                pause();
            }
        }
    });
}
 
Example #3
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Produces an busines server running on a given port.
 * In this demo, admin can make several parallel Actors just to emulate
 * Hexagonal Architecture (in real life making identical web-server actors make not much sense)
 *
 * @param port - port number must be different for each instance
 */

Server produceOrganizationServerAndAddToCache(World world, int port) {
  final OrganizationResource resource = new OrganizationResource(world,port);

  final Server server;
  server = Server.startWith(
          world.stage(),
          Resources.are(resource.routes()),
          Filters.none(),
          port,
          Sizing.defineWith(4, 10, 10, 1024),
          Timing.defineWith(3, 1, 100));
  cache.put(port,server);
  return server;
}
 
Example #4
Source File: InMemoryStateStoreRedispatchControlTest.java    From vlingo-symbio with Mozilla Public License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  world = World.startWithDefaults("test-store");

  interest = new MockStateStoreResultInterest();
  dispatcher = new MockStateStoreDispatcher(interest);

  final StateAdapterProvider stateAdapterProvider = new StateAdapterProvider(world);
  new EntryAdapterProvider(world);

  stateAdapterProvider.registerAdapter(Entity1.class, new Entity1StateAdapter());
  // NOTE: No adapter registered for Entity2.class because it will use the default

  StateTypeStateStoreMap.stateTypeToStoreName(Entity1.class, StoreName);

  store = world.actorFor(StateStore.class, InMemoryStateStoreActor.class, Arrays.asList(dispatcher));
}
 
Example #5
Source File: SourcedTypeRegistry.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Construct my default state with {@code sourcedTypes} creating the {@code Journal}
 * of type {@code journalType}, and register me with the {@code world}.
 * @param world the World to which I am registered
 * @param journalType the concrete {@code Actor} type of the Journal to create
 * @param dispatcher the {@code Dispatcher<Dispatchable<Entry<?>,State<?>>>} of the journalType
 * @param sourcedTypes all {@code Class<Sourced<?>>} types of to register
 * @param <A> the type of Actor used for the Journal implementation
 * @param <S> the {@code Sourced<?>} types to register
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public <A extends Actor, S extends Sourced<?>> SourcedTypeRegistry(
        final World world,
        final Class<A> journalType,
        final Dispatcher<Dispatchable<Entry<?>,State<?>>> dispatcher,
        final Class<S> ... sourcedTypes) {

  this(world);

  final Journal<?> journal = world.actorFor(Journal.class, journalType, dispatcher);

  EntryAdapterProvider.instance(world);

  for (Class<S> sourcedType : sourcedTypes) {
    this.register(new Info(journal, sourcedType, sourcedType.getSimpleName()));
  }
}
 
Example #6
Source File: StateProjectionDispatcherTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
public static ProjectionDispatcher filterFor(
        final World world,
        final ProjectionDispatcher projectionDispatcher,
        final String[] becauseOf,
        final FilterOutcome filterOutcome) {

  final Protocols projectionProtocols =
          world.actorFor(
                  new Class<?>[] { ProjectionDispatcher.class, Projection.class },
                  FilterProjectionDispatcherActor.class,
                  filterOutcome);

  final Protocols.Two<ProjectionDispatcher, Projection> projectionFilter = Protocols.two(projectionProtocols);

  projectionDispatcher.projectTo(projectionFilter._2, becauseOf);

  return projectionFilter._1;
}
 
Example #7
Source File: CommandSourcedTest.java    From vlingo-lattice with Mozilla Public License 2.0 6 votes vote down vote up
@Before
@SuppressWarnings({ "unchecked", "rawtypes" })
public void setUp() {
  world = World.startWithDefaults("test-cs");

  dispatcher = new MockJournalDispatcher();

  journal = world.actorFor(Journal.class, InMemoryJournalActor.class, dispatcher);

  registry = new SourcedTypeRegistry(world);
  registry.register(new Info(journal, TestCommandSourcedEntity.class, TestCommandSourcedEntity.class.getSimpleName()));
  registry.info(TestCommandSourcedEntity.class)
    .registerEntryAdapter(DoCommand1.class, new DoCommand1Adapter())
    .registerEntryAdapter(DoCommand2.class, new DoCommand2Adapter())
    .registerEntryAdapter(DoCommand3.class, new DoCommand3Adapter());

  result = new Result();
  entity = world.actorFor(Entity.class, TestCommandSourcedEntity.class, result);
}
 
Example #8
Source File: CalculationTests.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() {
    final World world = TestWorld.start("calculation-test").world();

    final MapQueryExpression objectQuery =
            MapQueryExpression.using(Calculation.class, "find", MapQueryExpression.map("id", "id"));

    final ObjectStore objectStore =
            world.stage().actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher());

    final StateObjectMapper stateObjectMapper =
            StateObjectMapper.with(CalculationState.class, new Object(), new Object());

    final ObjectTypeRegistry.Info<CalculationState> info =
            new ObjectTypeRegistry.Info(objectStore, CalculationState.class,
                    "ObjectStore", objectQuery, stateObjectMapper);

    new ObjectTypeRegistry(world).register(info);

    CalculationQueryProvider.using(world.stage(), objectStore);
}
 
Example #9
Source File: OrganizationResourceTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  world = World.startWithDefaults("OrganizationsResourceTest");
  
  resource = new OrganizationResource(world);
  
  serverPort = baseServerPort.getAndIncrement();
  
  server =
          Server.startWith(
                  world.stage(),
                  Resources.are(resource.routes()),
                  Filters.none(),
                  serverPort,
                  Sizing.defineWith(4, 10, 10, 1024),
                  Timing.defineWith(3, 1, 100));

  progress = new Progress();

  consumer = world.actorFor(ResponseChannelConsumer.class, Definition.has(TestResponseChannelConsumer.class, Definition.parameters(progress)));

  client = new BasicClientRequestResponseChannel(Address.from(Host.of("localhost"), serverPort, AddressType.NONE), consumer, 100, 10240, world.defaultLogger());
}
 
Example #10
Source File: RequestReplyTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatRequestReplyRuns() {
  System.out.println("RequestReply: is starting.");

  final World world = World.startWithDefaults("requestreply-test");

  final RequestReplyResults results = new RequestReplyResults();
  final AccessSafely access = results.afterCompleting(2);

  final Service service = world.actorFor(Service.class, Server.class);
  world.actorFor(Consumer.class, Client.class, service, results);

  Assert.assertEquals(1, (int) access.readFrom("afterReplyReceivedCount"));
  Assert.assertEquals(1, (int) access.readFrom("afterQueryPerformedCount"));

  System.out.println("RequestReply: is completed.");
}
 
Example #11
Source File: ReturnAddressTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatReturnAddressRuns() {
  System.out.println("ReturnAddress: is starting.");

  final World world = World.startWithDefaults("returnaddress-test");

  final ReturnAddressResults results = new ReturnAddressResults();
  final AccessSafely access = results.afterCompleting(2);

  final Service service = world.actorFor(Service.class, Server.class);
  world.actorFor(Consumer.class, Client.class, service, results);

  Assert.assertEquals(1, (int) access.readFrom("afterSimpleReplyCount"));
  Assert.assertEquals(1, (int) access.readFrom("afterComplexReplyCount"));

  System.out.println("ReturnAddress: is completed.");
}
 
Example #12
Source File: FiltersTest.java    From vlingo-http with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatServerStartsWithFilters() {
  final World world = World.startWithDefaults("filters");

  Resource<?> resource =
          ConfigurationResource.defining("profile", ProfileResource.class, 5,
            Actions.canBe("PUT", "/users/{userId}/profile", "define(String userId, body:io.vlingo.http.sample.user.ProfileData profileData)", "io.vlingo.http.sample.user.ProfileDataMapper")
                    .also("GET", "/users/{userId}/profile", "query(String userId)", "io.vlingo.http.sample.user.ProfileDataMapper")
                    .thatsAll());

  port = PORT_TO_USE.incrementAndGet();

  Server server =
          Server.startWith(
                  world.stage(),
                  Resources.are(resource),
                  Filters.are(Arrays.asList(new RequestFilter1()), Filters.noResponseFilters()),
                  port,
                  Sizing.define(),
                  Timing.define());

  assertNotNull(server);
}
 
Example #13
Source File: OrderTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() {
    final World world = TestWorld.start("order-test").world();

    messagingClient = Mockito.mock(MessagingClient.class);
    applicationRegistry = Mockito.mock(ApplicationRegistry.class);
    Mockito.when(applicationRegistry.retrieveStage()).thenReturn(world.stage());
    Mockito.when(applicationRegistry.retrieveMessagingClient()).thenReturn(messagingClient);

    final MapQueryExpression objectQuery =
            MapQueryExpression.using(Order.class, "find", MapQueryExpression.map("id", "id"));

    final ObjectStore objectStore =
            world.stage().actorFor(ObjectStore.class, InMemoryObjectStoreActor.class, new MockDispatcher());

    final StateObjectMapper stateObjectMapper =
            StateObjectMapper.with(Order.class, new Object(), new Object());

    final ObjectTypeRegistry.Info<OrderState> info =
            new ObjectTypeRegistry.Info(objectStore, OrderState.class,
                    "ObjectStore", objectQuery, stateObjectMapper);

    new ObjectTypeRegistry(world).register(info);

    OrderQueryProvider.using(world.stage(), objectStore);
}
 
Example #14
Source File: ResourceFailureTest.java    From vlingo-http with Mozilla Public License 2.0 6 votes vote down vote up
@Before
public void setUp() {
  world = World.startWithDefaults("test-request-failure");

  resource = new FailResource();

  port = nextPort.incrementAndGet();

  server = Server.startWith(
          world.stage(),
          Resources.are(resource.routes()),
          Filters.none(),
          port,
          Sizing.define(),
          Timing.define());
}
 
Example #15
Source File: CompetingConsumerTest.java    From vlingo-examples with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testThatConsumersCompete() {
  final World world = World.startWithDefaults("competing-consumer-test");
  final int poolSize = 4;
  final int messagesToSend = 8;
  final CompetingConsumerResults results = new CompetingConsumerResults();
  final WorkConsumer workConsumer =
          world.actorFor(WorkConsumer.class, WorkRouterActor.class, poolSize, results);
  final AccessSafely access = results.afterCompleting(messagesToSend);

  for (int i = 0; i < messagesToSend; i++) {
    workConsumer.consumeWork(new WorkItem(i));
  }

  Assert.assertEquals(8, (int) access.readFrom("afterItemConsumedCount"));
}
 
Example #16
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * This server demonstrate the ability to open a port that only performs admin
 */
private Server produceAdminServerAndAddToCache(World world, int port) {
  final AdminResource resource = new AdminResource(world,this);

  final Server server;
  server = Server.startWith(
          world.stage(),
          Resources.are(resource.routes()),
          Filters.none(),
          port,
          Sizing.defineWith(4, 10, 10, 1024),
          Timing.defineWith(3, 1, 100));
  cache.put(port,server);
  return server;
}
 
Example #17
Source File: Bootstrap.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private Bootstrap() throws Exception {
  final World world = World.startWithDefaults("agile-collaboration");

  final Exchange camelExchange = new ExchangeBootstrap(world).initExchange();
  final ExchangeDispatcher dispatcher = new ExchangeDispatcher(camelExchange);
  final Journal journal = world.actorFor(Journal.class, InMemoryJournalActor.class, dispatcher);
  final SourcedTypeRegistry registry = new SourcedTypeRegistry(world);

  SourcedRegistration.registerAllWith(registry, journal);
}
 
Example #18
Source File: VaultResourceTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
  world = World.startWithDefaults("test-vault");

  actionGetPrivateToken = new Action(0, "GET", "/tokens/{publicToken}", "generatePrivateToken(String publicToken)", null);
  final List<Action> actions = Arrays.asList(actionGetPrivateToken);

  final Class<? extends ResourceHandler> resourceHandlerClass =
          (Class<? extends ResourceHandler>) Class.forName("io.vlingo.backservice.resource.VaultResource");

  final Resource<?> resource = ConfigurationResource.defining("vault", resourceHandlerClass, 5, actions);

  dispatcher = Dispatcher.startWith(world.stage(), Resources.are(resource));
}
 
Example #19
Source File: PlaygroundTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testPlayPingPong() {
  final World world = World.startWithDefaults("playground");
  final TestUntil until = TestUntil.happenings(1);
  final Pinger pinger = world.actorFor(Pinger.class, PingerActor.class, until);
  final Ponger ponger = world.actorFor(Ponger.class, PongerActor.class);

  pinger.ping(ponger);

  until.completes();

  world.terminate();
}
 
Example #20
Source File: InMemoryEventJournalActorTest.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  world = World.startWithDefaults("test-journal");
  this.dispatcher = new MockDispatcher<>(new MockConfirmDispatchedResultInterest());

  journal = Journal.using(world.stage(), InMemoryJournalActor.class, this.dispatcher);
  EntryAdapterProvider.instance(world).registerAdapter(Test1Source.class, new Test1SourceAdapter());
  EntryAdapterProvider.instance(world).registerAdapter(Test2Source.class, new Test2SourceAdapter());
  StateAdapterProvider.instance(world).registerAdapter(SnapshotState.class, new SnapshotStateAdapter());
}
 
Example #21
Source File: DomainEventListener.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Queue("registered-order")
public void handle(final byte[] data) throws IOException {
    final World world = applicationRegistry.retrieveWorld();
    final JsonNode json = objectMapper.readTree(data);
    final Location location = Location.valueOf(json.get("site").asText());
    final ItemId itemId = ItemId.of(json.get("productId").get("id").asLong());
    final Integer quantity = json.get("quantity").asInt();

    Stock.unload(world.stage(), location, itemId, quantity);
}
 
Example #22
Source File: MessageFilterTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatMessageFilterRuns() {

    System.out.println("Message Filter: is starting.");

    final World world = World.startWithDefaults("message-filter-test");

    final MessageFilterResults results = new MessageFilterResults();

    final AccessSafely access = results.afterCompleting(3);

    final InventorySystem restrictedInventorySystemActor =
            world.actorFor(InventorySystem.class, RestrictedInventorySystemActor.class, results);

    final InventorySystem notRestrictedInventorySystemActor =
            world.actorFor(InventorySystem.class, NotRestrictedInventorySystemActor.class, results);

    final InventorySystem inventoryMessageFilter =
            world.actorFor(InventorySystem.class, InventorySystemMessageFilter.class, results, notRestrictedInventorySystemActor);

    final Order order =
            new Order("1",
                    "TypeDEF",
                    Arrays.asList(
                            new OrderItem("2", "TypeDEF", "A description", 100d),
                            new OrderItem("3", "TypeDEF", "A description", 150d))
                            .stream().collect(toMap(OrderItem::orderItemId, identity())));

    restrictedInventorySystemActor.processOrder(order);
    notRestrictedInventorySystemActor.processOrder(order);
    inventoryMessageFilter.processOrder(order);

    Assert.assertEquals(1, (int) access.readFrom("afterOrderProcessedCount"));
    Assert.assertEquals(2, (int) access.readFrom("afterOrderFilteredCount"));

    System.out.println("Message Filter: is completed.");
}
 
Example #23
Source File: ResourceTestFixtures.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  world = World.start(WORLD_NAME);

  actionPostUser = new Action(0, "POST", "/users", "register(body:io.vlingo.http.sample.user.UserData userData)", null);
  actionPatchUserContact = new Action(1, "PATCH", "/users/{userId}/contact", "changeContact(String userId, body:io.vlingo.http.sample.user.ContactData contactData)", null);
  actionPatchUserName = new Action(2, "PATCH", "/users/{userId}/name", "changeName(String userId, body:io.vlingo.http.sample.user.NameData nameData)", null);
  actionGetUser = new Action(3, "GET", "/users/{userId}", "queryUser(String userId)", null);
  actionGetUsers = new Action(4, "GET", "/users", "queryUsers()", null);
  actionGetUserError = new Action(5, "GET", "/users/{userId}/error", "queryUserError(String userId)", null);
  actionPutUser = new Action(6, "PUT", "/users/{userId}", "changeUser(String userId, body:io.vlingo.http.sample.user.UserData userData)", null);


  final List<Action> actions =
          Arrays.asList(
                  actionPostUser,
                  actionPatchUserContact,
                  actionPatchUserName,
                  actionGetUser,
                  actionGetUsers,
                  actionGetUserError,
                  actionPutUser);

  resourceHandlerClass = ConfigurationResource.newResourceHandlerClassFor("io.vlingo.http.sample.user.UserResource");

  resource = ConfigurationResource.newResourceFor("user", resourceHandlerClass, 7, actions);

  resource.allocateHandlerPool(world.stage());

  final Map<String, Resource<?>> oneResource = new HashMap<>(1);

  oneResource.put(resource.name, resource);

  resources = new Resources(oneResource);
  dispatcher = new TestDispatcher(resources, world.defaultLogger());
}
 
Example #24
Source File: InventoryOrdersTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Test lifecycle of an {@link OrderPlaced}
 */
@Test
public void testOrderPlaced() {

    OrderItem orderItem1 = new OrderItem ( "1", "TypeABC.4", "An item of type ABC.4.", 29.95 );
    OrderItem orderItem2 = new OrderItem ( "2", "TypeABC.1", "An item of type ABC.1.", 99.95 );
    OrderItem orderItem3 = new OrderItem ( "3", "TypeABC.9", "An item of type ABC.9.", 14.95 );

    Map<String, OrderItem> items = Maps.newHashMap ();
    items.put ( orderItem1.getItemType (), orderItem1 );
    items.put ( orderItem2.getItemType (), orderItem2 );
    items.put ( orderItem3.getItemType (), orderItem3 );

    OrderPlaced orderPlaced = new OrderPlaced ( new Order ( "123", "TypeABC", items ) );

    OrderItem orderItem4 = new OrderItem ( "4", "TypeXYZ.2", "An item of type XYZ.2.", 74.95 );
    OrderItem orderItem5 = new OrderItem ( "5", "TypeXYZ.1", "An item of type XYZ.1.", 59.95 );
    OrderItem orderItem6 = new OrderItem ( "6", "TypeXYZ.7", "An item of type XYZ.7.", 29.95 );
    OrderItem orderItem7 = new OrderItem ( "7", "TypeXYZ.5", "An item of type XYZ.5.", 9.95 );

    Map<String, OrderItem> items1 = Maps.newHashMap ();
    items1.put ( orderItem4.getItemType (), orderItem4 );
    items1.put ( orderItem5.getItemType (), orderItem5 );
    items1.put ( orderItem6.getItemType (), orderItem6 );
    items1.put ( orderItem7.getItemType (), orderItem7 );

    OrderPlaced orderPlaced2 = new OrderPlaced ( new Order ( "124", "TypeXYZ", items1 ) );

    final World world = World.startWithDefaults ( WORLD_NAME );
    final OrderRoutingResults results = new OrderRoutingResults();
    final AccessSafely access = results.afterCompleting(2);

    final OrderRouter orderRouter = world.actorFor (OrderRouter.class, OrderRouterActor.class, results);
    orderRouter.routeOrder ( orderPlaced );
    orderRouter.routeOrder ( orderPlaced2 );

    Assert.assertEquals(2, (int) access.readFrom("afterOrderRoutedCount"));

    world.terminate ();
}
 
Example #25
Source File: ServerBootstrap.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
private ServerBootstrap() {
  world = World.start("vlingo-http-server");

  final UserResourceFluent userResource = new UserResourceFluent(world);
  final ProfileResourceFluent profileResource = new ProfileResourceFluent(world);
  final Resource<?> r1 = userResource.routes();
  final Resource<?> r2 = profileResource.routes();
  final Resources resources = Resources.are(r1, r2);

  server =
          Server.startWith(
                  world.stage(),
                  resources,
                  Filters.none(),
                  8081,
                  Sizing.defineWith(4, 10, 100, 10240),
                  Timing.defineWith(3, 1, 100),
                  "arrayQueueMailbox",
                  "arrayQueueMailbox");

  Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run() {
      if (instance != null) {
        instance.server.stop();

        System.out.println("\n");
        System.out.println("==============================");
        System.out.println("Stopping vlingo/http Server...");
        System.out.println("==============================");
      }
    }
  });
}
 
Example #26
Source File: InMemoryJournal.java    From vlingo-symbio with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public InMemoryJournal(
        final List<Dispatcher<Dispatchable<Entry<T>,RS>>> dispatchers,
        final World world,
        final long checkConfirmationExpirationInterval,
        final long confirmationExpiration) {

  this.entryAdapterProvider = EntryAdapterProvider.instance(world);
  this.stateAdapterProvider = StateAdapterProvider.instance(world);
  this.journal = new ArrayList<>();
  this.journalReaders = new HashMap<>(1);
  this.streamReaders = new HashMap<>(1);
  this.streamIndexes = new HashMap<>();
  this.snapshots = new HashMap<>();

  this.dispatchers = dispatchers;
  this.dispatchables = new CopyOnWriteArrayList<>();
  final InMemoryDispatcherControlDelegate<Entry<T>, RS> dispatcherControlDelegate = new InMemoryDispatcherControlDelegate<>(dispatchables);

  this.dispatcherControl = world.stage().actorFor(
          DispatcherControl.class,
          Definition.has(
                  DispatcherControlActor.class,
                  new DispatcherControlInstantiator(
                          dispatchers,
                          dispatcherControlDelegate,
                          checkConfirmationExpirationInterval,
                          confirmationExpiration)));
}
 
Example #27
Source File: FeedResourceTest.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  world = World.startWithDefaults("test-stream-userResource");

  final int testServerPort = serverPort.incrementAndGet();

  properties = new java.util.Properties();
  properties.setProperty("server.http.port", ""+testServerPort);
  properties.setProperty("server.dispatcher.pool", "10");
  properties.setProperty("server.buffer.pool.size", "100");
  properties.setProperty("server.message.buffer.size", "65535");
  properties.setProperty("server.probe.interval", "2");
  properties.setProperty("server.probe.timeout", "2");
  properties.setProperty("server.processor.pool.size", "10");
  properties.setProperty("server.request.missing.content.timeout", "100");

  properties.setProperty("feed.resource.name.events", FeedURI);
  properties.setProperty("feed.resource.events.producer.class", "io.vlingo.http.resource.feed.EventsFeedProducerActor");
  properties.setProperty("feed.resource.events.elements", "5");
  properties.setProperty("feed.resource.events.pool", "10");

  server = Server.startWith(world.stage(), properties);
  assertTrue(server.startUp().await(500L));

  progress = new Progress();
  consumer = world.actorFor(ResponseChannelConsumer.class, Definition.has(TestResponseChannelConsumer.class, Definition.parameters(progress)));
  client = new NettyClientRequestResponseChannel(Address.from(Host.of("localhost"), testServerPort, AddressType.NONE), consumer, 100, 10240);
}
 
Example #28
Source File: PipesAndFiltersTest.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testThatPipesAndFiltersRuns() {
  System.out.println("PipesAndFilters: is starting.");

  final World world = World.startWithDefaults("pipesandfilters-test");

  final PipeAndFilterResults results = new PipeAndFilterResults();
  final AccessSafely access = results.afterCompleting(9);

  final String orderText = "(encryption)(certificate)<order id='123'>...</order>";
  final byte[] rawOrderBytes = orderText.getBytes();

  final OrderProcessor filter5 = world.actorFor(OrderProcessor.class, OrderManagementSystem.class, results);
  final OrderProcessor filter4 = world.actorFor(OrderProcessor.class, Deduplicator.class, filter5, results);
  final OrderProcessor filter3 = world.actorFor(OrderProcessor.class, Authenticator.class, filter4, results);
  final OrderProcessor filter2 = world.actorFor(OrderProcessor.class, Decrypter.class, filter3, results);
  final OrderProcessor filter1 = world.actorFor(OrderProcessor.class, OrderAcceptanceEndpoint.class, filter2, results);

  filter1.processIncomingOrder(rawOrderBytes);
  filter1.processIncomingOrder(rawOrderBytes);

  Assert.assertEquals(2, (int) access.readFrom("afterOrderAuthenticatedCount"));
  Assert.assertEquals(2, (int) access.readFrom("afterOrderDecryptedCount"));
  Assert.assertEquals(2, (int) access.readFrom("afterOrderDeduplicatedCount"));
  Assert.assertEquals(2, (int) access.readFrom("afterOrderAcceptedCount"));
  Assert.assertEquals(1, (int) access.readFrom("afterOrderManagedCount"));

  System.out.println("PipesAndFilters: is completed.");
}
 
Example #29
Source File: SseStreamResourceTest.java    From vlingo-http with Mozilla Public License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  world = World.startWithDefaults("test-stream-userResource");
  Configuration.define();
  resource = new MockSseStreamResource(world);
  Configuration.define();
  context = new MockRequestResponseContext(new MockResponseSenderChannel());
  client = new SseClient(context);
  AllSseFeedActor.registerInstantiator();
}
 
Example #30
Source File: CalculationResource.java    From vlingo-examples with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public Completes<Response> calculate(final ExecuteCalculation executeCalculation) {
    final World world = applicationRegistry.retrieveWorld();
    final Integer firstOperand = executeCalculation.firstOperand();
    final Integer secondOperand = executeCalculation.secondOperand();
    final Operation operation = Operation.withName(executeCalculation.operationName());
    return response(Ok, Calculation.calculate(world.stage(), operation, firstOperand, secondOperand));
}