2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 Nordix Foundation
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
21 package org.oransc.enrichment.repository;
23 import java.util.Collection;
24 import java.util.HashMap;
26 import java.util.Vector;
28 import org.oransc.enrichment.exceptions.ServiceException;
31 * Dynamic representation of all EI Jobs in the system.
34 private Map<String, EiJob> allEiJobs = new HashMap<>();
36 private MultiMap<EiJob> jobsByType = new MultiMap<>();
38 public synchronized void put(EiJob job) {
39 allEiJobs.put(job.id(), job);
40 jobsByType.put(job.type().getId(), job.id(), job);
43 public synchronized Collection<EiJob> getJobs() {
44 return new Vector<>(allEiJobs.values());
47 public synchronized EiJob getJob(String id) throws ServiceException {
48 EiJob ric = allEiJobs.get(id);
50 throw new ServiceException("Could not find EI job: " + id);
55 public synchronized Collection<EiJob> getJobsForType(String typeId) {
56 return jobsByType.get(typeId);
59 public synchronized Collection<EiJob> getJobsForType(EiType type) {
60 return jobsByType.get(type.getId());
63 public synchronized EiJob get(String id) {
64 return allEiJobs.get(id);
67 public synchronized EiJob remove(String id) {
68 EiJob job = allEiJobs.get(id);
75 public synchronized void remove(EiJob job) {
76 this.allEiJobs.remove(job.id());
77 jobsByType.remove(job.type().getId(), job.id());
80 public synchronized int size() {
81 return allEiJobs.size();
84 public synchronized void clear() {
85 this.allEiJobs.clear();
86 this.jobsByType.clear();