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    *   https://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.util.internal.UnstableApi;
20  
21  /**
22   * The default implementation of the {@link BinaryMemcacheResponse}.
23   */
24  @UnstableApi
25  public class DefaultBinaryMemcacheResponse extends AbstractBinaryMemcacheMessage implements BinaryMemcacheResponse {
26  
27      /**
28       * Default magic byte for a request.
29       */
30      public static final byte RESPONSE_MAGIC_BYTE = (byte) 0x81;
31  
32      private short status;
33  
34      /**
35       * Create a new {@link DefaultBinaryMemcacheResponse} with the header only.
36       */
37      public DefaultBinaryMemcacheResponse() {
38          this(null, null);
39      }
40  
41      /**
42       * Create a new {@link DefaultBinaryMemcacheResponse} with the header and key.
43       *
44       * @param key    the key to use.
45       */
46      public DefaultBinaryMemcacheResponse(ByteBuf key) {
47          this(key, null);
48      }
49  
50      /**
51       * Create a new {@link DefaultBinaryMemcacheResponse} with the header, key and extras.
52       *
53       * @param key    the key to use.
54       * @param extras the extras to use.
55       */
56      public DefaultBinaryMemcacheResponse(ByteBuf key, ByteBuf extras) {
57          super(key, extras);
58          setMagic(RESPONSE_MAGIC_BYTE);
59      }
60  
61      @Override
62      public short status() {
63          return status;
64      }
65  
66      @Override
67      public BinaryMemcacheResponse setStatus(short status) {
68          this.status = status;
69          return this;
70      }
71  
72      @Override
73      public BinaryMemcacheResponse retain() {
74          super.retain();
75          return this;
76      }
77  
78      @Override
79      public BinaryMemcacheResponse retain(int increment) {
80          super.retain(increment);
81          return this;
82      }
83  
84      @Override
85      public BinaryMemcacheResponse touch() {
86          super.touch();
87          return this;
88      }
89  
90      @Override
91      public BinaryMemcacheResponse touch(Object hint) {
92          super.touch(hint);
93          return this;
94      }
95  
96      /**
97       * Copies special metadata hold by this instance to the provided instance
98       *
99       * @param dst The instance where to copy the metadata of this instance to
100      */
101     void copyMeta(DefaultBinaryMemcacheResponse dst) {
102         super.copyMeta(dst);
103         dst.status = status;
104     }
105 }