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);
}