use of com.oracle.bedrock.runtime.concurrent.options.StreamName in project oracle-bedrock by coherence-community.
the class SocketBasedRemoteChannelTest method shouldReceiveEventsInOrder.
@Test
public void shouldReceiveEventsInOrder() throws Exception {
int count = 100;
final CountDownLatch latch = new CountDownLatch(count);
final List<Integer> list = new ArrayList<>();
RemoteEventListener listener = new RemoteEventListener() {
@Override
public void onEvent(RemoteEvent event) {
list.add(((Event) event).getId());
latch.countDown();
}
};
try (SocketBasedRemoteChannelServer server = new SocketBasedRemoteChannelServer("Test")) {
StreamName streamName = StreamName.of("Foo");
InetAddress address = server.open();
server.addListener(listener, streamName);
try (SocketBasedRemoteChannelClient client = new SocketBasedRemoteChannelClient(address, server.getPort())) {
client.open();
for (int i = 0; i < count; i++) {
client.raise(new Event(i), streamName);
}
assertThat(latch.await(1, TimeUnit.MINUTES), is(true));
assertThat(list.size(), is(count));
for (int i = 0; i < count; i++) {
assertThat(list.get(i), is(i));
}
}
}
}
use of com.oracle.bedrock.runtime.concurrent.options.StreamName in project oracle-bedrock by coherence-community.
the class AbstractControllableRemoteChannel method removeListener.
@Override
public void removeListener(RemoteEventListener listener, Option... options) {
OptionsByType optionsByType = OptionsByType.of(options);
StreamName streamName = optionsByType.get(StreamName.class);
eventListenersByStreamName.computeIfPresent(streamName, (name, eventListeners) -> {
eventListeners.remove(listener);
return eventListeners.size() == 0 ? null : eventListeners;
});
}
use of com.oracle.bedrock.runtime.concurrent.options.StreamName in project oracle-bedrock by coherence-community.
the class AbstractRemoteChannel method raise.
@Override
public CompletableFuture<Void> raise(RemoteEvent event, Option... options) {
if (isOpen()) {
OptionsByType optionsByType = OptionsByType.of(options);
StreamName streamName = optionsByType.get(StreamName.class);
// by default we acknowledge when sent
optionsByType.addIfAbsent(AcknowledgeWhen.SENT);
EventOperation operation = new EventOperation(streamName, event, optionsByType);
return sendOperation(operation, optionsByType);
} else {
throw new IllegalStateException("RemoteChannel is closed");
}
}
use of com.oracle.bedrock.runtime.concurrent.options.StreamName in project oracle-bedrock by coherence-community.
the class SocketBasedRemoteChannelTest method shouldRaiseAndProcessEvents.
@Test
public void shouldRaiseAndProcessEvents() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
RemoteEventListener listener = new RemoteEventListener() {
@Override
public void onEvent(RemoteEvent event) {
latch.countDown();
}
};
try (SocketBasedRemoteChannelServer server = new SocketBasedRemoteChannelServer("Test")) {
StreamName streamName = StreamName.of("Foo");
InetAddress address = server.open();
server.addListener(listener, streamName);
try (SocketBasedRemoteChannelClient client = new SocketBasedRemoteChannelClient(address, server.getPort())) {
client.open();
client.raise(new Event(1), streamName);
assertThat(latch.await(1, TimeUnit.MINUTES), is(true));
}
}
}
use of com.oracle.bedrock.runtime.concurrent.options.StreamName in project oracle-bedrock by coherence-community.
the class AbstractControllableRemoteChannel method addListener.
@Override
public void addListener(RemoteEventListener listener, Option... options) {
OptionsByType optionsByType = OptionsByType.of(options);
StreamName streamName = optionsByType.get(StreamName.class);
eventListenersByStreamName.compute(streamName, (name, eventListeners) -> {
if (eventListeners == null) {
eventListeners = new CopyOnWriteArraySet<>();
}
eventListeners.add(listener);
return eventListeners;
});
}
Aggregations