View Javadoc
1   /*
2    * Copyright 2013 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.memcache.binary;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.Unpooled;
20  
21  /**
22   * The default implementation of a {@link FullBinaryMemcacheRequest}.
23   */
24  public class DefaultFullBinaryMemcacheRequest extends DefaultBinaryMemcacheRequest
25      implements FullBinaryMemcacheRequest {
26  
27      private final ByteBuf content;
28  
29      /**
30       * Create a new {@link DefaultBinaryMemcacheRequest} with the header, key and extras.
31       *
32       * @param key    the key to use.
33       * @param extras the extras to use.
34       */
35      public DefaultFullBinaryMemcacheRequest(String key, ByteBuf extras) {
36          this(key, extras, Unpooled.buffer(0));
37      }
38  
39      /**
40       * Create a new {@link DefaultBinaryMemcacheRequest} with the header, key, extras and content.
41       *
42       * @param key     the key to use.
43       * @param extras  the extras to use.
44       * @param content the content of the full request.
45       */
46      public DefaultFullBinaryMemcacheRequest(String key, ByteBuf extras,
47                                              ByteBuf content) {
48          super(key, extras);
49          if (content == null) {
50              throw new NullPointerException("Supplied content is null.");
51          }
52  
53          this.content = content;
54      }
55  
56      @Override
57      public ByteBuf content() {
58          return content;
59      }
60  
61      @Override
62      public int refCnt() {
63          return content.refCnt();
64      }
65  
66      @Override
67      public FullBinaryMemcacheRequest retain() {
68          super.retain();
69          content.retain();
70          return this;
71      }
72  
73      @Override
74      public FullBinaryMemcacheRequest retain(int increment) {
75          super.retain(increment);
76          content.retain(increment);
77          return this;
78      }
79  
80      @Override
81      public FullBinaryMemcacheRequest touch() {
82          super.touch();
83          content.touch();
84          return this;
85      }
86  
87      @Override
88      public FullBinaryMemcacheRequest touch(Object hint) {
89          super.touch(hint);
90          content.touch(hint);
91          return this;
92      }
93  
94      @Override
95      public boolean release() {
96          super.release();
97          return content.release();
98      }
99  
100     @Override
101     public boolean release(int decrement) {
102         super.release(decrement);
103         return content.release(decrement);
104     }
105 
106     @Override
107     public FullBinaryMemcacheRequest copy() {
108         ByteBuf extras = extras();
109         if (extras != null) {
110             extras = extras.copy();
111         }
112         return new DefaultFullBinaryMemcacheRequest(key(), extras, content().copy());
113     }
114 
115     @Override
116     public FullBinaryMemcacheRequest duplicate() {
117         ByteBuf extras = extras();
118         if (extras != null) {
119             extras = extras.duplicate();
120         }
121         return new DefaultFullBinaryMemcacheRequest(key(), extras, content().duplicate());
122     }
123 }