Saturday, February 26, 2011

Wrap anything within Quartz

I had this idea while using Quartz at work that it rather than writing a lot of boilerplate code around libraries like Twitter4J and RestFB, it would be nice if I could just wrap any method into a Quartz Job, with scheduling, error handling, etc.; something like this:

FacebookService service = wrap(FacebookService.class);
queue(service.updateStatus(statusMessage)).schedule(nextMonday).after(new Callback {
  @Override
  public Object run() {
    System.out.println("Posted the status, and it was: " + getResult().getMessage());
  }
});


The syntax is (supposed to be) similar to Mockito's. I'm not sure how well this approach will stand up from a thread-safety perspective, but I've started a project on Github, very basic right now, that I think has some promise!

No comments: