Skip to content

Commit

Permalink
简化接口定义方法
Browse files Browse the repository at this point in the history
  • Loading branch information
xlorne committed Nov 29, 2017
1 parent 016269f commit b672172
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@
*/
public interface ILCNResource<T> {

void close() throws Exception;

/**
* 用于关闭时检查是否未删除
* @return TxTask任务对象
*/
TxTask getWaitTask();

/**
* 事务组id
* @return
*/
String getGroupId();

void transaction() throws Exception;

/**
* 是否是重复调用执行
* @param isGroup
*/
void setHasIsGroup(boolean isGroup);

T get();

int getMaxOutTime();
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,8 @@ public void setHasIsGroup(boolean isGroup) {
hasGroup = isGroup;
}

public int getMaxOutTime() {
return maxOutTime;
}

private boolean hasClose = false;

@Override
public Connection get() {
return connection;
}

@Override
public void commit() throws SQLException {
Expand Down Expand Up @@ -172,7 +164,6 @@ public void run0() {
}


@Override
public void transaction() throws SQLException {
if (waitTask == null) {
connection.rollback();
Expand All @@ -183,14 +174,14 @@ public void transaction() throws SQLException {

//start 结束就是全部事务的结束表示,考虑start挂掉的情况
Timer timer = new Timer();
logger.info("maxOutTime:" + getMaxOutTime());
logger.info("maxOutTime:" + maxOutTime);
timer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("auto execute ,groupId:" + getGroupId());
dataSourceService.schedule(getGroupId(), waitTask);
}
}, getMaxOutTime());
}, maxOutTime);

System.out.println("transaction is wait for TxManager notify, groupId : " + getGroupId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,12 @@ public String getGroupId() {
return groupId;
}

public int getMaxOutTime() {
return maxOutTime;
}

@Override
public void setHasIsGroup(boolean isGroup) {
hasGroup = isGroup;
}

@Override
public RedisConnection get() {
return redisConnection;
}

public LCNRedisConnection(RedisConnection redisConnection, DataSourceService dataSourceService, TxTransactionLocal transactionLocal, ICallClose<LCNRedisConnection> runnable) {
this.redisConnection = redisConnection;
Expand Down Expand Up @@ -124,7 +117,6 @@ public List<Object> exec() {
return null;
}

@Override
public void transaction() throws Exception {
if (waitTask == null) {
redisConnection.close();
Expand All @@ -140,7 +132,7 @@ public void run() {
System.out.println("自动回滚->" + getGroupId());
dataSourceService.schedule(getGroupId(), waitTask);
}
}, getMaxOutTime());
}, maxOutTime);

System.out.println("transaction-awaitTask->" + getGroupId());
waitTask.awaitTask();
Expand Down

0 comments on commit b672172

Please sign in to comment.