mirror of
https://github.com/ethauvin/rife2.git
synced 2025-05-01 02:58:12 -07:00
Further workflow engine simplification, the event type doesn't need to have a particular API, it can be any object.
This commit is contained in:
parent
004c313119
commit
ba69340d20
6 changed files with 13 additions and 78 deletions
|
@ -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_;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
* <p>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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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};
|
||||
}
|
||||
}
|
|
@ -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<EventType, Collection<String>> eventsMapping_;
|
||||
private final ConcurrentHashMap<Object, Collection<String>> eventsMapping_;
|
||||
private final List<Event> pendingEvents_;
|
||||
private final CopyOnWriteArraySet<EventListener> 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<>();
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue