aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-04-14 18:04:50 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-04-14 18:04:50 +0200
commit8477e8a888d584cf1352a4b69d7cefb2b7cd9ace (patch)
treea99e339e302c31ef33e55bf7de5ae3333df11a92 /src
parentb59f08bb5b08be7972086037ec54b23ea9fb49f8 (diff)
downloadquartz-based-queue-8477e8a888d584cf1352a4b69d7cefb2b7cd9ace.tar.gz
quartz-based-queue-8477e8a888d584cf1352a4b69d7cefb2b7cd9ace.tar.bz2
quartz-based-queue-8477e8a888d584cf1352a4b69d7cefb2b7cd9ace.tar.xz
quartz-based-queue-8477e8a888d584cf1352a4b69d7cefb2b7cd9ace.zip
o Dropping quartz, using straight executor service.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/main/java/io/trygvis/CreateArticleCallable.java13
-rwxr-xr-xsrc/main/java/io/trygvis/Main.java21
-rwxr-xr-xsrc/main/java/io/trygvis/UpdateArticleCallable.java (renamed from src/main/java/io/trygvis/UpdateArticeCallable.java)3
-rwxr-xr-xsrc/main/java/io/trygvis/data/TaskRepository.java4
-rwxr-xr-xsrc/main/java/io/trygvis/model/Queue.java12
-rwxr-xr-xsrc/main/java/io/trygvis/model/Task.java74
-rwxr-xr-xsrc/main/java/io/trygvis/queue/AsyncService.java4
-rwxr-xr-xsrc/main/java/io/trygvis/queue/JpaAsyncService.java306
-rwxr-xr-xsrc/main/java/io/trygvis/spring/Config.java2
-rwxr-xr-xsrc/main/resources/logback.xml22
10 files changed, 259 insertions, 202 deletions
diff --git a/src/main/java/io/trygvis/CreateArticleCallable.java b/src/main/java/io/trygvis/CreateArticleCallable.java
index e727b46..85734fc 100755
--- a/src/main/java/io/trygvis/CreateArticleCallable.java
+++ b/src/main/java/io/trygvis/CreateArticleCallable.java
@@ -6,21 +6,28 @@ import org.slf4j.*;
import org.springframework.stereotype.*;
import org.springframework.transaction.annotation.*;
-import java.util.*;
import javax.persistence.*;
+import java.util.*;
import static org.springframework.transaction.annotation.Propagation.*;
-@Component
+@Component("createArticle")
+@Transactional(propagation = MANDATORY)
public class CreateArticleCallable implements AsyncService.AsyncCallable {
private final Logger log = LoggerFactory.getLogger(getClass());
@PersistenceContext
private EntityManager entityManager;
-// @Transactional(propagation = REQUIRES_NEW)
+ private Random random = new Random();
+
public void run() throws Exception {
log.info("CreateArticeJob.run: BEGIN");
+
+ if (random.nextBoolean()) {
+ throw new RuntimeException("failing create article");
+ }
+
Date now = new Date();
log.info("now = {}", now);
diff --git a/src/main/java/io/trygvis/Main.java b/src/main/java/io/trygvis/Main.java
index aafb728..448c3e4 100755
--- a/src/main/java/io/trygvis/Main.java
+++ b/src/main/java/io/trygvis/Main.java
@@ -7,12 +7,12 @@ import org.slf4j.bridge.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.context.support.*;
import org.springframework.stereotype.*;
-import org.springframework.transaction.annotation.*;
+
+import java.util.*;
import static java.lang.System.*;
@Component
-@Transactional
public class Main {
private static final Logger log = LoggerFactory.getLogger(Main.class);
@@ -23,7 +23,7 @@ public class Main {
setProperty("database.url", getProperty("jdbc.url", "jdbc:postgresql://localhost/" + username));
setProperty("database.username", username);
setProperty("database.password", username);
- setProperty("hibernate.showSql", "true");
+// setProperty("hibernate.showSql", "true");
setProperty("hibernate.hbm2ddl.auto", "create"); // create
setProperty("hibernate.dialect", PostgreSQL82Dialect.class.getName());
@@ -50,19 +50,26 @@ public class Main {
private AsyncService<AsyncService.QueueRef, AsyncService.ExecutionRef> asyncService;
@Autowired
- private CreateArticleCallable createArticleCallable;
+ @Qualifier("createArticle")
+ private AsyncService.AsyncCallable createArticleCallable;
@Autowired
- private UpdateArticeCallable updateArticeCallable;
+ @Qualifier("createArticle")
+ private AsyncService.AsyncCallable/*UpdateArticleCallable*/ updateArticleCallable;
public void run() throws Exception {
log.info("Main.run");
- asyncService.registerQueue("create-queue", 1, createArticleCallable);
+ JpaAsyncService.JpaQueueRef queueRef = asyncService.registerQueue("create-queue", 10, createArticleCallable);
+ log.info("queue registered: ref = {}", queueRef);
// asyncService.registerQueue("update-queue", 1, updateArticeCallable);
AsyncService.QueueRef queue = asyncService.getQueue("create-queue");
- AsyncService.ExecutionRef executionRef = asyncService.schedule(queue);
+ List<AsyncService.ExecutionRef> refs = new ArrayList<>();
+
+ for (int i = 0; i < 10; i++) {
+ refs.add(asyncService.schedule(queue));
+ }
}
}
diff --git a/src/main/java/io/trygvis/UpdateArticeCallable.java b/src/main/java/io/trygvis/UpdateArticleCallable.java
index d022655..7ed8b63 100755
--- a/src/main/java/io/trygvis/UpdateArticeCallable.java
+++ b/src/main/java/io/trygvis/UpdateArticleCallable.java
@@ -12,7 +12,8 @@ import javax.persistence.*;
import static org.springframework.transaction.annotation.Propagation.*;
@Component
-public class UpdateArticeCallable implements AsyncService.AsyncCallable {
+public class UpdateArticleCallable
+ implements AsyncService.AsyncCallable {
private final Logger log = LoggerFactory.getLogger(getClass());
private final Random r = new Random();
diff --git a/src/main/java/io/trygvis/data/TaskRepository.java b/src/main/java/io/trygvis/data/TaskRepository.java
index 0b65199..e24d520 100755
--- a/src/main/java/io/trygvis/data/TaskRepository.java
+++ b/src/main/java/io/trygvis/data/TaskRepository.java
@@ -1,7 +1,11 @@
package io.trygvis.data;
import io.trygvis.model.*;
+import io.trygvis.model.Queue;
import org.springframework.data.jpa.repository.*;
+import java.util.*;
+
public interface TaskRepository extends JpaRepository<Task, Long> {
+ List<Task> findByQueueAndCompletedIsNull(Queue queue);
}
diff --git a/src/main/java/io/trygvis/model/Queue.java b/src/main/java/io/trygvis/model/Queue.java
index 52c5c0f..aeec405 100755
--- a/src/main/java/io/trygvis/model/Queue.java
+++ b/src/main/java/io/trygvis/model/Queue.java
@@ -19,6 +19,10 @@ public class Queue {
private long interval;
+ @SuppressWarnings("UnusedDeclaration")
+ private Queue() {
+ }
+
public Queue(String name, long interval) {
this.name = name;
this.interval = interval;
@@ -43,4 +47,12 @@ public class Queue {
public void setInterval(long interval) {
this.interval = interval;
}
+
+ public String toString() {
+ return "Queue{" +
+ "id=" + id +
+ ", name='" + name + '\'' +
+ ", interval=" + interval +
+ '}';
+ }
}
diff --git a/src/main/java/io/trygvis/model/Task.java b/src/main/java/io/trygvis/model/Task.java
index fa44e26..e86b623 100755
--- a/src/main/java/io/trygvis/model/Task.java
+++ b/src/main/java/io/trygvis/model/Task.java
@@ -1,6 +1,8 @@
package io.trygvis.model;
import javax.persistence.*;
+import java.util.*;
+import java.util.regex.*;
@Entity
public class Task {
@@ -12,21 +14,81 @@ public class Task {
@ManyToOne
private Queue queue;
- private Long long1;
+ private Date scheduled;
- public Task(Queue queue) {
+ private Date lastRun;
+
+ private int runCount;
+
+ private Date completed;
+
+ private String arguments;
+
+ private static final Pattern pattern = Pattern.compile(" ");
+
+ @SuppressWarnings("UnusedDeclaration")
+ private Task() {
+ }
+
+ public Task(Queue queue, Date scheduled, String... arguments) {
this.queue = queue;
+ this.scheduled = scheduled;
+
+ StringBuilder builder = new StringBuilder(arguments.length * 100);
+ for (String argument : arguments) {
+ if (pattern.matcher(argument).matches()) {
+ throw new RuntimeException("Bad argument: '" + argument + "'.");
+ }
+ builder.append(argument).append(' ');
+ }
+ this.arguments = builder.toString();
}
public Integer getId() {
return id;
}
- public Long getLong1() {
- return long1;
+ public String[] getArguments() {
+ return arguments.split(" ");
+ }
+
+ public Date getScheduled() {
+ return scheduled;
+ }
+
+ public Date getLastRun() {
+ return lastRun;
+ }
+
+ public int getRunCount() {
+ return runCount;
+ }
+
+ public Date getCompleted() {
+ return completed;
+ }
+
+ public void setCompleted(Date completed) {
+ this.completed = completed;
+ }
+
+ public void registerRun() {
+ lastRun = new Date();
+ runCount++;
+ }
+
+ public void registerComplete(Date completed) {
+ this.completed = completed;
}
- public void setLong1(Long long1) {
- this.long1 = long1;
+ public String toString() {
+ return "Task{" +
+ "id=" + id +
+ ", queue=" + queue +
+ ", scheduled=" + scheduled +
+ ", lastRun=" + lastRun +
+ ", completed=" + completed +
+ ", arguments='" + arguments + '\'' +
+ '}';
}
}
diff --git a/src/main/java/io/trygvis/queue/AsyncService.java b/src/main/java/io/trygvis/queue/AsyncService.java
index de0a1af..f792f5e 100755
--- a/src/main/java/io/trygvis/queue/AsyncService.java
+++ b/src/main/java/io/trygvis/queue/AsyncService.java
@@ -4,11 +4,11 @@ import org.quartz.*;
public interface AsyncService<QueueRef extends AsyncService.QueueRef, ExecutionRef extends AsyncService.ExecutionRef> {
- void registerQueue(String name, int interval, AsyncCallable callable) throws SchedulerException;
+ JpaAsyncService.JpaQueueRef registerQueue(String name, int interval, AsyncCallable callable) throws SchedulerException;
QueueRef getQueue(String name);
- ExecutionRef schedule(QueueRef queue);
+ ExecutionRef schedule(QueueRef queue, String... args);
interface QueueRef {
}
diff --git a/src/main/java/io/trygvis/queue/JpaAsyncService.java b/src/main/java/io/trygvis/queue/JpaAsyncService.java
index e715c6d..95d5ef3 100755
--- a/src/main/java/io/trygvis/queue/JpaAsyncService.java
+++ b/src/main/java/io/trygvis/queue/JpaAsyncService.java
@@ -1,61 +1,36 @@
package io.trygvis.queue;
-import io.trygvis.data.QueueRepository;
-import io.trygvis.data.TaskRepository;
+import io.trygvis.data.*;
import io.trygvis.model.Queue;
-import org.quartz.Job;
-import org.quartz.JobDataMap;
-import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
-import org.quartz.JobKey;
-import org.quartz.JobPersistenceException;
-import org.quartz.Scheduler;
-import org.quartz.SchedulerException;
-import org.quartz.SchedulerFactory;
-import org.quartz.SimpleScheduleBuilder;
-import org.quartz.SimpleTrigger;
-import org.quartz.TriggerBuilder;
-import org.quartz.impl.JobDetailImpl;
-import org.quartz.impl.StdSchedulerFactory;
-import org.quartz.impl.jdbcjobstore.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.jdbc.datasource.DataSourceUtils;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.PlatformTransactionManager;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.annotation.*;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.RollbackException;
-import javax.persistence.TypedQuery;
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.SQLException;
+import io.trygvis.model.*;
+import org.quartz.*;
+import org.slf4j.*;
+import org.springframework.beans.factory.annotation.*;
+import org.springframework.stereotype.*;
+import org.springframework.transaction.*;
+import org.springframework.transaction.annotation.*;
+import org.springframework.transaction.support.*;
+
+import javax.persistence.*;
import java.util.*;
+import java.util.concurrent.*;
-import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
+import static java.util.concurrent.TimeUnit.*;
+import static org.springframework.transaction.support.TransactionSynchronizationManager.*;
@SuppressWarnings("SpringJavaAutowiringInspection")
@Component
-public class JpaAsyncService implements AsyncService<JpaAsyncService.JpaQueueRef, JpaAsyncService.JpaExecutionRef>,
- ApplicationContextAware {
+public class JpaAsyncService implements AsyncService<JpaAsyncService.JpaQueueRef, JpaAsyncService.JpaExecutionRef>/*, ApplicationContextAware*/ {
private final Logger log = LoggerFactory.getLogger(getClass());
+ private final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10, Executors.defaultThreadFactory());
+
@PersistenceContext
private EntityManager entityManager;
@Autowired
- private DataSource dataSource;
-
- @Autowired
- private PlatformTransactionManager transactionManager;
+ private TransactionTemplate transactionTemplate;
@Autowired
private QueueRepository queueRepository;
@@ -63,59 +38,17 @@ public class JpaAsyncService implements AsyncService<JpaAsyncService.JpaQueueRef
@Autowired
private TaskRepository taskRepository;
- private Scheduler scheduler;
-
- private static DataSource dataSourceStatic;
-
- private static PlatformTransactionManager transactionManagerStatic;
-
- private static class Context {
- ApplicationContext applicationContext;
- List<AsyncCallable> callables = new ArrayList<>();
- }
-
- private final Context context = new Context();
-
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
- this.context.applicationContext = applicationContext;
- }
-
- @PostConstruct
- public void postConstruct() throws Exception {
- transactionManagerStatic = transactionManager;
- dataSourceStatic = dataSource;
- log.info("afterPropertiesSet!!");
- Properties quartzProperties = new Properties();
- quartzProperties.setProperty(StdSchedulerFactory.PROP_JOB_STORE_CLASS, JobStoreTX.class.getName());
- quartzProperties.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, "queue");
- quartzProperties.setProperty(StdSchedulerFactory.PROP_SCHED_SKIP_UPDATE_CHECK, "true");
- quartzProperties.setProperty(StdSchedulerFactory.PROP_SCHED_SKIP_UPDATE_CHECK, "true");
-// quartzProperties.setProperty(StdSchedulerFactory.PROP_DATASOURCE_PREFIX, "wat");
- quartzProperties.setProperty(StdSchedulerFactory.PROP_JOB_STORE_CLASS, JpaDataSourceJobStore.class.getName());
- quartzProperties.setProperty(StdSchedulerFactory.PROP_JOB_STORE_LOCK_HANDLER_CLASS, SimpleSemaphore.class.getName());
- quartzProperties.setProperty("org.quartz.threadPool.threadCount", "10");
- quartzProperties.setProperty("org.quartz.jobStore.driverDelegateClass", PostgreSQLDelegate.class.getName());
- quartzProperties.setProperty("org.quartz.scheduler.jmx.export", "true");
- SchedulerFactory schedulerFactory = new StdSchedulerFactory(quartzProperties);
-
- scheduler = schedulerFactory.getScheduler();
- scheduler.getContext().put("context", context);
- scheduler.start();
- }
-
- @PreDestroy
- public void preDestroy() throws Exception {
- scheduler.shutdown();
- }
-
@Transactional
- public synchronized void registerQueue(String name, int interval, AsyncCallable callable) throws SchedulerException {
+ public synchronized JpaQueueRef registerQueue(String name, int interval, AsyncCallable callable) throws SchedulerException {
+ log.info("registerQueue: ENTER");
Queue q = queueRepository.findByName(name);
+ log.info("q = {}", q);
+
if (q == null) {
- Queue queue = new Queue(name, interval);
- queueRepository.save(queue);
+ q = new Queue(name, interval);
+ q = queueRepository.save(q);
} else {
boolean dirty = false;
if (interval != q.getInterval()) {
@@ -124,133 +57,170 @@ public class JpaAsyncService implements AsyncService<JpaAsyncService.JpaQueueRef
}
if (dirty) {
- queueRepository.save(q);
+ q = queueRepository.save(q);
}
}
- context.callables.add(callable);
- int index = context.callables.size() - 1;
+ log.info("q = {}", q);
+ entityManager.flush();
+// entityManager.detach(q);
+ log.info("q = {}", q);
- JobDetailImpl jobDetail = new JobDetailImpl();
- JobKey jobKey = JobKey.jobKey("queue-" + name);
+ JpaQueueRef queueRef = new JpaQueueRef(q);
- jobDetail.setKey(jobKey);
- jobDetail.setJobClass(AsyncServiceJob.class);
- jobDetail.setDurability(true);
- jobDetail.getJobDataMap().put("index", Integer.toString(index));
- scheduler.addJob(jobDetail, true);
+ log.info("registerQueue: LEAVE");
- SimpleScheduleBuilder schedule = simpleSchedule().
- repeatForever().
- withIntervalInSeconds(interval);
-
- SimpleTrigger trigger = TriggerBuilder.newTrigger().
- withSchedule(schedule).
- withIdentity(jobKey.getName()).
- forJob(jobKey).
- build();
-
- if(scheduler.checkExists(trigger.getKey())) {
- scheduler.unscheduleJob(trigger.getKey());
- }
+ registerSynchronization(new MyTransactionSynchronization(callable, interval, queueRef));
- scheduler.scheduleJob(trigger);
+ return queueRef;
}
@Transactional(readOnly = true)
public JpaQueueRef getQueue(String name) {
- TypedQuery<Queue> query = entityManager.createQuery("select q from io.trygvis.model.Queue q where name = ?1", Queue.class);
- query.setParameter(1, name);
- List<Queue> list = query.getResultList();
- System.out.println("list.size() = " + list.size());
+ Queue queue = queueRepository.findByName(name);
- if (list.size() == 0) {
+ if (queue == null) {
throw new RollbackException("No such queue: '" + name + "'.");
}
- Queue queue = list.get(0);
-
- entityManager.detach(query);
+ entityManager.detach(queue);
return new JpaQueueRef(queue);
}
@Transactional
- public JpaExecutionRef schedule(JpaQueueRef queue) {
- return null;
+ public JpaExecutionRef schedule(JpaQueueRef queue, String... args) {
+ log.info("schedule: ENTER");
+ Date scheduled = new Date();
+ Task task = new Task(queue.queue, scheduled, args);
+ log.info("task = {}", task);
+ taskRepository.save(task);
+ log.info("task = {}", task);
+// entityManager.detach(task);
+ log.info("schedule: LEAVE");
+ return new JpaExecutionRef(task);
}
- static class JpaQueueRef implements AsyncService.QueueRef {
+ public static class JpaQueueRef implements AsyncService.QueueRef {
public final Queue queue;
JpaQueueRef(Queue queue) {
this.queue = queue;
}
- }
- static class JpaExecutionRef implements AsyncService.ExecutionRef {
+ public String toString() {
+ return "JpaQueueRef{" +
+ "queue=" + queue +
+ '}';
+ }
}
- public static class AsyncServiceJob implements Job {
- private final Logger log = LoggerFactory.getLogger(getClass());
+ public static class JpaExecutionRef implements AsyncService.ExecutionRef {
+ private final Task task;
- public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
- try {
- log.info("Running");
+ public JpaExecutionRef(Task task) {
+ this.task = task;
+ }
- Context context = (Context) jobExecutionContext.getScheduler().getContext().get("context");
+ public String toString() {
+ return "JpaExecutionRef{" +
+ "task=" + task +
+ '}';
+ }
+ }
- for (Map.Entry<String, Object> entry : jobExecutionContext.getMergedJobDataMap().entrySet()) {
- log.info("{} = {}, class= {}", entry.getKey(), entry.getValue(), entry.getValue() != null ? entry.getValue().getClass() : "<null>");
- }
+ private class CheckTimerTask implements Runnable {
+ private final AsyncCallable callable;
+ private final JpaQueueRef queueRef;
+
+ private CheckTimerTask(AsyncCallable callable, JpaQueueRef queueRef) {
+ this.callable = callable;
+ this.queueRef = queueRef;
+ }
+
+ public void run() {
+ log.info("JpaAsyncService$CheckTimerTask.run");
- int index = jobExecutionContext.getMergedJobDataMap().getIntFromString("index");
- AsyncCallable callable = context.callables.get(index);
+ List<Task> tasks = taskRepository.findByQueueAndCompletedIsNull(queueRef.queue);
- log.info("Calling {}", callable);
- callable.run();
+ System.out.println("tasks.size() = " + tasks.size());
- } catch (Throwable e) {
- log.warn("fail", e);
-// throw new JobExecutionException(e, false);
+ try {
+ for (final Task task : tasks) {
+ try {
+ executeTask(task);
+ } catch (TransactionException e) {
+ log.warn("Task execution failed", e);
+ }
+ }
+ } catch (Exception e) {
+ log.warn("Error while execution tasks.", e);
}
}
+
+ private void executeTask(final Task task) {
+ final Date run = new Date();
+ log.info("Setting last run on task. date = {}, task = {}", run, task);
+ transactionTemplate.execute(new TransactionCallbackWithoutResult() {
+ protected void doInTransactionWithoutResult(TransactionStatus status) {
+ task.registerRun();
+ taskRepository.save(task);
+ }
+ });
+
+ transactionTemplate.execute(new TransactionCallbackWithoutResult() {
+ protected void doInTransactionWithoutResult(TransactionStatus status) {
+ try {
+ callable.run();
+ Date completed = new Date();
+ log.info("Setting completed on task. date = {}, task = {}", completed, task);
+ task.registerComplete(completed);
+ taskRepository.save(task);
+ } catch (Exception e) {
+ throw new RuntimeException("Error while executing callback", e);
+ }
+ }
+ });
+ }
}
- public static class JpaDataSourceJobStore extends JobStoreSupport {
+ private class MyTransactionSynchronization implements TransactionSynchronization {
+
+ private final AsyncCallable callable;
- public JpaDataSourceJobStore() {
- setDataSource("wat");
+ private final int interval;
+
+ private final JpaQueueRef queueRef;
+
+ public MyTransactionSynchronization(AsyncCallable callable, int interval, JpaQueueRef queueRef) {
+ this.callable = callable;
+ this.interval = interval;
+ this.queueRef = queueRef;
}
- protected Connection getNonManagedTXConnection() throws JobPersistenceException {
-// DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
-// definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
-// TransactionStatus transaction = transactionManagerStatic.getTransaction(definition);
+ public void suspend() {
+ }
-// System.out.println("dataSourceStatic = " + dataSourceStatic);
- Connection c = DataSourceUtils.getConnection(dataSourceStatic);
- try {
- c.setAutoCommit(false);
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
-// System.out.println("c = " + c);
+ public void resume() {
+ }
- return c;
+ public void flush() {
}
- protected void closeConnection(Connection c) {
- try {
- DataSourceUtils.doCloseConnection(c, dataSourceStatic);
- } catch (SQLException e) {
- e.printStackTrace();
- }
+ public void beforeCommit(boolean readOnly) {
+ }
+ public void beforeCompletion() {
}
- protected Object executeInLock(String lockName, TransactionCallback txCallback) throws JobPersistenceException {
- return executeInNonManagedTXLock(lockName, txCallback);
+ public void afterCommit() {
+ }
+
+ public void afterCompletion(int status) {
+ log.info("status = {}", status);
+ if (status == TransactionSynchronization.STATUS_COMMITTED) {
+ executor.scheduleAtFixedRate(new CheckTimerTask(callable, queueRef), 1000, 1000 * interval, MILLISECONDS);
+ }
}
}
}
diff --git a/src/main/java/io/trygvis/spring/Config.java b/src/main/java/io/trygvis/spring/Config.java
index 6bc8960..5df4dac 100755
--- a/src/main/java/io/trygvis/spring/Config.java
+++ b/src/main/java/io/trygvis/spring/Config.java
@@ -119,7 +119,7 @@ public class Config {
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
@Value("${hibernate.hbm2ddl.auto}") String hbm2ddl,
- @Value("${hibernate.showSql}") boolean showSql,
+ @Value("${hibernate.showSql:false}") boolean showSql,
@Value("${hibernate.dialect}") String dialect) {
LocalContainerEntityManagerFactoryBean x = new LocalContainerEntityManagerFactoryBean();
x.setDataSource(dataSource);
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml
index 5fa174f..39e3dbd 100755
--- a/src/main/resources/logback.xml
+++ b/src/main/resources/logback.xml
@@ -1,21 +1,15 @@
<configuration debug="false">
<logger name="io.trygvis" level="DEBUG"/>
-<!--
+<!-- <logger name="org.springframework" level="INFO"/> -->
<logger name="org.springframework" level="INFO"/>
--->
- <logger name="org.springframework" level="INFO"/>
- <logger name="org.springframework.scheduling" level="DEBUG"/>
- <logger name="org.springframework.jdbc.core.JdbcTemplate" level="DEBUG"/>
- <logger name="org.hibernate" level="DEBUG"/>
- <logger name="org.quartz" level="DEBUG"/>
- <logger name="org.quartz.impl.jdbcjobstore.SimpleSemaphore" level="INFO"/>
-<!--
- <logger name="org" level="INFO"/>
- <logger name="net" level="INFO"/>
- <logger name="com" level="INFO"/>
--->
- <logger name="com.jolbox" level="DEBUG"/>
+ <logger name="org.springframework.jdbc" level="INFO"/>
+ <logger name="org.springframework.orm" level="INFO"/>
+
+ <logger name="org.hibernate" level="INFO"/>
+ <logger name="org.hibernate.SQL" level="INFO"/>
+
+ <logger name="com.jolbox" level="INFO"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>