Skip to content

Commit

Permalink
Update Red5 version to 1.3.31; lifecycle refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mondain committed Mar 18, 2024
1 parent c40dfa7 commit 50a2c33
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 149 deletions.
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.red5</groupId>
<artifactId>red5-parent</artifactId>
<version>1.3.30</version>
<version>1.3.31</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>red5-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/org/red5/client/Red5Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class Red5Client {
/**
* Current server version with revision
*/
public static final String VERSION = "Red5 Client 1.3.30";
public static final String VERSION = "Red5 Client 1.3.31";

/**
* Create a new Red5Client object using the connection local to the current thread A bit of magic that lets you access the red5 scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public void invoke(String method, Object[] params, IPendingServiceCallback callb
*/
@Override
public void disconnect() {
log.debug("disconnect: {}", conn);
log.debug("disconnect - connection: {}", conn);
if (conn != null) {
streamDataList.clear();
conn.close();
Expand Down
4 changes: 2 additions & 2 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.red5</groupId>
<artifactId>red5-parent</artifactId>
<version>1.3.30</version>
<version>1.3.31</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>red5-server-common</artifactId>
Expand Down Expand Up @@ -113,7 +113,7 @@
<dependency>
<groupId>net.engio</groupId>
<artifactId>mbassador</artifactId>
<version>1.3.30</version>
<version>1.3.31</version>
</dependency> -->
<dependency>
<groupId>junit</groupId>
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/org/red5/server/api/Red5.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public final class Red5 {
/**
* Server version with revision
*/
public static final String VERSION = "Red5 Server 1.3.30";
public static final String VERSION = "Red5 Server 1.3.31";

/**
* Server version for fmsVer requests
*/
public static final String FMS_VERSION = "RED5/1,3,30,0";
public static final String FMS_VERSION = "RED5/1,3,31,0";

/**
* Server capabilities
Expand Down
2 changes: 1 addition & 1 deletion io/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.red5</groupId>
<artifactId>red5-parent</artifactId>
<version>1.3.30</version>
<version>1.3.31</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>red5-io</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<name>Red5</name>
<description>The Red5 server</description>
<groupId>org.red5</groupId>
<version>1.3.30</version>
<version>1.3.31</version>
<url>https://github.com/Red5/red5-server</url>
<inceptionYear>2005</inceptionYear>
<organization>
Expand Down Expand Up @@ -105,7 +105,7 @@
<bc.version>1.62</bc.version>
<mina.version>2.0.23</mina.version>
<!-- Can no longer open-end spring, 6.0 forces jdk 17 -->
<spring.version>5.3.32</spring.version>
<spring.version>5.3.33</spring.version>
<tomcat.version>8.5.95</tomcat.version>
<junit.version>[4.13.1,)</junit.version>
<isoparser.version>1.9.39</isoparser.version>
Expand Down Expand Up @@ -514,7 +514,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -524,7 +524,7 @@
</plugin>
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<version>3.2.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
2 changes: 1 addition & 1 deletion server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.red5</groupId>
<artifactId>red5-parent</artifactId>
<version>1.3.30</version>
<version>1.3.31</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>red5-server</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public WebSocketPlugin() {
/** {@inheritDoc} */
@Override
public void doStart() throws Exception {
super.doStart();
log.trace("WebSocketPlugin start");
// add scope listener to allow creation of websocket scopes
scopeListener = new ScopeListenerAdapter() {
Expand Down Expand Up @@ -136,7 +135,6 @@ public void doStop() throws Exception {
});
managerMap.clear();
executor.shutdownNow();
super.doStop();
}

/**
Expand Down
135 changes: 60 additions & 75 deletions server/src/main/java/org/red5/server/plugin/PluginRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.red5.logging.Red5LoggerFactory;
import org.red5.server.api.plugin.IRed5Plugin;
Expand All @@ -30,16 +27,27 @@ public class PluginRegistry {
// keeps track of plug-ins, keyed by plug-in name
private static volatile ConcurrentMap<String, IRed5Plugin> plugins = new ConcurrentHashMap<>(3, 0.9f, 1);

// locks for guarding plug-ins
private final static ReadWriteLock pluginLock = new ReentrantReadWriteLock();

private final static Lock pluginReadLock;

private final static Lock pluginWriteLock;
/**
* Returns true if the plug-in is registered.
*
* @param plugin
* plugin
* @return true if the plug-in is registered
*/
public static boolean isRegistered(IRed5Plugin plugin) {
String pluginName = plugin.getName();
return plugins.containsKey(pluginName);
}

static {
pluginReadLock = pluginLock.readLock();
pluginWriteLock = pluginLock.writeLock();
/**
* Returns true if the plug-in is registered.
*
* @param pluginName
* plugin name
* @return true if the plug-in is registered
*/
public static boolean isRegistered(String pluginName) {
return plugins.containsKey(pluginName);
}

/**
Expand All @@ -51,27 +59,21 @@ public class PluginRegistry {
public static void register(IRed5Plugin plugin) {
log.debug("Register plugin: {}", plugin);
String pluginName = plugin.getName();
//get a write lock
pluginWriteLock.lock();
try {
if (plugins.containsKey(pluginName)) {
//get old plugin
IRed5Plugin oldPlugin = plugins.get(pluginName);
//if they are not the same shutdown the older one
if (!plugin.equals(oldPlugin)) {
try {
oldPlugin.doStop();
} catch (Exception e) {
log.warn("Exception caused when stopping old plugin", e);
}
//replace old one
plugins.replace(pluginName, plugin);
if (plugins.containsKey(pluginName)) {
//get old plugin
IRed5Plugin oldPlugin = plugins.get(pluginName);
//if they are not the same shutdown the older one
if (!plugin.equals(oldPlugin)) {
try {
oldPlugin.doStop();
} catch (Exception e) {
log.warn("Exception caused when stopping old plugin", e);
}
} else {
plugins.put(pluginName, plugin);
//replace old one
plugins.replace(pluginName, plugin);
}
} finally {
pluginWriteLock.unlock();
} else {
plugins.put(pluginName, plugin);
}
}

Expand All @@ -83,30 +85,24 @@ public static void register(IRed5Plugin plugin) {
*/
public static void unregister(IRed5Plugin plugin) {
log.debug("Unregister plugin: {}", plugin);
//get a write lock
pluginWriteLock.lock();
try {
if (plugins.containsValue(plugin)) {
boolean removed = false;
for (Entry<String, IRed5Plugin> f : plugins.entrySet()) {
if (plugin.equals(f.getValue())) {
log.debug("Removing {}", plugin);
plugins.remove(f.getKey());
removed = true;
break;
} else {
log.debug("Not equal - {} {}", plugin, f.getValue());
}
}
if (!removed) {
log.debug("Last try to remove the plugin");
plugins.remove(plugin.getName());
if (plugins.containsValue(plugin)) {
boolean removed = false;
for (Entry<String, IRed5Plugin> f : plugins.entrySet()) {
if (plugin.equals(f.getValue())) {
log.debug("Removing {}", plugin);
plugins.remove(f.getKey());
removed = true;
break;
} else {
log.debug("Not equal - {} {}", plugin, f.getValue());
}
} else {
log.warn("Plugin is not registered {}", plugin);
}
} finally {
pluginWriteLock.unlock();
if (!removed) {
log.debug("Last try to remove the plugin");
plugins.remove(plugin.getName());
}
} else {
log.warn("Plugin is not registered {}", plugin);
}
}

Expand All @@ -118,13 +114,7 @@ public static void unregister(IRed5Plugin plugin) {
* @return requested plug-in matching the name given or null if not found
*/
public static IRed5Plugin getPlugin(String pluginName) {
IRed5Plugin plugin = null;
pluginReadLock.lock();
try {
plugin = plugins.get(pluginName);
} finally {
pluginReadLock.unlock();
}
IRed5Plugin plugin = plugins.get(pluginName);
return plugin;
}

Expand All @@ -136,23 +126,18 @@ public static IRed5Plugin getPlugin(String pluginName) {
*/
public static void shutdown() throws Exception {
log.info("Destroying and cleaning up {} plugins", plugins.size());
//loop through the plugins and stop them
pluginReadLock.lock();
try {
for (Entry<String, IRed5Plugin> pluginEntry : plugins.entrySet()) {
IRed5Plugin plugin = pluginEntry.getValue();
try {
plugin.doStop();
} catch (Exception ex) {
if (plugin != null) {
log.warn("Plugin stop failed for: {}", plugin.getName(), ex);
} else {
log.warn("Plugin stop failed", ex);
}
// loop through the plugins and stop them
for (Entry<String, IRed5Plugin> pluginEntry : plugins.entrySet()) {
IRed5Plugin plugin = pluginEntry.getValue();
try {
plugin.doStop();
} catch (Exception ex) {
if (plugin != null) {
log.warn("Plugin stop failed for: {}", plugin.getName(), ex);
} else {
log.warn("Plugin stop failed", ex);
}
}
} finally {
pluginReadLock.unlock();
}
plugins.clear();
}
Expand Down
Loading

0 comments on commit 50a2c33

Please sign in to comment.