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