Package: AbstractListenableFuture

AbstractListenableFuture

nameinstructionbranchcomplexitylinemethod
AbstractListenableFuture()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
addListener(Runnable, Executor)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
runListeners()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
3: * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved.
4: *
5: * This program is licensed to you under the Apache License Version 2.0,
6: * and you may not use this file except in compliance with the Apache License Version 2.0.
7: * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
8: *
9: * Unless required by applicable law or agreed to in writing,
10: * software distributed under the Apache License Version 2.0 is distributed on an
11: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
13: */
14:
15: /*
16: * Copyright (C) 2007 Google Inc.
17: *
18: * Licensed under the Apache License, Version 2.0 (the "License");
19: * you may not use this file except in compliance with the License.
20: * You may obtain a copy of the License at
21: *
22: * http://www.apache.org/licenses/LICENSE-2.0
23: *
24: * Unless required by applicable law or agreed to in writing, software
25: * distributed under the License is distributed on an "AS IS" BASIS,
26: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27: * See the License for the specific language governing permissions and
28: * limitations under the License.
29: */
30:
31: package com.ning.http.client.listenable;
32:
33: import com.ning.http.client.ListenableFuture;
34:
35: import java.util.concurrent.Executor;
36:
37: /**
38: * <p>An abstract base implementation of the listener support provided by
39: * {@link ListenableFuture}. This class uses an {@link ExecutionList} to
40: * guarantee that all registered listeners will be executed. Listener/Executor
41: * pairs are stored in the execution list and executed in the order in which
42: * they were added, but because of thread scheduling issues there is no
43: * guarantee that the JVM will execute them in order. In addition, listeners
44: * added after the task is complete will be executed immediately, even if some
45: * previously added listeners have not yet been executed.
46: *
47: * @author Sven Mawson
48: * @since 1
49: */
50: public abstract class AbstractListenableFuture<V> implements ListenableFuture<V> {
51:
52: // The execution list to hold our executors.
53: private final ExecutionList executionList = new ExecutionList();
54:
55: /*
56: * Adds a listener/executor pair to execution list to execute when this task
57: * is completed.
58: */
59:
60: public ListenableFuture<V> addListener(Runnable listener, Executor exec) {
61: executionList.add(listener, exec);
62: return this;
63: }
64:
65: /*
66: * Override the done method to execute the execution list.
67: */
68: protected void runListeners() {
69: executionList.run();
70: }
71: }