Skip to content

Instantly share code, notes, and snippets.

@mseemann
Created December 23, 2019 18:07
Show Gist options
  • Save mseemann/e429f98c2ba09a1ed76733d741304e5e to your computer and use it in GitHub Desktop.
Save mseemann/e429f98c2ba09a1ed76733d741304e5e to your computer and use it in GitHub Desktop.
import io.mseemann.medium.jmxpg.beans.AppInfo;
import io.mseemann.medium.jmxpg.beans.Requests;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
import java.util.Hashtable;
public class App {
static final String NAMESPACE = "jmxpg.mbeans";
static final String GET_REQUESTS_O_NAME = NAMESPACE + ":type=Requests,verb=GET";
static final String POST_REQUESTS_O_NAME = NAMESPACE + ":type=Requests,verb=POST";
public static void main(String... args) throws Exception {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
AppInfo appInfo = new AppInfo();
appInfo.setStatus("starting");
Hashtable<String, String> keyValues = new Hashtable<>();
keyValues.put("type", "AppInfo");
keyValues.put("Version", App.class.getPackage().getImplementationVersion());
mbs.registerMBean(appInfo, new ObjectName("jmxpg.mbeans", keyValues));
Requests getRequests = new Requests();
mbs.registerMBean(getRequests, new ObjectName(GET_REQUESTS_O_NAME));
Requests postRequests = new Requests();
mbs.registerMBean(postRequests, new ObjectName(POST_REQUESTS_O_NAME));
// start a small simulation
new Thread(new AppStateSimulation(appInfo)).start();
new Thread(new RequestSimulation(getRequests, 50)).start();
new Thread(new RequestSimulation(postRequests, 150)).start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> appInfo.setStatus("exited")));
Thread.sleep(Integer.MAX_VALUE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment