@Override
  public void closeSessions(String principalName, String principalClassName) throws Exception {
    if ((principalName == null)
        || (principalName.trim().length() == 0)
        || (principalClassName == null)
        || (principalClassName.trim().length() == 0)) {
      return;
    }

    principalName = principalName.trim();
    principalClassName = principalClassName.trim();

    Map<Long, Map<String, String>> sessionPrincipalMap =
        serviceManagementBean.getLoggedInSessions();

    for (Map.Entry<Long, Map<String, String>> entry : sessionPrincipalMap.entrySet()) {
      long sessionId = entry.getKey();
      Map<String, String> userPrincipals = entry.getValue();

      for (Map.Entry<String, String> principal : userPrincipals.entrySet()) {
        String key = principal.getKey();
        String value = principal.getValue();

        // Case sensitive for both name and class-name.
        if (key.equals(principalName) && (value.equals(principalClassName))) {
          SessionMXBean sessionBean = managementServiceHandler.getSessionMXBean(sessionId);
          sessionBean.close();
          serviceManagementBean.removeSessionManagementBean(sessionId);
          break;
        }
      }
    }
  }
  @Override
  public Map<String, String> getUserPrincipals(Long sessionId) {
    // First, get the map of session ID to user principals for that session.
    Map<Long, Map<String, String>> sessionPrincipalMap =
        serviceManagementBean.getLoggedInSessions();

    if (sessionPrincipalMap != null) {
      for (Map.Entry<Long, Map<String, String>> entry : sessionPrincipalMap.entrySet()) {
        if (entry.getKey() == sessionId.longValue()) {
          return entry.getValue();
        }
      }
    }

    return null;
  }
  /**
   * Return a map of session mbean names to the user principals for those sessions. The
   * serviceManagementBean stores them as session ID to user principals, and we have to convert the
   * session ID to mbean name here. Gross, but it's the only way to not have JMX-specific stuff in
   * the ServiceManagementBean.
   */
  @Override
  public Map<String, Map<String, String>> getLoggedInSessions() {
    // First, get the map of session ID to user principals for that session.
    Map<Long, Map<String, String>> sessionPrincipalMap =
        serviceManagementBean.getLoggedInSessions();

    Map<String, Map<String, String>> result = new HashMap<>();

    for (Map.Entry<Long, Map<String, String>> entry : sessionPrincipalMap.entrySet()) {
      long sessionId = entry.getKey();
      Map<String, String> userPrincipals = entry.getValue();
      ObjectName sessionMBeanName =
          managementServiceHandler.getSessionMXBean(sessionId).getObjectName();
      result.put(sessionMBeanName.toString(), userPrincipals);
    }

    return result;
  }
 @Override
 public void restart() throws Exception {
   serviceManagementBean.restart();
 }
 @Override
 public void stop() throws Exception {
   serviceManagementBean.stop();
 }
 @Override
 public boolean isHeartbeatRunning() {
   return serviceManagementBean.isHeartbeatRunning();
 }
 @Override
 public boolean isServiceConnected() {
   return serviceManagementBean.isServiceConnected();
 }
 @Override
 public int getHeartbeatPingFailuresCount() {
   return serviceManagementBean.getHeartbeatPingFailuresCount();
 }
 @Override
 public String getLatestException() {
   return serviceManagementBean.getLatestException();
 }
 @Override
 public long getNumberOfCumulativeEmulatedSessions() {
   return serviceManagementBean.getCumulativeEmulatedSessionCount();
 }
 @Override
 public long getLastFailedConnectTime() {
   return serviceManagementBean.getLastFailedConnectTime();
 }
 @Override
 public long getLastSuccessfulConnectTime() {
   return serviceManagementBean.getLastSuccessfulConnectTime();
 }
 @Override
 public long getTotalBytesSentCount() {
   return serviceManagementBean.getTotalBytesSentCount();
 }
 @Override
 public void clearCumulativeSessionsCount() {
   serviceManagementBean.clearCumulativeSessionsCount();
 }
 @Override
 public boolean getLastHeartbeatPingResult() {
   return serviceManagementBean.getLastHeartbeatPingResult();
 }
 public int getIndex() {
   return serviceManagementBean.getId();
 }
 @Override
 public long getLastHeartbeatPingTimestamp() {
   return serviceManagementBean.getLastHeartbeatPingTimestamp();
 }
 @Override
 public long getNumberOfCurrentNativeSessions() {
   return serviceManagementBean.getCurrentNativeSessionCount();
 }
 @Override
 public long getNumberOfExceptions() {
   return serviceManagementBean.getExceptionCount();
 }