Skip to content

Commit

Permalink
Move redis communication classes from red5 applications to bbb-apps-c…
Browse files Browse the repository at this point in the history
…ommon project.
  • Loading branch information
GhaziTriki committed Nov 21, 2018
1 parent 8e10280 commit fbd1d63
Show file tree
Hide file tree
Showing 43 changed files with 471 additions and 937 deletions.
2 changes: 1 addition & 1 deletion akka-bbb-fsesl/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object Dependencies {
val akkaActor = "com.typesafe.akka" % "akka-actor_2.12" % Versions.akkaVersion
val akkaSl4fj = "com.typesafe.akka" % "akka-slf4j_2.12" % Versions.akkaVersion

val logback = "ch.qos.logback" % "logback-classic" % Versions.logback % "runtime"
val logback = "ch.qos.logback" % "logback-classic" % Versions.logback
val commonsCodec = "commons-codec" % "commons-codec" % Versions.codec

val apacheLang = "org.apache.commons" % "commons-lang3" % Versions.lang
Expand Down
44 changes: 0 additions & 44 deletions bbb-apps-common/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import org.bigbluebutton.build._

organization := "org.bigbluebutton"

version := "0.0.4-SNAPSHOT"

val compileSettings = Seq(
Expand All @@ -27,48 +25,6 @@ val compileSettings = Seq(
// into eclipse.
retrieveManaged := true

// https://mvnrepository.com/artifact/org.scala-lang/scala-library
libraryDependencies += "org.scala-lang" % "scala-library" % scalaVersion.value
// https://mvnrepository.com/artifact/org.scala-lang/scala-compiler
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value

// https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor_2.12
libraryDependencies += "com.typesafe.akka" % "akka-actor_2.12" % "2.5.1"
// https://mvnrepository.com/artifact/com.typesafe.akka/akka-slf4j_2.12
libraryDependencies += "com.typesafe.akka" % "akka-slf4j_2.12" % "2.5.1"

// https://mvnrepository.com/artifact/com.github.etaty/rediscala_2.12
libraryDependencies += "com.github.etaty" % "rediscala_2.12" % "1.8.0"

libraryDependencies += "com.softwaremill.quicklens" %% "quicklens" % "1.4.11"

libraryDependencies += "org.bigbluebutton" % "bbb-common-message_2.12" % "0.0.20-SNAPSHOT"

libraryDependencies += "com.google.code.gson" % "gson" % "2.8.5"

// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.7"
libraryDependencies += "commons-io" % "commons-io" % "2.4"
libraryDependencies += "org.apache.commons" % "commons-pool2" % "2.6.0"
libraryDependencies += "org.slf4j" % "slf4j-api" % "1.7.23" % "provided"


libraryDependencies += "junit" % "junit" % "4.12" % "test"
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"

// For generating test reports
libraryDependencies += "org.pegdown" % "pegdown" % "1.6.0" % "test"
// https://mvnrepository.com/artifact/com.typesafe.akka/akka-testkit_2.12
libraryDependencies += "com.typesafe.akka" % "akka-testkit_2.12" % "2.5.1" % "test"

// https://mvnrepository.com/artifact/org.scalactic/scalactic_2.12
libraryDependencies += "org.scalactic" % "scalactic_2.12" % "3.0.3" % "test"

// https://mvnrepository.com/artifact/org.scalatest/scalatest_2.12
libraryDependencies += "org.scalatest" % "scalatest_2.12" % "3.0.3" % "test"

libraryDependencies += "org.mockito" % "mockito-core" % "2.7.22" % "test"

Seq(Revolver.settings: _*)
lazy val appsCommons = (project in file(".")).settings(name := "bbb-apps-common", libraryDependencies ++= Dependencies.runtime).settings(compileSettings)

Expand Down
4 changes: 2 additions & 2 deletions bbb-apps-common/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ object Dependencies {
val scalaCompiler = "org.scala-lang" % "scala-compiler" % Versions.scala

val akkaActor = "com.typesafe.akka" % "akka-actor_2.12" % Versions.akkaVersion
val akkaSl4fj = "com.typesafe.akka" % "akka-slf4j_2.12" % Versions.akkaVersion
val akkaSl4fj = "com.typesafe.akka" % "akka-slf4j_2.12" % Versions.akkaVersion % "provided"

val googleGson = "com.google.code.gson" % "gson" % Versions.gson
val quicklens = "com.softwaremill.quicklens" %% "quicklens" % Versions.quicklens
val sl4jApi = "org.slf4j" % "slf4j-api" % Versions.sl4j
val sl4jApi = "org.slf4j" % "slf4j-api" % Versions.sl4j % "provided"

val apacheLang = "org.apache.commons" % "commons-lang3" % Versions.lang
val apacheIo = "commons-io" % "commons-io" % Versions.io
Expand Down
5 changes: 4 additions & 1 deletion bbb-common-message/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ object Dependencies {
val gson = "2.8.5"
val jackson = "2.9.7"
val sl4j = "1.7.25"
val red5 = "1.0.10-M9"

// Redis
val redisScala = "1.8.0"
Expand All @@ -34,7 +35,8 @@ object Dependencies {

val googleGson = "com.google.code.gson" % "gson" % Versions.gson
val jacksonModule = "com.fasterxml.jackson.module" %% "jackson-module-scala" % Versions.jackson
val sl4jApi = "org.slf4j" % "slf4j-api" % Versions.sl4j
val sl4jApi = "org.slf4j" % "slf4j-api" % Versions.sl4j % "runtime"
val red5 = "org.red5" % "red5-server-common" % Versions.red5

val lettuceCore = "io.lettuce" % "lettuce-core" % Versions.lettuce
val redisScala = "com.github.etaty" % "rediscala_2.12" % Versions.redisScala
Expand All @@ -60,6 +62,7 @@ object Dependencies {
Compile.googleGson,
Compile.jacksonModule,
Compile.sl4jApi,
Compile.red5,
Compile.lettuceCore,
Compile.redisScala) ++ testing
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
*
* Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
*/

package org.bigbluebutton.common2.redis;

import io.lettuce.core.RedisClient;

public abstract class RedisAwareCommunicator {

protected RedisClient redisClient;

protected String host;
protected String password;
protected int port;
protected String clientName;

public abstract void start();

public abstract void stop();

public void setPassword(String password) {
this.password = password;
}

public void setClientName(String clientName) {
this.clientName = clientName;
}

public void setHost(String host) {
this.host = host;
}

public void setPort(int port) {
this.port = port;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,17 @@
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.dynamic.RedisCommandFactory;

public class RedisStorageService {
public class RedisStorageService extends RedisAwareCommunicator {

private static Logger log = LoggerFactory.getLogger(RedisStorageService.class);

private RedisClient redisClient;
private StatefulRedisConnection<String, String> connection;

private String host;
private String password;
private int port;
private String clientName;
private long keyExpiry;

MeetingCommands meetingCommands;
RecordingCommands recordingCommands;

private StatefulRedisConnection<String, String> connection;

public void start() {
log.info("Starting RedisStorageService");
RedisURI redisUri = RedisURI.Builder.redis(this.host, this.port).withClientName(this.clientName).build();
Expand Down Expand Up @@ -94,9 +90,11 @@ public void record(String meetingId, Map<String, String> event) {
log.debug("Recording meeting event {} inside a transaction", meetingId);
RedisCommands<String, String> commands = connection.sync();
commands.multi();
String msgid = recordingCommands.incrementRecords();
// @fixme increment Long msgid =
// recordingCommands.incrementRecords("global:nextRecordedMsgId");
Long msgid = 999L;
recordingCommands.recordEventName("recording:" + meetingId + ":" + msgid, event);
recordingCommands.recordEventValues("meeting:" + meetingId + ":" + "recordings", msgid);
recordingCommands.recordEventValues("meeting:" + meetingId + ":" + "recordings", Long.toString(msgid));
commands.exec();
}

Expand All @@ -110,23 +108,31 @@ public void removeMeeting(String meetingId) {
commands.exec();
}

private String recordMeeting(String key, Map<String, String> info) {
return meetingCommands.recordMeetingInfo(key, info);
}

public void setPassword(String password) {
this.password = password;
}
public void recordAndExpire(String meetingId, Map<String, String> event) {
log.debug("Recording meeting event {} inside a transaction", meetingId);
RedisCommands<String, String> commands = connection.sync();
commands.multi();

public void setClientName(String clientName) {
this.clientName = clientName;
// @fixme increment Long msgid =
// recordingCommands.incrementRecords("global:nextRecordedMsgId");
Long msgid = 999L;
recordingCommands.recordEventName("recording:" + meetingId + ":" + msgid, event);
recordingCommands.recordEventValues("meeting:" + meetingId + ":recordings", Long.toString(msgid));
/**
* We set the key to expire after 14 days as we are still recording the
* event into redis even if the meeting is not recorded. (ralam sept 23,
* 2015)
*/
// @fixme buggy recordingCommands.expireKey("meeting:" + meetingId +
// ":recordings", keyExpiry);
recordingCommands.recordEventValues("meeting:" + meetingId + ":recordings", Long.toString(msgid));
// @fixme buggy recordingCommands.expireKey("meeting:" + meetingId +
// ":recordings", keyExpiry);
commands.exec();
}

public void setHost(String host) {
this.host = host;
private String recordMeeting(String key, Map<String, String> info) {
return meetingCommands.recordMeetingInfo(key, info);
}

public void setPort(int port) {
this.port = port;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public interface MeetingCommands extends Commands {
List<String> mget(String... keys);

@Command("DEL ?0")
String deleteMeeting(String meetingKey);
Long deleteMeeting(String meetingKey);

@Command("SREM ?0")
String deleteMeetings(String meetingsKey);
Long deleteMeetings(String meetingsKey);

@Command("HMSET ?0 ?1")
String recordMeetingInfo(String meetingKey, Map<String, String> values);

@Command("SADD ?0 ?1")
String addBreakoutRooms(String parentKey, String breakoutId);
Long addBreakoutRooms(String parentKey, String breakoutId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
import io.lettuce.core.dynamic.annotation.Command;

public interface RecordingCommands extends Commands {
@Command("INCR global:nextRecordedMsgId")
String incrementRecords();
// Temporary deactivated due to a bug
// @Command("INCR ?0")
// Long incrementRecords(String key);

@Command("HMSET ?0 ?1")
String recordEventName(String meetingKey, Map<String, String> values);

@Command("RPUSH ?0 ?1")
String recordEventValues(String meetingKey, String values);
Long recordEventValues(String meetingKey, String values);
// Buggy command !!
// @Command("EXPIRE ?0 ?1")
// Boolean expireKey(String key, long seconds);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.bigbluebutton.red5.pubsub;
package org.bigbluebutton.common2.redis.pubsub;

import java.util.Set;

Expand All @@ -22,4 +22,4 @@ public void notifyListeners(String pattern, String channel, String message) {
listener.handleMessage(pattern, channel, message);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
*/
package org.bigbluebutton.voiceconf.messaging;
package org.bigbluebutton.common2.redis.pubsub;

public interface MessageHandler {
void handleMessage(String pattern, String channel, String message);
void handleMessage(String pattern, String channel, String message);
}
Loading

0 comments on commit fbd1d63

Please sign in to comment.