RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.game.service.StartupService Class Reference

An ExecutorService that waits for all its events to finish executing. More...

Inheritance diagram for com.runehive.game.service.StartupService:
Collaboration diagram for com.runehive.game.service.StartupService:

Public Member Functions

boolean awaitTermination (long timeout, TimeUnit unit) throws InterruptedException
void awaitUntilFinished (long timeout, TimeUnit timeUnit)
void execute (Runnable command)
int getPendingTaskAmount ()
 Gets the number of pending tasks.
boolean isShutdown ()
boolean isTerminated ()
void shutdown ()
List< Runnable > shutdownNow ()
Future<?> submit (Runnable task)
void waitForPendingTasks () throws ExecutionException
 Waits for pending tasks to complete.

Package Functions

public< T > List< Future< T > > invokeAll (Collection<? extends Callable< T > > tasks) throws InterruptedException
public< T > List< Future< T > > invokeAll (Collection<? extends Callable< T > > tasks, long timeout, TimeUnit unit) throws InterruptedException
public< T > T invokeAny (Collection<? extends Callable< T > > tasks) throws InterruptedException, ExecutionException
public< T > T invokeAny (Collection<? extends Callable< T > > tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
public< T > Future< T > submit (Callable< T > task)
public< T > Future< T > submit (Runnable task, T result)

Private Attributes

BlockingQueue< Future<?> > pendingTasks = new LinkedBlockingQueue<>()
 A list of pending tasks.
ExecutorService service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())
 The service backing this service.

Detailed Description

An ExecutorService that waits for all its events to finish executing.

Author
Graham Edgecombe

Definition at line 13 of file StartupService.java.

Member Function Documentation

◆ awaitTermination()

boolean com.runehive.game.service.StartupService.awaitTermination ( long timeout,
TimeUnit unit ) throws InterruptedException

Definition at line 58 of file StartupService.java.

58 {
59 return service.awaitTermination(timeout, unit);
60 }

References service.

◆ awaitUntilFinished()

void com.runehive.game.service.StartupService.awaitUntilFinished ( long timeout,
TimeUnit timeUnit )

Definition at line 40 of file StartupService.java.

40 {
41 try {
42 service.awaitTermination(timeout, timeUnit);
43 } catch (InterruptedException e) {
44 e.printStackTrace();
45 }
46 }

References service.

◆ execute()

void com.runehive.game.service.StartupService.execute ( Runnable command)

Definition at line 134 of file StartupService.java.

134 {
135 service.execute(command);
136 }

References service.

◆ getPendingTaskAmount()

int com.runehive.game.service.StartupService.getPendingTaskAmount ( )

Gets the number of pending tasks.

Returns
The number of pending tasks.

Definition at line 53 of file StartupService.java.

53 {
54 return pendingTasks.size();
55 }

References pendingTasks.

◆ invokeAll() [1/2]

public< T > List< Future< T > > com.runehive.game.service.StartupService.invokeAll ( Collection<? extends Callable< T > > tasks) throws InterruptedException
package

Definition at line 63 of file StartupService.java.

63 {
64 List<Future<T>> futures = service.invokeAll(tasks);
65 for (Future<?> future : futures) {
66 pendingTasks.add(future);
67 }
68 return futures;
69 }

References pendingTasks, and service.

◆ invokeAll() [2/2]

public< T > List< Future< T > > com.runehive.game.service.StartupService.invokeAll ( Collection<? extends Callable< T > > tasks,
long timeout,
TimeUnit unit ) throws InterruptedException
package

Definition at line 72 of file StartupService.java.

73 {
74 List<Future<T>> futures = service.invokeAll(tasks, timeout, unit);
75 for (Future<?> future : futures) {
76 pendingTasks.add(future);
77 }
78 return futures;
79 }

References pendingTasks, and service.

◆ invokeAny() [1/2]

public< T > T com.runehive.game.service.StartupService.invokeAny ( Collection<? extends Callable< T > > tasks) throws InterruptedException, ExecutionException
package

Definition at line 82 of file StartupService.java.

82 {
83 return service.invokeAny(tasks);
84 }

References service.

◆ invokeAny() [2/2]

public< T > T com.runehive.game.service.StartupService.invokeAny ( Collection<? extends Callable< T > > tasks,
long timeout,
TimeUnit unit ) throws InterruptedException, ExecutionException, TimeoutException
package

Definition at line 87 of file StartupService.java.

88 {
89 return service.invokeAny(tasks, timeout, unit);
90 }

References service.

◆ isShutdown()

boolean com.runehive.game.service.StartupService.isShutdown ( )

Definition at line 93 of file StartupService.java.

93 {
94 return service.isShutdown();
95 }

References service.

Referenced by waitForPendingTasks().

Here is the caller graph for this function:

◆ isTerminated()

boolean com.runehive.game.service.StartupService.isTerminated ( )

Definition at line 98 of file StartupService.java.

98 {
99 return service.isTerminated();
100 }

References service.

◆ shutdown()

void com.runehive.game.service.StartupService.shutdown ( )

Definition at line 103 of file StartupService.java.

103 {
104 service.shutdown();
105 }

References service.

◆ shutdownNow()

List< Runnable > com.runehive.game.service.StartupService.shutdownNow ( )

Definition at line 108 of file StartupService.java.

108 {
109 return service.shutdownNow();
110 }

References service.

◆ submit() [1/3]

public< T > Future< T > com.runehive.game.service.StartupService.submit ( Callable< T > task)
package

Definition at line 113 of file StartupService.java.

113 {
114 Future<T> future = service.submit(task);
115 pendingTasks.add(future);
116 return future;
117 }

References pendingTasks, and service.

◆ submit() [2/3]

Future<?> com.runehive.game.service.StartupService.submit ( Runnable task)

Definition at line 120 of file StartupService.java.

120 {
121 Future<?> future = service.submit(task);
122 pendingTasks.add(future);
123 return future;
124 }

References pendingTasks, and service.

◆ submit() [3/3]

public< T > Future< T > com.runehive.game.service.StartupService.submit ( Runnable task,
T result )
package

Definition at line 127 of file StartupService.java.

127 {
128 Future<T> future = service.submit(task, result);
129 pendingTasks.add(future);
130 return future;
131 }

References pendingTasks, and service.

◆ waitForPendingTasks()

void com.runehive.game.service.StartupService.waitForPendingTasks ( ) throws ExecutionException

Waits for pending tasks to complete.

Exceptions
ExecutionExceptionif an error in a task occurred.

Definition at line 27 of file StartupService.java.

27 {
28 while (pendingTasks.size() > 0) {
29 if (isShutdown()) {
30 return;
31 }
32 try {
33 pendingTasks.take().get();
34 } catch (InterruptedException e) {
35 continue;
36 }
37 }
38 }

References isShutdown(), and pendingTasks.

Here is the call graph for this function:

Member Data Documentation

◆ pendingTasks

BlockingQueue<Future<?> > com.runehive.game.service.StartupService.pendingTasks = new LinkedBlockingQueue<>()
private

A list of pending tasks.

Definition at line 19 of file StartupService.java.

Referenced by getPendingTaskAmount(), invokeAll(), invokeAll(), submit(), submit(), submit(), and waitForPendingTasks().

◆ service

ExecutorService com.runehive.game.service.StartupService.service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())
private

The documentation for this class was generated from the following file: