public abstract class DefaultAbstractTokenContainerService<T extends Token<T>,C extends TokenContainer<T>> extends AbstractTokenChangeGenerator<T,TokenEvent<T>> implements TokenContainerService<T,C>
TokenManager
and BatchService
ChangeGenerator
; it will also generate Events of TypeSynchronousTokenChangeListener
Constructor and Description |
---|
DefaultAbstractTokenContainerService() |
Modifier and Type | Method and Description |
---|---|
protected abstract Supplier<javax.persistence.Query> |
createTokensStateQuery(C tokenContainer,
T afterToken,
T beforeToken,
Collection states,
PageInfo pageInfo)
REUSABLE | use with
#getTokens(TokenContainer, Token, Collection, String) |
Collection<? extends T> |
filter(Collection<? extends T> tokens)
All client sent tokens should be validated/filtered internally.
|
protected javax.persistence.EntityManager |
getEntityManager() |
T |
getFirstToken(C tokenContainer,
Collection states)
Get the first token for a group of status
|
T |
getLastToken(C tokenContainer,
Collection states)
In Some situations a token may need to be put end of Q in a particular State(s).
|
protected List<Object[]> |
getMovesForInterLinkingTokens(List<T> tokens)
For
ReQueableToken s lnk them. |
protected List<Object[]> |
getMovesForLinkingTokensAfter(List<T> tokens,
T tokenAfter)
Link the internal tokens in order after the "tokenAfter".
|
protected List<Object[]> |
getMovesForMovedTokens(List<T> tokens)
The positions from which the tokens move (create spaces), patch them.
|
List<TokenPosition<T>> |
getPositions(List<T> tokens,
Collection states)
|
List<T> |
getReadyToBeProcessed(C tokenContainer,
T lastToken)
REUSABLE
|
abstract List<T> |
getTokens(C tokenContainer) |
protected abstract List<T> |
getTokens(C tokenContainer,
Collection c,
String field)
For a given
Token Field name, where each element in the Collection matches the Token field value; fetch Token
Example: If we wish to get all tokens with GUIDs in a set. |
List<T> |
getTokens(C tokenContainer,
T afterToken,
Collection states)
REUSABLE
|
List<T> |
getTokens(C tokenContainer,
T afterToken,
T beforeToken,
Collection states,
PageInfo pageInfo)
REUSABLE
|
protected abstract Number |
getTokenSequenceId(C container,
T token)
A Raw sequence#/position for a
Token in the order it was added. |
List<T> |
getTokensFrom(C tokenContainer,
T token,
Collection states)
Get all
Tokens s in sequence till (excluding) the token |
List<T> |
getTokensTill(C tokenContainer,
T token,
Collection states)
Get all
Tokens s in sequence till (excluding) the token |
void |
linkTokens(C tokenContainer,
List<T> tokens)
Re-Q / Move the tokens
|
abstract List<T> |
lookupById(C tokenContainer,
Object identifier)
Lookup token(s) in a token container, using any of the following identifiers.
|
protected List<T> |
lookupById(C tokenContainer,
Object identifier,
Supplier<javax.persistence.Query> query) |
void |
lookupBySequence(C tokenContainer,
Map<Number,T> indexMap)
For each Number in the indeces, provide a Token, if it exists.
|
T |
lookupBySequence(C tokenContainer,
Number sequence)
Lookup a token in a Container by sequence number
in tokens that are
#getReadyToBeProcessed(TokenContainer, Token) . |
int |
move(C tokenContainer,
List<T> tokens,
T tokenAfter)
Deprecated.
See
TokenContainerService.move(TokenContainer, List, Token) JavaDoc for reason |
protected void |
notifyAllListeners(Supplier<Collection<T>> tokensSupplier,
TokenEvent<T> tokenEvent)
Convenience default method that allows basic mandatory actions like
fetching all the tokens and apply
AbstractTokenChangeGenerator.trackChange(Object) with asynchronous considerations |
protected abstract void |
persistMoves(C tokenContainer,
List<Object[]> moves)
A Move[] is an array [
Token.getId() , ReQueableToken.getPreviousRef() , ReQueableToken.getNextRef() ].A List of moves |
T |
poll(C tokenContainer)
Poll then next token READY to be served.
|
List<T> |
poll(C tokenContainer,
Integer size)
An optimized Poll with N number of Tokens in one go.
|
List<T> |
poll(C tokenContainer,
Integer size,
T lastToken)
|
T |
poll(C tokenContainer,
T lastToken)
Based on Last Token return next
Token in TokenContainer .This is for fail safe to ensure if a Token is lost in network errors, then the server knows last point of rollback. |
void |
setEntityManager(javax.persistence.EntityManager em) |
protected <S extends FlowStatus> |
updateStatus(C tokenContainer,
Collection c,
S status,
Function<String,javax.persistence.Query> query,
TokenEvent<T> tokenEvent) |
protected <S extends FlowStatus> |
updateStatus(Collection c,
S status,
Function<String,javax.persistence.Query> query,
TokenEvent<T> tokenEvent) |
protected abstract void |
updateTokenStatusInProcess(T token)
Update token to IN PROGRESS type state.
|
protected boolean |
validateMove(Object[] m) |
addChangeListener, getListeners, getTrackChange, notifyAllListeners, setListeners, setTrackChange, trackChange, trackChange
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
add, getAssignedContainer, getMaxResultSize, getQStatesStrategy, getSequence, getType, hasNext, init, lookup, remove, save, size, update, updateStatus, updateStatus
protected static final Long SKIP_MOVE
public DefaultAbstractTokenContainerService()
protected javax.persistence.EntityManager getEntityManager()
public abstract List<T> lookupById(C tokenContainer, Object identifier)
TokenContainerService
List
is supported. For all practical purposes this will be a single result.lookupById
in interface TokenContainerService<T extends Token<T>,C extends TokenContainer<T>>
tokenContainer
- as TokenContainer
type identifier
- as name String, Id LongList
of public void lookupBySequence(C tokenContainer, Map<Number,T> indexMap)
lookupBySequence
in interface TokenContainerService<T extends Token<T>,C extends TokenContainer<T>>
batch
- as Batch
indexMap
- as modifiable Map
of the sequence as input and its value (if not null) as Token
corresponding to it.public T lookupBySequence(C tokenContainer, Number sequence)
TokenContainerService
#getReadyToBeProcessed(TokenContainer, Token)
.lookupBySequence
in interface TokenContainerService<T extends Token<T>,C extends TokenContainer<T>>
tokenContainer
- as container type sequence
- as Number
protected abstract void updateTokenStatusInProcess(T token)
Queue.remove()
tokenContainer
- as token
- as Token
public T poll(C tokenContainer)
TokenContainerService
QStatesStrategy.getReadyToBeProcessed()
poll
in interface TokenContainerService<T extends Token<T>,C extends TokenContainer<T>>
tokenContainer
- as container type Token
within the container. null if none#getReadyToBeProcessed(TokenContainer)
,
QStatesStrategy
public T poll(C tokenContainer, T lastToken)
TokenContainerService
Token
in TokenContainer
.poll
in interface TokenContainerService<T extends Token<T>,C extends TokenContainer<T>>
tokenContainer
- as TokenContainer
type lastToken
- as Token
type Token
type public List<T> poll(C tokenContainer, Integer size)
TokenContainerService
poll
in interface TokenContainerService<T extends Token<T>,C extends TokenContainer<T>>
tokenContainer
- as TokenContainer
type List
of Token
of type public List<T> poll(C tokenContainer, Integer size, T lastToken)
TokenContainerService
Token
s (of size), in Shift
.poll
in interface TokenContainerService<T extends Token<T>,C extends TokenContainer<T>>
tokenContainer
- as TokenContainer
type List
of Token
of type public void setEntityManager(javax.persistence.EntityManager em)
em
- the em to setpublic Collection<? extends T> filter(Collection<? extends T> tokens)
tokens
- protected List<T> lookupById(C tokenContainer, Object identifier, Supplier<javax.persistence.Query> query)
public List<T> getReadyToBeProcessed(C tokenContainer, T lastToken)
tokenContainer
- as TokenContainer
type lastToken
- as Token
type query
- List
#createTokensStateQuery(TokenContainer, Token, String)
protected abstract Supplier<javax.persistence.Query> createTokensStateQuery(C tokenContainer, T afterToken, T beforeToken, Collection states, PageInfo pageInfo)
#getTokens(TokenContainer, Token, Collection, String)
tokenContainer
- as TokenContainer
type afterToken
- AFTER which tokens should be queried as Token
type beforeTokem
- BEFORE which tokens should be queried as Token
type states
- as Collection of Token States. Example TokenStatus
pageInfo
- as PageInfo. Can be nullSupplier
DefaultAbstractTokenContainerService#getTokens(TokenContainer, Token, Collection, String)
public List<T> getTokens(C tokenContainer, T afterToken, T beforeToken, Collection states, PageInfo pageInfo)
#createTokensStateQuery(TokenContainer, Token, String)
public List<T> getTokens(C tokenContainer, T afterToken, Collection states)
tokenContainer
- as TokenContainer
type afterToken
- as Token
type states
- as Collection of Token States. Example TokenStatus
List
#createTokensStateQuery(TokenContainer, Token, String)
protected abstract List<T> getTokens(C tokenContainer, Collection c, String field)
Token
Field name, where each element in the Collection
matches the Token
field value; fetch Token
tokenContainer
- as TokenContainer
we wish to fetch the Token
s only for. Null implies all.c
- as Collection
of Ids or values that represent the fieldfield
- as String
. Blank means the type is Token, if not blank then the field should contain a prefix "."AbstractTokenChangeGenerator.notifyAllListeners(TokenEvent)
public List<TokenPosition<T>> getPositions(List<T> tokens, Collection states)
TokenPosition
of a Token
within its container #getTokens(...)
; all getTokens are expected to be sorted based on Q-sorting algo already,
so any prioritization etc would be assumed taken care of within any wsorting within getTokens(...)getPositions
in interface TokenContainerService<T extends Token<T>,C extends TokenContainer<T>>
tokens
- as List
of Token
type states
- as Token StatesNumber
. null if in a ready stateBatch.getSequence(Token)
,
TokenContainerService.getSequence(TokenContainer, Token)
protected abstract Number getTokenSequenceId(C container, T token)
Token
in the order it was added.
This does NOT indicate its TokenContainerService.getSequence(TokenContainer, Token)
or getPositions(List, Collection)
protected <S extends FlowStatus> List<T> updateStatus(Collection c, S status, Function<String,javax.persistence.Query> query, TokenEvent<T> tokenEvent)
c
- as Collection
of Token
sstatus
- as FlowStatus
to update toquery
- as Function
to convert Field name to Query
tokenEvent
- as TokenEvent
#notifyAllListeners(Supplier, TokenEventFlowStatus, TokenEvent)
protected <S extends FlowStatus> List<T> updateStatus(C tokenContainer, Collection c, S status, Function<String,javax.persistence.Query> query, TokenEvent<T> tokenEvent)
tokenContainer
- as TokenContainer
or null (for tokens across containers)c
- as Collection
of Token
sstatus
- as FlowStatus
to update toquery
- as Function
to convert Field name to Query
tokenEvent
- as TokenEvent
#notifyAllListeners(Supplier, TokenEventFlowStatus, TokenEvent)
protected void notifyAllListeners(Supplier<Collection<T>> tokensSupplier, TokenEvent<T> tokenEvent)
AbstractTokenChangeGenerator.trackChange(Object)
with asynchronous considerationstokens
- Supplier
of Token
sstatus
- as TokenEvent.TokenEventFlowStatus
tokenEvent
- as TokenEvent
SynchronousChange
,
TokenEvent
,
BasicTokenEvent
,
Feedback
,
SynchronousTokenChangeListener
public T getLastToken(C tokenContainer, Collection states)
tokenContainer
- as TokenContainer
type states
- as Collection
of status type objects (Optional. If not specified will search across all Status)Token
public T getFirstToken(C tokenContainer, Collection states)
tokenContainer
- as TokenContainer
type states
- as Collection
of status type objects (Optional. If not specified will search across all Status)Token
public List<T> getTokensTill(C tokenContainer, T token, Collection states)
Tokens
s in sequence till (excluding) the tokentokenContainer
- as TokenContainer
type token
- as Token
tillstates
- as Collection
of status type objects (Optional. If not specified will search across all Status)List
of Token
spublic List<T> getTokensFrom(C tokenContainer, T token, Collection states)
Tokens
s in sequence till (excluding) the tokentokenContainer
- as TokenContainer
type token
- as Token
from (excluding)states
- as Collection
of status type objects (Optional. If not specified will search across all Status)List
of Token
sprotected boolean validateMove(Object[] m)
protected abstract void persistMoves(C tokenContainer, List<Object[]> moves)
Token.getId()
, ReQueableToken.getPreviousRef()
, ReQueableToken.getNextRef()
].List
of movestokenContainer
- as TokenContainer
type moves
- as List of Move (Object[])protected List<Object[]> getMovesForInterLinkingTokens(List<T> tokens)
ReQueableToken
s lnk them.tokens
- as List of Token
stokenAfter
- as optional token after which the tokens will be added/intelinkedpublic void linkTokens(C tokenContainer, List<T> tokens)
linkTokens
in interface TokenContainerService<T extends Token<T>,C extends TokenContainer<T>>
tokenContainer
- as TokenContainer
type tokens
- as List of Token
sprotected List<Object[]> getMovesForLinkingTokensAfter(List<T> tokens, T tokenAfter)
#persistMoves(List, T)
,
move(TokenContainer, List, Token)
protected List<Object[]> getMovesForMovedTokens(List<T> tokens)
#persistMoves(List, T)
,
move(TokenContainer, List, Token)
@Deprecated public int move(C tokenContainer, List<T> tokens, T tokenAfter)
TokenContainerService.move(TokenContainer, List, Token)
JavaDoc for reasonToken
s are of ReQueableToken
type.move
in interface TokenContainerService<T extends Token<T>,C extends TokenContainer<T>>
tokenContainer
- as TokenContainer
type tokens
- as List of Token
sUSAGE CAUTION
Copyright © 2018. All rights reserved.