[Red5commits] [2163] added initial methods to uninitialize webscopes
jbauch
luke at codegent.com
Wed Jul 4 15:50:10 EDT 2007
added initial methods to uninitialize webscopes
Timestamp: 07/04/07 14:41:42 EST (less than one hour ago)
Change: 2163
Author: jbauch
Files (see diff or trac for details):
java/server/trunk/src/org/red5/server/Scope.java
java/server/trunk/src/org/red5/server/WebScope.java
Trac: http://mirror1.cvsdude.com/trac/osflash/red5/changeset/2163
Index: /java/server/trunk/src/org/red5/server/WebScope.java
===================================================================
--- /java/server/trunk/src/org/red5/server/WebScope.java (revision 2084)
+++ /java/server/trunk/src/org/red5/server/WebScope.java (revision 2163)
@@ -20,8 +20,11 @@
*/
+import java.util.Iterator;
+
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.red5.server.api.IConnection;
import org.red5.server.api.IGlobalScope;
import org.red5.server.api.IServer;
@@ -29,11 +32,14 @@
/**
- * Web scope is special scope that is aware of servlet context and
- * represents scope of Red5 application in servlet container (or application server) like Tomcat, Jetty or JBoss.
+ * Web scope is special scope that is aware of servlet context and represents
+ * scope of Red5 application in servlet container (or application server)
+ * like Tomcat, Jetty or JBoss.
*
- * Web scope is aware of virtual hosts configuration for Red5 application and is the first scope that instantiated
- * after Red5 application got started.
- * Then it loads virtual hosts configuration, adds mappings of paths to global scope that is injected thru Spring
- * IoC context file and runs initialization process.
+ * Web scope is aware of virtual hosts configuration for Red5 application and is
+ * the first scope that instantiated after Red5 application got started.
+ *
+ * Then it loads virtual hosts configuration, adds mappings of paths to global
+ * scope that is injected thru Spring IoC context file and runs initialization
+ * process.
*
* Red5 server implementation instance and ServletContext are injected as well.
@@ -66,4 +72,9 @@
protected String[] hostnames;
+ /**
+ * Has the web scope been registered?
+ */
+ protected boolean registered;
+
/**
* Setter for global scope. Sets persistence class.
@@ -138,7 +149,12 @@
/**
- * Map all vhosts to global scope then initialize
- */
- public void register() {
+ * Map all vhosts to global scope then initialize
+ */
+ public synchronized void register() {
+ if (registered) {
+ // Already registered
+ return;
+ }
+
if (hostnames != null && hostnames.length > 0) {
for (String element : hostnames) {
@@ -149,4 +165,35 @@
// We don't want to have configured scopes to get freed when a client disconnects.
keepOnDisconnect = true;
+ registered = true;
+ }
+
+ /**
+ * Uninitialize and remove all vhosts from the global scope.
+ */
+ public synchronized void unregister() {
+ if (!registered) {
+ // Not registered
+ return;
+ }
+
+ keepOnDisconnect = false;
+ // We need to disconnect all clients before unregistering
+ Iterator<IConnection> iter = getConnections();
+ while (iter.hasNext()) {
+ IConnection conn = iter.next();
+ conn.close();
+ }
+ uninit();
+ if (hostnames != null && hostnames.length > 0) {
+ for (String element : hostnames) {
+ server.removeMapping(element, getName());
+ }
+ }
+ // Various cleanup tasks
+ setStore(null);
+ super.setParent(null);
+ setServletContext(null);
+ setServer(null);
+ registered = false;
}
Index: /java/server/trunk/src/org/red5/server/Scope.java
===================================================================
--- /java/server/trunk/src/org/red5/server/Scope.java (revision 2140)
+++ /java/server/trunk/src/org/red5/server/Scope.java (revision 2163)
@@ -865,4 +865,16 @@
/**
+ * Uninitialize scope and unregister from parent.
+ */
+ public void uninit() {
+ stop();
+ if (hasParent()) {
+ if (parent.hasChildScope(name)) {
+ parent.removeChildScope(this);
+ }
+ }
+ }
+
+ /**
* Check if scope is enabled
* @return <code>true</code> if scope is enabled, <code>false</code> otherwise
@@ -1025,6 +1037,24 @@
* @return <code>true</code> if scope has handler and it's start method returned true, <code>false</code> otherwise
*/
- public boolean start() {
- return enabled && !running && !(hasHandler() && !handler.start(this));
+ public synchronized boolean start() {
+ boolean result = false;
+ if (enabled && !running) {
+ if (hasHandler()) {
+ // Only start if scope handler allows it
+ try {
+ result = handler.start(this);
+ } catch (Throwable e) {
+ log.error("Could not start scope " + this, e);
+ }
+ } else {
+ // Always start scopes without handlers
+ if (log.isDebugEnabled()) {
+ log.debug("Scope " + this + " has no handler, allowing start.");
+ }
+ result = true;
+ }
+ running = result;
+ }
+ return result;
}
@@ -1032,5 +1062,13 @@
* Stops scope
*/
- public void stop() {
+ public synchronized void stop() {
+ if (enabled && running && hasHandler()) {
+ try {
+ handler.stop(this);
+ } catch (Throwable e) {
+ log.error("Could not stop scope " + this, e);
+ }
+ }
+ running = false;
}
Note:
Diffs are chopped if more than 25k.
This is to get past the limit on the mailing list.
More information about the Red5commits
mailing list