-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
50 lines (41 loc) · 1.75 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package JSR160JMXRemoting;
import JSR160JMXRemoting.mxbean.MessageQueue;
import JSR160JMXRemoting.mbean.Speaker;
import JSR160JMXRemoting.mbean.SpeakerMBean;
import JSR160JMXRemoting.mxbean.Message;
import javax.management.*;
import java.lang.management.ManagementFactory;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
/**
* To JMX connection between different servers add the following params to your jvm:
*
* -Dcom.sun.management.jmxremote.port=8090 \
* -Dcom.sun.management.jmxremote.authenticate=false \
* -Dcom.sun.management.jmxremote.ssl=false \
*
* for example:
* java -Dcom.sun.management.jmxremote.port=8090 \
* -Dcom.sun.management.jmxremote.authenticate=false \
* -Dcom.sun.management.jmxremote.ssl=false \
* -jar *-SNAPSHOT.jar
*/
public class Main {
public static void main(String[] args) throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName speakerName = new ObjectName("com.ibrahimatay:type=Speaker");
SpeakerMBean bean = new Speaker();
mbs.registerMBean(bean, speakerName);
ObjectName messageName = new ObjectName("com.ibrahimatay:type=Message");
Queue<Message> messages = new ArrayBlockingQueue<Message>(10);
messages.add(new Message("Message 1"));
messages.add(new Message("Message 2"));
messages.add(new Message("Message 3"));
messages.add(new Message("Message 4"));
MessageQueue messageQueue = new MessageQueue(messages);
mbs.registerMBean(messageQueue, messageName);
System.out.println("Started");
while (true) {
}
}
}