public void stopServer(ProcessCtx srvProcess) throws Exception {
int timeout = 15; // seconds
try {
if (FileUtility.exists(srvProcess.getPidFileName())) {
SCMgmtClient clientMgmt = new SCMgmtClient(TestConstants.HOST, srvProcess.getSCPort(),
srvProcess.getConnectionType());
clientMgmt.attach(timeout);
String serviceName = srvProcess.getServiceNames().split(",")[0];
clientMgmt.enableService(serviceName); // service might be disabled during tests
if (srvProcess.getCommunicatorType() == TestConstants.COMMUNICATOR_TYPE_SESSION) {
// Create session with KILL command
SCSessionService scSessionService = clientMgmt.newSessionService(serviceName);
SCMessage scMessage = new SCMessage();
scMessage.setSessionInfo(TestConstants.killServerCmd);
try {
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);
}
testLogger.info("Server " + srvProcess.getProcessName() + " stopped");
} catch (Exception e) {
testLogger.info(e.getMessage());