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 java.util.concurrent.TimeUnit;
24 import org.onap.aai.cl.api.Logger;
25 import org.onap.aai.cl.eelf.LoggerFactory;
26 import org.onap.crud.logging.CrudServiceMsgs;
27 import org.onap.crud.service.CrudAsyncGraphDataService.CollectGraphResponse;
28 import org.onap.crud.util.CrudProperties;
29 import org.onap.crud.util.CrudServiceConstants;
30 import com.google.common.cache.Cache;
31 import com.google.common.cache.CacheBuilder;
34 * Self expiring Cache to hold request transactionIds . Events are expired
35 * automatically after 2 seconds of request time out
37 public class CrudAsyncGraphEventCache {
38 private static Logger logger = LoggerFactory.getInstance().getLogger(CrudAsyncGraphEventCache
41 private static Integer interval;
44 // Set the cache eviction timeout = request timeout + 2 sec for the
46 interval = CrudAsyncGraphDataService.DEFAULT_REQUEST_TIMEOUT + 2000;
49 .parseInt(CrudProperties.get(CrudServiceConstants.CRD_ASYNC_REQUEST_TIMEOUT) + 2000);
50 } catch (Exception ex) {
51 logger.error(CrudServiceMsgs.ASYNC_DATA_CACHE_ERROR, "Unable to parse "
52 + CrudServiceConstants.CRD_ASYNC_REQUEST_TIMEOUT + " error: "
57 private final static Cache<String, CollectGraphResponse> cache = CacheBuilder.newBuilder()
58 .expireAfterWrite(interval, TimeUnit.MILLISECONDS).build();
61 public static void put(String uuid, CollectGraphResponse collector) {
62 cache.put(uuid, collector);
66 public static CollectGraphResponse get(String uuid) {
67 return cache.getIfPresent(uuid);
70 public static void invalidate(String uuid) {
71 cache.invalidate(uuid);