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