You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2015/04/15 18:53:48 UTC

[11/12] tomee git commit: Expanding example

Expanding example


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/4d27f4ce
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/4d27f4ce
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/4d27f4ce

Branch: refs/heads/master
Commit: 4d27f4ce8663057dd8d2177b804568c6126fd10a
Parents: 52e53c1
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Wed Apr 15 16:29:18 2015 +0100
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Wed Apr 15 17:52:50 2015 +0100

----------------------------------------------------------------------
 examples/resources-jmx-example/pom.xml          | 19 ++++++
 .../resources-jmx-ear/pom.xml                   | 19 ++++++
 .../resources-jmx-ejb/pom.xml                   | 19 ++++++
 .../resource/jmx/factory/Converter.java         |  1 +
 .../superbiz/resource/jmx/factory/Editors.java  |  1 +
 .../resource/jmx/factory/PrimitiveTypes.java    |  1 +
 .../superbiz/resource/jmx/resources/Hello.java  | 10 ++-
 .../src/main/resources/META-INF/beans.xml       | 19 ++++++
 .../src/main/resources/META-INF/resources.xml   |  9 ++-
 .../java/org/superbiz/resource/jmx/JMXTest.java | 71 ++++++++++++++++++--
 .../src/test/resources/arquillian.xml           | 33 ++++-----
 11 files changed, 173 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/4d27f4ce/examples/resources-jmx-example/pom.xml
----------------------------------------------------------------------
diff --git a/examples/resources-jmx-example/pom.xml b/examples/resources-jmx-example/pom.xml
index 4898c9e..62f5d03 100644
--- a/examples/resources-jmx-example/pom.xml
+++ b/examples/resources-jmx-example/pom.xml
@@ -1,4 +1,23 @@
 <?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.
+  -->
+
 <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>

http://git-wip-us.apache.org/repos/asf/tomee/blob/4d27f4ce/examples/resources-jmx-example/resources-jmx-ear/pom.xml
----------------------------------------------------------------------
diff --git a/examples/resources-jmx-example/resources-jmx-ear/pom.xml b/examples/resources-jmx-example/resources-jmx-ear/pom.xml
index e83de66..df3df69 100644
--- a/examples/resources-jmx-example/resources-jmx-ear/pom.xml
+++ b/examples/resources-jmx-example/resources-jmx-ear/pom.xml
@@ -1,4 +1,23 @@
 <?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.
+  -->
+
 <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>

http://git-wip-us.apache.org/repos/asf/tomee/blob/4d27f4ce/examples/resources-jmx-example/resources-jmx-ejb/pom.xml
----------------------------------------------------------------------
diff --git a/examples/resources-jmx-example/resources-jmx-ejb/pom.xml b/examples/resources-jmx-example/resources-jmx-ejb/pom.xml
index e44feb1..c84851a 100644
--- a/examples/resources-jmx-example/resources-jmx-ejb/pom.xml
+++ b/examples/resources-jmx-example/resources-jmx-ejb/pom.xml
@@ -1,4 +1,23 @@
 <?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.
+  -->
+
 <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>

http://git-wip-us.apache.org/repos/asf/tomee/blob/4d27f4ce/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/Converter.java
----------------------------------------------------------------------
diff --git a/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/Converter.java b/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/Converter.java
index 07305ee..e540f4e 100644
--- a/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/Converter.java
+++ b/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/Converter.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.superbiz.resource.jmx.factory;
 
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/4d27f4ce/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/Editors.java
----------------------------------------------------------------------
diff --git a/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/Editors.java b/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/Editors.java
index 33c9fc8..c39cf7e 100644
--- a/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/Editors.java
+++ b/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/Editors.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.superbiz.resource.jmx.factory;
 
 import java.beans.PropertyEditor;

http://git-wip-us.apache.org/repos/asf/tomee/blob/4d27f4ce/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/PrimitiveTypes.java
----------------------------------------------------------------------
diff --git a/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/PrimitiveTypes.java b/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/PrimitiveTypes.java
index da9e56c..9377409 100644
--- a/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/PrimitiveTypes.java
+++ b/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/factory/PrimitiveTypes.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.superbiz.resource.jmx.factory;
 
 public enum PrimitiveTypes {

http://git-wip-us.apache.org/repos/asf/tomee/blob/4d27f4ce/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/resources/Hello.java
----------------------------------------------------------------------
diff --git a/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/resources/Hello.java b/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/resources/Hello.java
index 5b04d8f..d6b5493 100644
--- a/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/resources/Hello.java
+++ b/examples/resources-jmx-example/resources-jmx-ejb/src/main/java/org/superbiz/resource/jmx/resources/Hello.java
@@ -19,11 +19,9 @@
 
 package org.superbiz.resource.jmx.resources;
 
-import java.util.concurrent.atomic.AtomicInteger;
-
 public class Hello implements HelloMBean {
 
-    private AtomicInteger count = new AtomicInteger(0);
+    private int count = 0;
 
     @Override
     public String greet(String name) {
@@ -36,16 +34,16 @@ public class Hello implements HelloMBean {
 
     @Override
     public int getCount() {
-        return count.get();
+        return count;
     }
 
     @Override
     public void setCount(int value) {
-        count.set(value);
+        count = value;
     }
 
     @Override
     public void increment() {
-        count.incrementAndGet();
+        count++;
     }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/4d27f4ce/examples/resources-jmx-example/resources-jmx-ejb/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/examples/resources-jmx-example/resources-jmx-ejb/src/main/resources/META-INF/beans.xml b/examples/resources-jmx-example/resources-jmx-ejb/src/main/resources/META-INF/beans.xml
index c659db4..8af19c5 100644
--- a/examples/resources-jmx-example/resources-jmx-ejb/src/main/resources/META-INF/beans.xml
+++ b/examples/resources-jmx-example/resources-jmx-ejb/src/main/resources/META-INF/beans.xml
@@ -1,3 +1,22 @@
 <?xml version="1.0"?>
+<!--
+  ~ 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 xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd"/>

http://git-wip-us.apache.org/repos/asf/tomee/blob/4d27f4ce/examples/resources-jmx-example/resources-jmx-ejb/src/main/resources/META-INF/resources.xml
----------------------------------------------------------------------
diff --git a/examples/resources-jmx-example/resources-jmx-ejb/src/main/resources/META-INF/resources.xml b/examples/resources-jmx-example/resources-jmx-ejb/src/main/resources/META-INF/resources.xml
index cff5fff..03bd9d0 100644
--- a/examples/resources-jmx-example/resources-jmx-ejb/src/main/resources/META-INF/resources.xml
+++ b/examples/resources-jmx-example/resources-jmx-ejb/src/main/resources/META-INF/resources.xml
@@ -22,6 +22,13 @@
   <Resource id="Hello" class-name="org.superbiz.resource.jmx.factory.JMXBeanCreator" factory-name="create">
     code org.superbiz.resource.jmx.resources.Hello
     name superbiz.test:name=Hello
-    count 12345
+    count 20
   </Resource>
+
+  <Resource id="Alternative" class-name="org.superbiz.resource.jmx.resources.Alternative">
+    code org.superbiz.resource.jmx.resources.Alternative
+    name superbiz.test:name=Alternative
+    count 20
+  </Resource>
+
 </Resources>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tomee/blob/4d27f4ce/examples/resources-jmx-example/resources-jmx-ejb/src/test/java/org/superbiz/resource/jmx/JMXTest.java
----------------------------------------------------------------------
diff --git a/examples/resources-jmx-example/resources-jmx-ejb/src/test/java/org/superbiz/resource/jmx/JMXTest.java b/examples/resources-jmx-example/resources-jmx-ejb/src/test/java/org/superbiz/resource/jmx/JMXTest.java
index 6a9438c..42fc51f 100644
--- a/examples/resources-jmx-example/resources-jmx-ejb/src/test/java/org/superbiz/resource/jmx/JMXTest.java
+++ b/examples/resources-jmx-example/resources-jmx-ejb/src/test/java/org/superbiz/resource/jmx/JMXTest.java
@@ -28,6 +28,7 @@ import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.superbiz.resource.jmx.resources.AlternativeMBean;
 import org.superbiz.resource.jmx.resources.HelloMBean;
 
 import javax.annotation.Resource;
@@ -46,6 +47,9 @@ public class JMXTest {
     @EJB
     private TestEjb ejb;
 
+    @EJB
+    private AlternativeEjb alternativeEjb;
+
     @Deployment
     public static EnterpriseArchive createDeployment() {
 
@@ -68,16 +72,16 @@ public class JMXTest {
 
         Assert.assertNotNull(ejb);
         
-        Assert.assertEquals(0, mbs.getAttribute(objectName, "Count"));
-        Assert.assertEquals(0, ejb.getCount());
+        Assert.assertEquals(20, mbs.getAttribute(objectName, "Count"));
+        Assert.assertEquals(20, ejb.getCount());
         
         mbs.invoke(objectName, "increment", new Object[0], new String[0]);
-        Assert.assertEquals(1, mbs.getAttribute(objectName, "Count"));
-        Assert.assertEquals(1, ejb.getCount());
+        Assert.assertEquals(21, mbs.getAttribute(objectName, "Count"));
+        Assert.assertEquals(21, ejb.getCount());
         
         ejb.increment();
-        Assert.assertEquals(2, mbs.getAttribute(objectName, "Count"));
-        Assert.assertEquals(2, ejb.getCount());
+        Assert.assertEquals(22, mbs.getAttribute(objectName, "Count"));
+        Assert.assertEquals(22, ejb.getCount());
 
         Attribute attribute = new Attribute("Count", 12345);
         mbs.setAttribute(objectName, attribute);
@@ -92,6 +96,37 @@ public class JMXTest {
         Assert.assertEquals("Hello, world", ejb.greet("world"));
     }
 
+    @Test
+    public void testPostConstruct() throws Exception {
+        final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+        final ObjectName objectName = new ObjectName("superbiz.test:name=Alternative");
+
+        Assert.assertNotNull(alternativeEjb);
+
+        Assert.assertEquals(20, mbs.getAttribute(objectName, "Count"));
+        Assert.assertEquals(20, alternativeEjb.getCount());
+
+        mbs.invoke(objectName, "increment", new Object[0], new String[0]);
+        Assert.assertEquals(21, mbs.getAttribute(objectName, "Count"));
+        Assert.assertEquals(21, alternativeEjb.getCount());
+
+        alternativeEjb.increment();
+        Assert.assertEquals(22, mbs.getAttribute(objectName, "Count"));
+        Assert.assertEquals(22, alternativeEjb.getCount());
+
+        Attribute attribute = new Attribute("Count", 12345);
+        mbs.setAttribute(objectName, attribute);
+        Assert.assertEquals(12345, mbs.getAttribute(objectName, "Count"));
+        Assert.assertEquals(12345, alternativeEjb.getCount());
+
+        alternativeEjb.setCount(23456);
+        Assert.assertEquals(23456, mbs.getAttribute(objectName, "Count"));
+        Assert.assertEquals(23456, alternativeEjb.getCount());
+
+        Assert.assertEquals("Hello, world", mbs.invoke(objectName, "greet", new Object[] { "world" }, new String[] { String.class.getName() }));
+        Assert.assertEquals("Hello, world", alternativeEjb.greet("world"));
+    }
+
     @Singleton
     @Lock(LockType.READ)
     public static class TestEjb {
@@ -115,4 +150,28 @@ public class JMXTest {
             return helloMBean.getCount();
         }
     }
+
+    @Singleton
+    @Lock(LockType.READ)
+    public static class AlternativeEjb {
+
+        @Resource(name="jmx/Alternative")
+        private AlternativeMBean alternativeMBean;
+
+        public String greet(String name) {
+            return alternativeMBean.greet(name);
+        }
+
+        public void setCount(int count) {
+            alternativeMBean.setCount(count);
+        }
+
+        public void increment() {
+            alternativeMBean.increment();
+        }
+
+        public int getCount() {
+            return alternativeMBean.getCount();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/4d27f4ce/examples/resources-jmx-example/resources-jmx-ejb/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/examples/resources-jmx-example/resources-jmx-ejb/src/test/resources/arquillian.xml b/examples/resources-jmx-example/resources-jmx-ejb/src/test/resources/arquillian.xml
index b015420..7466cda 100644
--- a/examples/resources-jmx-example/resources-jmx-ejb/src/test/resources/arquillian.xml
+++ b/examples/resources-jmx-example/resources-jmx-ejb/src/test/resources/arquillian.xml
@@ -1,21 +1,22 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <!--
-
-    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.
--->
+  ~ 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.
+  -->
 <arquillian>
   <container qualifier="tomee" default="true">
     <configuration>