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.handler.codec.memcache.MemcacheMessage;
20  
21  /**
22   * An interface that defines a binary Memcache message, providing common properties for
23   * {@link BinaryMemcacheRequest} and {@link BinaryMemcacheResponse}.
24   * <p/>
25   * A {@link BinaryMemcacheMessage} always consists of a header and optional extras or/and
26   * a key.
27   *
28   * @see BinaryMemcacheRequest
29   * @see BinaryMemcacheResponse
30   */
31  public interface BinaryMemcacheMessage extends MemcacheMessage {
32  
33      /**
34       * Returns the magic byte for the message.
35       *
36       * @return the magic byte.
37       */
38      byte magic();
39  
40      /**
41       * Sets the magic byte.
42       *
43       * @param magic the magic byte to use.
44       * @see BinaryMemcacheOpcodes for typesafe opcodes.
45       */
46      BinaryMemcacheMessage setMagic(byte magic);
47  
48      /**
49       * Returns the opcode for the message.
50       *
51       * @return the opcode.
52       */
53      byte opcode();
54  
55      /**
56       * Sets the opcode for the message.
57       *
58       * @param code the opcode to use.
59       */
60      BinaryMemcacheMessage setOpcode(byte code);
61  
62      /**
63       * Returns the key length of the message.
64       * <p/>
65       * This may return 0, since the key is optional.
66       *
67       * @return the key length.
68       */
69      short keyLength();
70  
71      /**
72       * Set the key length of the message.
73       * <p/>
74       * This may be 0, since the key is optional.
75       *
76       * @param keyLength the key length to use.
77       */
78      BinaryMemcacheMessage setKeyLength(short keyLength);
79  
80      /**
81       * Return the extras length of the message.
82       * <p/>
83       * This may be 0, since the extras content is optional.
84       *
85       * @return the extras length.
86       */
87      byte extrasLength();
88  
89      /**
90       * Set the extras length of the message.
91       * <p/>
92       * This may be 0, since the extras content is optional.
93       *
94       * @param extrasLength the extras length.
95       */
96      BinaryMemcacheMessage setExtrasLength(byte extrasLength);
97  
98      /**
99       * Returns the data type of the message.
100      *
101      * @return the data type of the message.
102      */
103     byte dataType();
104 
105     /**
106      * Sets the data type of the message.
107      *
108      * @param dataType the data type of the message.
109      */
110     BinaryMemcacheMessage setDataType(byte dataType);
111 
112     /**
113      * Returns the total body length.
114      * <p/>
115      * Note that this may be 0, since the body is optional.
116      *
117      * @return the total body length.
118      */
119     int totalBodyLength();
120 
121     /**
122      * Sets the total body length.
123      * <p/>
124      * Note that this may be 0, since the body length is optional.
125      *
126      * @param totalBodyLength the total body length.
127      */
128     BinaryMemcacheMessage setTotalBodyLength(int totalBodyLength);
129 
130     /**
131      * Returns the opaque value.
132      *
133      * @return the opaque value.
134      */
135     int opaque();
136 
137     /**
138      * Sets the opaque value.
139      *
140      * @param opaque the opqaue value to use.
141      */
142     BinaryMemcacheMessage setOpaque(int opaque);
143 
144     /**
145      * Returns the CAS identifier.
146      *
147      * @return the CAS identifier.
148      */
149     long cas();
150 
151     /**
152      * Sets the CAS identifier.
153      *
154      * @param cas the CAS identifier to use.
155      */
156     BinaryMemcacheMessage setCas(long cas);
157 
158     /**
159      * Returns the optional key of the document.
160      *
161      * @return the key of the document.
162      */
163     String key();
164 
165     /**
166      * Sets the key of the document.
167      *
168      * @param key the key of the message.
169      */
170     BinaryMemcacheMessage setKey(String key);
171 
172     /**
173      * Returns a {@link ByteBuf} representation of the optional extras.
174      *
175      * @return the optional extras.
176      */
177     ByteBuf extras();
178 
179     /**
180      * Sets the extras buffer on the message.
181      *
182      * @param extras the extras buffer of the document.
183      */
184     BinaryMemcacheMessage setExtras(ByteBuf extras);
185 
186     /**
187      * Increases the reference count by {@code 1}.
188      */
189     @Override
190     BinaryMemcacheMessage retain();
191 
192     /**
193      * Increases the reference count by the specified {@code increment}.
194      */
195     @Override
196     BinaryMemcacheMessage retain(int increment);
197 
198     @Override
199     BinaryMemcacheMessage touch();
200 
201     @Override
202     BinaryMemcacheMessage touch(Object hint);
203 }