1 //
2 // ========================================================================
3 // Copyright (c) 1995-2015 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 /**
38 * <p>A callback abstraction that handles completed/failed events of asynchronous operations.</p>
39 *
40 * <p>Semantically this is equivalent to an optimise Promise<Void>, but callback is a more meaningful
41 * name than EmptyPromise</p>
42 */
43 public interface Callback
44 {
45 /**
46 * <p>Callback invoked when the operation completes.</p>
47 *
48 * @see #failed(Throwable)
49 */
50 public abstract void succeeded();
51
52 /**
53 * <p>Callback invoked when the operation fails.</p>
54 * @param x the reason for the operation failure
55 */
56 public void failed(Throwable x);
57
58 /**
59 * <p>Empty implementation of {@link Callback}</p>
60 */
61 public static class Adapter implements Callback
62 {
63 /**
64 * Instance of Adapter that can be used when the callback methods need an empty
65 * implementation without incurring in the cost of allocating a new Adapter object.
66 */
67 public static final Adapter INSTANCE = new Adapter();
68
69 @Override
70 public void succeeded()
71 {
72 }
73
74 @Override
75 public void failed(Throwable x)
76 {
77 }
78 }
79 }