[jboss-jira] [JBoss JIRA] (WFCORE-1157) Managmement and JMX notifications when ControlledProcessState changes

Kabir Khan (JIRA) issues at jboss.org
Wed Apr 13 06:57:01 EDT 2016


    [ https://issues.jboss.org/browse/WFCORE-1157?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13191121#comment-13191121 ] 

Kabir Khan commented on WFCORE-1157:
------------------------------------

It seems we already have the mechanism to register a property change listener with the ControlledProcessStateService. This is used in another few places, so perhaps we should just do that? Otherwise some untangling is needed of the order where we create the NotificationSupport and the ControlledProcessState.

The following change just to get some logging:
{code}
$git diff --cached 
diff --git a/controller/src/main/java/org/jboss/as/controller/AbstractControllerService.java b/controller/src/main/java/org/jboss/as/controller/AbstractControllerService.java
index 463fcb7..2b93c69 100644
--- a/controller/src/main/java/org/jboss/as/controller/AbstractControllerService.java
+++ b/controller/src/main/java/org/jboss/as/controller/AbstractControllerService.java
@@ -24,6 +24,8 @@ package org.jboss.as.controller;
 
 import static org.jboss.as.controller.logging.ControllerLogger.ROOT_LOGGER;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.io.IOException;
 import java.util.List;
 import java.util.ServiceLoader;
@@ -81,6 +83,7 @@ public abstract class AbstractControllerService implements Service<ModelControll
      * @see #BOOT_STACK_SIZE_PROPERTY
      */
     public static final int DEFAULT_BOOT_STACK_SIZE = 2 * 1024 * 1024;
+    private final PropertyChangeListener propertyChangeListener;
 
     private static int getBootStackSize() {
         String prop = WildFlySecurityManager.getPropertyPrivileged(BOOT_STACK_SIZE_PROPERTY, null);
@@ -262,6 +265,15 @@ public abstract class AbstractControllerService implements Service<ModelControll
         this.authorizer = authorizer;
         this.bootErrorCollector = new BootErrorCollector();
         this.capabilityRegistry = capabilityRegistry.createShadowCopy(); //create shadow copy of proper registry so changes can only be visible by .publish()
+        this.propertyChangeListener = new PropertyChangeListener() {
+            @Override
+            public void propertyChange(PropertyChangeEvent evt) {
+                if ("currentState".equals(evt.getPropertyName())) {
+                    ControlledProcessState.State newState = (ControlledProcessState.State) evt.getNewValue();
+                    System.out.println("------> CHANGED STATE TO " + newState);
+                }
+            }
+        };
     }
 
     @Override
@@ -277,6 +289,7 @@ public abstract class AbstractControllerService implements Service<ModelControll
         final ExecutorService executorService = injectedExecutorService.getOptionalValue();
 
         final NotificationSupport notificationSupport = NotificationSupport.Factory.create(executorService);
+        processState.getService().addPropertyChangeListener(propertyChangeListener);
         WritableAuthorizerConfiguration authorizerConfig = authorizer.getWritableAuthorizerConfiguration();
         authorizerConfig.reset();
         ManagementResourceRegistration rootResourceRegistration = ManagementResourceRegistration.Factory.create(rootResourceDefinition, authorizerConfig, capabilityRegistry);
@@ -499,6 +512,7 @@ public abstract class AbstractControllerService implements Service<ModelControll
         } finally {
             context.asynchronous();
         }
+        this.processState.getService().removePropertyChangeListener(propertyChangeListener);
     }
 
     /**
{code}

results in the following output starting a standalone instance:
{code}
12:42:21,431 INFO  [org.jboss.modules] (main) JBoss Modules version 1.5.1.Final
12:42:21,638 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
12:42:21,721 INFO  [org.jboss.as] (MSC service thread 1-6) WFLYSRV0049: WildFly Core 3.0.0.Alpha1-SNAPSHOT "Kenny" starting
12:42:22,256 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
12:42:22,278 INFO  [org.xnio] (MSC service thread 1-4) XNIO version 3.3.6.Final
12:42:22,285 INFO  [org.xnio.nio] (MSC service thread 1-4) XNIO NIO Implementation Version 3.3.6.Final
12:42:22,327 INFO  [org.jboss.remoting] (MSC service thread 1-4) JBoss Remoting version 4.0.18.Final
12:42:22,384 WARN  [org.jboss.as.domain.http.api.undertow] (MSC service thread 1-8) WFLYDMHTTP0003: Unable to load console module for slot main, disabling console
12:42:22,518 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
12:42:22,519 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
12:42:22,519 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Core 3.0.0.Alpha1-SNAPSHOT "Kenny" started in 1441ms - Started 56 of 58 services (16 services are lazy, passive or on-demand)
12:42:22,522 INFO  [stdout] (Controller Boot Thread) ------> CHANGED STATE TO running
{code}
Next I remove a socket binding:
{code}
12:43:47,754 INFO  [stdout] (management-handler-thread - 1) ------> CHANGED STATE TO reload-required
{code}
Doing a reload gives
{code}
12:39:11,778 INFO  [stdout] (management-handler-thread - 1) ------> CHANGED STATE TO stopping
12:39:11,799 INFO  [org.jboss.as] (MSC service thread 1-7) WFLYSRV0050: WildFly Core 3.0.0.Alpha1-SNAPSHOT "Kenny" stopped in 20ms
12:39:11,800 INFO  [org.jboss.as] (MSC service thread 1-7) WFLYSRV0049: WildFly Core 3.0.0.Alpha1-SNAPSHOT "Kenny" starting
12:39:11,840 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
12:39:11,853 WARN  [org.jboss.as.domain.http.api.undertow] (MSC service thread 1-6) WFLYDMHTTP0003: Unable to load console module for slot main, disabling console
12:39:11,888 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
12:39:11,889 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
12:39:11,889 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Core 3.0.0.Alpha1-SNAPSHOT "Kenny" started in 87ms - Started 56 of 58 services (16 services are lazy, passive or on-demand)
12:39:11,890 INFO  [stdout] (Controller Boot Thread) ------> CHANGED STATE TO running
{code}
So it seems that all the changes will get captured properly using this approach *apart from 'starting'*. That change happens before the property change listener is registered. One option is to hardcode it when I register the listener in the AbstractControllerService.start() method. Unless we want to detangle this and make sure that the NotificationSupport is created before the ControlledProcessState (currently happens in the various bootstrap classes).

I have not looked into what JMX would do yet.

> Managmement and JMX notifications when ControlledProcessState changes
> ---------------------------------------------------------------------
>
>                 Key: WFCORE-1157
>                 URL: https://issues.jboss.org/browse/WFCORE-1157
>             Project: WildFly Core
>          Issue Type: Enhancement
>          Components: Domain Management, JMX
>            Reporter: Brian Stansberry
>            Assignee: Kabir Khan
>             Fix For: 3.0.0.Alpha1
>
>
> When Jeff Mesnil added the core management notification stuff an obvious thing to do was to emit notifications around ControlledProcessState changes. But I forgot. :( So lets do it.



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the jboss-jira mailing list