Permalink
Browse files

Added Javadoc comments to Diezel XML. Changed withKeyFinder signature…

… to use Class as argument.
  • Loading branch information...
1 parent bfd7de3 commit 36d58e058f0f8aa3c88eac5b0bb214d2d3a326f7 @leoneu leoneu committed Feb 23, 2012
View
8 subprojects/s4-base/src/main/java/org/apache/s4/base/Event.java
@@ -22,6 +22,14 @@
import com.google.common.collect.Maps;
+/**
+ * The base event class in S4. The base class supports generic key/value pairs which us useful for rapid prototyping and
+ * for inter-application communication. For greater efficiency and type safety, extend this class to create custom event
+ * types.
+ *
+ * @author leo
+ *
+ */
public class Event {
private static final Logger logger = LoggerFactory.getLogger(Event.class);
View
79 subprojects/s4-edsl/src/main/diezel/s4/s4.xml
@@ -5,57 +5,134 @@
<expression>(pe , type , prop* , (fireOn , afterInterval? , afterNumEvents?)? , (timer, withPeriod)? , (cache, size , expires? )? , asSingleton? , (emit, onField?, (withKey|withKeyFinder)?, to )* )+ , build</expression>
<transitions>
<transition name="pe">
+ <javadoc>
+ Creates a new {@link org.apache.s4.core.ProcessingElement} prototype.
+ @param name the PE name.
+ @see org.apache.s4.core.ProcessingElement
+ </javadoc>
<signature>pe(java.lang.String name)</signature>
</transition>
<transition name="type">
+ <javadoc>
+ Specifies the type of {@link org.apache.s4.core.ProcessingElement}.
+ @param type the PE type.
+ @see org.apache.s4.core.ProcessingElement
+ </javadoc>
<signature><![CDATA[type(java.lang.Class<? extends org.apache.s4.core.ProcessingElement> peType)]]></signature>
</transition>
<transition name="prop">
+ <javadoc>
+ Set a PE property value. The PE class must have a field name that matches {@code propName}. Otherwise, a runtime error will be thrown.
+ @param propName the property name that matches a field name.
+ @param propValue the property value specified as a string.
+ </javadoc>
<signature>prop(java.lang.String propName, java.lang.String propValue)</signature>
</transition>
<transition name="fireOn">
+ <javadoc>
+ Creates a {@link org.apache.s4.core.ProcessingElement} trigger that fires when an {@link org.apache.s4.base.Event} arrives.
+ @param eventType the type of event that fires this trigger.
+ @see org.apache.s4.core.ProcessingElement#setTrigger
+ </javadoc>
<signature><![CDATA[fireOn(java.lang.Class<? extends org.apache.s4.base.Event> eventType)]]></signature>
</transition>
<transition name="afterInterval">
+ <javadoc>Sets a trigger condition that specifies the minimum amount of time before the trigger is fired again.
+ @param interval the minimum time interval between trigger events.
+ @param timeUnit the time unit used to express the interval.
+ @see org.apache.s4.core.ProcessingElement#setTrigger
+ </javadoc>
<signature>afterInterval(long interval, java.util.concurrent.TimeUnit timeUnit)</signature>
</transition>
<transition name="afterNumEvents">
+ <javadoc>Sets a trigger condition that specifies the minimum of events that need to arrive before the trigger is fired again.
+ @param numEvents the minimum number of events between trigger activations.
+ @see org.apache.s4.core.ProcessingElement#setTrigger
+ </javadoc>
<signature>afterNumEvents(int numEvents)</signature>
</transition>
<transition name="timer">
+ <javadoc>Activate the PE timer.
+ @see org.apache.s4.core.ProcessingElement#setTimerInterval
+ </javadoc>
<signature>timer()</signature>
</transition>
<transition name="withPeriod">
+ <javadoc>Set the PE timer interval.
+ @param interval in timeUnit.
+ @param timeUnit the interval timeUnit
+ @see org.apache.s4.core.ProcessingElement#setTimerInterval
+ </javadoc>
<signature>withPeriod(long interval, java.util.concurrent.TimeUnit timeUnit)</signature>
</transition>
<transition name="cache">
+ <javadoc>Configure the PE cache.
+ @see org.apache.s4.core.ProcessingElement#setPECache
+ </javadoc>
<signature>cache()</signature>
</transition>
<transition name="size">
+ <javadoc>Sets the maximum number of PE instances in the cache.
+ @param size maximum number of PE instances
+ @see org.apache.s4.core.ProcessingElement#setPECache
+ </javadoc>
<signature>size(int size)</signature>
</transition>
<transition name="expires">
+ <javadoc>Sets the cache duration.
+ @param duration time in timeUnit.
+ @param timeUnit the expiration timeUnit
+ @see org.apache.s4.core.ProcessingElement#setPECache
+ </javadoc>
<signature>expires(long duration, java.util.concurrent.TimeUnit timeUnit)</signature>
</transition>
<transition name="asSingleton">
+ <javadoc>Make this prototype a singleton. Only one PE instance will be created.
+ @see org.apache.s4.core.ProcessingElement#setSingleton
+ </javadoc>
<signature>asSingleton()</signature>
</transition>
<transition name="emit">
+ <javadoc>Specify the type of event that will be emitted by this PE.
+ @param event the event type.
+ @see org.apache.s4.core.Stream
+ </javadoc>
<signature><![CDATA[emit(java.lang.Class<? extends org.apache.s4.base.Event> event)]]></signature>
</transition>
<transition name="onField">
+ <javadoc>.
+ @param onField the PE field name to which we need to bing this stream. This field is required to disambiguate when there is more than one target stream with the same Event type.
+ @see org.apache.s4.edsl.AppBuilder
+ @see org.apache.s4.core.Stream
+ </javadoc>
<signature>onField(java.lang.String fieldName)</signature>
</transition>
<transition name="withKeyFinder">
- <signature><![CDATA[withKeyFinder(org.apache.s4.base.KeyFinder<? extends org.apache.s4.base.Event> keyFinder)]]></signature>
+ <javadoc>Use a {@link org.apache.s4.base.KeyFinder} to retrieve the key value.
+ @param keyFinder
+ @see org.apache.s4.core.Stream
+ @see org.apache.s4.base.KeyFinder
+ @see org.apache.s4.base.Key
+ </javadoc>
+ <signature><![CDATA[withKeyFinder(Class<?> keyFinder)]]></signature>
</transition>
<transition name="withKey">
+ <javadoc>Provide the key name that matches a key in the generic {@link org.apache.s4.base.Event} class.
+ @param key
+ @see org.apache.s4.core.Stream
+ @see org.apache.s4.base.Event
+ @see org.apache.s4.base.Key
+ </javadoc>
<signature>withKey(java.lang.String key)</signature>
</transition>
<transition name="to">
+ <javadoc>Provide the target PEs to which this event is sent.
+ @param targetPeNames array of target PEs.
+ </javadoc>
<signature>to(java.lang.String... targetPeNames)</signature>
</transition>
<transition name="build">
+ <javadoc>Final method creates the S4 app.</javadoc>
<return>org.apache.s4.core.App</return>
<signature>build()</signature>
</transition>
View
10 subprojects/s4-edsl/src/main/java/org/apache/s4/edsl/StreamBuilder.java
@@ -61,6 +61,16 @@ void setKeyFinder(KeyFinder<?> keyFinder) {
stream.setName(type.getCanonicalName() + "," + keyFinder.getClass().getCanonicalName());
}
+ @SuppressWarnings("unchecked")
+ void setKeyFinder(Class<?> type) {
+ try {
+ stream.setKey((KeyFinder<T>) type.newInstance());
+ } catch (Exception e) {
+ logger.error("Unable to create instance of KeyFinder [{}].", type.toString());
+ e.printStackTrace();
+ }
+ }
+
void setKey(String keyDescriptor) {
stream.setKey(keyDescriptor);
View
6 subprojects/s4-edsl/src/test/java/org/apache/s4/edsl/MyApp.java
@@ -12,11 +12,11 @@ public void onInit() {
pe("PEY").type(PEY.class).prop("duration", "4").prop("height", "99").timer()
.withPeriod(2, TimeUnit.MINUTES).emit(EventA.class).onField("stream3")
- .withKeyFinder(new DurationKeyFinder()).to("PEZ").emit(EventA.class).onField("heightpez")
- .withKeyFinder(new HeightKeyFinder()).to("PEZ").
+ .withKeyFinder(DurationKeyFinder.class).to("PEZ").emit(EventA.class).onField("heightpez")
+ .withKeyFinder(HeightKeyFinder.class).to("PEZ").
pe("PEX").type(PEX.class).prop("query", "money").cache().size(100).expires(1, TimeUnit.MINUTES)
- .asSingleton().emit(EventB.class).withKeyFinder(new QueryKeyFinder()).to("PEY", "PEZ").
+ .asSingleton().emit(EventB.class).withKeyFinder(QueryKeyFinder.class).to("PEY", "PEZ").
build();
}
View
10 subprojects/s4-example/src/main/java/org/apache/s4/example/edsl/counter/CounterApp.java
@@ -48,22 +48,22 @@ protected void onInit() {
pe("Print").type(PrintPE.class).asSingleton().
pe("User Count").type(CounterPE.class).fireOn(Event.class).afterInterval(100, TimeUnit.MILLISECONDS)
- .emit(CountEvent.class).withKeyFinder(new CountKeyFinder()).to("Print").
+ .emit(CountEvent.class).withKeyFinder(CountKeyFinder.class).to("Print").
pe("Gender Count").type(CounterPE.class).fireOn(Event.class).afterInterval(100, TimeUnit.MILLISECONDS)
- .emit(CountEvent.class).withKeyFinder(new CountKeyFinder()).to("Print").
+ .emit(CountEvent.class).withKeyFinder(CountKeyFinder.class).to("Print").
pe("Age Count").type(CounterPE.class).fireOn(Event.class).afterInterval(100, TimeUnit.MILLISECONDS)
- .emit(CountEvent.class).withKeyFinder(new CountKeyFinder()).to("Print").
+ .emit(CountEvent.class).withKeyFinder(CountKeyFinder.class).to("Print").
pe("Generate User Event").type(GenerateUserEventPE.class).timer().withPeriod(1, TimeUnit.MILLISECONDS)
.asSingleton().
- emit(UserEvent.class).withKeyFinder(new UserIDKeyFinder()).to("User Count").
+ emit(UserEvent.class).withKeyFinder(UserIDKeyFinder.class).to("User Count").
emit(UserEvent.class).withKey("gender").to("Gender Count").
- emit(UserEvent.class).withKeyFinder(new AgeKeyFinder()).to("Age Count").
+ emit(UserEvent.class).withKeyFinder(AgeKeyFinder.class).to("Age Count").
build();
}

0 comments on commit 36d58e0

Please sign in to comment.