You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2016/12/04 11:01:44 UTC

svn commit: r1772522 [40/45] - in /tomee/site/trunk: content/ content/admin/ content/admin/cluster/ content/admin/configuration/ content/advanced/ content/advanced/applicationcomposer/ content/advanced/client/ content/advanced/setup/ content/advanced/s...

Added: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-events.adoc
URL: http://svn.apache.org/viewvc/tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-events.adoc?rev=1772522&view=auto
==============================================================================
--- tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-events.adoc (added)
+++ tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-events.adoc Sun Dec  4 11:01:40 2016
@@ -0,0 +1,185 @@
+= Schedule CDI Events
+:jbake-date: 2016-09-06
+:jbake-type: page
+:jbake-tomeepdf:
+:jbake-status: published
+
+Example schedule-events can be browsed at https://github.com/apache/tomee/tree/master/examples/schedule-events
+
+
+This example uses a nice CDI/EJB combination to schedule CDI Events.  This is useful if you want CDI Events that fire regularly or at a specific time or calendar date.
+
+Effectively this is a simple wrapper around the `BeanManager.fireEvent(Object,Annotations...)` method that adds `ScheduleExpression` into the mix.
+
+==  ScheduleExpression and @Timeout
+
+The logic here is simple, we effecitvely expose a method identical to `BeanManager.fireEvent(Object, Annotations...)` and wrap it as  `scheduleEvent(ScheduleExpression, Object, Annotation...)`
+
+To do that we use the EJB `TimerService` (under the covers this is Quartz) and create an `@Timeout` method which will be run when the `ScheduleExpression` activates.
+
+The `@Timeout` method, simply called `timeout`, takes the event and fires it.
+
+
+[source,java]
+----
+@Singleton
+@Lock(LockType.READ)
+public class Scheduler {
+
+    @Resource
+    private TimerService timerService;
+
+    @Resource
+    private BeanManager beanManager;
+
+    public void scheduleEvent(ScheduleExpression schedule, Object event, Annotation... qualifiers) {
+
+        timerService.createCalendarTimer(schedule, new TimerConfig(new EventConfig(event, qualifiers), false));
+    }
+
+    @Timeout
+    private void timeout(Timer timer) {
+        final EventConfig config = (EventConfig) timer.getInfo();
+
+        beanManager.fireEvent(config.getEvent(), config.getQualifiers());
+    }
+
+    // Doesn't actually need to be serializable, just has to implement it
+    private final class EventConfig implements Serializable {
+
+        private final Object event;
+        private final Annotation[] qualifiers;
+
+        private EventConfig(Object event, Annotation[] qualifiers) {
+            this.event = event;
+            this.qualifiers = qualifiers;
+        }
+
+        public Object getEvent() {
+            return event;
+        }
+
+        public Annotation[] getQualifiers() {
+            return qualifiers;
+        }
+    }
+}
+----
+
+
+Then to use it, have `Scheduler` injected as an EJB and enjoy.
+
+
+[source,java]
+----
+public class SomeBean {
+
+    @EJB
+    private Scheduler scheduler;
+
+    public void doit() throws Exception {
+
+        // every five minutes
+        final ScheduleExpression schedule = new ScheduleExpression()
+                .hour("*")
+                .minute("*")
+                .second("*/5");
+
+        scheduler.scheduleEvent(schedule, new TestEvent("five"));
+    }
+
+    /**
+     * Event will fire every five minutes
+     */
+    public void observe(@Observes TestEvent event) {
+        // process the event
+    }
+
+}
+----
+
+
+==  Test Case
+
+A working test case for the above would be as follows:
+
+
+[source,java]
+----
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.ejb.AccessTimeout;
+import javax.ejb.EJB;
+import javax.ejb.ScheduleExpression;
+import javax.ejb.embeddable.EJBContainer;
+import javax.enterprise.event.Observes;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class SchedulerTest {
+
+    public static final CountDownLatch events = new CountDownLatch(3);
+
+    @EJB
+    private Scheduler scheduler;
+
+    @Test
+    public void test() throws Exception {
+
+        final ScheduleExpression schedule = new ScheduleExpression()
+                .hour("*")
+                .minute("*")
+                .second("*/5");
+
+        scheduler.scheduleEvent(schedule, new TestEvent("five"));
+
+        Assert.assertTrue(events.await(1, TimeUnit.MINUTES));
+    }
+
+
+    @AccessTimeout(value = 1, unit = TimeUnit.MINUTES)
+    public void observe(@Observes TestEvent event) {
+        if ("five".equals(event.getMessage())) {
+            events.countDown();
+        }
+    }
+
+    public static class TestEvent {
+        private final String message;
+
+        public TestEvent(String message) {
+            this.message = message;
+        }
+
+        public String getMessage() {
+            return message;
+        }
+    }
+
+    @Before
+    public void setup() throws Exception {
+        EJBContainer.createEJBContainer().getContext().bind("inject", this);
+    }
+}
+----
+
+
+
+==  You must know
+
+ - CDI Events are not multi-treaded
+
+If there are 10 observers and each of them take 7 minutes to execute, then the total execution time for the one event is 70 minutes.  It would do you absolutely no good to schedule that event to fire more frequently than 70 minutes.
+
+What would happen if you did?  Depends on the `@Singleton` `@Lock` policy
+
+ - `@Lock(WRITE)` is the default.  In this mode the `timeout` method would essentially be locked until the previous invocation completes.  Having it fire every 5 minutes even though you can only process one every 70 minutes would eventually cause all the pooled timer threads to be waiting on your Singleton.
+ - `@Lock(READ)` allows for parallel execution of the `timeout` method.  Events will fire in parallel for a while.  However since they actually are taking 70 minutes each, within an hour or so we'll run out of threads in the timer pool just like above.
+
+The elegant solution is to use `@Lock(WRITE)` then specify some short timeout like `@AccessTimeout(value = 1, unit = TimeUnit.MINUTES)` on the `timeout` method.  When the next 5 minute invocation is triggered, it will wait up until 1 minute to get access to the Singleton before giving up.  This will keep your timer pool from filling up with backed up jobs -- the "overflow" is simply discarded.
+

Propchange: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-events.adoc
------------------------------------------------------------------------------
    svn:executable = *

Added: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-expression.adoc
URL: http://svn.apache.org/viewvc/tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-expression.adoc?rev=1772522&view=auto
==============================================================================
--- tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-expression.adoc (added)
+++ tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-expression.adoc Sun Dec  4 11:01:40 2016
@@ -0,0 +1,185 @@
+= Schedule Expression
+:jbake-date: 2016-09-06
+:jbake-type: page
+:jbake-tomeepdf:
+:jbake-status: published
+
+Example schedule-expression can be browsed at https://github.com/apache/tomee/tree/master/examples/schedule-expression
+
+
+In this example we exercise the `TimerService`.
+
+
+NOTE: "The TimerService interface provides enterprise bean components with access to the container-provided Timer Service. 
+
+The EJB Timer Service allows entity beans, stateless session beans, and message-driven beans to be registered for timer 
+callback events at a specified time, after a specified elapsed time, or after a specified interval."
+
+For a complete description of the TimerService, please refer to the Java EE tutorial dedicated to the 
+link:http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html[Timer Service].
+
+==  FarmerBrown
+
+At `PostConstruct` we create 5 programmatic timers. First four will most likely not be triggered during the test
+execution, however the last one will timeout a couple of times.
+
+Each timer contains an info attribute, which can be inspected at timeout.   
+
+
+[source,java]
+----
+package org.superbiz.corn;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.ScheduleExpression;
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TimerConfig;
+import javax.ejb.TimerService;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * This is where we schedule all of Farmer Brown's corn jobs
+ *
+ * @version $Revision$ $Date$
+ */
+@Singleton
+@Lock(LockType.READ) // allows timers to execute in parallel
+@Startup
+public class FarmerBrown {
+
+    private final AtomicInteger checks = new AtomicInteger();
+
+    @Resource
+    private TimerService timerService;
+
+    @PostConstruct
+    private void construct() {
+        final TimerConfig plantTheCorn = new TimerConfig("plantTheCorn", false);
+        timerService.createCalendarTimer(new ScheduleExpression().month(5).dayOfMonth("20-Last").minute(0).hour(8), plantTheCorn);
+        timerService.createCalendarTimer(new ScheduleExpression().month(6).dayOfMonth("1-10").minute(0).hour(8), plantTheCorn);
+
+        final TimerConfig harvestTheCorn = new TimerConfig("harvestTheCorn", false);
+        timerService.createCalendarTimer(new ScheduleExpression().month(9).dayOfMonth("20-Last").minute(0).hour(8), harvestTheCorn);
+        timerService.createCalendarTimer(new ScheduleExpression().month(10).dayOfMonth("1-10").minute(0).hour(8), harvestTheCorn);
+
+        final TimerConfig checkOnTheDaughters = new TimerConfig("checkOnTheDaughters", false);
+        timerService.createCalendarTimer(new ScheduleExpression().second("*").minute("*").hour("*"), checkOnTheDaughters);
+    }
+
+    @Timeout
+    public void timeout(Timer timer) {
+        if ("plantTheCorn".equals(timer.getInfo())) {
+            plantTheCorn();
+        } else if ("harvestTheCorn".equals(timer.getInfo())) {
+            harvestTheCorn();
+        } else if ("checkOnTheDaughters".equals(timer.getInfo())) {
+            checkOnTheDaughters();
+        }
+    }
+
+    private void plantTheCorn() {
+        // Dig out the planter!!!
+    }
+
+    private void harvestTheCorn() {
+        // Dig out the combine!!!
+    }
+
+    private void checkOnTheDaughters() {
+        checks.incrementAndGet();
+    }
+
+    public int getChecks() {
+        return checks.get();
+    }
+}
+----
+
+
+==  FarmerBrownTest
+
+The test class acquires an instance from the context and waits for 5 seconds to give the timers a chance to timeout.
+
+
+[source,java]
+----
+package org.superbiz.corn;
+
+import junit.framework.TestCase;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.Context;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class FarmerBrownTest extends TestCase {
+
+    public void test() throws Exception {
+
+        final Context context = EJBContainer.createEJBContainer().getContext();
+
+        final FarmerBrown farmerBrown = (FarmerBrown) context.lookup("java:global/schedule-expression/FarmerBrown");
+
+        // Give Farmer brown a chance to do some work
+        Thread.sleep(SECONDS.toMillis(5));
+
+        final int checks = farmerBrown.getChecks();
+        assertTrue(checks + "", checks > 4);
+    }
+}
+----
+
+
+=  Running
+
+    
+
+[source]
+----
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.corn.FarmerBrownTest
+Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
+http://tomee.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/schedule-expression
+INFO - openejb.base = /Users/dblevins/examples/schedule-expression
+INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/schedule-expression/target/classes
+INFO - Beginning load: /Users/dblevins/examples/schedule-expression/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/schedule-expression
+WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime.
+INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container)
+INFO - Auto-creating a container for bean FarmerBrown: Container(type=SINGLETON, id=Default Singleton Container)
+INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+INFO - Auto-creating a container for bean org.superbiz.corn.FarmerBrownTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Enterprise application "/Users/dblevins/examples/schedule-expression" loaded.
+INFO - Assembling app: /Users/dblevins/examples/schedule-expression
+INFO - Jndi(name="java:global/schedule-expression/FarmerBrown!org.superbiz.corn.FarmerBrown")
+INFO - Jndi(name="java:global/schedule-expression/FarmerBrown")
+INFO - Jndi(name="java:global/EjbModule481105279/org.superbiz.corn.FarmerBrownTest!org.superbiz.corn.FarmerBrownTest")
+INFO - Jndi(name="java:global/EjbModule481105279/org.superbiz.corn.FarmerBrownTest")
+INFO - Created Ejb(deployment-id=org.superbiz.corn.FarmerBrownTest, ejb-name=org.superbiz.corn.FarmerBrownTest, container=Default Managed Container)
+INFO - Created Ejb(deployment-id=FarmerBrown, ejb-name=FarmerBrown, container=Default Singleton Container)
+INFO - Started Ejb(deployment-id=org.superbiz.corn.FarmerBrownTest, ejb-name=org.superbiz.corn.FarmerBrownTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=FarmerBrown, ejb-name=FarmerBrown, container=Default Singleton Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/schedule-expression)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.141 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+----
+
+    

Propchange: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-expression.adoc
------------------------------------------------------------------------------
    svn:executable = *

Added: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-methods-meta.adoc
URL: http://svn.apache.org/viewvc/tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-methods-meta.adoc?rev=1772522&view=auto
==============================================================================
--- tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-methods-meta.adoc (added)
+++ tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-methods-meta.adoc Sun Dec  4 11:01:40 2016
@@ -0,0 +1,384 @@
+= Schedule Methods Meta
+:jbake-date: 2016-09-06
+:jbake-type: page
+:jbake-tomeepdf:
+:jbake-status: published
+
+Example schedule-methods-meta can be browsed at https://github.com/apache/tomee/tree/master/examples/schedule-methods-meta
+
+
+*Help us document this example! Click the blue pencil icon in the upper right to edit this page.*
+
+==  BiAnnually
+
+
+[source,java]
+----
+package org.superbiz.corn.meta.api;
+
+import javax.ejb.Schedule;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Metatype
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+
+public @interface BiAnnually {
+    public static interface $ {
+
+        @BiAnnually
+        @Schedule(second = "0", minute = "0", hour = "0", dayOfMonth = "1", month = "1,6")
+        public void method();
+    }
+}
+----
+
+
+==  BiMonthly
+
+
+[source,java]
+----
+package org.superbiz.corn.meta.api;
+
+import javax.ejb.Schedule;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Metatype
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+
+public @interface BiMonthly {
+    public static interface $ {
+
+        @BiMonthly
+        @Schedule(second = "0", minute = "0", hour = "0", dayOfMonth = "1,15")
+        public void method();
+    }
+}
+----
+
+
+==  Daily
+
+
+[source,java]
+----
+package org.superbiz.corn.meta.api;
+
+import javax.ejb.Schedule;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Metatype
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+
+public @interface Daily {
+    public static interface $ {
+
+        @Daily
+        @Schedule(second = "0", minute = "0", hour = "0", dayOfMonth = "*")
+        public void method();
+    }
+}
+----
+
+
+==  HarvestTime
+
+
+[source,java]
+----
+package org.superbiz.corn.meta.api;
+
+import javax.ejb.Schedule;
+import javax.ejb.Schedules;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Metatype
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+
+public @interface HarvestTime {
+    public static interface $ {
+
+        @HarvestTime
+        @Schedules({
+                @Schedule(month = "9", dayOfMonth = "20-Last", minute = "0", hour = "8"),
+                @Schedule(month = "10", dayOfMonth = "1-10", minute = "0", hour = "8")
+        })
+        public void method();
+    }
+}
+----
+
+
+==  Hourly
+
+
+[source,java]
+----
+package org.superbiz.corn.meta.api;
+
+import javax.ejb.Schedule;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Metatype
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+
+public @interface Hourly {
+    public static interface $ {
+
+        @Hourly
+        @Schedule(second = "0", minute = "0", hour = "*")
+        public void method();
+    }
+}
+----
+
+
+==  Metatype
+
+
+[source,java]
+----
+package org.superbiz.corn.meta.api;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Metatype
+@Target(ElementType.ANNOTATION_TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Metatype {
+}
+----
+
+
+==  Organic
+
+
+[source,java]
+----
+package org.superbiz.corn.meta.api;
+
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Singleton;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Metatype
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+
+@Singleton
+@Lock(LockType.READ)
+public @interface Organic {
+}
+----
+
+
+==  PlantingTime
+
+
+[source,java]
+----
+package org.superbiz.corn.meta.api;
+
+import javax.ejb.Schedule;
+import javax.ejb.Schedules;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Metatype
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+
+public @interface PlantingTime {
+    public static interface $ {
+
+        @PlantingTime
+        @Schedules({
+                @Schedule(month = "5", dayOfMonth = "20-Last", minute = "0", hour = "8"),
+                @Schedule(month = "6", dayOfMonth = "1-10", minute = "0", hour = "8")
+        })
+        public void method();
+    }
+}
+----
+
+
+==  Secondly
+
+
+[source,java]
+----
+package org.superbiz.corn.meta.api;
+
+import javax.ejb.Schedule;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Metatype
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+
+public @interface Secondly {
+    public static interface $ {
+
+        @Secondly
+        @Schedule(second = "*", minute = "*", hour = "*")
+        public void method();
+    }
+}
+----
+
+
+==  FarmerBrown
+
+
+[source,java]
+----
+package org.superbiz.corn.meta;
+
+import org.superbiz.corn.meta.api.HarvestTime;
+import org.superbiz.corn.meta.api.Organic;
+import org.superbiz.corn.meta.api.PlantingTime;
+import org.superbiz.corn.meta.api.Secondly;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * This is where we schedule all of Farmer Brown's corn jobs
+ *
+ * @version $Revision$ $Date$
+ */
+@Organic
+public class FarmerBrown {
+
+    private final AtomicInteger checks = new AtomicInteger();
+
+    @PlantingTime
+    private void plantTheCorn() {
+        // Dig out the planter!!!
+    }
+
+    @HarvestTime
+    private void harvestTheCorn() {
+        // Dig out the combine!!!
+    }
+
+    @Secondly
+    private void checkOnTheDaughters() {
+        checks.incrementAndGet();
+    }
+
+    public int getChecks() {
+        return checks.get();
+    }
+}
+----
+
+
+==  FarmerBrownTest
+
+
+[source,java]
+----
+package org.superbiz.corn.meta;
+
+import junit.framework.TestCase;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.Context;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class FarmerBrownTest extends TestCase {
+
+    public void test() throws Exception {
+
+        final Context context = EJBContainer.createEJBContainer().getContext();
+
+        final FarmerBrown farmerBrown = (FarmerBrown) context.lookup("java:global/schedule-methods-meta/FarmerBrown");
+
+        // Give Farmer brown a chance to do some work
+        Thread.sleep(SECONDS.toMillis(5));
+
+        assertTrue(farmerBrown.getChecks() > 4);
+    }
+}
+----
+
+
+=  Running
+
+    
+
+[source]
+----
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.corn.meta.FarmerBrownTest
+Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
+http://tomee.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/schedule-methods-meta
+INFO - openejb.base = /Users/dblevins/examples/schedule-methods-meta
+INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/schedule-methods-meta/target/classes
+INFO - Beginning load: /Users/dblevins/examples/schedule-methods-meta/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/schedule-methods-meta
+INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container)
+INFO - Auto-creating a container for bean FarmerBrown: Container(type=SINGLETON, id=Default Singleton Container)
+INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+INFO - Auto-creating a container for bean org.superbiz.corn.meta.FarmerBrownTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Enterprise application "/Users/dblevins/examples/schedule-methods-meta" loaded.
+INFO - Assembling app: /Users/dblevins/examples/schedule-methods-meta
+INFO - Jndi(name="java:global/schedule-methods-meta/FarmerBrown!org.superbiz.corn.meta.FarmerBrown")
+INFO - Jndi(name="java:global/schedule-methods-meta/FarmerBrown")
+INFO - Jndi(name="java:global/EjbModule1809441479/org.superbiz.corn.meta.FarmerBrownTest!org.superbiz.corn.meta.FarmerBrownTest")
+INFO - Jndi(name="java:global/EjbModule1809441479/org.superbiz.corn.meta.FarmerBrownTest")
+INFO - Created Ejb(deployment-id=org.superbiz.corn.meta.FarmerBrownTest, ejb-name=org.superbiz.corn.meta.FarmerBrownTest, container=Default Managed Container)
+INFO - Created Ejb(deployment-id=FarmerBrown, ejb-name=FarmerBrown, container=Default Singleton Container)
+INFO - Started Ejb(deployment-id=org.superbiz.corn.meta.FarmerBrownTest, ejb-name=org.superbiz.corn.meta.FarmerBrownTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=FarmerBrown, ejb-name=FarmerBrown, container=Default Singleton Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/schedule-methods-meta)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.166 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+----
+
+    

Propchange: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-methods-meta.adoc
------------------------------------------------------------------------------
    svn:executable = *

Added: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-methods.adoc
URL: http://svn.apache.org/viewvc/tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-methods.adoc?rev=1772522&view=auto
==============================================================================
--- tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-methods.adoc (added)
+++ tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-methods.adoc Sun Dec  4 11:01:40 2016
@@ -0,0 +1,141 @@
+= Schedule Methods
+:jbake-date: 2016-09-06
+:jbake-type: page
+:jbake-tomeepdf:
+:jbake-status: published
+
+Example schedule-methods can be browsed at https://github.com/apache/tomee/tree/master/examples/schedule-methods
+
+
+*Help us document this example! Click the blue pencil icon in the upper right to edit this page.*
+
+==  FarmerBrown
+
+
+[source,java]
+----
+package org.superbiz.corn;
+
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.Schedule;
+import javax.ejb.Schedules;
+import javax.ejb.Singleton;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * This is where we schedule all of Farmer Brown's corn jobs
+ *
+ * @version $Revision$ $Date$
+ */
+@Singleton
+@Lock(LockType.READ) // allows timers to execute in parallel
+public class FarmerBrown {
+
+    private final AtomicInteger checks = new AtomicInteger();
+
+    @Schedules({
+            @Schedule(month = "5", dayOfMonth = "20-Last", minute = "0", hour = "8"),
+            @Schedule(month = "6", dayOfMonth = "1-10", minute = "0", hour = "8")
+    })
+    private void plantTheCorn() {
+        // Dig out the planter!!!
+    }
+
+    @Schedules({
+            @Schedule(month = "9", dayOfMonth = "20-Last", minute = "0", hour = "8"),
+            @Schedule(month = "10", dayOfMonth = "1-10", minute = "0", hour = "8")
+    })
+    private void harvestTheCorn() {
+        // Dig out the combine!!!
+    }
+
+    @Schedule(second = "*", minute = "*", hour = "*")
+    private void checkOnTheDaughters() {
+        checks.incrementAndGet();
+    }
+
+    public int getChecks() {
+        return checks.get();
+    }
+}
+----
+
+
+==  FarmerBrownTest
+
+
+[source,java]
+----
+package org.superbiz.corn;
+
+import junit.framework.TestCase;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.Context;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class FarmerBrownTest extends TestCase {
+
+    public void test() throws Exception {
+
+        final Context context = EJBContainer.createEJBContainer().getContext();
+
+        final FarmerBrown farmerBrown = (FarmerBrown) context.lookup("java:global/schedule-methods/FarmerBrown");
+
+        // Give Farmer brown a chance to do some work
+        Thread.sleep(SECONDS.toMillis(5));
+
+        assertTrue(farmerBrown.getChecks() > 4);
+    }
+}
+----
+
+
+=  Running
+
+    
+
+[source]
+----
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.corn.FarmerBrownTest
+Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
+http://tomee.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/schedule-methods
+INFO - openejb.base = /Users/dblevins/examples/schedule-methods
+INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/schedule-methods/target/classes
+INFO - Beginning load: /Users/dblevins/examples/schedule-methods/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/schedule-methods
+INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container)
+INFO - Auto-creating a container for bean FarmerBrown: Container(type=SINGLETON, id=Default Singleton Container)
+INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+INFO - Auto-creating a container for bean org.superbiz.corn.FarmerBrownTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Enterprise application "/Users/dblevins/examples/schedule-methods" loaded.
+INFO - Assembling app: /Users/dblevins/examples/schedule-methods
+INFO - Jndi(name="java:global/schedule-methods/FarmerBrown!org.superbiz.corn.FarmerBrown")
+INFO - Jndi(name="java:global/schedule-methods/FarmerBrown")
+INFO - Jndi(name="java:global/EjbModule660493198/org.superbiz.corn.FarmerBrownTest!org.superbiz.corn.FarmerBrownTest")
+INFO - Jndi(name="java:global/EjbModule660493198/org.superbiz.corn.FarmerBrownTest")
+INFO - Created Ejb(deployment-id=org.superbiz.corn.FarmerBrownTest, ejb-name=org.superbiz.corn.FarmerBrownTest, container=Default Managed Container)
+INFO - Created Ejb(deployment-id=FarmerBrown, ejb-name=FarmerBrown, container=Default Singleton Container)
+INFO - Started Ejb(deployment-id=org.superbiz.corn.FarmerBrownTest, ejb-name=org.superbiz.corn.FarmerBrownTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=FarmerBrown, ejb-name=FarmerBrown, container=Default Singleton Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/schedule-methods)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.121 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+----
+
+    

Propchange: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/schedule-methods.adoc
------------------------------------------------------------------------------
    svn:executable = *

Added: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/server-events.adoc
URL: http://svn.apache.org/viewvc/tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/server-events.adoc?rev=1772522&view=auto
==============================================================================
--- tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/server-events.adoc (added)
+++ tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/server-events.adoc Sun Dec  4 11:01:40 2016
@@ -0,0 +1,9 @@
+= server-events
+:jbake-date: 2016-09-06
+:jbake-type: page
+:jbake-tomeepdf:
+:jbake-status: published
+
+Example server-events can be browsed at https://github.com/apache/tomee/tree/master/examples/server-events
+
+No README.md yet, be the first to contribute one!

Propchange: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/server-events.adoc
------------------------------------------------------------------------------
    svn:executable = *

Added: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-cdi-interceptor.adoc
URL: http://svn.apache.org/viewvc/tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-cdi-interceptor.adoc?rev=1772522&view=auto
==============================================================================
--- tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-cdi-interceptor.adoc (added)
+++ tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-cdi-interceptor.adoc Sun Dec  4 11:01:40 2016
@@ -0,0 +1,127 @@
+= simple-cdi-interceptor
+:jbake-date: 2016-09-06
+:jbake-type: page
+:jbake-tomeepdf:
+:jbake-status: published
+
+Example simple-cdi-interceptor can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-cdi-interceptor
+
+= Simple CDI Interceptor
+
+Let's write a simple application that would allow us to book tickets for a movie show. As with all applications, logging is one cross-cutting concern that we have. 
+
+(Relevant snippets are inlined but you can check out the complete code, from the links provided)
+
+How do we mark which methods are to be intercepted ? Wouldn't it be handy to annotate a method like 
+
+
+[source,java]
+----
+@Log
+public void aMethod(){...} 
+
+Let's create an  annotation that would "mark" a method for interception. 
+
+@InterceptorBinding
+@Target({ TYPE, METHOD })
+@Retention(RUNTIME)
+public @interface Log {
+}
+----
+
+
+Sure, you haven't missed the @InterceptorBinding annotation above ! Now that our custom annotation is created, lets attach it (or to use a better term for it, "bind it" )
+to an interceptor. 
+
+So here's our logging interceptor. An @AroundInvoke method and we are almost done.
+
+
+[source,java]
+----
+@Interceptor
+@Log  //binding the interceptor here. now any method annotated with @Log would be intercepted by logMethodEntry
+public class LoggingInterceptor {
+    @AroundInvoke
+    public Object logMethodEntry(InvocationContext ctx) throws Exception {
+        System.out.println("Entering method: " + ctx.getMethod().getName());
+        //or logger.info statement 
+        return ctx.proceed();
+    }
+}
+----
+
+
+Now the @Log annotation we created is bound to this interceptor.
+
+That done, let's annotate at class-level or method-level and have fun intercepting ! 
+
+
+[source,java]
+----
+@Log
+@Stateful
+public class BookShow implements Serializable {
+    private static final long serialVersionUID = 6350400892234496909L;
+    public List<String> getMoviesList() {
+        List<String> moviesAvailable = new ArrayList<String>();
+        moviesAvailable.add("12 Angry Men");
+        moviesAvailable.add("Kings speech");
+        return moviesAvailable;
+    }
+    public Integer getDiscountedPrice(int ticketPrice) {
+        return ticketPrice - 50;
+    }
+    // assume more methods are present
+}
+----
+
+
+The `@Log` annotation applied at class level denotes that all the methods should be intercepted with `LoggingInterceptor`.
+
+Before we say "all done" there's one last thing we are left with ! To enable the interceptors ! 
+
+Lets quickly put up a [beans.xml file]
+
+
+[source,xml]
+----
+<beans>
+  <interceptors>
+    <class>org.superbiz.cdi.bookshow.interceptors.LoggingInterceptor
+    </class>
+  </interceptors>
+</beans>
+----
+
+
+ in META-INF
+
+
+Those lines in beans.xml not only "enable" the interceptors, but also define the "order of execution" of the interceptors.
+But we'll see that in another example on multiple-cdi-interceptors.
+
+Fire up the test, and we should see a 'Entering method: getMoviesList' printed in the console.
+
+= Tests
+    Apache OpenEJB 4.0.0-beta-2    build: 20111103-01:00
+    http://tomee.apache.org/
+    INFO - openejb.home = /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors
+    INFO - openejb.base = /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors
+    INFO - Using 'javax.ejb.embeddable.EJBContainer=true' 
+    INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+    INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+    INFO - Found EjbModule in classpath: /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors/target/classes
+    INFO - Beginning load: /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors/target/classes
+    INFO - Configuring enterprise application: /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors
+    INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+    INFO - Auto-creating a container for bean cdi-simple-interceptors.Comp: Container(type=MANAGED, id=Default Managed Container)
+    INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container)
+    INFO - Auto-creating a container for bean BookShow: Container(type=STATEFUL, id=Default Stateful Container)
+    INFO - Enterprise application "/media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors" loaded.
+    INFO - Assembling app: /media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors
+    INFO - Jndi(name="java:global/cdi-simple-interceptors/BookShow!org.superbiz.cdi.bookshow.beans.BookShow")
+    INFO - Jndi(name="java:global/cdi-simple-interceptors/BookShow")
+    INFO - Created Ejb(deployment-id=BookShow, ejb-name=BookShow, container=Default Stateful Container)
+    INFO - Started Ejb(deployment-id=BookShow, ejb-name=BookShow, container=Default Stateful Container)
+    INFO - Deployed Application(path=/media/fthree/Workspace/open4/openejb/examples/cdi-simple-interceptors)
+    Entering method: getMoviesList

Propchange: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-cdi-interceptor.adoc
------------------------------------------------------------------------------
    svn:executable = *

Added: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-cmp2.adoc
URL: http://svn.apache.org/viewvc/tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-cmp2.adoc?rev=1772522&view=auto
==============================================================================
--- tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-cmp2.adoc (added)
+++ tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-cmp2.adoc Sun Dec  4 11:01:40 2016
@@ -0,0 +1,361 @@
+= EJB 2.1 CMP EntityBeans (CMP2)
+:jbake-date: 2016-09-06
+:jbake-type: page
+:jbake-tomeepdf:
+:jbake-status: published
+
+Example simple-cmp2 can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-cmp2
+
+
+
+
+OpenEJB, the EJB Container for TomEE and Geronimo,  does support all of EJB 1.1 to 3.1, including CMP2.
+
+The CMP2 implementation is actually done by adapting the CMP2 bean into a JPA Entity dynamically at deploy time.
+
+Appropriate subclasses, a JPA persistence.xml file and a mapping.xml file are generated at deployment
+time for the CMP2 EntityBeans and all the Entities will be then run on OpenJPA.  This innovative code
+has been used as the sole CMP2 implementation in Geronimo for its J2EE 1.4, JavaEE 5 and JavaEE 6 certifications.
+
+The persistence.xml and mapping.xml files generated at deploy time can be saved to disk and included
+in the application, allowing you to:
+
+ - gain finer control over persistence options
+ - slowly convert individual entities from CMP2 to JPA
+
+Let's see an example.
+
+=  Movies application
+
+The following is a basic EJB 2.1 application consisting of one CMP2 Entity.  For those that are reading this example
+out of curiosity and are not familiar with CMP2 or EJB 2.x, each CMP2 Entity is composed of two parts
+
+ - **A Home interface** which has data access methods like "find", "create", and "remove".  This is essentially
+  what people use `@Stateless` beans for today, but with difference that you do not need to supply
+  the implementation of the interface -- the container will generate one for you.  This is partly what inspired
+  the creation of the OpenEJB-specific link:dynamic-dao-implementation.html[Dynamic DAO] feature.
+
+ - **An abstract EntityBean class** which declares the persistent "properties" of the entity without actually
+declaring any fields.  It is the container's job to implement the actual methods and create the appropriate
+fields.  OpenEJB will implement this bean as a JPA `@Entity` bean.
+
+As such a CMP2 EntityBean is really just the description of a persistent object and the description of a 
+data-access object.  There is no actual code to write.
+
+The majority of work in CMP2 is done in the xml:
+
+ - **ejb-jar.xml** mapping information, which describes the persistent properties of the entity and the queries
+ for all *Home* find, create and remove methods.  This information will be converted by OpenEJB into
+ a JPA mapping.xml file.  All queries in the cmp2 part of the ejb-jar.xml are converted 
+ into named queries in JPA and generally everything is converted to its JPA equivalent. 
+
+==  CMP2 EntityBean, MovieBean
+
+
+[source,java]
+----
+package org.superbiz.cmp2;
+
+import javax.ejb.EntityBean;
+
+public abstract class MovieBean implements EntityBean {
+
+    public MovieBean() {
+    }
+
+    public Integer ejbCreate(String director, String title, int year) {
+        this.setDirector(director);
+        this.setTitle(title);
+        this.setYear(year);
+        return null;
+    }
+
+    public abstract java.lang.Integer getId();
+
+    public abstract void setId(java.lang.Integer id);
+
+    public abstract String getDirector();
+
+    public abstract void setDirector(String director);
+
+    public abstract String getTitle();
+
+    public abstract void setTitle(String title);
+
+    public abstract int getYear();
+
+    public abstract void setYear(int year);
+
+}
+----
+
+
+==  CMP2 Home interface, Movies
+
+
+[source,java]
+----
+package org.superbiz.cmp2;
+
+import javax.ejb.CreateException;
+import javax.ejb.FinderException;
+import java.util.Collection;
+
+/**
+ * @version $Revision$ $Date$
+ */
+interface Movies extends javax.ejb.EJBLocalHome {
+    Movie create(String director, String title, int year) throws CreateException;
+
+    Movie findByPrimaryKey(Integer primarykey) throws FinderException;
+
+    Collection<Movie> findAll() throws FinderException;
+
+    Collection<Movie> findByDirector(String director) throws FinderException;
+}
+----
+
+
+==  CMP2 mapping in ejb-jar.xml
+
+
+[source,xml]
+----
+<ejb-jar>
+  <enterprise-beans>
+    <entity>
+      <ejb-name>MovieBean</ejb-name>
+      <local-home>org.superbiz.cmp2.Movies</local-home>
+      <local>org.superbiz.cmp2.Movie</local>
+      <ejb-class>org.superbiz.cmp2.MovieBean</ejb-class>
+      <persistence-type>Container</persistence-type>
+      <prim-key-class>java.lang.Integer</prim-key-class>
+      <reentrant>false</reentrant>
+      <cmp-version>2.x</cmp-version>
+      <abstract-schema-name>MovieBean</abstract-schema-name>
+      <cmp-field>
+        <field-name>id</field-name>
+      </cmp-field>
+      <cmp-field>
+        <field-name>director</field-name>
+      </cmp-field>
+      <cmp-field>
+        <field-name>year</field-name>
+      </cmp-field>
+      <cmp-field>
+        <field-name>title</field-name>
+      </cmp-field>
+      <primkey-field>id</primkey-field>
+      <query>
+        <query-method>
+          <method-name>findByDirector</method-name>
+          <method-params>
+            <method-param>java.lang.String</method-param>
+          </method-params>
+        </query-method>
+        <ejb-ql>SELECT m FROM MovieBean m WHERE m.director = ?1</ejb-ql>
+      </query>
+      <query>
+        <query-method>
+          <method-name>findAll</method-name>
+          <method-params/>
+        </query-method>
+        <ejb-ql>SELECT m FROM MovieBean as m</ejb-ql>
+      </query>
+    </entity>
+  </enterprise-beans>
+</ejb-jar>
+----
+
+    
+
+==  openejb-jar.xml
+
+
+[source,xml]
+----
+<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1">
+  <enterprise-beans>
+    <entity>
+      <ejb-name>MovieBean</ejb-name>
+      <key-generator xmlns="http://www.openejb.org/xml/ns/pkgen-2.1">
+        <uuid/>
+      </key-generator>
+    </entity>
+  </enterprise-beans>
+</openejb-jar>
+----
+
+    
+
+==  MoviesTest
+
+
+[source,java]
+----
+package org.superbiz.cmp2;
+
+import junit.framework.TestCase;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.util.Collection;
+import java.util.Properties;
+
+/**
+ * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $
+ */
+public class MoviesTest extends TestCase {
+
+    public void test() throws Exception {
+        Properties p = new Properties();
+        p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
+        p.put("movieDatabase", "new://Resource?type=DataSource");
+        p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
+        p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
+
+        p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource");
+        p.put("movieDatabaseUnmanaged.JdbcDriver", "org.hsqldb.jdbcDriver");
+        p.put("movieDatabaseUnmanaged.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
+        p.put("movieDatabaseUnmanaged.JtaManaged", "false");
+
+        Context context = new InitialContext(p);
+
+        Movies movies = (Movies) context.lookup("MovieBeanLocalHome");
+
+        movies.create("Quentin Tarantino", "Reservoir Dogs", 1992);
+        movies.create("Joel Coen", "Fargo", 1996);
+        movies.create("Joel Coen", "The Big Lebowski", 1998);
+
+        Collection<Movie> list = movies.findAll();
+        assertEquals("Collection.size()", 3, list.size());
+
+        for (Movie movie : list) {
+            movies.remove(movie.getPrimaryKey());
+        }
+
+        assertEquals("Movies.findAll()", 0, movies.findAll().size());
+    }
+}
+----
+
+
+=  Running
+
+    
+
+[source]
+----
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.cmp2.MoviesTest
+Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
+http://tomee.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/simple-cmp2/target
+INFO - openejb.base = /Users/dblevins/examples/simple-cmp2/target
+INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+INFO - Configuring Service(id=movieDatabaseUnmanaged, type=Resource, provider-id=Default JDBC Database)
+INFO - Configuring Service(id=movieDatabase, type=Resource, provider-id=Default JDBC Database)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/simple-cmp2/target/classes
+INFO - Beginning load: /Users/dblevins/examples/simple-cmp2/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/simple-cmp2/target/classpath.ear
+INFO - Configuring Service(id=Default CMP Container, type=Container, provider-id=Default CMP Container)
+INFO - Auto-creating a container for bean MovieBean: Container(type=CMP_ENTITY, id=Default CMP Container)
+INFO - Configuring PersistenceUnit(name=cmp)
+INFO - Adjusting PersistenceUnit cmp <jta-data-source> to Resource ID 'movieDatabase' from 'null'
+INFO - Adjusting PersistenceUnit cmp <non-jta-data-source> to Resource ID 'movieDatabaseUnmanaged' from 'null'
+INFO - Enterprise application "/Users/dblevins/examples/simple-cmp2/target/classpath.ear" loaded.
+INFO - Assembling app: /Users/dblevins/examples/simple-cmp2/target/classpath.ear
+INFO - PersistenceUnit(name=cmp, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 160ms
+INFO - Jndi(name=MovieBeanLocalHome) --> Ejb(deployment-id=MovieBean)
+INFO - Jndi(name=global/classpath.ear/simple-cmp2/MovieBean!org.superbiz.cmp2.Movies) --> Ejb(deployment-id=MovieBean)
+INFO - Jndi(name=global/classpath.ear/simple-cmp2/MovieBean) --> Ejb(deployment-id=MovieBean)
+INFO - Created Ejb(deployment-id=MovieBean, ejb-name=MovieBean, container=Default CMP Container)
+INFO - Started Ejb(deployment-id=MovieBean, ejb-name=MovieBean, container=Default CMP Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/simple-cmp2/target/classpath.ear)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.919 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+----
+
+
+=  CMP2 to JPA
+
+As mentioned OpenEJB will implement the abstract CMP2 `EntityBean` as a JPA `@Entity`, create a `persistence.xml` file and convert all `ejb-jar.xml` mapping and queries to
+a JPA `entity-mappings.xml` file.
+
+Both of these files will be written to disk by setting the system property `openejb.descriptors.output` to `true`.  In the testcase
+above, this can be done via the `InitialContext` parameters via code like this:
+
+    Properties p = new Properties();
+    p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
+
+    // setup the data sources as usual...
+
+    // write the generated descriptors
+    p.put("openejb.descriptors.output", "true");
+
+    Context context = new InitialContext(p);
+
+Below are the generated `persistence.xml` and `mapping.xml` files for our CMP2 `EntityBean`
+
+==  CMP2 to JPA generated persistence.xml file
+
+
+[source,xml]
+----
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+    <persistence-unit name="cmp" transaction-type="JTA">
+        <jta-data-source>movieDatabase</jta-data-source>
+        <non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source>
+        <mapping-file>META-INF/openejb-cmp-generated-orm.xml</mapping-file>
+        <class>openejb.org.superbiz.cmp2.MovieBean</class>
+        <properties>
+            <property name="openjpa.jdbc.SynchronizeMappings"
+            value="buildSchema(ForeignKeys=true, Indexes=false, IgnoreErrors=true)"/>
+            <property name="openjpa.Log" value="DefaultLevel=INFO"/>
+        </properties>
+    </persistence-unit>
+</persistence>
+----
+
+
+All of this `persitence.xml` can be changed, however the `persistence-unit` must have the `name` fixed to `cmp`.
+
+==  CMP2 to JPA generated mapping file
+
+Note that the `persistence.xml` above refers to this mappings file as `META-INF/openejb-cmp-generated-orm.xml`.  It is possible
+to rename this file to whatever name you prefer, just make sure to update the `<mapping-file>` element of the `cmp` persistence unit
+accordingly.
+
+
+[source,xml]
+----
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="1.0">
+    <entity class="openejb.org.superbiz.cmp2.MovieBean" name="MovieBean">
+        <description>simple-cmp2#MovieBean</description>
+        <table/>
+        <named-query name="MovieBean.findByDirector(java.lang.String)">
+            <query>SELECT m FROM MovieBean m WHERE m.director = ?1</query>
+        </named-query>
+        <named-query name="MovieBean.findAll">
+            <query>SELECT m FROM MovieBean as m</query>
+        </named-query>
+        <attributes>
+            <id name="id">
+                <generated-value strategy="IDENTITY"/>
+            </id>
+            <basic name="director"/>
+            <basic name="year"/>
+            <basic name="title"/>
+        </attributes>
+    </entity>
+</entity-mappings>
+----
+

Propchange: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-cmp2.adoc
------------------------------------------------------------------------------
    svn:executable = *

Added: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb-and-cdi.adoc
URL: http://svn.apache.org/viewvc/tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb-and-cdi.adoc?rev=1772522&view=auto
==============================================================================
--- tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb-and-cdi.adoc (added)
+++ tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb-and-cdi.adoc Sun Dec  4 11:01:40 2016
@@ -0,0 +1,211 @@
+= Simple MDB and CDI
+:jbake-date: 2016-09-06
+:jbake-type: page
+:jbake-tomeepdf:
+:jbake-status: published
+
+Example simple-mdb-and-cdi can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-mdb-and-cdi
+
+
+*Help us document this example! Click the blue pencil icon in the upper right to edit this page.*
+
+==  ChatBean
+
+
+[source,java]
+----
+package org.superbiz.mdb;
+
+import javax.annotation.Resource;
+import javax.ejb.MessageDriven;
+import javax.inject.Inject;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+@MessageDriven
+public class ChatBean implements MessageListener {
+
+    @Resource
+    private ConnectionFactory connectionFactory;
+
+    @Resource(name = "AnswerQueue")
+    private Queue answerQueue;
+
+    @Inject
+    private ChatRespondCreator responder;
+
+    public void onMessage(Message message) {
+        try {
+
+            final TextMessage textMessage = (TextMessage) message;
+            final String question = textMessage.getText();
+            final String response = responder.respond(question);
+
+            if (response != null) {
+                respond(response);
+            }
+        } catch (JMSException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private void respond(String text) throws JMSException {
+
+        Connection connection = null;
+        Session session = null;
+
+        try {
+            connection = connectionFactory.createConnection();
+            connection.start();
+
+            // Create a Session
+            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+            // Create a MessageProducer from the Session to the Topic or Queue
+            MessageProducer producer = session.createProducer(answerQueue);
+            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+            // Create a message
+            TextMessage message = session.createTextMessage(text);
+
+            // Tell the producer to send the message
+            producer.send(message);
+        } finally {
+            // Clean up
+            if (session != null) session.close();
+            if (connection != null) connection.close();
+        }
+    }
+}
+----
+
+
+==  ChatRespondCreator
+
+
+[source,java]
+----
+package org.superbiz.mdb;
+
+public class ChatRespondCreator {
+    public String respond(String question) {
+        if ("Hello World!".equals(question)) {
+            return "Hello, Test Case!";
+        } else if ("How are you?".equals(question)) {
+            return "I'm doing well.";
+        } else if ("Still spinning?".equals(question)) {
+            return "Once every day, as usual.";
+        }
+        return null;
+    }
+}
+----
+
+
+==  beans.xml
+
+
+[source,xml]
+----
+<!--
+
+    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.
+-->
+<beans/>
+----
+
+    
+
+==  ChatBeanTest
+
+
+[source,java]
+----
+package org.superbiz.mdb;
+
+import junit.framework.TestCase;
+
+import javax.annotation.Resource;
+import javax.ejb.embeddable.EJBContainer;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+public class ChatBeanTest extends TestCase {
+
+    @Resource
+    private ConnectionFactory connectionFactory;
+
+    @Resource(name = "ChatBean")
+    private Queue questionQueue;
+
+    @Resource(name = "AnswerQueue")
+    private Queue answerQueue;
+
+    public void test() throws Exception {
+        EJBContainer.createEJBContainer().getContext().bind("inject", this);
+
+
+        final Connection connection = connectionFactory.createConnection();
+
+        connection.start();
+
+        final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        final MessageProducer questions = session.createProducer(questionQueue);
+
+        final MessageConsumer answers = session.createConsumer(answerQueue);
+
+
+        sendText("Hello World!", questions, session);
+
+        assertEquals("Hello, Test Case!", receiveText(answers));
+
+
+        sendText("How are you?", questions, session);
+
+        assertEquals("I'm doing well.", receiveText(answers));
+
+
+        sendText("Still spinning?", questions, session);
+
+        assertEquals("Once every day, as usual.", receiveText(answers));
+    }
+
+    private void sendText(String text, MessageProducer questions, Session session) throws JMSException {
+
+        questions.send(session.createTextMessage(text));
+    }
+
+    private String receiveText(MessageConsumer answers) throws JMSException {
+
+        return ((TextMessage) answers.receive(1000)).getText();
+    }
+}
+----
+

Propchange: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb-and-cdi.adoc
------------------------------------------------------------------------------
    svn:executable = *

Added: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb-with-descriptor.adoc
URL: http://svn.apache.org/viewvc/tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb-with-descriptor.adoc?rev=1772522&view=auto
==============================================================================
--- tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb-with-descriptor.adoc (added)
+++ tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb-with-descriptor.adoc Sun Dec  4 11:01:40 2016
@@ -0,0 +1,268 @@
+= Simple MDB with Descriptor
+:jbake-date: 2016-09-06
+:jbake-type: page
+:jbake-tomeepdf:
+:jbake-status: published
+
+Example simple-mdb-with-descriptor can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-mdb-with-descriptor
+
+
+*Help us document this example! Click the blue pencil icon in the upper right to edit this page.*
+
+==  ChatBean
+
+
+[source,java]
+----
+package org.superbiz.mdbdesc;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+public class ChatBean implements MessageListener {
+
+    private ConnectionFactory connectionFactory;
+
+    private Queue answerQueue;
+
+    public void onMessage(Message message) {
+        try {
+
+            final TextMessage textMessage = (TextMessage) message;
+            final String question = textMessage.getText();
+
+            if ("Hello World!".equals(question)) {
+
+                respond("Hello, Test Case!");
+            } else if ("How are you?".equals(question)) {
+
+                respond("I'm doing well.");
+            } else if ("Still spinning?".equals(question)) {
+
+                respond("Once every day, as usual.");
+            }
+        } catch (JMSException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private void respond(String text) throws JMSException {
+
+        Connection connection = null;
+        Session session = null;
+
+        try {
+            connection = connectionFactory.createConnection();
+            connection.start();
+
+            // Create a Session
+            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+            // Create a MessageProducer from the Session to the Topic or Queue
+            MessageProducer producer = session.createProducer(answerQueue);
+            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+            // Create a message
+            TextMessage message = session.createTextMessage(text);
+
+            // Tell the producer to send the message
+            producer.send(message);
+        } finally {
+            // Clean up
+            if (session != null) session.close();
+            if (connection != null) connection.close();
+        }
+    }
+}
+----
+
+
+==  ejb-jar.xml
+
+
+[source,xml]
+----
+<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" metadata-complete="true">
+  <enterprise-beans>
+
+    <message-driven>
+
+      <ejb-name>ChatBean</ejb-name>
+      <ejb-class>org.superbiz.mdbdesc.ChatBean</ejb-class>
+
+      <messaging-type>javax.jms.MessageListener</messaging-type>
+
+      <activation-config>
+        <activation-config-property>
+          <activation-config-property-name>destination</activation-config-property-name>
+          <activation-config-property-value>ChatBean</activation-config-property-value>
+        </activation-config-property>
+        <activation-config-property>
+          <activation-config-property-name>destinationType</activation-config-property-name>
+          <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
+        </activation-config-property>
+      </activation-config>
+
+      <resource-ref>
+        <res-ref-name>java:comp/env/org.superbiz.mdbdesc.ChatBean/connectionFactory</res-ref-name>
+        <res-type>javax.jms.ConnectionFactory</res-type>
+        <injection-target>
+          <injection-target-class>org.superbiz.mdbdesc.ChatBean</injection-target-class>
+          <injection-target-name>connectionFactory</injection-target-name>
+        </injection-target>
+      </resource-ref>
+
+      <resource-env-ref>
+        <resource-env-ref-name>java:comp/env/AnswerQueue</resource-env-ref-name>
+        <resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
+        <mapped-name>AnswerQueue</mapped-name>
+        <injection-target>
+          <injection-target-class>org.superbiz.mdbdesc.ChatBean</injection-target-class>
+          <injection-target-name>answerQueue</injection-target-name>
+        </injection-target>
+      </resource-env-ref>
+
+    </message-driven>
+
+  </enterprise-beans>
+</ejb-jar>
+----
+
+    
+
+==  ChatBeanTest
+
+
+[source,java]
+----
+package org.superbiz.mdb;
+
+import junit.framework.TestCase;
+
+import javax.annotation.Resource;
+import javax.ejb.embeddable.EJBContainer;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+public class ChatBeanTest extends TestCase {
+
+    @Resource
+    private ConnectionFactory connectionFactory;
+
+    @Resource(name = "ChatBean")
+    private Queue questionQueue;
+
+    @Resource(name = "AnswerQueue")
+    private Queue answerQueue;
+
+    public void test() throws Exception {
+
+        EJBContainer.createEJBContainer().getContext().bind("inject", this);
+
+        final Connection connection = connectionFactory.createConnection();
+
+        connection.start();
+
+        final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        final MessageProducer questions = session.createProducer(questionQueue);
+
+        final MessageConsumer answers = session.createConsumer(answerQueue);
+
+
+        sendText("Hello World!", questions, session);
+
+        assertEquals("Hello, Test Case!", receiveText(answers));
+
+
+        sendText("How are you?", questions, session);
+
+        assertEquals("I'm doing well.", receiveText(answers));
+
+
+        sendText("Still spinning?", questions, session);
+
+        assertEquals("Once every day, as usual.", receiveText(answers));
+    }
+
+    private void sendText(String text, MessageProducer questions, Session session) throws JMSException {
+
+        questions.send(session.createTextMessage(text));
+    }
+
+    private String receiveText(MessageConsumer answers) throws JMSException {
+
+        return ((TextMessage) answers.receive(1000)).getText();
+    }
+}
+----
+
+
+=  Running
+
+    
+
+[source]
+----
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.mdb.ChatBeanTest
+Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
+http://tomee.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/simple-mdb-with-descriptor
+INFO - openejb.base = /Users/dblevins/examples/simple-mdb-with-descriptor
+INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/simple-mdb-with-descriptor/target/classes
+INFO - Beginning load: /Users/dblevins/examples/simple-mdb-with-descriptor/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/simple-mdb-with-descriptor
+WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime.
+INFO - Configuring Service(id=Default MDB Container, type=Container, provider-id=Default MDB Container)
+INFO - Auto-creating a container for bean ChatBean: Container(type=MESSAGE, id=Default MDB Container)
+INFO - Configuring Service(id=Default JMS Resource Adapter, type=Resource, provider-id=Default JMS Resource Adapter)
+INFO - Configuring Service(id=Default JMS Connection Factory, type=Resource, provider-id=Default JMS Connection Factory)
+INFO - Auto-creating a Resource with id 'Default JMS Connection Factory' of type 'javax.jms.ConnectionFactory for 'ChatBean'.
+INFO - Auto-linking resource-ref 'java:comp/env/org.superbiz.mdbdesc.ChatBean/connectionFactory' in bean ChatBean to Resource(id=Default JMS Connection Factory)
+INFO - Configuring Service(id=AnswerQueue, type=Resource, provider-id=Default Queue)
+INFO - Auto-creating a Resource with id 'AnswerQueue' of type 'javax.jms.Queue for 'ChatBean'.
+INFO - Auto-linking resource-env-ref 'java:comp/env/AnswerQueue' in bean ChatBean to Resource(id=AnswerQueue)
+INFO - Configuring Service(id=ChatBean, type=Resource, provider-id=Default Queue)
+INFO - Auto-creating a Resource with id 'ChatBean' of type 'javax.jms.Queue for 'ChatBean'.
+INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+INFO - Auto-creating a container for bean org.superbiz.mdb.ChatBeanTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Auto-linking resource-ref 'java:comp/env/org.superbiz.mdb.ChatBeanTest/connectionFactory' in bean org.superbiz.mdb.ChatBeanTest to Resource(id=Default JMS Connection Factory)
+INFO - Auto-linking resource-env-ref 'java:comp/env/AnswerQueue' in bean org.superbiz.mdb.ChatBeanTest to Resource(id=AnswerQueue)
+INFO - Auto-linking resource-env-ref 'java:comp/env/ChatBean' in bean org.superbiz.mdb.ChatBeanTest to Resource(id=ChatBean)
+INFO - Enterprise application "/Users/dblevins/examples/simple-mdb-with-descriptor" loaded.
+INFO - Assembling app: /Users/dblevins/examples/simple-mdb-with-descriptor
+INFO - Jndi(name="java:global/EjbModule1842275169/org.superbiz.mdb.ChatBeanTest!org.superbiz.mdb.ChatBeanTest")
+INFO - Jndi(name="java:global/EjbModule1842275169/org.superbiz.mdb.ChatBeanTest")
+INFO - Created Ejb(deployment-id=org.superbiz.mdb.ChatBeanTest, ejb-name=org.superbiz.mdb.ChatBeanTest, container=Default Managed Container)
+INFO - Created Ejb(deployment-id=ChatBean, ejb-name=ChatBean, container=Default MDB Container)
+INFO - Started Ejb(deployment-id=org.superbiz.mdb.ChatBeanTest, ejb-name=org.superbiz.mdb.ChatBeanTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=ChatBean, ejb-name=ChatBean, container=Default MDB Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/simple-mdb-with-descriptor)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.914 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+----
+
+    

Propchange: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb-with-descriptor.adoc
------------------------------------------------------------------------------
    svn:executable = *

Added: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb.adoc
URL: http://svn.apache.org/viewvc/tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb.adoc?rev=1772522&view=auto
==============================================================================
--- tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb.adoc (added)
+++ tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb.adoc Sun Dec  4 11:01:40 2016
@@ -0,0 +1,233 @@
+= Simple MDB
+:jbake-date: 2016-09-06
+:jbake-type: page
+:jbake-tomeepdf:
+:jbake-status: published
+
+Example simple-mdb can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-mdb
+
+
+Below is a fun app, a chat application that uses JMS. We create a message driven bean, by marking our class with `@MessageDriven`. A message driven bean has some similarities with a stateless session bean, in the part that it is pooled too.
+
+Well, lets tell our chat-app to listen for incoming messages. That we do by implementing `MessageListener` and overriding the `onMessage(Message message)`.
+
+Then this app "listens" for incoming messages, and the messages picked up are processed by `onMessage(Message message)` method.
+
+That finishes our message driven bean implementation. The "processing" part could be anything that fits your business-requirement.
+
+In this case, it is to respond to the user. The `respond` method shows how a Message can be sent.
+
+This sequence diagram shows how a message is sent.
+
+<img src="../../resources/mdb-flow.png" alt=""/>
+
+==  ChatBean
+
+
+[source,java]
+----
+package org.superbiz.mdb;
+
+import javax.annotation.Resource;
+import javax.ejb.MessageDriven;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+@MessageDriven
+public class ChatBean implements MessageListener {
+
+    @Resource
+    private ConnectionFactory connectionFactory;
+
+    @Resource(name = "AnswerQueue")
+    private Queue answerQueue;
+
+    public void onMessage(Message message) {
+        try {
+
+            final TextMessage textMessage = (TextMessage) message;
+            final String question = textMessage.getText();
+
+            if ("Hello World!".equals(question)) {
+
+                respond("Hello, Test Case!");
+            } else if ("How are you?".equals(question)) {
+
+                respond("I'm doing well.");
+            } else if ("Still spinning?".equals(question)) {
+
+                respond("Once every day, as usual.");
+            }
+        } catch (JMSException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private void respond(String text) throws JMSException {
+
+        Connection connection = null;
+        Session session = null;
+
+        try {
+            connection = connectionFactory.createConnection();
+            connection.start();
+
+            // Create a Session
+            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+            // Create a MessageProducer from the Session to the Topic or Queue
+            MessageProducer producer = session.createProducer(answerQueue);
+            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+            // Create a message
+            TextMessage message = session.createTextMessage(text);
+
+            // Tell the producer to send the message
+            producer.send(message);
+        } finally {
+            // Clean up
+            if (session != null) session.close();
+            if (connection != null) connection.close();
+        }
+    }
+}
+----
+
+
+==  ChatBeanTest
+
+
+[source,java]
+----
+package org.superbiz.mdb;
+
+import junit.framework.TestCase;
+
+import javax.annotation.Resource;
+import javax.ejb.embeddable.EJBContainer;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+public class ChatBeanTest extends TestCase {
+
+    @Resource
+    private ConnectionFactory connectionFactory;
+
+    @Resource(name = "ChatBean")
+    private Queue questionQueue;
+
+    @Resource(name = "AnswerQueue")
+    private Queue answerQueue;
+
+    public void test() throws Exception {
+        EJBContainer.createEJBContainer().getContext().bind("inject", this);
+
+
+        final Connection connection = connectionFactory.createConnection();
+
+        connection.start();
+
+        final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+        final MessageProducer questions = session.createProducer(questionQueue);
+
+        final MessageConsumer answers = session.createConsumer(answerQueue);
+
+
+        sendText("Hello World!", questions, session);
+
+        assertEquals("Hello, Test Case!", receiveText(answers));
+
+
+        sendText("How are you?", questions, session);
+
+        assertEquals("I'm doing well.", receiveText(answers));
+
+
+        sendText("Still spinning?", questions, session);
+
+        assertEquals("Once every day, as usual.", receiveText(answers));
+    }
+
+    private void sendText(String text, MessageProducer questions, Session session) throws JMSException {
+
+        questions.send(session.createTextMessage(text));
+    }
+
+    private String receiveText(MessageConsumer answers) throws JMSException {
+
+        return ((TextMessage) answers.receive(1000)).getText();
+    }
+}
+----
+
+
+=  Running
+
+    
+
+[source]
+----
+-------------------------------------------------------
+ T E S T S
+-------------------------------------------------------
+Running org.superbiz.mdb.ChatBeanTest
+Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
+http://tomee.apache.org/
+INFO - openejb.home = /Users/dblevins/examples/simple-mdb
+INFO - openejb.base = /Users/dblevins/examples/simple-mdb
+INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+INFO - Found EjbModule in classpath: /Users/dblevins/examples/simple-mdb/target/classes
+INFO - Beginning load: /Users/dblevins/examples/simple-mdb/target/classes
+INFO - Configuring enterprise application: /Users/dblevins/examples/simple-mdb
+WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime.
+INFO - Auto-configuring a message driven bean ChatBean destination ChatBean to be destinationType javax.jms.Queue
+INFO - Configuring Service(id=Default MDB Container, type=Container, provider-id=Default MDB Container)
+INFO - Auto-creating a container for bean ChatBean: Container(type=MESSAGE, id=Default MDB Container)
+INFO - Configuring Service(id=Default JMS Resource Adapter, type=Resource, provider-id=Default JMS Resource Adapter)
+INFO - Configuring Service(id=Default JMS Connection Factory, type=Resource, provider-id=Default JMS Connection Factory)
+INFO - Auto-creating a Resource with id 'Default JMS Connection Factory' of type 'javax.jms.ConnectionFactory for 'ChatBean'.
+INFO - Auto-linking resource-ref 'java:comp/env/org.superbiz.mdb.ChatBean/connectionFactory' in bean ChatBean to Resource(id=Default JMS Connection Factory)
+INFO - Configuring Service(id=AnswerQueue, type=Resource, provider-id=Default Queue)
+INFO - Auto-creating a Resource with id 'AnswerQueue' of type 'javax.jms.Queue for 'ChatBean'.
+INFO - Auto-linking resource-env-ref 'java:comp/env/AnswerQueue' in bean ChatBean to Resource(id=AnswerQueue)
+INFO - Configuring Service(id=ChatBean, type=Resource, provider-id=Default Queue)
+INFO - Auto-creating a Resource with id 'ChatBean' of type 'javax.jms.Queue for 'ChatBean'.
+INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+INFO - Auto-creating a container for bean org.superbiz.mdb.ChatBeanTest: Container(type=MANAGED, id=Default Managed Container)
+INFO - Auto-linking resource-ref 'java:comp/env/org.superbiz.mdb.ChatBeanTest/connectionFactory' in bean org.superbiz.mdb.ChatBeanTest to Resource(id=Default JMS Connection Factory)
+INFO - Auto-linking resource-env-ref 'java:comp/env/AnswerQueue' in bean org.superbiz.mdb.ChatBeanTest to Resource(id=AnswerQueue)
+INFO - Auto-linking resource-env-ref 'java:comp/env/ChatBean' in bean org.superbiz.mdb.ChatBeanTest to Resource(id=ChatBean)
+INFO - Enterprise application "/Users/dblevins/examples/simple-mdb" loaded.
+INFO - Assembling app: /Users/dblevins/examples/simple-mdb
+INFO - Jndi(name="java:global/EjbModule1515710343/org.superbiz.mdb.ChatBeanTest!org.superbiz.mdb.ChatBeanTest")
+INFO - Jndi(name="java:global/EjbModule1515710343/org.superbiz.mdb.ChatBeanTest")
+INFO - Created Ejb(deployment-id=org.superbiz.mdb.ChatBeanTest, ejb-name=org.superbiz.mdb.ChatBeanTest, container=Default Managed Container)
+INFO - Created Ejb(deployment-id=ChatBean, ejb-name=ChatBean, container=Default MDB Container)
+INFO - Started Ejb(deployment-id=org.superbiz.mdb.ChatBeanTest, ejb-name=org.superbiz.mdb.ChatBeanTest, container=Default Managed Container)
+INFO - Started Ejb(deployment-id=ChatBean, ejb-name=ChatBean, container=Default MDB Container)
+INFO - Deployed Application(path=/Users/dblevins/examples/simple-mdb)
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.547 sec
+
+Results :
+
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+----
+
+    

Propchange: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-mdb.adoc
------------------------------------------------------------------------------
    svn:executable = *

Added: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-rest.adoc
URL: http://svn.apache.org/viewvc/tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-rest.adoc?rev=1772522&view=auto
==============================================================================
--- tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-rest.adoc (added)
+++ tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-rest.adoc Sun Dec  4 11:01:40 2016
@@ -0,0 +1,148 @@
+= Simple REST
+:jbake-date: 2016-09-06
+:jbake-type: page
+:jbake-tomeepdf:
+:jbake-status: published
+
+Example simple-rest can be browsed at https://github.com/apache/tomee/tree/master/examples/simple-rest
+
+
+Defining a REST service is pretty easy, simply ad @Path annotation to a class then define on methods
+the HTTP method to use (@GET, @POST, ...).
+
+= The Code
+
+==  The REST service: @Path, @GET, @POST
+
+Here we see a bean that uses the Bean-Managed Concurrency option as well as the @Startup annotation which causes the bean to be instantiated by the container when the application starts. Singleton beans with @ConcurrencyManagement(BEAN) are responsible for their own thread-safety. The bean shown is a simple properties "registry" and provides a place where options could be set and retrieved by all beans in the application.
+
+
+[source,java]
+----
+package org.superbiz.rest;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+@Path("/greeting")
+public class GreetingService {
+    @GET
+    public String message() {
+        return "Hi REST!";
+    }
+
+    @POST
+    public String lowerCase(final String message) {
+        return "Hi REST!".toLowerCase();
+    }
+}
+----
+
+
+=  Testing
+
+==  Test for the JAXRS service
+
+The test uses the OpenEJB ApplicationComposer to make it trivial.
+
+The idea is first to activate the jaxrs services. This is done using @EnableServices annotation.
+
+Then we create on the fly the application simply returning an object representing the web.xml. Here we simply
+use it to define the context root but you can use it to define your REST Application too. And to complete the
+application definition we add @Classes annotation to define the set of classes to use in this app.
+
+Finally to test it we use cxf client API to call the REST service in get() and post() methods.
+
+
+[source,java]
+----
+package org.superbiz.rest;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.openejb.jee.SingletonBean;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.EnableServices;
+import org.apache.openejb.junit.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+@EnableServices(value = "jaxrs")
+@RunWith(ApplicationComposer.class)
+public class GreetingServiceTest {
+    @Module
+    public SingletonBean app() {
+        return (SingletonBean) new SingletonBean(GreetingService.class).localBean();
+    }
+
+    @Test
+    public void get() throws IOException {
+        final String message = WebClient.create("http://localhost:4204").path("/GreetingServiceTest/greeting/").get(String.class);
+        assertEquals("Hi REST!", message);
+    }
+
+    @Test
+    public void post() throws IOException {
+        final String message = WebClient.create("http://localhost:4204").path("/GreetingServiceTest/greeting/").post("Hi REST!", String.class);
+        assertEquals("hi rest!", message);
+    }
+}
+----
+
+
+= Running
+
+Running the example is fairly simple. In the "simple-rest" directory run:
+
+    $ mvn clean install
+
+Which should create output like the following.
+
+    INFO - Cannot find the configuration file [conf/openejb.xml].  Will attempt to create one for the beans deployed.
+    INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+    INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+    INFO - Creating TransactionManager(id=Default Transaction Manager)
+    INFO - Creating SecurityService(id=Default Security Service)
+    INFO - Initializing network services
+    INFO - Creating ServerService(id=httpejbd)
+    INFO - Creating ServerService(id=cxf-rs)
+    INFO - Initializing network services
+    INFO - Starting service httpejbd
+    INFO - Started service httpejbd
+    INFO - Starting service cxf-rs
+    INFO - Started service cxf-rs
+    INFO -   ** Bound Services **
+    INFO -   NAME                 IP              PORT
+    INFO -   httpejbd             127.0.0.1       4204
+    INFO - -------
+    INFO - Ready!
+    INFO - Configuring enterprise application: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest
+    INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+    INFO - Auto-creating a container for bean org.superbiz.rest.GreetingServiceTest: Container(type=MANAGED, id=Default Managed Container)
+    INFO - Creating Container(id=Default Managed Container)
+    INFO - Using directory /tmp for stateful session passivation
+    INFO - Enterprise application "/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest" loaded.
+    INFO - Assembling app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest
+    INFO - Existing thread singleton service in SystemInstance() null
+    INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@12c9b196
+    INFO - Succeeded in installing singleton service
+    INFO - OpenWebBeans Container is starting...
+    INFO - Adding OpenWebBeansPlugin : [CdiPlugin]
+    INFO - All injection points are validated successfully.
+    INFO - OpenWebBeans Container has started, it took 11 ms.
+    INFO - Deployed Application(path=/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest)
+    INFO - Setting the server's publish address to be http://127.0.0.1:4204/test
+    INFO - REST Service: http://127.0.0.1:4204/test/greeting/.*  -> Pojo org.superbiz.rest.GreetingService
+    INFO - Undeploying app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest
+    INFO - Stopping network services
+    INFO - Stopping server services
+    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.004 sec
+
+    Results :
+
+    Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
+

Propchange: tomee/site/trunk/generators/site-tomee-ng/src/main/jbake/content/examples/simple-rest.adoc
------------------------------------------------------------------------------
    svn:executable = *