First part of onap rename
[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  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.requesthandler.helper;
26
27 import org.apache.commons.lang.ObjectUtils;
28 import org.onap.appc.executor.objects.UniqueRequestIdentifier;
29 import com.att.eelf.configuration.EELFLogger;
30 import com.att.eelf.configuration.EELFManager;
31
32 import java.util.Collections;
33 import java.util.Set;
34 import java.util.concurrent.ConcurrentHashMap;
35
36 /**
37  *
38  * This class serves as Request Registry, which holds the
39  * request unique parameters (originatorId,requestId,subRequestId)
40  * in memory.
41  */
42 public class RequestRegistry {
43
44     static Set<UniqueRequestIdentifier> set = Collections.newSetFromMap(new ConcurrentHashMap<UniqueRequestIdentifier, Boolean>());
45     private static final EELFLogger logger = EELFManager.getInstance().getLogger(RequestRegistry.class);
46     public RequestRegistry(){
47
48     }
49
50     /**
51      * This method accepts unique request parameters and adds it to Request Registry
52      * if Registry already contains same parameters it returns false,
53      * else returns true.
54      * @param requestIdentifier
55      * @return
56      */
57     public boolean registerRequest(UniqueRequestIdentifier requestIdentifier){
58
59         if (logger.isTraceEnabled()) {
60             logger.trace("Entering to registerRequest with UniqueRequestIdentifier = "+ ObjectUtils.toString(requestIdentifier));
61         }
62         boolean output = set.add(requestIdentifier);
63         logger.debug(" Output = " + output);
64         if (logger.isTraceEnabled()) {
65             logger.trace("Exiting from registerRequest with (output = "+ ObjectUtils.toString(output)+")");
66         }
67         return output;
68     }
69
70     /**
71      * This method accepts unique request parameters and removes request
72      * from the Request Registry
73      * @param requestIdentifier
74      */
75     public void removeRequest(UniqueRequestIdentifier requestIdentifier){
76         if (logger.isTraceEnabled()) {
77             logger.trace("Entering to removeRequest with UniqueRequestIdentifier = "+ ObjectUtils.toString(requestIdentifier));
78         }
79         set.remove(requestIdentifier);
80     }
81
82     /**
83      * This method returns the count of currently registered requests
84      * in the request registry
85      * * @return currently registered requests count
86      */
87     public int getRegisteredRequestCount() {
88         if (logger.isTraceEnabled()) {
89             logger.trace("Entering to getRegisteredRequestCount");
90         }
91         return set.size();
92     }
93 }