diff --git a/.gitignore.txt b/.gitignore.txt
index 8c32860..a8fd4da 100644
--- a/.gitignore.txt
+++ b/.gitignore.txt
@@ -6,4 +6,5 @@ ehthumbs.db
Icon?
Thumbs.db
build/*
-bin/*
\ No newline at end of file
+bin/*
+.settings/*
\ No newline at end of file
diff --git a/README.textile b/README.textile
index 5cb8ece..1470457 100644
--- a/README.textile
+++ b/README.textile
@@ -11,6 +11,8 @@ h1. A new approach to events in Java.
h2. Examples
+h3. Basic Signal Example
+
// using the Java Signals event model in a simple banking example
import com.paulm.jsignal.Signal;
import com.paulm.jsignal.SignalException;
@@ -64,70 +66,36 @@ class ATM
}
}
+h3. PrioritySignal Example
+
// using the Java Signals event model for priority based event dispatching
-import com.paulm.jsignal.PrioritySignal;
-import com.paulm.jsignal.SignalException;
-public class BankApp
-{
- // for display purposes only
- private String priority;
-
- public static void main (String args[])
- {
- BankApp lowPriorityApp = new BankApp();
- lowPriorityApp.priority = "LOW";
- BankApp highPriorityApp = new BankApp();
- highPriorityApp.priority = "HIGH";
- ATM atm = new ATM();
- try
- {
- // add the high and low priority handlers
- // note that Integers are compared by their natural ordering, so a lower number has a higher priority in this case
- atm.transactionComplete.add(lowPriorityApp, "handleNewBalance", 1);
- atm.transactionComplete.add(highPriorityApp, "handleNewBalance", 0);
- }
- catch (SignalException e)
- {
- e.printStackTrace();
- }
- atm.doTransaction();
- }
+//...
+// we can specify generically a comparable type to use as priority, in this case we will use Integers
+PrioritySignal transactionComplete = new PrioritySignal(String.class, double.class);
+//...
- public void handleNewBalance (String name, double balance)
- {
- System.out.println("New balance recieved with "+priority+" priority, name:"+name+" balance:"+balance);
- }
-}
+// add the high and low priority handlers
+// note that Integers are compared by their natural ordering, so a lower number has a higher priority in this case
+atm.transactionComplete.add(lowPriorityApp, "handleNewBalance", 1);
+atm.transactionComplete.add(highPriorityApp, "handleNewBalance", 0);
-class ATM
-{
- protected final PrioritySignal transactionComplete;
-
- public ATM ()
- {
- // we can specify generically a comparable type to use as priority, in this case we will use Integers
- transactionComplete = new PrioritySignal(String.class, double.class);
- }
-
- public void doTransaction ()
- {
- // do something
- try
- {
- // dispatch the event; to enforce strict-typing of event data, the data types of the arguments must match up with formal parameters
- transactionComplete.dispatch("Paul", 17.06);
- }
- catch (SignalException e)
- {
- e.printStackTrace();
- }
- }
-}
+h3. WeakSignal Example
+
+
// using WeakSignals for memory sensitive code
+
+//...
+WeakSignal signal = new WeakSignal();
+Listener listener = new Listener();
+signal.add(listener, "callback");
+listener = null;
+//... after garbage collection
+
+signal.dispatch(); // listener was garbaged collected and automatically removed as a listener from the WeakSignal instance
*Note:* Because native AWT events haven't yet been wrapped by Java Signals, there is no need to post a side by side comparison of the two methods. You can find Oracle's tutorial on events "here":http://download.oracle.com/javase/tutorial/uiswing/events/index.html
-h3. Links
+h2. Links
* "Robert Penner's original Signals API for AS3":https://github.com/robertpenner/as3-signals
* Feel free to contact me at paulahmoore@shaw.ca with any questions/comments/concerns/critiques/etc
\ No newline at end of file
diff --git a/build.properties b/build.properties
index 81019fc..08f49fb 100644
--- a/build.properties
+++ b/build.properties
@@ -1,7 +1,7 @@
# Project properties
project.name=jsignal
project.title=Java Signals
-project.version=2.1
+project.version=2.2
project.author=Paul Moore
# Build directories
diff --git a/src/com/paulm/jsignal/PrioritySignal.java b/src/com/paulm/jsignal/PrioritySignal.java
index 0bbe270..fcf93e5 100644
--- a/src/com/paulm/jsignal/PrioritySignal.java
+++ b/src/com/paulm/jsignal/PrioritySignal.java
@@ -40,9 +40,9 @@
* @author Paul Moore
* @see com.paulm.jsignal.Signal
*/
-public class PrioritySignal > extends Signal
+public final class PrioritySignal > extends Signal
{
- private PriorityQueue> listenerQueue;
+ private PriorityQueue listenerQueue;
/**
* Constructor
@@ -64,7 +64,7 @@ public PrioritySignal (int initialCapacity, Class>... params)
{
super(params);
- listenerQueue = new PriorityQueue>(initialCapacity);
+ listenerQueue = new PriorityQueue(initialCapacity);
}
/**
@@ -90,19 +90,19 @@ public Object add (Object listener, String callback, boolean addOnce, E priority
}
catch (SecurityException e)
{
- SignalException se = new SignalException (e.getLocalizedMessage()+" listener:"+listener+" callback:"+callback+" priority:"+priority);
+ SignalException se = new SignalException (e+" listener:"+listener+" callback:"+callback+" priority:"+priority);
log.throwing("PrioritySignal", "add", se);
throw se;
}
catch (NoSuchMethodException e)
{
- SignalException se = new SignalException (e.getLocalizedMessage()+" listener:"+listener+" callback:"+callback+" priority:"+priority);
+ SignalException se = new SignalException (e+" listener:"+listener+" callback:"+callback+" priority:"+priority);
log.throwing("PrioritySignal", "add", se);
throw se;
}
- PrioritySlot newSlot = new PrioritySlot(listener, delegate, addOnce, priority);
- Slot previous = listenerMap.put(listener, newSlot);
+ ISlot newSlot = new PrioritySlot(listener, delegate, addOnce, priority);
+ ISlot previous = listenerMap.put(listener, newSlot);
if (previous != null)
{
@@ -187,8 +187,8 @@ public void removeAll ()
@Override
public void dispatch (Object... args) throws SignalException
{
- PrioritySlot slot;
- PriorityQueue> newQueue = new PriorityQueue>(listenerQueue.size());
+ ISlot slot;
+ PriorityQueue newQueue = new PriorityQueue(listenerQueue.size());
while (!listenerQueue.isEmpty())
{
@@ -200,19 +200,19 @@ public void dispatch (Object... args) throws SignalException
}
catch (IllegalArgumentException e)
{
- SignalException se = new SignalException (e.getLocalizedMessage()+" listener:"+slot.getDelegate()+" args:"+Arrays.deepToString(args));
+ SignalException se = new SignalException (e+" listener:"+slot.getDelegate()+" args:"+Arrays.deepToString(args));
log.throwing("PrioritySignal", "add", se);
throw se;
}
catch (IllegalAccessException e)
{
- SignalException se = new SignalException (e.getLocalizedMessage()+" listener:"+slot.getDelegate()+" args:"+Arrays.deepToString(args));
+ SignalException se = new SignalException (e+" listener:"+slot.getDelegate()+" args:"+Arrays.deepToString(args));
log.throwing("PrioritySignal", "add", se);
throw se;
}
catch (InvocationTargetException e)
{
- SignalException se = new SignalException (e.getLocalizedMessage()+" listener:"+slot.getDelegate()+" args:"+Arrays.deepToString(args));
+ SignalException se = new SignalException (e+" listener:"+slot.getDelegate()+" args:"+Arrays.deepToString(args));
log.throwing("PrioritySignal", "add", se);
throw se;
}
diff --git a/src/com/paulm/jsignal/PrioritySlot.java b/src/com/paulm/jsignal/PrioritySlot.java
index caa8380..b154073 100644
--- a/src/com/paulm/jsignal/PrioritySlot.java
+++ b/src/com/paulm/jsignal/PrioritySlot.java
@@ -26,7 +26,7 @@
import java.lang.reflect.Method;
-class PrioritySlot > extends Slot implements Comparable>
+final class PrioritySlot > extends Slot implements Comparable>
{
private E priority;
diff --git a/src/com/paulm/jsignal/Signal.java b/src/com/paulm/jsignal/Signal.java
index fba5800..d5ad929 100644
--- a/src/com/paulm/jsignal/Signal.java
+++ b/src/com/paulm/jsignal/Signal.java
@@ -48,13 +48,14 @@ public class Signal implements ISignalOwner
{
protected final Class>[] params;
- protected final Map