From ba69340d2003e768dfb6b4cb59a9cff441616042 Mon Sep 17 00:00:00 2001 From: Geert Bevin Date: Wed, 18 Jan 2023 23:23:29 -0500 Subject: [PATCH] Further workflow engine simplification, the event type doesn't need to have a particular API, it can be any object. --- lib/src/main/java/rife/workflow/Event.java | 6 +-- .../main/java/rife/workflow/EventType.java | 39 ------------------- lib/src/main/java/rife/workflow/Task.java | 10 ++--- .../config/InstrumentWorkflowConfig.java | 3 +- .../java/rife/workflow/run/TaskRunner.java | 5 +-- .../rifeworkflowtasks/TestEventTypes.java | 28 +------------ 6 files changed, 13 insertions(+), 78 deletions(-) delete mode 100644 lib/src/main/java/rife/workflow/EventType.java diff --git a/lib/src/main/java/rife/workflow/Event.java b/lib/src/main/java/rife/workflow/Event.java index a2e8b21f..40534cc7 100644 --- a/lib/src/main/java/rife/workflow/Event.java +++ b/lib/src/main/java/rife/workflow/Event.java @@ -20,7 +20,7 @@ import java.util.Date; public class Event { private final Date moment_ = new Date(); private final Task source_; - private final EventType type_; + private final Object type_; private final Object data_; /** @@ -31,7 +31,7 @@ public class Event { * @param data the data that has to be sent along with the event * @since 1.0 */ - public Event(final Task source, final EventType type, final Object data) { + public Event(final Task source, final Object type, final Object data) { source_ = source; type_ = type; data_ = data; @@ -63,7 +63,7 @@ public class Event { * @return this event's type * @since 1.0 */ - public EventType getType() { + public Object getType() { return type_; } diff --git a/lib/src/main/java/rife/workflow/EventType.java b/lib/src/main/java/rife/workflow/EventType.java deleted file mode 100644 index 7968b0c1..00000000 --- a/lib/src/main/java/rife/workflow/EventType.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com) - * Licensed under the Apache License, Version 2.0 (the "License") - */ -package rife.workflow; - -/** - * The type of an event. - *

The only basic requirement is that a unique textual type identifier is - * present for each logically different type. Apart from that, classes can - * extend this base class to create more elaborate constructs, if required. - * - * @author Geert Bevin (gbevin[remove] at uwyn dot com) - * @since 1.0 - */ -public abstract class EventType { - /** - * Returns the textual type identifier that uniquely defines an event type. - * - * @return the textual type identifier - * @since 1.0 - */ - public abstract String getType(); - - public String toString() { - return getType(); - } - - public boolean equals(Object obj) { - if (null == obj) return false; - if (obj == this) return true; - if (!(obj instanceof EventType)) return false; - return ((EventType) obj).getType().equals(getType()); - } - - public int hashCode() { - return getType().hashCode(); - } -} \ No newline at end of file diff --git a/lib/src/main/java/rife/workflow/Task.java b/lib/src/main/java/rife/workflow/Task.java index 35cf2d6b..8f916ebd 100644 --- a/lib/src/main/java/rife/workflow/Task.java +++ b/lib/src/main/java/rife/workflow/Task.java @@ -37,11 +37,11 @@ public abstract class Task implements CloneableContinuable { * * @param runner the task runner where the even should be triggered * @param type the type of the event - * @see #trigger(rife.workflow.run.TaskRunner, EventType, Object) + * @see #trigger(rife.workflow.run.TaskRunner, Object, Object) * @see TaskRunner#trigger * @since 1.0 */ - protected void trigger(TaskRunner runner, EventType type) { + protected void trigger(TaskRunner runner, Object type) { trigger(runner, type, null); } @@ -52,11 +52,11 @@ public abstract class Task implements CloneableContinuable { * @param runner the task runner where the even should be triggered * @param type the type of the event * @param data the data that will be sent with the event - * @see #trigger(rife.workflow.run.TaskRunner, EventType) + * @see #trigger(rife.workflow.run.TaskRunner, Object) * @see TaskRunner#trigger * @since 1.0 */ - protected void trigger(TaskRunner runner, EventType type, Object data) { + protected void trigger(TaskRunner runner, Object type, Object data) { runner.trigger(new Event(this, type, data)); } @@ -69,7 +69,7 @@ public abstract class Task implements CloneableContinuable { * @return the event that woke up the task * @since 1.0 */ - public final Event waitForEvent(EventType type) { + public final Event waitForEvent(Object type) { // this should not be triggered, since bytecode rewriting will replace this // method call with the appropriate logic throw new UnsupportedOperationException(); diff --git a/lib/src/main/java/rife/workflow/config/InstrumentWorkflowConfig.java b/lib/src/main/java/rife/workflow/config/InstrumentWorkflowConfig.java index 78fa10fb..a98afb0c 100644 --- a/lib/src/main/java/rife/workflow/config/InstrumentWorkflowConfig.java +++ b/lib/src/main/java/rife/workflow/config/InstrumentWorkflowConfig.java @@ -7,7 +7,6 @@ package rife.workflow.config; import rife.continuations.CloneableContinuable; import rife.continuations.ContinuationConfigInstrument; import rife.workflow.Event; -import rife.workflow.EventType; import rife.workflow.run.TaskRunner; /** @@ -43,6 +42,6 @@ public class InstrumentWorkflowConfig implements ContinuationConfigInstrument { } public Class[] getCallMethodArgumentTypes() { - return new Class[]{EventType.class}; + return new Class[]{Object.class}; } } \ No newline at end of file diff --git a/lib/src/main/java/rife/workflow/run/TaskRunner.java b/lib/src/main/java/rife/workflow/run/TaskRunner.java index 35b142cb..6001630b 100644 --- a/lib/src/main/java/rife/workflow/run/TaskRunner.java +++ b/lib/src/main/java/rife/workflow/run/TaskRunner.java @@ -14,7 +14,6 @@ import java.util.concurrent.*; import rife.continuations.*; import rife.continuations.basic.*; import rife.workflow.Event; -import rife.workflow.EventType; import rife.workflow.config.InstrumentWorkflowConfig; /** @@ -34,7 +33,7 @@ public class TaskRunner { private final ExecutorService taskExecutor_; private final BasicContinuableRunner runner_; - private final ConcurrentHashMap> eventsMapping_; + private final ConcurrentHashMap> eventsMapping_; private final List pendingEvents_; private final CopyOnWriteArraySet listeners_; @@ -173,7 +172,7 @@ public class TaskRunner { private class EventTypeCallTargetRetriever implements CallTargetRetriever { public CloneableContinuable getCallTarget(Object target, CallState state) { - var type = (EventType) target; + var type = target; eventsMapping_.compute(type, (eventType, ids) -> { if (ids == null) ids = new HashSet<>(); diff --git a/lib/src/test/java/rifeworkflowtasks/TestEventTypes.java b/lib/src/test/java/rifeworkflowtasks/TestEventTypes.java index ba7c93ca..4dab98b6 100644 --- a/lib/src/test/java/rifeworkflowtasks/TestEventTypes.java +++ b/lib/src/test/java/rifeworkflowtasks/TestEventTypes.java @@ -4,30 +4,6 @@ */ package rifeworkflowtasks; -import rife.workflow.EventType; - -public abstract class TestEventTypes { - public static final EventType TYPE1 = new EventType() { - public String getType() { - return "TYPE1"; - } - }; - - public static final EventType TYPE2 = new EventType() { - public String getType() { - return "TYPE2"; - } - }; - - public static final EventType BEGIN = new EventType() { - public String getType() { - return "BEGIN"; - } - }; - - public static final EventType END = new EventType() { - public String getType() { - return "END"; - } - }; +public enum TestEventTypes { + TYPE1, TYPE2, BEGIN, END } \ No newline at end of file