1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.memcache.binary;
17
18 import io.netty.buffer.ByteBuf;
19 import io.netty.buffer.Unpooled;
20 import io.netty.util.internal.ObjectUtil;
21 import io.netty.util.internal.UnstableApi;
22
23
24
25
26 @UnstableApi
27 public class DefaultFullBinaryMemcacheResponse extends DefaultBinaryMemcacheResponse
28 implements FullBinaryMemcacheResponse {
29
30 private final ByteBuf content;
31
32
33
34
35
36
37
38 public DefaultFullBinaryMemcacheResponse(ByteBuf key, ByteBuf extras) {
39 this(key, extras, Unpooled.buffer(0));
40 }
41
42
43
44
45
46
47
48
49 public DefaultFullBinaryMemcacheResponse(ByteBuf key, ByteBuf extras,
50 ByteBuf content) {
51 super(key, extras);
52 this.content = ObjectUtil.checkNotNull(content, "content");
53 setTotalBodyLength(keyLength() + extrasLength() + content.readableBytes());
54 }
55
56 @Override
57 public ByteBuf content() {
58 return content;
59 }
60
61 @Override
62 public FullBinaryMemcacheResponse retain() {
63 super.retain();
64 return this;
65 }
66
67 @Override
68 public FullBinaryMemcacheResponse retain(int increment) {
69 super.retain(increment);
70 return this;
71 }
72
73 @Override
74 public FullBinaryMemcacheResponse touch() {
75 super.touch();
76 return this;
77 }
78
79 @Override
80 public FullBinaryMemcacheResponse touch(Object hint) {
81 super.touch(hint);
82 content.touch(hint);
83 return this;
84 }
85
86 @Override
87 protected void deallocate() {
88 super.deallocate();
89 content.release();
90 }
91
92 @Override
93 public FullBinaryMemcacheResponse copy() {
94 ByteBuf key = key();
95 if (key != null) {
96 key = key.copy();
97 }
98 ByteBuf extras = extras();
99 if (extras != null) {
100 extras = extras.copy();
101 }
102 return newInstance(key, extras, content().copy());
103 }
104
105 @Override
106 public FullBinaryMemcacheResponse duplicate() {
107 ByteBuf key = key();
108 if (key != null) {
109 key = key.duplicate();
110 }
111 ByteBuf extras = extras();
112 if (extras != null) {
113 extras = extras.duplicate();
114 }
115 return newInstance(key, extras, content().duplicate());
116 }
117
118 @Override
119 public FullBinaryMemcacheResponse retainedDuplicate() {
120 return replace(content().retainedDuplicate());
121 }
122
123 @Override
124 public FullBinaryMemcacheResponse replace(ByteBuf content) {
125 ByteBuf key = key();
126 if (key != null) {
127 key = key.retainedDuplicate();
128 }
129 ByteBuf extras = extras();
130 if (extras != null) {
131 extras = extras.retainedDuplicate();
132 }
133 return newInstance(key, extras, content);
134 }
135
136 private FullBinaryMemcacheResponse newInstance(ByteBuf key, ByteBuf extras, ByteBuf content) {
137 DefaultFullBinaryMemcacheResponse newInstance = new DefaultFullBinaryMemcacheResponse(key, extras, content);
138 copyMeta(newInstance);
139 return newInstance;
140 }
141 }