use of io.scalecube.transport.Address in project scalecube by scalecube.
the class NettyClientTransport method connect.
private Observable<ChannelContext> connect(Address address) {
AsyncSubject<ChannelContext> subject = AsyncSubject.create();
ChannelFuture channelFuture = bootstrap.connect(address.host(), address.port());
channelFuture.addListener((ChannelFutureListener) future -> {
Throwable error = future.cause();
if (future.isSuccess()) {
future.channel().pipeline().fireChannelActive();
try {
ChannelContext channelContext = ChannelSupport.getChannelContextOrThrow(future.channel());
channelContext.listenClose(input -> outboundChannels.remove(address));
subject.onNext(channelContext);
subject.onCompleted();
} catch (Exception throwable) {
error = throwable;
}
}
if (error != null) {
outboundChannels.remove(address);
subject.onError(future.cause());
}
});
Scheduler scheduler = Schedulers.from(channelFuture.channel().eventLoop());
return subject.subscribeOn(scheduler);
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class DefaultEventStreamTest method testChannelContextCreateIfAbsentConsumerNotCalled.
@Test
public void testChannelContextCreateIfAbsentConsumerNotCalled() {
Address address = Address.from("localhost:8080");
ChannelContext channelContext = ChannelContext.create(address);
String id = channelContext.getId();
AtomicBoolean consumerCalled = new AtomicBoolean();
// create context on top of exsting context attributes => result from map
ChannelContext channelContext1 = ChannelContext.createIfAbsent(id, address, input -> consumerCalled.set(true));
assertFalse(consumerCalled.get());
assertEquals(channelContext, channelContext1);
}
use of io.scalecube.transport.Address in project scalecube by scalecube.
the class AddressTest method testParseHostPort.
@Test
public void testParseHostPort() throws Exception {
Address address1 = Address.from("localhost:5810");
assertEquals(5810, address1.port());
assertEquals(Addressing.getLocalIpAddress().getHostAddress(), address1.host());
Address address2 = Address.from("127.0.0.1:5810");
assertEquals(5810, address1.port());
assertEquals(Addressing.getLocalIpAddress().getHostAddress(), address2.host());
assertEquals(address1, address2);
}
Aggregations