com.mpush.tools.Utils类的使用及代码示例

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

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

Utils介绍

[英]Created by ohun on 2015/12/25.
[中]ohun于2015年12月25日创建。

代码示例

代码示例来源:origin: mpusher/mpush

public void fetchFormMQ() {
  Utils.newThread("mq-push", this::dispatch);
}

代码示例来源:origin: mpusher/mpush

public static String lookupLocalIp() {
  if (LOCAL_IP == null) {
    LOCAL_IP = getInetAddress(true);
  }
  return LOCAL_IP;
}

代码示例来源:origin: mpusher/mpush

@Test
  public void testSend() throws Exception {
    String host = "239.239.239.99";//多播地址
    int port = 9998;
    String message = "test-multicastSocket";
    try {
      InetAddress group = InetAddress.getByName(host);
      MulticastSocket s = new MulticastSocket();
      //加入多播组
      s.joinGroup(new InetSocketAddress(host, port), Utils.getLocalNetworkInterface());
      DatagramPacket dp = new DatagramPacket(message.getBytes(), message.length(), group, port);
      s.send(dp);
      s.close();
    } catch (UnknownHostException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

  }
}

代码示例来源:origin: mpusher/mpush

@Test
  public void getLocalIP() throws Exception {
    System.out.println(Utils.lookupLocalIp());
    System.out.println(Utils.lookupExtranetIp());

  }
}

代码示例来源:origin: mpusher/mpush

@Override
public void init() {
  super.init();
  messageDispatcher.register(Command.OK, () -> new GatewayOKHandler(mPushClient));
  messageDispatcher.register(Command.ERROR, () -> new GatewayErrorHandler(mPushClient));
  channelHandler = new UDPChannelHandler(messageDispatcher);
  channelHandler.setMulticastAddress(Utils.getInetAddress(CC.mp.net.gateway_client_multicast));
  channelHandler.setNetworkInterface(Utils.getLocalNetworkInterface());
}

代码示例来源:origin: mpusher/mpush

@Test
public void test2() {
  boolean ret = Utils.checkHealth("120.27.196.68", 80);
  System.out.println(ret);
}

代码示例来源:origin: mpusher/mpush

@Override
  public Object monitor(Object... args) {
    Map<String, Object> result = new HashMap<>();
    Map<String, Executor> pools = threadPoolManager.getActivePools();
    for (Map.Entry<String, Executor> entry : pools.entrySet()) {
      String serviceName = entry.getKey();
      Executor executor = entry.getValue();
      if (executor instanceof ThreadPoolExecutor) {
        result.put(serviceName, getPoolInfo((ThreadPoolExecutor) executor));
      } else if (executor instanceof EventLoopGroup) {
        result.put(serviceName, getPoolInfo((EventLoopGroup) executor));
      }
    }
    return result;
  }
}

代码示例来源:origin: mpusher/mpush

/**
 * 获取内网IP地址
 *
 * @return 内网IP地址
 */
public static String getLocalIp() {
  if (CC.mp.net.local_ip.length() > 0) {
    return CC.mp.net.local_ip;
  }
  return Utils.lookupLocalIp();
}

代码示例来源:origin: mpusher/mpush

/**
 * 获取外网IP地址
 *
 * @return 外网IP地址
 */
public static String getPublicIp() {
  if (CC.mp.net.public_ip.length() > 0) {
    return CC.mp.net.public_ip;
  }
  String localIp = getLocalIp();
  String remoteIp = public_ip_mapping.getString(localIp);
  if (remoteIp == null) {
    remoteIp = Utils.lookupExtranetIp();
  }
  return remoteIp == null ? localIp : remoteIp;
}

代码示例来源:origin: mpusher/mpush

@Override
public void init() {
  super.init();
  messageDispatcher.register(Command.GATEWAY_PUSH, () -> new GatewayPushHandler(mPushServer.getPushCenter()));
  messageDispatcher.register(Command.GATEWAY_KICK, () -> new GatewayKickUserHandler(mPushServer.getRouterCenter()));
  channelHandler.setMulticastAddress(Utils.getInetAddress(CC.mp.net.gateway_server_multicast));
  channelHandler.setNetworkInterface(Utils.getLocalNetworkInterface());
}

代码示例来源:origin: mpusher/mpush

@Test
public void test() {
  boolean ret = Utils.checkHealth("120.27.196.68", 82);
  System.out.println(ret);
}

代码示例来源:origin: mpusher/mpush

@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
  LOGGER.warn("one task rejected, poolConfig={}, poolInfo={}", poolConfig, Utils.getPoolInfo(e));
  if (!dumping) {
    dumping = true;
    dumpJVMInfo();
  }
  if (rejectedPolicy == REJECTED_POLICY_ABORT) {
    throw new RejectedExecutionException("one task rejected, pool=" + poolConfig.getName());
  } else if (rejectedPolicy == REJECTED_POLICY_CALLER_RUNS) {
    if (!e.isShutdown()) {
      r.run();
    }
  }
}

代码示例来源:origin: com.github.mpusher/mpush-tools

/**
 * 获取内网IP地址
 *
 * @return 内网IP地址
 */
public static String getLocalIp() {
  if (CC.mp.net.local_ip.length() > 0) {
    return CC.mp.net.local_ip;
  }
  return Utils.lookupLocalIp();
}

代码示例来源:origin: com.github.mpusher/mpush-tools

/**
 * 获取外网IP地址
 *
 * @return 外网IP地址
 */
public static String getPublicIp() {
  if (CC.mp.net.public_ip.length() > 0) {
    return CC.mp.net.public_ip;
  }
  String localIp = getLocalIp();
  String remoteIp = public_ip_mapping.getString(localIp);
  if (remoteIp == null) {
    remoteIp = Utils.lookupExtranetIp();
  }
  return remoteIp == null ? localIp : remoteIp;
}

代码示例来源:origin: mpusher/mpush

@Override
protected void doStart(Listener listener) throws Throwable {
  if (printLog || dumpEnabled) {
    thread = Utils.newThread(ThreadNames.T_MONITOR, this);
    thread.setDaemon(true);
    thread.start();
  }
  listener.onSuccess();
}

代码示例来源:origin: com.github.mpusher/mpush-client

@Override
public void init() {
  super.init();
  messageDispatcher.register(Command.OK, () -> new GatewayOKHandler(mPushClient));
  messageDispatcher.register(Command.ERROR, () -> new GatewayErrorHandler(mPushClient));
  channelHandler = new UDPChannelHandler(messageDispatcher);
  channelHandler.setMulticastAddress(Utils.getInetAddress(CC.mp.net.gateway_client_multicast));
  channelHandler.setNetworkInterface(Utils.getLocalNetworkInterface());
}

代码示例来源:origin: mpusher/mpush

@Test
public void TestServer() throws Exception {
  //接受组播和发送组播的数据报服务都要把组播地址添加进来
  String host = "239.239.239.88";//多播地址
  int port = 9998;
  InetAddress group = InetAddress.getByName(host);
  DatagramChannel channel = DatagramChannel.open(StandardProtocolFamily.INET);
  channel.bind(new InetSocketAddress(port));
  channel.join(group, Utils.getLocalNetworkInterface());
  ByteBuffer buffer = ByteBuffer.allocate(1024);
  SocketAddress sender = channel.receive(buffer);
  buffer.flip();
  byte[] data = new byte[buffer.remaining()];
  buffer.get(data);
  System.out.println(new String(data));
}

代码示例来源:origin: mpusher/mpush

public static String lookupExtranetIp() {
  if (EXTRANET_IP == null) {
    EXTRANET_IP = getInetAddress(false);
  }
  return EXTRANET_IP;
}

代码示例来源:origin: mpusher/mpush

@Override
public void run() {
  logger.debug("do dns mapping checkHealth ...");
  Map<String, List<DnsMapping>> all = this.getAll();
  Map<String, List<DnsMapping>> available = Maps.newConcurrentMap();
  all.forEach((key, dnsMappings) -> {
    List<DnsMapping> okList = Lists.newArrayList();
    dnsMappings.forEach(dnsMapping -> {
      if (checkHealth(dnsMapping.getIp(), dnsMapping.getPort())) {
        okList.add(dnsMapping);
      } else {
        logger.warn("dns can not reachable:" + Jsons.toJson(dnsMapping));
      }
    });
    available.put(key, okList);
  });
  this.update(available);
}

代码示例来源:origin: com.github.mpusher/mpush-monitor

@Override
  public Object monitor(Object... args) {
    Map<String, Object> result = new HashMap<>();
    Map<String, Executor> pools = threadPoolManager.getActivePools();
    for (Map.Entry<String, Executor> entry : pools.entrySet()) {
      String serviceName = entry.getKey();
      Executor executor = entry.getValue();
      if (executor instanceof ThreadPoolExecutor) {
        result.put(serviceName, getPoolInfo((ThreadPoolExecutor) executor));
      } else if (executor instanceof EventLoopGroup) {
        result.put(serviceName, getPoolInfo((EventLoopGroup) executor));
      }
    }
    return result;
  }
}

相关文章