コード例 #1
0
ファイル: SocketServer.java プロジェクト: dleyanlin/iast
  public static void main(String[] argv) {
    if (argv.length == 3) {
      init(argv[0], argv[1], argv[2]);
    } else {
      usage("Wrong number of arguments.");
    }
    try {
      cat.info("Listening on port " + port);
      ServerSocket serverSocket = new ServerSocket(port);
      for (; ; ) {
        cat.info("Waiting to accept a new client.");
        Socket socket = serverSocket.accept();
        InetAddress inetAddress = socket.getInetAddress();
        cat.info("Connected to client at " + inetAddress);

        LoggerRepository h = (LoggerRepository) server.hierarchyMap.get(inetAddress);
        if (h == null) {
          h = server.configureHierarchy(inetAddress);
        }
        cat.info("Starting new socket node.");
        new Thread(new SocketNode(socket, h)).start();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
ファイル: SocketServer.java プロジェクト: dleyanlin/iast
  LoggerRepository configureHierarchy(InetAddress inetAddress) {
    cat.info("Locating configuration file for " + inetAddress);

    String s = inetAddress.toString();
    int i = s.indexOf("/");
    if (i == -1) {
      cat.warn("Could not parse the inetAddress [" + inetAddress + "]. Using default hierarchy.");

      return genericHierarchy();
    }
    String key = s.substring(0, i);

    File configFile = new File(this.dir, key + CONFIG_FILE_EXT);
    if (configFile.exists()) {
      Hierarchy h = new Hierarchy(new RootLogger(Level.DEBUG));
      this.hierarchyMap.put(inetAddress, h);

      new PropertyConfigurator().doConfigure(configFile.getAbsolutePath(), h);

      return h;
    }
    cat.warn("Could not find config file [" + configFile + "].");
    return genericHierarchy();
  }