2013-10-01 15:42:05 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2013 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
package io.netty.handler.codec.memcache.binary;
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.Unpooled;
|
2016-04-12 14:22:41 +02:00
|
|
|
import io.netty.util.internal.UnstableApi;
|
2013-10-01 15:42:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The default implementation of a {@link FullBinaryMemcacheResponse}.
|
|
|
|
*/
|
2016-04-12 14:22:41 +02:00
|
|
|
@UnstableApi
|
2013-10-01 15:42:05 +02:00
|
|
|
public class DefaultFullBinaryMemcacheResponse extends DefaultBinaryMemcacheResponse
|
|
|
|
implements FullBinaryMemcacheResponse {
|
|
|
|
|
|
|
|
private final ByteBuf content;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new {@link DefaultFullBinaryMemcacheResponse} with the header, key and extras.
|
|
|
|
*
|
|
|
|
* @param key the key to use.
|
|
|
|
* @param extras the extras to use.
|
|
|
|
*/
|
2016-01-29 18:58:35 +01:00
|
|
|
public DefaultFullBinaryMemcacheResponse(ByteBuf key, ByteBuf extras) {
|
2014-02-28 08:08:40 +01:00
|
|
|
this(key, extras, Unpooled.buffer(0));
|
2013-10-01 15:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new {@link DefaultFullBinaryMemcacheResponse} with the header, key, extras and content.
|
|
|
|
*
|
|
|
|
* @param key the key to use.
|
|
|
|
* @param extras the extras to use.
|
|
|
|
* @param content the content of the full request.
|
|
|
|
*/
|
2016-01-29 18:58:35 +01:00
|
|
|
public DefaultFullBinaryMemcacheResponse(ByteBuf key, ByteBuf extras,
|
2014-02-28 08:08:40 +01:00
|
|
|
ByteBuf content) {
|
|
|
|
super(key, extras);
|
2013-10-01 15:42:05 +02:00
|
|
|
if (content == null) {
|
|
|
|
throw new NullPointerException("Supplied content is null.");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.content = content;
|
2016-04-05 01:23:17 +02:00
|
|
|
setTotalBodyLength(keyLength() + extrasLength() + content.readableBytes());
|
2013-10-01 15:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ByteBuf content() {
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FullBinaryMemcacheResponse retain() {
|
2014-06-24 08:04:50 +02:00
|
|
|
super.retain();
|
2013-10-01 15:42:05 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FullBinaryMemcacheResponse retain(int increment) {
|
2014-06-24 08:04:50 +02:00
|
|
|
super.retain(increment);
|
2013-10-01 15:42:05 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-01-28 12:00:28 +01:00
|
|
|
@Override
|
|
|
|
public FullBinaryMemcacheResponse touch() {
|
2014-06-24 08:04:50 +02:00
|
|
|
super.touch();
|
2014-01-28 12:00:28 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2014-01-29 03:44:59 +01:00
|
|
|
@Override
|
|
|
|
public FullBinaryMemcacheResponse touch(Object hint) {
|
2014-06-24 08:04:50 +02:00
|
|
|
super.touch(hint);
|
2014-01-29 03:44:59 +01:00
|
|
|
content.touch(hint);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-10-01 15:42:05 +02:00
|
|
|
@Override
|
2016-01-31 00:53:11 +01:00
|
|
|
protected void deallocate() {
|
|
|
|
super.deallocate();
|
|
|
|
content.release();
|
2013-10-01 15:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FullBinaryMemcacheResponse copy() {
|
2016-01-29 18:58:35 +01:00
|
|
|
ByteBuf key = key();
|
|
|
|
if (key != null) {
|
|
|
|
key = key.copy();
|
|
|
|
}
|
2014-06-24 09:08:46 +02:00
|
|
|
ByteBuf extras = extras();
|
2014-06-24 08:04:50 +02:00
|
|
|
if (extras != null) {
|
|
|
|
extras = extras.copy();
|
|
|
|
}
|
2019-05-22 11:05:52 +02:00
|
|
|
return newInstance(key, extras, content().copy());
|
2013-10-01 15:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FullBinaryMemcacheResponse duplicate() {
|
2016-01-29 18:58:35 +01:00
|
|
|
ByteBuf key = key();
|
|
|
|
if (key != null) {
|
|
|
|
key = key.duplicate();
|
|
|
|
}
|
2014-06-24 09:08:46 +02:00
|
|
|
ByteBuf extras = extras();
|
2014-06-24 08:04:50 +02:00
|
|
|
if (extras != null) {
|
|
|
|
extras = extras.duplicate();
|
|
|
|
}
|
2019-05-22 11:05:52 +02:00
|
|
|
return newInstance(key, extras, content().duplicate());
|
2013-10-01 15:42:05 +02:00
|
|
|
}
|
2016-04-14 10:31:48 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public FullBinaryMemcacheResponse retainedDuplicate() {
|
|
|
|
return replace(content().retainedDuplicate());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FullBinaryMemcacheResponse replace(ByteBuf content) {
|
|
|
|
ByteBuf key = key();
|
|
|
|
if (key != null) {
|
|
|
|
key = key.retainedDuplicate();
|
|
|
|
}
|
|
|
|
ByteBuf extras = extras();
|
|
|
|
if (extras != null) {
|
|
|
|
extras = extras.retainedDuplicate();
|
|
|
|
}
|
2019-05-22 11:05:52 +02:00
|
|
|
return newInstance(key, extras, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
private FullBinaryMemcacheResponse newInstance(ByteBuf key, ByteBuf extras, ByteBuf content) {
|
|
|
|
DefaultFullBinaryMemcacheResponse newInstance = new DefaultFullBinaryMemcacheResponse(key, extras, content);
|
|
|
|
copyMeta(newInstance);
|
|
|
|
return newInstance;
|
2016-04-14 10:31:48 +02:00
|
|
|
}
|
2013-10-01 15:42:05 +02:00
|
|
|
}
|