tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r797834 - in /websites/staging/openejb/trunk/content: dev/ examples-trunk/ examples-trunk/cdi-alternative-and-stereotypes/ examples-trunk/cdi-events/ examples-trunk/cdi-events/src/ examples-trunk/cdi-events/src/main/ examples-trunk/cdi-even...
Date Tue, 01 Nov 2011 04:00:10 GMT
Author: buildbot
Date: Tue Nov  1 04:00:09 2011
New Revision: 797834

Log:
Staging update by buildbot

Added:
    websites/staging/openejb/trunk/content/dev/writing-examples.html
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/README.html
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/pom.xml
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/java/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/java/org/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/java/org/superbiz/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/java/org/superbiz/cdi/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/java/org/superbiz/cdi/events/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/resources/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/resources/META-INF/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/resources/META-INF/beans.xml
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/superbiz/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/superbiz/cdi/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/superbiz/cdi/events/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/resources/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/resources/META-INF/
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/resources/META-INF/beans.xml
    websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/resources/log4j.xml
Modified:
    websites/staging/openejb/trunk/content/examples-trunk/cdi-alternative-and-stereotypes/README.html
    websites/staging/openejb/trunk/content/examples-trunk/pom.xml

Added: websites/staging/openejb/trunk/content/dev/writing-examples.html
==============================================================================
--- websites/staging/openejb/trunk/content/dev/writing-examples.html (added)
+++ websites/staging/openejb/trunk/content/dev/writing-examples.html Tue Nov  1 04:00:09 2011
@@ -0,0 +1,198 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+
+    <meta charset="utf-8">
+      <title>Writing Examples</title>
+    <meta name="description" content="">
+    <meta name="author" content="">
+
+    <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
+    <!--[if lt IE 9]>
+      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+    <![endif]-->
+
+    <!-- Le styles -->
+    <link href="./../bootstrap.css" rel="stylesheet">
+    <link href="./../prettify.css" rel="stylesheet">
+    <link href="./../bootstrap-mods.css" rel="stylesheet">
+
+    <style type="text/css">
+      body {
+        padding-top: 60px;
+      }
+    </style>
+
+
+    <!-- Le fav and touch icons -->
+    <link rel="shortcut icon" href="./../images/favicon.ico">
+    <link rel="apple-touch-icon" href="./../images/apple-touch-icon.png">
+    <link rel="apple-touch-icon" sizes="72x72" href="./../images/apple-touch-icon-72x72.png">
+    <link rel="apple-touch-icon" sizes="114x114" href="./../images/apple-touch-icon-114x114.png">
+
+    <script src="./../javascript/prettify.js" type="text/javascript"></script>
+    <script src="./../javascript/jquery-latest.js"></script>
+    <script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
+    <script src="./../javascript/common.js"></script>
+    <script src="./../javascript/prettyprint.js"></script>
+
+  </head>
+
+  <body>
+
+    <div class="topbar">
+      <div class="fill">
+        <div class="container">
+          <a class="brand" href="./../index.html">Apache TomEE</a>
+          <ul class="nav">
+            <li><a href="./../index.html">Home</a></li>
+            <li><a href="./../downloads.html">Downloads</a></li>
+            <li><a href="./../documentation.html">Documentation</a></li>
+            <li><a href="./../support.html">Support</a></li>
+          </ul>
+
+            <!-- Google CSE Search Box Begins  -->
+            <FORM class="pull-right" id="searchbox_010475492895890475512:_t4iqjrgx90"
action="http://www.google.com/cse">
+                <INPUT type="hidden" name="cx" value="010475492895890475512:_t4iqjrgx90">
+                <INPUT type="hidden" name="cof" value="FORID:0">
+                <INPUT name="q" type="text" placeholder="Search">
+            </FORM>
+            <!--<SCRIPT type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_010475492895890475512:_t4iqjrgx90"></SCRIPT>-->
+            <!-- Google CSE Search Box Ends -->
+        </div>
+      </div>
+    </div>
+
+    <div class="container">
+
+    
+
+<div class="page-header">
+<small><a href="./..//index.html">Home</a>&nbsp;&raquo&nbsp;<a
href="./..//dev/">Dev</a></small><br>
+<h1>Writing Examples</h1>
+</div>
+
+<p>Some basic guideliness of writing examples:</p>
+
+<ul>
+<li>focus on one idea per example</li>
+<li>keep examples short
+<ul>
+<li>one test case</li>
+<li>minimal code to make the point</li>
+</ul></li>
+<li>avoid showing an entire API in one example, if possible</li>
+<li>be concious of the cost of "setting the stage"</li>
+<li>if examples get too big, split it</li>
+</ul>
+
+<h1>Noise vs signal</h1>
+
+<p>Example scenarios do not need to be believable and should not be elaborate.  Get
to the point in as few classes as possible.</p>
+
+<p>You should be able to explain the entire example in two minutes.</p>
+
+<h1>5 was to do the same thing</h1>
+
+<p>It takes time to learn the example scenario.  Be very mindful of that.</p>
+
+<p>If there are five ways to do the same thing, avoid making 5 different different
scenarios.  Copy the example to a new directory, and tweak it to show the variation.</p>
+
+<p>So say you used objects <code>Green</code>, <code>Square</code>
and <code>Checkers</code> to show the basic concept and you wish to show the next
variation of that same concecpt.  It is tempting to add to the same
+example objects <code>Yellow</code>, <code>Triangle</code> and <code>PolkaDots</code>.</p>
+
+<p>Avoid that.  Copy <code>Green</code>, <code>Square</code>
and <code>Checkers</code> to a new example, change the package name, and update
the few lines needed to show the difference.</p>
+
+<p>Which is easier to learn?</p>
+
+<ul>
+<li>934 + 55 = 989</li>
+<li>513 - 19 = 494</li>
+<li>468 * 44 = 20592</li>
+<li>708 / 89 = 7</li>
+<li>401 % 63 = 23</li>
+</ul>
+
+<p>Or:</p>
+
+<ul>
+<li>102 + 35 = 137</li>
+<li>102 - 35 = 67</li>
+<li>102 * 35 = 3570</li>
+<li>102 / 35 = 2</li>
+<li>102 % 35 = 32</li>
+</ul>
+
+<p>When presenting, you only get so much time to show people ideas.  If they have to
learn a new set of names and understand their relationship on each tiny variation, it severely
+impacts their ability to see what is supposed to be the same and what is supposed to be different.
 As a presenter this means you must show less and what you do show will be shown
+less clearly.</p>
+
+<p>When names and scenarios are consistent, the variations jump out quickly and with
impact.</p>
+
+<p>If there are five ways to do the same thing, show the same thing five different
ways.</p>
+
+<h1>Short Class Names</h1>
+
+<p>You don't need to document the example with the class name.  Class names that are
a mouthful cannot be effectively used in presentations or screencasts.</p>
+
+<p>Try to stick with one or two word class names.  Three tops.</p>
+
+<p>Avoid:</p>
+
+<ul>
+<li><code>BeanWithTwoDecoratorsAndOneProducerMethod</code></li>
+</ul>
+
+<p>Try instead:</p>
+
+<ul>
+<li><code>BlueBean</code></li>
+</ul>
+
+<p>Shorter names can be easier for all sorts of reasons.  Less words to keep "floating
in the head" when trying to truly see an example.</p>
+
+<p>Using the numbers from the previous section, which is easier?</p>
+
+<ul>
+<li>102 + 35 = 137</li>
+<li>102 - 35 = 67</li>
+<li>102 * 35 = 3570</li>
+<li>102 / 35 = 2</li>
+<li>102 % 35 = 32</li>
+</ul>
+
+<p>Or:</p>
+
+<ul>
+<li>12 + 3 = 15</li>
+<li>12 - 3 = 9</li>
+<li>12 * 3 = 36</li>
+<li>12 / 3 = 4</li>
+<li>12 % 3 = 0</li>
+</ul>
+
+<p>There's a finite amount people can keep in their head, save space for the important
stuff.</p>
+
+
+
+
+      <footer>
+        <p>
+        Copyright &copy; 2011 The Apache Software Foundation, Licensed under the Apache
License, Version 2.0.
+        Apache and the Apache feather logo are trademarks of The Apache Software Foundation.
+        </p>
+      </footer>
+
+    </div> <!-- /container -->
+
+  <SPAN style="display: none">
+    <SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">
+    </SCRIPT>
+    <SCRIPT type="text/javascript">
+      _uacct = "UA-2717626-1";
+      urchinTracker();
+    </SCRIPT>
+  </SPAN>
+
+  </body>
+</html>

Modified: websites/staging/openejb/trunk/content/examples-trunk/cdi-alternative-and-stereotypes/README.html
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-alternative-and-stereotypes/README.html
(original)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-alternative-and-stereotypes/README.html
Tue Nov  1 04:00:09 2011
@@ -140,10 +140,12 @@ public @interface Mock {}
 <p>So now we have our <code>@Mock</code> annotation which is a stereotype
able to replace <code>@Alternative</code> annotation
 we simply add this annotation to our mocks.</p>
 
-<p>If you run it now you'll have this exception:
-    javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.superbiz.cdi.stereotype.Vehicle]
is not found with the qualifiers
-    Qualifiers: [@javax.enterprise.inject.Default()]
-    for injection into Field Injection Point, field name :  vehicle, Bean Owner : [Journey,
Name:null, WebBeans Type:ENTERPRISE, API Types:[java.lang.Object,org.superbiz.cdi.stereotype.Journey],
Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]]</p>
+<p>If you run it now you'll have this exception:</p>
+
+<pre><code>javax.enterprise.inject.UnsatisfiedResolutionException: Api type [org.superbiz.cdi.stereotype.Vehicle]
is not found with the qualifiers
+Qualifiers: [@javax.enterprise.inject.Default()]
+for injection into Field Injection Point, field name :  vehicle, Bean Owner : [Journey, Name:null,
WebBeans Type:ENTERPRISE, API Types:[java.lang.Object,org.superbiz.cdi.stereotype.Journey],
Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]]
+</code></pre>
 
 <p>It means the stereotype is not activated. To do it simply add it to your <code>META-INF/beans.xml</code>:</p>
 

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-events/README.html
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-events/README.html (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-events/README.html Tue Nov 
1 04:00:09 2011
@@ -0,0 +1,144 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+
+    <meta charset="utf-8">
+      <title></title>
+    <meta name="description" content="">
+    <meta name="author" content="">
+
+    <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
+    <!--[if lt IE 9]>
+      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+    <![endif]-->
+
+    <!-- Le styles -->
+    <link href="./../../bootstrap.css" rel="stylesheet">
+    <link href="./../../prettify.css" rel="stylesheet">
+    <link href="./../../bootstrap-mods.css" rel="stylesheet">
+
+    <style type="text/css">
+      body {
+        padding-top: 60px;
+      }
+    </style>
+
+
+    <!-- Le fav and touch icons -->
+    <link rel="shortcut icon" href="./../../images/favicon.ico">
+    <link rel="apple-touch-icon" href="./../../images/apple-touch-icon.png">
+    <link rel="apple-touch-icon" sizes="72x72" href="./../../images/apple-touch-icon-72x72.png">
+    <link rel="apple-touch-icon" sizes="114x114" href="./../../images/apple-touch-icon-114x114.png">
+
+    <script src="./../../javascript/prettify.js" type="text/javascript"></script>
+    <script src="./../../javascript/jquery-latest.js"></script>
+    <script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
+    <script src="./../../javascript/common.js"></script>
+    <script src="./../../javascript/prettyprint.js"></script>
+
+  </head>
+
+  <body>
+
+    <div class="topbar">
+      <div class="fill">
+        <div class="container">
+          <a class="brand" href="./../../index.html">Apache TomEE</a>
+          <ul class="nav">
+            <li><a href="./../../index.html">Home</a></li>
+            <li><a href="./../../downloads.html">Downloads</a></li>
+            <li><a href="./../../documentation.html">Documentation</a></li>
+            <li><a href="./../../support.html">Support</a></li>
+          </ul>
+
+            <!-- Google CSE Search Box Begins  -->
+            <FORM class="pull-right" id="searchbox_010475492895890475512:_t4iqjrgx90"
action="http://www.google.com/cse">
+                <INPUT type="hidden" name="cx" value="010475492895890475512:_t4iqjrgx90">
+                <INPUT type="hidden" name="cof" value="FORID:0">
+                <INPUT name="q" type="text" placeholder="Search">
+            </FORM>
+            <!--<SCRIPT type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_010475492895890475512:_t4iqjrgx90"></SCRIPT>-->
+            <!-- Google CSE Search Box Ends -->
+        </div>
+      </div>
+    </div>
+
+    <div class="container">
+
+    
+
+<div class="row">
+    <div class="span8">
+        <small><a href="./../..//index.html">Home</a>&nbsp;&raquo&nbsp;<a
href="./../..//examples-trunk/">Examples Trunk</a>&nbsp;&raquo&nbsp;<a
href="./../..//examples-trunk/cdi-events/">Cdi Events</a></small><br>
+    </div>
+    <div class="span8">
+        <div class="pull-right">
+            <small><a href="http://ci.apache.org/projects/openejb/examples-generated/cdi-events/cdi-events.zip">download
example</a>
+        </div>
+    </div>
+</div>
+
+<div class="page-header">
+<h1></h1>
+</div>
+
+<h1>CDI events: loose coupling and extensibility</h1>
+
+<p>CDI allows you to extend business code by the Notifier/Observer pattern.</p>
+
+<p>To do it you simply inject a field <code>Event</code> in the notifier
class. This class is a template
+and the parameter type is the object type to fire. Then when you want to notify observers
+you simply call the method fire of the event object passing as a parameter the event itself
+(your own class!).</p>
+
+<p>On the other side you annotated a method parameter <code>@Observes</code>
and the parameter type is the sent type
+by the notifier.</p>
+
+<p>Note: of course you can add qualifiers to be more precise on your events.</p>
+
+<h1>The example</h1>
+
+<p>The example is pretty simple: an ejb uses the <code>@Schedule</code>
annotation to get a notification each second.
+The each second this EJB will send the current date through CDI events.</p>
+
+<p>This is our "business" code. It is a simple behavior (nothing).</p>
+
+<p>In our test (which is considered as an extension) we created an observer (<code>Observer</code>
class)
+which simply store and log each received date.</p>
+
+<p>The test itself (<code>EventTest</code>) simply verifies the dates were
received.</p>
+
+<h1>Conclusion</h1>
+
+<p>CDI let's implement very easily plugins through this event mecanism.</p>
+
+<p>If you go further and look at CDI plugin API you'll realize it is simply the same
kind
+of events. CDI events is really the basis of CDI.</p>
+
+
+<div class="page-header">&nbsp;</div>
+<h4>APIs Used</h4>
+
+
+
+
+      <footer>
+        <p>
+        Copyright &copy; 2011 The Apache Software Foundation, Licensed under the Apache
License, Version 2.0.
+        Apache and the Apache feather logo are trademarks of The Apache Software Foundation.
+        </p>
+      </footer>
+
+    </div> <!-- /container -->
+
+  <SPAN style="display: none">
+    <SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">
+    </SCRIPT>
+    <SCRIPT type="text/javascript">
+      _uacct = "UA-2717626-1";
+      urchinTracker();
+    </SCRIPT>
+  </SPAN>
+
+  </body>
+</html>

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-events/pom.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-events/pom.xml (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-events/pom.xml Tue Nov  1 04:00:09
2011
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<!-- $Rev: 1178411 $ $Date: 2011-10-03 15:35:26 +0200 (lun. 03 oct. 2011) $ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.superbiz</groupId>
+  <artifactId>cdi-events</artifactId>
+  <packaging>jar</packaging>
+  <version>1.1-SNAPSHOT</version>
+  <name>OpenEJB :: Examples :: CDI Events</name>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.3.2</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <repositories>
+    <repository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>6.0-3-SNAPSHOT</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <!--
+    The <scope>test</scope> guarantees that non of your runtime
+    code is dependent on any OpenEJB classes.
+    -->
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>openejb-core</artifactId>
+      <version>4.0.0-beta-2-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <!-- to show events we log them in the test -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>1.6.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.6.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <version>1.2.16</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <!--
+  This section allows you to configure where to publish libraries for sharing.
+  It is not required and may be deleted.  For more information see:
+  http://maven.apache.org/plugins/maven-deploy-plugin/
+  -->
+  <distributionManagement>
+    <repository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/repo/</url>
+    </repository>
+    <snapshotRepository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/snapshot-repo/</url>
+    </snapshotRepository>
+  </distributionManagement>
+</project>

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/java/org/superbiz/cdi/events/Notifier.java
Tue Nov  1 04:00:09 2011
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.cdi.events;
+
+import javax.ejb.Schedule;
+import javax.ejb.Singleton;
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+import java.util.Date;
+
+/**
+ * @author rmannibucau
+ */
+@Singleton
+public class Notifier {
+    @Inject private Event<Date> dateEvent;
+
+    @Schedule(second = "*", minute = "*", hour = "*")
+    public void sendHour() {
+        dateEvent.fire(new Date());
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/resources/META-INF/beans.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/resources/META-INF/beans.xml
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/main/resources/META-INF/beans.xml
Tue Nov  1 04:00:09 2011
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd" />

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/superbiz/cdi/events/EventTest.java
Tue Nov  1 04:00:09 2011
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.cdi.events;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.inject.Inject;
+import javax.naming.NamingException;
+
+import static junit.framework.Assert.assertTrue;
+
+/**
+ * @author rmannibucau
+ */
+public class EventTest {
+    private static EJBContainer container;
+    private static String initialLogProperty;
+
+    @Inject
+    private Observer observer;
+
+    @BeforeClass
+    public static void start() throws NamingException {
+        initialLogProperty = System.getProperty("openejb.logger.external");
+        System.setProperty("openejb.logger.external", "true");
+        container = EJBContainer.createEJBContainer();
+    }
+
+    @AfterClass
+    public static void shutdown() {
+        if (container != null) {
+            container.close();
+        }
+        if (initialLogProperty != null) {
+            System.setProperty("openejb.logger.external", initialLogProperty);
+        } else {
+            System.getProperties().remove("openejb.logger.external");
+        }
+    }
+
+    @Before
+    public void inject() throws NamingException {
+        container.getContext().bind("inject", this);
+    }
+
+    @After
+    public void reset() throws NamingException {
+        container.getContext().unbind("inject");
+    }
+
+    @Test
+    public void observe() throws InterruptedException {
+        Thread.sleep(4000);
+        assertTrue(observer.getDates().size() > 3); // in 4s normally at least 3 events
were received
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/java/org/superbiz/cdi/events/Observer.java
Tue Nov  1 04:00:09 2011
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.superbiz.cdi.events;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.enterprise.event.Observes;
+import javax.inject.Singleton;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author rmannibucau
+ */
+@Singleton
+public class Observer {
+    private static final Logger LOGGER = LoggerFactory.getLogger(Observer.class);
+
+    private List<Date> dates = new ArrayList<Date>();
+
+    public void saveDate(@Observes Date date) {
+        dates.add(date);
+        LOGGER.info("received date '{}'", date);
+    }
+
+    public List<Date> getDates() {
+        return dates;
+    }
+}

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/resources/META-INF/beans.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/resources/META-INF/beans.xml
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/resources/META-INF/beans.xml
Tue Nov  1 04:00:09 2011
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd" />

Added: websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/resources/log4j.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/resources/log4j.xml
(added)
+++ websites/staging/openejb/trunk/content/examples-trunk/cdi-events/src/test/resources/log4j.xml
Tue Nov  1 04:00:09 2011
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+  <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
+    <param name="Target" value="System.out"/>
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{2}] %m%n"/>
+    </layout>
+  </appender>
+
+  <logger name="org.superbiz.cdi.events.Observer" additivity="false">
+    <level value="info"/>
+    <appender-ref ref="stdout"/>
+  </logger>
+  <logger name="org.apache" additivity="false">
+    <level value="info"/>
+    <appender-ref ref="stdout"/>
+  </logger>
+
+  <root>
+    <priority value="WARN"/>
+    <appender-ref ref="stdout"/>
+  </root>
+</log4j:configuration>

Modified: websites/staging/openejb/trunk/content/examples-trunk/pom.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/pom.xml (original)
+++ websites/staging/openejb/trunk/content/examples-trunk/pom.xml Tue Nov  1 04:00:09 2011
@@ -17,7 +17,7 @@
     limitations under the License.
 -->
 
-<!-- $Rev: 1195236 $ $Date: 2011-10-30 20:07:00 +0000 (Sun, 30 Oct 2011) $ -->
+<!-- $Rev: 1195386 $ $Date: 2011-10-31 10:00:38 +0000 (Mon, 31 Oct 2011) $ -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <parent>
@@ -90,6 +90,7 @@
     <module>cdi-produces-disposes</module>
     <module>dynamic-implementation</module>
     <module>cdi-alternative-and-stereotypes</module>
+    <module>cdi-events</module>
   </modules>
   <profiles>
     <profile>



Mime
View raw message