Class ServicePool
java.lang.Object
io.github.simplexdevelopment.scheduler.ServicePool
- All Implemented Interfaces:
Identifier
A service pool is a collection of services which are managed by a single scheduler.
The scheduler can either be an instance of
Scheduler
or ReactorBukkitScheduler
.
Using Scheduler
allows for more flexibility, but doesn't communicate with the Main thread.
Using ReactorBukkitScheduler
allows for communication with the Main thread, but is less flexible.- See Also:
-
ReactorBukkitScheduler
Scheduler
-
Field Summary
Modifier and TypeFieldDescriptionA collection of services related to this service pool.private static final String
The defaultString
used to identify unmarked services.private final String
The name used to identify this service pool.private final reactor.core.scheduler.Scheduler
The scheduler used to run the services in this pool. -
Constructor Summary
ConstructorDescriptionServicePool
(String name, boolean multithreaded) This will create a new instance of a Service Pool with aScheduler
as its main scheduler.ServicePool
(String name, org.bukkit.plugin.java.JavaPlugin plugin) This will create a new instance of a Service Pool with theReactorBukkitScheduler
as its main scheduler. -
Method Summary
Modifier and TypeMethodDescription(package private) void
addService
(IService service) getName()
reactor.core.scheduler.Scheduler
@NotNull reactor.core.publisher.Mono<IService>
getService
(String service_name) Gets a service based on the name of the service defined byIdentifier.getName()
.(package private) boolean
isValidService
(IService service) Checks to see if the defined service is present within this pool.@NotNull reactor.core.publisher.Mono<reactor.core.Disposable>
queueService
(IService service) This method is the actual method used to schedule a service.@NotNull reactor.core.publisher.Flux<reactor.core.Disposable>
This method can be used to start all the services registered with this pool.@NotNull reactor.core.publisher.Mono<ServicePool>
recycle()
This will clear the ServicePool of all services and return an empty pool.(package private) void
removeService
(IService service) This method removes a service from the service pool set.@NotNull reactor.core.publisher.Mono<Void>
stopService
(@NotNull String service_name, @Nullable reactor.core.publisher.Mono<reactor.core.Disposable> disposable) This is the method used to stop a service.@NotNull reactor.core.publisher.Mono<Void>
stopServices
(@NotNull reactor.core.publisher.Flux<reactor.core.Disposable> disposableThread) This method can be used to stop all the services registered with this pool.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.github.simplexdevelopment.api.Identifier
getNumericalId, getUniqueId
-
Field Details
-
DEFAULT
The defaultString
used to identify unmarked services. This will cause errors if left unchecked.- See Also:
-
associatedServices
A collection of services related to this service pool. -
scheduler
private final reactor.core.scheduler.Scheduler schedulerThe scheduler used to run the services in this pool. -
name
The name used to identify this service pool.
-
-
Constructor Details
-
ServicePool
This will create a new instance of a Service Pool with aScheduler
as its main scheduler. This should be used if you'd like to execute tasks without communicating on the main server thread.- Parameters:
name
- The name of this service pool.multithreaded
- Whether this service pool should be multithreaded, or operate upon a single thread.
-
ServicePool
This will create a new instance of a Service Pool with theReactorBukkitScheduler
as its main scheduler. This should be used if you'd like to execute tasks while communicating on the main server thread.- Parameters:
name
- The name of this service pool.
-
-
Method Details
-
addService
- Parameters:
service
- Add a service to the pool's service collection.
-
isValidService
Checks to see if the defined service is present within this pool.- Parameters:
service
- The service to check against this pool.- Returns:
- Whether the service is registered with this pool.
-
getAssociatedServices
-
queueService
@NotNull public @NotNull reactor.core.publisher.Mono<reactor.core.Disposable> queueService(IService service) This method is the actual method used to schedule a service. This will register the service with the scheduler, and then return aDisposable
object encapsulated within aMono
. IfIService.isPeriodic()
returns true, then the service will be scheduled to run periodically. Otherwise, it will be scheduled to run once.- Parameters:
service
- The name of the service to queue. This should be a service that is located within this service pool. If you name a service that is stored within another service pool, this method will throw an error.- Returns:
- A
Mono
object which contains aDisposable
element which can be used to destroy the registered service.
-
queueServices
@NotNull public @NotNull reactor.core.publisher.Flux<reactor.core.Disposable> queueServices()This method can be used to start all the services registered with this pool. If there are no services, this will do nothing.- Returns:
- A
Flux
object which contains a collection ofDisposable
elements, which can be used to destroy the registered services usingstopServices(Flux)
.
-
stopServices
@NotNull public @NotNull reactor.core.publisher.Mono<Void> stopServices(@NotNull @NotNull reactor.core.publisher.Flux<reactor.core.Disposable> disposableThread) This method can be used to stop all the services registered with this pool. If there are no services, this will do nothing.- Parameters:
disposableThread
- Areactor.core.publisher.Flux<reactor.core.Disposable>
which contains all the services that should be disposed..- Returns:
- A
reactor.core.publisher.Mono<Void>
object which can be used to stop the services.
-
stopService
@NotNull public @NotNull reactor.core.publisher.Mono<Void> stopService(@NotNull @NotNull String service_name, @Nullable @Nullable reactor.core.publisher.Mono<reactor.core.Disposable> disposable) This is the method used to stop a service. This will call the relativeDisposable.dispose()
method to theScheduler
supplied for this pool. If you are using theReactorBukkitScheduler
, this will cancel the task upstream on theBukkitScheduler
.- Parameters:
service_name
- The name of the service to stop.disposable
- ADisposable
object which contains the service that should be disposed.- Returns:
- A
reactor.core.publisher.Mono<Void>
object which can be used to stop the service.
-
getService
Gets a service based on the name of the service defined byIdentifier.getName()
. This will search the service pool for a service with the same name, and return it.- Parameters:
service_name
- The name of the service to get.- Returns:
- A
Mono
object which contains the service.
-
removeService
This method removes a service from the service pool set.- Parameters:
service
- The service to remove from the pool's service collection.
-
recycle
This will clear the ServicePool of all services and return an empty pool.- Returns:
- This service pool after being cleared of all services. You will need to register services with this pool again before using it.
-
getScheduler
@Contract(pure=true) public reactor.core.scheduler.Scheduler getScheduler()- Returns:
- The
Scheduler
which hosts the threads for the service pool.
-
getName
- Specified by:
getName
in interfaceIdentifier
- Returns:
- The name of the identifiable object in a readable format.
-