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.time.Duration;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
29 import org.immutables.gson.Gson;
30 import org.oran.dmaapadapter.clients.AsyncRestClient;
35 public static class Parameters {
37 private String filter;
39 private BufferTimeout bufferTimeout;
41 private int maxConcurrency;
43 public Parameters() {}
45 public Parameters(String filter, BufferTimeout bufferTimeout, int maxConcurrency) {
47 this.bufferTimeout = bufferTimeout;
48 this.maxConcurrency = maxConcurrency;
51 public int getMaxConcurrency() {
52 return maxConcurrency == 0 ? 1 : maxConcurrency;
57 public static class BufferTimeout {
58 public BufferTimeout(int maxSize, long maxTimeMiliseconds) {
59 this.maxSize = maxSize;
60 this.maxTimeMiliseconds = maxTimeMiliseconds;
63 public BufferTimeout() {}
68 private long maxTimeMiliseconds;
70 public Duration getMaxTime() {
71 return Duration.ofMillis(maxTimeMiliseconds);
76 private final String id;
79 private final String callbackUrl;
82 private final InfoType type;
85 private final String owner;
88 private final Parameters parameters;
91 private final String lastUpdated;
93 private final Pattern jobDataFilter;
96 private final AsyncRestClient consumerRestClient;
98 public Job(String id, String callbackUrl, InfoType type, String owner, String lastUpdated, Parameters parameters,
99 AsyncRestClient consumerRestClient) {
101 this.callbackUrl = callbackUrl;
104 this.lastUpdated = lastUpdated;
105 this.parameters = parameters;
106 if (parameters != null && parameters.filter != null) {
107 jobDataFilter = Pattern.compile(parameters.filter);
109 jobDataFilter = null;
111 this.consumerRestClient = consumerRestClient;
114 public boolean isFilterMatch(String data) {
115 if (jobDataFilter == null) {
118 Matcher matcher = jobDataFilter.matcher(data);
119 return matcher.find();
122 public boolean isBuffered() {
123 return parameters != null && parameters.bufferTimeout != null && parameters.bufferTimeout.maxSize > 0
124 && parameters.bufferTimeout.maxTimeMiliseconds > 0;