@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { InetSocketAddress sourceAddress = sourceAddress(ctx.channel()); ctx.channel().attr(ATTR_SOURCE_INET_ADDR).setIfAbsent(sourceAddress); ctx.channel().attr(ATTR_SOURCE_ADDRESS).setIfAbsent(sourceAddress.getAddress().getHostAddress()); ctx.channel().attr(ATTR_SOURCE_PORT).setIfAbsent(sourceAddress.getPort()); InetSocketAddress localAddress = localAddress(ctx.channel()); ctx.channel().attr(ATTR_LOCAL_INET_ADDR).setIfAbsent(localAddress); ctx.channel().attr(ATTR_LOCAL_ADDRESS).setIfAbsent(localAddress.getAddress().getHostAddress()); ctx.channel().attr(ATTR_LOCAL_PORT).setIfAbsent(localAddress.getPort()); // ATTR_LOCAL_ADDRESS and ATTR_LOCAL_PORT get overwritten with what is received in // Proxy Protocol (via the LB), so set local server's address, port explicitly ctx.channel().attr(ATTR_SERVER_LOCAL_ADDRESS).setIfAbsent(localAddress.getAddress().getHostAddress()); ctx.channel().attr(ATTR_SERVER_LOCAL_PORT).setIfAbsent(localAddress.getPort()); if (INBOUND_TCP_PASSTHROUGH__PORT.get() == ctx.channel().attr(ATTR_SERVER_LOCAL_PORT).get()) { ctx.channel().attr(ATTR_TCP_PASSTHROUGH_INBOUND_CONN).set(true); } super.channelActive(ctx); }
public static AbstractChannel getChannel(ChannelHandlerContext ctx) { Attribute<AbstractChannel> attr = ctx.channel().attr(CHANNEL_KEY); AbstractChannel sofaChannel = attr.get(); if (sofaChannel == null) { sofaChannel = new NettyChannel(ctx); AbstractChannel old = attr.setIfAbsent(sofaChannel); if (old != null) { sofaChannel = old; } } return sofaChannel; }
public static AbstractChannel getChannel(ChannelHandlerContext ctx) { Attribute<AbstractChannel> attr = ctx.channel().attr(CHANNEL_KEY); AbstractChannel sofaChannel = attr.get(); if (sofaChannel == null) { sofaChannel = new NettyChannel(ctx); AbstractChannel old = attr.setIfAbsent(sofaChannel); if (old != null) { sofaChannel = old; } } return sofaChannel; }
/** * Returns the {@link NettyChannel} for given {@link Channel}, this method never return null. */ public static NettyChannel attachChannel(Channel channel) { Attribute<NettyChannel> attr = channel.attr(NETTY_CHANNEL_KEY); NettyChannel nChannel = attr.get(); if (nChannel == null) { NettyChannel newNChannel = new NettyChannel(channel); nChannel = attr.setIfAbsent(newNChannel); if (nChannel == null) { nChannel = newNChannel; } } return nChannel; }
/** * Returns the {@link NettyChannel} for given {@link Channel}, this method never return null. */ public static NettyChannel attachChannel(Channel channel) { Attribute<NettyChannel> attr = channel.attr(NETTY_CHANNEL_KEY); NettyChannel nChannel = attr.get(); if (nChannel == null) { NettyChannel newNChannel = new NettyChannel(channel); nChannel = attr.setIfAbsent(newNChannel); if (nChannel == null) { nChannel = newNChannel; } } return nChannel; }
private static boolean attachPublishEventOnChannel(RegisterMeta meta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(C_PUBLISH_KEY); ConcurrentSet<RegisterMeta> registerMetaSet = attr.get(); if (registerMetaSet == null) { ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>(); registerMetaSet = attr.setIfAbsent(newRegisterMetaSet); if (registerMetaSet == null) { registerMetaSet = newRegisterMetaSet; } } return registerMetaSet.add(meta); }
private static boolean attachSubscribeEventOnChannel(RegisterMeta.ServiceMeta serviceMeta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta.ServiceMeta>> attr = channel.attr(C_SUBSCRIBE_KEY); ConcurrentSet<RegisterMeta.ServiceMeta> serviceMetaSet = attr.get(); if (serviceMetaSet == null) { ConcurrentSet<RegisterMeta.ServiceMeta> newServiceMetaSet = new ConcurrentSet<>(); serviceMetaSet = attr.setIfAbsent(newServiceMetaSet); if (serviceMetaSet == null) { serviceMetaSet = newServiceMetaSet; } } return serviceMetaSet.add(serviceMeta); }
private static boolean attachPublishEventOnChannel(RegisterMeta meta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(S_PUBLISH_KEY); ConcurrentSet<RegisterMeta> registerMetaSet = attr.get(); if (registerMetaSet == null) { ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>(); registerMetaSet = attr.setIfAbsent(newRegisterMetaSet); if (registerMetaSet == null) { registerMetaSet = newRegisterMetaSet; } } return registerMetaSet.add(meta); }
private static boolean attachPublishCancelEventOnChannel(RegisterMeta meta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(S_PUBLISH_KEY); ConcurrentSet<RegisterMeta> registerMetaSet = attr.get(); if (registerMetaSet == null) { ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>(); registerMetaSet = attr.setIfAbsent(newRegisterMetaSet); if (registerMetaSet == null) { registerMetaSet = newRegisterMetaSet; } } return registerMetaSet.remove(meta); }
private static boolean attachPublishEventOnChannel(RegisterMeta meta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(S_PUBLISH_KEY); ConcurrentSet<RegisterMeta> registerMetaSet = attr.get(); if (registerMetaSet == null) { ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>(); registerMetaSet = attr.setIfAbsent(newRegisterMetaSet); if (registerMetaSet == null) { registerMetaSet = newRegisterMetaSet; } } return registerMetaSet.add(meta); }
private static boolean attachSubscribeEventOnChannel(RegisterMeta.ServiceMeta serviceMeta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta.ServiceMeta>> attr = channel.attr(S_SUBSCRIBE_KEY); ConcurrentSet<RegisterMeta.ServiceMeta> serviceMetaSet = attr.get(); if (serviceMetaSet == null) { ConcurrentSet<RegisterMeta.ServiceMeta> newServiceMetaSet = new ConcurrentSet<>(); serviceMetaSet = attr.setIfAbsent(newServiceMetaSet); if (serviceMetaSet == null) { serviceMetaSet = newServiceMetaSet; } } return serviceMetaSet.add(serviceMeta); }
private static boolean attachSubscribeEventOnChannel(RegisterMeta.ServiceMeta serviceMeta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta.ServiceMeta>> attr = channel.attr(S_SUBSCRIBE_KEY); ConcurrentSet<RegisterMeta.ServiceMeta> serviceMetaSet = attr.get(); if (serviceMetaSet == null) { ConcurrentSet<RegisterMeta.ServiceMeta> newServiceMetaSet = new ConcurrentSet<>(); serviceMetaSet = attr.setIfAbsent(newServiceMetaSet); if (serviceMetaSet == null) { serviceMetaSet = newServiceMetaSet; } } return serviceMetaSet.add(serviceMeta); }
private static boolean attachPublishEventOnChannel(RegisterMeta meta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(C_PUBLISH_KEY); ConcurrentSet<RegisterMeta> registerMetaSet = attr.get(); if (registerMetaSet == null) { ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>(); registerMetaSet = attr.setIfAbsent(newRegisterMetaSet); if (registerMetaSet == null) { registerMetaSet = newRegisterMetaSet; } } return registerMetaSet.add(meta); }
private static boolean attachSubscribeEventOnChannel(RegisterMeta.ServiceMeta serviceMeta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta.ServiceMeta>> attr = channel.attr(C_SUBSCRIBE_KEY); ConcurrentSet<RegisterMeta.ServiceMeta> serviceMetaSet = attr.get(); if (serviceMetaSet == null) { ConcurrentSet<RegisterMeta.ServiceMeta> newServiceMetaSet = new ConcurrentSet<>(); serviceMetaSet = attr.setIfAbsent(newServiceMetaSet); if (serviceMetaSet == null) { serviceMetaSet = newServiceMetaSet; } } return serviceMetaSet.add(serviceMeta); }
private static boolean attachPublishCancelEventOnChannel(RegisterMeta meta, Channel channel) { Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(S_PUBLISH_KEY); ConcurrentSet<RegisterMeta> registerMetaSet = attr.get(); if (registerMetaSet == null) { ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>(); registerMetaSet = attr.setIfAbsent(newRegisterMetaSet); if (registerMetaSet == null) { registerMetaSet = newRegisterMetaSet; } } return registerMetaSet.remove(meta); }
@Override public void handle(Channel channel, Command command, String... args) { if (args.length < 2) { channel.writeAndFlush("Need password!" + JConstants.NEWLINE); return; } String password = SystemPropertyUtil.get("monitor.server.password"); if (password == null) { password = DEFAULT_PASSWORD; } if (password.equals(MD5Util.getMD5(args[1]))) { channel.attr(AUTH_KEY).setIfAbsent(AUTH_OBJECT); channel.writeAndFlush("OK" + JConstants.NEWLINE); } else { channel.writeAndFlush("Permission denied!" + JConstants.NEWLINE) .addListener(ChannelFutureListener.CLOSE); } }
private static State state(RequestContext ctx) { final Attribute<State> attr = ctx.attr(STATE); final State state = attr.get(); if (state == null) { final State newState = new State(); final State oldState = attr.setIfAbsent(newState); if (oldState != null) { return oldState; } else { return newState; } } return state; }
@Override public void handle(Channel channel, Command command, String... args) { if (args.length < 2) { channel.writeAndFlush("Need password!" + JConstants.NEWLINE); return; } String password = SystemPropertyUtil.get("monitor.server.password"); if (password == null) { password = DEFAULT_PASSWORD; } if (password.equals(MD5Util.getMD5(args[1]))) { channel.attr(AUTH_KEY).setIfAbsent(AUTH_OBJECT); channel.writeAndFlush("OK" + JConstants.NEWLINE); } else { channel.writeAndFlush("Permission denied!" + JConstants.NEWLINE) .addListener(ChannelFutureListener.CLOSE); } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { InetSocketAddress sourceAddress = sourceAddress(ctx.channel()); ctx.channel().attr(ATTR_SOURCE_INET_ADDR).setIfAbsent(sourceAddress); ctx.channel().attr(ATTR_SOURCE_ADDRESS).setIfAbsent(sourceAddress.getAddress().getHostAddress()); ctx.channel().attr(ATTR_SOURCE_PORT).setIfAbsent(sourceAddress.getPort()); InetSocketAddress localAddress = localAddress(ctx.channel()); ctx.channel().attr(ATTR_LOCAL_INET_ADDR).setIfAbsent(localAddress); ctx.channel().attr(ATTR_LOCAL_ADDRESS).setIfAbsent(localAddress.getAddress().getHostAddress()); ctx.channel().attr(ATTR_LOCAL_PORT).setIfAbsent(localAddress.getPort()); // ATTR_LOCAL_ADDRESS and ATTR_LOCAL_PORT get overwritten with what is received in // Proxy Protocol (via the LB), so set local server's address, port explicitly ctx.channel().attr(ATTR_SERVER_LOCAL_ADDRESS).setIfAbsent(localAddress.getAddress().getHostAddress()); ctx.channel().attr(ATTR_SERVER_LOCAL_PORT).setIfAbsent(localAddress.getPort()); if (INBOUND_TCP_PASSTHROUGH__PORT.get() == ctx.channel().attr(ATTR_SERVER_LOCAL_PORT).get()) { ctx.channel().attr(ATTR_TCP_PASSTHROUGH_INBOUND_CONN).set(true); } super.channelActive(ctx); }
public static AbstractChannel getChannel(ChannelHandlerContext ctx) { Attribute<AbstractChannel> attr = ctx.channel().attr(CHANNEL_KEY); AbstractChannel sofaChannel = attr.get(); if (sofaChannel == null) { sofaChannel = new NettyChannel(ctx); AbstractChannel old = attr.setIfAbsent(sofaChannel); if (old != null) { sofaChannel = old; } } return sofaChannel; }