• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / JavaSpiNNaker / 6168056629

12 Sep 2023 11:09AM UTC coverage: 36.957% (-0.09%) from 37.05%
6168056629

push

github

web-flow
Merge pull request #1038 from SpiNNakerManchester/dependabot/maven/org.webjars-swagger-ui-5.6.1

Bump org.webjars:swagger-ui from 5.4.2 to 5.6.1

8676 of 23476 relevant lines covered (36.96%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

30.43
/SpiNNaker-allocserv/src/main/java/uk/ac/manchester/spinnaker/alloc/allocator/ProxyRememberer.java
1
/*
2
 * Copyright (c) 2022 The University of Manchester
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package uk.ac.manchester.spinnaker.alloc.allocator;
17

18
import static java.util.Objects.nonNull;
19

20
import java.util.ArrayList;
21
import java.util.HashMap;
22
import java.util.List;
23
import java.util.Map;
24

25
import javax.annotation.PreDestroy;
26

27
import org.springframework.stereotype.Component;
28

29
import com.google.errorprone.annotations.concurrent.GuardedBy;
30

31
import uk.ac.manchester.spinnaker.alloc.proxy.ProxyCore;
32

33
/**
34
 * Remembers websocket proxies so that they can be closed when the state of a
35
 * job invalidates them. This class takes care to be thread-safe. The
36
 * information it holds is <em>not</em> persistent.
37
 *
38
 * @author Donal Fellows
39
 */
40
@Component
41
class ProxyRememberer {
2✔
42
        @GuardedBy("itself")
2✔
43
        private final Map<Integer, List<ProxyCore>> proxies = new HashMap<>();
44

45
        /**
46
         * Called when service is shutting down. Kill <em>everything!</em>
47
         */
48
        @PreDestroy
49
        private void closeAllProxies() {
50
                synchronized (proxies) {
×
51
                        proxies.values().forEach(list -> list.forEach(ProxyCore::close));
×
52
                        proxies.clear(); // Just in case
×
53
                }
×
54
        }
×
55

56
        /**
57
         * Note down that a job has a websocket proxy active.
58
         *
59
         * @param jobId
60
         *            The job ID.
61
         * @param proxy
62
         *            The websocket proxy.
63
         */
64
        void rememberProxyForJob(Integer jobId, ProxyCore proxy) {
65
                synchronized (proxies) {
×
66
                        proxies.computeIfAbsent(jobId, __ -> new ArrayList<>()).add(proxy);
×
67
                }
×
68
        }
×
69

70
        /**
71
         * Stop remembering a job's particular websocket proxy.
72
         *
73
         * @param jobId
74
         *            The job ID.
75
         * @param proxy
76
         *            The websocket proxy.
77
         */
78
        void removeProxyForJob(Integer jobId, ProxyCore proxy) {
79
                synchronized (proxies) {
×
80
                        var list = proxies.get(jobId);
×
81
                        if (nonNull(list)) {
×
82
                                list.remove(proxy);
×
83
                        }
84
                }
×
85
        }
×
86

87
        private List<ProxyCore> removeProxyListForJob(Integer jobId) {
88
                synchronized (proxies) {
2✔
89
                        return proxies.remove(jobId);
2✔
90
                }
91
        }
92

93
        /**
94
         * Close all remembered websocket proxies for a job. This is called when the
95
         * state of a job changes significantly (i.e., when the set of boards that
96
         * may be communicated with changes).
97
         *
98
         * @param jobId
99
         *            The job ID.
100
         */
101
        void killProxies(Integer jobId) {
102
                var list = removeProxyListForJob(jobId);
2✔
103
                if (nonNull(list)) {
2✔
104
                        list.forEach(ProxyCore::close);
×
105
                }
106
        }
2✔
107
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc