Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Display menu and subscribed channels after each operation. Added gett…

…ers/setters for pubnub.subscriptions channel names
  • Loading branch information...
commit b9256d875da675fb693f706014587c0d0c1a7a5b 1 parent abbc66a
authored February 01, 2013
47  java/3.4/examples/src/com/pubnub/examples/PubnubDemoConsole.java
@@ -158,74 +158,78 @@ public void startDemo() {
158 158
 			System.out.println("Cipher Key = " + this.cipher_key);
159 159
 			pubnub = new Pubnub("demo", "demo", "demo", this.cipher_key, this.SSL);
160 160
 		}
161  
-		
162 161
 
163  
-		System.out.println("ENTER 1  FOR Subscribe");
164  
-		System.out.println("ENTER 2  FOR Publish");
165  
-		System.out.println("ENTER 3  FOR Presence");
166  
-		System.out.println("ENTER 4  FOR Detailed History");
167  
-		System.out.println("ENTER 5  FOR Here_Now");
168  
-		System.out.println("ENTER 6  FOR Unsubscribe");
169  
-		System.out.println("ENTER 7  FOR Presence-Unsubscribe");
170  
-		System.out.println("ENTER 8  FOR Time");
171  
-		System.out.println("ENTER 9  FOR EXIT OR QUIT");
172  
-		System.out.println("ENTER 10 FOR Disconnect-And-Resubscribe");
173  
-		System.out.println("ENTER 11 FOR Toggle Resume On Reconnect");
  162
+
  163
+        displayMenuOptions();
174 164
 		
175 165
 		String channelName = null;
176 166
 		int command = 0;
177 167
 		while ((command = reader.nextInt()) != 9 ){
178 168
 			reader.nextLine();
179 169
 			switch(command) {
  170
+
  171
+            case 0:
  172
+                displayMenuOptions();
180 173
 			case 1:
181 174
 				System.out.println("Subscribe: Enter Channel name");
182 175
 				channelName = reader.nextLine();
183 176
 				subscribe(channelName);
184 177
 				System.out.println("Subscribed to following channels: ");
185 178
 				System.out.println(PubnubUtil.joinString(pubnub.getSubscribedChannelsArray(), " : "));
  179
+                displayMenuOptions();
186 180
 				break;
187 181
 			case 2:
188 182
 				System.out.println("Publish: Enter Channel name");
189 183
 				channelName = reader.nextLine();
190 184
 				publish(channelName);
  185
+                displayMenuOptions();
191 186
 				break;
192 187
 			case 3:
193 188
 				System.out.println("Presence: Enter Channel name");
194 189
 				channelName = reader.nextLine();
195  
-				presence(channelName);	
  190
+				presence(channelName);
  191
+                displayMenuOptions();
196 192
 				break;
197 193
 			case 4:
198 194
 				System.out.println("Detailed History: Enter Channel name");
199 195
 				channelName = reader.nextLine();
200 196
 				detailedHistory(channelName);
  197
+                displayMenuOptions();
201 198
 				break;
202 199
 			case 5:
203 200
 				System.out.println("Here Now : Enter Channel name");
204 201
 				channelName = reader.nextLine();
205 202
 				hereNow(channelName);
  203
+                displayMenuOptions();
206 204
 				break;
207 205
 			case 6:
208 206
 				System.out.println("Unsubscribe: Enter Channel name");
209 207
 				channelName = reader.nextLine();
210 208
 				unsubscribe(channelName);
  209
+                displayMenuOptions();
211 210
 				break;
212 211
 			case 7:
213 212
 				System.out.println("UnsubscribePresence : Enter Channel name");
214 213
 				channelName = reader.nextLine();
215 214
 				unsubscribePresence(channelName);
  215
+                displayMenuOptions();
216 216
 				break;
217 217
 			case 8:
218 218
 				time();
  219
+                displayMenuOptions();
219 220
 				break;
220 221
 			case 10:
221 222
 				disconnectAndResubscribe();
  223
+                displayMenuOptions();
222 224
 				break;
223 225
 			case 11:
224 226
 				pubnub.setResumeOnReconnect(pubnub.isResumeOnReconnect()?false:true);
225 227
 				System.out.println("RESUME ON RECONNECT : " + pubnub.isResumeOnReconnect() );
  228
+                displayMenuOptions();
226 229
 				break;
227 230
 			default: 
228 231
 				System.out.println("Invalid Input");
  232
+                displayMenuOptions();
229 233
 			}
230 234
 		}
231 235
 		System.out.println("Exiting");
@@ -233,7 +237,22 @@ public void startDemo() {
233 237
 
234 238
 	}
235 239
 
236  
-	/**
  240
+    private void displayMenuOptions() {
  241
+        System.out.println("ENTER 1  FOR Subscribe " + "(Currently subscribed to " + this.pubnub.getCurrentlySubscribedChannelNames() + ")");
  242
+        System.out.println("ENTER 2  FOR Publish");
  243
+        System.out.println("ENTER 3  FOR Presence");
  244
+        System.out.println("ENTER 4  FOR Detailed History");
  245
+        System.out.println("ENTER 5  FOR Here_Now");
  246
+        System.out.println("ENTER 6  FOR Unsubscribe");
  247
+        System.out.println("ENTER 7  FOR Presence-Unsubscribe");
  248
+        System.out.println("ENTER 8  FOR Time");
  249
+        System.out.println("ENTER 9  FOR EXIT OR QUIT");
  250
+        System.out.println("ENTER 10 FOR Disconnect-And-Resubscribe");
  251
+        System.out.println("ENTER 11 FOR Toggle Resume On Reconnect");
  252
+        System.out.println("\nENTER 0 to display this menu");
  253
+    }
  254
+
  255
+    /**
237 256
 	 * @param args
238 257
 	 */
239 258
 	public static void main(String[] args) {
7  java/3.4/srcPubnubApi/com/pubnub/api/Pubnub.java
@@ -50,7 +50,7 @@
50 50
 	private static Logger log = Logger.getLogger(
51 51
             Pubnub.class.getName());
52 52
 
53  
-	public void shutdown() {
  53
+    public void shutdown() {
54 54
 		nonSubscribeManager.stop();
55 55
 		subscribeManager.stop();
56 56
 	}
@@ -71,6 +71,11 @@ private String getOrigin() {
71 71
 		return ORIGIN_STR; 
72 72
 	}
73 73
 
  74
+    public String getCurrentlySubscribedChannelNames() {
  75
+        String currentChannels = subscriptions.getChannelString();
  76
+        return currentChannels.equals("") ? "no channels." : currentChannels;
  77
+    }
  78
+
74 79
 	public void setResumeOnReconnect(boolean resumeOnReconnect) {
75 80
 		this.resumeOnReconnect = resumeOnReconnect;
76 81
 	}

0 notes on commit b9256d8

Please sign in to comment.
Something went wrong with that request. Please try again.