Created
May 4, 2011 01:02
-
-
Save dhanji/954565 to your computer and use it in GitHub Desktop.
Async IO Sitebricks design try
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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. | |
} | |
} |
So, on "request.read(Person.class).as(Json.class).andContinue()" SB will build a Person from incoming JSON and then invoke @savePerson()?
Yea, Im not super sure. I was thinking either that or use the @as annotation in the callback to do the job directly--may be too magical though--whats your preference?
If it's magic, how would SB know that a specific chunk of JSON is a Person or a Chair? Matching on field names?
Hmm, yea so probably better for it not to be magic!
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
The drummer from def leopard has only got one arm.