View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 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  /*
20   * Copyright (c) 2012 the original author or authors.
21   *
22   * Licensed under the Apache License, Version 2.0 (the "License");
23   * you may not use this file except in compliance with the License.
24   * You may obtain a copy of the License at
25   *
26   *     http://www.apache.org/licenses/LICENSE-2.0
27   *
28   * Unless required by applicable law or agreed to in writing, software
29   * distributed under the License is distributed on an "AS IS" BASIS,
30   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31   * See the License for the specific language governing permissions and
32   * limitations under the License.
33   */
34  
35  package org.eclipse.jetty.util;
36  
37  import org.eclipse.jetty.util.log.Log;
38  
39  /**
40   * <p>A callback abstraction that handles completed/failed events of asynchronous operations.</p>
41   *
42   * <p>Semantically this is equivalent to an optimise Promise&lt;Void&gt;, but callback is a more meaningful 
43   * name than EmptyPromise</p>
44   */
45  public interface Callback
46  {
47      /**
48       * <p>Callback invoked when the operation completes.</p>
49       *
50       * @see #failed(Throwable)
51       */
52      public abstract void succeeded();
53  
54      /**
55       * <p>Callback invoked when the operation fails.</p>
56       * @param x the reason for the operation failure
57       */
58      public void failed(Throwable x);
59  
60      /**
61       * <p>Empty implementation of {@link Callback}</p>
62       */
63      public static class Adapter implements Callback
64      {
65          @Override
66          public void succeeded()
67          {
68          }
69  
70          @Override
71          public void failed(Throwable x)
72          {
73              Log.getLogger(this.getClass()).warn(x);
74          }
75      }
76  }