2017-12-21 11 views
0

안녕하십니까? Startup bean의 @PostConstruct 메소드에서 JMX를 통해 wildfly 서버의 시스템 속성을로드하려고합니다. 배포가 시작될 때 이미 시작된 서버 인스턴스에서 제대로 작동하지만 서버 인스턴스 부트 스트래핑으로 시작하는 동안 실패합니다.Wildfly의 Startup Bean의 JMX를 통한 AttributeNotFoundException

제이보스 11.0.0.CR1 시작 콩 코드 :

package ru.wildfly.test.ejb.wildflyconsulregistrar.startup; 
import ru.wildfly.test.ejb.wildflyconsulregistrar.api.ConsulRegistrar; 

import javax.annotation.PostConstruct; 
import javax.annotation.PreDestroy; 
import javax.ejb.Singleton; 
import javax.ejb.Startup; 
import javax.inject.Inject; 

@Startup 
@Singleton 
public class WildflyConsulRegistrarStartupBean { 

    @Inject 
    private ConsulRegistrar consulRegistrar; 

    @PostConstruct 
    public void initialize() { 
     registerServices(); 
    } 

    private void registerServices() { 
     consulRegistrar.registerService("WildflyTestCluster"); 
    } 


    ............. 
} 

ConsulRegistrar 코드 :

package ru.wildfly.test.ejb.wildflyconsulregistrar.impl; 

import com.ecwid.consul.v1.ConsulClient; 
import com.ecwid.consul.v1.agent.model.NewService; 
import ru.test.ejb.wildflyconsulregistrar.api.ConsulRegistrar; 
import ru.wildfly.test.ejb.wildflyconsulregistrar.serversettings.api.CurrentServerNodeSettings; 

import javax.annotation.PostConstruct; 
import javax.enterprise.context.Dependent; 
import javax.inject.Inject; 
import java.text.MessageFormat; 
import java.util.ArrayList; 
import java.util.List; 

@Dependent 
public class ConsulRegistrarImpl implements ConsulRegistrar { 

    ............... 

    @Inject 
    private CurrentServerNodeSettings currentServerNodeSettings; 

    ............. 

    @Override 
    public void registerService(String serviceName) { 
     String currentNodeName = currentServerNodeSettings.getCurrentNodeName(); 
     ........................ 
    } 

    ....................... 

} 

CurrentServerNodeSettings 코드 :

package ru.wildfly.test.ejb.wildflyconsulregistrar.serversettings.impl; 


import ru.wildfly.test.ejb.wildflyconsulregistrar.serversettings.api.CurrentServerNodeSettings; 

import javax.enterprise.context.Dependent; 
import javax.management.MBeanServer; 
import javax.management.ObjectName; 
import java.lang.management.ManagementFactory; 

@Dependent 
public class CurrentServerNodeSettingsWildflyImpl implements CurrentServerNodeSettings { 

    .................... 

    @Override 
    public String getCurrentNodeName() { 
     String currentNodeName = getPlatformMBeanServerAttributeValue(String.class, "jboss.as:system-property=server.name", "value"); 
     return currentNodeName; 
    } 

    private <T> T getPlatformMBeanServerAttributeValue(Class<T> valueType, String objectName, String attributeName) { 
     T attributeValue = null; 

     try { 
      MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); 
      Object attributeObject = mBeanServer.getAttribute(new ObjectName(objectName), attributeName); 

      attributeValue = attributeObject != null ? (valueType.cast(attributeObject)) : null; 
     } catch (Exception ex) { 
      throw new IllegalStateException(ex); 
     } 

     return attributeValue; 
    } 
} 

오류 메시지 :

Caused by: java.lang.IllegalStateException: 
javax.management.AttributeNotFoundException: 
"WFLYCTL0216: Management resource '[(\"system-property\" => \"server.name\")]' not found" 
at ru.wildfly.test.ejb.wildflyconsulregistrar.serversettings.impl.CurrentServerNodeSettingsWildflyImpl 
.getPlatformMBeanServerAttributeValue(CurrentServerNodeSettingsWildflyImpl.java:41) 

jboss 포럼 https://developer.jboss.org/message/971717#971717에서 동일한 문제가 발견되었지만 답이 없습니다.

제안 사항?

답변

0

이것은 시작하는 동안 종속성 문제입니다. 즉 @PostConstruct 메서드가 실행 된 후 서버 이름이 설정됩니다. 응용 프로그램에서 처음 액세스 할 때 서버 이름을 느슨하게로드하십시오.

Wildly에는 모듈 종속성의 정의에도 불구하고 응용 프로그램에서 배포 순서를 적용 할 수있는 일반적인 방법이 없습니다. 그러나 이것은 귀하의 경우에 도움이되지 않습니다.

+0

로드 균형 조정에 포함시키기 위해 서비스 검색 구성 요소에 현재 서버 인스턴스를 등록하려면이 등록 정보가 필요합니다. 내가 의존 할 수있는 의존성이 없다면, 어떤 종류의 재시도 시스템으로 작업을 구현할 것이다. 그럼에도 불구하고, 고마워. – netfisher777