etreschenkov 2023-05-29 14:21:52 +03:00
parent 751da613a5
commit 537f8a3ff6
6 changed files with 64 additions and 6 deletions

View file

@ -5,10 +5,14 @@ import org.slf4j.LoggerFactory;
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.platform.enumeration.Section;
import ru.spcex.platform.enumeration.SessionStatus;
import ru.spcex.platform.enumeration.SessionType;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.utils.enumeration.IMessageResolver;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
public abstract class AbstractSession {
@ -26,12 +30,12 @@ public abstract class AbstractSession {
this.messageResolver = messageResolver;
}
protected <T, R> StageResult<R> runStage(TaskType type, ISessionStage stage) {
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) {
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);
@ -48,6 +52,7 @@ public abstract class AbstractSession {
}
protected abstract void runSession(BaseRequest<?> req);
protected void endSession() {
synchronized (this.currStage) {
this.currStage.set(null);
@ -73,4 +78,16 @@ public abstract class AbstractSession {
}
}
protected boolean checkIsActive() {
Session activeSession = sessionImdg.getSingleObjectByFieldValues(Map.of(
"sectionType", sectionType().getKey(),
"section", section().getKey(),
"sessionStatus", SessionStatus.ACTV.getKey())
);
return activeSession != null;
}
protected abstract Section section();
protected abstract SessionType sectionType();
}

View file

@ -163,4 +163,14 @@ public class PrimaryAuctionB0Session extends AbstractSession implements Initiali
}
}
}
@Override
protected Section section() {
return Section.FOND;
}
@Override
protected SessionType sectionType() {
return SessionType.IPO0;
}
}

View file

@ -201,4 +201,14 @@ public class PrimaryAuctionBnSession extends AbstractSession implements Initiali
}
}
}
@Override
protected Section section() {
return Section.FOND;
}
@Override
protected SessionType sectionType() {
return SessionType.IPOB;
}
}

View file

@ -163,4 +163,14 @@ public class PrimaryAuctionT0Session extends AbstractSession implements Initiali
}
}
}
@Override
protected Section section() {
return Section.FOND;
}
@Override
protected SessionType sectionType() {
return SessionType.IPOT;
}
}

View file

@ -201,4 +201,14 @@ public class SecondaryAuctionT0Session extends AbstractSession implements Initia
}
}
}
@Override
protected Section section() {
return Section.FOND;
}
@Override
protected SessionType sectionType() {
return SessionType.TRDT;
}
}

View file

@ -25,7 +25,7 @@ public class SessionManager {
}
public void defineAndStartSession(LauncherCommandRequest commandRequest) {
Long sessionId = commandRequest.getSessionId();
// Long sessionId = commandRequest.getSessionId();
SessionType sessionType = IEnumKey.getEnumByKey(SessionType.class, commandRequest.getSessionType());
Section section = IEnumKey.getEnumByKey(Section.class, commandRequest.getSection());
if (sessionType == null || section == null) {
@ -35,12 +35,13 @@ public class SessionManager {
BaseRequest<?> baseRequest = new BaseRequest<>();
AbstractSession session = null;
switch (sessionType){
case IPOB : session = primaryAuctionBnSession;
case IPOT : session = primaryAuctionT0Session;
case IPO0 : session = primaryAuctionBnSession;
case IPOB -> session = primaryAuctionBnSession;
case IPOT -> session = primaryAuctionT0Session;
case IPO0 -> session = primaryAuctionB0Session;
}
if (session != null) {
//checkActive
session.runSession(baseRequest);
}
}