Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added copyright info, cleanup, refactoring, fixes
- Loading branch information
Luigi R. Viggiano
committed
Nov 27, 2014
1 parent
d9d27ce
commit 907fb6a
Showing
5 changed files
with
180 additions
and
258 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
owner/src/test/java/org/aeonbits/owner/examples/JMXExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2012-2014, Luigi R. Viggiano | ||
* All rights reserved. | ||
* | ||
* This software is distributable under the BSD license. | ||
* See the terms of the BSD license in the documentation provided with this software. | ||
*/ | ||
|
||
package org.aeonbits.owner.examples; | ||
|
||
import org.aeonbits.owner.Accessible; | ||
import org.aeonbits.owner.ConfigFactory; | ||
import org.aeonbits.owner.Mutable; | ||
import org.aeonbits.owner.Reloadable; | ||
import org.aeonbits.owner.event.ReloadEvent; | ||
import org.aeonbits.owner.event.ReloadListener; | ||
|
||
import javax.management.DynamicMBean; | ||
import javax.management.InstanceAlreadyExistsException; | ||
import javax.management.MBeanRegistrationException; | ||
import javax.management.MBeanServer; | ||
import javax.management.MalformedObjectNameException; | ||
import javax.management.NotCompliantMBeanException; | ||
import javax.management.ObjectName; | ||
import java.beans.PropertyChangeEvent; | ||
import java.beans.PropertyChangeListener; | ||
import java.lang.management.ManagementFactory; | ||
|
||
/** | ||
* @author Luigi R. Viggiano | ||
*/ | ||
public class JMXExample { | ||
|
||
public interface MyConfig extends DynamicMBean, Mutable, Accessible, Reloadable { | ||
|
||
@Key("server.port.number") | ||
@DefaultValue("80") | ||
int port(); | ||
|
||
@Key("server.host.name") | ||
@DefaultValue("localhost") | ||
String hostname(); | ||
|
||
} | ||
|
||
public static void main(String[] args) throws InterruptedException, MalformedObjectNameException, | ||
InstanceAlreadyExistsException, NotCompliantMBeanException, MBeanRegistrationException { | ||
MyConfig cfg = ConfigFactory.create(MyConfig.class); | ||
|
||
cfg.addPropertyChangeListener(new PropertyChangeListener() { | ||
public void propertyChange(PropertyChangeEvent evt) { | ||
System.out.printf("prop change event [%s = %s -> %s]%n", evt.getPropertyName(), evt.getOldValue(), evt.getNewValue()); | ||
} | ||
}); | ||
|
||
cfg.addReloadListener(new ReloadListener() { | ||
public void reloadPerformed(ReloadEvent event) { | ||
System.out.printf("reload event detected%n"); | ||
} | ||
}); | ||
|
||
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); | ||
|
||
mbs.registerMBean(cfg, new ObjectName("org.aeonbits.owner.examples:type=MyConfig")); | ||
|
||
System.out.println("Now, launch jconsole and attach to the java process. Set a negative port number to exit."); | ||
|
||
while (cfg.port() >= 0) { | ||
System.out.printf("\rport: %d hostname: %s \t\t\t\t", cfg.port(), cfg.hostname()); | ||
Thread.sleep(500); | ||
} | ||
|
||
} | ||
|
||
} |
19 changes: 13 additions & 6 deletions
19
owner/src/test/java/org/aeonbits/owner/jmx/InvalidJMXBeanTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.