Example usage for io.netty.util Attribute get

List of usage examples for io.netty.util Attribute get

Introduction

In this page you can find the example usage for io.netty.util Attribute get.

Prototype

T get();

Source Link

Document

Returns the current value, which may be null

Usage

From source file:de.unipassau.isl.evs.ssh.core.network.handler.TimeoutHandler.java

License:Open Source License

public static boolean getPingEnabled(Channel ch) {
    final Attribute<Boolean> attr = ch.attr(SEND_PINGS);
    attr.setIfAbsent(false);//w ww .  j a  va  2  s. c o  m
    return attr.get();
}

From source file:freddo.dtalk2.broker.netty.NettyChannel.java

License:Apache License

public Object getAttribute(AttributeKey<Object> key) {
    Attribute<Object> attr = mContext.attr(key);
    return attr.get();
}

From source file:io.gatling.http.client.pool.ChannelPool.java

License:Apache License

private void incrementStreamCount(Channel channel) {
    Attribute<Integer> streamCountAttr = channel.attr(CHANNEL_POOL_STREAM_COUNT_ATTRIBUTE_KEY);
    streamCountAttr.set(streamCountAttr.get() + 1);
}

From source file:io.gatling.http.client.pool.ChannelPool.java

License:Apache License

public void offer(Channel channel) {
    ChannelPoolKey key = channel.attr(CHANNEL_POOL_KEY_ATTRIBUTE_KEY).get();
    assertNotNull(key, "Channel doesn't have a key");

    if (isHttp1(channel)) {
        remoteChannels(key).offer(channel);
        touch(channel);//from w w w  .ja v a  2s. c  o m
    } else {
        Attribute<Integer> streamCountAttr = channel.attr(CHANNEL_POOL_STREAM_COUNT_ATTRIBUTE_KEY);
        Integer currentStreamCount = streamCountAttr.get();
        if (currentStreamCount == null) {
            remoteChannels(key).offer(channel);
            streamCountAttr.set(1);
        } else {
            streamCountAttr.set(currentStreamCount - 1);
            if (currentStreamCount == 1) {
                // so new value is 0
                touch(channel);
            }
        }
    }
}

From source file:io.grpc.netty.ProtocolNegotiators.java

License:Apache License

private static ChannelLogger negotiationLogger(AttributeMap attributeMap) {
    Attribute<ChannelLogger> attr = attributeMap.attr(NettyClientTransport.LOGGER_KEY);
    final ChannelLogger channelLogger = attr.get();
    if (channelLogger != null) {
        return channelLogger;
    }/* ww  w  .  ja v  a  2  s  . c om*/
    // This is only for tests where there may not be a valid logger.
    final class NoopChannelLogger extends ChannelLogger {

        @Override
        public void log(ChannelLogLevel level, String message) {
        }

        @Override
        public void log(ChannelLogLevel level, String messageFormat, Object... args) {
        }
    }

    return new NoopChannelLogger();
}

From source file:io.moquette.parser.netty.ConnectDecoderTest.java

License:Open Source License

@Test
public void testBaseHeader_311() throws UnsupportedEncodingException {
    m_buff = Unpooled.buffer(12);/*from w w  w. j a v  a2 s .c o m*/
    initBaseHeader311(m_buff);
    List<Object> results = new ArrayList<>();

    //Excercise
    m_msgdec.decode(this.attrMap, m_buff, results);

    //Verify
    assertFalse(results.isEmpty());
    verifyBaseHeader311((ConnectMessage) results.get(0));
    Attribute<Integer> attr = this.attrMap.attr(MQTTDecoder.PROTOCOL_VERSION);
    assertEquals(VERSION_3_1_1, attr.get().intValue());
}

From source file:io.moquette.parser.netty.ConnectDecoderTest.java

License:Open Source License

@Test(expected = CorruptedFrameException.class)
public void testBaseHeader_311_withFlagsTouched() throws UnsupportedEncodingException {
    m_buff = Unpooled.buffer(12);/*  www  .  j av  a  2s .  c o m*/
    initBaseHeader311_withFixedFlags(m_buff, (byte) 0x01);
    List<Object> results = new ArrayList<Object>();

    //Excercise
    m_msgdec.decode(this.attrMap, m_buff, results);

    //Verify
    assertFalse(results.isEmpty());
    verifyBaseHeader311((ConnectMessage) results.get(0));
    Attribute<Integer> attr = this.attrMap.attr(MQTTDecoder.PROTOCOL_VERSION);
    assertEquals(VERSION_3_1_1, attr.get().intValue());
}

From source file:io.moquette.parser.netty.ConnectDecoderTest.java

License:Open Source License

@Test(expected = CorruptedFrameException.class)
public void testConnectFlags_311_withNot0Reserved() throws UnsupportedEncodingException {
    m_buff = Unpooled.buffer(12);//from www . ja  va2 s.c  o  m
    initBaseHeader311_withFixedFlags(m_buff, (byte) 0, (byte) 0xCF); // sets the bit(0) = 1
    List<Object> results = new ArrayList<Object>();

    //Excercise
    m_msgdec.decode(this.attrMap, m_buff, results);

    //Verify
    assertFalse(results.isEmpty());
    verifyBaseHeader311((ConnectMessage) results.get(0));
    Attribute<Integer> attr = this.attrMap.attr(MQTTDecoder.PROTOCOL_VERSION);
    assertEquals(VERSION_3_1_1, attr.get().intValue());
}

From source file:io.moquette.server.netty.NettyChannel.java

License:Open Source License

public Object getAttribute(AttributeKey<Object> key) {
    Attribute<Object> attr = m_channel.attr(key);
    return attr.get();
}

From source file:net.hasor.rsf.console.TelnetHandler.java

License:Apache License

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    InetSocketAddress inetAddress = (InetSocketAddress) ctx.channel().remoteAddress();
    String remoteAddress = inetAddress.getAddress().getHostAddress();
    ///*from   www.  jav  a  2  s.c  o m*/
    boolean contains = false;
    for (String addr : this.inBoundAddress) {
        if (addr.equals(remoteAddress))
            contains = true;
    }
    //
    if (!contains) {
        logger.warn("rsfConsole -> reject inBound socket ,remoteAddress = {}.", remoteAddress);
        ctx.write("--------------------------------------------\r\n\r\n");
        ctx.write("I'm sorry you are not allowed to connect RSF Console.\r\n\r\n");
        ctx.write(" your address is :" + remoteAddress + "\r\n");
        ctx.write("--------------------------------------------\r\n");
        ctx.flush();
        ctx.close();
        return;
    } else {
        logger.info("rsfConsole -> accept inBound socket ,remoteAddress = {}.", remoteAddress);
    }
    //
    RsfSettings settings = this.rsfContext.getSettings();
    List<String> rsfAddressList = getStrings(settings.getBindAddressSet());
    //
    Attribute<RsfCommandSession> attr = ctx.attr(SessionKEY);
    if (attr.get() == null) {
        logger.info("rsfConsole -> new  RsfCommandSession.");
        attr.set(new RsfCommandSession(this.rsfContext, ctx));
    }
    logger.info("rsfConsole -> send Welcome info.");
    // Send greeting for a new connection.
    ctx.write("--------------------------------------------\r\n\r\n");
    ctx.write("Welcome to RSF Console!\r\n");
    ctx.write("\r\n");
    ctx.write("     login : " + new Date() + " now. form " + ctx.channel().remoteAddress() + "\r\n");
    ctx.write("    workAt : " + ctx.channel().localAddress() + "\r\n");
    for (int i = 0; i < rsfAddressList.size(); i++) {
        if (i == 0) {
            ctx.write("rsfAddress : " + rsfAddressList.get(i) + "\r\n");
        } else {
            ctx.write("           : " + rsfAddressList.get(i) + "\r\n");
        }
    }
    ctx.write("  unitName : " + this.rsfContext.getSettings().getUnitName() + "\r\n\r\n");
    ctx.write("Tips: You can enter a 'help' or 'help -a' for more information.\r\n");
    ctx.write("use the 'exit' or 'quit' out of the console.\r\n");
    ctx.write("--------------------------------------------\r\n");
    ctx.write(CMD);
    ctx.flush();
}