[Red5commits] [1602] Service and Scheduling packages documenting is complete. Some minor code improve
mklishin
luke at codegent.com
Wed Jan 24 11:04:03 EST 2007
Service and Scheduling packages documenting is complete. Some minor code improvements, added exception handling to job execution by QuartzSchedulingService?.
Timestamp: 12/25/06 00:40:37 EST (1 month ago)
Change: 1602
Author: mklishin
Files (see diff or trac for details):
java/server/trunk/src/org/red5/server/scheduling/QuartzSchedulingService.java
java/server/trunk/src/org/red5/server/scheduling/QuartzSchedulingServiceJob.java
java/server/trunk/src/org/red5/server/service/Call.java
java/server/trunk/src/org/red5/server/service/ConversionUtils.java
java/server/trunk/src/org/red5/server/service/MethodNotFoundException.java
java/server/trunk/src/org/red5/server/service/PendingCall.java
java/server/trunk/src/org/red5/server/service/ServiceInvoker.java
java/server/trunk/src/org/red5/server/service/ServiceNotFoundException.java
Trac: http://mirror1.cvsdude.com/trac/osflash/red5/changeset/1602
Index: /java/server/trunk/src/org/red5/server/scheduling/QuartzSchedulingServiceJob.java
===================================================================
--- /java/server/trunk/src/org/red5/server/scheduling/QuartzSchedulingServiceJob.java (revision 1597)
+++ /java/server/trunk/src/org/red5/server/scheduling/QuartzSchedulingServiceJob.java (revision 1602)
@@ -20,4 +20,6 @@
*/
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
@@ -33,10 +35,20 @@
*/
public class QuartzSchedulingServiceJob implements Job {
+ /**
+ * Scheduling service constant
+ */
+ protected static final String SCHEDULING_SERVICE = "scheduling_service";
- protected static final String SCHEDULING_SERVICE = "scheduling_service";
+ /**
+ * Scheduled job constant
+ */
+ protected static final String SCHEDULED_JOB = "scheduled_job";
- protected static final String SCHEDULED_JOB = "scheduled_job";
+ /**
+ * Logger
+ */
+ private Log log = LogFactory.getLog( QuartzSchedulingService.class );
- /** {@inheritDoc} */
+ /** {@inheritDoc} */
public void execute(JobExecutionContext arg0) throws JobExecutionException {
ISchedulingService service = (ISchedulingService) arg0.getJobDetail()
@@ -44,6 +56,11 @@
IScheduledJob job = (IScheduledJob) arg0.getJobDetail().getJobDataMap()
.get(SCHEDULED_JOB);
- job.execute(service);
- }
+ try {
+ job.execute(service);
+ } catch (CloneNotSupportedException e) {
+ log.error("Job " + job.toString() + " execution failed, clone not supported.");
+ throw new RuntimeException(e);
+ }
+ }
}
Index: /java/server/trunk/src/org/red5/server/scheduling/QuartzSchedulingService.java
===================================================================
--- /java/server/trunk/src/org/red5/server/scheduling/QuartzSchedulingService.java (revision 1597)
+++ /java/server/trunk/src/org/red5/server/scheduling/QuartzSchedulingService.java (revision 1602)
@@ -20,19 +20,14 @@
*/
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.*;
+import org.quartz.impl.StdSchedulerFactory;
+import org.red5.server.api.scheduling.IScheduledJob;
+import org.red5.server.api.scheduling.ISchedulingService;
+
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.quartz.JobDetail;
-import org.quartz.Scheduler;
-import org.quartz.SchedulerException;
-import org.quartz.SchedulerFactory;
-import org.quartz.SimpleTrigger;
-import org.quartz.Trigger;
-import org.quartz.impl.StdSchedulerFactory;
-import org.red5.server.api.scheduling.IScheduledJob;
-import org.red5.server.api.scheduling.ISchedulingService;
/**
@@ -43,13 +38,24 @@
*/
public class QuartzSchedulingService implements ISchedulingService {
-
+ /**
+ * Logger
+ */
private Log log = LogFactory
.getLog(QuartzSchedulingService.class.getName());
- private static SchedulerFactory schedFact = new StdSchedulerFactory();
+ /**
+ * Creates schedulers
+ */
+ private static SchedulerFactory schedFact = new StdSchedulerFactory();
- private Scheduler scheduler;
+ /**
+ * Service scheduler
+ */
+ private Scheduler scheduler;
- private long jobDetailCounter = 0;
+ /**
+ * Number of job details
+ */
+ private long jobDetailCounter;
/** Constructs a new QuartzSchedulingService. */
@@ -64,7 +70,7 @@
/**
- * Getter for property 'jobName'.
+ * Getter for job name.
*
- * @return Value for property 'jobName'.
+ * @return Job name
*/
private synchronized String getJobName() {
@@ -74,5 +80,13 @@
}
- private void scheduleJob(String name, Trigger trigger, IScheduledJob job) {
+ /**
+ * Schedules job
+ * @param name Job name
+ * @param trigger Job trigger
+ * @param job Scheduled job object
+ *
+ * @see org.red5.server.api.scheduling.IScheduledJob
+ */
+ private void scheduleJob(String name, Trigger trigger, IScheduledJob job) {
// Store reference to applications job and service
JobDetail jobDetail = new JobDetail(name, null,
Index: /java/server/trunk/src/org/red5/server/service/PendingCall.java
===================================================================
--- /java/server/trunk/src/org/red5/server/service/PendingCall.java (revision 1597)
+++ /java/server/trunk/src/org/red5/server/service/PendingCall.java (revision 1602)
@@ -20,32 +20,55 @@
*/
+import org.red5.server.api.service.IPendingServiceCall;
+import org.red5.server.api.service.IPendingServiceCallback;
+
import java.util.HashSet;
import java.util.Set;
-import org.red5.server.api.service.IPendingServiceCall;
-import org.red5.server.api.service.IPendingServiceCallback;
+/**
+ * Pending call is remote call operation that is in pending state. Remote calls to services
+ * are asynchronous, that is, after call but before result callback remote calls are in
+ * pending state.
+ */
+public class PendingCall extends Call implements IPendingServiceCall {
+ /**
+ * Result object
+ */
+ private Object result;
-public class PendingCall extends Call implements IPendingServiceCall {
+ /**
+ * List of callbacks (event listeners)
+ */
+ private HashSet<IPendingServiceCallback> callbacks = new HashSet<IPendingServiceCallback>();
- private Object result = null;
-
- private HashSet<IPendingServiceCallback> callbacks = new HashSet<IPendingServiceCallback>();
-
- public PendingCall(String method) {
+ /**
+ * Creates pending call with given method name
+ * @param method Method name
+ */
+ public PendingCall(String method) {
super(method);
}
+ /**
+ * Creates pending call with given method name and array of parameters
+ * @param method Method name
+ * @param args Parameters
+ */
public PendingCall(String method, Object[] args) {
super(method, args);
}
+ /**
+ * Creates pending call with given method name, service name and array of parametes
+ *
+ * @param name Service name
+ * @param method Method name
+ * @param args Parameters
+ */
public PendingCall(String name, String method, Object[] args) {
super(name, method, args);
}
- /** {@inheritDoc} */ /*
- * (non-Javadoc)
- *
- * @see org.red5.server.service.ServiceCall#getResult()
+ /** {@inheritDoc}
*/
public Object getResult() {
@@ -53,8 +76,5 @@
}
- /** {@inheritDoc} */ /*
- * (non-Javadoc)
- *
- * @see org.red5.server.service.temp#setResult(java.lang.Object)
+ /** {@inheritDoc}
*/
public void setResult(Object result) {
Index: /java/server/trunk/src/org/red5/server/service/ConversionUtils.java
===================================================================
--- /java/server/trunk/src/org/red5/server/service/ConversionUtils.java (revision 1519)
+++ /java/server/trunk/src/org/red5/server/service/ConversionUtils.java (revision 1602)
@@ -19,16 +19,4 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
-import java.text.NumberFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
import org.apache.commons.beanutils.BeanMap;
@@ -40,6 +28,12 @@
import org.red5.server.api.IConnection;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.text.NumberFormat;
+import java.util.*;
+
/**
- *
+ * Misc utils for convertions
+ *
* @author The Red5 Project (red5 at osflash.org)
* @author Luke Hubbard, Codegent Ltd (luke at codegent.com)
@@ -57,5 +51,8 @@
Float.class, Double.class };
- private static final Class[][] PARAMETER_CHAINS = {
+ /**
+ * Parameter chains
+ */
+ private static final Class[][] PARAMETER_CHAINS = {
{ boolean.class, null }, { byte.class, Short.class },
{ char.class, Integer.class }, { short.class, Integer.class },
@@ -87,5 +84,13 @@
}
- public static Object convert(Object source, Class target)
+ /**
+ * Convert source to given class
+ * @param source Source object
+ * @param target Target class
+ * @return Converted object
+ * @throws ConversionException If object can't be converted
+ *
+ */
+ public static Object convert(Object source, Class target)
throws ConversionException {
if (target == null) {
@@ -134,5 +139,12 @@
}
- public static Object convertToArray(Object source, Class target)
+ /**
+ * Convert to array
+ * @param source Source object
+ * @param target Target class
+ * @return Converted object
+ * @throws ConversionException If object can't be converted
+ */
+ public static Object convertToArray(Object source, Class target)
throws ConversionException {
try {
@@ -158,5 +170,11 @@
}
- public static Object convertToWrappedPrimitive(Object source, Class wrapper) {
+ /**
+ * Convert to wrapped primitive
+ * @param source Source object
+ * @param wrapper Primitive wrapper type
+ * @return Converted object
+ */
+ public static Object convertToWrappedPrimitive(Object source, Class wrapper) {
if (source == null || wrapper == null) {
return null;
@@ -175,5 +193,11 @@
}
- public static Object convertStringToWrapper(String str, Class wrapper) {
+ /**
+ * Convert string to primitive wrapper like Boolean or Float
+ * @param str String to convert
+ * @param wrapper Primitive wrapper type
+ * @return Converted object
+ */
+ public static Object convertStringToWrapper(String str, Class wrapper) {
if (wrapper.equals(String.class)) {
return str;
@@ -196,5 +220,11 @@
}
- public static Object convertNumberToWrapper(Number num, Class wrapper) {
+ /**
+ * Convert number to primitive wrapper like Boolean or Float
+ * @param num Number to conver
+ * @param wrapper Primitive wrapper type
+ * @return Converted object
+ */
+ public static Object convertNumberToWrapper(Number num, Class wrapper) {
//XXX Paul: Using valueOf will reduce object creation
if (wrapper.equals(String.class)) {
@@ -218,7 +248,14 @@
}
- public static List findMethodsByNameAndNumParams(Object object,
+ /**
+ * Find method by name and number of parameters
+ * @param object Object to find method on
+ * @param method Method name
+ * @param numParam Number of parameters
+ * @return List of methods that match by name and number of parameters
+ */
+ public static List<Method> findMethodsByNameAndNumParams(Object object,
String method, int numParam) {
- LinkedList list = new LinkedList();
+ LinkedList<Method> list = new LinkedList<Method>();
Method[] methods = object.getClass().getMethods();
for (Method m : methods) {
@@ -239,5 +276,12 @@
}
- public static Object[] convertParams(Object[] source, Class[] target)
+ /**
+ * Convert parameters using methods of this utility class
+ * @param source Array of source object
+ * @param target Array of target classes
+ * @return Array of converted objects
+ * @throws ConversionException If object can't be converted
+ */
+ public static Object[] convertParams(Object[] source, Class[] target)
throws ConversionException {
Object[] converted = new Object[target.length];
@@ -248,5 +292,11 @@
}
- public static List convertArrayToList(Object[] source)
+ /**
+ *
+ * @param source
+ * @return
+ * @throws ConversionException
+ */
+ public static List convertArrayToList(Object[] source)
throws ConversionException {
ArrayList list = new ArrayList(source.length);
@@ -257,5 +307,12 @@
}
- public static Object convertMapToBean(Map source, Class target)
+ /**
+ * Convert map to bean
+ * @param source Source map
+ * @param target Target class
+ * @return Bean of that class
+ * @throws ConversionException
+ */
+ public static Object convertMapToBean(Map source, Class target)
throws ConversionException {
Object bean = newInstance(target.getClass().getName());
@@ -272,9 +329,19 @@
}
- public static Map convertBeanToMap(Object source) {
+ /**
+ * Convert bean to map
+ * @param source Source bean
+ * @return Converted map
+ */
+ public static Map convertBeanToMap(Object source) {
return new BeanMap(source);
}
- public static Set convertArrayToSet(Object[] source) {
+ /**
+ * Convert array to set, removing duplicates
+ * @param source Source array
+ * @return Set
+ */
+ public static Set convertArrayToSet(Object[] source) {
HashSet set = new HashSet();
for (Object element : source) {
@@ -284,8 +351,13 @@
}
- protected static Object newInstance(String className) {
+ /**
+ * Create new class instance
+ * @param className Class name; may not be loaded by JVM yet
+ * @return Instance of given class
+ */
+ protected static Object newInstance(String className) {
Object instance = null;
try {
- Class clazz = Thread.currentThread().getContextClassLoader()
+ Class<?> clazz = Thread.currentThread().getContextClassLoader()
.loadClass(className);
instance = clazz.newInstance();
Index: /java/server/trunk/src/org/red5/server/service/Call.java
===================================================================
--- /java/server/trunk/src/org/red5/server/service/Call.java (revision 1597)
+++ /java/server/trunk/src/org/red5/server/service/Call.java (revision 1602)
@@ -23,4 +23,5 @@
/**
+ * Basic service call (remote call) implementation
*
* @author The Red5 Project (red5 at osflash.org)
@@ -28,43 +29,89 @@
*/
public class Call implements IServiceCall {
-
+ /**
+ * Pending status constant
+ */
public static final byte STATUS_PENDING = 0x01;
-
+ /**
+ * Success result constant
+ */
public static final byte STATUS_SUCCESS_RESULT = 0x02;
-
+ /**
+ * Returned value is null constant
+ */
public static final byte STATUS_SUCCESS_NULL = 0x03;
-
+ /**
+ * Service returns no value constant
+ */
public static final byte STATUS_SUCCESS_VOID = 0x04;
-
+ /**
+ * Service not found constant
+ */
public static final byte STATUS_SERVICE_NOT_FOUND = 0x10;
-
+ /**
+ * Service's method not found constant
+ */
public static final byte STATUS_METHOD_NOT_FOUND = 0x11;
-
+ /**
+ * Access denied constant
+ */
public static final byte STATUS_ACCESS_DENIED = 0x12;
- public static final byte STATUS_INVOCATION_EXCEPTION = 0x13;
-
- public static final byte STATUS_GENERAL_EXCEPTION = 0x14;
-
- protected String serviceName = null;
-
- protected String serviceMethodName = null;
-
+ /**
+ * Exception on invocation constant
+ */
+ public static final byte STATUS_INVOCATION_EXCEPTION = 0x13;
+
+ /**
+ * General exception constant
+ */
+ public static final byte STATUS_GENERAL_EXCEPTION = 0x14;
+
+ /**
+ * Service name
+ */
+ protected String serviceName;
+ /**
+ * Service method name
+ */
+ protected String serviceMethodName;
+ /**
+ * Call arguments
+ */
protected Object[] arguments = null;
-
+ /**
+ * Call status, initial one is pending
+ */
protected byte status = STATUS_PENDING;
-
- protected Exception exception = null;
-
+ /**
+ * Call exception if any, null by default
+ */
+ protected Exception exception;
+
+ /**
+ * Creates call from method name
+ * @param method Method name
+ */
public Call(String method) {
serviceMethodName = method;
}
- public Call(String method, Object[] args) {
+ /**
+ * Creates call from method name and array of call parameters
+ * @param method Method name
+ * @param args Call parameters
+ */
+ public Call(String method, Object[] args) {
serviceMethodName = method;
arguments = args;
}
- public Call(String name, String method, Object[] args) {
+ /**
+ * Creates call from given service name, method name and array of call parameters
+ * @param name Service name
+ * @param method Service method name
+ * @param args Call parameters
+ */
+ public Call(String name, String method, Object[] args) {
serviceName = name;
serviceMethodName = method;
@@ -72,8 +119,6 @@
}
- /** {@inheritDoc} */ /*
- * (non-Javadoc)
- *
- * @see org.red5.server.service.ServiceCall#isSuccess()
+ /**
+ * {@inheritDoc}
*/
public boolean isSuccess() {
@@ -83,8 +128,6 @@
}
- /** {@inheritDoc} */ /*
- * (non-Javadoc)
- *
- * @see org.red5.server.service.ServiceCall#getServiceMethodName()
+ /**
+ * {@inheritDoc}
*/
public String getServiceMethodName() {
@@ -93,7 +136,7 @@
/**
- * Setter for property 'serviceMethodName'.
+ * Setter for service method name
*
- * @param serviceMethodName Value to set for property 'serviceMethodName'.
+ * @param serviceMethodName New service method name value
*/
public void setServiceMethodName(String serviceMethodName) {
@@ -101,8 +144,6 @@
}
- /** {@inheritDoc} */ /*
- * (non-Javadoc)
- *
- * @see org.red5.server.service.ServiceCall#getServiceName()
+ /**
+ * {@inheritDoc}
*/
public String getServiceName() {
@@ -111,7 +152,7 @@
/**
- * Setter for property 'serviceName'.
+ * Setter for service name
*
- * @param serviceName Value to set for property 'serviceName'.
+ * @param serviceName New service name value
*/
public void setServiceName(String serviceName) {
@@ -119,8 +160,6 @@
}
- /** {@inheritDoc} */ /*
- * (non-Javadoc)
- *
- * @see org.red5.server.service.ServiceCall#getArguments()
+ /**
+ * {@inheritDoc}
*/
public Object[] getArguments() {
@@ -129,7 +168,7 @@
/**
- * Setter for property 'arguments'.
+ * Setter for arguments.
*
- * @param args Value to set for property 'arguments'.
+ * @param args Arguments.
*/
public void setArguments(Object[] args) {
@@ -137,8 +176,6 @@
}
- /** {@inheritDoc} */ /*
- * (non-Javadoc)
- *
- * @see org.red5.server.service.ServiceCall#getStatus()
+ /**
+ * {@inheritDoc}
*/
public byte getStatus() {
@@ -146,8 +183,6 @@
}
- /** {@inheritDoc} */ /*
- * (non-Javadoc)
- *
- * @see org.red5.server.service.temp#setStatus(byte)
+ /**
+ * {@inheritDoc}
*/
public void setStatus(byte status) {
@@ -155,8 +190,6 @@
}
- /** {@inheritDoc} */ /*
- * (non-Javadoc)
- *
- * @see org.red5.server.service.ServiceCall#getException()
+ /**
+ * {@inheritDoc}
*/
public Exception getException() {
@@ -164,8 +197,6 @@
}
- /** {@inheritDoc} */ /*
- * (non-Javadoc)
- *
- * @see org.red5.server.service.temp#setException(java.lang.Exception)
+ /**
+ * {@inheritDoc}
*/
public void setException(Exception exception) {
Index: /java/server/trunk/src/org/red5/server/service/MethodNotFoundException.java
===================================================================
--- /java/server/trunk/src/org/red5/server/service/MethodNotFoundException.java (revision 1519)
+++ /java/server/trunk/src/org/red5/server/service/MethodNotFoundException.java (revision 1602)
@@ -21,4 +21,5 @@
/**
+ * Thrown if service method is not found so call throws exception
*
* @author The Red5 Project (red5 at osflash.org)
@@ -32,5 +33,9 @@
private static final long serialVersionUID = 7559230924102506068L;
- public MethodNotFoundException(String methodName) {
+ /**
+ * Creates exception with given method name
+ * @param methodName Service method name that can't be found
+ */
+ public MethodNotFoundException(String methodName) {
super("Method not found: " + methodName);
}
Index: /java/server/trunk/src/org/red5/server/service/ServiceNotFoundException.java
===================================================================
--- /java/server/trunk/src/org/red5/server/service/ServiceNotFoundException.java (revision 1519)
+++ /java/server/trunk/src/org/red5/server/service/ServiceNotFoundException.java (revision 1602)
@@ -21,4 +21,5 @@
/**
+ * Thrown when service can't be found thus remote call throws an exception
*
* @author The Red5 Project (red5 at osflash.org)
@@ -32,5 +33,9 @@
private static final long serialVersionUID = 7543755414829244027L;
- public ServiceNotFoundException(String serviceName) {
+ /**
+ * Creates new exception with service name
+ * @param serviceName Name of service that couldn't been found
+ */
+ public ServiceNotFoundException(String serviceName) {
super("Service not found: " + serviceName);
}
Index: /java/server/trunk/src/org/red5/server/service/ServiceInvoker.java
===================================================================
--- /java/server/trunk/src/org/red5/server/service/ServiceInvoker.java (revision 1597)
+++ /java/server/trunk/src/org/red5/server/service/ServiceInvoker.java (revision 1602)
@@ -19,9 +19,4 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashSet;
-import java.util.Set;
import org.apache.commons.logging.Log;
@@ -34,5 +29,11 @@
import org.red5.server.api.service.IServiceInvoker;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
/**
+ * Makes remote calls, invoking services, resolves service handlers
*
* @author The Red5 Project (red5 at osflash.org)
@@ -41,14 +42,23 @@
public class ServiceInvoker implements IServiceInvoker {
- private static final Log log = LogFactory.getLog(ServiceInvoker.class);
-
- public static final String SERVICE_NAME = "serviceInvoker";
-
- private Set<IServiceResolver> serviceResolvers = new HashSet<IServiceResolver>();
+ /**
+ * Logger
+ */
+ private static final Log log = LogFactory.getLog(ServiceInvoker.class);
+
+ /**
+ * Service name
+ */
+ public static final String SERVICE_NAME = "serviceInvoker";
+
+ /**
+ * Service resolvers set
+ */
+ private Set<IServiceResolver> serviceResolvers = new HashSet<IServiceResolver>();
/**
- * Setter for property 'serviceResolvers'.
+ * Setter for service resolvers.
*
- * @param resolvers Value to set for property 'serviceResolvers'.
+ * @param resolvers Service resolvers
*/
public void setServiceResolvers(Set<IServiceResolver> resolvers) {
@@ -59,7 +69,7 @@
* Lookup a handler for the passed service name in the given scope.
*
- * @param scope
- * @param serviceName
- * @return
+ * @param scope Scope
+ * @param serviceName Service name
+ * @return Service handler
*/
private Object getServiceHandler(IScope scope, String serviceName) {
@@ -91,6 +101,8 @@
Object service = getServiceHandler(scope, serviceName);
if (service == null) {
- call.setException(new ServiceNotFoundException(serviceName));
- call.setStatus(Call.STATUS_SERVICE_NOT_FOUND);
+ // Exception must be thrown if service was not found
+ call.setException(new ServiceNotFoundException(serviceName));
+ // Set call status
+ call.setStatus(Call.STATUS_SERVICE_NOT_FOUND);
log.warn("Service not found: " + serviceName);
return;
@@ -100,5 +112,6 @@
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