Initial source code
[oam/tr069-adapter.git] / acs / cpe / src / main / java / org / commscope / tr069adapter / acs / cpe / handler / ConnectionReqTimeoutHandler.java
diff --git a/acs/cpe/src/main/java/org/commscope/tr069adapter/acs/cpe/handler/ConnectionReqTimeoutHandler.java b/acs/cpe/src/main/java/org/commscope/tr069adapter/acs/cpe/handler/ConnectionReqTimeoutHandler.java
new file mode 100644 (file)
index 0000000..c4a43ce
--- /dev/null
@@ -0,0 +1,61 @@
+/*\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.acs.cpe.handler;\r
+\r
+import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CR_TIMEOUT_CALLBACK;\r
+\r
+import java.io.Serializable;\r
+\r
+import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;\r
+import org.commscope.tr069adapter.acs.cpe.processor.ConnectionReqEventProcessor;\r
+import org.commscope.tr069adapter.common.timer.TimerListener;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.slf4j.MDC;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.stereotype.Component;\r
+\r
+@Component(CR_TIMEOUT_CALLBACK)\r
+public class ConnectionReqTimeoutHandler implements TimerListener {\r
+\r
+  private static final Logger logger = LoggerFactory.getLogger(ConnectionReqTimeoutHandler.class);\r
+\r
+  private static final String CLIENT_STR = "client";\r
+\r
+  @Autowired\r
+  private ConnectionReqEventProcessor connectionReqEventProcessor;\r
+\r
+  @Override\r
+  public void notifyTimeout(String timerId, Serializable data) {\r
+    TR069DeviceDetails deviceDetails = (TR069DeviceDetails) data;\r
+    MDC.put(CLIENT_STR, deviceDetails.getDeviceId());\r
+    logger.debug(\r
+        "Connection request initiation has timed out, where as device has not sent INFORM event");\r
+\r
+    try {\r
+      connectionReqEventProcessor.initiateConnectionRequest(deviceDetails, true);\r
+      logger.debug("Successfully initiated Connection request on device");\r
+    } catch (Exception e) {\r
+      logger.error("Couldn't initiate connection request, an error occurred: {}", e.getMessage());\r
+    } finally {\r
+      MDC.remove(CLIENT_STR);\r
+    }\r
+  }\r
+\r
+}\r