コード例 #1
0
 public DefaultNettyChannel(
     ClientBootstrap bootstrap, String remoteHost, int remotePort, int timeout) {
   this.bootstrap = bootstrap;
   this.remoteAddress = new InetSocketAddress(remoteHost, remotePort);
   this.remoteAddressString = NetUtils.toAddress(remoteHost, remotePort);
   this.timeout = timeout;
 }
コード例 #2
0
ファイル: AbstractServer.java プロジェクト: hanjk1234/pigeon
 public int getAvailablePort(int port) {
   int lastPort = port;
   if (!useLastPort) {
     lastPort = NetUtils.getAvailablePort(lastPort);
   } else {
     String filePath = LoggerLoader.LOG_ROOT + "/pigeon-port.conf";
     File file = new File(filePath);
     Properties properties = null;
     String key = null;
     try {
       key = this.getClass().getResource("/").getPath() + port;
       if (file.exists()) {
         try {
           properties = FileUtils.readFile(new FileInputStream(file));
           String strLastPort = properties.getProperty(key);
           if (StringUtils.isNotBlank(strLastPort)) {
             lastPort = Integer.parseInt(strLastPort);
           }
         } catch (Throwable e) {
         }
       }
     } catch (RuntimeException e) {
     }
     lastPort = NetUtils.getAvailablePort(lastPort);
     if (properties == null) {
       properties = new Properties();
     }
     if (key != null) {
       properties.put(key, lastPort);
     }
     try {
       FileUtils.writeFile(file, properties);
     } catch (IOException e) {
     }
   }
   return lastPort;
 }