OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | easybeans-commits List | May 2008 Index

<--  Date Index  --> <--  Thread Index  -->

[easybeans-commits] [3339] trunk/util: Event module :


Title: [3339] trunk/util: Event module :
Revision
3339
Author
missonng
Date
2008-05-29 11:58:31 +0200 (Thu, 29 May 2008)

Log Message

Event module :
Classes and interfaces names refactor.
Include a small test program.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/util/.classpath (3338 => 3339)


--- trunk/util/.classpath	2008-05-29 07:50:04 UTC (rev 3338)
+++ trunk/util/.classpath	2008-05-29 09:58:31 UTC (rev 3339)
@@ -28,6 +28,11 @@
 	<classpathentry kind="src" path="modules/ee/metadata/war/impl/src/test/resources"/>
 	<classpathentry kind="src" output="target-eclipse/classes" path="modules/event/api/src/main/java"/>
 	<classpathentry kind="src" output="target-eclipse/classes" path="modules/event/impl/src/main/java"/>
+	<classpathentry kind="src" output="target-eclipse/test-classes" path="modules/event/impl/src/test/java">
+		<attributes>
+			<attribute name="maven.type" value="test"/>
+		</attributes>
+	</classpathentry>
 	<classpathentry kind="src" output="target-eclipse/classes" path="modules/execution/src/main/java"/>
 	<classpathentry kind="src" output="target-eclipse/test-classes" path="modules/execution/src/test/java">
 		<attributes>

Deleted: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/Event.java (3338 => 3339)


--- trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/Event.java	2008-05-29 07:50:04 UTC (rev 3338)
+++ trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/Event.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -1,180 +0,0 @@
-/**
- * OW2 Util
- * Copyright (C) 2008 Bull S.A.S.
- * Contact: easybeans@xxxxxxx
- *
- * 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.1 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; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
- *
- * --------------------------------------------------------------------------
- * $Id$
- * --------------------------------------------------------------------------
- */
-
-package org.ow2.util.event.api;
-
-import java.util.EventObject;
-
-/**
- * Provide data that event switch and listeners need to handle events.
- * @author missonng
- */
-public final class Event extends EventObject implements Comparable<Event> {
-    /**
-     * Define the base interface for event's type.
-     * @author missonng
-     */
-    public interface EventType {
-
-    }
-
-    /**
-     * The serialVersionUID.
-     */
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * A static field to number events.
-     */
-    private static long nextNumber = 0;
-
-    /**
-     * The event type.
-     */
-    private EventType type;
-
-    /**
-     * The event data.
-     */
-    private Object data;
-
-    /**
-     * The event message.
-     */
-    private String message;
-
-    /**
-     * The event number.
-     */
-    private long number;
-
-    /**
-     * The event time.
-     */
-    private long time;
-
-    /**
-     * The event constructor.<br>
-     * The event message and data fields will be set to null.
-     * @param psource The event source.
-     * @param ptype The event type.
-     */
-    public Event(final Object psource, final EventType ptype) {
-        this(psource, ptype, null, null);
-    }
-
-    /**
-     * The event constructor.<br>
-     * The event message field will be set to null.
-     * @param psource The event source.
-     * @param ptype The event type.
-     * @param pdata The event data.
-     */
-    public Event(final Object psource, final EventType ptype, final Object pdata) {
-        this(psource, ptype, pdata, null);
-    }
-
-    /**
-     * The event constructor.<br>
-     * The event data field will be set to null.
-     * @param psource The event source.
-     * @param ptype The event type.
-     * @param pmessage The event message.
-     */
-    public Event(final Object psource, final EventType ptype, final String pmessage) {
-        this(psource, ptype, null, pmessage);
-    }
-
-    /**
-     * The event constructor.
-     * @param psource The event source.
-     * @param ptype The event type.
-     * @param pdata The event data.
-     * @param pmessage The event message.
-     */
-    public Event(final Object psource, final EventType ptype, final Object pdata, final String pmessage) {
-        super(psource);
-        if (psource == null) {
-            throw new NullPointerException("Event provider should not be null");
-        }
-        if (ptype == null) {
-            throw new NullPointerException("Event type should not be null");
-        }
-        this.type = ptype;
-        this.data = ""
-        this.message = pmessage;
-        this.number = Event.nextNumber++;
-        this.time = System.currentTimeMillis();
-    }
-
-    /**
-     * Get the event type.
-     * @return The event type.
-     */
-    public EventType type() {
-        return this.type;
-    }
-
-    /**
-     * Get the event message.
-     * @return The event message.
-     */
-    public String message() {
-        return this.message;
-    }
-
-    /**
-     * Get the event data.
-     * @return The event data.
-     */
-    public Object data() {
-        return this.data;
-    }
-
-    /**
-     * Get the event number.
-     * @return The event number.
-     */
-    public long number() {
-        return this.number;
-    }
-
-    /**
-     * Get the event time.
-     * @return The event time.
-     */
-    public long time() {
-        return this.time;
-    }
-
-    /**
-     * Compare this event to the specified event using the event number.
-     * @param pevent The event to compare to.
-     * @return A negative integer, zero, or a positive integer as this event's number is less than,
-     * equal to, or greater than the specified event's number.
-     */
-    public int compareTo(final Event pevent) {
-        return (int) (this.number - pevent.number);
-    }
-}

Added: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/EventPriority.java (0 => 3339)


--- trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/EventPriority.java	                        (rev 0)
+++ trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/EventPriority.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -0,0 +1,69 @@
+/**
+ * OW2 Util
+ * Copyright (C) 2008 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * 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.1 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.event.api;
+
+/**
+ * Define handler's priorities.<br>
+ * Priorities natural order is define by the ordinal in this enumeration.<br>
+ * The special value NONE_PRIORITY is defined to delimit synchronous priorities from asynchronous priorities.
+ * It shouldn't be use, but will be treated as the highest asynchronous priority if you do so.
+ * @author missonng
+ */
+public enum EventPriority {
+    /**
+     * Ordinal : 0.
+     */
+    SYNC_HIGH_PRIORITY,
+
+    /**
+     * Ordinal : 1.
+     */
+    SYNC_NORM_PRIORITY,
+
+    /**
+     * Ordinal : 2.
+     */
+    SYNC_LOW_PRIORITY,
+
+    /**
+     * Ordinal : 3.
+     */
+    NONE_PRIORITY,
+
+    /**
+     * Ordinal : 4.
+     */
+    ASYNC_HIGH_PRIORITY,
+
+    /**
+     * Ordinal : 5.
+     */
+    ASYNC_NORM_PRIORITY,
+
+    /**
+     * Ordinal : 6.
+     */
+    ASYNC_LOW_PRIORITY;
+}
Property changes on: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/EventPriority.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEvent.java (0 => 3339)


--- trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEvent.java	                        (rev 0)
+++ trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEvent.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -0,0 +1,62 @@
+/**
+ * OW2 Util
+ * Copyright (C) 2008 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * 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.1 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.event.api;
+
+
+/**
+ * Provide data that event switch and listeners need to handle events.
+ * @author missonng
+ */
+public interface IEvent {
+    /**
+     * Get the event type.
+     * @return The event type.
+     */
+    IEventType getType();
+
+    /**
+     * Get the event message.
+     * @return The event message.
+     */
+    String getMessage();
+
+    /**
+     * Get the event data.
+     * @return The event data.
+     */
+    Object getData();
+
+    /**
+     * Get the event number.
+     * @return The event number.
+     */
+    long getNumber();
+
+    /**
+     * Get the event time.
+     * @return The event time.
+     */
+    long getTime();
+}
Property changes on: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEvent.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventDispatcher.java (from rev 3336, trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventLighter.java) (0 => 3339)


--- trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventDispatcher.java	                        (rev 0)
+++ trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventDispatcher.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -0,0 +1,49 @@
+/**
+ * OW2 Util
+ * Copyright (C) 2008 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * 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.1 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.event.api;
+
+/**
+ * Define methods an event lighter has to implement.
+ * @author missonng
+ */
+public interface IEventDispatcher {
+    /**
+     * Add a new event listener.
+     * @param plistener The listener to add.
+     */
+    void addListener(final IEventListener plistener);
+
+    /**
+     * Remove an event listener.
+     * @param plistener The listener to remove.
+     */
+    void removeListener(final IEventListener plistener);
+
+    /**
+     * Dispatch this event.
+     * @param pevent The event to dispatch.
+     */
+    void dispatchEvent(final IEvent pevent);
+}

Property changes: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventDispatcher.java


Name: svn:mime-type
   + text/plain

Copied: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventDispatcherHelper.java (from rev 3336, trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventLighterHelper.java) (0 => 3339)


--- trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventDispatcherHelper.java	                        (rev 0)
+++ trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventDispatcherHelper.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -0,0 +1,48 @@
+/**
+ * OW2 Util
+ * Copyright (C) 2008 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * 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.1 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.event.api;
+
+/**
+ * Define methods services have to implement to get access to the event service.
+ * @author missonng
+ */
+public interface IEventDispatcherHelper {
+    /**
+     * Get the event lighter.
+     * @return The event lighter.
+     */
+    IEventDispatcher getEventLighter();
+
+    /**
+     * Set the event lighter.
+     * @param plighter The event lighter.
+     */
+    void setEventLighter(IEventDispatcher plighter);
+
+    /**
+     * Unset the event lighter.
+     */
+    void unsetEventLighter();
+}

Property changes: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventDispatcherHelper.java


Name: svn:mime-type
   + text/plain

Deleted: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventHandler.java (3338 => 3339)


--- trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventHandler.java	2008-05-29 07:50:04 UTC (rev 3338)
+++ trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventHandler.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -1,96 +0,0 @@
-/**
- * OW2 Util
- * Copyright (C) 2008 Bull S.A.S.
- * Contact: easybeans@xxxxxxx
- *
- * 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.1 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; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
- *
- * --------------------------------------------------------------------------
- * $Id$
- * --------------------------------------------------------------------------
- */
-
-package org.ow2.util.event.api;
-
-/**
- * Define methods handlers need to be switch and schedule.
- * @author missonng
- */
-public interface IEventHandler {
-    /**
-     * Check if the handler can handle this event.<br>
-     * It is critical for the event switch performance that this method respond as quick as possible (A few microseconds).<br>
-     * Please do avoid I/O, synchronization, ... in this method.
-     * @param pevent The event to handle.
-     * @return True if the handler can handle this event, false otherwise.
-     */
-    boolean accept(Event pevent);
-
-    /**
-     * Handle the event.
-     * @param pevent The event to handle.
-     */
-    void handle(Event pevent);
-
-    /**
-     * Get the handler priority.
-     * @return The handler priority.
-     */
-    Priority priority();
-
-    /**
-     * Define handler's priorities.<br>
-     * Priorities natural order is define by the ordinal in this enumeration.<br>
-     * The special value NONE_PRIORITY is defined to delimit synchronous priorities from asynchronous priorities.
-     * It shouldn't be use, but will be treated as the highest asynchronous priority if you do so.
-     * @author missonng
-     */
-    public enum Priority {
-        /**
-         * Ordinal : 0.
-         */
-        SYNC_HIGH_PRIORITY,
-
-        /**
-         * Ordinal : 1.
-         */
-        SYNC_NORM_PRIORITY,
-
-        /**
-         * Ordinal : 2.
-         */
-        SYNC_LOW_PRIORITY,
-
-        /**
-         * Ordinal : 3.
-         */
-        NONE_PRIORITY,
-
-        /**
-         * Ordinal : 4.
-         */
-        ASYNC_HIGH_PRIORITY,
-
-        /**
-         * Ordinal : 5.
-         */
-        ASYNC_NORM_PRIORITY,
-
-        /**
-         * Ordinal : 6.
-         */
-        ASYNC_LOW_PRIORITY;
-    }
-}

Deleted: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventLighter.java (3338 => 3339)


--- trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventLighter.java	2008-05-29 07:50:04 UTC (rev 3338)
+++ trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventLighter.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -1,49 +0,0 @@
-/**
- * OW2 Util
- * Copyright (C) 2008 Bull S.A.S.
- * Contact: easybeans@xxxxxxx
- *
- * 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.1 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; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
- *
- * --------------------------------------------------------------------------
- * $Id$
- * --------------------------------------------------------------------------
- */
-
-package org.ow2.util.event.api;
-
-/**
- * Define methods an event lighter has to implement.
- * @author missonng
- */
-public interface IEventLighter {
-    /**
-     * Register a new event handler.
-     * @param phandler The handler to register.
-     */
-    void register(final IEventHandler phandler);
-
-    /**
-     * Unregister an event handler.
-     * @param phandler The handler to unregister.
-     */
-    void unregister(final IEventHandler phandler);
-
-    /**
-     * Light this event.
-     * @param pevent The event to light.
-     */
-    void light(final Event pevent);
-}

Deleted: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventLighterHelper.java (3338 => 3339)


--- trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventLighterHelper.java	2008-05-29 07:50:04 UTC (rev 3338)
+++ trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventLighterHelper.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -1,48 +0,0 @@
-/**
- * OW2 Util
- * Copyright (C) 2008 Bull S.A.S.
- * Contact: easybeans@xxxxxxx
- *
- * 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.1 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; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
- *
- * --------------------------------------------------------------------------
- * $Id$
- * --------------------------------------------------------------------------
- */
-
-package org.ow2.util.event.api;
-
-/**
- * Define methods services have to implement to get access to the event service.
- * @author missonng
- */
-public interface IEventLighterHelper {
-    /**
-     * Get the event lighter.
-     * @return The event lighter.
-     */
-    IEventLighter getEventLighter();
-
-    /**
-     * Set the event lighter.
-     * @param plighter The event lighter.
-     */
-    void setEventLighter(IEventLighter plighter);
-
-    /**
-     * Unset the event lighter.
-     */
-    void unsetEventLighter();
-}

Copied: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventListener.java (from rev 3336, trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventHandler.java) (0 => 3339)


--- trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventListener.java	                        (rev 0)
+++ trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventListener.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -0,0 +1,53 @@
+/**
+ * OW2 Util
+ * Copyright (C) 2008 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * 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.1 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.event.api;
+
+
+/**
+ * Define methods handlers need to be switch and schedule.
+ * @author missonng
+ */
+public interface IEventListener {
+    /**
+     * Check if the handler can handle this event.<br>
+     * It is critical for the event switch performance that this method respond as quick as possible (A few microseconds).<br>
+     * Please do avoid I/O, synchronization, ... in this method.
+     * @param pevent The event to handle.
+     * @return True if the handler can handle this event, false otherwise.
+     */
+    boolean acceptEvent(IEvent pevent);
+
+    /**
+     * Handle the event.
+     * @param pevent The event to handle.
+     */
+    void handleEvent(IEvent pevent);
+
+    /**
+     * Get the handler priority.
+     * @return The handler priority.
+     */
+    EventPriority getPriority();
+}

Property changes: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventListener.java


Name: svn:mime-type
   + text/plain

Added: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventType.java (0 => 3339)


--- trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventType.java	                        (rev 0)
+++ trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventType.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -0,0 +1,33 @@
+/**
+ * OW2 Util
+ * Copyright (C) 2008 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * 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.1 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.event.api;
+
+/**
+ * Define the base interface for event's type.
+ * @author missonng
+ */
+public interface IEventType {
+
+}
Property changes on: trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/IEventType.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/util/modules/event/impl/pom.xml (3338 => 3339)


--- trunk/util/modules/event/impl/pom.xml	2008-05-29 07:50:04 UTC (rev 3338)
+++ trunk/util/modules/event/impl/pom.xml	2008-05-29 09:58:31 UTC (rev 3339)
@@ -45,5 +45,14 @@
       <artifactId>util-event-api</artifactId>
       <version>${project.version}</version>
     </dependency>
+
+    <!-- Tests -->
+    <dependency>
+      <groupId>org.testng</groupId>
+      <artifactId>testng</artifactId>
+      <version>5.1</version>
+      <classifier>jdk15</classifier>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>

Copied: trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/Event.java (from rev 3336, trunk/util/modules/event/api/src/main/java/org/ow2/util/event/api/Event.java) (0 => 3339)


--- trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/Event.java	                        (rev 0)
+++ trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/Event.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -0,0 +1,165 @@
+/**
+ * OW2 Util
+ * Copyright (C) 2008 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * 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.1 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.event.impl;
+
+import java.util.EventObject;
+
+import org.ow2.util.event.api.IEvent;
+import org.ow2.util.event.api.IEventType;
+
+/**
+ * Provide data that event switch and listeners need to handle events.
+ * @author missonng
+ */
+public class Event extends EventObject implements IEvent {
+    /**
+     * The serialVersionUID.
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * A static field to number events.
+     */
+    private static long nextNumber = 0;
+
+    /**
+     * The event type.
+     */
+    private IEventType type;
+
+    /**
+     * The event data.
+     */
+    private Object data;
+
+    /**
+     * The event message.
+     */
+    private String message;
+
+    /**
+     * The event number.
+     */
+    private long number;
+
+    /**
+     * The event time.
+     */
+    private long time;
+
+    /**
+     * The event constructor.<br>
+     * The event message and data fields will be set to null.
+     * @param psource The event source.
+     * @param ptype The event type.
+     */
+    public Event(final Object psource, final IEventType ptype) {
+        this(psource, ptype, null, null);
+    }
+
+    /**
+     * The event constructor.<br>
+     * The event message field will be set to null.
+     * @param psource The event source.
+     * @param ptype The event type.
+     * @param pdata The event data.
+     */
+    public Event(final Object psource, final IEventType ptype, final Object pdata) {
+        this(psource, ptype, pdata, null);
+    }
+
+    /**
+     * The event constructor.<br>
+     * The event data field will be set to null.
+     * @param psource The event source.
+     * @param ptype The event type.
+     * @param pmessage The event message.
+     */
+    public Event(final Object psource, final IEventType ptype, final String pmessage) {
+        this(psource, ptype, null, pmessage);
+    }
+
+    /**
+     * The event constructor.
+     * @param psource The event source.
+     * @param ptype The event type.
+     * @param pdata The event data.
+     * @param pmessage The event message.
+     */
+    public Event(final Object psource, final IEventType ptype, final Object pdata, final String pmessage) {
+        super(psource);
+        if (psource == null) {
+            throw new NullPointerException("Event provider should not be null");
+        }
+        if (ptype == null) {
+            throw new NullPointerException("Event type should not be null");
+        }
+        this.type = ptype;
+        this.data = ""
+        this.message = pmessage;
+        this.number = Event.nextNumber++;
+        this.time = System.currentTimeMillis();
+    }
+
+    /**
+     * Get the event type.
+     * @return The event type.
+     */
+    public IEventType getType() {
+        return this.type;
+    }
+
+    /**
+     * Get the event message.
+     * @return The event message.
+     */
+    public String getMessage() {
+        return this.message;
+    }
+
+    /**
+     * Get the event data.
+     * @return The event data.
+     */
+    public Object getData() {
+        return this.data;
+    }
+
+    /**
+     * Get the event number.
+     * @return The event number.
+     */
+    public long getNumber() {
+        return this.number;
+    }
+
+    /**
+     * Get the event time.
+     * @return The event time.
+     */
+    public long getTime() {
+        return this.time;
+    }
+}

Property changes: trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/Event.java


Name: svn:mime-type
   + text/plain

Copied: trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/EventDispatcher.java (from rev 3337, trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/EventLighter.java) (0 => 3339)


--- trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/EventDispatcher.java	                        (rev 0)
+++ trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/EventDispatcher.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -0,0 +1,262 @@
+/**
+ * OW2 Util
+ * Copyright (C) 2008 Bull S.A.S.
+ * Contact: easybeans@xxxxxxx
+ *
+ * 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.1 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; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ *
+ * --------------------------------------------------------------------------
+ * $Id$
+ * --------------------------------------------------------------------------
+ */
+
+package org.ow2.util.event.impl;
+
+import java.util.TreeMap;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.ow2.util.event.api.EventPriority;
+import org.ow2.util.event.api.IEvent;
+import org.ow2.util.event.api.IEventDispatcher;
+import org.ow2.util.event.api.IEventListener;
+
+/**
+ * Implement the IEventLighter interface.
+ * @author missonng
+ */
+public class EventDispatcher implements IEventDispatcher {
+    /**
+     * Execute scheduled runnable.<br>
+     * Workers get runnable to execute from the lighter synchronous queue.<br>
+     * A worker dies when the special runnable KILL is taken from the queue.<br>
+     * This method avoid complex synchronization to kill workers properly.
+     * @author missonng
+     */
+    private final class EventWorker extends Thread {
+        /**
+         * Execute scheduled runnable.
+         */
+        @Override
+        public void run() {
+            final SynchronousQueue<Runnable> queue = EventDispatcher.this.queue;
+            final Runnable kill = EventDispatcher.KILL;
+            while (true) {
+                try {
+                    final Runnable task = queue.take();
+                    if (task != kill) {
+                        task.run();
+                    } else {
+                        return;
+                    }
+                } catch (InterruptedException ex) {
+                    continue;
+                }
+            }
+        }
+    }
+
+    /**
+     * The default number of workers.
+     */
+    private static final int DEFAULT_SIZE = 100;
+
+    /**
+     * The special runnable use to kill workers.
+     */
+    private static final Runnable KILL = new Runnable() {
+        public void run() {
+
+        }
+    };
+
+    /**
+     * The listener set.<br>
+     * Use a copy-on-write set allow iteration on the set with neither synchronization, nor ConcurrentModificationException.
+     */
+    private final CopyOnWriteArraySet<IEventListener> listeners = new CopyOnWriteArraySet<IEventListener>();
+
+    /**
+     * The runnable queue.<br>
+     * Use this type of queue to synchronize with workers is a simple and high-performance choice.
+     */
+    private final SynchronousQueue<Runnable> queue = new SynchronousQueue<Runnable>();
+
+    /**
+     * The number of workers.<br>
+     * Use an atomic integer allow to implement thread-safe size getter and setter without synchronization.
+     */
+    private final AtomicInteger size = new AtomicInteger();
+
+    /**
+     * The event dispatcher constructor.
+     */
+    public EventDispatcher() {
+        this.setSize(EventDispatcher.DEFAULT_SIZE);
+    }
+
+    /**
+     * Add a new event listener.
+     * @param plistener The listener to add.
+     */
+    public void addListener(final IEventListener plistener) {
+        if (plistener == null) {
+            throw new NullPointerException();
+        }
+        this.listeners.add(plistener);
+    }
+
+    /**
+     * Remove an event listener.
+     * @param plistener The listener to remove.
+     */
+    public void removeListener(final IEventListener plistener) {
+        this.listeners.remove(plistener);
+    }
+
+    /**
+     * Get the number of workers.
+     * @return The number of workers.
+     */
+    public int getSize() {
+        return this.size.get();
+    }
+
+    /**
+     * Set the number of workers.
+     * @param psize The number of workers.
+     */
+    public void setSize(final int psize) {
+        final int diff = this.size.getAndSet(psize) - psize;
+        final SynchronousQueue<Runnable> queue = this.queue;
+        final Runnable kill = EventDispatcher.KILL;
+        if (diff > 0) {
+            for (int i = 0; i < diff; i++) {
+                while (true) {
+                    try {
+                        queue.put(kill);
+                        break;
+                    } catch (InterruptedException ex) {
+                        continue;
+                    }
+                }
+            }
+        } else {
+            for (int i = 0; i > diff; i--) {
+                new EventWorker().start();
+            }
+        }
+    }
+
+    /**
+     * Dispatch this event.
+     * @param pevent The event to dispatch.
+     */
+    public void dispatchEvent(final IEvent pevent) {
+        final TreeMap<EventPriority, ConcurrentLinkedQueue<IEventListener>> map =
+            new TreeMap<EventPriority, ConcurrentLinkedQueue<IEventListener>>();
+
+        for (final IEventListener handler : EventDispatcher.this.listeners) {
+            ConcurrentLinkedQueue<IEventListener> handlers = map.get(handler.getPriority());
+            if (handlers == null) {
+                handlers = new ConcurrentLinkedQueue<IEventListener>();
+                map.put(handler.getPriority(), handlers);
+            }
+            handlers.add(handler);
+        }
+
+        for (final Entry<EventPriority, ConcurrentLinkedQueue<IEventListener>> entry : map.entrySet()) {
+            if (entry.getKey().ordinal() < EventPriority.NONE_PRIORITY.ordinal()) {
+                handleSync(pevent, entry.getValue());
+            } else {
+                handleAsync(pevent, entry.getValue());
+            }
+        }
+    }
+
+    /**
+     * Schedule this event listener queue on one or more worker(s).<br>
+     * This queue is schedule on an additional worker each time this thread gets the processor and the queue is not empty.<br>
+     * This method blocks until each listener in the queue have been executed.
+     * @param event The event to handle.
+     * @param listeners The listener queue to schedule.
+     */
+    private void handleSync(final IEvent event, final ConcurrentLinkedQueue<IEventListener> listeners) {
+        final SynchronousQueue<Runnable> queue = EventDispatcher.this.queue;
+        final Semaphore semaphore = new Semaphore(0);
+        final int size = listeners.size();
+        while (listeners.size() > 0) {
+            try {
+                queue.put(new Runnable() {
+                    public void run() {
+                        while (true) {
+                            final IEventListener handler = listeners.poll();
+                            if (handler != null) {
+                                try {
+                                    handler.handleEvent(event);
+                                } catch (Exception ex) {
+                                    continue;
+                                } finally {
+                                    semaphore.release();
+                                }
+                            } else {
+                                return;
+                            }
+                        }
+                    }
+                });
+            } catch (InterruptedException ex) {
+                continue;
+            }
+        }
+        semaphore.acquireUninterruptibly(size);
+    }
+
+    /**
+     * Schedule this event listener queue on one or more worker(s).<br>
+     * This queue is schedule on an additional worker each time this thread gets the processor and the queue is not empty.
+     * @param event The event to handle.
+     * @param listeners The listener queue to schedule.
+     */
+    private void handleAsync(final IEvent event, final ConcurrentLinkedQueue<IEventListener> listeners) {
+        final SynchronousQueue<Runnable> queue = EventDispatcher.this.queue;
+        while (listeners.size() > 0) {
+            try {
+                queue.put(new Runnable() {
+                    public void run() {
+                        while (true) {
+                            final IEventListener handler = listeners.poll();
+                            if (handler != null) {
+                                try {
+                                    handler.handleEvent(event);
+                                } catch (Exception ex) {
+                                    continue;
+                                }
+                            } else {
+                                return;
+                            }
+                        }
+                    }
+                });
+            } catch (InterruptedException ex) {
+                continue;
+            }
+        }
+    }
+}

Property changes: trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/EventDispatcher.java


Name: svn:mime-type
   + text/plain

Deleted: trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/EventLighter.java (3338 => 3339)


--- trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/EventLighter.java	2008-05-29 07:50:04 UTC (rev 3338)
+++ trunk/util/modules/event/impl/src/main/java/org/ow2/util/event/impl/EventLighter.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -1,262 +0,0 @@
-/**
- * OW2 Util
- * Copyright (C) 2008 Bull S.A.S.
- * Contact: easybeans@xxxxxxx
- *
- * 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.1 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; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
- *
- * --------------------------------------------------------------------------
- * $Id$
- * --------------------------------------------------------------------------
- */
-
-package org.ow2.util.event.impl;
-
-import java.util.TreeMap;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.ow2.util.event.api.Event;
-import org.ow2.util.event.api.IEventHandler;
-import org.ow2.util.event.api.IEventLighter;
-import org.ow2.util.event.api.IEventHandler.Priority;
-
-/**
- * Implement the IEventLighter interface.
- * @author missonng
- */
-public final class EventLighter implements IEventLighter {
-    /**
-     * Execute scheduled runnable.<br>
-     * Workers get runnable to execute from the lighter synchronous queue.<br>
-     * A worker dies when the special runnable KILL is taken from the queue.<br>
-     * This method avoid complex synchronization to kill workers properly.
-     * @author missonng
-     */
-    private final class EventWorker extends Thread {
-        /**
-         * Execute scheduled runnable.
-         */
-        @Override
-        public void run() {
-            final SynchronousQueue<Runnable> queue = EventLighter.this.queue;
-            final Runnable kill = EventLighter.KILL;
-            while (true) {
-                try {
-                    final Runnable task = queue.take();
-                    if (task != kill) {
-                        task.run();
-                    } else {
-                        return;
-                    }
-                } catch (InterruptedException ex) {
-                    continue;
-                }
-            }
-        }
-    }
-
-    /**
-     * The default number of workers.
-     */
-    private static final int DEFAULT_SIZE = 100;
-
-    /**
-     * The special runnable use to kill workers.
-     */
-    private static final Runnable KILL = new Runnable() {
-        public void run() {
-
-        }
-    };
-
-    /**
-     * The handler set.<br>
-     * Use a copy-on-write set allow iteration on the set with neither synchronization, nor ConcurrentModificationException.
-     */
-    private final CopyOnWriteArraySet<IEventHandler> handlers = new CopyOnWriteArraySet<IEventHandler>();
-
-    /**
-     * The runnable queue.<br>
-     * Use this type of queue to synchronize with workers is a simple and high-performance choice.
-     */
-    private final SynchronousQueue<Runnable> queue = new SynchronousQueue<Runnable>();
-
-    /**
-     * The number of workers.<br>
-     * Use an atomic integer allow to implement thread-safe size getter and setter without synchronization.
-     */
-    private final AtomicInteger size = new AtomicInteger();
-
-    /**
-     * The lighter constructor.
-     */
-    public EventLighter() {
-        this.size(EventLighter.DEFAULT_SIZE);
-    }
-
-    /**
-     * Register a new handler.
-     * @param phandler The handler to register.
-     */
-    public void register(final IEventHandler phandler) {
-        if (phandler == null) {
-            throw new NullPointerException();
-        }
-        this.handlers.add(phandler);
-    }
-
-    /**
-     * Unregister a handler.
-     * @param phandler The handler to unregister.
-     */
-    public void unregister(final IEventHandler phandler) {
-        this.handlers.remove(phandler);
-    }
-
-    /**
-     * Get the number of workers.
-     * @return The number of workers.
-     */
-    public int size() {
-        return this.size.get();
-    }
-
-    /**
-     * Set the number of workers.
-     * @param psize The number of workers.
-     */
-    public void size(final int psize) {
-        final int diff = this.size.getAndSet(psize) - psize;
-        final SynchronousQueue<Runnable> queue = this.queue;
-        final Runnable kill = EventLighter.KILL;
-        if (diff > 0) {
-            for (int i = 0; i < diff; i++) {
-                while (true) {
-                    try {
-                        queue.put(kill);
-                        break;
-                    } catch (InterruptedException ex) {
-                        continue;
-                    }
-                }
-            }
-        } else {
-            for (int i = 0; i > diff; i--) {
-                new EventWorker().start();
-            }
-        }
-    }
-
-    /**
-     * Light this event.
-     * @param pevent The event to light.
-     */
-    public void light(final Event pevent) {
-        final TreeMap<Priority, ConcurrentLinkedQueue<IEventHandler>> map =
-            new TreeMap<Priority, ConcurrentLinkedQueue<IEventHandler>>();
-
-        for (final IEventHandler handler : EventLighter.this.handlers) {
-            ConcurrentLinkedQueue<IEventHandler> handlers = map.get(handler.priority());
-            if (handlers == null) {
-                handlers = new ConcurrentLinkedQueue<IEventHandler>();
-                map.put(handler.priority(), handlers);
-            }
-            handlers.add(handler);
-        }
-
-        for (final Entry<Priority, ConcurrentLinkedQueue<IEventHandler>> entry : map.entrySet()) {
-            if (entry.getKey().ordinal() < Priority.NONE_PRIORITY.ordinal()) {
-                handleSync(pevent, entry.getValue());
-            } else {
-                handleAsync(pevent, entry.getValue());
-            }
-        }
-    }
-
-    /**
-     * Schedule this event handlers queue on one or more worker(s).<br>
-     * This queue is schedule on an additional worker each time this thread gets the processor and the queue is not empty.<br>
-     * This method blocks until each handler in the queue have been executed.
-     * @param event The event to handle.
-     * @param handlers The handler queue to schedule.
-     */
-    private void handleSync(final Event event, final ConcurrentLinkedQueue<IEventHandler> handlers) {
-        final SynchronousQueue<Runnable> queue = EventLighter.this.queue;
-        final Semaphore semaphore = new Semaphore(0);
-        final int size = handlers.size();
-        while (handlers.size() > 0) {
-            try {
-                queue.put(new Runnable() {
-                    public void run() {
-                        while (true) {
-                            final IEventHandler handler = handlers.poll();
-                            if (handler != null) {
-                                try {
-                                    handler.handle(event);
-                                } catch (Exception ex) {
-                                    continue;
-                                } finally {
-                                    semaphore.release();
-                                }
-                            } else {
-                                return;
-                            }
-                        }
-                    }
-                });
-            } catch (InterruptedException ex) {
-                continue;
-            }
-        }
-        semaphore.acquireUninterruptibly(size);
-    }
-
-    /**
-     * Schedule this event handlers queue on one or more worker(s).<br>
-     * This queue is schedule on an additional worker each time this thread gets the processor and the queue is not empty.
-     * @param event The event to handle.
-     * @param handlers The handler queue to schedule.
-     */
-    private void handleAsync(final Event event, final ConcurrentLinkedQueue<IEventHandler> handlers) {
-        final SynchronousQueue<Runnable> queue = EventLighter.this.queue;
-        while (handlers.size() > 0) {
-            try {
-                queue.put(new Runnable() {
-                    public void run() {
-                        while (true) {
-                            final IEventHandler handler = handlers.poll();
-                            if (handler != null) {
-                                try {
-                                    handler.handle(event);
-                                } catch (Exception ex) {
-                                    continue;
-                                }
-                            } else {
-                                return;
-                            }
-                        }
-                    }
-                });
-            } catch (InterruptedException ex) {
-                continue;
-            }
-        }
-    }
-}

Added: trunk/util/modules/event/impl/src/test/java/org/ow2/util/event/impl/test/EventTest.java (0 => 3339)


--- trunk/util/modules/event/impl/src/test/java/org/ow2/util/event/impl/test/EventTest.java	                        (rev 0)
+++ trunk/util/modules/event/impl/src/test/java/org/ow2/util/event/impl/test/EventTest.java	2008-05-29 09:58:31 UTC (rev 3339)
@@ -0,0 +1,177 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.ow2.util.event.impl.test;
+
+import java.util.ArrayList;
+import java.util.concurrent.Semaphore;
+
+import org.ow2.util.event.api.EventPriority;
+import org.ow2.util.event.api.IEvent;
+import org.ow2.util.event.api.IEventListener;
+import org.ow2.util.event.api.IEventType;
+import org.ow2.util.event.impl.Event;
+import org.ow2.util.event.impl.EventDispatcher;
+import org.testng.annotations.Test;
+
+/**
+ *
+ * @author guillaume
+ */
+public class EventTest extends Thread {
+    public class Result {
+        public Event evn;
+        public Thread thr;
+        public long tbgn;
+        public long tend;
+    }
+
+    public static void main(final String[] args) throws Exception {
+        EventTest main = new EventTest();
+        main.start();
+        main.join();
+    }
+
+    @Override
+    public void run() {
+        try {
+            this.test();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Test(timeOut=10000)
+    public void test() {
+        //File file = new File("test.out");
+        //file.createNewFile();
+        //FileOutputStream out = new FileOutputStream(file);
+
+        //nb event the test will dispatch
+        final long[] nbes = {1000};//{10000};
+
+        //nb listener
+        final long[] nbls = {10};//{10, 20, 40};
+
+        //events period in nanosecond
+        final long[] dts = {1000000};//{4000000, 2000000, 1000000};
+
+        //synchronous listener rate (% * nb listener)
+        final double[] ratesls = {.4};//{.1, .2, .4};
+
+        //listeners processing time (% * events period)
+        final double[] ratetts = {.01};//{.01, .05, .10, .50};
+
+        //weird event listeners processing time (% * events period)
+        final double[] ratethtts = {100.0};//{10.0, 50.0, 100.0, 500.0};
+
+        //weird event rate (% * nb event)
+        final double[] ratenbhtts = {.001};//{.001, .005, .01, .05};
+
+        for (final long nbe : nbes) {
+            for (final long nbl : nbls) {
+                for (final long dt : dts) {
+                    for (final double ratesl : ratesls) {
+                        for (final double ratett : ratetts) {
+                            for (final double ratethtt : ratethtts) {
+                                for (final double ratenbhtt : ratenbhtts) {
+                                    final ArrayList<Result> results = new ArrayList<Result>();
+                                    final Semaphore semaphore = new Semaphore((int)(1-nbe), true);
+                                    final EventDispatcher dispatcher = new EventDispatcher();
+                                    final long tt = (long)(ratett * dt);
+                                    final long htt = (long)(ratethtt * dt);
+
+                                    for (long i=0;i<nbl;i++) {
+                                        EventPriority temp;
+                                        if ((double)i / nbl < ratesl) {
+                                            temp = EventPriority.SYNC_NORM_PRIORITY;
+                                        } else {
+                                            temp = EventPriority.ASYNC_NORM_PRIORITY;
+                                        }
+                                        final EventPriority priority = temp;
+                                        dispatcher.addListener(new IEventListener() {
+                                            public boolean acceptEvent(final IEvent event) {
+                                                return true;
+                                            }
+
+                                            public void handleEvent(final IEvent event) {
+                                                //System.out.println(event.number()+":"+this.hashCode()+":"+this.priority()+":"+System.nanoTime());
+                                                final long t = System.nanoTime();
+                                                final long tt = (Long)event.getData();
+                                                while (System.nanoTime() - t < tt) {
+                                                    ;
+                                                    //System.out.println(event.number()+":"+this.hashCode()+":"+this.priority()+":"+System.nanoTime());
+                                                }
+                                            }
+
+                                            public EventPriority getPriority() {
+                                                return priority;
+                                            }
+                                        });
+                                    }
+
+                                    for (long i=0;i<nbe;i++) {
+                                        final Result result = new Result();
+                                        result.evn = new Event(new Object(), new IEventType() {}, (i % (1 / ratenbhtt) == 0) ? htt : tt);
+                                        result.thr = new Thread() {
+                                            @Override
+                                            public void run() {
+                                                result.tbgn = System.nanoTime();
+                                                dispatcher.dispatchEvent(result.evn);
+                                                result.tend = System.nanoTime();
+                                                semaphore.release();
+                                            }
+                                        };
+
+                                        results.add(result);
+                                    }
+
+                                    for (final Result result : results) {
+                                        final long t = System.nanoTime();
+                                        result.thr.start();
+                                        while (System.nanoTime() - t < dt) {
+                                            ;
+                                        }
+                                    }
+
+                                    semaphore.acquireUninterruptibly();
+                                    dispatcher.setSize(0);
+
+                                    long meantt = 0;
+                                    long meanhtt = 0;
+                                    long nbtt = 0;
+                                    long nbhtt = 0;
+                                    for (final Result result : results) {
+                                        if ((Long)result.evn.getData() == tt) {
+                                            nbtt++;
+                                            meantt += result.tend - result.tbgn;
+                                        } else {
+                                            nbhtt++;
+                                            meanhtt += result.tend - result.tbgn;
+                                        }
+                                    }
+
+                                    String str = nbe + ";" +
+                                                nbl + ";" +
+                                                dt + ";" +
+                                                ratesl + ";" +
+                                                ratett + ";" +
+                                                ratethtt + ";" +
+                                                ratenbhtt + ";" +
+                                                (meantt/nbtt) + ";" +
+                                                (meanhtt/nbhtt) + ";" +
+                                                ((meantt + meanhtt) / (nbtt + nbhtt)) + "\n";
+                                    //out.write(str.getBytes());
+                                    System.out.println(str);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        System.out.println("Finished successfully!!!!");
+    }
+}
Property changes on: trunk/util/modules/event/impl/src/test/java/org/ow2/util/event/impl/test/EventTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain


<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 2006-2007, OW2 Consortium | contact | webmaster.