Refine search
@AssistedInject public UdpTransport(@Assisted Configuration configuration, EventLoopGroupFactory eventLoopGroupFactory, NettyTransportConfiguration nettyTransportConfiguration, ThroughputCounter throughputCounter, LocalMetricRegistry localRegistry) { super(configuration, eventLoopGroupFactory, throughputCounter, localRegistry); this.nettyTransportConfiguration = nettyTransportConfiguration; this.channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); }
public void close() { System.out.println("Closing all sockets..."); DefaultChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); userSession.forEach((userKey, session) -> { allChannels.addAll(session.appChannels); allChannels.addAll(session.hardwareChannels); }); allChannels.close().awaitUninterruptibly(); }
@Override public ChannelGroupFuture writeAndFlush(Object message, ChannelMatcher matcher, boolean voidPromise) { if (message == null) { throw new NullPointerException("message"); } final ChannelGroupFuture future; if (voidPromise) { for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { c.writeAndFlush(safeDuplicate(message), c.voidPromise()); } } future = voidFuture; } else { Map<Channel, ChannelFuture> futures = new LinkedHashMap<Channel, ChannelFuture>(size()); for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.writeAndFlush(safeDuplicate(message))); } } future = new DefaultChannelGroupFuture(this, futures, executor); } ReferenceCountUtil.release(message); return future; }
@Override public ChannelGroupFuture newCloseFuture(ChannelMatcher matcher) { Map<Channel, ChannelFuture> futures = new LinkedHashMap<Channel, ChannelFuture>(size()); for (Channel c: serverChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.closeFuture()); } } for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.closeFuture()); } } return new DefaultChannelGroupFuture(this, futures, executor); }
@Override public ChannelGroupFuture close(ChannelMatcher matcher) { if (matcher == null) { throw new NullPointerException("matcher"); } Map<Channel, ChannelFuture> futures = new LinkedHashMap<Channel, ChannelFuture>(size()); if (stayClosed) { // It is important to set the closed to true, before closing channels. // Our invariants are: // closed=true happens-before ChannelGroup.close() // ChannelGroup.add() happens-before checking closed==true // // See https://github.com/netty/netty/issues/4020 closed = true; } for (Channel c: serverChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.close()); } } for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.close()); } } return new DefaultChannelGroupFuture(this, futures, executor); }
@Override public ChannelGroupFuture write(Object message, ChannelMatcher matcher, boolean voidPromise) { if (message == null) { throw new NullPointerException("message"); } if (matcher == null) { throw new NullPointerException("matcher"); } final ChannelGroupFuture future; if (voidPromise) { for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { c.write(safeDuplicate(message), c.voidPromise()); } } future = voidFuture; } else { Map<Channel, ChannelFuture> futures = new LinkedHashMap<Channel, ChannelFuture>(size()); for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.write(safeDuplicate(message))); } } future = new DefaultChannelGroupFuture(this, futures, executor); } ReferenceCountUtil.release(message); return future; }
@Override public ChannelGroupFuture disconnect(ChannelMatcher matcher) { if (matcher == null) { throw new NullPointerException("matcher"); } Map<Channel, ChannelFuture> futures = new LinkedHashMap<Channel, ChannelFuture>(size()); for (Channel c: serverChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.disconnect()); } } for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.disconnect()); } } return new DefaultChannelGroupFuture(this, futures, executor); }
@Override public ChannelGroupFuture deregister(ChannelMatcher matcher) { if (matcher == null) { throw new NullPointerException("matcher"); } Map<Channel, ChannelFuture> futures = new LinkedHashMap<Channel, ChannelFuture>(size()); for (Channel c: serverChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.deregister()); } } for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.deregister()); } } return new DefaultChannelGroupFuture(this, futures, executor); }
public ChannelGroup getGroup(String... itemIds) { if(ArrayUtils.isEmpty(itemIds)) { return DEFAULT; } ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); if(!CollectionUtils.isEmpty(items)) { items.entrySet().stream().filter(entry -> ObjectCompare.isInList(entry.getKey(), itemIds)).forEach(entry -> channelGroup.add(entry.getValue())); } return channelGroup; }
HttpServerImpl shared = vertx.sharedHttpServers().get(id); if (shared == null || port == 0) { serverChannelGroup = new DefaultChannelGroup("vertx-acceptor-channels", GlobalEventExecutor.INSTANCE); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(vertx.getAcceptorEventLoopGroup(), availableWorkers); } else { Channel serverChannel = res.result(); if (serverChannel.localAddress() instanceof InetSocketAddress) { HttpServerImpl.this.actualPort = ((InetSocketAddress)serverChannel.localAddress()).getPort(); } else { HttpServerImpl.this.actualPort = address.port();
@Override public CompletionStage<NodeConnectionReport> closeConnectionAsync( SocketAddress connection, CloseType type) { Optional<Channel> channel = this.clientChannelGroup .stream() .filter(c -> c.remoteAddress().equals(connection)) .findFirst(); if (channel.isPresent()) { ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); channelGroup.add(channel.get()); ClusterConnectionReport clusterReport = new ClusterConnectionReport(getCluster().getId()); NodeConnectionReport report = clusterReport.addNode(this, Collections.singletonList(connection), getAddress()); return closeChannelGroup(channelGroup, type).thenApply(f -> report); } else { CompletableFuture<NodeConnectionReport> failedFuture = new CompletableFuture<>(); failedFuture.completeExceptionally(new IllegalArgumentException("Not found")); return failedFuture; } }
/** * Starts this mock server and listens for traffic on the given port. * * @param port the port to which this server should bind * * @return a {@code Future} that will succeed when the server has bound to the given port and is ready to accept * traffic */ public Future<Void> start(final int port) { final ChannelFuture channelFuture = this.bootstrap.bind(port); this.allChannels = new DefaultChannelGroup(channelFuture.channel().eventLoop(), true); this.allChannels.add(channelFuture.channel()); return channelFuture; }
public ChannelGroup getGroup() { ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); if(!CollectionUtils.isEmpty(items)) { items.forEach((itemId, channel) -> channelGroup.add(channel)); } return channelGroup; }
@Override public ChannelGroupFuture close() { return close(ChannelMatchers.all()); }
@Override public ChannelGroupFuture deregister() { return deregister(ChannelMatchers.all()); }
@Override public ChannelGroupFuture newCloseFuture(ChannelMatcher matcher) { Map<Channel, ChannelFuture> futures = new LinkedHashMap<Channel, ChannelFuture>(size()); for (Channel c: serverChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.closeFuture()); } } for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.closeFuture()); } } return new DefaultChannelGroupFuture(this, futures, executor); }
@Override public ChannelGroupFuture close(ChannelMatcher matcher) { if (matcher == null) { throw new NullPointerException("matcher"); } Map<Channel, ChannelFuture> futures = new LinkedHashMap<Channel, ChannelFuture>(size()); if (stayClosed) { // It is important to set the closed to true, before closing channels. // Our invariants are: // closed=true happens-before ChannelGroup.close() // ChannelGroup.add() happens-before checking closed==true // // See https://github.com/netty/netty/issues/4020 closed = true; } for (Channel c: serverChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.close()); } } for (Channel c: nonServerChannels.values()) { if (matcher.matches(c)) { futures.put(c, c.close()); } } return new DefaultChannelGroupFuture(this, futures, executor); }