[jboss-svn-commits] JBL Code SVN: r37167 - in labs/jbosstm/trunk/ArjunaCore: examples and 11 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jun 29 12:14:47 EDT 2011
Author: tomjenkinson
Date: 2011-06-29 12:14:47 -0400 (Wed, 29 Jun 2011)
New Revision: 37167
Added:
labs/jbosstm/trunk/ArjunaCore/examples/
labs/jbosstm/trunk/ArjunaCore/examples/pom.xml
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/pom.xml
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/main/
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/main/java/
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/main/java/org/
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/main/java/org/jboss/
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/main/java/org/jboss/narayana/
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/main/java/org/jboss/narayana/examples/
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/main/java/org/jboss/narayana/examples/stm/
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/main/java/org/jboss/narayana/examples/stm/AtomicObject.java
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/test/
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/test/java/
labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/test/java/TestAtomicObject.java
Log:
JBTM-854 updated to provide an example for TXOJ
Added: labs/jbosstm/trunk/ArjunaCore/examples/pom.xml
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/examples/pom.xml (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/examples/pom.xml 2011-06-29 16:14:47 UTC (rev 37167)
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.narayana.arjunacore.examples</groupId>
+ <artifactId>examples</artifactId>
+ <version>5.0.0.M1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>JBoss Core Examples</name>
+ <description>All examples of JBoss Core</description>
+ <repositories>
+ <repository>
+ <id>jboss-public-repository-group</id>
+ <name>JBoss Public Maven Repository Group</name>
+ <url>https://repository.jboss.org/nexus/content/groups/public/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ <modules>
+ <module>txoj-stm</module>
+ </modules>
+</project>
Added: labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/pom.xml
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/pom.xml (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/pom.xml 2011-06-29 16:14:47 UTC (rev 37167)
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ LLC, and others contributors as indicated by the @authors tag. All rights
+ reserved. See the copyright.txt in the distribution for a full listing of
+ individual contributors. This copyrighted material is made available to anyone
+ wishing to use, modify, copy, or redistribute it subject to the terms and
+ conditions of the GNU Lesser General Public License, v. 2.1. This program
+ is distributed in the hope that it will be useful, but WITHOUT A WARRANTY;
+ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the GNU Lesser General Public License for more details. You
+ should have received a copy of the GNU Lesser General Public License, v.2.1
+ along with this distribution; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.narayana.arjunacore.examples</groupId>
+ <artifactId>examples</artifactId>
+ <version>5.0.0.M1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>txoj-stm</artifactId>
+ <packaging>jar</packaging>
+ <name>TXOJ as STM example</name>
+ <description>TXOJ as STM example</description>
+ <build>
+ <plugins>
+ <!-- This plugin allows our example to be tested -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <workingDirectory>${project.build.directory}/surefire-working-directory</workingDirectory>
+ </configuration>
+ </plugin>
+ <!-- This plugin allows our example to be executed by maven -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <executable>java</executable>
+ <workingDirectory>${project.build.directory}/exec-working-directory</workingDirectory>
+ <arguments>
+ <argument>-classpath</argument>
+ <classpath/>
+ <argument>TransactionManagerExample</argument>
+ </arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.jbossts</groupId>
+ <artifactId>jbossjta</artifactId>
+ <version>4.15.1.Final</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/main/java/org/jboss/narayana/examples/stm/AtomicObject.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/main/java/org/jboss/narayana/examples/stm/AtomicObject.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/main/java/org/jboss/narayana/examples/stm/AtomicObject.java 2011-06-29 16:14:47 UTC (rev 37167)
@@ -0,0 +1,173 @@
+package org.jboss.narayana.examples.stm;
+
+import java.io.IOException;
+
+import com.arjuna.ats.arjuna.AtomicAction;
+import com.arjuna.ats.arjuna.coordinator.ActionStatus;
+import com.arjuna.ats.arjuna.state.InputObjectState;
+import com.arjuna.ats.arjuna.state.OutputObjectState;
+import com.arjuna.ats.txoj.Lock;
+import com.arjuna.ats.txoj.LockManager;
+import com.arjuna.ats.txoj.LockMode;
+import com.arjuna.ats.txoj.LockResult;
+
+public class AtomicObject extends LockManager {
+
+ private int state;
+
+ public AtomicObject() {
+ super();
+
+ state = 0;
+
+ AtomicAction A = new AtomicAction();
+
+ A.begin();
+
+ if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
+ if (A.commit() == ActionStatus.COMMITTED)
+ System.out.println("Created persistent object " + get_uid());
+ else
+ System.out.println("Action.commit error.");
+ } else {
+ A.abort();
+
+ System.out.println("setlock error.");
+ }
+ }
+
+ public void incr(int value) throws Exception {
+ AtomicAction A = new AtomicAction();
+
+ A.begin();
+
+ if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
+ state += value;
+
+ if (A.commit() != ActionStatus.COMMITTED)
+ throw new Exception("Action commit error.");
+ else
+ return;
+ }
+
+ A.abort();
+
+ throw new Exception("Write lock error.");
+ }
+
+ public void set(int value) throws Exception {
+ AtomicAction A = new AtomicAction();
+
+ A.begin();
+
+ if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
+ state = value;
+
+ if (A.commit() != ActionStatus.COMMITTED)
+ throw new Exception("Action commit error.");
+ else
+ return;
+ }
+
+ A.abort();
+
+ throw new Exception("Write lock error.");
+ }
+
+ public int get() throws Exception {
+ AtomicAction A = new AtomicAction();
+ int value = -1;
+
+ A.begin();
+
+ if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
+ value = state;
+
+ if (A.commit() == ActionStatus.COMMITTED)
+ return value;
+ else
+ throw new Exception("Action commit error.");
+ }
+
+ A.abort();
+
+ throw new Exception("Read lock error.");
+ }
+
+ public boolean save_state(OutputObjectState os, int ot) {
+ boolean result = super.save_state(os, ot);
+
+ if (!result)
+ return false;
+
+ try {
+ os.packInt(state);
+ } catch (IOException e) {
+ result = false;
+ }
+
+ return result;
+ }
+
+ public boolean restore_state(InputObjectState os, int ot) {
+ boolean result = super.restore_state(os, ot);
+
+ if (!result)
+ return false;
+
+ try {
+ state = os.unpackInt();
+ } catch (IOException e) {
+ result = false;
+ }
+
+ return result;
+ }
+
+ public String type() {
+ return "/StateManager/LockManager/AtomicObject";
+ }
+
+ public static void main(String[] args) throws Exception {
+ AtomicObject obj = new AtomicObject();
+ AtomicAction a = new AtomicAction();
+
+ a.begin();
+
+ obj.set(1234);
+
+ a.commit();
+
+ if (obj.get() != 1234) {
+ throw new RuntimeException("The object was not set to 1234");
+ }
+
+ a = new AtomicAction();
+
+ a.begin();
+
+ obj.incr(1);
+
+ a.abort();
+
+ if (obj.get() != 1234) {
+ throw new RuntimeException(
+ "The object was not set to 1234 after abort");
+ }
+
+ a = new AtomicAction();
+
+ a.begin();
+
+ obj.incr(11111);
+
+ a.commit();
+
+ if (obj.get() != 12345) {
+ throw new RuntimeException(
+ "The object was not set to 12345 after commit");
+ }
+
+ System.out.println("Atomic object operated as expected");
+ }
+}
Added: labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/test/java/TestAtomicObject.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/test/java/TestAtomicObject.java (rev 0)
+++ labs/jbosstm/trunk/ArjunaCore/examples/txoj-stm/src/test/java/TestAtomicObject.java 2011-06-29 16:14:47 UTC (rev 37167)
@@ -0,0 +1,11 @@
+import org.jboss.narayana.examples.stm.AtomicObject;
+import org.junit.Test;
+
+public class TestAtomicObject {
+
+ @Test
+ public void testAtomicObject() throws Exception {
+ // We know this thorws an exception on failure
+ AtomicObject.main(null);
+ }
+}
More information about the jboss-svn-commits
mailing list