@@ -35,7 +35,6 @@ public void onPSubscribe(String pattern, int subscribedChannels) {
35
35
}
36
36
37
37
public void onPong (String pattern ) {
38
-
39
38
}
40
39
41
40
public void unsubscribe () {
@@ -132,52 +131,66 @@ public void proceed(Connection client, String... channels) {
132
131
private void process () {
133
132
134
133
do {
135
- List <Object > reply = client .getUnflushedObjectMultiBulkReply ();
136
- final Object firstObj = reply .get (0 );
137
- if (!(firstObj instanceof byte [])) {
138
- throw new JedisException ("Unknown message type: " + firstObj );
139
- }
140
- final byte [] resp = (byte []) firstObj ;
141
- if (Arrays .equals (SUBSCRIBE .getRaw (), resp )) {
142
- subscribedChannels = ((Long ) reply .get (2 )).intValue ();
143
- final byte [] bchannel = (byte []) reply .get (1 );
144
- final String strchannel = (bchannel == null ) ? null : SafeEncoder .encode (bchannel );
145
- onSubscribe (strchannel , subscribedChannels );
146
- } else if (Arrays .equals (UNSUBSCRIBE .getRaw (), resp )) {
147
- subscribedChannels = ((Long ) reply .get (2 )).intValue ();
148
- final byte [] bchannel = (byte []) reply .get (1 );
149
- final String strchannel = (bchannel == null ) ? null : SafeEncoder .encode (bchannel );
150
- onUnsubscribe (strchannel , subscribedChannels );
151
- } else if (Arrays .equals (MESSAGE .getRaw (), resp )) {
152
- final byte [] bchannel = (byte []) reply .get (1 );
153
- final byte [] bmesg = (byte []) reply .get (2 );
154
- final String strchannel = (bchannel == null ) ? null : SafeEncoder .encode (bchannel );
155
- final String strmesg = (bmesg == null ) ? null : SafeEncoder .encode (bmesg );
156
- onMessage (strchannel , strmesg );
157
- } else if (Arrays .equals (PMESSAGE .getRaw (), resp )) {
158
- final byte [] bpattern = (byte []) reply .get (1 );
159
- final byte [] bchannel = (byte []) reply .get (2 );
160
- final byte [] bmesg = (byte []) reply .get (3 );
161
- final String strpattern = (bpattern == null ) ? null : SafeEncoder .encode (bpattern );
162
- final String strchannel = (bchannel == null ) ? null : SafeEncoder .encode (bchannel );
163
- final String strmesg = (bmesg == null ) ? null : SafeEncoder .encode (bmesg );
164
- onPMessage (strpattern , strchannel , strmesg );
165
- } else if (Arrays .equals (PSUBSCRIBE .getRaw (), resp )) {
166
- subscribedChannels = ((Long ) reply .get (2 )).intValue ();
167
- final byte [] bpattern = (byte []) reply .get (1 );
168
- final String strpattern = (bpattern == null ) ? null : SafeEncoder .encode (bpattern );
169
- onPSubscribe (strpattern , subscribedChannels );
170
- } else if (Arrays .equals (PUNSUBSCRIBE .getRaw (), resp )) {
171
- subscribedChannels = ((Long ) reply .get (2 )).intValue ();
172
- final byte [] bpattern = (byte []) reply .get (1 );
173
- final String strpattern = (bpattern == null ) ? null : SafeEncoder .encode (bpattern );
174
- onPUnsubscribe (strpattern , subscribedChannels );
175
- } else if (Arrays .equals (PONG .getRaw (), resp )) {
176
- final byte [] bpattern = (byte []) reply .get (1 );
177
- final String strpattern = (bpattern == null ) ? null : SafeEncoder .encode (bpattern );
178
- onPong (strpattern );
134
+ Object reply = client .getUnflushedObject ();
135
+
136
+ if (reply instanceof List ) {
137
+ List <Object > listReply = (List <Object >) reply ;
138
+ final Object firstObj = listReply .get (0 );
139
+ if (!(firstObj instanceof byte [])) {
140
+ throw new JedisException ("Unknown message type: " + firstObj );
141
+ }
142
+ final byte [] resp = (byte []) firstObj ;
143
+ if (Arrays .equals (SUBSCRIBE .getRaw (), resp )) {
144
+ subscribedChannels = ((Long ) listReply .get (2 )).intValue ();
145
+ final byte [] bchannel = (byte []) listReply .get (1 );
146
+ final String strchannel = (bchannel == null ) ? null : SafeEncoder .encode (bchannel );
147
+ onSubscribe (strchannel , subscribedChannels );
148
+ } else if (Arrays .equals (UNSUBSCRIBE .getRaw (), resp )) {
149
+ subscribedChannels = ((Long ) listReply .get (2 )).intValue ();
150
+ final byte [] bchannel = (byte []) listReply .get (1 );
151
+ final String strchannel = (bchannel == null ) ? null : SafeEncoder .encode (bchannel );
152
+ onUnsubscribe (strchannel , subscribedChannels );
153
+ } else if (Arrays .equals (MESSAGE .getRaw (), resp )) {
154
+ final byte [] bchannel = (byte []) listReply .get (1 );
155
+ final byte [] bmesg = (byte []) listReply .get (2 );
156
+ final String strchannel = (bchannel == null ) ? null : SafeEncoder .encode (bchannel );
157
+ final String strmesg = (bmesg == null ) ? null : SafeEncoder .encode (bmesg );
158
+ onMessage (strchannel , strmesg );
159
+ } else if (Arrays .equals (PMESSAGE .getRaw (), resp )) {
160
+ final byte [] bpattern = (byte []) listReply .get (1 );
161
+ final byte [] bchannel = (byte []) listReply .get (2 );
162
+ final byte [] bmesg = (byte []) listReply .get (3 );
163
+ final String strpattern = (bpattern == null ) ? null : SafeEncoder .encode (bpattern );
164
+ final String strchannel = (bchannel == null ) ? null : SafeEncoder .encode (bchannel );
165
+ final String strmesg = (bmesg == null ) ? null : SafeEncoder .encode (bmesg );
166
+ onPMessage (strpattern , strchannel , strmesg );
167
+ } else if (Arrays .equals (PSUBSCRIBE .getRaw (), resp )) {
168
+ subscribedChannels = ((Long ) listReply .get (2 )).intValue ();
169
+ final byte [] bpattern = (byte []) listReply .get (1 );
170
+ final String strpattern = (bpattern == null ) ? null : SafeEncoder .encode (bpattern );
171
+ onPSubscribe (strpattern , subscribedChannels );
172
+ } else if (Arrays .equals (PUNSUBSCRIBE .getRaw (), resp )) {
173
+ subscribedChannels = ((Long ) listReply .get (2 )).intValue ();
174
+ final byte [] bpattern = (byte []) listReply .get (1 );
175
+ final String strpattern = (bpattern == null ) ? null : SafeEncoder .encode (bpattern );
176
+ onPUnsubscribe (strpattern , subscribedChannels );
177
+ } else if (Arrays .equals (PONG .getRaw (), resp )) {
178
+ final byte [] bpattern = (byte []) listReply .get (1 );
179
+ final String strpattern = (bpattern == null ) ? null : SafeEncoder .encode (bpattern );
180
+ onPong (strpattern );
181
+ } else {
182
+ throw new JedisException ("Unknown message type: " + firstObj );
183
+ }
184
+ } else if (reply instanceof byte []) {
185
+ byte [] resp = (byte []) reply ;
186
+ String str = SafeEncoder .encode (resp );
187
+ if ("PONG" .equalsIgnoreCase (str )) {
188
+ onPong (null );
189
+ } else {
190
+ onPong (str );
191
+ }
179
192
} else {
180
- throw new JedisException ("Unknown message type: " + firstObj );
193
+ throw new JedisException ("Unknown message type: " + reply );
181
194
}
182
195
} while (isSubscribed ());
183
196
0 commit comments