1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.redis;
17
18 import io.netty.util.AbstractReferenceCounted;
19 import io.netty.util.ReferenceCountUtil;
20 import io.netty.util.internal.ObjectUtil;
21 import io.netty.util.internal.StringUtil;
22 import io.netty.util.internal.UnstableApi;
23
24 import java.util.Collections;
25 import java.util.List;
26
27
28
29
30 @UnstableApi
31 public class ArrayRedisMessage extends AbstractReferenceCounted implements RedisMessage {
32
33 private final List<RedisMessage> children;
34
35 private ArrayRedisMessage() {
36 children = Collections.emptyList();
37 }
38
39
40
41
42
43
44 public ArrayRedisMessage(List<RedisMessage> children) {
45
46 this.children = ObjectUtil.checkNotNull(children, "children");
47 }
48
49
50
51
52
53
54 public final List<RedisMessage> children() {
55 return children;
56 }
57
58
59
60
61
62
63 public boolean isNull() {
64 return false;
65 }
66
67 @Override
68 protected void deallocate() {
69 for (RedisMessage msg : children) {
70 ReferenceCountUtil.release(msg);
71 }
72 }
73
74 @Override
75 public ArrayRedisMessage touch(Object hint) {
76 for (RedisMessage msg : children) {
77 ReferenceCountUtil.touch(msg);
78 }
79 return this;
80 }
81
82 @Override
83 public String toString() {
84 return new StringBuilder(StringUtil.simpleClassName(this))
85 .append('[')
86 .append("children=")
87 .append(children.size())
88 .append(']').toString();
89 }
90
91
92
93
94 public static final ArrayRedisMessage NULL_INSTANCE = new ArrayRedisMessage() {
95 @Override
96 public boolean isNull() {
97 return true;
98 }
99
100 @Override
101 public ArrayRedisMessage retain() {
102 return this;
103 }
104
105 @Override
106 public ArrayRedisMessage retain(int increment) {
107 return this;
108 }
109
110 @Override
111 public ArrayRedisMessage touch() {
112 return this;
113 }
114
115 @Override
116 public ArrayRedisMessage touch(Object hint) {
117 return this;
118 }
119
120 @Override
121 public boolean release() {
122 return false;
123 }
124
125 @Override
126 public boolean release(int decrement) {
127 return false;
128 }
129
130 @Override
131 public String toString() {
132 return "NullArrayRedisMessage";
133 }
134 };
135
136
137
138
139 public static final ArrayRedisMessage EMPTY_INSTANCE = new ArrayRedisMessage() {
140
141 @Override
142 public ArrayRedisMessage retain() {
143 return this;
144 }
145
146 @Override
147 public ArrayRedisMessage retain(int increment) {
148 return this;
149 }
150
151 @Override
152 public ArrayRedisMessage touch() {
153 return this;
154 }
155
156 @Override
157 public ArrayRedisMessage touch(Object hint) {
158 return this;
159 }
160
161 @Override
162 public boolean release() {
163 return false;
164 }
165
166 @Override
167 public boolean release(int decrement) {
168 return false;
169 }
170
171 @Override
172 public String toString() {
173 return "EmptyArrayRedisMessage";
174 }
175 };
176
177 }