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;
17  
18  import io.netty.channel.ChannelHandler;
19  import io.netty.channel.ChannelPipeline;
20  import io.netty.handler.codec.MessageAggregator;
21  import io.netty.handler.codec.memcache.binary.BinaryMemcacheRequestDecoder;
22  import io.netty.handler.codec.memcache.binary.BinaryMemcacheResponseEncoder;
23  import io.netty.util.internal.UnstableApi;
24  
25  /**
26   * A {@link ChannelHandler} that aggregates an {@link MemcacheMessage}
27   * and its following {@link MemcacheContent}s into a single {@link MemcacheMessage} with
28   * no following {@link MemcacheContent}s.  It is useful when you don't want to take
29   * care of memcache messages where the content comes along in chunks. Insert this
30   * handler after a AbstractMemcacheObjectDecoder in the {@link ChannelPipeline}.
31   * <p/>
32   * For example, here for the binary protocol:
33   * <p/>
34   * <pre>
35   * {@link ChannelPipeline} p = ...;
36   * ...
37   * p.addLast("decoder", new {@link BinaryMemcacheRequestDecoder}());
38   * p.addLast("aggregator", <b>new {@link io.netty.handler.codec.memcache.binary.BinaryMemcacheObjectAggregator}(1048576)
39   * </b>);
40   * ...
41   * p.addLast("encoder", new {@link BinaryMemcacheResponseEncoder}());
42   * p.addLast("handler", new YourMemcacheRequestHandler());
43   * </pre>
44   */
45  @UnstableApi
46  public abstract class AbstractMemcacheObjectAggregator<H extends MemcacheMessage> extends
47          MessageAggregator<MemcacheObject, H, MemcacheContent, FullMemcacheMessage> {
48  
49      protected AbstractMemcacheObjectAggregator(int maxContentLength) {
50          super(maxContentLength);
51      }
52  
53      @Override
54      protected boolean isContentMessage(MemcacheObject msg) throws Exception {
55          return msg instanceof MemcacheContent;
56      }
57  
58      @Override
59      protected boolean isLastContentMessage(MemcacheContent msg) throws Exception {
60          return msg instanceof LastMemcacheContent;
61      }
62  
63      @Override
64      protected boolean isAggregated(MemcacheObject msg) throws Exception {
65          return msg instanceof FullMemcacheMessage;
66      }
67  
68      @Override
69      protected boolean isContentLengthInvalid(H start, int maxContentLength) {
70          return false;
71      }
72  
73      @Override
74      protected Object newContinueResponse(H start, int maxContentLength, ChannelPipeline pipeline) {
75          return null;
76      }
77  
78      @Override
79      protected boolean closeAfterContinueResponse(Object msg) throws Exception {
80          throw new UnsupportedOperationException();
81      }
82  
83      @Override
84      protected boolean ignoreContentAfterContinueResponse(Object msg) throws Exception {
85          throw new UnsupportedOperationException();
86      }
87  }