geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From esh...@apache.org
Subject incubator-geode git commit: GEODE-1221 Move no longer supported use case to test tree.
Date Wed, 13 Apr 2016 17:05:39 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/develop 90ab09cc4 -> 6c033cfe7


GEODE-1221 Move no longer supported use case to test tree.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/6c033cfe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/6c033cfe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/6c033cfe

Branch: refs/heads/develop
Commit: 6c033cfe75de2e42d97bacf7cae122fc1adc8600
Parents: 90ab09c
Author: eshu <eshu@pivotal.io>
Authored: Wed Apr 13 10:02:58 2016 -0700
Committer: eshu <eshu@pivotal.io>
Committed: Wed Apr 13 10:02:58 2016 -0700

----------------------------------------------------------------------
 .../cache/execute/util/CommitFunction.java      | 141 ------------------
 .../execute/util/NestedTransactionFunction.java | 116 ---------------
 .../cache/execute/util/RollbackFunction.java    | 136 ------------------
 .../cache/ClientServerTransactionDUnitTest.java |   2 -
 .../gemfire/internal/cache/CommitFunction.java  | 142 +++++++++++++++++++
 .../cache/NestedTransactionFunction.java        | 116 +++++++++++++++
 .../internal/cache/RollbackFunction.java        | 137 ++++++++++++++++++
 7 files changed, 395 insertions(+), 395 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6c033cfe/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/CommitFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/CommitFunction.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/CommitFunction.java
deleted file mode 100644
index 23139b4..0000000
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/CommitFunction.java
+++ /dev/null
@@ -1,141 +0,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.
- */
-package com.gemstone.gemfire.internal.cache.execute.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.logging.log4j.Logger;
-
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.cache.CacheTransactionManager;
-import com.gemstone.gemfire.cache.TransactionDataNodeHasDepartedException;
-import com.gemstone.gemfire.cache.TransactionId;
-import com.gemstone.gemfire.cache.execute.Execution;
-import com.gemstone.gemfire.cache.execute.Function;
-import com.gemstone.gemfire.cache.execute.FunctionContext;
-import com.gemstone.gemfire.cache.execute.FunctionException;
-import com.gemstone.gemfire.cache.execute.FunctionInvocationTargetException;
-import com.gemstone.gemfire.cache.execute.FunctionService;
-import com.gemstone.gemfire.distributed.DistributedMember;
-import com.gemstone.gemfire.internal.cache.TXId;
-import com.gemstone.gemfire.internal.logging.LogService;
-
-/**
- * This function can be used by GemFire clients and peers to commit an existing
- * transaction. A {@link TransactionId} corresponding to the transaction to be
- * committed must be provided as an argument while invoking this function.<br />
- * 
- * This function should execute only on one server. If the transaction is not
- * hosted on the server where the function is invoked then this function decides
- * to invoke a nested {@link NestedTransactionFunction} which executes on the member where
- * transaction is hosted.<br />
- * 
- * This function returns a single Boolean as result, whose value is <code>Boolean.TRUE</code>
- * if the transaction committed successfully otherwise the return value is
- * <code>Boolean.FALSE</code>.<br />
- * 
- * To execute this function, it is recommended to use the {@link Execution} obtained by
- * using TransactionFunctionService. <br />
- * 
- * To summarize, this function should be used as follows:
- * 
- * <pre>
- * Execution exe = TransactionFunctionService.onTransaction(txId);
- * List l = (List) exe.execute(commitFunction).getResult();
- * Boolean result = (Boolean) l.get(0);
- * </pre>
- * 
- * This function is <b>not</b> registered on the cache servers by default, and
- * it is the user's responsibility to register this function. see
- * {@link FunctionService#registerFunction(Function)}
- * 
- * @since 6.6.1
- */
-public class CommitFunction implements Function {
-  private static final Logger logger = LogService.getLogger();
-
-  private static final long serialVersionUID = 7851518767859544501L;
-
-  public boolean hasResult() {
-    return true;
-  }
-
-  public void execute(FunctionContext context) {
-    Cache cache = CacheFactory.getAnyInstance();
-    TXId txId = null;
-    try {
-      txId = (TXId) context.getArguments();
-    } catch (ClassCastException e) {
-      logger.info("CommitFunction should be invoked with a TransactionId as an argument i.e.
withArgs(txId).execute(function)");
-      throw e;
-    }
-    DistributedMember member = txId.getMemberId();
-    Boolean result = false;
-    final boolean isDebugEnabled = logger.isDebugEnabled();
-    if (cache.getDistributedSystem().getDistributedMember().equals(member)) {
-      if (isDebugEnabled) {
-        logger.debug("CommitFunction: for transaction: {} committing locally", txId);
-      }
-      CacheTransactionManager txMgr = cache.getCacheTransactionManager();
-      if (txMgr.tryResume(txId)) {
-        if (isDebugEnabled) {
-          logger.debug("CommitFunction: resumed transaction: {}", txId);
-        }
-        txMgr.commit();
-        result = true;
-      }
-    } else {
-      ArrayList args = new ArrayList();
-      args.add(txId);
-      args.add(NestedTransactionFunction.COMMIT);
-      Execution ex = FunctionService.onMember(cache.getDistributedSystem(),
-          member).withArgs(args);
-      if (isDebugEnabled) {
-        logger.debug("CommitFunction: for transaction: {} executing NestedTransactionFunction
on member: {}", txId, member);
-      }
-      try {
-        List list = (List) ex.execute(new NestedTransactionFunction()).getResult();
-        result = (Boolean) list.get(0);
-      } catch (FunctionException fe) {
-        if (fe.getCause() instanceof FunctionInvocationTargetException) {
-          throw new TransactionDataNodeHasDepartedException("Could not commit on member:"+member);
-        } else {
-          throw fe;
-        }
-      }
-    }
-    if (isDebugEnabled) {
-      logger.debug("CommitFunction: for transaction: {} returning result: {}", txId, result);
-    }
-    context.getResultSender().lastResult(result);
-  }
-
-  public String getId() {
-    return getClass().getName();
-  }
-
-  public boolean optimizeForWrite() {
-    return true;
-  }
-
-  public boolean isHA() {
-    return false;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6c033cfe/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/NestedTransactionFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/NestedTransactionFunction.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/NestedTransactionFunction.java
deleted file mode 100644
index 9e4aa9d..0000000
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/NestedTransactionFunction.java
+++ /dev/null
@@ -1,116 +0,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.
- */
-package com.gemstone.gemfire.internal.cache.execute.util;
-
-import java.util.ArrayList;
-
-import org.apache.logging.log4j.Logger;
-
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.cache.CacheTransactionManager;
-import com.gemstone.gemfire.cache.TransactionId;
-import com.gemstone.gemfire.cache.execute.Function;
-import com.gemstone.gemfire.cache.execute.FunctionContext;
-import com.gemstone.gemfire.cache.execute.FunctionService;
-import com.gemstone.gemfire.internal.cache.TXId;
-import com.gemstone.gemfire.internal.logging.LogService;
-
-/**
- * This function is used by {@link CommitFunction} to commit existing transaction.
- * A {@link TransactionId} corresponding to the transaction to be
- * committed must be provided as an argument while invoking this function.<br />
- * 
- * When executed this function commits a transaction if it exists locally.<br />
- * 
- * This function returns a single Boolean as result, whose value is <code>Boolean.TRUE</code>
- * if the transaction committed successfully otherwise the return value is
- * <code>Boolean.FALSE</code><br />
- * 
- * This function is <b>not</b> registered on the cache servers by default, and
- * it is the user's responsibility to register this function. see
- * {@link FunctionService#registerFunction(Function)}
- * 
- * @see CommitFunction
- * @since 6.6.1
- *
- */
-public class NestedTransactionFunction implements Function {
-  private static final Logger logger = LogService.getLogger();
-
-  public static final int COMMIT = 1;
-  public static final int ROLLBACK = 2;
-  
-  private static final long serialVersionUID = 1400965724856341543L;
-
-  public boolean hasResult() {
-    return true;
-  }
-
-  public void execute(FunctionContext context) {
-    Cache cache = CacheFactory.getAnyInstance();
-    ArrayList args = (ArrayList) context.getArguments();
-    TXId txId = null;
-    int action = 0;
-    try {
-      txId = (TXId) args.get(0);
-      action = (Integer) args.get(1);
-    } catch (ClassCastException e) {
-      logger.info("CommitFunction should be invoked with a TransactionId as an argument i.e.
withArgs(txId).execute(function)");
-      throw e;
-    }
-    CacheTransactionManager txMgr = cache.getCacheTransactionManager();
-    Boolean result = false;
-    final boolean isDebugEnabled = logger.isDebugEnabled();
-    if (txMgr.tryResume(txId)) {
-      if (isDebugEnabled) {
-        logger.debug("CommitFunction: resumed transaction: {}", txId);
-      }
-      if (action == COMMIT) {
-        if (isDebugEnabled) {
-          logger.debug("CommitFunction: committing transaction: {}", txId);
-        }
-        txMgr.commit();
-      } else if (action == ROLLBACK) {
-        if (isDebugEnabled) {
-          logger.debug("CommitFunction: rolling back transaction: {}", txId);
-        }
-        txMgr.rollback();
-      } else {
-        throw new IllegalStateException("unknown transaction termination action");
-      }
-      result = true;
-    }
-    if (isDebugEnabled) {
-      logger.debug("CommitFunction: for transaction: {} sending result: {}", txId, result);
-    }
-    context.getResultSender().lastResult(result);
-  }
-
-  public String getId() {
-    return getClass().getName();
-  }
-
-  public boolean optimizeForWrite() {
-    return true;
-  }
-
-  public boolean isHA() {
-    return false;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6c033cfe/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/RollbackFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/RollbackFunction.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/RollbackFunction.java
deleted file mode 100644
index f413d6c..0000000
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/execute/util/RollbackFunction.java
+++ /dev/null
@@ -1,136 +0,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.
- */
-package com.gemstone.gemfire.internal.cache.execute.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.logging.log4j.Logger;
-
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.cache.CacheTransactionManager;
-import com.gemstone.gemfire.cache.TransactionDataNodeHasDepartedException;
-import com.gemstone.gemfire.cache.TransactionId;
-import com.gemstone.gemfire.cache.execute.Execution;
-import com.gemstone.gemfire.cache.execute.Function;
-import com.gemstone.gemfire.cache.execute.FunctionContext;
-import com.gemstone.gemfire.cache.execute.FunctionException;
-import com.gemstone.gemfire.cache.execute.FunctionService;
-import com.gemstone.gemfire.distributed.DistributedMember;
-import com.gemstone.gemfire.internal.cache.TXId;
-import com.gemstone.gemfire.internal.logging.LogService;
-
-/**
- * This function can be used by GemFire clients and peers to rollback an existing
- * transaction. A {@link TransactionId} corresponding to the transaction to be
- * rolledback must be provided as an argument while invoking this function.<br />
- * 
- * This function should execute only on one server. If the transaction is not
- * hosted on the server where the function is invoked then this function decides
- * to invoke a {@link NestedTransactionFunction} which executes on the member where
- * transaction is hosted.<br />
- * 
- * This function returns a single Boolean as result, whose value is <code>Boolean.TRUE</code>
- * if the transaction rolled back successfully otherwise the return value is
- * <code>Boolean.FALSE</code>.<br />
- * 
- * To execute this function, it is recommended to use the {@link Execution} obtained by
- * using TransactionFunctionService. <br />
- * 
- * To summarize, this function should be used as follows:
- * 
- * <pre>
- * Execution exe = TransactionFunctionService.onTransaction(txId);
- * List l = (List) exe.execute(rollbackFunction).getResult();
- * Boolean result = (Boolean) l.get(0);
- * </pre>
- * 
- * This function is <b>not</b> registered on the cache servers by default, and
- * it is the user's responsibility to register this function. see
- * {@link FunctionService#registerFunction(Function)}
- * 
- * @since 6.6.1
- */
-public class RollbackFunction implements Function {
-  private static final Logger logger = LogService.getLogger();
-
-  private static final long serialVersionUID = 1377183180063184795L;
-
-  public boolean hasResult() {
-    return true;
-  }
-
-  public void execute(FunctionContext context) {
-    Cache cache = CacheFactory.getAnyInstance();
-    TXId txId = null;
-    try {
-      txId = (TXId) context.getArguments();
-    } catch (ClassCastException e) {
-      logger.info("RollbackFunction should be invoked with a TransactionId as an argument
i.e. withArgs(txId).execute(function)");
-      throw e;
-    }
-    DistributedMember member = txId.getMemberId();
-    Boolean result = false;
-    final boolean isDebugEnabled = logger.isDebugEnabled();
-    if (cache.getDistributedSystem().getDistributedMember().equals(member)) {
-      if (isDebugEnabled) {
-        logger.debug("RollbackFunction: for transaction: {} rolling back locally", txId);
-      }
-      CacheTransactionManager txMgr = cache.getCacheTransactionManager();
-      if (txMgr.tryResume(txId)) {
-        if (isDebugEnabled) {
-          logger.debug("RollbackFunction: resumed transaction: {}", txId);
-        }
-        txMgr.rollback();
-        result = true;
-      }
-    } else {
-      ArrayList args = new ArrayList();
-      args.add(txId);
-      args.add(NestedTransactionFunction.ROLLBACK);
-      Execution ex = FunctionService.onMember(cache.getDistributedSystem(),
-          member).withArgs(args);
-      if (isDebugEnabled) {
-        logger.debug("RollbackFunction: for transaction: {} executing NestedTransactionFunction
on member: {}", txId, member);
-      }
-      try {
-        List list = (List) ex.execute(new NestedTransactionFunction()).getResult();
-        result = (Boolean) list.get(0);
-      } catch (FunctionException fe) {
-        throw new TransactionDataNodeHasDepartedException("Could not Rollback on member:"+member);
-      }
-    }
-    if (isDebugEnabled) {
-      logger.debug("RollbackFunction: for transaction: {} returning result: {}", txId, result);
-    }
-    context.getResultSender().lastResult(result);
-  }
-
-  public String getId() {
-    return getClass().getName();
-  }
-
-  public boolean optimizeForWrite() {
-    return true;
-  }
-
-  public boolean isHA() {
-    return false;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6c033cfe/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ClientServerTransactionDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ClientServerTransactionDUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ClientServerTransactionDUnitTest.java
index 926a50a..672c5e6 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ClientServerTransactionDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ClientServerTransactionDUnitTest.java
@@ -85,8 +85,6 @@ import com.gemstone.gemfire.internal.cache.execute.data.CustId;
 import com.gemstone.gemfire.internal.cache.execute.data.Customer;
 import com.gemstone.gemfire.internal.cache.execute.data.Order;
 import com.gemstone.gemfire.internal.cache.execute.data.OrderId;
-import com.gemstone.gemfire.internal.cache.execute.util.CommitFunction;
-import com.gemstone.gemfire.internal.cache.execute.util.RollbackFunction;
 import com.gemstone.gemfire.internal.cache.tx.ClientTXStateStub;
 import com.gemstone.gemfire.test.dunit.Host;
 import com.gemstone.gemfire.test.dunit.IgnoredException;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6c033cfe/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/CommitFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/CommitFunction.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/CommitFunction.java
new file mode 100644
index 0000000..051465d
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/CommitFunction.java
@@ -0,0 +1,142 @@
+/*
+ * 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 com.gemstone.gemfire.internal.cache;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.logging.log4j.Logger;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.CacheTransactionManager;
+import com.gemstone.gemfire.cache.TransactionDataNodeHasDepartedException;
+import com.gemstone.gemfire.cache.TransactionId;
+import com.gemstone.gemfire.cache.execute.Execution;
+import com.gemstone.gemfire.cache.execute.Function;
+import com.gemstone.gemfire.cache.execute.FunctionContext;
+import com.gemstone.gemfire.cache.execute.FunctionException;
+import com.gemstone.gemfire.cache.execute.FunctionInvocationTargetException;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.distributed.DistributedMember;
+import com.gemstone.gemfire.internal.cache.TXId;
+import com.gemstone.gemfire.internal.logging.LogService;
+
+/**
+ * This function can be used by GemFire clients and peers to commit an existing
+ * transaction. A {@link TransactionId} corresponding to the transaction to be
+ * committed must be provided as an argument while invoking this function.<br />
+ * 
+ * This function should execute only on one server. If the transaction is not
+ * hosted on the server where the function is invoked then this function decides
+ * to invoke a nested {@link NestedTransactionFunction} which executes on the member where
+ * transaction is hosted.<br />
+ * 
+ * This function returns a single Boolean as result, whose value is <code>Boolean.TRUE</code>
+ * if the transaction committed successfully otherwise the return value is
+ * <code>Boolean.FALSE</code>.<br />
+ * 
+ * To execute this function, it is recommended to use the {@link Execution} obtained by
+ * using TransactionFunctionService. <br />
+ * 
+ * To summarize, this function should be used as follows:
+ * 
+ * <pre>
+ * Execution exe = TransactionFunctionService.onTransaction(txId);
+ * List l = (List) exe.execute(commitFunction).getResult();
+ * Boolean result = (Boolean) l.get(0);
+ * </pre>
+ * 
+ * This function is <b>not</b> registered on the cache servers by default, and
+ * it is the user's responsibility to register this function. see
+ * {@link FunctionService#registerFunction(Function)}
+ * 
+ * @since 6.6.1
+ */
+public class CommitFunction implements Function {
+  private static final Logger logger = LogService.getLogger();
+
+  private static final long serialVersionUID = 7851518767859544501L;
+
+  public boolean hasResult() {
+    return true;
+  }
+
+  public void execute(FunctionContext context) {
+    Cache cache = CacheFactory.getAnyInstance();
+    TXId txId = null;
+    try {
+      txId = (TXId) context.getArguments();
+    } catch (ClassCastException e) {
+      logger.info("CommitFunction should be invoked with a TransactionId as an argument i.e.
withArgs(txId).execute(function)");
+      throw e;
+    }
+    DistributedMember member = txId.getMemberId();
+    Boolean result = false;
+    final boolean isDebugEnabled = logger.isDebugEnabled();
+    if (cache.getDistributedSystem().getDistributedMember().equals(member)) {
+      if (isDebugEnabled) {
+        logger.debug("CommitFunction: for transaction: {} committing locally", txId);
+      }
+      CacheTransactionManager txMgr = cache.getCacheTransactionManager();
+      if (txMgr.tryResume(txId)) {
+        if (isDebugEnabled) {
+          logger.debug("CommitFunction: resumed transaction: {}", txId);
+        }
+        txMgr.commit();
+        result = true;
+      }
+    } else {
+      ArrayList args = new ArrayList();
+      args.add(txId);
+      args.add(NestedTransactionFunction.COMMIT);
+      Execution ex = FunctionService.onMember(cache.getDistributedSystem(),
+          member).withArgs(args);
+      if (isDebugEnabled) {
+        logger.debug("CommitFunction: for transaction: {} executing NestedTransactionFunction
on member: {}", txId, member);
+      }
+      try {
+        List list = (List) ex.execute(new NestedTransactionFunction()).getResult();
+        result = (Boolean) list.get(0);
+      } catch (FunctionException fe) {
+        if (fe.getCause() instanceof FunctionInvocationTargetException) {
+          throw new TransactionDataNodeHasDepartedException("Could not commit on member:"+member);
+        } else {
+          throw fe;
+        }
+      }
+    }
+    if (isDebugEnabled) {
+      logger.debug("CommitFunction: for transaction: {} returning result: {}", txId, result);
+    }
+    context.getResultSender().lastResult(result);
+  }
+
+  public String getId() {
+    return getClass().getName();
+  }
+
+  public boolean optimizeForWrite() {
+    return true;
+  }
+
+  public boolean isHA() {
+    //GEM-207
+    return true;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6c033cfe/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/NestedTransactionFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/NestedTransactionFunction.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/NestedTransactionFunction.java
new file mode 100644
index 0000000..edf259c
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/NestedTransactionFunction.java
@@ -0,0 +1,116 @@
+/*
+ * 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 com.gemstone.gemfire.internal.cache;
+
+import java.util.ArrayList;
+
+import org.apache.logging.log4j.Logger;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.CacheTransactionManager;
+import com.gemstone.gemfire.cache.TransactionId;
+import com.gemstone.gemfire.cache.execute.Function;
+import com.gemstone.gemfire.cache.execute.FunctionContext;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.internal.cache.TXId;
+import com.gemstone.gemfire.internal.logging.LogService;
+
+/**
+ * This function is used by {@link CommitFunction} to commit existing transaction.
+ * A {@link TransactionId} corresponding to the transaction to be
+ * committed must be provided as an argument while invoking this function.<br />
+ * 
+ * When executed this function commits a transaction if it exists locally.<br />
+ * 
+ * This function returns a single Boolean as result, whose value is <code>Boolean.TRUE</code>
+ * if the transaction committed successfully otherwise the return value is
+ * <code>Boolean.FALSE</code><br />
+ * 
+ * This function is <b>not</b> registered on the cache servers by default, and
+ * it is the user's responsibility to register this function. see
+ * {@link FunctionService#registerFunction(Function)}
+ * 
+ * @see CommitFunction
+ * @since 6.6.1
+ *
+ */
+public class NestedTransactionFunction implements Function {
+  private static final Logger logger = LogService.getLogger();
+
+  public static final int COMMIT = 1;
+  public static final int ROLLBACK = 2;
+  
+  private static final long serialVersionUID = 1400965724856341543L;
+
+  public boolean hasResult() {
+    return true;
+  }
+
+  public void execute(FunctionContext context) {
+    Cache cache = CacheFactory.getAnyInstance();
+    ArrayList args = (ArrayList) context.getArguments();
+    TXId txId = null;
+    int action = 0;
+    try {
+      txId = (TXId) args.get(0);
+      action = (Integer) args.get(1);
+    } catch (ClassCastException e) {
+      logger.info("CommitFunction should be invoked with a TransactionId as an argument i.e.
withArgs(txId).execute(function)");
+      throw e;
+    }
+    CacheTransactionManager txMgr = cache.getCacheTransactionManager();
+    Boolean result = false;
+    final boolean isDebugEnabled = logger.isDebugEnabled();
+    if (txMgr.tryResume(txId)) {
+      if (isDebugEnabled) {
+        logger.debug("CommitFunction: resumed transaction: {}", txId);
+      }
+      if (action == COMMIT) {
+        if (isDebugEnabled) {
+          logger.debug("CommitFunction: committing transaction: {}", txId);
+        }
+        txMgr.commit();
+      } else if (action == ROLLBACK) {
+        if (isDebugEnabled) {
+          logger.debug("CommitFunction: rolling back transaction: {}", txId);
+        }
+        txMgr.rollback();
+      } else {
+        throw new IllegalStateException("unknown transaction termination action");
+      }
+      result = true;
+    }
+    if (isDebugEnabled) {
+      logger.debug("CommitFunction: for transaction: {} sending result: {}", txId, result);
+    }
+    context.getResultSender().lastResult(result);
+  }
+
+  public String getId() {
+    return getClass().getName();
+  }
+
+  public boolean optimizeForWrite() {
+    return true;
+  }
+
+  public boolean isHA() {
+    return false;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6c033cfe/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/RollbackFunction.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/RollbackFunction.java
b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/RollbackFunction.java
new file mode 100644
index 0000000..7a319a2
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/RollbackFunction.java
@@ -0,0 +1,137 @@
+/*
+ * 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 com.gemstone.gemfire.internal.cache;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.logging.log4j.Logger;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.CacheTransactionManager;
+import com.gemstone.gemfire.cache.TransactionDataNodeHasDepartedException;
+import com.gemstone.gemfire.cache.TransactionId;
+import com.gemstone.gemfire.cache.execute.Execution;
+import com.gemstone.gemfire.cache.execute.Function;
+import com.gemstone.gemfire.cache.execute.FunctionContext;
+import com.gemstone.gemfire.cache.execute.FunctionException;
+import com.gemstone.gemfire.cache.execute.FunctionService;
+import com.gemstone.gemfire.distributed.DistributedMember;
+import com.gemstone.gemfire.internal.cache.TXId;
+import com.gemstone.gemfire.internal.logging.LogService;
+
+/**
+ * This function can be used by GemFire clients and peers to rollback an existing
+ * transaction. A {@link TransactionId} corresponding to the transaction to be
+ * rolledback must be provided as an argument while invoking this function.<br />
+ * 
+ * This function should execute only on one server. If the transaction is not
+ * hosted on the server where the function is invoked then this function decides
+ * to invoke a {@link NestedTransactionFunction} which executes on the member where
+ * transaction is hosted.<br />
+ * 
+ * This function returns a single Boolean as result, whose value is <code>Boolean.TRUE</code>
+ * if the transaction rolled back successfully otherwise the return value is
+ * <code>Boolean.FALSE</code>.<br />
+ * 
+ * To execute this function, it is recommended to use the {@link Execution} obtained by
+ * using TransactionFunctionService. <br />
+ * 
+ * To summarize, this function should be used as follows:
+ * 
+ * <pre>
+ * Execution exe = TransactionFunctionService.onTransaction(txId);
+ * List l = (List) exe.execute(rollbackFunction).getResult();
+ * Boolean result = (Boolean) l.get(0);
+ * </pre>
+ * 
+ * This function is <b>not</b> registered on the cache servers by default, and
+ * it is the user's responsibility to register this function. see
+ * {@link FunctionService#registerFunction(Function)}
+ * 
+ * @since 6.6.1
+ */
+public class RollbackFunction implements Function {
+  private static final Logger logger = LogService.getLogger();
+
+  private static final long serialVersionUID = 1377183180063184795L;
+
+  public boolean hasResult() {
+    return true;
+  }
+
+  public void execute(FunctionContext context) {
+    Cache cache = CacheFactory.getAnyInstance();
+    TXId txId = null;
+    try {
+      txId = (TXId) context.getArguments();
+    } catch (ClassCastException e) {
+      logger.info("RollbackFunction should be invoked with a TransactionId as an argument
i.e. withArgs(txId).execute(function)");
+      throw e;
+    }
+    DistributedMember member = txId.getMemberId();
+    Boolean result = false;
+    final boolean isDebugEnabled = logger.isDebugEnabled();
+    if (cache.getDistributedSystem().getDistributedMember().equals(member)) {
+      if (isDebugEnabled) {
+        logger.debug("RollbackFunction: for transaction: {} rolling back locally", txId);
+      }
+      CacheTransactionManager txMgr = cache.getCacheTransactionManager();
+      if (txMgr.tryResume(txId)) {
+        if (isDebugEnabled) {
+          logger.debug("RollbackFunction: resumed transaction: {}", txId);
+        }
+        txMgr.rollback();
+        result = true;
+      }
+    } else {
+      ArrayList args = new ArrayList();
+      args.add(txId);
+      args.add(NestedTransactionFunction.ROLLBACK);
+      Execution ex = FunctionService.onMember(cache.getDistributedSystem(),
+          member).withArgs(args);
+      if (isDebugEnabled) {
+        logger.debug("RollbackFunction: for transaction: {} executing NestedTransactionFunction
on member: {}", txId, member);
+      }
+      try {
+        List list = (List) ex.execute(new NestedTransactionFunction()).getResult();
+        result = (Boolean) list.get(0);
+      } catch (FunctionException fe) {
+        throw new TransactionDataNodeHasDepartedException("Could not Rollback on member:"+member);
+      }
+    }
+    if (isDebugEnabled) {
+      logger.debug("RollbackFunction: for transaction: {} returning result: {}", txId, result);
+    }
+    context.getResultSender().lastResult(result);
+  }
+
+  public String getId() {
+    return getClass().getName();
+  }
+
+  public boolean optimizeForWrite() {
+    return true;
+  }
+
+  public boolean isHA() {
+    //GEM-207
+    return true;
+  }
+
+}


Mime
View raw message