3.10. 서버 라이프사이클 이벤트 알림


JBoss EAP core-management 하위 시스템 또는 Cryostat를 사용하여 서버 라이프사이클 이벤트에 대한 알림을 설정할 수 있습니다. 서버 런타임 구성 상태 또는 서버 실행 상태가 변경되면 알림이 트리거됩니다.

JBoss EAP의 서버 런타임 구성 상태는 STARTING,RUNNING,RELOAD_REQUIRED,RESTART_REQUIRED,STOPPING, STOPPED 입니다.

JBoss EAP에 대한 서버 실행 상태는 STARTING,NORMAL,ADMIN_ONLY,PRE_SUSPEND,SUSPENDING,SUSPENDED,STOPPING, STOPPED 입니다.

리스너를 JBoss EAP 코어 관리 하위 시스템에 등록하여 서버 라이프사이클 이벤트를 모니터링할 수 있습니다. 다음 단계에서는 이벤트를 파일에 기록하는 리스너 예제를 생성하고 등록하는 방법을 보여줍니다.

사전 요구 사항

  • JBoss EAP가 실행 중입니다.

프로세스

  1. 리스너를 생성합니다.

    아래 예제와 같이 org.wildfly.extension.core.management.client.ProcessStateListener 의 구현을 만듭니다.

    예: Listener 클래스

    package org.simple.lifecycle.events.listener;
    
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    
    import org.wildfly.extension.core.management.client.ProcessStateListener;
    import org.wildfly.extension.core.management.client.ProcessStateListenerInitParameters;
    import org.wildfly.extension.core.management.client.RunningStateChangeEvent;
    import org.wildfly.extension.core.management.client.RuntimeConfigurationStateChangeEvent;
    
    public class SimpleListener implements ProcessStateListener {
    
        private File file;
        private FileWriter fileWriter;
        private ProcessStateListenerInitParameters parameters;
    
        public void init(ProcessStateListenerInitParameters parameters) {
            this.parameters = parameters;
            this.file = new File(parameters.getInitProperties().get("file"));
            try {
                fileWriter = new FileWriter(file, true);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
        public void cleanup() {
            try {
                fileWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                fileWriter = null;
            }
        }
    
        public void runtimeConfigurationStateChanged(RuntimeConfigurationStateChangeEvent evt) {
            try {
                fileWriter.write(String.format("Runtime configuration state change for %s: %s to %s\n", parameters.getProcessType(), evt.getOldState(), evt.getNewState()));
                fileWriter.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
        public void runningStateChanged(RunningStateChangeEvent evt) {
            try {
                fileWriter.write(String.format("Running state change for %s: %s to %s\n", parameters.getProcessType(), evt.getOldState(), evt.getNewState()));
                fileWriter.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    참고

    리스너를 구현할 때 다음 사항을 고려하십시오.

    • 서버가 다시 로드되는 경우 서버가 중지되는 동안 리스너가 수신 대기를 중지하고 서버가 시작될 때 리스너가 다시 로드됩니다. 따라서 구현은 동일한 JVM 내에서 여러 번 올바르게 로드, 초기화 및 제거할 수 있는지 확인해야 합니다.
    • 리스너에 대한 알림은 서버 상태 변경에 대한 응답을 허용하기 위해 차단하고 있습니다. 구현은 차단 또는 교착 상태가 되지 않도록 해야 합니다.
    • 각 리스너 인스턴스는 자체 스레드에서 실행되며 순서가 보장되지 않습니다.
  2. 클래스를 컴파일하고 JAR에 패키징합니다.

    컴파일하려면 org.wildfly.core:wildfly-core-client Maven 모듈을 사용해야 합니다.

  3. JAR을 JBoss EAP 모듈로 추가합니다.

    다음 관리 CLI 명령을 사용하여 JAR의 모듈 이름과 경로를 제공합니다.

    module add --name=org.simple.lifecycle.events.listener --dependencies=org.wildfly.extension.core-management-client --resources=/path/to/simple-listener-0.0.1-SNAPSHOT.jar
    중요

    모듈 관리 CLI 명령을 사용하여 모듈을 추가 및 제거하는 것은 기술 프리뷰로만 제공됩니다. 이 명령은 관리형 도메인에서 사용하거나 관리 CLI에 원격으로 연결할 때 적합하지 않습니다. 모듈은 프로덕션 환경에서 수동으로 추가제거해야 합니다.

    기술 프리뷰 기능은 Red Hat 프로덕션 서비스 수준 계약(SLA)에서 지원하지 않으며, 기능상 완전하지 않을 수 있어 프로덕션에 사용하지 않는 것이 좋습니다. 이러한 기능을 사용하면 향후 제품 기능을 조기에 이용할 수 있어 개발 과정에서 고객이 기능을 테스트하고 피드백을 제공할 수 있습니다.

    기술 프리뷰 기능에 대한 지원 범위에 대한 정보는 Red Hat 고객 포털에서 기술 프리뷰 기능 지원 범위를 참조하십시오.

  4. 리스너를 등록합니다.

    다음 관리 CLI 명령을 사용하여 core-management 하위 시스템에 리스너를 추가합니다. 서버 라이프사이클 이벤트를 기록하려면 class, module, file 위치를 지정합니다.

    /subsystem=core-management/process-state-listener=my-simple-listener:add(class=org.simple.lifecycle.events.listener.SimpleListener, module=org.simple.lifecycle.events.listener,properties={file=/path/to/my-listener-output.txt})

이제 서버 라이프사이클 이벤트가 위의 SimpleListener 클래스를 기반으로 my-listener-output.txt 파일에 기록됩니다. 예를 들어 관리 CLI에서 :suspend 명령을 실행하면 다음이 my-listener-output.txt 파일에 출력됩니다.

Running state change for STANDALONE_SERVER: normal to suspending
Running state change for STANDALONE_SERVER: suspending to suspended

이는 실행 중 상태가 정상에서 일시 중지됨으로 변경된 후 일시 중지됨 나타냅니다.

3.10.2. Cryostat 알림을 사용하여 서버 라이프사이클 이벤트 모니터링

Cryostat 알림 리스너를 등록하여 서버 라이프사이클 이벤트를 모니터링할 수 있습니다. 다음 단계에서는 이벤트를 파일에 기록하는 예제 리스너를 생성하고 추가하는 방법을 보여줍니다.

사전 요구 사항

  • JBoss EAP가 실행 중입니다.

프로세스

  1. 리스너를 생성합니다.

    아래 예제와 같이 java.management.NotificationListener 의 구현을 생성합니다.

    예: Listener 클래스

    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.nio.charset.StandardCharsets;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.nio.file.StandardOpenOption;
    
    import java.management.AttributeChangeNotification;
    import java.management.Notification;
    import java.management.NotificationListener;
    
    import org.jboss.logging.Logger;
    
    public class StateNotificationListener implements NotificationListener {
    
      public static final String RUNTIME_CONFIGURATION_FILENAME = "runtime-configuration-notifications.txt";
      public static final String RUNNING_FILENAME = "running-notifications.txt";
      private final Path targetFile;
    
      public StateNotificationListener() {
        this.targetFile = Paths.get("notifications/data").toAbsolutePath();
        init(targetFile);
      }
    
      protected Path getRuntimeConfigurationTargetFile() {
        return this.targetFile.resolve(RUNTIME_CONFIGURATION_FILENAME);
      }
    
      protected Path getRunningConfigurationTargetFile() {
        return this.targetFile.resolve(RUNNING_FILENAME);
      }
    
      protected final void init(Path targetFile) {
        try {
          Files.createDirectories(targetFile);
    
          if (!Files.exists(targetFile.resolve(RUNTIME_CONFIGURATION_FILENAME))) {
            Files.createFile(targetFile.resolve(RUNTIME_CONFIGURATION_FILENAME));
          }
    
          if (!Files.exists(targetFile.resolve(RUNNING_FILENAME))) {
            Files.createFile(targetFile.resolve(RUNNING_FILENAME));
          }
        } catch (IOException ex) {
            Logger.getLogger(StateNotificationListener.class).error("Problem handling JMX Notification", ex);
        }
      }
    
      @Override
      public void handleNotification(Notification notification, Object handback) {
        AttributeChangeNotification attributeChangeNotification = (AttributeChangeNotification) notification;
        if ("RuntimeConfigurationState".equals(attributeChangeNotification.getAttributeName())) {
          writeNotification(attributeChangeNotification, getRuntimeConfigurationTargetFile());
        } else {
          writeNotification(attributeChangeNotification, getRunningConfigurationTargetFile());
        }
      }
    
      private void writeNotification(AttributeChangeNotification notification, Path path) {
        try (BufferedWriter in = Files.newBufferedWriter(path, StandardCharsets.UTF_8, StandardOpenOption.APPEND)) {
          in.write(String.format("%s %s %s %s", notification.getType(), notification.getSequenceNumber(), notification.getSource().toString(), notification.getMessage()));
          in.newLine();
          in.flush();
        } catch (IOException ex) {
          Logger.getLogger(StateNotificationListener.class).error("Problem handling JMX Notification", ex);
        }
      }
    }

  2. 알림 리스너를 등록합니다.

    알림 리스너를 Server에 추가합니다.

    예: 알림 리스너 추가

    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    server.addNotificationListener(ObjectName.getInstance("jboss.root:type=state"), new StateNotificationListener(), null, null);

  3. JBoss EAP 패키지 및 배포.

이제 서버 라이프사이클 이벤트가 위의 StateNotificationListener 클래스를 기반으로 파일에 기록됩니다. 예를 들어 관리 CLI에서 :suspend 명령을 실행하면 running-notifications.txt 파일에 다음이 출력됩니다.

jmx.attribute.change 5 jboss.root:type=state The attribute 'RunningState' has changed from 'normal' to 'suspending'
jmx.attribute.change 6 jboss.root:type=state The attribute 'RunningState' has changed from 'suspending' to 'suspended'

이는 실행 중 상태가 정상에서 일시 중지됨으로 변경된 후 일시 중지됨 나타냅니다.

Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2026 Red Hat
맨 위로 이동