Skip to content

Commit

Permalink
Merge branch 'develop' into feature/schedule-java-ee-timer
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroyle committed May 12, 2015
2 parents a27280d + 9823fee commit ea430aa
Show file tree
Hide file tree
Showing 36 changed files with 410 additions and 219 deletions.
2 changes: 1 addition & 1 deletion JBossServicePlusTimerTest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<version>2.14.1</version>
<configuration>
<systemPropertyVariables>
<arquillian.launch>jboss</arquillian.launch>
<arquillian.launch>jboss-as-7.0</arquillian.launch>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down
25 changes: 25 additions & 0 deletions JBossServicePlusTimerTest/src/main/java/timertest/AppConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package timertest;

import javax.enterprise.context.ApplicationScoped;

/**
*
* @author pete
*/
@ApplicationScoped
public class AppConfig {

private String schedule;

public AppConfig() {
}

public String getSchedule() {
return schedule;
}

public void setSchedule(String schedule) {
this.schedule = schedule;
}

}
Original file line number Diff line number Diff line change
@@ -1,64 +1,21 @@
package timertest;

import java.lang.annotation.Annotation;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.AfterDeploymentValidation;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.BeforeShutdown;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessObserverMethod;

/**
*
* @author peteroyle
*/
public class DummyExtension implements Extension {

/**
* Because "Extension classes should be public and have a public constructor for maximum portability"
*/
public DummyExtension() {
System.out.println("Initiailised DummyService");
public void afterValidation(@Observes AfterDeploymentValidation afterValid, final BeanManager manager,
AppConfig appConfig) {
System.out.println("After validation running ...");
appConfig.setSchedule("0 5 * * * *");
System.out.println("After validation complete");
}

public void registerDummyServiceObserver(@Observes ProcessObserverMethod pom, DummyService dummyService) {
System.out.println("processing observer method");
dummyService.init();
}

public void afterValidation(@Observes AfterDeploymentValidation afterValid, final BeanManager manager
) {
DummyService dummyService = getInstanceByType(manager, DummyService.class);
System.out.println("After validation");
dummyService.init();
}

public void stopProviders(@Observes BeforeShutdown event, final BeanManager manager) {

}


/**
* Utility method allowing managed instances of beans to provide entry points
* for non-managed beans (such as {@link WeldContainer}). Should only called
* once CDI has finished booting.
*
* @param manager the BeanManager to use to access the managed instance
* @param type the type of the Bean
* @param bindings the bean's qualifiers
* @return a managed instance of the bean
*
*/
public static <T> T getInstanceByType(final BeanManager manager, final Class<T> type, final Annotation... bindings) {
// TODO: (PR): fix this catch and swallow hackery
try {
final Bean<?> bean = manager.resolve(manager.getBeans(type));
final CreationalContext<?> cc = manager.createCreationalContext(bean);
return type.cast(manager.getReference(bean, type, cc));
} catch (Throwable t) {
return null;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package timertest;

import javax.ejb.LocalBean;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.TimerService;
import javax.inject.Inject;

/**
*
* @author peteroyle
*/
@Singleton
@LocalBean
public class DummyServiceEjb implements DummyService {
@Startup
public class DummyServiceEjb {

@Inject
private AppConfig appConfig;
@Resource
private TimerService timerService;

@PostConstruct
public void init() {
System.out.println("Initialising dummy service implementation");
System.out.println("App Config Schedule: " + appConfig.getSchedule());
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package timertest;

import javax.inject.Inject;
Expand All @@ -22,14 +17,14 @@
public class DummyServiceTest {

@Inject
private DummyService dummyService;
private DummyServiceEjb dummyService;

@Deployment
public static WebArchive createDefaultArchive() {
WebArchive archive = ShrinkWrap.create(WebArchive.class, "test.war");
archive.addAsWebInfResource("META-INF/beans.xml", "beans.xml");
archive.addClass(DummyService.class);
archive.addClass(DummyServiceEjb.class);
archive.addClass(AppConfig.class);

archive.addAsResource("META-INF/services/javax.enterprise.inject.spi.Extension", "META-INF/services/javax.enterprise.inject.spi.Extension");
archive.addClass(DummyExtension.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<property name="deploymentExportPath">target/deployment</property>
</engine>
<defaultProtocol type="Servlet 3.0"/>
<container qualifier="jboss" default="true">
<container qualifier="jboss-as-7.0" default="true">
<configuration>
<property name="jbossHome">${project.build.directory}/${jboss.dir.name.test}/</property>
</configuration>
Expand Down
4 changes: 0 additions & 4 deletions impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
<artifactId>seam-cron-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.solder</groupId>
<artifactId>solder-impl</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
Expand Down
48 changes: 38 additions & 10 deletions impl/src/main/java/org/jboss/seam/cron/util/PropertyResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
package org.jboss.seam.cron.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.apache.deltaspike.core.api.config.ConfigResolver;
import org.jboss.seam.cron.impl.scheduling.exception.SchedulerConfigurationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -27,28 +30,53 @@ public class PropertyResolver {

static {
try {
cronProperties.load(PropertyResolver.class.getResourceAsStream(SCHEDULE_PROPERTIES_PATH));
final InputStream propertyResource = PropertyResolver.class.getResourceAsStream(SCHEDULE_PROPERTIES_PATH);
if (propertyResource != null) {
cronProperties.load(propertyResource);
} else {
LoggerFactory.getLogger(PropertyResolver.class).warn("Cron could not find " + SCHEDULE_PROPERTIES_PATH
+ " on the classpath and therefore will not be using it as a source of named schedules.");
}
} catch (IOException ex) {
LoggerFactory.getLogger(PropertyResolver.class).warn("Cron could not find " + SCHEDULE_PROPERTIES_PATH
+ " on the classpath and therefore will not be using it a source of named schedules.", ex);
LoggerFactory.getLogger(PropertyResolver.class).warn("Cron could not read from " + SCHEDULE_PROPERTIES_PATH
+ " on the classpath and therefore will not be using it as a source of named schedules.", ex);
}
}

public static String resolve(String key) {
return resolve(key, false);
}

public static String resolve(String key, boolean mandatory) {
String value;
try {
// try all the power of DeltaSpike first
// TODO: this is not working or not reliable yet, and will usually fall through to the resolveUsingBuiltInMethods method.
Class.forName("org.apache.deltaspike.core.api.config.ConfigResolver");
log.debug("Using DeltaSpike config resolver to resolve {0}", key);
value = ConfigResolver.getProjectStageAwarePropertyValue(key);
} catch (ClassNotFoundException ex) {
log.debug("Falling back to built-in property resolution resolving property {0}", key);
// fall back to System properties
value = System.getProperty(key);
if (value == null) {
// failing that, try cron.properties
value = cronProperties.getProperty(key);
if (StringUtils.isEmpty(value)) {
value = resolveUsingBuiltInMethods(key);
}
} catch (ClassNotFoundException ex) {
value = resolveUsingBuiltInMethods(key);
}
if (mandatory && StringUtils.isEmpty(value)) {
throw new SchedulerConfigurationException(
"Found empty or missing cron definition for named schedule '"
+ key + "'. It should be specified in the file "
+ SCHEDULE_PROPERTIES_PATH + " on the classpath, or as a system property.");
}
return value;
}

protected static String resolveUsingBuiltInMethods(String key) {
log.debug("Falling back to built-in property resolution resolving property {0}", key);
// fall back to System properties
String value = System.getProperty(key);
if (value == null) {
// failing that, try cron.properties
value = cronProperties.getProperty(key);
}
return value;
}
Expand Down
20 changes: 20 additions & 0 deletions nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<config-data xmlns="http://www.netbeans.org/ns/maven-config-data/1">
<configurations>
<configuration id="longtests-provider-type-java-ee" profiles="">
<property name="longtests">true</property>
<property name="provider.type">java-ee</property>
</configuration>
<configuration id="provider-type-java-ee" profiles="">
<property name="provider.type">java-ee</property>
</configuration>
</configurations>
</config-data>
</project-shared-configuration>
Loading

0 comments on commit ea430aa

Please sign in to comment.