]> WPIA git - gigi.git/blob - lib/jetty/org/eclipse/jetty/util/Promise.java
Importing upstream Jetty jetty-9.2.1.v20140609
[gigi.git] / lib / jetty / org / eclipse / jetty / util / Promise.java
1 //
2 //  ========================================================================
3 //  Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 //  ------------------------------------------------------------------------
5 //  All rights reserved. This program and the accompanying materials
6 //  are made available under the terms of the Eclipse Public License v1.0
7 //  and Apache License v2.0 which accompanies this distribution.
8 //
9 //      The Eclipse Public License is available at
10 //      http://www.eclipse.org/legal/epl-v10.html
11 //
12 //      The Apache License v2.0 is available at
13 //      http://www.opensource.org/licenses/apache2.0.php
14 //
15 //  You may elect to redistribute this code under either of these licenses.
16 //  ========================================================================
17 //
18
19 package org.eclipse.jetty.util;
20
21 import org.eclipse.jetty.util.log.Log;
22
23 /**
24  * <p>A callback abstraction that handles completed/failed events of asynchronous operations.</p>
25  *
26  * @param <C> the type of the context object
27  */
28 public interface Promise<C>
29 {
30     /**
31      * <p>Callback invoked when the operation completes.</p>
32      *
33      * @param result the context
34      * @see #failed(Throwable)
35      */
36     public abstract void succeeded(C result);
37
38     /**
39      * <p>Callback invoked when the operation fails.</p>
40      *
41      * @param x the reason for the operation failure
42      */
43     public void failed(Throwable x);
44     
45
46     /**
47      * <p>Empty implementation of {@link Promise}</p>
48      *
49      * @param <C> the type of the context object
50      */
51     public static class Adapter<C> implements Promise<C>
52     {
53         @Override
54         public void succeeded(C result)
55         {
56         }
57
58         @Override
59         public void failed(Throwable x)
60         {
61             Log.getLogger(this.getClass()).warn(x);
62         }
63     }
64
65 }