* error message received from SC <br />
*/
public synchronized void attach(int operationTimeoutSeconds) throws SCServiceException, SCMPValidatorException {
// 1. checking preconditions and validate
if (this.attached) {
throw new SCServiceException("SCClient already attached.");
}
if (host == null) {
throw new SCMPValidatorException("Host is missing.");
}
ValidatorUtility.validateInt(Constants.MIN_PORT_VALUE, this.port, Constants.MAX_PORT_VALUE, SCMPError.HV_WRONG_PORTNR);
// 2. initialize call & invoke
synchronized (AppContext.communicatorsLock) {
AppContext.init();
RemoteNodeConfiguration remoteNodeConf = new RemoteNodeConfiguration(this.port + "client", this.host, this.port,
this.connectionType.getValue(), this.keepAliveIntervalSeconds, 0, this.maxConnections);
this.requester = new SCRequester(remoteNodeConf, this.keepAliveTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
SCServiceCallback callback = new SCServiceCallback(true);
SCMPAttachCall attachCall = new SCMPAttachCall(this.requester);
try {
attachCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
} catch (Exception e) {
this.requester.destroy();
// release resources
AppContext.destroy();
throw new SCServiceException("Attach to " + host + ":" + port + " failed. ", e);
}
// 3. receiving reply and error handling
SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
if (reply.isFault()) {
this.requester.destroy();
// release resources
AppContext.destroy();
SCServiceException ex = new SCServiceException("Attach to " + host + ":" + port + " failed.");
ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
throw ex;
}
// 4. post process, reply to client
this.attached = true;
AppContext.attachedCommunicators.incrementAndGet();