src/jdk.incubator.adba/share/classes/jdk/incubator/sql2/Operation.java
branchJDK-8188051-branch
changeset 56380 f06946e00a26
child 56397 729f80d0cf31
equal deleted inserted replaced
56373:1f76a5f8e999 56380:f06946e00a26
       
     1 /*
       
     2  * Copyright (c)  2017, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 package jdk.incubator.sql2;
       
    26 
       
    27 import java.time.Duration;
       
    28 import java.util.function.Consumer;
       
    29 
       
    30 /**
       
    31  * A description of some work to be done by the database and how to process the
       
    32  * database output. An {@link Operation} is created by an
       
    33  * {@link OperationGroup}, configured and submitted. If not submitted it is not
       
    34  * executed. If submitted it is possibly executed according to the attributes of
       
    35  * the {@link OperationGroup} that created it.
       
    36  *
       
    37  * Note: A {@link Connection} is an {@link OperationGroup} and so can create
       
    38  * {@link Operation}s.
       
    39  *
       
    40  * @param <T> the type of the result of the {@link Operation}
       
    41  */
       
    42 public interface Operation<T> {
       
    43   
       
    44   /**
       
    45    * Provides an error handler for this {@link Operation}. If execution of this
       
    46    * {@link Operation} results in an error, before the Operation is completed,
       
    47    * the handler is called with the {@link Throwable} as the argument.
       
    48    * 
       
    49    * @param handler
       
    50    * @return this {@link Operation}
       
    51    */
       
    52   public Operation<T> onError(Consumer<Throwable> handler);
       
    53   
       
    54   /**
       
    55    * The minimum time before this {@link Operation} might be canceled
       
    56    * automatically. The default value is forever. The time is
       
    57    * counted from the beginning of Operation execution. The Operation will not
       
    58    * be canceled before {@code minTime} after the beginning of execution.
       
    59    * Some time at least {@code minTime} after the beginning of execution,
       
    60    * an attempt will be made to cancel the {@link Operation} if it has not yet
       
    61    * completed. Implementations are encouraged to attempt to cancel within a
       
    62    * reasonable time, though what is reasonable is implementation dependent.
       
    63    *
       
    64    * @param minTime minimum time to wait before attempting to cancel
       
    65    * @return this Operation
       
    66    * @throws IllegalArgumentException if minTime &lt;= 0 seconds
       
    67    * @throws IllegalStateException if this method is called more than once on
       
    68    * this operation
       
    69    */
       
    70   public Operation<T> timeout(Duration minTime);
       
    71 
       
    72   /**
       
    73    * Add this {@link Operation} to the tail of the {@link Operation} collection
       
    74    * of the {@link Connection} that created this {@link Operation}. An
       
    75    * {@link Operation} can be submitted only once. Once an {@link Operation} is
       
    76    * submitted it is immutable. Any attempt to modify a submitted
       
    77    * {@link Operation} will throw {@link IllegalStateException}.
       
    78    *
       
    79    * @return a {@link Submission} for this {@link Operation}
       
    80    * @throws IllegalStateException if this method is called more than once on
       
    81    * this operation
       
    82    */
       
    83   public Submission<T> submit();
       
    84 
       
    85 }