From d1d4fe1b1505b2a65c8047a1ae5936253ff3ac3e Mon Sep 17 00:00:00 2001 From: Frank Maritato Date: Tue, 11 Aug 2009 16:38:44 +0000 Subject: [PATCH] initial checkin git-svn-id: https://lwes.svn.sourceforge.net/svnroot/lwes/lwes-java/trunk@174 a2f82657-cdd2-4550-bd36-68a8e7111808 --- src/org/lwes/listener/EventCountingHandler.java | 51 +++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/org/lwes/listener/EventCountingHandler.java diff --git a/src/org/lwes/listener/EventCountingHandler.java b/src/org/lwes/listener/EventCountingHandler.java new file mode 100644 index 0000000..6c10801 --- /dev/null +++ b/src/org/lwes/listener/EventCountingHandler.java @@ -0,0 +1,51 @@ +package org.lwes.listener; +/** + * @author fmaritato + */ + +import org.lwes.Event; + +import java.net.InetAddress; + +public class EventCountingHandler implements EventHandler { + + protected int count = 0; + + public void destroy() { + System.out.println("Count: " + count); + } + + public void handleEvent(Event event) { + count++; + System.out.println("Count: "+count); + } + + public static void main(String[] args) throws Exception { + EventCountingHandler eventHandler = new EventCountingHandler(); + DatagramEventListener listener = new DatagramEventListener(); + listener.setAddress(InetAddress.getByName("224.1.1.11")); + listener.setPort(6969); + listener.addHandler(eventHandler); + listener.setTimeToLive(1); + listener.initialize(); + + Runtime.getRuntime().addShutdownHook(new ShutdownThread(eventHandler)); + + while (true) { + Thread.sleep(1000); + } + } + + static class ShutdownThread extends Thread { + + EventHandler eventHandler; + + ShutdownThread(EventHandler eh) { + eventHandler = eh; + } + + public void run() { + eventHandler.destroy(); + } + } +} -- 2.11.4.GIT