1 package org.apache.maven.surefire.junitcore.pc;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.concurrent.Future;
23 import java.util.concurrent.atomic.AtomicReference;
24
25 /**
26 * Wrapper of {@link ParallelComputer ParallelComputer status information} and tests been populated before
27 * a shutdown hook has been triggered.
28 *
29 * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
30 * @see ParallelComputer
31 * @since 2.18
32 */
33 final class ShutdownStatus
34 {
35 private final AtomicReference<ExecutionStatus> status =
36 new AtomicReference<ExecutionStatus>( ExecutionStatus.STARTED );
37
38 private Future<ShutdownResult> descriptionsBeforeShutdown;
39
40 boolean tryFinish()
41 {
42 return status.compareAndSet( ExecutionStatus.STARTED, ExecutionStatus.FINISHED );
43 }
44
45 boolean tryTimeout()
46 {
47 return status.compareAndSet( ExecutionStatus.STARTED, ExecutionStatus.TIMEOUT );
48 }
49
50 boolean isTimeoutElapsed()
51 {
52 return status.get() == ExecutionStatus.TIMEOUT;
53 }
54
55 Future<ShutdownResult> getDescriptionsBeforeShutdown()
56 {
57 return descriptionsBeforeShutdown;
58 }
59
60 void setDescriptionsBeforeShutdown( Future<ShutdownResult> descriptionsBeforeShutdown )
61 {
62 this.descriptionsBeforeShutdown = descriptionsBeforeShutdown;
63 }
64 }