diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-06-04 20:54:56 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-06-04 20:54:56 +0200 |
commit | 7465fdb9aa847d29dacc56adbe473f1c1ceb298e (patch) | |
tree | d04b5c859fc090a57355e7bc0e51a043cddc907b /src/main/java/io/trygvis/async/spring | |
parent | 1eeef021c65c85c24d62a0cc1ee4a746a601beb5 (diff) | |
download | quartz-based-queue-7465fdb9aa847d29dacc56adbe473f1c1ceb298e.tar.gz quartz-based-queue-7465fdb9aa847d29dacc56adbe473f1c1ceb298e.tar.bz2 quartz-based-queue-7465fdb9aa847d29dacc56adbe473f1c1ceb298e.tar.xz quartz-based-queue-7465fdb9aa847d29dacc56adbe473f1c1ceb298e.zip |
o Creating a QueueService on top of the DAOs.
Diffstat (limited to 'src/main/java/io/trygvis/async/spring')
-rw-r--r-- | src/main/java/io/trygvis/async/spring/SpringJdbcAsyncService.java | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/src/main/java/io/trygvis/async/spring/SpringJdbcAsyncService.java b/src/main/java/io/trygvis/async/spring/SpringJdbcAsyncService.java deleted file mode 100644 index 327dffa..0000000 --- a/src/main/java/io/trygvis/async/spring/SpringJdbcAsyncService.java +++ /dev/null @@ -1,100 +0,0 @@ -package io.trygvis.async.spring; - -import io.trygvis.async.AsyncService; -import io.trygvis.async.JdbcAsyncService; -import io.trygvis.async.SqlEffectExecutor; -import io.trygvis.queue.Queue; -import io.trygvis.queue.Task; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.jdbc.core.ConnectionCallback; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.support.TransactionSynchronization; -import org.springframework.transaction.support.TransactionSynchronizationAdapter; -import org.springframework.transaction.support.TransactionTemplate; - -import java.sql.Connection; -import java.sql.SQLException; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledThreadPoolExecutor; - -import static org.springframework.transaction.annotation.Propagation.REQUIRED; -import static org.springframework.transaction.support.TransactionSynchronizationManager.registerSynchronization; - -public class SpringJdbcAsyncService implements AsyncService { - private final Logger log = LoggerFactory.getLogger(getClass()); - - private final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10, Executors.defaultThreadFactory()); - - private final TransactionTemplate transactionTemplate; - - private final JdbcTemplate jdbcTemplate; - - private SqlEffectExecutor sqlEffectExecutor; - - final JdbcAsyncService jdbcAsyncService; - - public SpringJdbcAsyncService(TransactionTemplate transactionTemplate, JdbcTemplate jdbcTemplate) { - this.transactionTemplate = transactionTemplate; - this.jdbcTemplate = jdbcTemplate; - jdbcAsyncService = new JdbcAsyncService(); - sqlEffectExecutor = new SqlEffectExecutor(this.jdbcTemplate.getDataSource()); - } - - @Transactional(propagation = REQUIRED) - public Queue registerQueue(final String name, final int interval, final AsyncService.AsyncCallable callable) { - return jdbcTemplate.execute(new ConnectionCallback<Queue>() { - @Override - public Queue doInConnection(Connection c) throws SQLException { - - Queue q = jdbcAsyncService.registerQueue(c, sqlEffectExecutor, name, interval, callable); - - registerSynchronization(new TransactionSynchronizationAdapter() { - public void afterCompletion(int status) { - log.info("Transaction completed with status = {}", status); - if (status == TransactionSynchronization.STATUS_COMMITTED) { - jdbcAsyncService.startQueue(executor, name); - } - } - }); - - log.info("registerQueue: LEAVE"); - return q; - } - }); - } - - public Queue getQueue(String name) { - return jdbcAsyncService.getQueue(name); - } - - @Transactional(propagation = REQUIRED) - public Task schedule(final Queue queue, final String... args) { - return jdbcTemplate.execute(new ConnectionCallback<Task>() { - @Override - public Task doInConnection(Connection c) throws SQLException { - return jdbcAsyncService.schedule(c, queue, args); - } - }); - } - - public Task schedule(final long parent, final Queue queue, final String... args) { - return jdbcTemplate.execute(new ConnectionCallback<Task>() { - @Override - public Task doInConnection(Connection c) throws SQLException { - return jdbcAsyncService.schedule(c, parent, queue, args); - } - }); - } - - @Transactional(readOnly = true) - public Task update(final Task ref) { - return jdbcTemplate.execute(new ConnectionCallback<Task>() { - @Override - public Task doInConnection(Connection c) throws SQLException { - return jdbcAsyncService.update(c, ref); - } - }); - } -} |