- * Builds the permissions string to be verified.
- *
- * @param aafInstance The aaf instance
- * @return The permissions
- */
- String getPermission(String aafInstance) {
- try {
- String type = getAafType();
- String action = getAafAction();
- if ("".equals(aafInstance)) {
- aafInstance = getAafInstance();
+ * Manage a list of tasks to be executed when an event occurs. This makes the following guarantees:
+ * <ul>
+ * <li>Tasks can be safely added and removed in the middle of a run.</li>
+ * <li>No task will be returned more than once during a run.</li>
+ * <li>No task will be returned when it is not, at that moment, in the list of tasks.</li>
+ * <li>At the moment when next() returns null, all tasks on the list have been returned during the run.</li>
+ * <li>Initially and once next() returns null during a run, next() will continue to return null until startRun() is
+ * called.
+ * </ul>
+ */
+ static class TaskList {
+
+ private Iterator<Runnable> runlist;
+ private final HashSet<Runnable> tasks = new HashSet<>();
+ private HashSet<Runnable> togo;
+ private HashSet<Runnable> sofar;
+ private HashSet<Runnable> added;
+ private HashSet<Runnable> removed;
+
+ /**
+ * Start executing the sequence of tasks.
+ */
+ synchronized void startRun() {
+ sofar = new HashSet<>();
+ added = new HashSet<>();
+ removed = new HashSet<>();
+ togo = new HashSet<>(tasks);
+ runlist = togo.iterator();
+ }
+
+ /**
+ * Get the next task to execute.
+ */
+ synchronized Runnable next() {
+ while (runlist != null) {
+ if (runlist.hasNext()) {
+ Runnable task = runlist.next();
+ if (addTaskToSoFar(task)) {
+ return task;
+ }
+ }
+ if (!added.isEmpty()) {
+ togo = added;
+ added = new HashSet<>();
+ removed.clear();
+ runlist = togo.iterator();
+ continue;
+ }
+ togo = null;
+ added = null;
+ removed = null;
+ sofar = null;
+ runlist = null;