Skip to content

Commit 07520fa

Browse files
author
Devendra
committed
unsubscribe callback check
1 parent e6ad872 commit 07520fa

1 file changed

Lines changed: 275 additions & 0 deletions

File tree

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
package com.pubnub.examples;
2+
3+
import com.pubnub.api.Callback;
4+
import com.pubnub.api.Pubnub;
5+
import com.pubnub.api.PubnubError;
6+
import com.pubnub.api.PubnubException;
7+
8+
9+
class SubscribeCallback extends Callback {
10+
@Override
11+
public void successCallback(String channel, Object message) {
12+
System.out.println("Message : " + message + ", on " + channel);
13+
}
14+
@Override
15+
public void connectCallback(String channel, Object message) {
16+
System.out.println("Connect on : " + channel);
17+
}
18+
@Override
19+
public void errorCallback(String channel, PubnubError message) {
20+
System.out.println("Message : " + message + ", on " + channel);
21+
}
22+
}
23+
24+
class GenericCallback extends Callback {
25+
@Override
26+
public void successCallback(String channel, Object message) {
27+
System.out.println("CALLBACK : " + message );
28+
}
29+
@Override
30+
public void errorCallback(String channel, PubnubError error) {
31+
System.out.println("ERROR : " + error);
32+
}
33+
}
34+
35+
public class UnsubscribeCheck {
36+
37+
public static void main(String[] args) {
38+
Pubnub pubnub = new Pubnub("ds", "ds");
39+
40+
try {
41+
pubnub.subscribe("a", new SubscribeCallback());
42+
43+
Thread.sleep(5000);
44+
45+
pubnub.unsubscribeAll(new GenericCallback());
46+
47+
Thread.sleep(5000);
48+
49+
System.out.println();
50+
51+
pubnub.subscribe("a", new SubscribeCallback());
52+
53+
Thread.sleep(5000);
54+
pubnub.unsubscribe("a", new GenericCallback());
55+
56+
Thread.sleep(5000);
57+
58+
pubnub.channelGroupSubscribe("ab", new SubscribeCallback());
59+
60+
61+
Thread.sleep(5000);
62+
63+
pubnub.channelGroupUnsubscribe("ab", new GenericCallback());
64+
65+
Thread.sleep(5000);
66+
67+
System.out.println();
68+
69+
70+
71+
pubnub.channelGroupSubscribe("ab", new SubscribeCallback());
72+
73+
74+
Thread.sleep(5000);
75+
76+
pubnub.channelGroupUnsubscribe("ab");
77+
78+
79+
Thread.sleep(5000);
80+
81+
pubnub.channelGroupSubscribe("ab", new SubscribeCallback());
82+
pubnub.subscribe("a", new SubscribeCallback());
83+
84+
85+
Thread.sleep(5000);
86+
87+
pubnub.unsubscribeAll(new GenericCallback());
88+
89+
90+
91+
Thread.sleep(5000);
92+
System.out.println();
93+
pubnub.channelGroupSubscribe("ab", new SubscribeCallback());
94+
pubnub.channelGroupSubscribe("cd", new SubscribeCallback());
95+
pubnub.subscribe("a", new SubscribeCallback());
96+
pubnub.subscribe("b", new SubscribeCallback());
97+
98+
99+
Thread.sleep(5000);
100+
101+
pubnub.unsubscribeAll(new GenericCallback());
102+
103+
104+
105+
Thread.sleep(5000);
106+
107+
System.out.println();
108+
pubnub.channelGroupSubscribe("cd", new SubscribeCallback());
109+
pubnub.subscribe("a", new SubscribeCallback());
110+
pubnub.subscribe("b", new SubscribeCallback());
111+
112+
113+
Thread.sleep(5000);
114+
115+
pubnub.unsubscribeAll(new GenericCallback());
116+
117+
118+
Thread.sleep(5000);
119+
120+
System.out.println();
121+
pubnub.channelGroupSubscribe("cd", new SubscribeCallback());
122+
pubnub.subscribe("a", new SubscribeCallback());
123+
124+
125+
Thread.sleep(5000);
126+
127+
pubnub.unsubscribeAll(new GenericCallback());
128+
129+
Thread.sleep(5000);
130+
System.out.println();
131+
pubnub.channelGroupSubscribe("cd", new SubscribeCallback());
132+
133+
134+
Thread.sleep(5000);
135+
136+
pubnub.unsubscribeAll(new GenericCallback());
137+
138+
Thread.sleep(5000);
139+
System.out.println();
140+
pubnub.channelGroupSubscribe("cd", new SubscribeCallback());
141+
142+
143+
Thread.sleep(5000);
144+
145+
pubnub.unsubscribeAll(new GenericCallback());
146+
147+
Thread.sleep(5000);
148+
149+
150+
151+
pubnub.subscribe("a", new SubscribeCallback());
152+
153+
Thread.sleep(5000);
154+
155+
pubnub.unsubscribeAll();
156+
157+
Thread.sleep(5000);
158+
159+
System.out.println();
160+
161+
pubnub.subscribe("a", new SubscribeCallback());
162+
163+
Thread.sleep(5000);
164+
pubnub.unsubscribe("a", new GenericCallback());
165+
166+
Thread.sleep(5000);
167+
168+
pubnub.channelGroupSubscribe("ab", new SubscribeCallback());
169+
170+
171+
Thread.sleep(5000);
172+
173+
pubnub.channelGroupUnsubscribe("ab");
174+
175+
Thread.sleep(5000);
176+
177+
System.out.println();
178+
179+
180+
181+
pubnub.channelGroupSubscribe("ab", new SubscribeCallback());
182+
183+
184+
Thread.sleep(5000);
185+
186+
pubnub.channelGroupUnsubscribe("ab");
187+
188+
189+
Thread.sleep(5000);
190+
191+
pubnub.channelGroupSubscribe("ab", new SubscribeCallback());
192+
pubnub.subscribe("a", new SubscribeCallback());
193+
194+
195+
Thread.sleep(5000);
196+
197+
pubnub.unsubscribeAll();
198+
199+
200+
201+
Thread.sleep(5000);
202+
System.out.println();
203+
pubnub.channelGroupSubscribe("ab", new SubscribeCallback());
204+
pubnub.channelGroupSubscribe("cd", new SubscribeCallback());
205+
pubnub.subscribe("a", new SubscribeCallback());
206+
pubnub.subscribe("b", new SubscribeCallback());
207+
208+
209+
Thread.sleep(5000);
210+
211+
pubnub.unsubscribeAll();
212+
213+
214+
215+
Thread.sleep(5000);
216+
217+
System.out.println();
218+
pubnub.channelGroupSubscribe("cd", new SubscribeCallback());
219+
pubnub.subscribe("a", new SubscribeCallback());
220+
pubnub.subscribe("b", new SubscribeCallback());
221+
222+
223+
Thread.sleep(5000);
224+
225+
pubnub.unsubscribeAll();
226+
227+
228+
Thread.sleep(5000);
229+
230+
System.out.println();
231+
pubnub.channelGroupSubscribe("cd", new SubscribeCallback());
232+
pubnub.subscribe("a", new SubscribeCallback());
233+
234+
235+
Thread.sleep(5000);
236+
237+
pubnub.unsubscribeAll();
238+
239+
Thread.sleep(5000);
240+
System.out.println();
241+
pubnub.channelGroupSubscribe("cd", new SubscribeCallback());
242+
243+
244+
Thread.sleep(5000);
245+
246+
pubnub.unsubscribeAll();
247+
248+
Thread.sleep(5000);
249+
System.out.println();
250+
pubnub.channelGroupSubscribe("cd", new SubscribeCallback());
251+
252+
253+
Thread.sleep(5000);
254+
255+
pubnub.unsubscribeAll();
256+
257+
258+
259+
260+
261+
Thread.sleep(5000);
262+
pubnub.shutdown();
263+
264+
} catch (PubnubException e) {
265+
// TODO Auto-generated catch block
266+
e.printStackTrace();
267+
} catch (InterruptedException e) {
268+
// TODO Auto-generated catch block
269+
e.printStackTrace();
270+
}
271+
272+
273+
}
274+
275+
}

0 commit comments

Comments
 (0)