You are viewing a plain text version of this content. The canonical link for it is here.
Posted to s4-commits@incubator.apache.org by le...@apache.org on 2012/02/23 00:22:30 UTC

[1/7] git commit: Added Javadoc comments to Diezel XML. Changed withKeyFinder signature to use Class as argument.

Updated Branches:
  refs/heads/piper 2aa2cb236 -> 36d58e058


Added Javadoc comments to Diezel XML. Changed withKeyFinder signature to use Class as argument.


Project: http://git-wip-us.apache.org/repos/asf/incubator-s4/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s4/commit/36d58e05
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s4/tree/36d58e05
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s4/diff/36d58e05

Branch: refs/heads/piper
Commit: 36d58e058f0f8aa3c88eac5b0bb214d2d3a326f7
Parents: bfd7de3
Author: Leo Neumeyer <le...@apache.org>
Authored: Wed Feb 22 16:13:50 2012 -0800
Committer: Leo Neumeyer <le...@apache.org>
Committed: Wed Feb 22 16:13:50 2012 -0800

----------------------------------------------------------------------
 .../src/main/java/org/apache/s4/base/Event.java    |    8 ++
 subprojects/s4-edsl/src/main/diezel/s4/s4.xml      |   79 ++++++++++++++-
 .../java/org/apache/s4/edsl/StreamBuilder.java     |   10 ++
 .../src/test/java/org/apache/s4/edsl/MyApp.java    |    6 +-
 .../apache/s4/example/edsl/counter/CounterApp.java |   10 +-
 5 files changed, 104 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/36d58e05/subprojects/s4-base/src/main/java/org/apache/s4/base/Event.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-base/src/main/java/org/apache/s4/base/Event.java b/subprojects/s4-base/src/main/java/org/apache/s4/base/Event.java
index 0a71e29..11a950d 100644
--- a/subprojects/s4-base/src/main/java/org/apache/s4/base/Event.java
+++ b/subprojects/s4-base/src/main/java/org/apache/s4/base/Event.java
@@ -22,6 +22,14 @@ import org.slf4j.LoggerFactory;
 
 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);

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/36d58e05/subprojects/s4-edsl/src/main/diezel/s4/s4.xml
----------------------------------------------------------------------
diff --git a/subprojects/s4-edsl/src/main/diezel/s4/s4.xml b/subprojects/s4-edsl/src/main/diezel/s4/s4.xml
index 5330c47..90764b2 100644
--- a/subprojects/s4-edsl/src/main/diezel/s4/s4.xml
+++ b/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>

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/36d58e05/subprojects/s4-edsl/src/main/java/org/apache/s4/edsl/StreamBuilder.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-edsl/src/main/java/org/apache/s4/edsl/StreamBuilder.java b/subprojects/s4-edsl/src/main/java/org/apache/s4/edsl/StreamBuilder.java
index 841b109..82976e0 100644
--- a/subprojects/s4-edsl/src/main/java/org/apache/s4/edsl/StreamBuilder.java
+++ b/subprojects/s4-edsl/src/main/java/org/apache/s4/edsl/StreamBuilder.java
@@ -61,6 +61,16 @@ class StreamBuilder<T extends Event> {
         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);

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/36d58e05/subprojects/s4-edsl/src/test/java/org/apache/s4/edsl/MyApp.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-edsl/src/test/java/org/apache/s4/edsl/MyApp.java b/subprojects/s4-edsl/src/test/java/org/apache/s4/edsl/MyApp.java
index e299bbf..75fea88 100644
--- a/subprojects/s4-edsl/src/test/java/org/apache/s4/edsl/MyApp.java
+++ b/subprojects/s4-edsl/src/test/java/org/apache/s4/edsl/MyApp.java
@@ -12,11 +12,11 @@ public class MyApp extends BuilderS4DSL {
 
                 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();
     }

http://git-wip-us.apache.org/repos/asf/incubator-s4/blob/36d58e05/subprojects/s4-example/src/main/java/org/apache/s4/example/edsl/counter/CounterApp.java
----------------------------------------------------------------------
diff --git a/subprojects/s4-example/src/main/java/org/apache/s4/example/edsl/counter/CounterApp.java b/subprojects/s4-example/src/main/java/org/apache/s4/example/edsl/counter/CounterApp.java
index e59bcef..2019a1e 100644
--- a/subprojects/s4-example/src/main/java/org/apache/s4/example/edsl/counter/CounterApp.java
+++ b/subprojects/s4-example/src/main/java/org/apache/s4/example/edsl/counter/CounterApp.java
@@ -48,22 +48,22 @@ final public class CounterApp extends BuilderS4DSL {
         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();
     }