From 9893e352be1fda4118cc42024c477b57fe0bfe82 Mon Sep 17 00:00:00 2001 From: Richard Alam <ritzalam@gmail.com> Date: Fri, 13 Sep 2019 10:54:56 -0700 Subject: [PATCH] Add more akka fsesl logs - add more logs to trace messages - add FS status check by sending ESL message to FS --- .../FreeswitchConferenceEventListener.java | 9 +++-- .../voice/freeswitch/ConnectionManager.java | 23 +++++++++++- .../voice/freeswitch/ESLEventListener.java | 10 +++--- .../freeswitch/FreeswitchApplication.java | 6 ++-- .../actions/CheckFreeswitchStatusCommand.java | 35 +++++++++++++++++++ .../freeswitch/RxJsonMsgHdlrActor.scala | 2 +- 6 files changed, 74 insertions(+), 11 deletions(-) create mode 100755 akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/actions/CheckFreeswitchStatusCommand.java diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java index 00e4ad6a24..445d169314 100755 --- a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java +++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java @@ -22,10 +22,13 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; - import org.bigbluebutton.freeswitch.voice.events.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FreeswitchConferenceEventListener implements ConferenceEventListener { + private static Logger log = LoggerFactory.getLogger(FreeswitchConferenceEventListener.class); + private static final int SENDERTHREADS = 1; private static final Executor msgSenderExec = Executors.newFixedThreadPool(SENDERTHREADS); private static final Executor runExec = Executors.newFixedThreadPool(SENDERTHREADS); @@ -43,7 +46,7 @@ public class FreeswitchConferenceEventListener implements ConferenceEventListene messages.offer(event, 5, TimeUnit.SECONDS); } catch (InterruptedException e) { // TODO Auto-generated catch block - e.printStackTrace(); + log.error("Exception queueing message: ", e); } } @@ -103,7 +106,7 @@ public class FreeswitchConferenceEventListener implements ConferenceEventListene sendMessageToBigBlueButton(message); } catch (InterruptedException e) { // TODO Auto-generated catch block - e.printStackTrace(); + log.error("Exception taking message form queue: ", e); } } } diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ConnectionManager.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ConnectionManager.java index b63e0e0ade..7302cbfadf 100755 --- a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ConnectionManager.java +++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ConnectionManager.java @@ -54,6 +54,8 @@ public class ConnectionManager { private final ConferenceEventListener conferenceEventListener; private final ESLEventListener eslEventListener; + private long lastStatusCheck = 0L; + public ConnectionManager(ManagerConnection connManager, ESLEventListener eventListener, ConferenceEventListener confListener) { this.manager = connManager; @@ -62,6 +64,7 @@ public class ConnectionManager { } private void connect() { + //log.info("Connecting to FS ESL"); try { Client c = manager.getESLClient(); if (!c.canSend()) { @@ -74,10 +77,18 @@ public class ConnectionManager { c.cancelEventSubscriptions(); c.addEventListener(eslEventListener); c.setEventSubscriptions("plain", "all"); - c.addEventFilter(EVENT_NAME, "heartbeat"); + //c.addEventFilter(EVENT_NAME, "heartbeat"); c.addEventFilter(EVENT_NAME, "custom"); c.addEventFilter(EVENT_NAME, "background_job"); subscribed = true; + } else { + // Let's check for status every minute. + Long now = System.currentTimeMillis(); + if ((now - lastStatusCheck) > 60000) { + lastStatusCheck = now; + CheckFreeswitchStatusCommand fsStatusCmd = new CheckFreeswitchStatusCommand("foo", "bar"); + checkFreeswitchStatus(fsStatusCmd); + } } } } catch (InboundConnectionFailure e) { @@ -125,6 +136,7 @@ public class ConnectionManager { } public void checkIfConfIsRunningCommand(CheckIfConfIsRunningCommand command) { + log.info("Sending CheckIfConfIsRunningCommand to FreeSWITCH"); Client c = manager.getESLClient(); if (c.canSend()) { EslMessage response = c.sendSyncApiCommand(command.getCommand(), @@ -133,6 +145,15 @@ public class ConnectionManager { } } + public void checkFreeswitchStatus(CheckFreeswitchStatusCommand ccrc) { + Client c = manager.getESLClient(); + if (c.canSend()) { + EslMessage response = c.sendSyncApiCommand(ccrc.getCommand(), + ccrc.getCommandArgs()); + ccrc.handleResponse(response, conferenceEventListener); + } + } + public void checkIfConferenceIsRecording(ConferenceCheckRecordCommand ccrc) { Client c = manager.getESLClient(); if (c.canSend()) { diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java index 0a0dbdac62..5fe62e0dd7 100755 --- a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java +++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java @@ -44,6 +44,7 @@ public class ESLEventListener implements IEslEventListener { @Override public void exceptionCaught(ExceptionEvent e) { + log.warn("Exception caught: ", e); // setChanged(); // notifyObservers(e); } @@ -237,13 +238,14 @@ public class ESLEventListener implements IEslEventListener { @Override public void eventReceived(EslEvent event) { -// System.out.println("ESL Event Listener received event=[" + event.getEventName() + "]" + -// event.getEventHeaders().toString()); -// if (event.getEventName().equals(FreeswitchHeartbeatMonitor.EVENT_HEARTBEAT)) { + //System.out.println("ESL Event Listener received event=[" + event.getEventName() + "]" + + // event.getEventHeaders().toString()); + if (event.getEventName().equals("heartbeat")) { + log.info("Received heartbeat from FreeSWITCH"); //// setChanged(); // notifyObservers(event); // return; -// } + } } private Integer getMemberIdFromEvent(EslEvent e) { diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/FreeswitchApplication.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/FreeswitchApplication.java index 46400c9085..ead6c0740c 100755 --- a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/FreeswitchApplication.java +++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/FreeswitchApplication.java @@ -66,10 +66,11 @@ public class FreeswitchApplication implements IDelayedCommandListener{ private void queueMessage(FreeswitchCommand command) { try { + log.info("Queue message: " + command.getCommand() + " " + command.getCommandArgs()); messages.offer(command, 5, TimeUnit.SECONDS); } catch (InterruptedException e) { // TODO Auto-generated catch block - e.printStackTrace(); + log.error("Exception queueing message: ", e); } } @@ -94,7 +95,7 @@ public class FreeswitchApplication implements IDelayedCommandListener{ sendMessageToFreeswitch(message); } catch (InterruptedException e) { // TODO Auto-generated catch block - e.printStackTrace(); + log.error("Exception taking message from queue: ", e); } } } @@ -153,6 +154,7 @@ public class FreeswitchApplication implements IDelayedCommandListener{ private void sendMessageToFreeswitch(final FreeswitchCommand command) { Runnable task = new Runnable() { public void run() { + log.info("Sending message: " + command.getCommand() + " " + command.getCommandArgs()); if (command instanceof GetAllUsersCommand) { GetAllUsersCommand cmd = (GetAllUsersCommand) command; manager.getUsers(cmd); diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/actions/CheckFreeswitchStatusCommand.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/actions/CheckFreeswitchStatusCommand.java new file mode 100755 index 0000000000..d0d2aa67f0 --- /dev/null +++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/actions/CheckFreeswitchStatusCommand.java @@ -0,0 +1,35 @@ +package org.bigbluebutton.freeswitch.voice.freeswitch.actions; + +import com.google.gson.Gson; +import org.apache.commons.lang3.StringUtils; +import org.bigbluebutton.freeswitch.voice.events.ConferenceEventListener; +import org.freeswitch.esl.client.transport.message.EslMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CheckFreeswitchStatusCommand extends FreeswitchCommand { + private static Logger log = LoggerFactory.getLogger(CheckFreeswitchStatusCommand.class); + + public CheckFreeswitchStatusCommand(String room, String requesterId) { + super(room, requesterId); + } + + @Override + public String getCommand() { + return "status"; + } + + @Override + public String getCommandArgs() { + log.debug("Check FreeSWITCH Status."); + return ""; + } + + public void handleResponse(EslMessage response, ConferenceEventListener eventListener) { + + Gson gson = new Gson(); + log.info(gson.toJson(response.getBodyLines())); + + } + +} diff --git a/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/RxJsonMsgHdlrActor.scala b/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/RxJsonMsgHdlrActor.scala index 239045f1c6..546c361cbb 100755 --- a/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/RxJsonMsgHdlrActor.scala +++ b/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/RxJsonMsgHdlrActor.scala @@ -32,7 +32,7 @@ class RxJsonMsgHdlrActor(val fsApp: FreeswitchApplication) extends Actor with Ac } def handle(envelope: BbbCoreEnvelope, jsonNode: JsonNode): Unit = { - log.debug("Route envelope name " + envelope.name) + //log.debug("Route envelope name " + envelope.name) envelope.name match { case GetUsersInVoiceConfSysMsg.NAME => routeGetUsersInVoiceConfSysMsg(envelope, jsonNode) -- GitLab