Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BalancerFactory |
|
| 1.4;1,4 |
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 | /** | |
23 | * @author Tibor Digana (tibor17) | |
24 | * @since 2.16 | |
25 | * | |
26 | * @see Balancer | |
27 | */ | |
28 | public class BalancerFactory { | |
29 | private BalancerFactory() | |
30 | 0 | { |
31 | 0 | } |
32 | ||
33 | /** | |
34 | * Infinite permits. | |
35 | */ | |
36 | public static Balancer createInfinitePermitsBalancer() | |
37 | { | |
38 | 31 | return balancer( 0, false ); |
39 | } | |
40 | ||
41 | /** | |
42 | * Balancer without fairness. | |
43 | * Fairness guarantees the waiting schedulers to wake up in order they acquired a permit. | |
44 | * | |
45 | * @param concurrency number of permits to acquire when maintaining concurrency on tests | |
46 | */ | |
47 | public static Balancer createBalancer( int concurrency ) | |
48 | { | |
49 | 35 | return balancer( concurrency, false ); |
50 | } | |
51 | ||
52 | /** | |
53 | * Balancer with fairness. | |
54 | * Fairness guarantees the waiting schedulers to wake up in order they acquired a permit. | |
55 | * | |
56 | * @param concurrency number of permits to acquire when maintaining concurrency on tests | |
57 | */ | |
58 | public static Balancer createBalancerWithFairness( int concurrency ) | |
59 | { | |
60 | 48 | return balancer( concurrency, true ); |
61 | } | |
62 | ||
63 | private static Balancer balancer( int concurrency, boolean fairness ) | |
64 | { | |
65 | 114 | boolean shouldBalance = concurrency > 0 && concurrency < Integer.MAX_VALUE; |
66 | 114 | return shouldBalance ? new ThreadResourcesBalancer( concurrency, fairness ) : new NullBalancer(); |
67 | } | |
68 | } |