Package com.networknt.aws.lambda
Class LightLambdaExchange
- java.lang.Object
-
- com.networknt.aws.lambda.LightLambdaExchange
-
public final class LightLambdaExchange extends Object
Shared object among middleware threads containing information on the request/response event.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLightLambdaExchange.Attachable<T extends MiddlewareHandler>Attachment key class to attach data to the exchange.
-
Constructor Summary
Constructors Constructor Description LightLambdaExchange(com.amazonaws.services.lambda.runtime.Context context, Chain chain)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends MiddlewareHandler>
voidaddAttachment(LightLambdaExchange.Attachable<T> key, Object o)Adds an attachment to the exchange.LightLambdaExchangeaddExchangeFailedListener(LambdaExchangeFailureListener listener)LightLambdaExchangeaddRequestCompleteListener(LambdaRequestCompleteListener listener)LightLambdaExchangeaddResponseCompleteListener(LambdaResponseCompleteListener listener)voidexecuteChain()ObjectgetAttachment(LightLambdaExchange.Attachable<?> attachable)Get attachment object for given key.Map<LightLambdaExchange.Attachable<?>,Object>getAttachments()com.amazonaws.services.lambda.runtime.ContextgetContext()com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEventgetFinalizedRequest(boolean fromListener)Terminates the request portion of the exchange and invokes the exchangeRequestCompleteListeners.com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventgetFinalizedResponse(boolean fromListener)Terminates the response portion of the exchange and invokes the exchangeResponseCompleteListeners.com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEventgetReadOnlyRequest()com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEventgetRequest()com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventgetResponse()Returns the response object or an exception object if there was a failure.intgetState()intgetStatusCode()booleanhasFailedState()Check to see if the exchange has any error state at all.booleanisExchangeComplete()Checks to see if the exchange is complete.booleanisRequestComplete()booleanisRequestInProgress()Checks to see if the exchange is in the 'request in progress' state.booleanisResponseComplete()Checks to see if the exchange has the response portion complete.booleanisResponseInProgress()Checks to see if the exchange is in the response in progress state.voidsetInitialRequest(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request)Sets the request object of the exchange.voidsetInitialResponse(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent response)Sets the response object of the exchange.StringtoString()voidupdateExchangeStatus(com.networknt.status.Status status)Update the exchange.
-
-
-
Constructor Detail
-
LightLambdaExchange
public LightLambdaExchange(com.amazonaws.services.lambda.runtime.Context context, Chain chain)
-
-
Method Detail
-
executeChain
public void executeChain()
-
setInitialResponse
public void setInitialResponse(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent response)
Sets the response object of the exchange.- Parameters:
response- -
-
setInitialRequest
public void setInitialRequest(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request)
Sets the request object of the exchange.- Parameters:
request- -
-
getResponse
public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent getResponse()
Returns the response object or an exception object if there was a failure.- Returns:
- - return formatted response event.
-
getContext
public com.amazonaws.services.lambda.runtime.Context getContext()
-
getRequest
public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent getRequest()
-
getReadOnlyRequest
public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent getReadOnlyRequest()
-
getStatusCode
public int getStatusCode()
-
getFinalizedRequest
public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent getFinalizedRequest(boolean fromListener)
Terminates the request portion of the exchange and invokes the exchangeRequestCompleteListeners. You cannot finalize a request that has already been finalized.- Parameters:
fromListener- - if the call is from a listener, do not invoke listeners again.- Returns:
- - returns the complete and final request event.
-
getFinalizedResponse
public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent getFinalizedResponse(boolean fromListener)
Terminates the response portion of the exchange and invokes the exchangeResponseCompleteListeners. You cannot finalize a response that has already been finalized.- Parameters:
fromListener- - if the call is from a listener, do not invoke listeners again.- Returns:
- - returns the complete and final response event.
-
updateExchangeStatus
public void updateExchangeStatus(com.networknt.status.Status status)
Update the exchange. This happens automatically after each middleware execution, but it can be invoked manually by user logic.Once an exchange is marked as failed, no longer handle updates.
- Parameters:
status- - status to update the exchange with.
-
hasFailedState
public boolean hasFailedState()
Check to see if the exchange has any error state at all.- Returns:
- - returns true if the exchange has a failure state.
-
isRequestInProgress
public boolean isRequestInProgress()
Checks to see if the exchange is in the 'request in progress' state. The exchange is in the request state when the request chain is ready and has not finished executing.- Returns:
- - returns true if the exchange is handing the request.
-
isRequestComplete
public boolean isRequestComplete()
-
isResponseInProgress
public boolean isResponseInProgress()
Checks to see if the exchange is in the response in progress state. The exchange is in the response state when the request chain is complete, and the response chain is ready and has not finished executing.- Returns:
- - return true if the exchange is handling the response.
-
isResponseComplete
public boolean isResponseComplete()
Checks to see if the exchange has the response portion complete.- Returns:
- - true if the response is complete.
-
isExchangeComplete
public boolean isExchangeComplete()
Checks to see if the exchange is complete.- Returns:
- - true if the exchange is complete.
-
getState
public int getState()
- Returns:
- int state
-
addExchangeFailedListener
public LightLambdaExchange addExchangeFailedListener(LambdaExchangeFailureListener listener)
-
addResponseCompleteListener
public LightLambdaExchange addResponseCompleteListener(LambdaResponseCompleteListener listener)
-
addRequestCompleteListener
public LightLambdaExchange addRequestCompleteListener(LambdaRequestCompleteListener listener)
-
addAttachment
public <T extends MiddlewareHandler> void addAttachment(LightLambdaExchange.Attachable<T> key, Object o)
Adds an attachment to the exchange.- Type Parameters:
T- - Middleware key type.- Parameters:
key- - Attachable key.o- - object value.
-
getAttachment
public Object getAttachment(LightLambdaExchange.Attachable<?> attachable)
Get attachment object for given key.- Parameters:
attachable- - middleware key- Returns:
- - returns the object for the provided key. Can return null if it does not exist.
-
getAttachments
public Map<LightLambdaExchange.Attachable<?>,Object> getAttachments()
-
-