Created
May 15, 2013 00:56
-
-
Save miere/5580919 to your computer and use it in GitHub Desktop.
This class received a refactoring to make possible achieve asynchronous development soon.
When methods are short/tiny they make the class execution imperative. Basically, its methods
are now focuses on tiny jobs, and all blocking jobs can be now replaced with an asynchronous
call.
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
package layr.routing.service; | |
import layr.engine.RequestContext; | |
import layr.routing.api.Configuration; | |
import layr.routing.api.Response; | |
import layr.routing.api.RouteMethod; | |
import layr.routing.exceptions.NotFoundException; | |
import layr.routing.exceptions.RoutingException; | |
import layr.routing.exceptions.UnhandledException; | |
public class BusinessRoutingLifeCycle implements LifeCycle { | |
Configuration configuration; | |
RequestContext requestContext; | |
public BusinessRoutingLifeCycle(Configuration configuration) { | |
this.configuration = configuration; | |
} | |
public void createContext( ContainerRequestData<?, ?> containerRequestData ) { | |
this.requestContext = configuration.createContext( containerRequestData ); | |
} | |
public void run() throws NotFoundException, RoutingException, UnhandledException { | |
RouteMethod routeMethod = getMatchedRouteMethod(); | |
if ( routeMethod == null ) | |
throw new NotFoundException( "No route found." ); | |
runMethodAndRenderOutput( routeMethod ); | |
} | |
public RouteMethod getMatchedRouteMethod() { | |
BusinessRoutingMethodMatching businessRoutingMethodMatching = new BusinessRoutingMethodMatching( configuration, requestContext ); | |
RouteMethod routeMethod = businessRoutingMethodMatching.getMatchedRouteMethod(); | |
return routeMethod; | |
} | |
public void runMethodAndRenderOutput(RouteMethod routeMethod) throws RoutingException, UnhandledException { | |
Response response = runMethod( routeMethod ); | |
renderOutput( response ); | |
} | |
public void renderOutput(Response response) throws RoutingException { | |
BusinessRoutingRenderer renderer = new BusinessRoutingRenderer( configuration, requestContext ); | |
renderer.render(response); | |
} | |
public Response runMethod(RouteMethod routeMethod) throws UnhandledException { | |
BusinessRoutingMethodRunner runner = new BusinessRoutingMethodRunner( configuration, requestContext, routeMethod ); | |
Response response = runner.run(); | |
return response; | |
} | |
public RequestContext getRequestContext() { | |
return requestContext; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment