Skip to content

Getting Started

Fernando Nogueira edited this page May 19, 2017 · 1 revision

With Okra it is really easy to create a scheduling mechanism.

You just need to implement OkraItem or extend DefaultOkraItem like this:

public YourScheduledAction extends DefaultOkraItem {

  private long yourActionId;

  // ... getter and setter

}

With your class defined, you'll just need to schedule your actions:

...
public void yourSchedulingMethod() {
  // Retrieve your Okra instance...
  Okra okra;

  YourScheduledAction item = new YourScheduledAction();
  item.setRunDate(LocalDateTime.now().plusMinutes(30));
  item.setYourActionId(123);

  okra.schedule(item); // Schedules your action to be executed after 30 minutes.
}
...

If you are using OkraSimple, you will need to create a ThreadPool that will try to peek() items from your Okra scheduled items frequently like this:

// Method frequently called to retrieve scheduled items
public void loop() {
  Okra okra; // retrieve your Okra instance...

  Optional<YourScheduledAction> scheduledItem = okra.peek();
  
  if (scheduledItem.isPresent()) {
    // do what you need to do
  }

}
Clone this wiki locally