コード例 #1
0
  public SessionManager(
      CateScraper cateScraper, TimetableScraper timetableScraper, String motdFile) {
    assert cateScraper != null && timetableScraper != null;
    this.cateScraper = cateScraper;
    this.timetableScraper = timetableScraper;
    sessions = new ConcurrentHashMap<UUID, Session>();
    if (motdFile != null) {
      Log.info("Found motd file at: {}", motdFile);
      new Timer()
          .scheduleAtFixedRate(
              new TimerTask() {

                @Override
                public void run() {
                  Motd motd;
                  try {
                    motd = GsonInstance.gson.fromJson(new FileReader(motdFile), Motd.class);
                  } catch (IOException e) {
                    Log.warn("Failed to open MOTD file", e);
                    return;
                  }
                  if (!motd.equals(SessionManager.this.motd)) {
                    Log.info("Updated motd: {}", motd);
                    SessionManager.this.motd = motd;
                    sessions.values().forEach(session -> session.motd(motd));
                  }
                }
              },
              10000,
              10000);
    }
  }
コード例 #2
0
ファイル: CateServer.java プロジェクト: joshcc3/cate-server
 public static void main(String[] args) throws ClassNotFoundException {
   if (args.length < 4) {
     System.err.println(
         "usage: CateServer [port] [motd_file] [p12_file] [timetable_dir] [authmapper_file]");
     System.exit(1);
   }
   Log.info("args: {}", Arrays.toString(args));
   String authMapperFile = args.length < 5 ? null : args[4];
   new SessionServer(Integer.parseInt(args[0]), args[1], args[2], args[3], authMapperFile).start();
 }