Search code examples
javaserviceguavaspongeapi

Can I use Guava's Services with an API provided ExecutorService?


https://github.com/SpongePowered/SpongeAPI/blob/b1aa5e04aae06a86d50b646daad06bab697d1707/src/main/java/org/spongepowered/api/scheduler/SpongeExecutorService.java

SpongeAPI provides a ScheduledExecutorService , And Guava provides a well defined, and well tested abstract service class: https://google.github.io/guava/releases/19.0/api/docs/com/google/common/util/concurrent/AbstractScheduledService.html

Is it possible to extend the AbstractSceduledService in order to use the Sponge ScheduledExecutorService ?

I've tried extending AbstractScheduledService myself, But AbstractScheduledService.Scheduler has a private constructor, preventing creation of my own Schedulers to create custom scheduling.


Solution

  • If I'm understanding right, you should be able to override AbstractScheduledService.executor() to return a SpongeExecutorService.