Package org.serviceconnector.scmp

Examples of org.serviceconnector.scmp.SCMPMessage


    }
  }

  @Override
  public void receive(Exception ex) {
    SCMPMessage reqMessage = this.request.getMessage();
    String sid = reqMessage.getSessionId();
    LOGGER.warn("receive exception sid=" + sid + " " + ex.toString());
    // release permit
    this.cascClient.getCascClientSemaphore().release();
    // forward reply to client
    this.commandCallback.receive(ex);
View Full Code Here


      }
      CacheLogger.tryGetMessageFromCache(reqCacheKey, sessionId, reqPartNr);
      // meta entry exists
      if (metaEntry.isLoaded() == true) {
        // message already loaded - return message
        SCMPMessage cachedMessage = dataCache.get(metaEntry.getCacheKey() + Constants.SLASH + reqPartNr);
        if (cachedMessage != null) {
          // message found adapt header fields for requester
          cachedMessage.setServiceName(serviceName);
          cachedMessage.setMessageType(reqMessage.getMessageType());
          cachedMessage.setHeader(SCMPHeaderAttributeKey.MESSAGE_SEQUENCE_NR, reqMessage.getMessageSequenceNr());
          cachedMessage.setSessionId(sessionId);
          if (CacheLogger.isEnabled()) {
            CacheLogger.gotMessageFromCache(reqCacheKey, sessionId, cachedMessage.getBodyLength());
          }
        } else {
          LOGGER.error("Cache error, data-cache and meta-cache are not consistent. cacheKey=" + reqCacheKey
              + Constants.SLASH + reqPartNr);
        }
View Full Code Here

   * @param reply
   *            the reply {@inheritDoc}
   */
  @Override
  public void receive(SCMPMessage reply) {
    SCMPMessage reqMessage = request.getMessage();
    String serviceName = reqMessage.getServiceName();
    IStatefulServer server = this.cascSubscription.getServer();
    if (reqMessage.getHeader(SCMPHeaderAttributeKey.CASCADED_MASK) == null) {
      // free server from subscription if cascaded SC unsubscribes himself
      server.removeSession(this.cascSubscription);
    }
    // forward server reply to client
    reply.setIsReply(true);
View Full Code Here

   * @param ex
   *            the ex {@inheritDoc}
   */
  @Override
  public void receive(Exception ex) {
    SCMPMessage reqMessage = this.request.getMessage();
    String sid = reqMessage.getSessionId();
    LOGGER.warn("receive exception sid=" + sid + " " + ex.toString());
    String serviceName = reqMessage.getServiceName();
    IStatefulServer server = this.cascSubscription.getServer();

    if (reqMessage.getHeader(SCMPHeaderAttributeKey.CASCADED_MASK) == null) {
      // free server from subscription if cascaded SC unsubscribes himself
      server.removeSession(this.cascSubscription);
    }
    SCMPMessage fault = null;
    if (ex instanceof IdleTimeoutException) {
      // operation timeout handling
      fault = new SCMPMessageFault(SCMPError.OPERATION_TIMEOUT, "Operation timeout expired on SC csc unsubscribe sid=" + sid);
    } else if (ex instanceof IOException) {
      fault = new SCMPMessageFault(SCMPError.CONNECTION_EXCEPTION, "broken connection on SC csc unsubscribe sid=" + sid);
    } else if (ex instanceof InvalidMaskLengthException) {
      fault = new SCMPMessageFault(SCMPError.HV_WRONG_MASK, ex.getMessage() + " sid=" + sid);
    } else {
      fault = new SCMPMessageFault(SCMPError.SC_ERROR, "executing csc unsubscribe failed sid=" + sid);
    }
    // forward server reply to client
    fault.setIsReply(true);
    fault.setServiceName(serviceName);
    fault.setMessageType(SCMPMsgType.CSC_UNSUBSCRIBE);
    this.response.setSCMP(fault);
    this.responderCallback.responseCallback(request, response);
    // delete subscription failed abort!
    server.abortSession(this.cascSubscription, "unsubscribe failed, exception received in callback");
  }
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public void run(IRequest request, IResponse response, IResponderCallback responderCallback) throws Exception {
    SCMPMessage reqMessage = request.getMessage();
    int oti = reqMessage.getHeaderInt(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);
    String serviceName = reqMessage.getServiceName();
    // check service is present
    Service abstractService = this.getService(serviceName);
    String sessionId = reqMessage.getSessionId();

    switch (abstractService.getType()) {
    case CASCADED_SESSION_SERVICE:
      // clears message in cache if in loading state
      AppContext.getCacheManager().clearLoading(sessionId);
      CascadedSC cascadedSC = ((CascadedSessionService) abstractService).getCascadedSC();
      CommandCascCallback callback = new CommandCascCallback(request, response, responderCallback);
      cascadedSC.deleteSession(reqMessage, callback, oti);
      return;
    case CASCADED_FILE_SERVICE:
      cascadedSC = ((CascadedFileService) abstractService).getCascadedSC();
      callback = new CommandCascCallback(request, response, responderCallback);
      cascadedSC.deleteSession(reqMessage, callback, oti);
      return;
    default:
      // code for other types of services is below
      break;
    }

    // lookup session and checks properness
    Session session = this.getSessionById(sessionId);
    synchronized (session) {
      session.setPendingRequest(true); // IMPORTANT - set true because of parallel echo call
      // delete entry from session registry
      this.sessionRegistry.removeSession(session);
    }
    IServer abstractServer = session.getServer();

    switch (abstractServer.getType()) {
    case STATEFUL_SERVER:
      // code for type session service is below switch statement
      break;
    case FILE_SERVER:
      this.sessionRegistry.removeSession(session);
      ((FileServer) abstractServer).removeSession(session);
      // reply to client
      SCMPMessage reply = new SCMPMessage();
      reply.setIsReply(true);
      reply.setMessageType(getKey());
      response.setSCMP(reply);
      responderCallback.responseCallback(request, response);
      return;
    case CASCADED_SC:
    case UNDEFINED:
View Full Code Here

        // 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();
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public void validate(IRequest request) throws Exception {
    SCMPMessage message = request.getMessage();
    try {
      // msgSequenceNr mandatory
      String msgSequenceNr = message.getMessageSequenceNr();
      ValidatorUtility.validateLong(1, msgSequenceNr, SCMPError.HV_WRONG_MESSAGE_SEQUENCE_NR);
      // serviceName mandatory
      String serviceName = message.getServiceName();
      ValidatorUtility.validateStringLengthTrim(1, serviceName, Constants.MAX_LENGTH_SERVICENAME,
          SCMPError.HV_WRONG_SERVICE_NAME);
      // operation timeout mandatory
      String otiValue = message.getHeader(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);
      ValidatorUtility.validateInt(Constants.MIN_OTI_VALUE_CSC, otiValue, Constants.MAX_OTI_VALUE,
          SCMPError.HV_WRONG_OPERATION_TIMEOUT);
      // sessionId mandatory
      String sessionId = message.getSessionId();
      ValidatorUtility.validateStringLengthTrim(1, sessionId, Constants.MAX_STRING_LENGTH_256, SCMPError.HV_WRONG_SESSION_ID);
      // sessionInfo optional
      String sessionInfo = message.getHeader(SCMPHeaderAttributeKey.SESSION_INFO);
      ValidatorUtility.validateStringLengthIgnoreNull(1, sessionInfo, Constants.MAX_STRING_LENGTH_256,
          SCMPError.HV_WRONG_SESSION_INFO);
    } catch (HasFaultResponseException ex) {
      // needs to set message type at this point
      ex.setMessageType(getKey());
View Full Code Here

        detachCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        throw new SCServiceException("Detach client 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("Detach client 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.attached = false;
View Full Code Here

    if (this.synchronous == false) {
      // offering is only allowed if someone is expecting a message - prevents race conditions, an answer might
      // arrive late after operation timeout already run out, can be ignored
      return;
    }
    SCMPMessage fault = new SCMPMessageFault(ex);
    if (this.answer.offer(fault)) {
      // queue empty object can be added
      return;
    }
    // object could not be added - clear queue and offer again
View Full Code Here

      LOGGER.error("timeoutMillis <= 0");
      return null;
    }
    // set synchronous mode
    this.synchronous = true;
    SCMPMessage reply = null;
    try {
      // the method poll() from BlockingQueue waits inside
      reply = this.answer.poll(timeoutMillis, TimeUnit.MILLISECONDS);
      // reset synchronous mode
      this.synchronous = false;
    } catch (InterruptedException e) {
      // finally clause handles exception too
      LOGGER.warn("InterruptedException when waiting for message " + e);
    } finally {
      if (reply == null) {
        // time runs out before message got received
        reply = new SCMPMessageFault(SCMPError.REQUEST_WAIT_ABORT, "");
        reply.setMessageType(SCMPMsgType.UNDEFINED);
        LOGGER.error("Operation did not complete in time, timeout=" + timeoutMillis + "ms aborting callback="
            + this.getClass().getName());
      }
    }
    return reply;
View Full Code Here

TOP

Related Classes of org.serviceconnector.scmp.SCMPMessage

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.