org.jgroups.util.Util.getMBeanServer()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(175)

本文整理了Java中org.jgroups.util.Util.getMBeanServer()方法的一些代码示例,展示了Util.getMBeanServer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.getMBeanServer()方法的具体详情如下:
包路径:org.jgroups.util.Util
类名称:Util
方法名:getMBeanServer

Util.getMBeanServer介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

  1. public void channelDisconnected(JChannel channel) {
  2. if(jmx) {
  3. MBeanServer server=Util.getMBeanServer();
  4. if(server != null) {
  5. try {
  6. JmxConfigurator.unregisterChannel(channel, server, cluster_name);
  7. }
  8. catch(Exception e) {
  9. e.printStackTrace();
  10. }
  11. }
  12. }
  13. }

代码示例来源:origin: wildfly/wildfly

  1. public void stop() {
  2. looping=false;
  3. try {
  4. JmxConfigurator.unregisterChannel(channel, Util.getMBeanServer(), "jgroups", "mperf");
  5. }
  6. catch(Exception e) {
  7. e.printStackTrace();
  8. }
  9. Util.close(channel);
  10. }

代码示例来源:origin: wildfly/wildfly

  1. public void stop() {
  2. looping=false;
  3. try {
  4. JmxConfigurator.unregisterChannel(channel, Util.getMBeanServer(), "jgroups", "mperf");
  5. }
  6. catch(Exception e) {
  7. e.printStackTrace();
  8. }
  9. Util.close(channel);
  10. }

代码示例来源:origin: wildfly/wildfly

  1. public static void registerChannel(JChannel channel,String name) {
  2. MBeanServer server=Util.getMBeanServer();
  3. if(server != null) {
  4. try {
  5. JmxConfigurator.registerChannel(channel,
  6. server,
  7. (name != null? name : "jgroups"),
  8. channel.getClusterName(),
  9. true);
  10. }
  11. catch(Exception e) {
  12. e.printStackTrace();
  13. }
  14. }
  15. }

代码示例来源:origin: wildfly/wildfly

  1. public void start(String props, String name) throws Exception {
  2. this.props=props;
  3. this.name=name;
  4. StringBuilder sb=new StringBuilder();
  5. sb.append("\n\n----------------------- MPerf -----------------------\n");
  6. sb.append("Date: ").append(new Date()).append('\n');
  7. sb.append("Run by: ").append(System.getProperty("user.name")).append("\n");
  8. sb.append("JGroups version: ").append(Version.description).append('\n');
  9. System.out.println(sb);
  10. channel=new JChannel(props);
  11. channel.setName(name);
  12. channel.setReceiver(this);
  13. channel.connect("mperf");
  14. local_addr=channel.getAddress();
  15. JmxConfigurator.registerChannel(channel, Util.getMBeanServer(), "jgroups", "mperf", true);
  16. // send a CONFIG_REQ to the current coordinator, so we can get the current config
  17. Address coord=channel.getView().getCoord();
  18. if(coord != null && !local_addr.equals(coord))
  19. send(coord,null,MPerfHeader.CONFIG_REQ, Message.Flag.RSVP);
  20. }

代码示例来源:origin: wildfly/wildfly

  1. protected void _init(JChannel ch, long sleep_time, String name) throws Exception {
  2. this.sleep_time=sleep_time;
  3. channel=ch;
  4. if(name != null)
  5. channel.setName(name);
  6. channel.connect(getClass().getSimpleName());
  7. channel.setReceiver(receiver);
  8. try {
  9. MBeanServer server=Util.getMBeanServer();
  10. JmxConfigurator.registerChannel(channel, server, "jgroups-" + name, channel.getClusterName(), true);
  11. }
  12. catch(Throwable ex) {
  13. System.err.println("registering the channel with JMX failed: " + ex);
  14. }
  15. }

代码示例来源:origin: wildfly/wildfly

  1. public static void main(String[] args) {
  2. JmxDemo demo=new JmxDemo();
  3. demo.addNotificationListener((notification, handback) -> System.out.println(">> " + notification + ", handback=" + handback), null, "myHandback");
  4. demo.startNotifications();
  5. MBeanServer server=Util.getMBeanServer();
  6. if(server != null) {
  7. try {
  8. JmxConfigurator.register(demo, server, "demo:name=DemoObject");
  9. while(true) {
  10. Util.sleep(10000);
  11. }
  12. }
  13. catch(Exception e) {
  14. e.printStackTrace();
  15. }
  16. }
  17. }

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Lifecycle operation. Called after create(). When this method is called, the managed attributes
  3. * have already been set.<br>
  4. * Brings the Router into a fully functional state.
  5. */
  6. @ManagedOperation(description="Lifecycle operation. Called after create(). When this method is called, "
  7. + "the managed attributes have already been set. Brings the Router into a fully functional state.")
  8. public void start() throws Exception {
  9. if(!running.compareAndSet(false, true))
  10. return;
  11. if(jmx)
  12. JmxConfigurator.register(this, Util.getMBeanServer(), "jgroups:name=GossipRouter");
  13. InetAddress tmp=bind_addr != null? InetAddress.getByName(bind_addr) : null;
  14. server=use_nio? new NioServer(thread_factory, socket_factory, tmp, port, port, null, 0)
  15. : new TcpServer(thread_factory, socket_factory, tmp, port, port, null, 0);
  16. server.receiver(this);
  17. server.start();
  18. server.addConnectionListener(this);
  19. Runtime.getRuntime().addShutdownHook(new Thread(GossipRouter.this::stop));
  20. }

代码示例来源:origin: wildfly/wildfly

  1. protected void applyNewConfig(byte[] buffer) {
  2. final InputStream in=new ByteArrayInputStream(buffer);
  3. Thread thread=new Thread(() -> {
  4. try {
  5. JChannel ch=new JChannel(in);
  6. Util.sleepRandom(1000, 5000);
  7. channel.disconnect();
  8. JChannel tmp=channel;
  9. channel=ch;
  10. channel.setName(name);
  11. channel.setReceiver(MPerf.this);
  12. channel.connect("mperf");
  13. local_addr=channel.getAddress();
  14. JmxConfigurator.unregisterChannel(tmp, Util.getMBeanServer(), "jgroups", "mperf");
  15. Util.close(tmp);
  16. JmxConfigurator.registerChannel(channel, Util.getMBeanServer(), "jgroups", "mperf", true);
  17. }
  18. catch(Exception e) {
  19. System.err.println("failed creating new channel");
  20. }
  21. });
  22. System.out.println("<< restarting channel");
  23. thread.start();
  24. }

代码示例来源:origin: wildfly/wildfly

  1. public void start(String props, String name) throws Exception {
  2. this.props=props;
  3. this.name=name;
  4. StringBuilder sb=new StringBuilder();
  5. sb.append("\n\n----------------------- MPerf -----------------------\n");
  6. sb.append("Date: ").append(new Date()).append('\n');
  7. sb.append("Run by: ").append(System.getProperty("user.name")).append("\n");
  8. sb.append("JGroups version: ").append(Version.description).append('\n');
  9. System.out.println(sb);
  10. channel=new JChannel(props);
  11. channel.setName(name);
  12. disp=new RpcDispatcher(channel, this).setMembershipListener(this).setMethodLookup(id -> METHODS[id])
  13. .setMarshaller(new MperfMarshaller());
  14. send_options.mode(sync? ResponseMode.GET_ALL : ResponseMode.GET_NONE);
  15. if(oob)
  16. send_options.flags(Message.Flag.OOB);
  17. channel.connect("mperf");
  18. local_addr=channel.getAddress();
  19. JmxConfigurator.registerChannel(channel, Util.getMBeanServer(), "jgroups", "mperf", true);
  20. // send a CONFIG_REQ to the current coordinator, so we can get the current config
  21. Address coord=channel.getView().getCoord();
  22. if(coord != null && !local_addr.equals(coord))
  23. invokeRpc(configReq, coord, RequestOptions.ASYNC().flags(Message.Flag.RSVP), local_addr);
  24. }

代码示例来源:origin: wildfly/wildfly

  1. public void exit() { // 8
  2. ProtocolStack stack=channel.getProtocolStack();
  3. String cluster_name=channel.getClusterName();
  4. try {
  5. JmxConfigurator.unregisterChannel(channel, Util.getMBeanServer(), "jgroups", "mperf");
  6. }
  7. catch(Exception e) {
  8. }
  9. stack.stopStack(cluster_name);
  10. stack.destroy();
  11. }

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Always called before destroy(). Close connections and frees resources.
  3. */
  4. @ManagedOperation(description="Always called before destroy(). Closes connections and frees resources")
  5. public void stop() {
  6. if(!running.compareAndSet(true, false))
  7. return;
  8. try {
  9. JmxConfigurator.unregister(this, Util.getMBeanServer(), "jgroups:name=GossipRouter");
  10. }
  11. catch(Exception ex) {
  12. log.error(Util.getMessage("MBeanDeRegistrationFailed"), ex);
  13. }
  14. Util.close(server);
  15. log.debug("router stopped");
  16. }

代码示例来源:origin: wildfly/wildfly

  1. public void start() throws Exception {
  2. ch=new JChannel(props);
  3. if(name != null)
  4. ch.setName(name);
  5. execution_service=new ExecutionService(ch);
  6. runner=new ExecutionRunner(ch);
  7. ch.connect("executing-cluster");
  8. JmxConfigurator.registerChannel(ch, Util.getMBeanServer(),
  9. "execution-service", ch.getClusterName(), true);
  10. // Start a consumer
  11. queue.add(executor.submit(runner));
  12. random = new Random();
  13. printValues = false;
  14. try {
  15. loop();
  16. }
  17. catch(Exception e) {
  18. e.printStackTrace();
  19. }
  20. finally {
  21. Util.close(ch);
  22. }
  23. }

代码示例来源:origin: wildfly/wildfly

  1. public ReplicatedTree(String groupname, String props, long state_fetch_timeout, boolean jmx) throws Exception {
  2. if(groupname != null)
  3. this.groupname=groupname;
  4. if(props != null)
  5. this.props=props;
  6. this.jmx=jmx;
  7. this.state_fetch_timeout=state_fetch_timeout;
  8. channel=new JChannel(this.props);
  9. channel.setReceiver(this);
  10. channel.connect(this.groupname);
  11. if(jmx) {
  12. MBeanServer server=Util.getMBeanServer();
  13. if(server == null)
  14. throw new Exception("No MBeanServers found; need to run with an MBeanServer present, or inside JDK 5");
  15. JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName() , true);
  16. }
  17. start();
  18. }

代码示例来源:origin: wildfly/wildfly

  1. public void start(JChannel ch) throws Exception {
  2. this.ch=ch;
  3. lock_service=new LockService(ch);
  4. lock_service.addLockListener(this);
  5. ch.connect("lock-cluster");
  6. JmxConfigurator.registerChannel(ch, Util.getMBeanServer(), "lock-service", ch.getClusterName(), true);
  7. try {
  8. loop();
  9. }
  10. catch(Exception e) {
  11. e.printStackTrace();
  12. }
  13. finally {
  14. Util.close(ch);
  15. }
  16. }

代码示例来源:origin: wildfly/wildfly

  1. protected void start(InetAddress bind_addr, int port, boolean nio) throws Exception {
  2. server=nio? new NioServer(bind_addr, port) : new TcpServer(bind_addr, port);
  3. server.receiver(this);
  4. server.start();
  5. JmxConfigurator.register(server, Util.getMBeanServer(), "pub:name=pub-server");
  6. int local_port=server.localAddress() instanceof IpAddress? ((IpAddress)server.localAddress()).getPort(): 0;
  7. System.out.printf("\nPubServer listening at %s:%s\n", bind_addr != null? bind_addr : "0.0.0.0", local_port);
  8. }

代码示例来源:origin: wildfly/wildfly

  1. public void start() throws Exception {
  2. try {
  3. ch=new JChannel(props);
  4. if(name != null)
  5. ch.setName(name);
  6. lock_service=new LockService(ch);
  7. lock_service.addLockListener(this);
  8. ch.connect("lock-cluster");
  9. JmxConfigurator.registerChannel(ch, Util.getMBeanServer(), "lock-service", ch.getClusterName(), true);
  10. loop();
  11. }
  12. catch(Exception e) {
  13. e.printStackTrace();
  14. }
  15. finally {
  16. Util.close(ch);
  17. }
  18. }

代码示例来源:origin: wildfly/wildfly

  1. public void start(String props, boolean jmx, String name) throws Exception {
  2. channel=new JChannel(props).name(name);
  3. disp=new RpcDispatcher(channel, this) // no concurrent processing on incoming method calls
  4. .setMembershipListener(this).setMethodLookup(id -> METHODS[0]);
  5. if(jmx) {
  6. MBeanServer srv=Util.getMBeanServer();
  7. if(srv == null)
  8. throw new Exception("No MBeanServers found");
  9. JmxConfigurator.registerChannel(channel, srv, "jgroups", channel.getClusterName(), true);
  10. }
  11. channel.connect("rpc-speed-test");
  12. View view=channel.getView();
  13. if(view.size() > 2)
  14. System.err.printf("More than 2 members in cluster: %s; terminating\n", view);
  15. else
  16. loop();
  17. Util.close(disp, channel);
  18. }

代码示例来源:origin: wildfly/wildfly

  1. public void init(String props, final String name, String cluster_name) throws Exception {
  2. if(cluster_name != null)
  3. groupname=cluster_name;
  4. channel=new JChannel(props);
  5. if(name != null)
  6. channel.setName(name);
  7. disp=new RpcDispatcher(channel, this).setMethodLookup(id -> METHODS[id]).setMarshaller(new CustomMarshaller())
  8. .setMembershipListener(this);
  9. channel.connect(groupname);
  10. local_addr=channel.getAddress();
  11. try {
  12. MBeanServer server=Util.getMBeanServer();
  13. JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName(), true);
  14. }
  15. catch(Throwable ex) {
  16. System.err.println("registering the channel in JMX failed: " + ex);
  17. }
  18. }

代码示例来源:origin: wildfly/wildfly

  1. public void init(String props, String name, AddressGenerator generator, int bind_port) throws Throwable {
  2. channel=new JChannel(props).addAddressGenerator(generator).setName(name);
  3. if(bind_port > 0) {
  4. TP transport=channel.getProtocolStack().getTransport();
  5. transport.setBindPort(bind_port);
  6. }
  7. disp=new RpcDispatcher(channel, this).setMembershipListener(this).setMethodLookup(id -> METHODS[id])
  8. .setMarshaller(new UPerfMarshaller());
  9. channel.connect(groupname);
  10. local_addr=channel.getAddress();
  11. try {
  12. MBeanServer server=Util.getMBeanServer();
  13. JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName(), true);
  14. }
  15. catch(Throwable ex) {
  16. System.err.println("registering the channel in JMX failed: " + ex);
  17. }
  18. if(members.size() < 2)
  19. return;
  20. Address coord=members.get(0);
  21. Config config=disp.callRemoteMethod(coord, new MethodCall(GET_CONFIG), new RequestOptions(ResponseMode.GET_ALL, 5000));
  22. if(config != null) {
  23. applyConfig(config);
  24. System.out.println("Fetched config from " + coord + ": " + config + "\n");
  25. }
  26. else
  27. System.err.println("failed to fetch config from " + coord);
  28. }

相关文章

Util类方法