Class DefaultIdempotentService
- java.lang.Object
-
- io.microsphere.spring.web.idempotent.DefaultIdempotentService
-
- All Implemented Interfaces:
IdempotentService
public class DefaultIdempotentService extends java.lang.Object implements IdempotentService
The defaultIdempotentServiceimplementation which uses a weak referenceConcurrentReferenceHashMapto store the new generated token andsessioncontext to check the duplicated request with same token.- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
IdempotentService,ConcurrentReferenceHashMap,ConcurrentReferenceHashMap.ReferenceType.WEAK
-
-
Constructor Summary
Constructors Constructor Description DefaultIdempotentService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, java.lang.String token)Check the token is existedvoiddestroy()Destroyjava.lang.StringgenerateToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes)Generate a new token.java.lang.StringgetToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes)Get the token from the request.booleaninvalidate(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, java.lang.String token)Invalidate the tokenbooleanstoreToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, java.lang.String newToken)Store the token into backend storage.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.microsphere.spring.web.idempotent.IdempotentService
renewToken, validateToken
-
-
-
-
Method Detail
-
generateToken
public java.lang.String generateToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes)Description copied from interface:IdempotentServiceGenerate a new token.Note : The new token should not be generated twice in one request.
- Specified by:
generateTokenin interfaceIdempotentService- Parameters:
request- theNativeWebRequestattributes- theIdempotentAttributes- Returns:
- the new token
-
getToken
public java.lang.String getToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes)Description copied from interface:IdempotentServiceGet the token from the request.- Specified by:
getTokenin interfaceIdempotentService- Parameters:
request- theNativeWebRequestattributes- theIdempotentAttributes- Returns:
- the token from the request if exists
-
checkToken
public boolean checkToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, java.lang.String token)Description copied from interface:IdempotentServiceCheck the token is existed- Specified by:
checkTokenin interfaceIdempotentService- Parameters:
request- theNativeWebRequestattributes- theIdempotentAttributestoken- the token- Returns:
trueif exists
-
invalidate
public boolean invalidate(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, java.lang.String token)Description copied from interface:IdempotentServiceInvalidate the token- Specified by:
invalidatein interfaceIdempotentService- Parameters:
request- theNativeWebRequestattributes- theIdempotentAttributestoken- the token- Returns:
trueif invalidated successfully
-
storeToken
public boolean storeToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, java.lang.String newToken)Description copied from interface:IdempotentServiceStore the token into backend storage.- Specified by:
storeTokenin interfaceIdempotentService- Parameters:
request- theNativeWebRequestattributes- theIdempotentAttributesnewToken- the new generated token- Returns:
trueif stored successfully
-
destroy
public void destroy()
Description copied from interface:IdempotentServiceDestroy- Specified by:
destroyin interfaceIdempotentService
-
-