-/*\r
- * ============LICENSE_START========================================================================\r
- * ONAP : tr-069-adapter\r
- * =================================================================================================\r
- * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
- * =================================================================================================\r
- * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
- * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
- * may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
- * either express or implied. See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ===============LICENSE_END=======================================================================\r
- */\r
-\r
-package org.commscope.tr069adapter.mapper.sync;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.concurrent.Semaphore;\r
-import java.util.concurrent.TimeUnit;\r
-import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;\r
-import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;\r
-import org.commscope.tr069adapter.mapper.MapperConfigProperties;\r
-import org.commscope.tr069adapter.mapper.acs.ACSRequestSender;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.stereotype.Component;\r
-\r
-@Component\r
-public class SynchronizedRequestHandler {\r
-\r
- private static final Logger LOG = LoggerFactory.getLogger(SynchronizedRequestHandler.class);\r
-\r
- private static Map<String, DeviceRPCResponse> opResultMap = new HashMap<>();\r
- private static Map<String, Semaphore> semaphoreMap = new HashMap<>();\r
-\r
- @Autowired\r
- ACSRequestSender tr069RequestSender;\r
-\r
- @Autowired\r
- MapperConfigProperties config;\r
-\r
- public DeviceRPCResponse performDeviceOperation(DeviceRPCRequest deviceRPCRequest) {\r
- Long acsOperationId = tr069RequestSender.sendRequest(deviceRPCRequest);\r
-\r
- if (null == acsOperationId) {\r
- LOG.error("Request could not be sent. opId is null");\r
- return null;\r
- }\r
-\r
- String mapperUniqOperId =\r
- deviceRPCRequest.getDeviceDetails().getDeviceId() + "_" + acsOperationId;\r
- LOG.debug("Received operation mapperUniqOperId = {}", mapperUniqOperId);\r
-\r
- boolean isSuccess = false;\r
- try {\r
- isSuccess = waitForResult(mapperUniqOperId);\r
- } catch (InterruptedException e) {\r
- LOG.debug(\r
- "InterruptedException while waiting for tr069 operation result for operation request {}",\r
- deviceRPCRequest);\r
- LOG.error("Exception : {}", e.getMessage());\r
- Thread.currentThread().interrupt();\r
- }\r
- DeviceRPCResponse result = null;\r
- if (!isSuccess) {\r
- LOG.error("Request got timed out for operation {}", mapperUniqOperId);\r
- semaphoreMap.remove(mapperUniqOperId);\r
- } else {\r
- result = getOperationResult(mapperUniqOperId);\r
- LOG.debug("Received operation result for mapperUniqOperId = {} result : {}", mapperUniqOperId,\r
- result);\r
- }\r
- return result;\r
-\r
- }\r
-\r
- public void notifyResult(DeviceRPCResponse opResult) {\r
- Semaphore mutex = semaphoreMap\r
- .remove(opResult.getDeviceDetails().getDeviceId() + "_" + opResult.getOperationId());\r
- if (mutex != null) {\r
- opResultMap.put(opResult.getDeviceDetails().getDeviceId() + "_" + opResult.getOperationId(),\r
- opResult);\r
- mutex.release();\r
- }\r
- }\r
-\r
- private DeviceRPCResponse getOperationResult(String mapperUniqOperId) {\r
- return opResultMap.remove(mapperUniqOperId);\r
- }\r
-\r
- private boolean waitForResult(String mapperUniqOperId) throws InterruptedException {\r
- LOG.debug("Waiting for operation result for mapperUniqOperId : {}", mapperUniqOperId);\r
- Semaphore semaphore = new Semaphore(0);\r
- semaphoreMap.put(mapperUniqOperId, semaphore);\r
- LOG.debug("Semaphore MAP size = {}", semaphoreMap.size());\r
- LOG.debug("opResultMap MAP size = {}", opResultMap.size());\r
- Integer timeout = 0;\r
- if (null != config.getRequesTimeout()) {\r
- timeout = Integer.valueOf(config.getRequesTimeout());\r
- }\r
- return semaphore.tryAcquire(timeout, TimeUnit.SECONDS);\r
- }\r
-}\r
+/*
+ * ============LICENSE_START========================================================================
+ * ONAP : tr-069-adapter
+ * =================================================================================================
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.
+ * =================================================================================================
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
+ * may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ===============LICENSE_END=======================================================================
+ */
+
+package org.commscope.tr069adapter.mapper.sync;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;
+import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;
+import org.commscope.tr069adapter.mapper.MapperConfigProperties;
+import org.commscope.tr069adapter.mapper.acs.ACSRequestSender;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class SynchronizedRequestHandler {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SynchronizedRequestHandler.class);
+
+ private static Map<String, DeviceRPCResponse> opResultMap = new HashMap<>();
+ private static Map<String, Semaphore> semaphoreMap = new HashMap<>();
+
+ @Autowired
+ ACSRequestSender tr069RequestSender;
+
+ @Autowired
+ MapperConfigProperties config;
+
+ public DeviceRPCResponse performDeviceOperation(DeviceRPCRequest deviceRPCRequest) {
+ Long acsOperationId = tr069RequestSender.sendRequest(deviceRPCRequest);
+
+ if (null == acsOperationId) {
+ LOG.error("Request could not be sent. opId is null");
+ return null;
+ }
+
+ String mapperUniqOperId =
+ deviceRPCRequest.getDeviceDetails().getDeviceId() + "_" + acsOperationId;
+ LOG.debug("Received operation mapperUniqOperId = {}", mapperUniqOperId);
+
+ boolean isSuccess = false;
+ try {
+ isSuccess = waitForResult(mapperUniqOperId);
+ } catch (InterruptedException e) {
+ LOG.debug(
+ "InterruptedException while waiting for tr069 operation result for operation request {}",
+ deviceRPCRequest);
+ LOG.error("Exception : {}", e.getMessage());
+ Thread.currentThread().interrupt();
+ }
+ DeviceRPCResponse result = null;
+ if (!isSuccess) {
+ LOG.error("Request got timed out for operation {}", mapperUniqOperId);
+ semaphoreMap.remove(mapperUniqOperId);
+ } else {
+ result = getOperationResult(mapperUniqOperId);
+ LOG.debug("Received operation result for mapperUniqOperId = {} result : {}", mapperUniqOperId,
+ result);
+ }
+ return result;
+
+ }
+
+ public void notifyResult(DeviceRPCResponse opResult) {
+ Semaphore mutex = semaphoreMap
+ .remove(opResult.getDeviceDetails().getDeviceId() + "_" + opResult.getOperationId());
+ if (mutex != null) {
+ opResultMap.put(opResult.getDeviceDetails().getDeviceId() + "_" + opResult.getOperationId(),
+ opResult);
+ mutex.release();
+ }
+ }
+
+ private DeviceRPCResponse getOperationResult(String mapperUniqOperId) {
+ return opResultMap.remove(mapperUniqOperId);
+ }
+
+ private boolean waitForResult(String mapperUniqOperId) throws InterruptedException {
+ LOG.debug("Waiting for operation result for mapperUniqOperId : {}", mapperUniqOperId);
+ Semaphore semaphore = new Semaphore(0);
+ semaphoreMap.put(mapperUniqOperId, semaphore);
+ LOG.debug("Semaphore MAP size = {}", semaphoreMap.size());
+ LOG.debug("opResultMap MAP size = {}", opResultMap.size());
+ Integer timeout = 0;
+ if (null != config.getRequesTimeout()) {
+ timeout = Integer.valueOf(config.getRequesTimeout());
+ }
+ return semaphore.tryAcquire(timeout, TimeUnit.SECONDS);
+ }
+}