netty

来源:互联网 发布:淘宝素材网站有哪些 编辑:程序博客网 时间:2024/05/18 12:40

本测试类是为了演示netty 4.1.9 版本中的DefaultAttributeMap的用法,至于DefaultAttributeMap内部数据结构解析改天再完善,主要现在有急事,粘贴完我就走人。

package com.lihong.DDPush;import io.netty.util.Attribute;import io.netty.util.AttributeKey;import io.netty.util.DefaultAttributeMap;import org.junit.Test;/** * Created by lihong10 on 2017/5/27. */public class AttributeTest {    @Test    public void testAttributeKey() {        System.out.println(Integer.toBinaryString(-1));        AttributeKey<String> key1 = AttributeKey.newInstance("aa");        AttributeKey<String> key2 = AttributeKey.newInstance("bb");        AttributeKey<String> key3 = AttributeKey.newInstance("cc");        AttributeKey<String> key4 = AttributeKey.newInstance("dd");        AttributeKey<String> key5 = AttributeKey.newInstance("ee");        AttributeKey<String> key6 = AttributeKey.newInstance("ff");        AttributeKey<String> key7 = AttributeKey.newInstance("gg");        DefaultAttributeMap map = new DefaultAttributeMap();        Attribute<String> attr1 = map.attr(key1);        Attribute<String> attr2 = map.attr(key2);        Attribute<String> attr3 = map.attr(key3);        Attribute<String> attr4 = map.attr(key4);        Attribute<String> attr5 = map.attr(key5);        Attribute<String> attr6 = map.attr(key6);        Attribute<String> attr7 = map.attr(key7);        System.out.println(attr1.getClass());        attr1.set("aa-value");        attr2.set("bb-value");        attr3.set("cc-value");        attr1.remove();        Attribute<String> attr1_1 = map.attr(key1);        attr1_1.set("aa-new-value");        System.out.println(map.hasAttr(key1));        System.out.println(1&3);        System.out.println(2&3);        System.out.println(3&3);        System.out.println(4&3);        System.out.println(5&3);        System.out.println(6&3);        System.out.println(7&3);        System.out.println(map.hasAttr(key1));        System.out.println(map.hasAttr(key2));        System.out.println(map.hasAttr(key3));        System.out.println(map.hasAttr(key4));        System.out.println(map.hasAttr(key5));        System.out.println(map.hasAttr(key6));        System.out.println(map.hasAttr(key7));   }}
原创粉丝点击