mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 08:39:17 +00:00
Improve UpdateService by making it use a Logger and method referencing.
- Use correct thrown exception. - Use forEach and method referencing where possible.
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
package org.apollo.update;
|
package org.apollo.update;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.apollo.Service;
|
import org.apollo.Service;
|
||||||
import org.apollo.fs.IndexedFileSystem;
|
import org.apollo.fs.IndexedFileSystem;
|
||||||
@@ -27,6 +30,11 @@ public final class UpdateService extends Service {
|
|||||||
*/
|
*/
|
||||||
private static final int THREADS_PER_REQUEST_TYPE = Runtime.getRuntime().availableProcessors();
|
private static final int THREADS_PER_REQUEST_TYPE = Runtime.getRuntime().availableProcessors();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The logger for this class.
|
||||||
|
*/
|
||||||
|
private static final Logger logger = Logger.getLogger(UpdateService.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The update dispatcher.
|
* The update dispatcher.
|
||||||
*/
|
*/
|
||||||
@@ -59,9 +67,6 @@ public final class UpdateService extends Service {
|
|||||||
return dispatcher;
|
return dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the threads in the pool.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
int release = getContext().getRelease().getReleaseNumber();
|
int release = getContext().getRelease().getReleaseNumber();
|
||||||
@@ -72,23 +77,18 @@ public final class UpdateService extends Service {
|
|||||||
workers.add(new OnDemandRequestWorker(dispatcher, new IndexedFileSystem(base, true)));
|
workers.add(new OnDemandRequestWorker(dispatcher, new IndexedFileSystem(base, true)));
|
||||||
workers.add(new HttpRequestWorker(dispatcher, new IndexedFileSystem(base, true)));
|
workers.add(new HttpRequestWorker(dispatcher, new IndexedFileSystem(base, true)));
|
||||||
}
|
}
|
||||||
|
} catch (FileNotFoundException reason) {
|
||||||
|
logger.log(Level.SEVERE, "Unable to find index or data files from the file system.", reason);
|
||||||
|
}
|
||||||
|
|
||||||
for (RequestWorker<?, ?> worker : workers) {
|
workers.forEach(service::submit);
|
||||||
service.submit(worker);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.err.println("Error adding request workers - " + ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops the threads in the pool.
|
* Stops the threads in the pool.
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public void stop() {
|
||||||
for (RequestWorker<?, ?> worker : workers) {
|
workers.forEach(RequestWorker::stop);
|
||||||
worker.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
service.shutdownNow();
|
service.shutdownNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user