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

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

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

Util.getMBeanServer介绍

暂无

代码示例

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

public void channelDisconnected(JChannel channel) {
  if(jmx) {
    MBeanServer server=Util.getMBeanServer();
    if(server != null) {
      try {
        JmxConfigurator.unregisterChannel(channel, server, cluster_name);
      }
      catch(Exception e) {
        e.printStackTrace();
      }
    }
  }
}

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

public void stop() {
  looping=false;
  try {
    JmxConfigurator.unregisterChannel(channel, Util.getMBeanServer(), "jgroups", "mperf");
  }
  catch(Exception e) {
    e.printStackTrace();
  }
  Util.close(channel);
}

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

public void stop() {
  looping=false;
  try {
    JmxConfigurator.unregisterChannel(channel, Util.getMBeanServer(), "jgroups", "mperf");
  }
  catch(Exception e) {
    e.printStackTrace();
  }
  Util.close(channel);
}

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

public static void registerChannel(JChannel channel,String name) {
  MBeanServer server=Util.getMBeanServer();
  if(server != null) {
    try {
      JmxConfigurator.registerChannel(channel,
                      server,
                      (name != null? name : "jgroups"),
                      channel.getClusterName(),
                      true);
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}

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

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

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

protected void _init(JChannel ch, long sleep_time, String name) throws Exception {
  this.sleep_time=sleep_time;
  channel=ch;
  if(name != null)
    channel.setName(name);
  channel.connect(getClass().getSimpleName());
  channel.setReceiver(receiver);
  try {
    MBeanServer server=Util.getMBeanServer();
    JmxConfigurator.registerChannel(channel, server, "jgroups-" + name, channel.getClusterName(), true);
  }
  catch(Throwable ex) {
    System.err.println("registering the channel with JMX failed: " + ex);
  }
}

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

public static void main(String[] args) {
  JmxDemo demo=new JmxDemo();
  demo.addNotificationListener((notification, handback) -> System.out.println(">> " + notification + ", handback=" + handback), null, "myHandback");
  demo.startNotifications();
  MBeanServer server=Util.getMBeanServer();
  if(server != null) {
    try {
      JmxConfigurator.register(demo, server, "demo:name=DemoObject");
      while(true) {
        Util.sleep(10000);
      }
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}

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

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

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

protected void applyNewConfig(byte[] buffer) {
  final InputStream in=new ByteArrayInputStream(buffer);
  Thread thread=new Thread(() -> {
    try {
      JChannel ch=new JChannel(in);
      Util.sleepRandom(1000, 5000);
      channel.disconnect();
      JChannel tmp=channel;
      channel=ch;
      channel.setName(name);
      channel.setReceiver(MPerf.this);
      channel.connect("mperf");
      local_addr=channel.getAddress();
      JmxConfigurator.unregisterChannel(tmp, Util.getMBeanServer(), "jgroups", "mperf");
      Util.close(tmp);
      JmxConfigurator.registerChannel(channel, Util.getMBeanServer(), "jgroups", "mperf", true);
    }
    catch(Exception e) {
      System.err.println("failed creating new channel");
    }
  });
  System.out.println("<< restarting channel");
  thread.start();
}

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

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

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

public void exit() { // 8
  ProtocolStack stack=channel.getProtocolStack();
  String cluster_name=channel.getClusterName();
  try {
    JmxConfigurator.unregisterChannel(channel, Util.getMBeanServer(), "jgroups", "mperf");
  }
  catch(Exception e) {
  }
  stack.stopStack(cluster_name);
  stack.destroy();
}

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

/**
 * Always called before destroy(). Close connections and frees resources.
 */
@ManagedOperation(description="Always called before destroy(). Closes connections and frees resources")
public void stop() {
  if(!running.compareAndSet(true, false))
    return;
  try {
    JmxConfigurator.unregister(this, Util.getMBeanServer(), "jgroups:name=GossipRouter");
  }
  catch(Exception ex) {
    log.error(Util.getMessage("MBeanDeRegistrationFailed"), ex);
  }
  Util.close(server);
  log.debug("router stopped");
}

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

public void start() throws Exception {
  ch=new JChannel(props);
  if(name != null)
    ch.setName(name);
  execution_service=new ExecutionService(ch);
  runner=new ExecutionRunner(ch);
  ch.connect("executing-cluster");
  JmxConfigurator.registerChannel(ch, Util.getMBeanServer(), 
    "execution-service", ch.getClusterName(), true);
  
  // Start a consumer
  queue.add(executor.submit(runner));
  random = new Random();
  printValues = false;
  try {
    loop();
  }
  catch(Exception e) {
    e.printStackTrace();
  }
  finally {
    Util.close(ch);
  }
}

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

public ReplicatedTree(String groupname, String props, long state_fetch_timeout, boolean jmx) throws Exception {
  if(groupname != null)
    this.groupname=groupname;
  if(props != null)
    this.props=props;
  this.jmx=jmx;
  this.state_fetch_timeout=state_fetch_timeout;
  channel=new JChannel(this.props);
  channel.setReceiver(this);
  channel.connect(this.groupname);
  if(jmx) {
    MBeanServer server=Util.getMBeanServer();
    if(server == null)
      throw new Exception("No MBeanServers found; need to run with an MBeanServer present, or inside JDK 5");
    JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName() , true);
  }
  start();
}

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

public void start(JChannel ch) throws Exception {
  this.ch=ch;
  lock_service=new LockService(ch);
  lock_service.addLockListener(this);
  ch.connect("lock-cluster");
  JmxConfigurator.registerChannel(ch, Util.getMBeanServer(), "lock-service", ch.getClusterName(), true);
  try {
    loop();
  }
  catch(Exception e) {
    e.printStackTrace();
  }
  finally {
    Util.close(ch);
  }
}

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

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

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

public void start() throws Exception {
  try {
    ch=new JChannel(props);
    if(name != null)
      ch.setName(name);
    lock_service=new LockService(ch);
    lock_service.addLockListener(this);
    ch.connect("lock-cluster");
    JmxConfigurator.registerChannel(ch, Util.getMBeanServer(), "lock-service", ch.getClusterName(), true);
    loop();
  }
  catch(Exception e) {
    e.printStackTrace();
  }
  finally {
    Util.close(ch);
  }
}

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

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

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

public void init(String props, final String name, String cluster_name) throws Exception {
  if(cluster_name != null)
    groupname=cluster_name;
  channel=new JChannel(props);
  if(name != null)
    channel.setName(name);
  disp=new RpcDispatcher(channel, this).setMethodLookup(id -> METHODS[id]).setMarshaller(new CustomMarshaller())
   .setMembershipListener(this);
  channel.connect(groupname);
  local_addr=channel.getAddress();
  try {
    MBeanServer server=Util.getMBeanServer();
    JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName(), true);
  }
  catch(Throwable ex) {
    System.err.println("registering the channel in JMX failed: " + ex);
  }
}

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

public void init(String props, String name, AddressGenerator generator, int bind_port) throws Throwable {
  channel=new JChannel(props).addAddressGenerator(generator).setName(name);
  if(bind_port > 0) {
    TP transport=channel.getProtocolStack().getTransport();
    transport.setBindPort(bind_port);
  }
  disp=new RpcDispatcher(channel, this).setMembershipListener(this).setMethodLookup(id -> METHODS[id])
   .setMarshaller(new UPerfMarshaller());
  channel.connect(groupname);
  local_addr=channel.getAddress();
  try {
    MBeanServer server=Util.getMBeanServer();
    JmxConfigurator.registerChannel(channel, server, "jgroups", channel.getClusterName(), true);
  }
  catch(Throwable ex) {
    System.err.println("registering the channel in JMX failed: " + ex);
  }
  if(members.size() < 2)
    return;
  Address coord=members.get(0);
  Config config=disp.callRemoteMethod(coord, new MethodCall(GET_CONFIG), new RequestOptions(ResponseMode.GET_ALL, 5000));
  if(config != null) {
    applyConfig(config);
    System.out.println("Fetched config from " + coord + ": " + config + "\n");
  }
  else
    System.err.println("failed to fetch config from " + coord);
}

相关文章

Util类方法