[Red5commits] [866] persistence stores shouldn't depend on IScope but on ResourcePatternResolver?
jbauch
luke at codegent.com
Tue Jun 20 04:06:01 EDT 2006
persistence stores shouldn't depend on IScope but on ResourcePatternResolver?
Timestamp: 05/27/06 02:15:49 (4 weeks ago)
Change: 866
Author: jbauch
Files (see diff or trac for details):
java/server/trunk/src/org/red5/server/BasicScope.java
java/server/trunk/src/org/red5/server/Client.java
java/server/trunk/src/org/red5/server/GlobalScope.java
java/server/trunk/src/org/red5/server/api/ScopeUtils.java
java/server/trunk/src/org/red5/server/api/persistence/PersistenceUtils.java
java/server/trunk/src/org/red5/server/persistence/FilePersistence.java
java/server/trunk/src/org/red5/server/persistence/RamPersistence.java
java/server/trunk/src/org/red5/server/so/SharedObjectService.java
Trac: http://mirror1.cvsdude.com/trac/osflash/red5/changeset/866
Index: /java/server/trunk/src/org/red5/server/so/SharedObjectService.java
===================================================================
--- /java/server/trunk/src/org/red5/server/so/SharedObjectService.java (revision 864)
+++ /java/server/trunk/src/org/red5/server/so/SharedObjectService.java (revision 866)
@@ -9,9 +9,9 @@
import org.red5.server.api.IBasicScope;
import org.red5.server.api.IScope;
-import org.red5.server.api.ScopeUtils;
import org.red5.server.api.so.ISharedObject;
import org.red5.server.api.so.ISharedObjectService;
import org.red5.server.api.persistence.IPersistable;
import org.red5.server.api.persistence.IPersistenceStore;
+import org.red5.server.api.persistence.PersistenceUtils;
import org.red5.server.persistence.RamPersistence;
@@ -45,5 +45,5 @@
if (!scope.hasAttribute(SO_PERSISTENCE_STORE)) {
try {
- store = ScopeUtils.getPersistenceStore(scope, persistenceClassName);
+ store = PersistenceUtils.getPersistenceStore(scope, persistenceClassName);
log.info("Created persistence store " + store + " for shared objects.");
} catch (Exception err) {
Index: /java/server/trunk/src/org/red5/server/persistence/FilePersistence.java
===================================================================
--- /java/server/trunk/src/org/red5/server/persistence/FilePersistence.java (revision 864)
+++ /java/server/trunk/src/org/red5/server/persistence/FilePersistence.java (revision 866)
@@ -21,4 +21,5 @@
import org.red5.server.net.servlet.ServletUtils;
import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.ResourcePatternResolver;
/**
@@ -36,4 +37,8 @@
private String extension = ".red5";
+ public FilePersistence(ResourcePatternResolver resolver) {
+ super(resolver);
+ }
+
public FilePersistence(IScope scope) {
super(scope);
@@ -69,5 +74,5 @@
private IPersistable doLoad(String name, IPersistable object) {
IPersistable result = object;
- Resource data = ScopeUtils.findApplication(scope).getResource(name);
+ Resource data = resources.getResource(name);
if (data == null || !data.exists())
// No such file
@@ -182,5 +187,5 @@
private boolean saveObject(IPersistable object) {
String path = getObjectFilepath(object);
- Resource resPath = ScopeUtils.findApplication(scope).getResource(path);
+ Resource resPath = resources.getResource(path);
File file;
try {
@@ -197,5 +202,5 @@
String filename = getObjectFilename(object);
- Resource resFile = ScopeUtils.findApplication(scope).getResource(filename);
+ Resource resFile = resources.getResource(filename);
try {
ByteBuffer buf = ByteBuffer.allocate(1024);
@@ -231,5 +236,5 @@
String filename = path + "/" + name + extension;
- Resource resFile = ScopeUtils.findApplication(scope).getResource(filename);
+ Resource resFile = resources.getResource(filename);
if (!resFile.exists())
// File already deleted
Index: /java/server/trunk/src/org/red5/server/persistence/RamPersistence.java
===================================================================
--- /java/server/trunk/src/org/red5/server/persistence/RamPersistence.java (revision 862)
+++ /java/server/trunk/src/org/red5/server/persistence/RamPersistence.java (revision 866)
@@ -6,6 +6,9 @@
import org.red5.server.api.IScope;
+import org.red5.server.api.ScopeUtils;
import org.red5.server.api.persistence.IPersistable;
import org.red5.server.api.persistence.IPersistenceStore;
+
+import org.springframework.core.io.support.ResourcePatternResolver;
/**
@@ -21,8 +24,12 @@
protected static final String PERSISTENCE_NO_NAME = "__null__";
protected Map<String, IPersistable> objects = new HashMap<String, IPersistable>();
- protected IScope scope;
+ protected ResourcePatternResolver resources;
+
+ public RamPersistence(ResourcePatternResolver resources) {
+ this.resources = resources;
+ }
public RamPersistence(IScope scope) {
- this.scope = scope;
+ this((ResourcePatternResolver) ScopeUtils.findApplication(scope));
}
Index: /java/server/trunk/src/org/red5/server/BasicScope.java
===================================================================
--- /java/server/trunk/src/org/red5/server/BasicScope.java (revision 864)
+++ /java/server/trunk/src/org/red5/server/BasicScope.java (revision 866)
@@ -10,4 +10,5 @@
import org.red5.server.api.event.IEvent;
import org.red5.server.api.event.IEventListener;
+import org.red5.server.api.persistence.PersistenceUtils;
public class BasicScope extends PersistableAttributeStore implements IBasicScope {
@@ -26,5 +27,5 @@
this.persistenceClass = persistenceClass;
if (persistenceClass != null)
- setStore(ScopeUtils.getPersistenceStore(this, persistenceClass));
+ setStore(PersistenceUtils.getPersistenceStore(this, persistenceClass));
else
setStore(null);
Index: /java/server/trunk/src/org/red5/server/Client.java
===================================================================
--- /java/server/trunk/src/org/red5/server/Client.java (revision 722)
+++ /java/server/trunk/src/org/red5/server/Client.java (revision 866)
@@ -9,8 +9,9 @@
import org.apache.commons.logging.LogFactory;
import org.red5.server.api.IConnection;
+import org.red5.server.api.IClient;
import org.red5.server.api.IScope;
public class Client extends AttributeStore
- implements org.red5.server.api.IClient {
+ implements IClient {
protected static Log log =
Index: /java/server/trunk/src/org/red5/server/api/persistence/PersistenceUtils.java
===================================================================
--- /java/server/trunk/src/org/red5/server/api/persistence/PersistenceUtils.java (revision 866)
+++ /java/server/trunk/src/org/red5/server/api/persistence/PersistenceUtils.java (revision 866)
@@ -0,0 +1,74 @@
+package org.red5.server.api.persistence;
+
+/*
+ * RED5 Open Source Flash Server - http://www.osflash.org/red5
+ *
+ * Copyright © 2006 by respective authors (see below). All rights reserved.
+ *
+ * This library 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 2.1 of the License, or (at your option) any later
+ * version.
+ *
+ * This library 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 this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+import java.lang.reflect.Constructor;
+
+import org.springframework.core.io.support.ResourcePatternResolver;
+
+/**
+ * Helper class for persistence.
+ *
+ * @author The Red5 Project (red5 at osflash.org)
+ * @author Joachim Bauch (jojo at struktur.de)
+ */
+
+public class PersistenceUtils {
+
+ private static Constructor getPersistenceStoreConstructor(Class theClass, Class[] interfaces) throws Exception {
+ Constructor constructor = null;
+ for (Class interfaceClass : interfaces) {
+ try {
+ constructor = theClass.getConstructor(new Class[]{interfaceClass});
+ } catch (NoSuchMethodException err) {
+ // Ignore this error
+ }
+ if (constructor != null)
+ break;
+
+ constructor = getPersistenceStoreConstructor(theClass, interfaceClass.getInterfaces());
+ if (constructor != null)
+ break;
+ }
+ return constructor;
+ }
+
+ public static IPersistenceStore getPersistenceStore(ResourcePatternResolver resolver, String className) throws Exception {
+ Class persistenceClass = Class.forName(className);
+ Constructor constructor = getPersistenceStoreConstructor(persistenceClass, resolver.getClass().getInterfaces());
+ if (constructor == null) {
+ // Search in superclasses of the object.
+ Class superClass = resolver.getClass().getSuperclass();
+ while (superClass != null) {
+ constructor = getPersistenceStoreConstructor(persistenceClass, superClass.getInterfaces());
+ if (constructor != null)
+ break;
+
+ superClass = superClass.getSuperclass();
+ }
+ }
+
+ if (constructor == null)
+ throw new NoSuchMethodException();
+
+ return (IPersistenceStore) constructor.newInstance(new Object[]{resolver});
+ }
+
+}
Index: /java/server/trunk/src/org/red5/server/api/ScopeUtils.java
===================================================================
--- /java/server/trunk/src/org/red5/server/api/ScopeUtils.java (revision 864)
+++ /java/server/trunk/src/org/red5/server/api/ScopeUtils.java (revision 866)
@@ -1,8 +1,5 @@
package org.red5.server.api;
-import java.lang.reflect.Constructor;
-
import org.red5.server.api.persistence.IPersistable;
-import org.red5.server.api.persistence.IPersistenceStore;
import org.springframework.context.ApplicationContext;
@@ -114,42 +111,3 @@
}
- private static Constructor getPersistenceStoreConstructor(Class theClass, Class[] interfaces) throws Exception {
- Constructor constructor = null;
- for (Class interfaceClass : interfaces) {
- try {
- constructor = theClass.getConstructor(new Class[]{interfaceClass});
- } catch (NoSuchMethodException err) {
- // Ignore this error
- }
- if (constructor != null)
- break;
-
- constructor = getPersistenceStoreConstructor(theClass, interfaceClass.getInterfaces());
- if (constructor != null)
- break;
- }
- return constructor;
- }
-
- public static IPersistenceStore getPersistenceStore(IBasicScope scope, String className) throws Exception {
- Class persistenceClass = Class.forName(className);
- Constructor constructor = getPersistenceStoreConstructor(persistenceClass, scope.getClass().getInterfaces());
- if (constructor == null) {
- // Search in superclasses of the scope.
- Class superClass = scope.getClass().getSuperclass();
- while (superClass != null) {
- constructor = getPersistenceStoreConstructor(persistenceClass, superClass.getInterfaces());
- if (constructor != null)
- break;
-
- superClass = superClass.getSuperclass();
- }
- }
-
- if (constructor == null)
- throw new NoSuchMethodException();
-
- return (IPersistenceStore) constructor.newInstance(new Object[]{scope});
- }
-
}
Index: /java/server/trunk/src/org/red5/server/GlobalScope.java
===================================================================
--- /java/server/trunk/src/org/red5/server/GlobalScope.java (revision 864)
+++ /java/server/trunk/src/org/red5/server/GlobalScope.java (revision 866)
@@ -3,6 +3,6 @@
import org.red5.server.api.IGlobalScope;
import org.red5.server.api.IServer;
-import org.red5.server.api.ScopeUtils;
import org.red5.server.api.persistence.IPersistenceStore;
+import org.red5.server.api.persistence.PersistenceUtils;
public class GlobalScope extends Scope implements IGlobalScope {
@@ -21,5 +21,5 @@
try {
- store = ScopeUtils.getPersistenceStore(this, this.persistenceClass);
+ store = PersistenceUtils.getPersistenceStore(this, this.persistenceClass);
} catch (Exception error) {
log.error("Could not create persistence store.", error);
Note:
Diffs are chopped if more than 30k.
This is to get past the limit on the mailing list.
More information about the Red5commits
mailing list