Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of the project as part of a computer science course #310

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/main/java/org/red5/logging/ContextLoggingListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ContextLoggingListener implements ServletContextListener {

public void contextInitialized(ServletContextEvent event) {
ServletContext servletContext = event.getServletContext();
String contextName = servletContext.getContextPath().replaceAll("/", "");
String contextName = servletContext.getContextPath().replace("/", "");
if ("".equals(contextName)) {
contextName = "root";
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/red5/logging/DerbyLogInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class DerbyLogInterceptor {

public static OutputStream handleDerbyLogFile() {
return new OutputStream() {

private final String derbyLog = "Derby log: {}";
@Override
public void write(byte[] b) throws IOException {
log.info("Derby log: {}", new String(b));
log.info(derbyLog , new String(b));
}

@Override
Expand All @@ -35,10 +35,10 @@ public void write(int i) throws IOException {
}
//look for LF
if (i == 10) {
log.info("Derby log: {}", sb.toString());
log.info(derbyLog , sb.toString());
sb.delete(0, sb.length() - 1);
} else {
log.trace("Derby log: {}", i);
log.trace(derbyLog, i);
sb.append(new String(intToDWord(i)));
}
local.set(sb);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/red5/logging/LoggerContextFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class LoggerContextFilter implements Filter {

public void init(FilterConfig config) throws ServletException {
ServletContext servletContext = config.getServletContext();
contextName = servletContext.getContextPath().replaceAll("/", "");
contextName = servletContext.getContextPath().replace("/", "");
if ("".equals(contextName)) {
contextName = "root";
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/red5/logging/W3CAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,12 @@ public synchronized void doAppend(LoggingEvent event) {
//app-start application
//app-stop application
//filter based on event type - asterik allows all events
if (!events.equals("*")) {
if (!eventsList.contains(elements.get("x-event"))) {
if ((!events.equals("*")) && (!eventsList.contains(elements.get("x-event"))) {
elements.clear();
elements = null;
sbuf = null;
return;
}
}
//x-category event category
//x-event type of event
//date date at which the event occurred
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/red5/server/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ public void setApplicationContext(ApplicationContext context) {
if (config == null) {
config = "red5.xml";
}
//coreContext = new ClassPathXmlApplicationContext(config).useBeanFactory("red5.core").getFactory();
coreContext = (BeanFactory) new ClassPathXmlApplicationContext(config).getBean("red5.core");
} else {
logger.info("Setting parent bean factory as core");
Expand Down Expand Up @@ -319,7 +318,7 @@ public IScopeHandler lookupScopeHandler(String contextPath) {
String scopeHandlerName = getMappingStrategy().mapScopeHandlerName(contextPath);
// Get bean from bean factory
Object bean = applicationContext.getBean(scopeHandlerName);
if (bean != null && bean instanceof IScopeHandler) {
if (bean instanceof IScopeHandler) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that getBean cannot return a null

return (IScopeHandler) bean;
} else {
throw new ScopeHandlerNotFoundException(scopeHandlerName);
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/org/red5/server/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,16 @@ public class Launcher {
public void launch() throws Exception {
System.out.printf("Root: %s%nDeploy type: %s%n", System.getProperty("red5.root"), System.getProperty("red5.deployment.type"));
// check for the logback disable flag
// and check for context selector in system properties
boolean useLogback = Boolean.valueOf(System.getProperty("useLogback", "true"));
if (useLogback) {
// check for context selector in system properties
if (System.getProperty("logback.ContextSelector") == null) {
if ((useLogback) && (System.getProperty("logback.ContextSelector") == null)) {
// set our selector
System.setProperty("logback.ContextSelector", "org.red5.logging.LoggingContextSelector");
}
}
Red5LoggerFactory.setUseLogback(useLogback);
// install the slf4j bridge (mostly for JUL logging)
SLF4JBridgeHandler.install();
// log stdout and stderr to slf4j
//SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();
// get the first logger
Logger log = Red5LoggerFactory.getLogger(Launcher.class);
// version info banner
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/red5/server/jmx/JMXUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static void printMBeanInfo(ObjectName objectName, String className) {
for (int i = 0; i < notifInfo.length; i++) {
log.info(" ** NAME: \t" + notifInfo[i].getName());
log.info(" DESCR: \t" + notifInfo[i].getDescription());
String notifTypes[] = notifInfo[i].getNotifTypes();
String[] notifTypes = notifInfo[i].getNotifTypes();
for (int j = 0; j < notifTypes.length; j++) {
log.info(" TYPE: \t" + notifTypes[j]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RemotingProtocolDecoder {
* @return a List of {@link RemotingPacket} objects.
*/
public List<Object> decodeBuffer(IoBuffer buffer) {
List<Object> list = new LinkedList<Object>();
List<Object> list = new LinkedList<>();
Object packet = null;
try {
packet = decode(buffer);
Expand Down Expand Up @@ -73,22 +73,21 @@ public Object decode(IoBuffer in) throws Exception {
* Input data as byte buffer
* @return header map
*/
@SuppressWarnings("unchecked")
protected Map<String, Object> readHeaders(IoBuffer in) {
int version = in.getUnsignedShort(); // skip the version
int count = in.getUnsignedShort();
log.debug("Read headers - version: {} count: {}", version, count);
if (count == 0) {
// No headers present
return Collections.EMPTY_MAP;
return Collections.emptyMap();
}
Input input;
if (version == 3) {
input = new org.red5.io.amf3.Input(in);
} else {
input = new org.red5.io.amf.Input(in);
}
Map<String, Object> result = new HashMap<String, Object>();
Map<String, Object> result = new HashMap<>();
for (int i = 0; i < count; i++) {
String name = input.getString();
boolean required = in.get() == 0x01;
Expand All @@ -110,7 +109,7 @@ protected Map<String, Object> readHeaders(IoBuffer in) {
protected List<RemotingCall> decodeCalls(IoBuffer in) {
log.debug("Decode calls");
//in.getInt();
List<RemotingCall> calls = new LinkedList<RemotingCall>();
List<RemotingCall> calls = new LinkedList<>();
org.red5.io.amf.Input input = new org.red5.io.amf.Input(in);
int count = in.getUnsignedShort();
log.debug("Calls: {}", count);
Expand All @@ -124,7 +123,6 @@ protected List<RemotingCall> decodeCalls(IoBuffer in) {
Object[] args = null;
boolean isAMF3 = false;
@SuppressWarnings("unused")
int length = in.getInt();
// Set the limit and deserialize
// NOTE: disabled because the FP sends wrong values here
/*
Expand All @@ -133,7 +131,7 @@ protected List<RemotingCall> decodeCalls(IoBuffer in) {
byte type = in.get();
if (type == AMF.TYPE_ARRAY) {
int elements = in.getInt();
List<Object> values = new ArrayList<Object>();
List<Object> values = new ArrayList<>();
RefStorage refStorage = null;
for (int j = 0; j < elements; j++) {
byte amf3Check = in.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public IoBuffer encode(Object message) throws Exception {
for (IRemotingHeader header : headers) {
Output.putString(buf, IRemotingHeader.PERSISTENT_HEADER);
output.writeBoolean(false);
Map<String, Object> param = new HashMap<String, Object>();
Map<String, Object> param = new HashMap<>();
param.put("name", header.getName());
param.put("mustUnderstand", header.getMustUnderstand() ? Boolean.TRUE : Boolean.FALSE);
param.put("data", header.getValue());
Expand Down Expand Up @@ -145,7 +145,7 @@ protected StatusObject generateErrorResult(String code, Throwable error) {
// Return exception details to client
status.setApplication(((ClientDetailsException) error).getParameters());
if (((ClientDetailsException) error).includeStacktrace()) {
List<String> stack = new ArrayList<String>();
List<String> stack = new ArrayList<>();
for (StackTraceElement element : error.getStackTrace()) {
stack.add(element.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

/**
* Base RTMPT client / session.
*
*
* @author The Red5 Project
* @author Paul Gregoire ([email protected])
*/
Expand Down Expand Up @@ -100,7 +100,7 @@ public BaseRTMPTConnection(String type) {
* the size the resulting buffer should have
* @return a buffer containing the data to send or null if no messages are pending
*/
abstract public IoBuffer getPendingMessages(int targetSize);
public abstract IoBuffer getPendingMessages(int targetSize);

/** {@inheritDoc} */
@Override
Expand Down Expand Up @@ -171,7 +171,7 @@ public List<?> decode(IoBuffer data) {
log.debug("decode");
if (closing || state.getState() == RTMP.STATE_DISCONNECTED) {
// connection is being closed, don't decode any new packets
return Collections.EMPTY_LIST;
return Collections.emptyList();
}
if (log.isTraceEnabled()) {
log.trace("Current bytes read at decode: {}", data.limit());
Expand Down