1

Could you please give an example, how I can invoke the WroConfiguration.reloadCache() method via JMX? I use Wildfly, singleton startup ejb, in case it does matter.

JMX is switched on: jmxEnabled=true

Alexandr
  • 9,213
  • 12
  • 62
  • 102

2 Answers2

2

Here is an example and requirements in Java EE environment:

  1. in the wro.properties the following properties are applied:
cacheUpdatePeriod=0
modelUpdatePeriod=0
debug=false
disableCache=true
jmxEnabled=true
...
  1. Don't try to update wro cache model in ejb bean with @Singleton/@Startup annotations applied in the initial method with the @PostConstruct annotation applied. Wro MBean is not registred yet, so, it will not work.
  2. Example itself:
try
{
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = new ObjectName("wro4j-ROOT:type=WroConfiguration");
    mbs.invoke(name, "reloadCache", null, null);
    mbs.invoke(name, "reloadModel", null, null);
}
catch (InstanceNotFoundException e)
{
    logger.warn("Could not find wro4j MBean. It has not been initiated yet");
}
catch (Exception e)
{
    logger.error(e);
}
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Alexandr
  • 9,213
  • 12
  • 62
  • 102
1

When jmxEnabled configuration is set to true, the MBean is registered automatically. If you open the jconsole, you should see an MBean called something like "wro4j-ROOT" (the MBean name is dynamic based on the application context name). There you should find the operation called reloadModel & reloadCache which can be triggered via JMX.

Beside using JMX, I recommend using the following configuration: resourceWatcherUpdatePeriod (set this value to something bigger than 0). This is useful during development, when any change will be detected out of the box within the specified interval.

Alex Objelean
  • 3,893
  • 2
  • 27
  • 36