break;
}
int otiOnSCMillis = (int) (oti * basicConf.getOperationTimeoutMultiplier());
String sessionId = reqMessage.getSessionId();
Session session = this.getSessionById(sessionId);
if (session.hasPendingRequest() == true) {
LOGGER.warn("sid=" + sessionId + " has pending request");
SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.PARALLEL_REQUEST, "service="
+ reqMessage.getServiceName() + " sid=" + sessionId);
scmpCommandException.setMessageType(this.getKey());
throw scmpCommandException;
}
// sets the time of last execution
session.resetExecuteTime();
synchronized (session) {
session.setPendingRequest(true); // IMPORTANT - set true before reset timeout - because of parallel echo call
// reset session timeout to OTI+ECI - during wait for server reply
this.sessionRegistry.resetSessionTimeout(session, (otiOnSCMillis + session.getSessionTimeoutMillis()));
}
if (cache.isCacheEnabled()) {
try {
// try to load response from cache
SCMPMessage message = cache.tryGetMessageFromCacheOrLoad(reqMessage);
if (message != null) {
synchronized (session) {
// reset session timeout to ECI
this.sessionRegistry.resetSessionTimeout(session, session.getSessionTimeoutMillis());
session.setPendingRequest(false); // IMPORTANT - set false after reset timeout - parallel echo call
}
// message found in cache - hand it to the client
response.setSCMP(message);
responderCallback.responseCallback(request, response);
return;
}
} catch (Exception e) {
synchronized (session) {
// reset session timeout to ECI
this.sessionRegistry.resetSessionTimeout(session, session.getSessionTimeoutMillis());
session.setPendingRequest(false); // IMPORTANT - set false after reset timeout - because of parallel echo call
}
throw e;
}
}
ExecuteCommandCallback callback = null;
StatefulServer server = session.getStatefulServer();
int tries = (otiOnSCMillis / Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);
// Following loop implements the wait mechanism in case of a busy connection pool
int i = 0;
do {
// reset msgType, might have been modified in below execute try
reqMessage.setMessageType(this.getKey());
callback = new ExecuteCommandCallback(request, response, responderCallback, sessionId);
try {
server.execute(reqMessage, callback, otiOnSCMillis - (i * Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS));
// no exception has been thrown - get out of wait loop
break;
} catch (ConnectionPoolBusyException ex) {
LOGGER.debug("ConnectionPoolBusyException caught in wait mec of csc execute, tries left=" + tries);
if (i >= (tries - 1)) {
// only one loop outstanding - don't continue throw current exception
synchronized (session) {
// reset session timeout to ECI
this.sessionRegistry.resetSessionTimeout(session, session.getSessionTimeoutMillis());
session.setPendingRequest(false); // IMPORTANT - set false after reset - because of parallel echo call
}
LOGGER.debug(SCMPError.NO_FREE_CONNECTION.getErrorText("service=" + reqMessage.getServiceName()));
SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.NO_FREE_CONNECTION, "service="
+ reqMessage.getServiceName());
scmpCommandException.setMessageType(this.getKey());