Author: mladen.turk(a)jboss.com
Date: 2008-05-28 11:43:55 -0400 (Wed, 28 May 2008)
New Revision: 1629
Added:
sandbox/aloha/examples/
sandbox/aloha/examples/org/
sandbox/aloha/examples/org/jboss/
sandbox/aloha/examples/org/jboss/aloha/
sandbox/aloha/examples/org/jboss/aloha/AdvertiseExample.java
Log:
Add some example code
Added: sandbox/aloha/examples/org/jboss/aloha/AdvertiseExample.java
===================================================================
--- sandbox/aloha/examples/org/jboss/aloha/AdvertiseExample.java
(rev 0)
+++ sandbox/aloha/examples/org/jboss/aloha/AdvertiseExample.java 2008-05-28 15:43:55 UTC
(rev 1629)
@@ -0,0 +1,122 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import org.jboss.aloha.advertise.*;
+
+public class AdvertiseExample
+{
+
+ public class AdvertiseEventHandler implements IAdvertiseEvent
+ {
+
+ public AdvertiseEventHandler()
+ {
+ // Nothing
+ }
+ public void onEvent(AdvertiseEventType type, AdvertisedServer server)
+ {
+ if (type == AdvertiseEventType.ON_NEW_SERVER) {
+ System.out.println("\rNew Server detected: " + server);
+ System.out.print("Enter command> ");
+ }
+ else {
+ if (server.getStatusCode() == 410) {
+ System.out.println("\rServer: " + server + "
shudown!");
+ System.out.print("Enter command> ");
+ }
+ else {
+ System.out.println("\rServer: " + server + " status:
" + server.getStatusCode());
+ System.out.print("Enter command> ");
+ }
+ }
+ }
+
+ }
+
+ public AdvertiseListener listener;
+ public AdvertiseExample()
+ {
+ AdvertiseEventHandler eh = new AdvertiseEventHandler();
+ listener = new AdvertiseListener(eh);
+ }
+
+ public static void main(String [] args) {
+ try {
+ int ch;
+ AdvertiseExample ex = new AdvertiseExample();
+ ex.listener.setGroupAddress("234.5.6.7");
+ ex.listener.setSecurityKey("foo");
+
+ ex.listener.start();
+ byte [] ib = new byte[1024];
+ while (true) {
+ System.out.print("Enter command> ");
+ int len = System.in.read(ib);
+ if (len < 0)
+ break;
+ if (ib[len - 1] == '\n')
+ len--;
+ if (ib[len - 1] == '\r')
+ len--;
+ String cmd = new String(ib, 0, len);
+ if (cmd.charAt(0) == 'q' || cmd.charAt(0) == 'Q') {
+ ex.listener.destroy();
+ break;
+ }
+ else if (cmd.equalsIgnoreCase("stop")) {
+ ex.listener.stop();
+ }
+ else if (cmd.equalsIgnoreCase("destroy")) {
+ ex.listener.destroy();
+ }
+ else if (cmd.equalsIgnoreCase("start")) {
+ ex.listener.start();
+ }
+ else if (cmd.equalsIgnoreCase("pause")) {
+ ex.listener.pause();
+ }
+ else if (cmd.equalsIgnoreCase("resume")) {
+ ex.listener.resume();
+ }
+ else if (cmd.equalsIgnoreCase("list")) {
+ System.out.println("Adverised servers:");
+ for (AdvertisedServer s : ex.listener.getServers()) {
+ System.out.println(s + "@" +
+ s.getParameter(AdvertisedServer.MANAGER_HOST) +
+ " status: " + s.getStatusCode() + " " +
+ s.getStatusDescription());
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+
+}
Property changes on: sandbox/aloha/examples/org/jboss/aloha/AdvertiseExample.java
___________________________________________________________________
Name: svn:eol-style
+ native
Show replies by date