Package org.serviceconnector.api

Examples of org.serviceconnector.api.SCServiceException


      return;
    }
    if (reply.isFault()) {
      this.service.sessionActive = false;
      // operation failed
      SCServiceException ex = new SCServiceException("SCPublishService operation failed sid=" + this.service.sessionId);
      ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
      ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
      super.receive(ex);
      return;
    }
    // 4. post process, reply to client
    boolean noData = reply.getHeaderFlag(SCMPHeaderAttributeKey.NO_DATA);
View Full Code Here


   */
  public synchronized SCMessage createSession(int operationTimeoutSeconds, SCMessage scMessage, SCMessageCallback messageCallback)
      throws SCServiceException, SCMPValidatorException {
    // 1. checking preconditions and initialize
    if (this.sessionActive) {
      throw new SCServiceException("Session already created - delete session first.");
    }
    if (messageCallback == null) {
      throw new SCMPValidatorException("Message callback must be set.");
    }
    if (scMessage == null) {
      throw new SCMPValidatorException("Message (scMessage) must be set.");
    }
    // reset pendingRequest - necessary if service instances reused
    this.pendingRequest = false;
    this.messageCallback = messageCallback;
    this.requester.getSCMPMsgSequenceNr().reset();
    // 2. initialize call & invoke
    SCMPClnCreateSessionCall createSessionCall = new SCMPClnCreateSessionCall(this.requester, this.serviceName);
    createSessionCall.setRequestBody(scMessage.getData());
    createSessionCall.setCompressed(scMessage.isCompressed());
    createSessionCall.setSessionInfo(scMessage.getSessionInfo());
    createSessionCall.setEchoIntervalSeconds(this.echoIntervalSeconds);
    SCServiceCallback callback = new SCServiceCallback(true);
    try {
      createSessionCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    } catch (Exception e) {
      throw new SCServiceException("Create session 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)) {
      SCServiceException ex = new SCServiceException("Create session 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;
    }
    this.sessionId = reply.getSessionId();
    this.sessionActive = true;
    // 4. post process, reply to client
View Full Code Here

   */
  public synchronized SCMessage execute(int operationTimeoutSeconds, SCMessage scMessage) throws SCServiceException,
      SCMPValidatorException {
    // 1. checking preconditions and initialize
    if (this.sessionActive == false) {
      throw new SCServiceException("Execute not possible, no active session.");
    }
    if (this.pendingRequest) {
      // pending Request - reply still outstanding
      throw new SCServiceException("Execute not possible, there is a pending request - two pending request are not allowed.");
    }
    if (scMessage == null) {
      throw new SCMPValidatorException("Message (scMessage) must be set.");
    }
    this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
    // 2. initialize call & invoke
    SCMPClnExecuteCall clnExecuteCall = new SCMPClnExecuteCall(this.requester, this.serviceName, this.sessionId);
    clnExecuteCall.setMessageInfo(scMessage.getMessageInfo());
    clnExecuteCall.setCacheId(scMessage.getCacheId());
    clnExecuteCall.setCompressed(scMessage.isCompressed());
    clnExecuteCall.setPartSize(scMessage.getPartSize());
    clnExecuteCall.setRequestBody(scMessage.getData());
    SCServiceCallback callback = new SCServiceCallback(true);
    try {
      PerformanceLogger.beginThreadBound();
      clnExecuteCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    } catch (Exception e) {
      PerformanceLogger.endThreadBound(this.sessionId);
      throw new SCServiceException("Execute request failed. ", e);
    }
    // 3. receiving reply and error handling
    SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    PerformanceLogger.endThreadBound(this.sessionId);
    if (reply.isFault()) {
      SCServiceException scEx = new SCServiceException("Execute failed.");
      scEx.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
      scEx.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
      throw scEx;
    }
    // 4. post process, reply to client
    SCMessage replyToClient = new SCMessage();
    replyToClient.setData(reply.getBody());
View Full Code Here

   */
  public synchronized void send(int operationtTimeoutSeconds, SCMessage scMessage) throws SCServiceException,
      SCMPValidatorException {
    // 1. checking preconditions and initialize
    if (this.sessionActive == false) {
      throw new SCServiceException("Send not possible, no active session.");
    }
    if (this.pendingRequest) {
      // already executed before - reply still outstanding
      throw new SCServiceException("Send not possible, there is a pending request - two pending request are not allowed.");
    }
    if (scMessage == null) {
      throw new SCMPValidatorException("Message (scMessage) must be set.");
    }
    this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
    // important to set pendingRequest true in case of asynchronous communication
    this.pendingRequest = true;
    // 2. initialize call & invoke
    SCMPClnExecuteCall clnExecuteCall = new SCMPClnExecuteCall(this.requester, this.serviceName, this.sessionId);
    clnExecuteCall.setMessageInfo(scMessage.getMessageInfo());
    clnExecuteCall.setCacheId(scMessage.getCacheId());
    clnExecuteCall.setCompressed(scMessage.isCompressed());
    clnExecuteCall.setPartSize(scMessage.getPartSize());
    clnExecuteCall.setRequestBody(scMessage.getData());
    SCServiceCallback scmpCallback = new SCServiceCallback(this, this.messageCallback);
    try {
      clnExecuteCall.invoke(scmpCallback, operationtTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    } catch (Exception e) {
      this.pendingRequest = false;
      throw new SCServiceException("Send request failed. ", e);
    }
  }
View Full Code Here

      clnEchoCall.invoke(callback, this.echoTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    } catch (Exception e) {
      PerformanceLogger.endThreadBound(this.sessionId);
      // inactivate the session
      this.sessionActive = false;
      SCServiceException ex = new SCServiceException("Refreshing session by echo failed, service=" + this.serviceName
          + " sid=" + this.sessionId + ".");
      ex.setSCErrorCode(SCMPError.BROKEN_SESSION.getErrorCode());
      ex.setSCErrorText(SCMPError.BROKEN_SESSION.getErrorText("Can not send echo message for service=" + this.serviceName
          + " sid=" + this.sessionId + "."));
      this.messageCallback.receive(ex);
      return;
    }
    // 3. receiving reply and error handling
    SCMPMessage reply = callback.getMessageSync(this.echoTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    PerformanceLogger.endThreadBound(this.sessionId);
    if (reply.isFault()) {
      // inactivate the session
      this.sessionActive = false;
      SCServiceException ex = new SCServiceException("Refreshing session by echo failed, service=" + this.serviceName
          + " sid=" + this.sessionId + ".");
      ex.setSCErrorCode(SCMPError.BROKEN_SESSION.getErrorCode());
      ex.setSCErrorText(SCMPError.BROKEN_SESSION.getErrorText("Can not send echo message for service=" + this.serviceName
          + " sid=" + this.sessionId + "."));
      this.messageCallback.receive(ex);
      return;
    }
    // 4. post process, reply to client
View Full Code Here

      // delete session not possible - no session on this service just ignore
      return;
    }
    if (this.pendingRequest) {
      // pending request - reply still outstanding
      throw new SCServiceException(
          "Delete session not possible, there is a pending request - two pending request are not allowed.");
    }
    // cancel session timeout even if its running already
    this.cancelSessionTimeout(true);
    this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
    try {
      // 2. initialize call & invoke
      SCServiceCallback callback = new SCServiceCallback(true);
      SCMPClnDeleteSessionCall deleteSessionCall = new SCMPClnDeleteSessionCall(this.requester, this.serviceName,
          this.sessionId);
      if (scMessage != null) {
        // message might be null for deleteSession operation
        deleteSessionCall.setSessionInfo(scMessage.getSessionInfo());
      }
      try {
        deleteSessionCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        throw new SCServiceException("Delete session failed ", e);
      }
      // 3. receiving reply and error handling
      SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      if (reply.isFault()) {
        SCServiceException ex = new SCServiceException("Delete session failed.");
        ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
        ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
        throw ex;
      }
    } finally {
      // 4. post process, reply to client
      this.sessionId = null;
View Full Code Here

   *             publish message is not set<br />
   */
  public final void publish(int operationTimeoutSeconds, SCPublishMessage publishMessage) throws SCServiceException,
      SCMPValidatorException {
    if (this.registered == false) {
      throw new SCServiceException("Server is not registered for a service.");
    }
    if (publishMessage == null) {
      throw new SCMPValidatorException("Publish message is missing.");
    }
    synchronized (this) {
      this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
      // get lock on scServer - only one server is allowed to communicate over the initial connection
      SCMPPublishCall publishCall = new SCMPPublishCall(this.requester, serviceName);
      publishCall.setRequestBody(publishMessage.getData());
      publishCall.setMask(publishMessage.getMask());
      publishCall.setPartSize(publishMessage.getPartSize());
      publishCall.setMessageInfo(publishMessage.getMessageInfo());
      SCServerCallback callback = new SCServerCallback(true);
      try {
        publishCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        throw new SCServiceException("Publish failed. ", e);
      }
      SCMPMessage message = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      if (message.isFault()) {
        SCServiceException ex = new SCServiceException("Publish failed.");
        ex.setSCErrorCode(message.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
        ex.setSCErrorText(message.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
        throw ex;
      }
    }
  }
View Full Code Here

   *             error message received from SC<br />
   */
  protected synchronized void doRegister(int operationTimeoutSeconds, int maxSessions, int maxConnections)
      throws SCServiceException {
    if (this.scServer.isListening() == false) {
      throw new SCServiceException("Listener must be started before register service is allowed.");
    }
    if (this.registered) {
      throw new SCServiceException("Server already registered for a service.");
    }
    // already validated
    int listenerPort = this.scServer.getListenerPort();
    int keepAliveIntervalSeconds = this.scServer.getKeepAliveIntervalSeconds();
    int checkRegistrationIntervalSeconds = this.scServer.getCheckRegistrationIntervalSeconds();
    boolean immediateConnect = this.scServer.isImmediateConnect();
    synchronized (AppContext.communicatorsLock) {
      // get communicator lock - avoids interference with other clients or scServers
      AppContext.init();
      this.requester.getSCMPMsgSequenceNr().reset();

      SCMPRegisterServerCall registerServerCall = new SCMPRegisterServerCall(this.requester, this.serviceName);

      registerServerCall.setMaxSessions(maxSessions);
      registerServerCall.setMaxConnections(maxConnections);
      registerServerCall.setPortNumber(listenerPort);
      registerServerCall.setImmediateConnect(immediateConnect);
      registerServerCall.setKeepAliveIntervalSeconds(keepAliveIntervalSeconds);
      registerServerCall.setCheckRegistrationIntervalSeconds(checkRegistrationIntervalSeconds);
      registerServerCall.setVersion(SCMPMessage.SC_VERSION.toString());
      registerServerCall.setLocalDateTime(DateTimeUtility.getCurrentTimeZoneMillis());
      SCServerCallback callback = new SCServerCallback(true);
      try {
        registerServerCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        throw new SCServiceException("Register server failed. ", e);
      }
      SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      if (reply.isFault()) {
        SCServiceException ex = new SCServiceException("Register server failed.");
        ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
        ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
        throw ex;
      }
      AppContext.attachedCommunicators.incrementAndGet();
    }
    // set up server timeout thread
View Full Code Here

   *             check registration failed<br />
   *             error message received from SC <br />
   */
  public synchronized void checkRegistration(int operationTimeoutSeconds) throws SCServiceException {
    if (this.registered == false) {
      throw new SCServiceException("Server is not registered for a service.");
    }
    // cancel server timeout not if its running already, you might interrupt current thread
    this.cancelServerTimeout(false);
    synchronized (this.scServer) {
      // get lock on scServer - only one server is allowed to communicate over the initial connection
      SCMPCheckRegistrationCall checkRegistrationCall = new SCMPCheckRegistrationCall(this.requester, this.serviceName);
      SCServerCallback callback = new SCServerCallback(true);
      try {
        checkRegistrationCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        throw new SCServiceException("Check registration failed. ", e);
      }
      SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      if (reply.isFault()) {
        SCServiceException ex = new SCServiceException("Check registration failed.");
        ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
        ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
        throw ex;
      }
    }
    // set up server timeout thread
    this.triggerServerTimeout();
View Full Code Here

        SCMPDeRegisterServerCall deRegisterServerCall = new SCMPDeRegisterServerCall(this.requester, this.serviceName);
        SCServerCallback callback = new SCServerCallback(true);
        try {
          deRegisterServerCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
        } catch (Exception e) {
          throw new SCServiceException("Deregister server failed. ", e);
        }
        SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
        if (reply.isFault()) {
          SCServiceException ex = new SCServiceException("Deregister server failed.");
          ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
          ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
          throw ex;
        }
      } finally {
        this.registered = false;
        AppContext.attachedCommunicators.decrementAndGet();
View Full Code Here

TOP

Related Classes of org.serviceconnector.api.SCServiceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.