Fix typos in documentation
[nonrtric.git] / enrichment-coordinator-service / src / main / java / org / oransc / enrichment / repository / EiJobs.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 Nordix Foundation
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20
21 package org.oransc.enrichment.repository;
22
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.Vector;
27
28 import org.oransc.enrichment.exceptions.ServiceException;
29
30 /**
31  * Dynamic representation of all EI Jobs in the system.
32  */
33 public class EiJobs {
34     private Map<String, EiJob> allEiJobs = new HashMap<>();
35
36     private MultiMap<EiJob> jobsByType = new MultiMap<>();
37
38     public synchronized void put(EiJob job) {
39         allEiJobs.put(job.id(), job);
40         jobsByType.put(job.type().getId(), job.id(), job);
41     }
42
43     public synchronized Collection<EiJob> getJobs() {
44         return new Vector<>(allEiJobs.values());
45     }
46
47     public synchronized EiJob getJob(String id) throws ServiceException {
48         EiJob ric = allEiJobs.get(id);
49         if (ric == null) {
50             throw new ServiceException("Could not find EI job: " + id);
51         }
52         return ric;
53     }
54
55     public synchronized Collection<EiJob> getJobsForType(String typeId) {
56         return jobsByType.get(typeId);
57     }
58
59     public synchronized Collection<EiJob> getJobsForType(EiType type) {
60         return jobsByType.get(type.getId());
61     }
62
63     public synchronized EiJob get(String id) {
64         return allEiJobs.get(id);
65     }
66
67     public synchronized EiJob remove(String id) {
68         EiJob job = allEiJobs.get(id);
69         if (job != null) {
70             remove(job);
71         }
72         return job;
73     }
74
75     public synchronized void remove(EiJob job) {
76         this.allEiJobs.remove(job.id());
77         jobsByType.remove(job.type().getId(), job.id());
78     }
79
80     public synchronized int size() {
81         return allEiJobs.size();
82     }
83
84     public synchronized void clear() {
85         this.allEiJobs.clear();
86         this.jobsByType.clear();
87     }
88
89 }