提交 2a3667c3 编写于 作者: W WangKai

fix some checkstyle

上级 05813876
......@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
......@@ -28,7 +28,7 @@ import lombok.Setter;
*/
@Getter
@Setter
public class AsyncSoftTransactionJobConfiguration {
public final class AsyncSoftTransactionJobConfiguration {
/**
* Job name.
......
......@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
......@@ -34,20 +34,22 @@ import java.util.List;
* @author wangkai
*/
@Slf4j
public class QuartzJob implements Job {
public final class QuartzJob implements Job {
@Override
public void execute(final JobExecutionContext jobExecutionContext) {
QuartzJobConfiguration quartzJobConfiguration = (QuartzJobConfiguration)jobExecutionContext.getJobDetail().getJobDataMap().get("quartzJobConfiguration");
TransactionLogStorage transactionLogStorage = (TransactionLogStorage)jobExecutionContext.getJobDetail().getJobDataMap().get("transactionLogStorage");
List<TransactionLog> TransactionLogList = transactionLogStorage.findEligibleTransactionLogs(quartzJobConfiguration.getJobConfig().getTransactionLogFetchDataCount(),
QuartzJobConfiguration quartzJobConfiguration = (QuartzJobConfiguration) jobExecutionContext.getJobDetail().getJobDataMap().get("quartzJobConfiguration");
TransactionLogStorage transactionLogStorage = (TransactionLogStorage) jobExecutionContext.getJobDetail().getJobDataMap().get("transactionLogStorage");
List<TransactionLog> transactionLogList = transactionLogStorage.findEligibleTransactionLogs(quartzJobConfiguration.getJobConfig().getTransactionLogFetchDataCount(),
quartzJobConfiguration.getJobConfig().getMaxDeliveryTryTimes(), quartzJobConfiguration.getJobConfig().getMaxDeliveryTryDelayMillis());
for (TransactionLog data : TransactionLogList) {
try (Connection conn = quartzJobConfiguration.getTargetDataSource(data.getDataSource()).getConnection()) {
transactionLogStorage.processData(conn, data, quartzJobConfiguration.getJobConfig().getMaxDeliveryTryTimes());
} catch (final SQLException | TransactionCompensationException ex) {
log.error(String.format("Async delivery times %s error, max try times is %s, exception is %s", data.getAsyncDeliveryTryTimes() + 1,
quartzJobConfiguration.getJobConfig().getMaxDeliveryTryTimes(), ex.getMessage()));
if (transactionLogList != null) {
for (TransactionLog data : transactionLogList) {
try (Connection conn = quartzJobConfiguration.getTargetDataSource(data.getDataSource()).getConnection()) {
transactionLogStorage.processData(conn, data, quartzJobConfiguration.getJobConfig().getMaxDeliveryTryTimes());
} catch (final SQLException | TransactionCompensationException ex) {
log.error(String.format("Async delivery times %s error, max try times is %s, exception is %s", data.getAsyncDeliveryTryTimes() + 1,
quartzJobConfiguration.getJobConfig().getMaxDeliveryTryTimes(), ex.getMessage()));
}
}
}
}
......
......@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
......@@ -31,7 +31,7 @@ import java.util.Map;
*/
@Getter
@Setter
public class QuartzJobConfiguration {
public final class QuartzJobConfiguration {
/**
* Data source for transaction manager.
......@@ -48,10 +48,21 @@ public class QuartzJobConfiguration {
*/
private io.shardingjdbc.transaction.config.AsyncSoftTransactionJobConfiguration jobConfig;
/**
* Get one data source by name.
*
* @param dataSourceName data source name
* @return dataSourceName object
*/
public DataSource getTargetDataSource(final String dataSourceName) {
return targetDataSource.get(dataSourceName);
}
/**
* Get next one transaction log data sorce.
*
* @return next one transaction log data sorce
*/
public DataSource getDefaultTransactionLogDataSource() {
return transactionLogDataSource.values().iterator().next();
}
......
......@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
......@@ -20,7 +20,14 @@ package io.shardingjdbc.transaction.job;
import io.shardingjdbc.transaction.datasource.impl.RdbTransactionLogDataSource;
import io.shardingjdbc.transaction.storage.TransactionLogStorageFactory;
import lombok.RequiredArgsConstructor;
import org.quartz.*;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.JobBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.CronScheduleBuilder;
import org.quartz.impl.StdSchedulerFactory;
/**
......@@ -35,6 +42,8 @@ public final class QuartzJobFactory {
/**
* start job.
*
* @throws SchedulerException quartz scheduler exception
*/
public void start() throws SchedulerException {
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
......@@ -45,8 +54,9 @@ public final class QuartzJobFactory {
private JobDetail buildJobDetail() {
JobDetail jobDetail = JobBuilder.newJob(QuartzJob.class).withIdentity(quartzJobConfiguration.getJobConfig().getName() + "-Job").build();
jobDetail.getJobDataMap().put("quartzJobConfiguration",quartzJobConfiguration);
jobDetail.getJobDataMap().put("transactionLogStorage", TransactionLogStorageFactory.createTransactionLogStorage(new RdbTransactionLogDataSource(quartzJobConfiguration.getDefaultTransactionLogDataSource())));
jobDetail.getJobDataMap().put("quartzJobConfiguration", quartzJobConfiguration);
jobDetail.getJobDataMap().put("transactionLogStorage",
TransactionLogStorageFactory.createTransactionLogStorage(new RdbTransactionLogDataSource(quartzJobConfiguration.getDefaultTransactionLogDataSource())));
return jobDetail;
}
......
......@@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册