Skip to content

Commit c40dfa7

Browse files
committed
Refactor codecs, logger, and rtmp client executor. Update spring
1 parent 5e896e7 commit c40dfa7

File tree

29 files changed

+249
-269
lines changed

29 files changed

+249
-269
lines changed

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.red5</groupId>
55
<artifactId>red5-parent</artifactId>
6-
<version>1.3.29</version>
6+
<version>1.3.30</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>red5-client</artifactId>

client/src/main/java/org/red5/client/Red5Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class Red5Client {
1818
/**
1919
* Current server version with revision
2020
*/
21-
public static final String VERSION = "Red5 Client 1.3.29";
21+
public static final String VERSION = "Red5 Client 1.3.30";
2222

2323
/**
2424
* Create a new Red5Client object using the connection local to the current thread A bit of magic that lets you access the red5 scope

client/src/main/java/org/red5/client/net/rtmp/BaseRTMPClientHandler.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.red5.server.stream.consumer.ConnectionConsumer;
5353
import org.slf4j.Logger;
5454
import org.slf4j.LoggerFactory;
55+
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
5556

5657
/**
5758
* Base class for clients (RTMP and RTMPT)
@@ -907,6 +908,15 @@ public void setProtocol(String protocol) throws Exception {
907908
public void setConnection(RTMPConnection conn) {
908909
this.conn = conn;
909910
this.conn.setHandler(this);
911+
if (conn.getExecutor() == null) {
912+
// setup executor
913+
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
914+
executor.setCorePoolSize(1);
915+
executor.setDaemon(true);
916+
executor.setMaxPoolSize(1);
917+
executor.initialize();
918+
conn.setExecutor(executor);
919+
}
910920
}
911921

912922
/**

client/src/main/java/org/red5/client/net/rtmp/RTMPClientConnManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class RTMPClientConnManager implements IConnectionManager<BaseConnection>
4242
private static int executorQueueCapacity = 32;
4343

4444
// whether or not to use the ThreadPoolTaskExecutor for incoming messages
45-
protected static boolean enableTaskExecutor;
45+
protected static boolean enableTaskExecutor = true;
4646

4747
protected static IConnectionManager<BaseConnection> instance;
4848

common/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.red5</groupId>
55
<artifactId>red5-parent</artifactId>
6-
<version>1.3.29</version>
6+
<version>1.3.30</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>red5-server-common</artifactId>
@@ -113,7 +113,7 @@
113113
<dependency>
114114
<groupId>net.engio</groupId>
115115
<artifactId>mbassador</artifactId>
116-
<version>1.3.29</version>
116+
<version>1.3.30</version>
117117
</dependency> -->
118118
<dependency>
119119
<groupId>junit</groupId>

common/src/main/java/org/red5/logging/LoggingContextSelector.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package org.red5.logging;
99

1010
import java.net.URL;
11-
import java.util.ArrayList;
1211
import java.util.List;
1312
import java.util.concurrent.ConcurrentHashMap;
1413
import java.util.concurrent.ConcurrentMap;
@@ -37,7 +36,7 @@ public class LoggingContextSelector implements ContextSelector {
3736

3837
private static final Semaphore lock = new Semaphore(1, true);
3938

40-
private static final ConcurrentMap<String, LoggerContext> contextMap = new ConcurrentHashMap<>(6, 0.9f, 1);
39+
private static final ConcurrentMap<String, LoggerContext> contextMap = new ConcurrentHashMap<>();
4140

4241
private static LoggerContext DEFAULT_CONTEXT;
4342

@@ -194,9 +193,7 @@ public LoggerContext detachLoggerContext(String contextName) {
194193
}
195194

196195
public List<String> getContextNames() {
197-
List<String> list = new ArrayList<>();
198-
list.addAll(contextMap.keySet());
199-
return list;
196+
return List.copyOf(contextMap.keySet());
200197
}
201198

202199
public void setContextConfigFile(String contextConfigFile) {

common/src/main/java/org/red5/logging/Red5LoggerFactory.java

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@ public class Red5LoggerFactory {
2929

3030
public static boolean DEBUG = true;
3131

32+
// root logger
33+
private static Logger rootLogger;
34+
35+
// context selector
36+
private static ContextSelector contextSelector;
37+
3238
static {
3339
DEBUG = Boolean.valueOf(System.getProperty("logback.debug", "false"));
3440
try {
35-
Logger logger = LoggerFactory.getILoggerFactory().getLogger(Logger.ROOT_LOGGER_NAME);
36-
logger.debug("Red5LoggerFactory instanced by Thread: {}", Thread.currentThread().getName());
41+
rootLogger = LoggerFactory.getILoggerFactory().getLogger(Logger.ROOT_LOGGER_NAME);
42+
rootLogger.debug("Red5LoggerFactory instanced by Thread: {}", Thread.currentThread().getName());
43+
rootLogger.debug("Logging context selector: {} impl: {}", System.getProperty("logback.ContextSelector"), getContextSelector());
44+
// get the context selector here
45+
contextSelector = getContextSelector();
3746
} catch (Throwable t) {
3847
t.printStackTrace();
3948
}
@@ -43,7 +52,7 @@ public static Logger getLogger(Class<?> clazz) {
4352
if (DEBUG) {
4453
System.out.printf("getLogger for: %s thread: %s%n", clazz.getName(), Thread.currentThread().getName());
4554
ClassLoader cl = Thread.currentThread().getContextClassLoader();
46-
System.out.printf("class loader: %s%n", cl);
55+
rootLogger.debug("Class loader: {}", cl);
4756
// if cl is WebappClassLoader type we can probably get the context from it
4857
//if (cl instanceof WebappClassLoader) {
4958
// getContextName()
@@ -52,37 +61,22 @@ public static Logger getLogger(Class<?> clazz) {
5261
Logger logger = null;
5362
if (useLogback) {
5463
// determine the red5 app name or servlet context name
55-
String contextName = CoreConstants.DEFAULT_CONTEXT_NAME;
64+
final String threadName = Thread.currentThread().getName();
5665
// route the Launcher entries to the correct context
57-
String[] parts = Thread.currentThread().getName().split("Loader:/");
58-
if (parts.length > 1) {
59-
contextName = parts[1];
66+
if (threadName.startsWith("Loader:/")) {
67+
String contextName = threadName.split("Loader:/")[1];
68+
logger = getLogger(clazz, contextName);
69+
} else {
70+
logger = getLogger(clazz, CoreConstants.DEFAULT_CONTEXT_NAME);
6071
}
61-
logger = Red5LoggerFactory.getLogger(clazz, contextName);
62-
/*
63-
* // get a reference to our caller Class caller = Thread.currentThread().getStackTrace()[2].getClassName(); if (DEBUG) { System.out.printf("Caller class: %s classloader: %s%n",
64-
* caller, caller.getClassLoader()); } // if the incoming class extends StatefulScopeWrappingAdapter we lookup the context by scope name boolean scopeAware =
65-
* StatefulScopeWrappingAdapter.class.isAssignableFrom(caller); if (DEBUG) { System.out.printf("scopeAware: %s%n", scopeAware); } if (scopeAware) { try { Class wrapper = null; if
66-
* ((wrapper = caller.asSubclass(StatefulScopeWrappingAdapter.class)) != null) { Method getScope = wrapper.getMethod("getScope", new Class[0]); // NPE will occur here if the scope
67-
* is not yet set on the application adapter IScope scope = (IScope) getScope.invoke(null, new Object[0]); if (DEBUG) { System.out.printf("scope: %s%n", scope); } contextName =
68-
* scope.getName(); } } catch (Exception cce) { //cclog.warn("Exception {}", e); } } else { // if the incoming class is a servlet we lookup the context name boolean
69-
* servletScopeAware = Servlet.class.isAssignableFrom(caller); if (DEBUG) { System.out.printf("servletScopeAware: %s%n", servletScopeAware); } if (servletScopeAware) { try { Class
70-
* wrapper = null; if ((wrapper = caller.asSubclass(Servlet.class)) != null) { //ServletConfig getServletConfig Method getServletConfig = wrapper.getMethod("getServletConfig", new
71-
* Class[0]); // NPE will occur here if the scope is not yet set on the application adapter ServletConfig config = (ServletConfig) getServletConfig.invoke(null, new Object[0]); if
72-
* (DEBUG) { System.out.printf("config: %s%n", config); } contextName = config.getServletContext().getContextPath().replaceAll("/", ""); if ("".equals(contextName)) { contextName =
73-
* "root"; } } } catch (Exception cce) { //cclog.warn("Exception {}", e); } } else { // route the Launcher entries to the correct context String[] parts =
74-
* Thread.currentThread().getName().split("Loader:/"); if (parts.length > 1) { contextName = parts[1]; } else { contextName = CoreConstants.DEFAULT_CONTEXT_NAME; } } } logger =
75-
* Red5LoggerFactory.getLogger(clazz, contextName);
76-
*/
7772
}
7873
if (logger == null) {
7974
logger = LoggerFactory.getLogger(clazz);
8075
}
8176
return logger;
8277
}
8378

84-
@SuppressWarnings({ "rawtypes" })
85-
public static Logger getLogger(Class clazz, String contextName) {
79+
public static Logger getLogger(Class<?> clazz, String contextName) {
8680
return getLogger(clazz.getName(), contextName);
8781
}
8882

@@ -97,22 +91,22 @@ public static Logger getLogger(String name, String contextName) {
9791
contextName = CoreConstants.DEFAULT_CONTEXT_NAME;
9892
}
9993
try {
100-
ContextSelector selector = Red5LoggerFactory.getContextSelector();
10194
// get the context for the given context name or default if null
102-
LoggerContext context = selector.getLoggerContext(contextName);
95+
LoggerContext context = contextSelector.getLoggerContext(contextName);
10396
// and if we get here, fall back to the default context
10497
if (context == null) {
10598
System.err.printf("No context named %s was found!!%n", contextName);
10699
}
107100
// get the logger from the context or default context
108101
if (context != null) {
109102
logger = context.getLogger(name);
110-
// System.out.printf("Application name: %s in context: %s%n", context.getProperty(KEY_APP_NAME), contextName);
103+
if (DEBUG) {
104+
rootLogger.debug("Application name: {} in context: {}", context.getProperty(CoreConstants.CONTEXT_NAME_KEY), contextName);
105+
}
111106
}
112107
} catch (Exception e) {
113108
// no logback, use whatever logger is in-place
114-
System.err.printf("Exception %s%n", e.getMessage());
115-
e.printStackTrace();
109+
rootLogger.error("Exception {}", e);
116110
}
117111
}
118112
if (logger == null) {
@@ -122,26 +116,26 @@ public static Logger getLogger(String name, String contextName) {
122116
}
123117

124118
public static ContextSelector getContextSelector() {
119+
ContextSelector selector = null;
125120
if (useLogback) {
126121
ContextSelectorStaticBinder contextSelectorBinder = ContextSelectorStaticBinder.getSingleton();
127-
ContextSelector selector = contextSelectorBinder.getContextSelector();
122+
selector = contextSelectorBinder.getContextSelector();
128123
if (selector == null) {
129124
if (DEBUG) {
130-
System.err.println("Context selector was null, creating default context");
125+
rootLogger.error("Context selector was null, creating default context");
131126
}
132127
LoggerContext defaultLoggerContext = new LoggerContext();
133128
defaultLoggerContext.setName(CoreConstants.DEFAULT_CONTEXT_NAME);
134129
try {
135130
contextSelectorBinder.init(defaultLoggerContext, null);
136131
selector = contextSelectorBinder.getContextSelector();
132+
rootLogger.debug("Context selector: {}", selector.getClass().getName());
137133
} catch (Exception e) {
138-
e.printStackTrace();
134+
rootLogger.error("Exception {}", e);
139135
}
140136
}
141-
//System.out.printf("Context selector: %s%n", selector.getClass().getName());
142-
return selector;
143137
}
144-
return null;
138+
return selector;
145139
}
146140

147141
public static void setUseLogback(boolean useLogback) {

common/src/main/java/org/red5/server/api/Red5.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public final class Red5 {
5757
/**
5858
* Server version with revision
5959
*/
60-
public static final String VERSION = "Red5 Server 1.3.29";
60+
public static final String VERSION = "Red5 Server 1.3.30";
6161

6262
/**
6363
* Server version for fmsVer requests
6464
*/
65-
public static final String FMS_VERSION = "RED5/1,3,29,0";
65+
public static final String FMS_VERSION = "RED5/1,3,30,0";
6666

6767
/**
6868
* Server capabilities

common/src/main/java/org/red5/server/net/rtmp/RTMPConnection.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,10 +1483,9 @@ public void onSuccess(Packet packet) {
14831483
}
14841484
log.info("Rejected task: {}", task);
14851485
} catch (Throwable e) {
1486-
log.error("Incoming message failed task: {}", task, e);
1486+
log.warn("Incoming message failed task: {}", task, e);
14871487
if (isDebug) {
1488-
log.debug("Execution rejected on {} - {}", getSessionId(), RTMP.states[getStateCode()]);
1489-
log.debug("Lock permits - decode: {} encode: {}", decoderLock.availablePermits(), encoderLock.availablePermits());
1488+
log.debug("Execution rejected on {} - {} lock permits - decode: {} encode: {}", getSessionId(), RTMP.states[getStateCode()], decoderLock.availablePermits(), encoderLock.availablePermits());
14901489
}
14911490
}
14921491
}

0 commit comments

Comments
 (0)