Skip to content

Instantly share code, notes, and snippets.

@dhanji
Created May 4, 2011 01:02
Show Gist options
  • Save dhanji/954565 to your computer and use it in GitHub Desktop.
Save dhanji/954565 to your computer and use it in GitHub Desktop.
Async IO Sitebricks design try
@At("/person/:name") @Async
public class PersonService {
@Before
void pre(Request request, @Named("name") String name) {
System.out.println("headers were: " + request.headers());
// We can either return a "Reply" here, or do nothing to continue processing
}
/**
* Callback for request body. This will be called after a Json entity is
* fully read into a Person object.
*/
@Post
void savePerson(@As(Json.class) Person person) {
save(person);
// Read next person (entity)...
}
/**
* Callback for Chairs. Multiple entity types can be interleaved in the
* same request using the HTTP 1.1 entities standard.
*/
@Post
Reply<?> saveChair(@As(Json.class) Chair chair) {
save(chair);
// Stop reading the request now & respond.
return Reply.saying().ok();
}
/**
* Callback on request. If no entity is being read, this will be called first.
*/
@Post
Reply<?> check(Request request) {
// Start a continuation or terminate the request by returning a non-continuing Reply.
return request.read(Person.class).as(Json.class).andContinue();
}
/**
* Callback for when response has been completely written.
*/
@After
void completed() {
// Release additional resources here, or something.
}
}
@michaelneale
Copy link

How will you pull now you don't work at google? will this help? I think not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment