This commit is contained in:
parent
28d7176a5c
commit
3dcb785ebb
3 changed files with 74 additions and 55 deletions
|
|
@ -0,0 +1,68 @@
|
||||||
|
package ru.spcex.clearing.session.stage;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import ru.clearing.classes.statics.data.misc.Session;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
public class AbstractSession {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
protected final Imdg<Session> sessionImdg;
|
||||||
|
protected final IMessageResolver messageResolver;
|
||||||
|
protected final AtomicReference<TaskType> currStage = new AtomicReference<>();
|
||||||
|
protected Session currSession;
|
||||||
|
|
||||||
|
public AbstractSession(
|
||||||
|
ImdgProvider imdgProvider,
|
||||||
|
IMessageResolver messageResolver) {
|
||||||
|
this.sessionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Session, Session.class);
|
||||||
|
this.messageResolver = messageResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <T, R> StageResult<R> runStage(TaskType type, ISessionStage stage) {
|
||||||
|
return runStage(type, null, stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
protected <T, R> StageResult<R> runStage(TaskType type, T payload, ISessionStage stage) {
|
||||||
|
continueRunning(type);
|
||||||
|
log.info("session.id={} step {} started", currSession.getId(), currStage.get());
|
||||||
|
Task<T> t = new Task<>(type, payload);
|
||||||
|
StageResult<?> stgRes = stage.submit(t);
|
||||||
|
log.info("session.id={} step {} result: {} ",
|
||||||
|
currSession.getId(),
|
||||||
|
currStage.get(),
|
||||||
|
stgRes.success ? "success" : messageResolver.resolve(stgRes.error));
|
||||||
|
if (!stgRes.success) {
|
||||||
|
endSession();
|
||||||
|
throw new StageException();
|
||||||
|
}
|
||||||
|
return (StageResult<R>) stgRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void endSession() {
|
||||||
|
synchronized (this.currStage) {
|
||||||
|
this.currStage.set(null);
|
||||||
|
this.currSession = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void continueRunning(TaskType t) {
|
||||||
|
synchronized (this.currStage) {
|
||||||
|
this.currStage.set(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean checkStage(TaskType t) {
|
||||||
|
synchronized (this.currStage) {
|
||||||
|
return this.currStage.get().equals(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -5,22 +5,19 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.clearing.classes.statics.data.execution.ExecutionCommon;
|
import ru.clearing.classes.statics.data.execution.ExecutionCommon;
|
||||||
import ru.clearing.classes.statics.data.misc.Session;
|
import ru.clearing.classes.statics.data.misc.Session;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
|
||||||
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
||||||
import ru.spcex.clearing.session.stage.impl.*;
|
import ru.spcex.clearing.session.stage.impl.*;
|
||||||
import ru.spcex.clearing.session.stage.task.*;
|
import ru.spcex.clearing.session.stage.task.*;
|
||||||
import ru.spcex.platform.enumeration.Section;
|
import ru.spcex.platform.enumeration.Section;
|
||||||
import ru.spcex.platform.enumeration.SessionStatus;
|
import ru.spcex.platform.enumeration.SessionStatus;
|
||||||
import ru.spcex.platform.enumeration.SessionType;
|
import ru.spcex.platform.enumeration.SessionType;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PrimaryAuctionBnSession {
|
public class PrimaryAuctionBnSession extends AbstractSession {
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
private final BalanceRevise balanceRevise;
|
private final BalanceRevise balanceRevise;
|
||||||
private final DealsPrepare dealsPrepare;
|
private final DealsPrepare dealsPrepare;
|
||||||
|
|
@ -34,11 +31,6 @@ public class PrimaryAuctionBnSession {
|
||||||
private final FinishingSession finishingSession;
|
private final FinishingSession finishingSession;
|
||||||
private final EndStageNotification endStageNotification;
|
private final EndStageNotification endStageNotification;
|
||||||
|
|
||||||
private Imdg<Session> sessionImdg;
|
|
||||||
private final IMessageResolver messageResolver;
|
|
||||||
private final AtomicReference<TaskType> currStage = new AtomicReference<>();
|
|
||||||
private Session currSession;
|
|
||||||
|
|
||||||
public PrimaryAuctionBnSession(
|
public PrimaryAuctionBnSession(
|
||||||
ImdgProvider imdgProvider,
|
ImdgProvider imdgProvider,
|
||||||
BalanceRevise balanceRevise,
|
BalanceRevise balanceRevise,
|
||||||
|
|
@ -50,6 +42,7 @@ public class PrimaryAuctionBnSession {
|
||||||
FormingPaymentInstruction formingPaymentInstruction,
|
FormingPaymentInstruction formingPaymentInstruction,
|
||||||
UnlockResources unlockResources,
|
UnlockResources unlockResources,
|
||||||
FinishingSession finishingSession, EndStageNotification endStageNotification, IMessageResolver messageResolver) {
|
FinishingSession finishingSession, EndStageNotification endStageNotification, IMessageResolver messageResolver) {
|
||||||
|
super(imdgProvider, messageResolver);
|
||||||
this.balanceRevise = balanceRevise;
|
this.balanceRevise = balanceRevise;
|
||||||
this.dealsPrepare = dealsPrepare;
|
this.dealsPrepare = dealsPrepare;
|
||||||
this.requirementsAndObligationCreation = requirementsAndObligationCreation;
|
this.requirementsAndObligationCreation = requirementsAndObligationCreation;
|
||||||
|
|
@ -60,9 +53,6 @@ public class PrimaryAuctionBnSession {
|
||||||
this.unlockResources = unlockResources;
|
this.unlockResources = unlockResources;
|
||||||
this.finishingSession = finishingSession;
|
this.finishingSession = finishingSession;
|
||||||
this.endStageNotification = endStageNotification;
|
this.endStageNotification = endStageNotification;
|
||||||
|
|
||||||
this.sessionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Session, Session.class);
|
|
||||||
this.messageResolver = messageResolver;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runSession(BaseRequest<?> req) {
|
public void runSession(BaseRequest<?> req) {
|
||||||
|
|
@ -135,27 +125,6 @@ public class PrimaryAuctionBnSession {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T, R> StageResult<R> runStage(TaskType type, ISessionStage stage) {
|
|
||||||
return runStage(type, null, stage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private <T, R> StageResult<R> runStage(TaskType type, T payload, ISessionStage stage) {
|
|
||||||
continueRunning(type);
|
|
||||||
log.info("session.id={} step {} started", currSession.getId(), currStage.get());
|
|
||||||
Task<T> t = new Task<>(type, payload);
|
|
||||||
StageResult<?> stgRes = stage.submit(t);
|
|
||||||
log.info("session.id={} step {} result: {} ",
|
|
||||||
currSession.getId(),
|
|
||||||
currStage.get(),
|
|
||||||
stgRes.success ? "success" : messageResolver.resolve(stgRes.error));
|
|
||||||
if (!stgRes.success) {
|
|
||||||
endSession();
|
|
||||||
throw new StageException();
|
|
||||||
}
|
|
||||||
return (StageResult<R>) stgRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean startSession() {
|
private boolean startSession() {
|
||||||
synchronized (this.currStage) {
|
synchronized (this.currStage) {
|
||||||
if (this.currStage.get() != null) {
|
if (this.currStage.get() != null) {
|
||||||
|
|
@ -175,26 +144,4 @@ public class PrimaryAuctionBnSession {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endSession() {
|
|
||||||
synchronized (this.currStage) {
|
|
||||||
this.currStage.set(null);
|
|
||||||
this.currSession = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void continueRunning(TaskType t) {
|
|
||||||
synchronized (this.currStage) {
|
|
||||||
this.currStage.set(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkStage(TaskType t) {
|
|
||||||
synchronized (this.currStage) {
|
|
||||||
return this.currStage.get().equals(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class StageException extends RuntimeException {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package ru.spcex.clearing.session.stage;
|
||||||
|
|
||||||
|
class StageException extends RuntimeException {
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue