(String[] args)
| 79 | new ThreadFactoryBuilder().setNameFormat("disk-cache-gc-%d").build()); |
| 80 | |
| 81 | public static void main(String[] args) throws Exception { |
| 82 | OptionsParser op = OptionsParser.builder().optionsClasses(Options.class).build(); |
| 83 | op.parseAndExitUponError(args); |
| 84 | |
| 85 | Options options = op.getOptions(Options.class); |
| 86 | |
| 87 | if (options.diskCache == null) { |
| 88 | System.err.println("--disk_cache must be specified."); |
| 89 | System.exit(1); |
| 90 | } |
| 91 | |
| 92 | if (options.maxSize <= 0 && options.maxAge.isZero()) { |
| 93 | System.err.println( |
| 94 | "At least one of --max_size or --max_age must be set to a positive value."); |
| 95 | System.exit(1); |
| 96 | } |
| 97 | |
| 98 | var root = getFileSystem().getPath(options.diskCache); |
| 99 | if (!root.isDirectory()) { |
| 100 | System.err.println("Expected --disk_cache to exist and be a directory."); |
| 101 | System.exit(1); |
| 102 | } |
| 103 | |
| 104 | var policy = |
| 105 | new CollectionPolicy( |
| 106 | options.maxSize == 0 ? Optional.empty() : Optional.of(options.maxSize), |
| 107 | options.maxAge.isZero() ? Optional.empty() : Optional.of(options.maxAge)); |
| 108 | |
| 109 | var gc = new DiskCacheGarbageCollector(root, executorService, policy); |
| 110 | |
| 111 | CollectionStats stats = gc.run(); |
| 112 | |
| 113 | System.out.println(stats.displayString()); |
| 114 | System.exit(0); |
| 115 | } |
| 116 | |
| 117 | private static FileSystem getFileSystem() { |
| 118 | // Note: the digest function is irrelevant, as the garbage collector scans the entire disk cache |
no test coverage detected