Change nexus values to properties
[appc.git] / appc-dispatcher / appc-request-handler / appc-request-handler-core / src / main / java / org / openecomp / appc / requesthandler / helper / RequestRegistry.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package org.openecomp.appc.requesthandler.helper;
23
24 import org.apache.commons.lang.ObjectUtils;
25 import org.openecomp.appc.executor.objects.UniqueRequestIdentifier;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28
29 import java.util.Collections;
30 import java.util.Set;
31 import java.util.concurrent.ConcurrentHashMap;
32
33 /**
34  *
35  * This class serves as Request Registry, which holds the
36  * request unique parameters (originatorId,requestId,subRequestId)
37  * in memory.
38  */
39 public class RequestRegistry {
40
41     static Set<UniqueRequestIdentifier> set = Collections.newSetFromMap(new ConcurrentHashMap<UniqueRequestIdentifier, Boolean>());
42     private static final EELFLogger logger = EELFManager.getInstance().getLogger(RequestRegistry.class);
43     public RequestRegistry(){
44
45     }
46
47     /**
48      * This method accepts unique request parameters and adds it to Request Registry
49      * if Registry already contains same parameters it returns false,
50      * else returns true.
51      * @param requestIdentifier
52      * @return
53      */
54     public boolean registerRequest(UniqueRequestIdentifier requestIdentifier){
55
56         if (logger.isTraceEnabled()) {
57             logger.trace("Entering to registerRequest with UniqueRequestIdentifier = "+ ObjectUtils.toString(requestIdentifier));
58         }
59         boolean output = set.add(requestIdentifier);
60         logger.debug(" Output = " + output);
61         if (logger.isTraceEnabled()) {
62             logger.trace("Exiting from registerRequest with (output = "+ ObjectUtils.toString(output)+")");
63         }
64         return output;
65     }
66
67     /**
68      * This method accepts unique request parameters and removes request
69      * from the Request Registry
70      * @param requestIdentifier
71      */
72     public void removeRequest(UniqueRequestIdentifier requestIdentifier){
73         if (logger.isTraceEnabled()) {
74             logger.trace("Entering to removeRequest with UniqueRequestIdentifier = "+ ObjectUtils.toString(requestIdentifier));
75         }
76         set.remove(requestIdentifier);
77     }
78
79 }