Return-Path: X-Original-To: apmail-aries-commits-archive@www.apache.org Delivered-To: apmail-aries-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7E75D18C26 for ; Thu, 25 Feb 2016 13:36:22 +0000 (UTC) Received: (qmail 41674 invoked by uid 500); 25 Feb 2016 13:36:21 -0000 Delivered-To: apmail-aries-commits-archive@aries.apache.org Received: (qmail 40779 invoked by uid 500); 25 Feb 2016 13:36:21 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 40766 invoked by uid 99); 25 Feb 2016 13:36:21 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Feb 2016 13:36:21 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id CE3FEC0185 for ; Thu, 25 Feb 2016 13:36:20 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.471 X-Spam-Level: * X-Spam-Status: No, score=1.471 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.329] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id ToSMXhuwPIlF for ; Thu, 25 Feb 2016 13:36:17 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 341C65F39D for ; Thu, 25 Feb 2016 13:36:17 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 6664BE0285 for ; Thu, 25 Feb 2016 13:36:16 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 4F25F3A01D9 for ; Thu, 25 Feb 2016 13:36:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1732301 - in /aries/trunk/tx-control/tx-control-api: ./ src/main/java/org/osgi/service/transaction/control/ src/main/java/org/osgi/service/transaction/control/recovery/ Date: Thu, 25 Feb 2016 13:36:16 -0000 To: commits@aries.apache.org From: timothyjward@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160225133616.4F25F3A01D9@svn01-us-west.apache.org> Author: timothyjward Date: Thu Feb 25 13:36:15 2016 New Revision: 1732301 URL: http://svn.apache.org/viewvc?rev=1732301&view=rev Log: [tx-control] Update to the latest API from the RFC Added: aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/ScopedWorkException.java aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/ aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/TransactionRecovery.java aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/package-info.java aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/packageinfo Modified: aries/trunk/tx-control/tx-control-api/pom.xml aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/TransactionRolledBackException.java aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/TransactionStarter.java Modified: aries/trunk/tx-control/tx-control-api/pom.xml URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-api/pom.xml?rev=1732301&r1=1732300&r2=1732301&view=diff ============================================================================== --- aries/trunk/tx-control/tx-control-api/pom.xml (original) +++ aries/trunk/tx-control/tx-control-api/pom.xml Thu Feb 25 13:36:15 2016 @@ -35,13 +35,15 @@ org.osgi.service.transaction.control, org.osgi.service.transaction.control.jdbc, - org.osgi.service.transaction.control.jpa + org.osgi.service.transaction.control.jpa, + org.osgi.service.transaction.control.recovery org.osgi.service.transaction.control, org.osgi.service.transaction.control.jdbc, org.osgi.service.transaction.control.jpa, + org.osgi.service.transaction.control.recovery, * 0.0.1-SNAPSHOT Added: aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/ScopedWorkException.java URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/ScopedWorkException.java?rev=1732301&view=auto ============================================================================== --- aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/ScopedWorkException.java (added) +++ aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/ScopedWorkException.java Thu Feb 25 13:36:15 2016 @@ -0,0 +1,203 @@ +/* + * Copyright (c) OSGi Alliance (2016). All Rights Reserved. + * + * Licensed 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.osgi.service.transaction.control; + +/** + * An Exception that is thrown when a piece of scoped work exits with an + * {@link Exception} + */ +public class ScopedWorkException extends RuntimeException { + + /** + */ + private static final long serialVersionUID = 4160254161503114842L; + + private final TransactionContext context; + + /** + * Creates a new TransactionException with the supplied message and cause + * + * @param message + * @param cause + * @param context + */ + public ScopedWorkException(String message, Throwable cause, TransactionContext context) { + super(message, cause); + this.context = context; + } + + /** + * @return The ongoing transaction context if the scope is still active + */ + public TransactionContext ongoingContext() { + return context; + } + + /** + * @return The cause of this Exception as a {@link RuntimeException} if it + * is one, or this otherwise + */ + public RuntimeException asRuntimeException() { + return (RuntimeException) getCause(); + } + + /** + * Throws the cause of this Exception as a RuntimeException the supplied + * Exception type. + *

+ * Usage is of the form: + * + *

+	 * public void doStuff() throws IOException {
+	 *     try {
+	 *         ...
+	 *     } catch (ScopedWorkException swe) {
+	 *         throw swe.as(IOException.class);
+	 *     }
+	 * }
+	 * 
+ * + * @param throwable + * @return This method will always throw an exception + * @throws T + */ + public T as(Class throwable) throws T { + Throwable t = getCause(); + + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } + + possibleThrow(throwable, t); + + throw new IllegalArgumentException( + "The cause of this Exception is not an instance of " + + throwable.getName(), + this); + } + + /** + * Throws the cause of this Exception as a RuntimeException or one of the + * supplied Exception types. + *

+ * Usage is of the form: + * + *

+	 * public void doStuff() throws IOException, ClassNotFoundException {
+	 *     try {
+	 *         ...
+	 *     } catch (ScopedWorkException swe) {
+	 *         throw swe.asOneOf(IOException.class, ClassNotFoundException.class);
+	 *     }
+	 * }
+	 * 
+ * + * @param a + * @param b + * @return This method will always throw an exception + * @throws A + * @throws B + */ + public RuntimeException asOneOf( + Class a, Class b) throws A, B { + Throwable t = getCause(); + + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } + + possibleThrow(a, t); + possibleThrow(b, t); + + throw new IllegalArgumentException( + "The cause of this Exception is not an instance of " + + String.join(", ", a.getName(), b.getName()), + this); + } + + /** + * Throws the cause of this Exception as a RuntimeException or one of the + * supplied Exception types. + * + * @see #asOneOf(Class, Class) + * @param a + * @param b + * @param c + * @return This method will always throw an exception + * @throws A + * @throws B + */ + public RuntimeException asOneOf( + Class a, Class b, Class c) throws A, B, C { + Throwable t = getCause(); + + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } + + possibleThrow(a, t); + possibleThrow(b, t); + possibleThrow(c, t); + + throw new IllegalArgumentException( + "The cause of this Exception is not an instance of " + String + .join(", ", a.getName(), b.getName(), c.getName()), + this); + } + + /** + * Throws the cause of this Exception as a RuntimeException or one of the + * supplied Exception types. + * + * @see #asOneOf(Class, Class) + * @param a + * @param b + * @param c + * @param d + * @return This method will always throw an exception + * @throws A + * @throws B + * @throws C + * @throws D + */ + public RuntimeException asOneOf( + Class a, Class b, Class c, Class d) throws A, B, C, D { + Throwable t = getCause(); + + if (t instanceof RuntimeException) { + throw (RuntimeException) t; + } + + possibleThrow(a, t); + possibleThrow(b, t); + possibleThrow(c, t); + possibleThrow(d, t); + + throw new IllegalArgumentException( + "The cause of this Exception is not an instance of " + String + .join(", ", a.getName(), b.getName(), c.getName()), + this); + } + + @SuppressWarnings("unchecked") + private void possibleThrow(Class x, Throwable t) + throws X { + if (x.isInstance(t)) { + throw (X) t; + } + } + +} Modified: aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/TransactionRolledBackException.java URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/TransactionRolledBackException.java?rev=1732301&r1=1732300&r2=1732301&view=diff ============================================================================== --- aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/TransactionRolledBackException.java (original) +++ aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/TransactionRolledBackException.java Thu Feb 25 13:36:15 2016 @@ -16,7 +16,8 @@ package org.osgi.service.transaction.control; /** - * An Exception indicating that the active transaction was rolled back + * An Exception indicating that the active transaction was unexpectedly rolled + * back */ public class TransactionRolledBackException extends TransactionException { Modified: aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/TransactionStarter.java URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/TransactionStarter.java?rev=1732301&r1=1732300&r2=1732301&view=diff ============================================================================== --- aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/TransactionStarter.java (original) +++ aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/TransactionStarter.java Thu Feb 25 13:36:15 2016 @@ -32,10 +32,13 @@ public interface TransactionStarter { * @throws TransactionException if there is an error starting or completing * the transaction * @throws TransactionRolledBackException if the transaction rolled back due - * to a failure + * to a failure in one of the resources or an internal error in + * the TransactionControl service + * @throws ScopedWorkException if the supplied work throws an + * {@link Exception} */ - T required(Callable work) - throws TransactionException, TransactionRolledBackException; + T required(Callable work) throws TransactionException, + TransactionRolledBackException, ScopedWorkException; /** * A new transaction is required to run the supplied piece of work. If an @@ -50,9 +53,11 @@ public interface TransactionStarter { * the transaction * @throws TransactionRolledBackException if the transaction rolled back due * to a failure + * @throws ScopedWorkException if the supplied work throws an + * {@link Exception} */ - T requiresNew(Callable work) - throws TransactionException, TransactionRolledBackException; + T requiresNew(Callable work) throws TransactionException, + TransactionRolledBackException, ScopedWorkException; /** * The supplied piece of work must be run outside the context of a @@ -69,8 +74,11 @@ public interface TransactionStarter { * @return The value returned by the work * @throws TransactionException if there is an error starting or completing * the transaction + * @throws ScopedWorkException if the supplied work throws an + * {@link Exception} */ - T notSupported(Callable work) throws TransactionException; + T notSupported(Callable work) + throws TransactionException, ScopedWorkException; /** * The supplied piece of work may run inside or outside the context of a @@ -88,8 +96,11 @@ public interface TransactionStarter { * @return The value returned by the work * @throws TransactionException if there is an error starting or completing * the transaction + * @throws ScopedWorkException if the supplied work throws an + * {@link Exception} */ - T supports(Callable work) throws TransactionException; + T supports(Callable work) + throws TransactionException, ScopedWorkException; } Added: aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/TransactionRecovery.java URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/TransactionRecovery.java?rev=1732301&view=auto ============================================================================== --- aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/TransactionRecovery.java (added) +++ aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/TransactionRecovery.java Thu Feb 25 13:36:15 2016 @@ -0,0 +1,21 @@ +package org.osgi.service.transaction.control.recovery; + +import javax.transaction.xa.XAResource; + +/** + * This service interface is published by Transaction control services that are + * able to support recovery. Any recoverable resources should register + * themselves with all available recovery services as they are created. + */ +public interface TransactionRecovery { + + /** + * Allow the {@link TransactionRecovery} service to attempt to recover any + * incomplete XA transactions. Any recovery failures that occur must be + * logged and not thrown to the caller of this service. + * + * @param resource + */ + public void recover(XAResource resource); + +} Added: aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/package-info.java URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/package-info.java?rev=1732301&view=auto ============================================================================== --- aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/package-info.java (added) +++ aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/package-info.java Thu Feb 25 13:36:15 2016 @@ -0,0 +1,39 @@ +/* + * Copyright (c) OSGi Alliance (2016). All Rights Reserved. + * + * Licensed 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. + */ + +/** + * Transaction Control Service Recovery Package Version 1.0. + *

+ * Bundles wishing to use this package must list the package in the + * Import-Package header of the bundle's manifest. This package has two types of + * users: the consumers that use the API in this package and the providers that + * implement the API in this package. + *

+ * Example import for consumers using the API in this package: + *

+ * {@code Import-Package: org.osgi.service.transaction.control.recovery; version="[1.0,2.0)"} + *

+ * Example import for providers implementing the API in this package: + *

+ * {@code Import-Package: org.osgi.service.transaction.control.recovery; version="[1.0,1.1)"} + * + * @version 1.0 + * @author $Id: + */ + +@org.osgi.annotation.versioning.Version("1.0.0") +package org.osgi.service.transaction.control.recovery; + Added: aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/packageinfo URL: http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/packageinfo?rev=1732301&view=auto ============================================================================== --- aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/packageinfo (added) +++ aries/trunk/tx-control/tx-control-api/src/main/java/org/osgi/service/transaction/control/recovery/packageinfo Thu Feb 25 13:36:15 2016 @@ -0,0 +1 @@ +version 1.0