2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.crud.service;
23 import com.google.common.cache.Cache;
24 import com.google.common.cache.CacheBuilder;
26 import java.util.concurrent.TimeUnit;
28 import org.onap.aai.cl.api.Logger;
29 import org.onap.aai.cl.eelf.LoggerFactory;
30 import org.onap.crud.logging.CrudServiceMsgs;
31 import org.onap.crud.service.CrudAsyncGraphDataService.CollectGraphResponse;
32 import org.onap.crud.util.CrudProperties;
33 import org.onap.crud.util.CrudServiceConstants;
36 * Self expiring Cache to hold request transactionIds . Events are expired
37 * automatically after 2 seconds of request time out
39 public class CrudAsyncGraphEventCache {
40 private static Logger logger = LoggerFactory.getInstance().getLogger(CrudAsyncGraphEventCache
43 private static Integer interval;
46 // Set the cache eviction timeout = request timeout + 2 sec for the
48 interval = CrudAsyncGraphDataService.DEFAULT_REQUEST_TIMEOUT + 2000;
51 .parseInt(CrudProperties.get(CrudServiceConstants.CRD_ASYNC_REQUEST_TIMEOUT) + 2000);
52 } catch (Exception ex) {
53 logger.error(CrudServiceMsgs.ASYNC_DATA_CACHE_ERROR, "Unable to parse "
54 + CrudServiceConstants.CRD_ASYNC_REQUEST_TIMEOUT + " error: "
59 private final static Cache<String, CollectGraphResponse> cache = CacheBuilder.newBuilder()
60 .expireAfterWrite(interval, TimeUnit.MILLISECONDS).build();
63 public static void put(String uuid, CollectGraphResponse collector) {
64 cache.put(uuid, collector);
68 public static CollectGraphResponse get(String uuid) {
69 return cache.getIfPresent(uuid);
72 public static void invalidate(String uuid) {
73 cache.invalidate(uuid);