*/
public SCSubscribeMessage subscribe(int operationTimeoutSeconds, SCSubscribeMessage scSubscribeMessage,
SCMessageCallback scMessageCallback) throws SCServiceException, SCMPValidatorException {
// 1. checking preconditions and initialize
if (this.sessionActive) {
throw new SCServiceException(this.serviceName + " already subscribed.");
}
if (scSubscribeMessage == null) {
throw new SCMPValidatorException("Subscribe message (scSubscribeMessage) must not be null.");
}
if (scMessageCallback == null) {
throw new SCMPValidatorException("Callback must be set.");
}
this.noDataIntervalSeconds = scSubscribeMessage.getNoDataIntervalSeconds();
String mask = scSubscribeMessage.getMask();
ValidatorUtility.validateMask(mask, SCMPError.HV_WRONG_MASK);
this.messageCallback = scMessageCallback;
this.requester.getSCMPMsgSequenceNr().reset();
// 2. initialize call & invoke
SCServiceCallback callback = new SCServiceCallback(true);
SCMPClnSubscribeCall subscribeCall = new SCMPClnSubscribeCall(this.requester, this.serviceName);
subscribeCall.setMask(scSubscribeMessage.getMask());
subscribeCall.setSessionInfo(scSubscribeMessage.getSessionInfo());
subscribeCall.setNoDataIntervalSeconds(scSubscribeMessage.getNoDataIntervalSeconds());
subscribeCall.setCompressed(scSubscribeMessage.isCompressed());
subscribeCall.setRequestBody(scSubscribeMessage.getData());
try {
subscribeCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
} catch (Exception e) {
throw new SCServiceException("Subscribe failed.", e);
}
// 3. receiving reply and error handling
SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
if (reply.isFault() || reply.getHeaderFlag(SCMPHeaderAttributeKey.REJECT_SESSION)) {
// reply is fault or rejected
SCServiceException ex = new SCServiceException("Subscribe failed.");
ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
ex.setAppErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.APP_ERROR_CODE));
ex.setAppErrorText(reply.getHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT));
throw ex;
}
// 4. post process, reply to client
this.sessionId = reply.getSessionId();
this.sessionActive = true;