Hi
im getting a NPE in my typelistener, and are wondering why..
Heres the module definiton:
bind(SchedulerFactory.class).toProvider(getScheduleFactoryProvider())
.asEagerSingleton();
ScheduledTypeListener scheduledTypeListener = new
ScheduledTypeListener();
requesting injection --> requestInjection(scheduledTypeListener);
Matcher<TypeLiteral<?>> matcher = new
AbstractMatcher<TypeLiteral<?>>() {
public boolean matches(TypeLiteral<?> type) {
return
(type.getRawType().isAnnotationPresent(Scheduled.class));
}
};
bindListener(matcher, scheduledTypeListener);
and the code for the listener:
public class ScheduledTypeListener implements TypeListener {
private SchedulerFactory schedulerFactory;
public <T> void hear(TypeLiteral<T> typeLiteral,
TypeEncounter<T> typeEncounter) {
if (typeLiteral.getRawType().isAnnotationPresent(Scheduled.class)) {
startSchedule(typeLiteral.getRawType());
}
}
private void startSchedule(Class clazz) {
Scheduler sched = null;
try {
NPE--> sched = getSchedulerFactory().getScheduler();
sched.start();
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JobDetail jobDetail = new JobDetail("myJob", // job name
sched.DEFAULT_GROUP, // job group (you can also specify
'null'
// to use the default group)
clazz); // the java class to execute
CronTrigger trigger = new CronTrigger(clazz.getCanonicalName());
Scheduled scheduled = (Scheduled)
clazz.getAnnotation(Scheduled.class);
String cronString = scheduled.cron();
try {
trigger.setCronExpression(cronString);
sched.scheduleJob(jobDetail, trigger);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Asking for injection--> @Inject
public void setSchedulerFactory(SchedulerFactory schedulerFactory) {
this.schedulerFactory = schedulerFactory;
}
public SchedulerFactory getSchedulerFactory() {
return schedulerFactory;
}
}
Full source with test case here: https://slurry.googlecode.com/svn , under
quartz4guice
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.