[gogoego] r3698 committed - init commit

8 views
Skip to first unread message

codesite...@google.com

unread,
May 15, 2010, 4:05:43 PM5/15/10
to gog...@googlegroups.com
Revision: 3698
Author: carl....@solertium.com
Date: Sat May 15 13:03:00 2010
Log: init commit
http://code.google.com/p/gogoego/source/detail?r=3698

Added:
/trunk/modules/com.solertium.util.scheduling/.classpath
/trunk/modules/com.solertium.util.scheduling/.project
/trunk/modules/com.solertium.util.scheduling/.settings

/trunk/modules/com.solertium.util.scheduling/.settings/org.eclipse.jdt.core.prefs
/trunk/modules/com.solertium.util.scheduling/META-INF
/trunk/modules/com.solertium.util.scheduling/META-INF/MANIFEST.MF
/trunk/modules/com.solertium.util.scheduling/build.properties
/trunk/modules/com.solertium.util.scheduling/src
/trunk/modules/com.solertium.util.scheduling/src/com
/trunk/modules/com.solertium.util.scheduling/src/com/solertium
/trunk/modules/com.solertium.util.scheduling/src/com/solertium/util

/trunk/modules/com.solertium.util.scheduling/src/com/solertium/util/scheduling

/trunk/modules/com.solertium.util.scheduling/src/com/solertium/util/scheduling/BasicOSGiSchedulerProperties.java

/trunk/modules/com.solertium.util.scheduling/src/com/solertium/util/scheduling/OSGiScheduler.java

/trunk/modules/com.solertium.util.scheduling/src/com/solertium/util/scheduling/OSGiSchedulerFactory.java

=======================================
--- /dev/null
+++ /trunk/modules/com.solertium.util.scheduling/.classpath Sat May 15
13:03:00 2010
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
=======================================
--- /dev/null
+++ /trunk/modules/com.solertium.util.scheduling/.project Sat May 15
13:03:00 2010
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>com.solertium.util.scheduling</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
=======================================
--- /dev/null
+++
/trunk/modules/com.solertium.util.scheduling/.settings/org.eclipse.jdt.core.prefs
Sat May 15 13:03:00 2010
@@ -0,0 +1,7 @@
+#Sat May 15 14:26:38 EDT 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
=======================================
--- /dev/null
+++ /trunk/modules/com.solertium.util.scheduling/META-INF/MANIFEST.MF Sat
May 15 13:03:00 2010
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Quartz Scheduler Connector
+Bundle-SymbolicName: com.solertium.util.scheduling
+Bundle-Version: 1.0.0
+Bundle-Vendor: SOLERTIUM
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.quartz_1.6.0;bundle-version="1.0.0"
+Import-Package: com.solertium.util
+Export-Package: com.solertium.util.scheduling
=======================================
--- /dev/null
+++ /trunk/modules/com.solertium.util.scheduling/build.properties Sat May
15 13:03:00 2010
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
=======================================
--- /dev/null
+++
/trunk/modules/com.solertium.util.scheduling/src/com/solertium/util/scheduling/BasicOSGiSchedulerProperties.java
Sat May 15 13:03:00 2010
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2007-2009 Solertium Corporation
+ *
+ * This file is part of the open source GoGoEgo project.
+ *
+ * Unless you have been granted a different license in writing by the
+ * copyright holders for GoGoEgo, you may only modify or redistribute
+ * this code under the terms of one of the following licenses:
+ *
+ * 1) The Eclipse Public License, v.1.0
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * 2) The GNU General Public License, version 2 or later
+ * http://www.gnu.org/licenses
+ */
+package com.solertium.util.scheduling;
+
+import java.util.Properties;
+
+/**
+ * BasicOSGiSchedulerProperties.java
+ *
+ * These properties should work under GoGoEgo. Feel
+ * free to override them in your implementation, but
+ * this should get you started.
+ *
+ * @author carl.scott <carl....@solertium.com>
+ *
+ */
+public class BasicOSGiSchedulerProperties extends Properties {
+
+ private static final long serialVersionUID = 1L;
+
+ public BasicOSGiSchedulerProperties() {
+ super();
+
setProperty("org.quartz.scheduler.instanceName", "DefaultQuartzScheduler");
+ setProperty("org.quartz.scheduler.rmi.export", "false");
+ setProperty("org.quartz.scheduler.rmi.proxy", "false");
+
setProperty("org.quartz.scheduler.wrapJobExecutionInUserTransaction", "false");
+
setProperty("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
+ setProperty("org.quartz.threadPool.threadCount", "10");
+ setProperty("org.quartz.threadPool.threadPriority", "5");
+
setProperty("org.quartz.threadPool.threadInheritsContextClassLoaderOfInitializingThread", "true");
+ setProperty("org.quartz.jobStore.misfireThreshold", "60000");
+ setProperty("org.quartz.jobStore.class", "org.quartz.simpl.RAMJobStore");
+ }
+
+}
=======================================
--- /dev/null
+++
/trunk/modules/com.solertium.util.scheduling/src/com/solertium/util/scheduling/OSGiScheduler.java
Sat May 15 13:03:00 2010
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2007-2009 Solertium Corporation
+ *
+ * This file is part of the open source GoGoEgo project.
+ *
+ * Unless you have been granted a different license in writing by the
+ * copyright holders for GoGoEgo, you may only modify or redistribute
+ * this code under the terms of one of the following licenses:
+ *
+ * 1) The Eclipse Public License, v.1.0
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * 2) The GNU General Public License, version 2 or later
+ * http://www.gnu.org/licenses
+ */
+package com.solertium.util.scheduling;
+
+import java.util.Properties;
+
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.SchedulerFactory;
+import org.quartz.Trigger;
+
+import com.solertium.util.TrivialExceptionHandler;
+
+/**
+ * OSGiScheduler.java
+ *
+ * Use this as the foundation for a scheduler for your application.
+ *
+ * @author carl.scott <carl....@solertium.com>
+ *
+ */
+public class OSGiScheduler {
+
+ private Scheduler scheduler = null;
+ private SchedulerFactory factory = null;
+
+ private boolean isInit;
+
+ public OSGiScheduler() {
+ this(new BasicOSGiSchedulerProperties());
+ }
+
+ public OSGiScheduler(Properties properties) {
+ isInit = false;
+ try {
+ init(properties);
+ isInit = true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ TrivialExceptionHandler.ignore(this, e);
+ }
+ }
+
+ private void init(Properties properties) throws SchedulerException {
+ try {
+ factory = new OSGiSchedulerFactory(properties);
+ scheduler = factory.getScheduler();
+ scheduler.start();
+ } catch (SchedulerException e) {
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ TrivialExceptionHandler.ignore(this, e);
+ }
+ }
+
+ public boolean isInit() {
+ return isInit;
+ }
+
+ public boolean scheduleJob(final JobDetail jobDetail, final Trigger
trigger) throws SchedulerException {
+ try {
+ scheduler.unscheduleJob(trigger.getName(), trigger.getGroup());
+ } catch (Throwable e) {
+ TrivialExceptionHandler.ignore(this, e);
+ }
+
+ final boolean isScheduled;
+ if (isScheduled = (scheduler != null && scheduler.isStarted()))
+ scheduler.scheduleJob(jobDetail, trigger);
+
+ return isScheduled;
+ }
+
+}
=======================================
--- /dev/null
+++
/trunk/modules/com.solertium.util.scheduling/src/com/solertium/util/scheduling/OSGiSchedulerFactory.java
Sat May 15 13:03:00 2010
@@ -0,0 +1,323 @@
+/*
+ * Copyright 2004-2005 OpenSymphony
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy
+ * of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package com.solertium.util.scheduling;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Properties;
+
+import org.quartz.Scheduler;
+import org.quartz.SchedulerConfigException;
+import org.quartz.SchedulerException;
+import org.quartz.core.JobRunShellFactory;
+import org.quartz.core.QuartzScheduler;
+import org.quartz.core.QuartzSchedulerResources;
+import org.quartz.core.SchedulingContext;
+import org.quartz.ee.jta.UserTransactionHelper;
+import org.quartz.impl.SchedulerRepository;
+import org.quartz.impl.StdJobRunShellFactory;
+import org.quartz.impl.StdSchedulerFactory;
+import org.quartz.simpl.PropertySettingJobFactory;
+import org.quartz.simpl.RAMJobStore;
+import org.quartz.simpl.SimpleClassLoadHelper;
+import org.quartz.simpl.SimpleThreadPool;
+import org.quartz.utils.PropertiesParser;
+
+/**
+ * OSGiSchedulerFactory.java
+ *
+ * This version of the StdSchedulerFactory removes any
+ * functionality that won't work in the current GoGoEgo/
+ * OSGi framework, such as reflection, and trims down to
+ * basic functionality that most systems can use.
+ *
+ * @author carl.scott <carl....@solertium.com>
+ *
+ */
+public class OSGiSchedulerFactory extends StdSchedulerFactory {
+
+ private SchedulerException initException = null;
+ private String propSrc = null;
+ private PropertiesParser cfg;
+
+ public OSGiSchedulerFactory(Properties props) throws SchedulerException {
+ initialize(props);
+ }
+
+ /**
+ * <p>
+ * Initialize the <code>{@link org.quartz.SchedulerFactory}</code> with
the
+ * contents of the given <code>Properties</code> object.
+ * </p>
+ */
+ public void initialize(Properties props) throws SchedulerException {
+ if (propSrc == null) {
+ propSrc = "an externally provided properties instance.";
+ }
+
+ this.cfg = new PropertiesParser(props);
+ }
+
+ /**
+ * <p>
+ * Returns a handle to the Scheduler produced by this factory.
+ * </p>
+ *
+ * <p>
+ * If one of the <code>initialize</code> methods has not be previously
+ * called, then the default (no-arg) <code>initialize()</code> method will
+ * be called by this method.
+ * </p>
+ */
+ public Scheduler getScheduler() throws SchedulerException {
+ if (cfg == null) {
+ initialize();
+ }
+
+ SchedulerRepository schedRep = SchedulerRepository.getInstance();
+
+ Scheduler sched = schedRep.lookup(getSchedulerName());
+
+ if (sched != null) {
+ if (sched.isShutdown()) {
+ schedRep.remove(getSchedulerName());
+ } else {
+ return sched;
+ }
+ }
+
+ sched = instantiate();
+
+ return sched;
+ }
+
+ private String getSchedulerName() {
+ return
cfg.getStringProperty(PROP_SCHED_INSTANCE_NAME, "QuartzScheduler");
+ }
+
+ /**
+ * This is the method that needed to be overriden. It creates a
RAMJobStore,
+ * SimpleClassLoadHelper, and SimpleThreadPool regardless of what
properties
+ * you supply. It also does not look for listeners of any kind, it just
+ * makes the simple scheduler.
+ *
+ * @return the scheduler
+ * @throws SchedulerException
+ */
+ private Scheduler instantiate() throws SchedulerException {
+ RAMJobStore js = null;
+ SimpleThreadPool tp = null;
+ QuartzScheduler qs = null;
+ SchedulingContext schedCtxt = null;
+ Properties tProps = null;
+ long idleWaitTime = -1;
+ long dbFailureRetry = -1;
+
+ SchedulerRepository schedRep = SchedulerRepository.getInstance();
+
+ // Get Scheduler Properties
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ String schedName =
cfg.getStringProperty(PROP_SCHED_INSTANCE_NAME, "QuartzScheduler");
+
+ String threadName = cfg.getStringProperty(PROP_SCHED_THREAD_NAME,
schedName + "_QuartzSchedulerThread");
+
+ idleWaitTime = cfg.getLongProperty(PROP_SCHED_IDLE_WAIT_TIME,
idleWaitTime);
+ dbFailureRetry =
cfg.getLongProperty(PROP_SCHED_DB_FAILURE_RETRY_INTERVAL, dbFailureRetry);
+
+ boolean makeSchedulerThreadDaemon =
cfg.getBooleanProperty(PROP_SCHED_MAKE_SCHEDULER_THREAD_DAEMON);
+
+ // Create class load helper
+ SimpleClassLoadHelper loadHelper = new SimpleClassLoadHelper();
+ loadHelper.initialize();
+
+ PropertySettingJobFactory jobFactory = new PropertySettingJobFactory();
+ jobFactory.setWarnIfPropertyNotFound(false);
+
+ tProps = cfg.getPropertyGroup(PROP_SCHED_JOB_FACTORY_PREFIX, true);
+ try {
+ setBeanProps(jobFactory, tProps);
+ } catch (Exception e) {
+ initException = new SchedulerException("JobFactory class '" +
jobFactory.getClass()
+ + "' props could not be configured.", e);
+ initException.setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION);
+ throw initException;
+ }
+
+ // Get ThreadPool Properties
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ tp = new SimpleThreadPool();
+
+ tp.setThreadsInheritContextClassLoaderOfInitializingThread(true);
+
+
+ // Get JobStore Properties
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ js = new RAMJobStore();
+ tProps = cfg.getPropertyGroup(PROP_JOB_STORE_PREFIX, true, new String[]
{ PROP_JOB_STORE_LOCK_HANDLER_PREFIX });
+ try {
+ setBeanProps(js, tProps);
+ } catch (Exception e) {
+ initException = new SchedulerException("JobStore class '" +
js.getClass()
+ + "' props could not be configured.", e);
+ initException.setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION);
+ throw initException;
+ }
+
+ // Set up any DataSources
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ // nothing to do
+
+ // Set up any SchedulerPlugins
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ // nothing to do
+
+ // Set up any JobListeners
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ // nothing to do
+
+ // Set up any TriggerListeners
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ // nothing to do
+
+ // Fire everything up
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ JobRunShellFactory jrsf = null; // Create correct run-shell factory...
+
+ UserTransactionHelper.setUserTxLocation(null);
+
+ jrsf = new StdJobRunShellFactory();
+
+ QuartzSchedulerResources rsrcs = new QuartzSchedulerResources();
+ rsrcs.setName(schedName);
+ rsrcs.setThreadName(threadName);
+ rsrcs.setInstanceId("DefaultQuartzScheduler");
+ rsrcs.setJobRunShellFactory(jrsf);
+ rsrcs.setMakeSchedulerThreadDaemon(makeSchedulerThreadDaemon);
+ rsrcs.setJMXExport(false);
+ rsrcs.setJMXObjectName(null);
+ rsrcs.setThreadPool(tp);
+
+ tp.setThreadCount(10);
+ tp.setThreadNamePrefix(schedName + "_Worker");
+ tp.initialize();
+
+ rsrcs.setJobStore(js);
+
+ schedCtxt = new SchedulingContext();
+ schedCtxt.setInstanceId(rsrcs.getInstanceId());
+
+ qs = new QuartzScheduler(rsrcs, schedCtxt, idleWaitTime, dbFailureRetry);
+
+ // Create Scheduler ref...
+ Scheduler scheduler = instantiate(rsrcs, qs);
+
+ // set job factory if specified
+ if (jobFactory != null) {
+ qs.setJobFactory(jobFactory);
+ }
+
+ // fire up job store, and runshell factory
+
+ js.initialize(loadHelper, qs.getSchedulerSignaler());
+
+ jrsf.initialize(scheduler, schedCtxt);
+
+ //log.println("Quartz scheduler '" + scheduler.getSchedulerName() + "'
initialized from " + propSrc);
+ //log.println("Quartz scheduler version: " + qs.getVersion());
+
+ // prevents the repository from being garbage collected
+ qs.addNoGCObject(schedRep);
+ // prevents the db manager from being garbage collected
+
+ schedRep.bind(scheduler);
+
+ return scheduler;
+ }
+
+ private void setBeanProps(Object obj, Properties props) throws
NoSuchMethodException, IllegalAccessException,
+ java.lang.reflect.InvocationTargetException, IntrospectionException,
SchedulerConfigException {
+ props.remove("class");
+
+ BeanInfo bi = Introspector.getBeanInfo(obj.getClass());
+ PropertyDescriptor[] propDescs = bi.getPropertyDescriptors();
+ PropertiesParser pp = new PropertiesParser(props);
+
+ Enumeration<Object> keys = props.keys();
+ while (keys.hasMoreElements()) {
+ String name = (String) keys.nextElement();
+ String c = name.substring(0, 1).toUpperCase(Locale.US);
+ String methName = "set" + c + name.substring(1);
+
+ java.lang.reflect.Method setMeth = getSetMethod(methName, propDescs);
+
+ try {
+ if (setMeth == null) {
+ throw new NoSuchMethodException("No setter for property '" + name
+ "'");
+ }
+
+ Class<?>[] params = setMeth.getParameterTypes();
+ if (params.length != 1) {
+ throw new NoSuchMethodException("No 1-argument setter for property '"
+ name + "'");
+ }
+ if (params[0].equals(int.class)) {
+ setMeth.invoke(obj, new Object[] {
Integer.valueOf(pp.getIntProperty(name)) });
+ } else if (params[0].equals(long.class)) {
+ setMeth.invoke(obj, new Object[] {
Long.valueOf(pp.getLongProperty(name)) });
+ } else if (params[0].equals(float.class)) {
+ setMeth.invoke(obj, new Object[] {
Float.valueOf(pp.getFloatProperty(name)) });
+ } else if (params[0].equals(double.class)) {
+ setMeth.invoke(obj, new Object[] {
Double.valueOf(pp.getDoubleProperty(name)) });
+ } else if (params[0].equals(boolean.class)) {
+ setMeth.invoke(obj, new Object[] {
Boolean.valueOf(pp.getBooleanProperty(name)) });
+ } else if (params[0].equals(String.class)) {
+ setMeth.invoke(obj, new Object[] { pp.getStringProperty(name) });
+ } else {
+ throw new NoSuchMethodException("No primitive-type setter for
property '" + name + "'");
+ }
+ } catch (NumberFormatException nfe) {
+ throw new SchedulerConfigException("Could not parse property '" + name
+ "' into correct data type: "
+ + nfe.toString());
+ }
+ }
+ }
+
+ private java.lang.reflect.Method getSetMethod(String name,
PropertyDescriptor[] props) {
+ for (int i = 0; i < props.length; i++) {
+ java.lang.reflect.Method wMeth = props[i].getWriteMethod();
+
+ if (wMeth != null && wMeth.getName().equals(name)) {
+ return wMeth;
+ }
+ }
+
+ return null;
+ }
+
+}
+

--
You received this message because you are subscribed to the Google Groups "GoGoEgo" group.
To post to this group, send email to gog...@googlegroups.com.
To unsubscribe from this group, send email to gogoego+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gogoego?hl=en.

Reply all
Reply to author
Forward
0 new messages