1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package io.netty.handler.codec.redis;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.channel.ChannelHandler;
20  import io.netty.channel.ChannelPipeline;
21  import io.netty.handler.codec.MessageAggregator;
22  import io.netty.util.internal.UnstableApi;
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  @UnstableApi
43  public final class RedisBulkStringAggregator extends MessageAggregator<RedisMessage, BulkStringHeaderRedisMessage,
44                                                                   BulkStringRedisContent, FullBulkStringRedisMessage> {
45  
46      
47  
48  
49      public RedisBulkStringAggregator() {
50          super(RedisConstants.REDIS_MESSAGE_MAX_LENGTH, RedisMessage.class);
51      }
52  
53      @Override
54      protected boolean isStartMessage(RedisMessage msg) throws Exception {
55          return msg instanceof BulkStringHeaderRedisMessage && !isAggregated(msg);
56      }
57  
58      @Override
59      protected boolean isContentMessage(RedisMessage msg) throws Exception {
60          return msg instanceof BulkStringRedisContent;
61      }
62  
63      @Override
64      protected boolean isLastContentMessage(BulkStringRedisContent msg) throws Exception {
65          return msg instanceof LastBulkStringRedisContent;
66      }
67  
68      @Override
69      protected boolean isAggregated(RedisMessage msg) throws Exception {
70          return msg instanceof FullBulkStringRedisMessage;
71      }
72  
73      @Override
74      protected boolean isContentLengthInvalid(BulkStringHeaderRedisMessage start, int maxContentLength)
75              throws Exception {
76          return start.bulkStringLength() > maxContentLength;
77      }
78  
79      @Override
80      protected Object newContinueResponse(BulkStringHeaderRedisMessage start, int maxContentLength,
81                                           ChannelPipeline pipeline) throws Exception {
82          return null;
83      }
84  
85      @Override
86      protected boolean closeAfterContinueResponse(Object msg) throws Exception {
87          throw new UnsupportedOperationException();
88      }
89  
90      @Override
91      protected boolean ignoreContentAfterContinueResponse(Object msg) throws Exception {
92          throw new UnsupportedOperationException();
93      }
94  
95      @Override
96      protected FullBulkStringRedisMessage beginAggregation(BulkStringHeaderRedisMessage start, ByteBuf content)
97              throws Exception {
98          return new FullBulkStringRedisMessage(content);
99      }
100 }