Package org.serviceconnector.api

Examples of org.serviceconnector.api.SCMessage


   * instances, sessionService2 gets an exception<br>
   * Expectation: cache loading exception
   */
  @Test
  public void t12_2ClientsCacheAndGetSameMessage() throws Exception {
    SCMessage request = new SCMessage();
    request.setCompressed(false);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);

    SCSessionService sessionService2 = client.newSessionService(TestConstants.sesServiceName1);
View Full Code Here


   * instances, sessionService2 gets an exception<br>
   * Expectation: cache loading exception
   */
  @Test
  public void t13_2ClientsOneLargeOneSmallRequestCacheAndGetSameMessage() throws Exception {
    SCMessage request = new SCMessage();
    request.setCompressed(false);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);

    SCSessionService sessionService2 = client.newSessionService(TestConstants.sesServiceName1);
    MsgCallback msgCallback2 = new MsgCallback(sessionService1);
    response = sessionService2.createSession(request, msgCallback2);

    // session service starts storing large message with cacheId 700
    String largeMessage = TestUtil.get10MBString();
    request.setData(largeMessage);
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    sessionService1.send(request);
    // to assure service1 started loading cache
    Thread.sleep(50);
    // session service2 starts getting large message from cache with cacheId 700
    request.setData(TestConstants.pangram);
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    try {
      response = sessionService2.execute(request);
      Assert.fail("Should throw an exception but did not.");
    } catch (SCServiceException e) {
      Assert.assertEquals(SCMPError.CACHE_LOADING.getErrorCode(), e.getSCErrorCode());
    }
    // get response from sessionService1 request
    msgCallback1.waitForMessage(60);
    response = msgCallback1.getResponse();
    SCMessage response2 = sessionService2.execute(request);
    Assert.assertEquals(response.getData(), response2.getData());
  }
View Full Code Here

   * Expectation: get messages from cache
   */
  @Test
  public void t14_2ClientsLargeMessage() throws Exception {
    String largeMessage = TestUtil.get10MBString();
    SCMessage request = new SCMessage();
    request.setPartSize(1 << 16); // 64KB
    request.setCompressed(false);
    SCMessage response = null;
    // session service starts storing large message with cacheId 700
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);
    request.setData("cache10MBStringFor1Hour");
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    sessionService1.send(request);

    Thread.sleep(10000);

    // session service2 starts getting large message from cache with cacheId 700
    SCSessionService sessionService2 = client.newSessionService(TestConstants.sesServiceName1);
    MsgCallback msgCallback2 = new MsgCallback(sessionService1);
    response = sessionService2.createSession(request, msgCallback2);
    request.setData("randomContent");
    request.setCacheId("700");
    response = sessionService2.execute(request);
    Assert.assertEquals(largeMessage, response.getData());

    // session service1 get message
    msgCallback1.waitForMessage(60);
    response = msgCallback1.getResponse();
    Assert.assertEquals(largeMessage, response.getData());
  }
View Full Code Here

    sessionClient.attach();
    cacheGuardianCbk = new GuardianCbk();

    sessionService1 = sessionClient.newSessionService(TestConstants.sesServiceName1);
    sessionCbk = new SessionMsgCallback(sessionService1);
    sessionService1.createSession(new SCMessage(), sessionCbk);
  }
View Full Code Here

    }
    this.sessionId = reply.getSessionId();
    this.sessionActive = true;
    // 4. post process, reply to client
    this.triggerSessionTimeout();
    SCMessage replyToClient = new SCMessage();
    replyToClient.setData(reply.getBody());
    replyToClient.setDataLength(reply.getBodyLength());
    replyToClient.setCompressed(reply.getHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION));
    replyToClient.setSessionId(this.sessionId);
    replyToClient.setSessionInfo(reply.getHeader(SCMPHeaderAttributeKey.SESSION_INFO));
    replyToClient.setAppErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.APP_ERROR_CODE));
    replyToClient.setAppErrorText(reply.getHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT));
    return replyToClient;
  }
View Full Code Here

      scEx.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
      throw scEx;
    }

    // 4. post process, reply to client
    SCMessage replyToClient = null;
    Integer nrOfAppendix = reply.getHeaderInt(SCMPHeaderAttributeKey.NR_OF_APPENDIX);
    SC_CACHING_METHOD cachingMethod = SC_CACHING_METHOD
        .getCachingMethod(reply.getHeader(SCMPHeaderAttributeKey.CACHING_METHOD));

    if (nrOfAppendix != null) {
      replyToClient = this.pollAppendices(operationTimeoutSeconds, nrOfAppendix, scMessage.getCacheId());
    } else if (cachingMethod == SC_CACHING_METHOD.INITIAL) {
      replyToClient = new SCManagedMessage();
      replyToClient.setCachingMethod(cachingMethod);
    } else {
      replyToClient = new SCMessage();
    }

    replyToClient.setData(reply.getBody());
    replyToClient.setDataLength(reply.getBodyLength());
    replyToClient.setCompressed(reply.getHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION));
    replyToClient.setSessionId(this.sessionId);
    replyToClient.setCacheId(reply.getCacheId());
    replyToClient.setCached(reply.getHeaderFlag(SCMPHeaderAttributeKey.CACHED));
    replyToClient.setCachePartNr(reply.getHeader(SCMPHeaderAttributeKey.CACHE_PARTN_NUMBER));
    replyToClient.setMessageInfo(reply.getHeader(SCMPHeaderAttributeKey.MSG_INFO));
    replyToClient.setAppErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.APP_ERROR_CODE));
    replyToClient.setAppErrorText(reply.getHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT));
    return replyToClient;
  }
View Full Code Here

    // look up srvService
    SrvSessionService srvService = this.getSrvSessionServiceByServiceName(serviceName);

    String sessionId = reqMessage.getSessionId();
    // create scMessage
    SCMessage scMessage = new SCMessage();
    scMessage.setData(reqMessage.getBody());
    scMessage.setDataLength(reqMessage.getBodyLength());
    scMessage.setCompressed(reqMessage.getHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION));
    scMessage.setMessageInfo(reqMessage.getHeader(SCMPHeaderAttributeKey.MSG_INFO));
    scMessage.setSessionId(sessionId);
    scMessage.setSessionInfo(reqMessage.getHeader(SCMPHeaderAttributeKey.SESSION_INFO));
    scMessage.setServiceName(reqMessage.getServiceName());
    int oti = Integer.parseInt(reqMessage.getHeader(SCMPHeaderAttributeKey.OPERATION_TIMEOUT));

    // inform callback with scMessages
    SCMessage scReply = srvService.getCallback().createSession(scMessage, oti);

    // set up reply
    SCMPMessage reply = new SCMPMessage();

    if (scReply != null) {
      reply.setBody(scReply.getData());
      if (scReply.isCompressed()) {
        reply.setHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION);
      }
      if (scReply.getAppErrorCode() != Constants.EMPTY_APP_ERROR_CODE) {
        reply.setHeader(SCMPHeaderAttributeKey.APP_ERROR_CODE, scReply.getAppErrorCode());
      }
      if (scReply.getAppErrorText() != null) {
        reply.setHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT, scReply.getAppErrorText());
      }
      if (scReply.isReject()) {
        // session rejected
        reply.setHeaderFlag(SCMPHeaderAttributeKey.REJECT_SESSION);
      } else {
        // create session in SCMPSessionCompositeRegistry
        SrvCommandAdapter.sessionCompositeRegistry.addSession(sessionId);
        // handling msgSequenceNr
        SCMPMessageSequenceNr msgSequenceNr = SrvCommandAdapter.sessionCompositeRegistry.getSCMPMsgSequenceNr(sessionId);
        reply.setHeader(SCMPHeaderAttributeKey.MESSAGE_SEQUENCE_NR, msgSequenceNr.getCurrentNr());
      }
      if (scReply.getSessionInfo() != null) {
        reply.setHeader(SCMPHeaderAttributeKey.SESSION_INFO, scReply.getSessionInfo());
      }
    }
    reply.setSessionId(reqMessage.getSessionId());
    reply.setServiceName(serviceName);
    reply.setMessageType(this.getKey());
View Full Code Here

      responderCallback.responseCallback(request, response);
      return;
    }

    // create scMessage
    SCMessage scMessage = new SCMessage();
    scMessage.setData(reqMessage.getBody());
    scMessage.setDataLength(reqMessage.getBodyLength());
    scMessage.setCompressed(reqMessage.getHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION));
    scMessage.setMessageInfo(reqMessage.getHeader(SCMPHeaderAttributeKey.MSG_INFO));
    scMessage.setSessionId(sessionId);
    scMessage.setServiceName(reqMessage.getServiceName());

    int oti = Integer.parseInt(reqMessage.getHeader(SCMPHeaderAttributeKey.OPERATION_TIMEOUT));

    // inform callback with scMessagesF
    ((SrvSessionService) srvService).getCallback().abortSession(scMessage, oti);
View Full Code Here

    scMessage.setMask(reqMessage.getHeader(SCMPHeaderAttributeKey.MASK));
    scMessage.setServiceName(reqMessage.getServiceName());
    int oti = Integer.parseInt(reqMessage.getHeader(SCMPHeaderAttributeKey.OPERATION_TIMEOUT));

    // inform callback with scMessages
    SCMessage scReply = srvService.getCallback().subscribe(scMessage, oti);

    // set up reply
    SCMPMessage reply = new SCMPMessage();

    if (scReply != null) {
      reply.setBody(scReply.getData());
      if (scReply.isCompressed()) {
        reply.setHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION);
      }
      if (scReply.getAppErrorCode() != Constants.EMPTY_APP_ERROR_CODE) {
        reply.setHeader(SCMPHeaderAttributeKey.APP_ERROR_CODE, scReply.getAppErrorCode());
      }
      if (scReply.getAppErrorText() != null) {
        reply.setHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT, scReply.getAppErrorText());
      }
      if (scReply.isReject()) {
        // subscription rejected
        reply.setHeaderFlag(SCMPHeaderAttributeKey.REJECT_SESSION);
      } else {
        // create session in SCMPSessionCompositeRegistry
        SrvCommandAdapter.sessionCompositeRegistry.addSession(sessionId);
        // handling msgSequenceNr
        SCMPMessageSequenceNr msgSequenceNr = SrvCommandAdapter.sessionCompositeRegistry.getSCMPMsgSequenceNr(sessionId);
        reply.setHeader(SCMPHeaderAttributeKey.MESSAGE_SEQUENCE_NR, msgSequenceNr.getCurrentNr());
      }
      if (scReply.getSessionInfo() != null) {
        reply.setHeader(SCMPHeaderAttributeKey.SESSION_INFO, scReply.getSessionInfo());
      }
    }
    reply.setServiceName(serviceName);
    reply.setSessionId(sessionId);
    reply.setMessageType(this.getKey());
View Full Code Here

   * Expectation: passes
   */
  @Test
  public void t01_() throws Exception {
    SCSessionService sessService = client.newSessionService(TestConstants.sesServerName1);
    SCMessage scMessage = new SCMessage();
    sessService.createSession(scMessage, new TestSessionServiceMessageCallback(sessService));
    SCPublishService pubService = client.newPublishService(TestConstants.pubServerName1);
    SCSubscribeMessage scSubscribeMessage = new SCSubscribeMessage();
    scSubscribeMessage.setMask(TestConstants.mask);
    pubService.subscribe(scSubscribeMessage, new TestPublishServiceMessageCallback(pubService));
View Full Code Here

TOP

Related Classes of org.serviceconnector.api.SCMessage

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.