Package org.serviceconnector.api.cln

Examples of org.serviceconnector.api.cln.SCPublishService


  /** {@inheritDoc} */
  @Override
  public void run() {
    // Connection to SC over HTTP
    SCClient sc = new SCClient("localhost", 7000, ConnectionType.NETTY_HTTP);
    SCPublishService 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 = "publish-1";
      service = sc.newPublishService(serviceName); // name of the service to use

      DemoPublishClientCallback cbk = new DemoPublishClientCallback(service); // callback on service!!
      // set up subscribe message
      SCSubscribeMessage msg = new SCSubscribeMessage();
      String mask = "0000121ABCDEFGHIJKLMNO-----------X-----------";
      msg.setSessionInfo("subscription-info"); // optional
      msg.setData("certificate or what so ever"); // optional
      msg.setMask(mask); // mandatory
      msg.setNoDataIntervalSeconds(100); // mandatory
      SCSubscribeMessage reply = service.subscribe(msg, cbk); // regular subscribe

      String sid = service.getSessionId();

      // wait to receive messages
      while (cbk.receivedMsg < 5) {
        Thread.sleep(1500);
      }
    } catch (Exception e) {
      LOGGER.error("run", e);
    } finally {
      try {
        SCSubscribeMessage msg = new SCSubscribeMessage();
        msg.setSessionInfo("kill server");
        service.unsubscribe(5, msg);
        sc.detach(2); // detaches from SC, stops communication
      } catch (Exception e) {
        LOGGER.info("cleanup " + e.toString());
      }
    }
View Full Code Here


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

   * Description: receive 2x100 messages in two subscriptions of the same client<br>
   * Expectation: passes
   */
  @Test
  public void t10_receiveTwoSubscriptions() throws Exception {
    SCPublishService service1 = client.newPublishService(TestConstants.pubServiceName1);
    SCPublishService service2 = client.newPublishService(TestConstants.pubServiceName1);

    int nrMessages = 100;
    MsgCallback cbk1 = new MsgCallback(service1);
    cbk1.setExpectedMessages(nrMessages);
    MsgCallback cbk2 = new MsgCallback(service2);
    cbk2.setExpectedMessages(nrMessages);

    SCSubscribeMessage subMsgRequest = new SCSubscribeMessage();
    SCSubscribeMessage subMsgResponse = null;
    subMsgRequest.setMask(TestConstants.mask);
    subMsgRequest.setData(Integer.toString(nrMessages));
    subMsgRequest.setDataLength(((String) subMsgRequest.getData()).length());

    subMsgResponse = service1.subscribe(subMsgRequest, cbk1);
    Assert.assertNotNull("the session ID is null", service1.getSessionId());
    Assert.assertEquals("message body is not the same length", subMsgRequest.getDataLength(), subMsgResponse.getDataLength());
    Assert.assertEquals("compression is not the same", subMsgRequest.isCompressed(), subMsgResponse.isCompressed());
    Assert.assertTrue("is not subscribed", service1.isSubscribed());

    subMsgRequest.setSessionInfo(TestConstants.publishCompressedMsgCmd);
    subMsgResponse = service2.subscribe(subMsgRequest, cbk2);
    Assert.assertNotNull("the session ID is null", service2.getSessionId());
    Assert.assertEquals("message body is not the same length", subMsgRequest.getDataLength(), subMsgResponse.getDataLength());
    Assert.assertEquals("compression is not the same", subMsgRequest.isCompressed(), subMsgResponse.isCompressed());
    Assert.assertTrue("is not subscribed", service2.isSubscribed());

    cbk1.waitForMessage(200);
    Assert.assertEquals("Nr messages does not match", nrMessages, cbk1.getMessageCount());
    SCMessage response = cbk1.getMessage();
    Assert.assertEquals("message body is empty", true, response.getDataLength() > 0);
    cbk2.waitForMessage(200);
    Assert.assertEquals("Nr messages does not match", nrMessages, cbk2.getMessageCount());
    response = cbk2.getMessage();
    Assert.assertEquals("message body is empty", true, response.getDataLength() > 0);

    service1.unsubscribe(4);
    Assert.assertNull("the session ID is not null)", service1.getSessionId());
    service2.unsubscribe(4);
    Assert.assertNull("the session ID is not null)", service2.getSessionId());
  }
View Full Code Here

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

  /**
   * Run example.
   */
  public void runExample() {
    SCClient sc = null;
    SCPublishService publishServiceA = null;
    try {
      sc = new SCClient("localhost", 7000);
      sc.setMaxConnections(100);

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

      publishServiceA = sc.newPublishService("publish-1");
      SCMessageCallback callback = new TestPublishCallback(publishServiceA);
      SCSubscribeMessage subscibeMessage = new SCSubscribeMessage();
      subscibeMessage.setMask("000012100012832102FADF-----------X-----------");
      subscibeMessage.setSessionInfo("sessionInfo");
      publishServiceA.subscribe(subscibeMessage, callback);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        // disconnects from SC
        publishServiceA.unsubscribe();
        sc.detach();
      } catch (Exception e) {
        sc = null;
      }
    }
View Full Code Here

   */
  @Test
  public void t95_TwoSubscribersServerGetsDestroyed() throws Exception {
    SCClient client2 = new SCClient(TestConstants.HOST, TestConstants.PORT_SC0_TCP, ConnectionType.NETTY_TCP);
    client2.attach();
    SCPublishService service1 = client.newPublishService(TestConstants.pubServiceName1);
    SCPublishService service2 = client2.newPublishService(TestConstants.pubServiceName1);

    SCSubscribeMessage subMsgRequest = new SCSubscribeMessage(TestConstants.pangram);
    subMsgRequest.setDataLength(TestConstants.pangram.length());
    SCSubscribeMessage subMsgResponse = null;
    subMsgRequest.setMask(TestConstants.mask);
    subMsgRequest.setSessionInfo(TestConstants.doNothingCmd);
    subMsgRequest.setNoDataIntervalSeconds(10);

    MsgCallback cbk1 = new MsgCallback(service1);
    MsgCallback cbk2 = new MsgCallback(service2);

    subMsgResponse = service1.subscribe(subMsgRequest, cbk1);
    subMsgResponse = service2.subscribe(subMsgRequest, cbk2);

    // destroy the server
    SystemSuperTest.ctrl.stopServerEnvironment(SystemSuperTest.srvCtxs);
    cbk1.waitForMessage(2);
    cbk2.waitForMessage(2);

    Assert.assertFalse("service1 is still active", service1.isActive());
    Assert.assertFalse("service2 is still active", service2.isActive());
    client2.detach();
  }
View Full Code Here

   */
  @Test
  public void t95_TwoSubscribersServerGetsDestroyed() throws Exception {
    SCClient client2 = new SCClient(TestConstants.HOST, TestConstants.PORT_SC2_TCP, ConnectionType.NETTY_TCP);
    client2.attach();
    SCPublishService service1 = client.newPublishService(TestConstants.pubServiceName1);
    SCPublishService service2 = client2.newPublishService(TestConstants.pubServiceName1);

    SCSubscribeMessage subMsgRequest = new SCSubscribeMessage(TestConstants.pangram);
    subMsgRequest.setDataLength(TestConstants.pangram.length());
    @SuppressWarnings("unused")
    SCSubscribeMessage subMsgResponse = null;
    subMsgRequest.setMask(TestConstants.mask);
    subMsgRequest.setSessionInfo(TestConstants.doNothingCmd);
    subMsgRequest.setNoDataIntervalSeconds(10);

    MsgCallback cbk1 = new MsgCallback(service1);
    MsgCallback cbk2 = new MsgCallback(service2);

    subMsgResponse = service1.subscribe(subMsgRequest, cbk1);
    subMsgResponse = service2.subscribe(subMsgRequest, cbk2);

    // destroy the server
    SystemSuperTest.ctrl.stopServerEnvironment(SystemSuperTest.srvCtxs);
    cbk1.waitForMessage(2);
    cbk2.waitForMessage(2);

    Assert.assertFalse("service1 is still active", service1.isActive());
    Assert.assertFalse("service2 is still active", service2.isActive());
    client2.detach();
  }
View Full Code Here

   * Description: two subscriptions from the same client<br>
   * Expectation: passes
   */
  @Test
  public void t40_twoSubscriptions() throws Exception {
    SCPublishService service1 = client.newPublishService(TestConstants.pubServiceName1);
    SCPublishService service2 = client.newPublishService(TestConstants.pubServiceName1);

    SCSubscribeMessage subMsgRequest = new SCSubscribeMessage(TestConstants.pangram);
    subMsgRequest.setDataLength(TestConstants.pangram.length());
    SCSubscribeMessage subMsgResponse = null;
    subMsgRequest.setMask(TestConstants.mask);
    subMsgRequest.setSessionInfo(TestConstants.doNothingCmd);
    subMsgRequest.setNoDataIntervalSeconds(10);

    MsgCallback cbk1 = new MsgCallback(service1);
    MsgCallback cbk2 = new MsgCallback(service2);

    subMsgResponse = service1.subscribe(subMsgRequest, cbk1);
    Assert.assertNotNull("the session ID is null", service1.getSessionId());
    Assert.assertEquals("message body is not the same length", subMsgRequest.getDataLength(), subMsgResponse.getDataLength());
    Assert.assertEquals("compression is not the same", subMsgRequest.isCompressed(), subMsgResponse.isCompressed());
    Assert.assertTrue("is not subscribed", service1.isSubscribed());

    subMsgResponse = service2.subscribe(subMsgRequest, cbk2);
    Assert.assertNotNull("the session ID is null", service2.getSessionId());
    Assert.assertEquals("message body is not the same length", subMsgRequest.getDataLength(), subMsgResponse.getDataLength());
    Assert.assertEquals("compression is not the same", subMsgRequest.isCompressed(), subMsgResponse.isCompressed());
    Assert.assertTrue("is not subscribed", service2.isSubscribed());

    service1.unsubscribe();
    Assert.assertNull("the session ID is not null)", service1.getSessionId());
    service2.unsubscribe();
    Assert.assertNull("the session ID is not null)", service2.getSessionId());
  }
View Full Code Here

   */
  @Test
  public void t95_TwoSubscribersServerGetsDestroyed() throws Exception {
    SCClient client2 = new SCClient(TestConstants.HOST, TestConstants.PORT_SC1_TCP, ConnectionType.NETTY_TCP);
    client2.attach();
    SCPublishService service1 = client.newPublishService(TestConstants.pubServiceName1);
    SCPublishService service2 = client2.newPublishService(TestConstants.pubServiceName1);

    SCSubscribeMessage subMsgRequest = new SCSubscribeMessage(TestConstants.pangram);
    subMsgRequest.setDataLength(TestConstants.pangram.length());
    SCSubscribeMessage subMsgResponse = null;
    subMsgRequest.setMask(TestConstants.mask);
    subMsgRequest.setSessionInfo(TestConstants.doNothingCmd);
    subMsgRequest.setNoDataIntervalSeconds(10);

    MsgCallback cbk1 = new MsgCallback(service1);
    MsgCallback cbk2 = new MsgCallback(service2);

    subMsgResponse = service1.subscribe(subMsgRequest, cbk1);
    subMsgResponse = service2.subscribe(subMsgRequest, cbk2);

    // destroy the server
    SystemSuperTest.ctrl.stopServerEnvironment(SystemSuperTest.srvCtxs);
    cbk1.waitForMessage(2);
    cbk2.waitForMessage(2);

    Assert.assertFalse("service1 is still active", service1.isActive());
    Assert.assertFalse("service2 is still active", service2.isActive());
    client2.detach();
  }
View Full Code Here

            scSessionService.createSession(scMessage, new TestSessionServiceMessageCallback(scSessionService));
          } catch (SCServiceException ex) {
          }
        } else {
          // Subscribe with KILL command
          SCPublishService scPublishService = clientMgmt.newPublishService(serviceName);
          SCSubscribeMessage scMessage = new SCSubscribeMessage();
          SCMessageCallback cbk = new TestPublishServiceMessageCallback(scPublishService);
          scMessage.setSessionInfo(TestConstants.killServerCmd);
          scMessage.setMask("ABCD"); // dummy (mask may not be empty)
          try {
            scPublishService.subscribe(scMessage, cbk);
          } catch (SCServiceException ex) {
          }
        }
        clientMgmt.detach();
        FileUtility.waitNotExistsOrUnlocked(srvProcess.getPidFileName(), timeout);
View Full Code Here

TOP

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

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.