Package org.serviceconnector.api.cln

Examples of org.serviceconnector.api.cln.SCSessionService


   */
  public void run() {

    // Connection to SC over HTTP
    SCClient sc = new SCClient("localhost", 7000, ConnectionType.NETTY_HTTP);
    SCSessionService service = null;

    try {
      sc.setMaxConnections(20); // can be set before attach, default 100 Connections
      sc.setKeepAliveIntervalSeconds(10); // can be set before attach, default 0 -> inactive
      sc.attach(); // attaching client to SC , communication starts

      String serviceName = "session-1";
      service = sc.newSessionService(serviceName); // name of the service to use
      service.setEchoIntervalSeconds(10); // can be set before create session
      service.setEchoTimeoutSeconds(2); // can be set before create session

      SCMessage msg = new SCMessage();
      msg.setSessionInfo("session-info"); // optional
      msg.setData("certificate or what so ever"); // optional
      SCMessageCallback cbk = new DemoSessionClientCallback(service); // callback on service!!
      SCMessage reply = service.createSession(10, msg, cbk); // create a session within 10 seconds
      Object body = reply.getData();

      String sid = service.getSessionId();

      SCMessage requestMsg = new SCMessage();
      SCMessage responseMsg = new SCMessage();

      for (int i = 0; i < 5; i++) {
        requestMsg.setData("body nr : " + i);
        responseMsg = service.execute(requestMsg); // regular synchronous call
        LOGGER.info("Message sent sync=" + requestMsg.getData());
        LOGGER.info("Message received sync=" + responseMsg.getData());
        Thread.sleep(2000);
      }
      for (int i = 0; i < 5; i++) {
        requestMsg.setData("body nr : " + i);
        service.send(requestMsg); // regular asynchronous call
        LOGGER.info("Message sent async=" + requestMsg.getData());
        Thread.sleep(2000);
      }

      requestMsg.setData("cache message body");
      requestMsg.setCacheId("700");
      responseMsg = service.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent to put in cache=" + requestMsg.getData());
      LOGGER.info("Message received=" + responseMsg.getData());

      responseMsg = service.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent with cacheId=" + requestMsg.getData());
      LOGGER.info("Message received from cache=" + responseMsg.getData());
    } catch (Exception e) {
      LOGGER.error("run", e);
    } finally {
      try {
        SCMessage msg = new SCMessage();
        msg.setSessionInfo("kill server");
        service.deleteSession(5, msg);
        sc.detach(2); // detaches from SC, stops communication
      } catch (Exception e) {
        LOGGER.error("cleanup", e);
      }
    }
View Full Code Here


  @Override
  public void run() {

    SCClient sc = new SCClient("localhost", 7000); // regular, defaults documented in javadoc
    sc = new SCClient("localhost", 7000, ConnectionType.NETTY_HTTP); // alternative with connection type
    SCSessionService service = null;
    try {
      sc.setMaxConnections(20); // can be set before attach
      sc.setKeepAliveIntervalSeconds(0); // can be set before attach
      sc.attach(); // regular

      String serviceName = "session-1";
      service = sc.newSessionService(serviceName); // regular, no other params possible
      service.setEchoIntervalSeconds(10); // can be set before create session
      service.setEchoTimeoutSeconds(2); // can be set before create session

      SCMessage msg = new SCMessage();
      msg.setSessionInfo("session-info"); // optional
      msg.setData("certificate or what so ever"); // optional
      SCMessageCallback cbk = new DemoSessionClientCallback(service); // callback on service!!
      service.createSession(10, msg, cbk); // alternative with operation timeout and message
      // service.createSession(msg); // alternative with message

      String sid = service.getSessionId();

      SCMessage requestMsg = new SCMessage();
      requestMsg.setCacheId("CBCD_SECURITY_MARKET");
      SCMessage responseMsg = new SCMessage();

      for (int i = 0; i < 10; i++) {
        requestMsg.setData("body nr : " + i);
        LOGGER.info("Message sent=" + requestMsg.getData());

        // service.send(cbk, requestMsg); // regular asynchronous call
        // service.send(cbk, requestMsg, 10); // alternative with operation timeout
        // service.receive(cbk); // wait for response
        // cbk.receive(); // wait for response ?
        // responseMsg = cbk.getMessage(); // response message

        // synchronous call encapsulates asynchronous call!
        responseMsg = service.execute(requestMsg); // regular synchronous call
        // responseMsg = service.execute(requestMsg, 10); // alternative with operation timeout

        LOGGER.info("Message received=" + responseMsg.getData());
        Thread.sleep(1000);
      }
      requestMsg.setData("kill server");
      // service.send(cbk, requestMsg);

    } catch (Exception e) {
      LOGGER.error("run", e);
    } finally {
      try {
        service.deleteSession(); // regular
        // service.deleteSession(10); // alternative with operation timeout
        // SCMessage msg = new SCMessage();
        // msg.setSessionInfo("session-info"); // optional
        // service.deleteSession(10, msg); // alternative with operation timeout and message
        // service.deleteSession(msg); // alternative with message
View Full Code Here

      sc.setMaxConnections(100);

      // connects to SC, checks connection to SC
      sc.attach();

      SCSessionService sessionServiceA = sc.newSessionService("session-1");
      // creates a session
      SCMessage scMessage = new SCMessage();
      scMessage.setSessionInfo("sessionInfo");
      sessionServiceA.setEchoTimeoutSeconds(300);
      SCMessageCallback cbk = new ExampleCallback(sessionServiceA);
      sessionServiceA.createSession(60, scMessage, cbk);

      SCMessage requestMsg = new SCMessage();
      requestMsg.setData("Hello World");
      requestMsg.setCompressed(false);

      sessionServiceA.send(requestMsg);

      // wait until message received
      waitForMessage(10);
      // deletes the session
      sessionServiceA.deleteSession();

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
View Full Code Here

      sc.setMaxConnections(100);

      // connects to SC, checks connection to SC
      sc.attach();

      SCSessionService sessionServiceA = sc.newSessionService("session-1");
      // creates a session
      SCMessage scMessage = new SCMessage();
      scMessage.setSessionInfo("sessionInfo");
      sessionServiceA.setEchoTimeoutSeconds(300);
      SCMessageCallback cbk = new ExampleCallback(sessionServiceA);
      sessionServiceA.createSession(60, scMessage, cbk);

      SCMessage requestMsg = new SCMessage();
      // set up large buffer
      byte[] buffer = new byte[9000000];
      for (int i = 0; i < buffer.length; i++) {
        buffer[i] = (byte) i;
      }
      requestMsg.setData(buffer);
      requestMsg.setPartSize(65536); // 64KB
      requestMsg.setCompressed(false);
      System.out.println(buffer.length);
      SCMessage responseMsg = sessionServiceA.execute(requestMsg);
      System.out.println(responseMsg.getData().toString());
      // deletes the session
      sessionServiceA.deleteSession();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        // disconnects from SC
View Full Code Here

      sc.setMaxConnections(100);

      // connects to SC, checks connection to SC
      sc.attach();

      SCSessionService sessionServiceA = sc.newSessionService("session-1");
      // creates a session
      SCMessage scMessage = new SCMessage();
      scMessage.setSessionInfo("sessionInfo");
      sessionServiceA.setEchoTimeoutSeconds(300);
      SCMessageCallback cbk = new ExampleCallback(sessionServiceA);
      sessionServiceA.createSession(60, scMessage, cbk);

      SCMessage requestMsg = new SCMessage();
      requestMsg.setData("Hello World");
      requestMsg.setCompressed(false);
      SCMessage responseMsg = sessionServiceA.execute(requestMsg);

      System.out.println(responseMsg.getData().toString());
      // deletes the session
      sessionServiceA.deleteSession();

    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
View Full Code Here

   */
  public void run() {

    // Connection to SC over HTTP
    SCClient sc = new SCClient("localhost", 7000, ConnectionType.NETTY_HTTP);
    SCSessionService sessionSrv = null;

    try {
      sc.setMaxConnections(20); // can be set before attach, default 100 Connections
      sc.setKeepAliveIntervalSeconds(10); // can be set before attach, default 0 -> inactive
      sc.attach(); // attaching client to SC , communication starts

      String serviceName = "session-1";
      sessionSrv = sc.newSessionService(serviceName); // name of the service to use
      sessionSrv.setEchoIntervalSeconds(10); // can be set before create session
      sessionSrv.setEchoTimeoutSeconds(2); // can be set before create session

      SCMessage msg = new SCMessage();
      msg.setSessionInfo("session-info"); // optional
      msg.setData("certificate or what so ever"); // optional
      SCMessageCallback cbk = new DemoSessionClientCallback(sessionSrv); // callback on service!!
      SCMessage reply = sessionSrv.createSession(10, msg, cbk); // create a session within 10 seconds
      Object body = reply.getData();   
     
      String sid = sessionSrv.getSessionId();

      SCMessage requestMsg = new SCMessage();
      SCMessage responseMsg = new SCMessage();

      requestMsg.setData("cache message body");
      requestMsg.setCacheId("700");
      responseMsg = sessionSrv.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent to put in cache=" + requestMsg.getData());
      LOGGER.info("Message received=" + responseMsg.getData());

      responseMsg = sessionSrv.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent with cacheId=" + requestMsg.getData());
      LOGGER.info("Message received from cache=" + responseMsg.getData());     
     
      SCPublishService publishService = sc.newPublishService("cacheGuardian1"); // name of the service to use

      DemoPublishClientCallback pubCbk = new DemoPublishClientCallback(publishService); // callback on service!!
      // set up subscribe message
      SCSubscribeMessage subMsg = new SCSubscribeMessage();
      String mask = "0000121ABCDEFGHIJKLMNO-----------X-----------";
      subMsg.setSessionInfo("subscription-info"); // optional
      subMsg.setData("certificate or what so ever"); // optional
      subMsg.setMask(mask); // mandatory
      subMsg.setNoDataIntervalSeconds(100); // mandatory
      SCSubscribeMessage subReply = publishService.subscribe(subMsg, pubCbk); // regular subscribe
     
      responseMsg = sessionSrv.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent with cacheId=" + requestMsg.getData());
      LOGGER.info("Message received from cache=" + responseMsg.getData());   
     
     
    } catch (Exception e) {
      LOGGER.error("run", e);
    } finally {
      try {
        SCMessage msg = new SCMessage();
        msg.setSessionInfo("kill server");
        sessionSrv.deleteSession(5, msg);
        sc.detach(2); // detaches from SC, stops communication
      } catch (Exception e) {
        LOGGER.error("cleanup", e);
      }
    }
View Full Code Here

   * Description: Create session (regular)<br>
   * 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));

    SCPublishService pubService1 = client.newPublishService(TestConstants.pubServiceName1);
    scSubscribeMessage.setNoDataIntervalSeconds(40);
    pubService1.subscribe(scSubscribeMessage, new TestPublishServiceMessageCallback(pubService1));

    System.out.println("APISessionSubscriptionTest.t01_()");

    try {
      sessService.deleteSession();
      pubService.unsubscribe();
    } catch (Exception e) {
      client.detach();
    }
    client.detach();
View Full Code Here

    // stop test server now, session on SC gets deleted
    ctrl.stopServer(srvCtxs.get(TestConstants.sesServerName1));
    ctrl.startServer(TestConstants.COMMUNICATOR_TYPE_SESSION, TestConstants.log4jSrvProperties, TestConstants.sesServerName1,
        TestConstants.PORT_SES_SRV_TCP, TestConstants.PORT_SC0_TCP, 100, 10, TestConstants.sesServiceName1);

    SCSessionService sessionService2 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService2);
    sessionService2.createSession(request, msgCallback1);
    message = new SCMessage();
    message.setMessageInfo(TestConstants.cacheCmd);
    message.setData("cache10MBStringFor1Hour");
    message.setCacheId("700");

    response = null;
    while (response == null) {
      try {
        response = sessionService2.execute(message);
      } catch (SCServiceException e) {
        if (e.getSCErrorCode() != SCMPError.CACHE_LOADING.getErrorCode()) {
          throw e;
        }
        Thread.sleep(5000);
View Full Code Here

    this.sessionClient.detach();

    // 2: connect new client to SC0
    SCClient clientToSc0 = new SCClient(TestConstants.HOST, TestConstants.PORT_SC0_TCP, ConnectionType.NETTY_TCP);
    clientToSc0.attach();
    SCSessionService sessionSrvToSC0 = clientToSc0.newSessionService(TestConstants.sesServiceName1);

    // 3: load data to cache (cid=700) on SC0
    SCMessage request = new SCMessage();
    request.setData("cacheFor1Hour_managedData");
    request.setCacheId("700");
    request.setMessageInfo(TestConstants.cacheCmd);
    sessionSrvToSC0.createSession(new SCMessage(), new SessionMsgCallback(sessionSrvToSC0));
    sessionSrvToSC0.execute(request);

    // 4: start cache guardian - publish 3 large appendix
    SCSubscribeMessage subMsg = new SCSubscribeMessage();
    subMsg.setMask(TestConstants.mask);
    subMsg.setSessionInfo(TestConstants.publish3LargeAppendixMsgCmd);
View Full Code Here

    this.startSC0AAndServers();

    // 1: connect new client2 to top level (cascaded) SC
    SCClient client2 = new SCClient(TestConstants.HOST, sessionClient.getPort(), ConnectionType.NETTY_TCP);
    client2.attach();
    SCSessionService sessionService2 = client2.newSessionService(TestConstants.sesServiceName1);
    sessionService2.createSession(new SCMessage(), new SessionMsgCallback(sessionService2));

    // 2: load data to cache (cid=700) by client1
    SCMessage request = new SCMessage();
    request.setData("cacheFor1Hour_managedData");
    request.setCacheId("700");
View Full Code Here

TOP

Related Classes of org.serviceconnector.api.cln.SCSessionService

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.