RuneHive-Game
Loading...
Searching...
No Matches
RequestWorkerPool.java
Go to the documentation of this file.
1package dev.advo.fs.dispatch;
2
3import java.io.File;
4import java.util.ArrayList;
5import java.util.List;
6import java.util.concurrent.ExecutorService;
7import java.util.concurrent.Executors;
8
9import dev.advo.fs.fs.IndexedFileSystem;
10
11
12/**
13 * A class which manages the pool of request workers.
14 * @author Graham
15 */
16public final class RequestWorkerPool {
17
18 /**
19 * The number of threads per request type.
20 */
21 private static final int THREADS_PER_REQUEST_TYPE = Runtime.getRuntime().availableProcessors();
22
23 /**
24 * The executor service.
25 */
26 private final ExecutorService service;
27
28 /**
29 * A list of request workers.
30 */
31 private final List<OnDemandRequestWorker> workers = new ArrayList<OnDemandRequestWorker>();
32
33 /**
34 * The request worker pool.
35 */
37 int totalThreads = THREADS_PER_REQUEST_TYPE;
38 service = Executors.newFixedThreadPool(totalThreads);
39 }
40
41 /**
42 * Starts the threads in the pool.
43 * @throws Exception if the file system cannot be created.
44 */
45 public void start() throws Exception {
46 File base = new File("./data/cache/");
47
48 for (int i = 0; i < THREADS_PER_REQUEST_TYPE; i++) {
49 workers.add(new OnDemandRequestWorker(new IndexedFileSystem(base, true)));
50 }
51
52 for (OnDemandRequestWorker worker : workers) {
53 service.submit(worker);
54 }
55 }
56
57}
A worker which services 'on-demand' requests.
void start()
Starts the threads in the pool.
RequestWorkerPool()
The request worker pool.
final ExecutorService service
The executor service.
final List< OnDemandRequestWorker > workers
A list of request workers.
static final int THREADS_PER_REQUEST_TYPE
The number of threads per request type.
A file system based on top of the operating system's file system.