Author: tveronezi
Date: Sat Jul 21 13:54:42 2012
New Revision: 1364096

URL: http://svn.apache.org/viewvc?rev=1364096&view=rev
Log:
https://issues.apache.org/jira/browse/OPENEJB-351

Added:
    openejb/trunk/openejb/examples/simple-stateless-callbacks/
    openejb/trunk/openejb/examples/simple-stateless-callbacks/README.md
    openejb/trunk/openejb/examples/simple-stateless-callbacks/build.xml
    openejb/trunk/openejb/examples/simple-stateless-callbacks/pom.xml
    openejb/trunk/openejb/examples/simple-stateless-callbacks/src/
    openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/
    openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/
    openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/
    
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/
    
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/
    
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/
    
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/CalculatorBean.java
    
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/ExecutionChannel.java
    
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/ExecutionObserver.java
    openejb/trunk/openejb/examples/simple-stateless-callbacks/src/test/
    openejb/trunk/openejb/examples/simple-stateless-callbacks/src/test/java/
    openejb/trunk/openejb/examples/simple-stateless-callbacks/src/test/java/org/
    
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/test/java/org/superbiz/
    
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/test/java/org/superbiz/stateless/
    
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/test/java/org/superbiz/stateless/basic/
    
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/test/java/org/superbiz/stateless/basic/CalculatorTest.java

Added: openejb/trunk/openejb/examples/simple-stateless-callbacks/README.md
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-stateless-callbacks/README.md?rev=1364096&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/simple-stateless-callbacks/README.md (added)
+++ openejb/trunk/openejb/examples/simple-stateless-callbacks/README.md Sat Jul 
21 13:54:42 2012
@@ -0,0 +1,228 @@
+Title: Simple Stateless with callback methods
+
+This example shows how to create a stateless session bean that uses the 
@PostConstruct, @PreDestroy and @AroundInvoke annotations.
+
+## CalculatorBean
+
+    package org.superbiz.stateless.basic;
+
+    import javax.annotation.PostConstruct;
+    import javax.annotation.PreDestroy;
+    import javax.ejb.Stateless;
+    import javax.interceptor.AroundInvoke;
+    import javax.interceptor.InvocationContext;
+
+    @Stateless
+    public class CalculatorBean {
+
+        @PostConstruct
+        public void postConstruct() {
+            ExecutionChannel.getInstance().notifyObservers("postConstruct");
+        }
+
+        @PreDestroy
+        public void preDestroy() {
+            ExecutionChannel.getInstance().notifyObservers("preDestroy");
+        }
+
+        @AroundInvoke
+        public Object intercept(InvocationContext ctx) throws Exception {
+            
ExecutionChannel.getInstance().notifyObservers(ctx.getMethod().getName());
+            return ctx.proceed();
+        }
+
+        public int add(int a, int b) {
+            return a + b;
+        }
+
+        public int subtract(int a, int b) {
+            return a - b;
+        }
+
+        public int multiply(int a, int b) {
+            return a * b;
+        }
+
+        public int divide(int a, int b) {
+            return a / b;
+        }
+
+        public int remainder(int a, int b) {
+            return a % b;
+        }
+
+    }
+
+## ExecutionChannel
+
+    package org.superbiz.counter;
+
+    import java.util.ArrayList;
+    import java.util.List;
+
+    public class ExecutionChannel {
+        private static final ExecutionChannel INSTANCE = new 
ExecutionChannel();
+
+        private final List<ExecutionObserver> observers = new 
ArrayList<ExecutionObserver>();
+
+        public static ExecutionChannel getInstance() {
+            return INSTANCE;
+        }
+
+        public void addObserver(ExecutionObserver observer) {
+            this.observers.add(observer);
+        }
+
+        public void notifyObservers(Object value) {
+            for (ExecutionObserver observer : this.observers) {
+                observer.onExecution(value);
+            }
+        }
+    }
+
+## ExecutionObserver
+
+    package org.superbiz.counter;
+
+    public interface ExecutionObserver {
+
+        void onExecution(Object value);
+
+    }
+
+
+## CalculatorTest
+
+    package org.superbiz.stateless.basic;
+
+    import org.junit.Assert;
+    import org.junit.Test;
+
+    import javax.ejb.embeddable.EJBContainer;
+    import javax.naming.Context;
+    import javax.naming.InitialContext;
+    import javax.naming.NamingException;
+    import java.util.ArrayList;
+    import java.util.List;
+    import java.util.Properties;
+
+    public class CalculatorTest implements ExecutionObserver {
+        private static final String JNDI = 
"java:global/simple-stateless-callbacks/CalculatorBean";
+
+        private List<Object> received = new ArrayList<Object>();
+
+        public Context getContext() throws NamingException {
+            final Properties p = new Properties();
+            p.put(Context.INITIAL_CONTEXT_FACTORY, 
"org.apache.openejb.core.LocalInitialContextFactory");
+            return new InitialContext(p);
+
+        }
+
+        @Test
+        public void test() throws Exception {
+            ExecutionChannel.getInstance().addObserver(this);
+
+            final EJBContainer container = EJBContainer.createEJBContainer();
+
+            {
+                final CalculatorBean calculator = (CalculatorBean) 
getContext().lookup(JNDI);
+
+                Assert.assertEquals(10, calculator.add(4, 6));
+
+                //the bean is constructed only when it is used for the first 
time
+                Assert.assertEquals("postConstruct", this.received.remove(0));
+                Assert.assertEquals("add", this.received.remove(0));
+
+                Assert.assertEquals(-2, calculator.subtract(4, 6));
+                Assert.assertEquals("subtract", this.received.remove(0));
+
+                Assert.assertEquals(24, calculator.multiply(4, 6));
+                Assert.assertEquals("multiply", this.received.remove(0));
+
+                Assert.assertEquals(2, calculator.divide(12, 6));
+                Assert.assertEquals("divide", this.received.remove(0));
+
+                Assert.assertEquals(4, calculator.remainder(46, 6));
+                Assert.assertEquals("remainder", this.received.remove(0));
+            }
+
+            {
+                final CalculatorBean calculator = (CalculatorBean) 
getContext().lookup(JNDI);
+
+                Assert.assertEquals(10, calculator.add(4, 6));
+                Assert.assertEquals("add", this.received.remove(0));
+
+            }
+
+            container.close();
+            Assert.assertEquals("preDestroy", this.received.remove(0));
+            Assert.assertTrue(this.received.isEmpty());
+        }
+
+        @Override
+        public void onExecution(Object value) {
+            System.out.println("Test step -> " + value);
+            this.received.add(value);
+        }
+    }
+
+# Running
+
+    -------------------------------------------------------
+     T E S T S
+    -------------------------------------------------------
+    Running org.superbiz.stateless.basic.CalculatorTest
+    INFO - 
********************************************************************************
+    INFO - OpenEJB http://openejb.apache.org/
+    INFO - Startup: Sat Jul 21 09:23:38 EDT 2012
+    INFO - Copyright 1999-2012 (C) Apache OpenEJB Project, All Rights Reserved.
+    INFO - Version: 4.1.0-SNAPSHOT
+    INFO - Build date: 20120721
+    INFO - Build time: 04:06
+    INFO - 
********************************************************************************
+    INFO - openejb.home = 
/home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks
+    INFO - openejb.base = 
/home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks
+    INFO - Created new singletonService 
org.apache.openejb.cdi.ThreadSingletonServiceImpl@527736bd
+    INFO - Succeeded in installing singleton service
+    INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+    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 - Beginning load: 
/home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks/target/classes
+    INFO - Configuring enterprise application: 
/home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks
+    INFO - Auto-deploying ejb CalculatorBean: 
EjbDeployment(deployment-id=CalculatorBean)
+    INFO - Configuring Service(id=Default Stateless Container, type=Container, 
provider-id=Default Stateless Container)
+    INFO - Auto-creating a container for bean CalculatorBean: 
Container(type=STATELESS, id=Default Stateless Container)
+    INFO - Creating Container(id=Default Stateless Container)
+    INFO - Configuring Service(id=Default Managed Container, type=Container, 
provider-id=Default Managed Container)
+    INFO - Auto-creating a container for bean 
org.superbiz.stateless.basic.CalculatorTest: 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 
"/home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks" 
loaded.
+    INFO - Assembling app: 
/home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks
+    INFO - 
Jndi(name="java:global/simple-stateless-callbacks/CalculatorBean!org.superbiz.stateless.basic.CalculatorBean")
+    INFO - Jndi(name="java:global/simple-stateless-callbacks/CalculatorBean")
+    INFO - Existing thread singleton service in SystemInstance() 
org.apache.openejb.cdi.ThreadSingletonServiceImpl@527736bd
+    INFO - OpenWebBeans Container is starting...
+    INFO - Adding OpenWebBeansPlugin : [CdiPlugin]
+    INFO - All injection points are validated successfully.
+    INFO - OpenWebBeans Container has started, it took 111 ms.
+    INFO - Created Ejb(deployment-id=CalculatorBean, ejb-name=CalculatorBean, 
container=Default Stateless Container)
+    INFO - Started Ejb(deployment-id=CalculatorBean, ejb-name=CalculatorBean, 
container=Default Stateless Container)
+    INFO - Deployed 
Application(path=/home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks)
+    Test step -> postConstruct
+    Test step -> add
+    Test step -> subtract
+    Test step -> multiply
+    Test step -> divide
+    Test step -> remainder
+    Test step -> add
+    INFO - Undeploying app: 
/home/boto/dev/ws/openejb_trunk/openejb/examples/simple-stateless-callbacks
+    Test step -> preDestroy
+    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.884 sec
+
+    Results :
+
+    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

Added: openejb/trunk/openejb/examples/simple-stateless-callbacks/build.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-stateless-callbacks/build.xml?rev=1364096&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/simple-stateless-callbacks/build.xml (added)
+++ openejb/trunk/openejb/examples/simple-stateless-callbacks/build.xml Sat Jul 
21 13:54:42 2012
@@ -0,0 +1,119 @@
+<?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: 1237516 $ $Date: 2012-01-29 19:48:17 -0500 (Sun, 29 Jan 2012) $ -->
+
+<project name="MyProject" default="dist" basedir="." 
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
+
+  <!-- ===============================================================
+
+  HOW TO RUN
+
+    Download 
http://archive.apache.org/dist/maven/binaries/maven-ant-tasks-2.0.9.jar
+    Then execute ant as follows:
+
+    ant -lib maven-ant-tasks-2.0.9.jar
+
+  NOTE
+
+    You do NOT need maven-ant-tasks-2.0.9.jar to use OpenEJB for embedded EJB
+    testing with Ant.  It is simply used in this example to make the build.xml
+    a bit simpler.  As long as OpenEJB and it's required libraries are in the
+    <junit> classpath, the tests will run with OpenEJB embedded.
+
+  ================================================================= -->
+
+  <artifact:remoteRepository id="apache.snapshot.repository" 
url="http://repository.apache.org/snapshots/"/>
+  <artifact:remoteRepository id="m2.repository" 
url="http://repo1.maven.org/maven2/"/>
+
+  <!-- Build Classpath -->
+  <artifact:dependencies pathId="classpath.main">
+    <dependency groupId="org.apache.openejb" artifactId="javaee-api-embedded" 
version="6.0-3"/>
+  </artifact:dependencies>
+
+  <!-- Test Build Classpath -->
+  <artifact:dependencies pathId="classpath.test.build">
+    <dependency groupId="junit" artifactId="junit" version="4.3.1"/>
+  </artifact:dependencies>
+
+  <!-- Test Run Classpath -->
+  <artifact:dependencies pathId="classpath.test.run">
+    <remoteRepository refid="apache.snapshot.repository"/>
+    <remoteRepository refid="m2.repository"/>
+
+    <dependency groupId="org.apache.openejb" artifactId="openejb-core" 
version="4.0.0-beta-1"/>
+    <dependency groupId="junit" artifactId="junit" version="4.3.1"/>
+  </artifact:dependencies>
+
+  <!-- Properties -->
+
+  <property name="src.main.java" location="src/main/java"/>
+  <property name="src.main.resources" location="src/main/resources"/>
+  <property name="src.test.java" location="src/test/java"/>
+  <property name="build.main" location="target/classes"/>
+  <property name="build.test" location="target/test-classes"/>
+  <property name="test.reports" location="target/test-reports"/>
+  <property name="dist" location="target"/>
+
+
+  <target name="init">
+    <mkdir dir="${build.main}"/>
+    <mkdir dir="${build.test}"/>
+    <mkdir dir="${test.reports}"/>
+  </target>
+
+  <target name="compile" depends="init">
+
+    <javac srcdir="${src.main.java}" destdir="${build.main}">
+      <classpath refid="classpath.main"/>
+    </javac>
+    <copy todir="${build.main}">
+      <fileset dir="${src.main.resources}"/>
+    </copy>
+
+    <javac srcdir="${src.test.java}" destdir="${build.test}">
+      <classpath location="${build.main}"/>
+      <classpath refid="classpath.main"/>
+      <classpath refid="classpath.test.build"/>
+    </javac>
+  </target>
+
+  <target name="test" depends="compile">
+    <junit fork="yes" printsummary="yes">
+      <classpath location="${build.main}"/>
+      <classpath location="${build.test}"/>
+      <classpath refid="classpath.main"/>
+      <classpath refid="classpath.test.build"/>
+      <classpath refid="classpath.test.run"/>
+
+      <formatter type="plain"/>
+
+      <batchtest fork="yes" todir="${test.reports}">
+        <fileset dir="${src.test.java}">
+          <include name="**/*Test.java"/>
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
+
+  <target name="dist" depends="test">
+    <jar jarfile="${dist}/myproject-1.0.jar" basedir="${build.main}"/>
+  </target>
+
+</project>

Added: openejb/trunk/openejb/examples/simple-stateless-callbacks/pom.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-stateless-callbacks/pom.xml?rev=1364096&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/simple-stateless-callbacks/pom.xml (added)
+++ openejb/trunk/openejb/examples/simple-stateless-callbacks/pom.xml Sat Jul 
21 13:54:42 2012
@@ -0,0 +1,96 @@
+<?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: 1346534 $ $Date: 2012-06-05 14:57:54 -0400 (Tue, 05 Jun 2012) $ -->
+
+<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>simple-stateless-callbacks</artifactId>
+  <packaging>jar</packaging>
+  <version>1.1-SNAPSHOT</version>
+  <name>OpenEJB :: Examples :: Simple Stateless Pojo Callbacks</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.4</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-4</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.10</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.1.0-SNAPSHOT</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: 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/CalculatorBean.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/CalculatorBean.java?rev=1364096&view=auto
==============================================================================
--- 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/CalculatorBean.java
 (added)
+++ 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/CalculatorBean.java
 Sat Jul 21 13:54:42 2012
@@ -0,0 +1,64 @@
+/**
+ * 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.stateless.basic;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.Stateless;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+@Stateless
+public class CalculatorBean {
+
+    @PostConstruct
+    public void postConstruct() {
+        ExecutionChannel.getInstance().notifyObservers("postConstruct");
+    }
+
+    @PreDestroy
+    public void preDestroy() {
+        ExecutionChannel.getInstance().notifyObservers("preDestroy");
+    }
+
+    @AroundInvoke
+    public Object intercept(InvocationContext ctx) throws Exception {
+        
ExecutionChannel.getInstance().notifyObservers(ctx.getMethod().getName());
+        return ctx.proceed();
+    }
+
+    public int add(int a, int b) {
+        return a + b;
+    }
+
+    public int subtract(int a, int b) {
+        return a - b;
+    }
+
+    public int multiply(int a, int b) {
+        return a * b;
+    }
+
+    public int divide(int a, int b) {
+        return a / b;
+    }
+
+    public int remainder(int a, int b) {
+        return a % b;
+    }
+
+}
\ No newline at end of file

Added: 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/ExecutionChannel.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/ExecutionChannel.java?rev=1364096&view=auto
==============================================================================
--- 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/ExecutionChannel.java
 (added)
+++ 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/ExecutionChannel.java
 Sat Jul 21 13:54:42 2012
@@ -0,0 +1,40 @@
+/**
+ * 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.stateless.basic;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ExecutionChannel {
+    private static final ExecutionChannel INSTANCE = new ExecutionChannel();
+
+    private final List<ExecutionObserver> observers = new 
ArrayList<ExecutionObserver>();
+
+    public static ExecutionChannel getInstance() {
+        return INSTANCE;
+    }
+
+    public void addObserver(ExecutionObserver observer) {
+        this.observers.add(observer);
+    }
+
+    public void notifyObservers(Object value) {
+        for (ExecutionObserver observer : this.observers) {
+            observer.onExecution(value);
+        }
+    }
+}

Added: 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/ExecutionObserver.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/ExecutionObserver.java?rev=1364096&view=auto
==============================================================================
--- 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/ExecutionObserver.java
 (added)
+++ 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/main/java/org/superbiz/stateless/basic/ExecutionObserver.java
 Sat Jul 21 13:54:42 2012
@@ -0,0 +1,23 @@
+/**
+ * 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.stateless.basic;
+
+public interface ExecutionObserver {
+
+    void onExecution(Object value);
+
+}

Added: 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/test/java/org/superbiz/stateless/basic/CalculatorTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/simple-stateless-callbacks/src/test/java/org/superbiz/stateless/basic/CalculatorTest.java?rev=1364096&view=auto
==============================================================================
--- 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/test/java/org/superbiz/stateless/basic/CalculatorTest.java
 (added)
+++ 
openejb/trunk/openejb/examples/simple-stateless-callbacks/src/test/java/org/superbiz/stateless/basic/CalculatorTest.java
 Sat Jul 21 13:54:42 2012
@@ -0,0 +1,88 @@
+/**
+ * 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.stateless.basic;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+public class CalculatorTest implements ExecutionObserver {
+    private static final String JNDI = 
"java:global/simple-stateless-callbacks/CalculatorBean";
+
+    private List<Object> received = new ArrayList<Object>();
+
+    public Context getContext() throws NamingException {
+        final Properties p = new Properties();
+        p.put(Context.INITIAL_CONTEXT_FACTORY, 
"org.apache.openejb.core.LocalInitialContextFactory");
+        return new InitialContext(p);
+
+    }
+
+    @Test
+    public void test() throws Exception {
+        ExecutionChannel.getInstance().addObserver(this);
+
+        final EJBContainer container = EJBContainer.createEJBContainer();
+
+        {
+            final CalculatorBean calculator = (CalculatorBean) 
getContext().lookup(JNDI);
+
+            Assert.assertEquals(10, calculator.add(4, 6));
+
+            //the bean is constructed only when it is used for the first time
+            Assert.assertEquals("postConstruct", this.received.remove(0));
+            Assert.assertEquals("add", this.received.remove(0));
+
+            Assert.assertEquals(-2, calculator.subtract(4, 6));
+            Assert.assertEquals("subtract", this.received.remove(0));
+
+            Assert.assertEquals(24, calculator.multiply(4, 6));
+            Assert.assertEquals("multiply", this.received.remove(0));
+
+            Assert.assertEquals(2, calculator.divide(12, 6));
+            Assert.assertEquals("divide", this.received.remove(0));
+
+            Assert.assertEquals(4, calculator.remainder(46, 6));
+            Assert.assertEquals("remainder", this.received.remove(0));
+        }
+
+        {
+            final CalculatorBean calculator = (CalculatorBean) 
getContext().lookup(JNDI);
+
+            Assert.assertEquals(10, calculator.add(4, 6));
+            Assert.assertEquals("add", this.received.remove(0));
+
+        }
+
+        container.close();
+        Assert.assertEquals("preDestroy", this.received.remove(0));
+        Assert.assertTrue(this.received.isEmpty());
+    }
+
+    @Override
+    public void onExecution(Object value) {
+        System.out.println("Test step -> " + value);
+        this.received.add(value);
+    }
+}


Reply via email to