1

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.

Ryan Leach
  • 4,262
  • 5
  • 34
  • 71

2 Answers2

1

Try extending CustomScheduler instead?

  • That get's me somewhat closer. I think I'm going to need to create some sort of hacky adapter if I want to get it to use gameticks instead of realtime though. https://github.com/SpongePowered/SpongeAPI/blob/b1aa5e04aae06a86d50b646daad06bab697d1707/src/main/java/org/spongepowered/api/scheduler/Task.java#L169 – Ryan Leach Jun 13 '18 at 04:35
  • It appears CustomSchedulers allow for dynamic scheduling, but not necessarily control over the executor used? – Ryan Leach Jun 13 '18 at 04:42
  • Right, `CustomScheduler` lets you set the delay to pass to the executor, and `executor()` lets you set the executor itself. Since you can control both sides, you _probably_ could get away with passing `Schedule` objects that say things like "5 seconds" but that your adapter then interprets as "5 ticks." (I think that's what you're getting at?) Depending on your needs, you might not even need `CustomScheduler`, just an existing method like `Scheduler.newFixedDelaySchedule`, where again you'd interpret the delays as ticks. – Chris Povirk Jun 14 '18 at 14:16
1

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

Chris Povirk
  • 3,738
  • 3
  • 29
  • 47