Skip to content

Commit

Permalink
SEAMCRON-3: More slight changes as per developer guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroyle committed May 25, 2011
1 parent 407a951 commit b8bae2e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 97 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void destroyProvider() throws CronProviderDestructionException {
try {
scheduler.shutdown();
} catch (SchedulerException ex) {
log.error("Error shutting down scheduler", ex);
log.warn("Error shutting down scheduler", ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void destroyProvider() throws CronProviderDestructionException {
try {
getScheduler().shutdown();
} catch (SchedulerException ex) {
log.error("Error shutting down scheduler", ex);
log.warn("Error shutting down scheduler", ex);
}
}

Expand Down
12 changes: 12 additions & 0 deletions spi/src/main/java/org/jboss/seam/cron/spi/SeamCronExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public class SeamCronExtension implements Extension {
private final Set<ObserverMethod> allObservers = new HashSet<ObserverMethod>();
private final Logger log = Logger.getLogger(SeamCronExtension.class);

/**
* Because "Extension classes should be public and have a public constructor
* for maximum portability"
*/
public SeamCronExtension() {
}

public void registerCronEventObserver(@Observes ProcessObserverMethod pom) {
allObservers.add(pom.getObserverMethod());
}
Expand All @@ -62,6 +69,11 @@ public void initProviders(@Observes AfterDeploymentValidation afterValid, final
if (schedulingProvider != null) {
cronSchedExt.initProviderScheduling(manager, schedulingProvider, allObservers);
}
// TODO: (PR): If there's an asynch provider present, check if the interceptor is enabled. See https://jira.jboss.org/jira/browse/WELDX-91
// final CronAsynchronousProvider asyncProvider = CdiUtils.getInstanceByType(manager, CronAsynchronousProvider.class);
// if (asyncProvider != null) {
// assert interceptors.isInterceptorEnabled(AsynchronousInterceptor.class);
// }
}

public void stopProviders(@Observes BeforeShutdown event, final BeanManager manager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ public class AsynchronousInterceptor {
public Object executeAsynchronously(final InvocationContext ctx) throws Exception {
Object result;

log.trace("Intercepting method invocation of " + ctx.getMethod().getName() + " to make it @Asynchronous");

if (log.isTraceEnabled()) {
log.trace("Intercepting method invocation of " + ctx.getMethod().getName() + " to make it @Asynchronous");
}

final Invoker ice = iceCopies.get();
ice.setInvocationContext(ctx);
final CronAsynchronousProvider asyncStrategy = asyncStgyCopies.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ public Object executeInvocationContext() throws Exception {
}
beanMan.fireEvent(result, qualifiers.toArray(new Annotation[qualifiers.size()]));
} else {
if (method.getReturnType().equals(Void.TYPE)) {
log.debug("Method invocation on " + method.getName() + ":" + method.getClass().getName() + " returns void, so not firing a post-execution event");
} else {
log.debug("Method invocation on " + method.getName() + ":" + method.getClass().getName() + " returned null, so not firing an event");
if (log.isTraceEnabled()) {
if (method.getReturnType().equals(Void.TYPE)) {
log.trace("Method invocation on " + method.getName() + ":" + method.getClass().getName() + " returns void, so not firing a post-execution event");
} else {
log.trace("Method invocation on " + method.getName() + ":" + method.getClass().getName() + " returned null, so not firing an event");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.ObserverMethod;
import javax.inject.Inject;
import org.apache.commons.lang.StringUtils;
import org.jboss.logging.Logger;
import org.jboss.seam.cron.api.scheduling.Every;
import org.jboss.seam.cron.api.scheduling.Scheduled;
import org.jboss.seam.cron.impl.scheduling.exception.SchedulerConfigurationException;
import org.jboss.seam.cron.impl.scheduling.exception.CronProviderInitialisationException;
import org.jboss.seam.cron.util.CdiUtils;
import org.jboss.seam.cron.impl.scheduling.util.SchedulePropertiesManager;
import org.jboss.seam.cron.spi.scheduling.trigger.IntervalTriggerDetail;
import org.jboss.seam.cron.spi.scheduling.trigger.ScheduledTriggerDetail;
import org.jboss.seam.cron.spi.scheduling.trigger.TriggerDetail;
import org.jboss.seam.solder.resourceLoader.Resource;

/**
* Scans all scheduling annotations and captures the configuration as a #{@link Set}
Expand All @@ -45,6 +46,11 @@
@ApplicationScoped
public class CronSchedulingInstaller {

public static final String SCHEDULE_PROPERTIES_PATH = "/cron.properties";

@Inject
@Resource(SCHEDULE_PROPERTIES_PATH)
private Properties schedProperties;
private final Logger log = Logger.getLogger(CronSchedulingInstaller.class);

/**
Expand Down Expand Up @@ -104,14 +110,13 @@ private String lookupNamedScheduleIfNecessary(final String scheduleSpec)
if (scheduleSpec.contains(" ")) {
cronScheduleSpec = scheduleSpec;
} else {
final Properties schedProperties = SchedulePropertiesManager.instance().getScheduleProperties();
cronScheduleSpec = schedProperties.getProperty(scheduleSpec);

if (StringUtils.isEmpty(cronScheduleSpec)) {
throw new SchedulerConfigurationException("Found empty or missing cron definition for named schedule '"
throw new SchedulerConfigurationException(
"Found empty or missing cron definition for named schedule '"
+ scheduleSpec + "'. Should be specified in the file "
+ SchedulePropertiesManager.SCHEDULE_PROPERTIES_PATH
+ " on the classpath.");
+ SCHEDULE_PROPERTIES_PATH + " on the classpath.");
}
}

Expand Down

0 comments on commit b8bae2e

Please sign in to comment.