Skip to content

Commit

Permalink
first pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
justparking committed Sep 29, 2015
1 parent 6f7e5dc commit 0350e33
Show file tree
Hide file tree
Showing 113 changed files with 18,857 additions and 2,382 deletions.
1 change: 1 addition & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ downtime
spamming
proxies
deactivation
embeddable
180 changes: 170 additions & 10 deletions nodel-framework-java/src/main/java/org/nodel/Handler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,232 @@ public class Handler {
public interface H0 {
public void handle();
}

/**
* For 1 argument/parameter handlers.
*/
public interface H1<T> {
public void handle(T value);
}

/**
* For 2 argument/parameter handlers.
*/
public interface H2<T0, T1> {
public void handle(T0 value0, T1 value1);
}

/**
* For 3 argument/parameter handlers.
*/
public interface H3<T0, T1, T2> {
public void handle(T0 value0, T1 value1, T2 value2);
}

/**
* For 4 argument/parameter handlers.
*/
public interface H4<T0, T1, T2, T3> {
public void handle(T0 value0, T1 value1, T2 value2, T3 value3);
}

/**
* For 5 argument/parameter handlers.
*/
public interface H5<T0, T1, T2, T3, T4> {
public void handle(T0 value0, T1 value1, T2 value2, T3 value3, T4 value4);
}

/**
* Thread-safe convenience method.
*/
public static void handle(H0 handler) {
if (handler != null)
handler.handle();
}

/**
* Thread-safe convenience method.
*/
public static <T0> void handle(H1<T0> handler, T0 value0) {
if (handler != null)
handler.handle(value0);
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1> void handle(H2<T0, T1> handler, T0 value0, T1 value1) {
if (handler != null)
handler.handle(value0, value1);
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1, T2> void handle(H3<T0, T1, T2> handler, T0 value0, T1 value1, T2 value2) {
if (handler != null)
handler.handle(value0, value1, value2);
}
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1, T2, T3> void handle(H4<T0, T1, T2, T3> handler, T0 value0, T1 value1, T2 value2, T3 value3) {
if (handler != null)
handler.handle(value0, value1, value2, value3);
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1, T2, T3, T4> void handle(H5<T0, T1, T2, T3, T4> handler, T0 value0, T1 value1, T2 value2, T3 value3, T4 value4) {
if (handler != null)
handler.handle(value0, value1, value2, value3, value4);
}

/**
* Thread-safe convenience method.
*/
public static void tryHandle(H0 handler) {
try {
if (handler != null)
handler.handle();
} catch (Exception exc) {
// ignore
}
}

/**
* Thread-safe convenience method.
*/
public static <T0> void tryHandle(H1<T0> handler, T0 value0) {
try {
if (handler != null)
handler.handle(value0);
} catch (Exception exc) {
// ignore
}
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1> void tryHandle(H2<T0, T1> handler, T0 value0, T1 value1) {
try {
if (handler != null)
handler.handle(value0, value1);
} catch (Exception exc) {
// ignore
}
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1, T2> void tryHandle(H3<T0, T1, T2> handler, T0 value0, T1 value1, T2 value2) {
try {
if (handler != null)
handler.handle(value0, value1, value2);
} catch (Exception exc) {
// ignore
}
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1, T2, T3> void tryHandle(H4<T0, T1, T2, T3> handler, T0 value0, T1 value1, T2 value2, T3 value3) {
try {
if (handler != null)
handler.handle(value0, value1, value2, value3);
} catch (Exception exc) {
// ignore
}
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1, T2, T3, T4> void tryHandle(H5<T0, T1, T2, T3, T4> handler, T0 value0, T1 value1, T2 value2, T3 value3, T4 value4) {
try {
if (handler != null)
handler.handle(value0, value1, value2, value3, value4);
} catch (Exception exc) {
// ignore
}
}

/**
* Thread-safe convenience method.
*/
public static void tryHandle(H0 handler, H1<Exception> excHandler) {
try {
if (handler != null)
handler.handle();
} catch (Exception exc) {
tryHandle(excHandler, exc);
}
}

/**
* Thread-safe convenience method.
*/
public static <T0> void tryHandle(H1<T0> handler, T0 value0, H1<Exception> excHandler) {
try {
if (handler != null)
handler.handle(value0);
} catch (Exception exc) {
tryHandle(excHandler, exc);
}
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1> void tryHandle(H2<T0, T1> handler, T0 value0, T1 value1, H1<Exception> excHandler) {
try {
if (handler != null)
handler.handle(value0, value1);
} catch (Exception exc) {
tryHandle(excHandler, exc);
}
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1, T2> void tryHandle(H3<T0, T1, T2> handler, T0 value0, T1 value1, T2 value2, H1<Exception> excHandler) {
try {
if (handler != null)
handler.handle(value0, value1, value2);
} catch (Exception exc) {
tryHandle(excHandler, exc);
}
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1, T2, T3> void tryHandle(H4<T0, T1, T2, T3> handler, T0 value0, T1 value1, T2 value2, T3 value3, H1<Exception> excHandler) {
try {
if (handler != null)
handler.handle(value0, value1, value2, value3);
} catch (Exception exc) {
tryHandle(excHandler, exc);
}
}

/**
* Thread-safe convenience method.
*/
public static <T0, T1, T2, T3, T4> void tryHandle(H5<T0, T1, T2, T3, T4> handler, T0 value0, T1 value1, T2 value2, T3 value3, T4 value4, H1<Exception> excHandler) {
try {
if (handler != null)
handler.handle(value0, value1, value2, value3, value4);
} catch (Exception exc) {
tryHandle(excHandler, exc);
}
}

} // (class)
19 changes: 14 additions & 5 deletions nodel-framework-java/src/main/java/org/nodel/Handlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static class H0 {
/**
* The list of handlers.
*/
private List<Handler.H0> handlers = new ArrayList<Handler.H0>();
private List<Handler.H0> handlers = new ArrayList<Handler.H0>(4);

/**
* Adds a handler. The handler must not block or throw exceptions.
Expand Down Expand Up @@ -76,7 +76,7 @@ public static class H1<T> {
/**
* The list of handlers.
*/
private List<Handler.H1<T>> handlers = new ArrayList<Handler.H1<T>>();
private List<Handler.H1<T>> handlers = new ArrayList<Handler.H1<T>>(4);

/**
* Adds a handler. The handler must not block or throw exceptions.
Expand All @@ -99,7 +99,16 @@ public void updateAll(T value) {
handler.handle(value);
} // (for)
}
} // (method)
}

/**
* Updates all handlers without using any thread-synchronization.
*/
public void updateAllUnsynchronized(T value) {
for (Handler.H1<T> handler : handlers) {
handler.handle(value);
} // (for)
}

/**
* Removes a handler.
Expand All @@ -125,7 +134,7 @@ public static class H2<T0, T1> {
/**
* The list of handlers.
*/
private List<Handler.H2<T0, T1>> handlers = new ArrayList<Handler.H2<T0, T1>>();
private List<Handler.H2<T0, T1>> handlers = new ArrayList<Handler.H2<T0, T1>>(4);

/**
* Adds a handler. The handler must not block or throw exceptions.
Expand Down Expand Up @@ -174,7 +183,7 @@ public static class H3<T0, T1, T2> {
/**
* The list of handlers.
*/
private List<Handler.H3<T0, T1, T2>> handlers = new ArrayList<Handler.H3<T0, T1, T2>>();
private List<Handler.H3<T0, T1, T2>> handlers = new ArrayList<Handler.H3<T0, T1, T2>>(4);

/**
* Adds a handler. The handler must not block or throw exceptions.
Expand Down
Loading

0 comments on commit 0350e33

Please sign in to comment.