Java Code Examples for io.vlingo.actors.Mailbox#send()

The following examples show how to use io.vlingo.actors.Mailbox#send() . 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: RingBufferDispatcherTest.java    From vlingo-actors with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testOverflowDispatch() throws Exception {
  final int mailboxSize = 64;
  final int overflowSize = mailboxSize * 2;
  final TestResults testResults = new TestResults(mailboxSize);

  final RingBufferDispatcher dispatcher = new RingBufferDispatcher(mailboxSize, 2, false, 4);

  final Mailbox mailbox = dispatcher.mailbox();

  final CountTakerActor actor = new CountTakerActor(testResults);

  for (int count = 1; count <= overflowSize; ++count) {
    final int countParam = count;
    final SerializableConsumer<CountTaker> consumer = (consumerActor) -> consumerActor.take(countParam);

    mailbox.send(actor, CountTaker.class, consumer, null, "take(int)");
  }

  dispatcher.start();

  assertEquals(overflowSize, testResults.getHighest());
}
 
Example 2
Source File: ManyToOneConcurrentArrayQueueDispatcherTest.java    From vlingo-actors with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testBasicDispatch() {
  final int mailboxSize = 64;
  final TestResults testResults = new TestResults(MailboxSize);

  final ManyToOneConcurrentArrayQueueDispatcher dispatcher =
          new ManyToOneConcurrentArrayQueueDispatcher(mailboxSize, 2, false, 4, 10);

  dispatcher.start();

  final Mailbox mailbox = dispatcher.mailbox();

  final CountTakerActor actor = new CountTakerActor(testResults);

  for (int count = 1; count <= mailboxSize; ++count) {
    final int countParam = count;
    final SerializableConsumer<CountTaker> consumer = (consumerActor) -> consumerActor.take(countParam);
    final LocalMessage<CountTaker> message = new LocalMessage<>(actor, CountTaker.class, consumer, "take(int)");

    mailbox.send(message);
  }

  assertEquals(mailboxSize, testResults.getHighest());
}
 
Example 3
Source File: RingBufferDispatcherTest.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testNotifyOnSendDispatch() throws Exception {
  final int mailboxSize = 64;
  final TestResults testResults = new TestResults(mailboxSize);

  final RingBufferDispatcher dispatcher =
          new RingBufferDispatcher(mailboxSize, 1000, true, 4);

  dispatcher.start();

  final Mailbox mailbox = dispatcher.mailbox();

  final CountTakerActor actor = new CountTakerActor(testResults);

  for (int count = 1; count <= mailboxSize; ++count) {
    final int countParam = count;
    final SerializableConsumer<CountTaker> consumer = (consumerActor) -> consumerActor.take(countParam);

    // notify if in back off
    mailbox.send(actor, CountTaker.class, consumer, null, "take(int)");

    // every third message give time for dispatcher to back off
    if (count % 3 == 0) {
      Thread.sleep(50);
    }
  }

  assertEquals(mailboxSize, testResults.getHighest());
}
 
Example 4
Source File: ManyToOneConcurrentArrayQueueDispatcherTest.java    From vlingo-actors with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testNotifyOnSendDispatch() throws Exception {
  final int mailboxSize = 64;
  final TestResults testResults = new TestResults(mailboxSize);

  final ManyToOneConcurrentArrayQueueDispatcher dispatcher =
          new ManyToOneConcurrentArrayQueueDispatcher(mailboxSize, 1000, true, 4, 10);

  dispatcher.start();

  final Mailbox mailbox = dispatcher.mailbox();

  final CountTakerActor actor = new CountTakerActor(testResults);

  for (int count = 1; count <= mailboxSize; ++count) {
    final int countParam = count;
    final SerializableConsumer<CountTaker> consumer = (consumerActor) -> consumerActor.take(countParam);
    final LocalMessage<CountTaker> message = new LocalMessage<>(actor, CountTaker.class, consumer, "take(int)");

    // notify if in back off
    mailbox.send(message);

    // every third message give time for dispatcher to back off
    if (count % 3 == 0) {
      Thread.sleep(50);
    }
  }

  assertEquals(mailboxSize, testResults.getHighest());
}
 
Example 5
Source File: RingBufferDispatcherTest.java    From vlingo-actors with Mozilla Public License 2.0 4 votes vote down vote up
@Test
public void testBasicDispatch() throws Exception {
  final int mailboxSize = 64;
  final TestResults testResults = new TestResults(mailboxSize);

  final RingBufferDispatcher dispatcher = new RingBufferDispatcher(mailboxSize, 2, false, 4);

  dispatcher.start();

  final Mailbox mailbox = dispatcher.mailbox();

  final CountTakerActor actor = new CountTakerActor(testResults);

  for (int count = 1; count <= mailboxSize; ++count) {
    final int countParam = count;
    final SerializableConsumer<CountTaker> consumer = (consumerActor) -> consumerActor.take(countParam);

    mailbox.send(actor, CountTaker.class, consumer, null, "take(int)");
  }

  assertEquals(mailboxSize, testResults.getHighest());
}