2 * ========================LICENSE_START=================================
5 * Copyright (C) 2021 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.oran.dmaapadapter.repository;
23 import java.util.Collection;
24 import java.util.HashMap;
26 import java.util.Vector;
28 import org.oran.dmaapadapter.exceptions.ServiceException;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.stereotype.Component;
35 private static final Logger logger = LoggerFactory.getLogger(Jobs.class);
37 private Map<String, Job> allJobs = new HashMap<>();
38 private MultiMap<Job> jobsByType = new MultiMap<>();
42 public synchronized Job getJob(String id) throws ServiceException {
43 Job job = allJobs.get(id);
45 throw new ServiceException("Could not find job: " + id);
50 public synchronized Job get(String id) {
51 return allJobs.get(id);
54 public synchronized void put(Job job) {
55 logger.debug("Put service: {}", job.getId());
56 allJobs.put(job.getId(), job);
57 jobsByType.put(job.getType().getId(), job.getId(), job);
60 public synchronized Iterable<Job> getAll() {
61 return new Vector<>(allJobs.values());
64 public synchronized Job remove(String id) {
65 Job job = allJobs.get(id);
72 public synchronized void remove(Job job) {
73 this.allJobs.remove(job.getId());
74 jobsByType.remove(job.getType().getId(), job.getId());
77 public synchronized int size() {
78 return allJobs.size();
81 public synchronized Collection<Job> getJobsForType(InfoType type) {
82 return jobsByType.get(type.getId());
85 public synchronized void clear() {