Package org.nuxeo.ecm.core.bulk
Class BulkServiceImpl
- java.lang.Object
-
- org.nuxeo.ecm.core.bulk.BulkServiceImpl
-
- All Implemented Interfaces:
javax.transaction.Synchronization,AsyncService<String,BulkStatus,Map<String,Serializable>>,BulkService
public class BulkServiceImpl extends Object implements BulkService, javax.transaction.Synchronization
Basic implementation ofBulkService.- Since:
- 10.2
-
-
Field Summary
Fields Modifier and Type Field Description static longABORTED_TTL_SECONDSstatic StringBULK_KV_STORE_NAMEstatic StringBULK_LOG_MANAGER_NAMEDeprecated.static StringCOMMAND_PREFIXstatic StringCOMMAND_STREAMstatic NameCOMMAND_STREAM_NAMEstatic longCOMPLETED_IN_ERROR_TTL_SECONDSstatic longCOMPLETED_TTL_SECONDSstatic StringDONE_STREAMstatic NameDONE_STREAM_NAMEstatic StringEXCLUSIVE_PREFIXprotected static longEXCLUSIVE_TTL_SECONDSprotected Map<String,BulkCommand>externalCommandsprotected AtomicLongexternalScrollerCounterprotected static ThreadLocal<Boolean>isEnlistedstatic StringPRODUCE_IMMEDIATE_OPTIONstatic StringRECORD_CODECDeprecated.static StringSTATUS_PREFIXstatic StringSTATUS_STREAMstatic NameSTATUS_STREAM_NAMEprotected static ThreadLocal<List<BulkCommand>>transactionCommands
-
Constructor Summary
Constructors Constructor Description BulkServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BulkStatusabort(String commandId)Aborts an asynchronous task.voidafterCompletion(int status)voidappendExternalBucket(BulkBucket bucket)Sends aBulkBucketto the right bulk action.booleanawait(String commandId, Duration duration)Waits for completion of given bulk command.booleanawait(Duration duration)Waits for completion of all bulk commands.voidbeforeCompletion()protected voidcheckIfScrollerExists(BulkCommand command)voidcompleteExternalScroll(String commandId, long count)Completes a running bulk computation having an external scroller.BulkCommandgetCommand(String commandId)Returns the command or null if the command is not found or aborted.KeyValueStoregetKvStore()Map<String,Serializable>getResult(String commandId)Retrieves the command execution result.BulkStatusgetStatus(String commandId)Returns the status of a task.List<BulkStatus>getStatuses(String username)Gets the list of action statuses triggered by the given user.protected booleanregisterSynchronization(javax.transaction.Synchronization sync)byte[]setCommand(BulkCommand command)Stores the command in the kv store, returns the encoded command.protected voidsetExclusive(BulkCommand command)byte[]setStatus(BulkStatus status)Stores the status in the kv store returns the encoded statusprotected Stringsubmit(String shardKey, String key, byte[] bytes)Stringsubmit(BulkCommand command)Submits aBulkCommandthat will be processed asynchronously, even if the current transaction rolls back (the method is not transactional).StringsubmitTransactional(BulkCommand command)Submits aBulkCommandthat will be processed asynchronously only if the transaction commits successfully (nothing will be submitted in case of transaction rollback).
-
-
-
Field Detail
-
BULK_LOG_MANAGER_NAME
@Deprecated public static final String BULK_LOG_MANAGER_NAME
Deprecated.- See Also:
- Constant Field Values
-
BULK_KV_STORE_NAME
public static final String BULK_KV_STORE_NAME
- See Also:
- Constant Field Values
-
COMMAND_STREAM
public static final String COMMAND_STREAM
- See Also:
- Constant Field Values
-
COMMAND_STREAM_NAME
public static final Name COMMAND_STREAM_NAME
-
STATUS_STREAM
public static final String STATUS_STREAM
- See Also:
- Constant Field Values
-
STATUS_STREAM_NAME
public static final Name STATUS_STREAM_NAME
-
DONE_STREAM
public static final String DONE_STREAM
- See Also:
- Constant Field Values
-
DONE_STREAM_NAME
public static final Name DONE_STREAM_NAME
-
COMMAND_PREFIX
public static final String COMMAND_PREFIX
- See Also:
- Constant Field Values
-
RECORD_CODEC
@Deprecated(since="11.4") public static final String RECORD_CODEC
Deprecated.- See Also:
- Constant Field Values
-
STATUS_PREFIX
public static final String STATUS_PREFIX
- See Also:
- Constant Field Values
-
EXCLUSIVE_PREFIX
public static final String EXCLUSIVE_PREFIX
- See Also:
- Constant Field Values
-
PRODUCE_IMMEDIATE_OPTION
public static final String PRODUCE_IMMEDIATE_OPTION
- See Also:
- Constant Field Values
-
COMPLETED_TTL_SECONDS
public static final long COMPLETED_TTL_SECONDS
- See Also:
- Constant Field Values
-
ABORTED_TTL_SECONDS
public static final long ABORTED_TTL_SECONDS
- See Also:
- Constant Field Values
-
COMPLETED_IN_ERROR_TTL_SECONDS
public static final long COMPLETED_IN_ERROR_TTL_SECONDS
- See Also:
- Constant Field Values
-
EXCLUSIVE_TTL_SECONDS
protected static final long EXCLUSIVE_TTL_SECONDS
- See Also:
- Constant Field Values
-
externalScrollerCounter
protected final AtomicLong externalScrollerCounter
-
externalCommands
protected final Map<String,BulkCommand> externalCommands
-
isEnlisted
protected static final ThreadLocal<Boolean> isEnlisted
-
transactionCommands
protected static final ThreadLocal<List<BulkCommand>> transactionCommands
-
-
Method Detail
-
submit
public String submit(BulkCommand command)
Description copied from interface:BulkServiceSubmits aBulkCommandthat will be processed asynchronously, even if the current transaction rolls back (the method is not transactional).- Specified by:
submitin interfaceBulkService- Parameters:
command- the command to submit- Returns:
- a unique bulk command identifier
-
checkIfScrollerExists
protected void checkIfScrollerExists(BulkCommand command)
-
getStatus
public BulkStatus getStatus(String commandId)
Description copied from interface:AsyncServiceReturns the status of a task.- Specified by:
getStatusin interfaceAsyncService<String,BulkStatus,Map<String,Serializable>>
-
setExclusive
protected void setExclusive(BulkCommand command)
-
setStatus
public byte[] setStatus(BulkStatus status)
Stores the status in the kv store returns the encoded status
-
getCommand
public BulkCommand getCommand(String commandId)
Description copied from interface:BulkServiceReturns the command or null if the command is not found or aborted.- Specified by:
getCommandin interfaceBulkService
-
abort
public BulkStatus abort(String commandId)
Description copied from interface:AsyncServiceAborts an asynchronous task. Service should try to cancel the task, if not possible it must try to stop it.- Specified by:
abortin interfaceAsyncService<String,BulkStatus,Map<String,Serializable>>
-
getResult
public Map<String,Serializable> getResult(String commandId)
Description copied from interface:AsyncServiceRetrieves the command execution result.- Specified by:
getResultin interfaceAsyncService<String,BulkStatus,Map<String,Serializable>>
-
setCommand
public byte[] setCommand(BulkCommand command)
Stores the command in the kv store, returns the encoded command.
-
await
public boolean await(String commandId, Duration duration) throws InterruptedException
Description copied from interface:BulkServiceWaits for completion of given bulk command.- Specified by:
awaitin interfaceBulkService- Parameters:
commandId- the command to waitduration- the duration to wait- Returns:
trueif bulk command completed orfalseif computation has not finished after the timeout- Throws:
InterruptedException
-
getKvStore
public KeyValueStore getKvStore()
-
await
public boolean await(Duration duration) throws InterruptedException
Description copied from interface:BulkServiceWaits for completion of all bulk commands.- Specified by:
awaitin interfaceBulkService- Parameters:
duration- the duration to wait- Returns:
trueif all bulk commands completed orfalseif one or more has not finished after the timeout- Throws:
InterruptedException
-
getStatuses
public List<BulkStatus> getStatuses(String username)
Description copied from interface:BulkServiceGets the list of action statuses triggered by the given user.- Specified by:
getStatusesin interfaceBulkService- Parameters:
username- the user name- Returns:
- the list of statuses
-
appendExternalBucket
public void appendExternalBucket(BulkBucket bucket)
Description copied from interface:BulkServiceSends aBulkBucketto the right bulk action.This method is useful to produce bucket externally when using an external scroller.
- Specified by:
appendExternalBucketin interfaceBulkService- Parameters:
bucket- the bucket to send to a bulk action
-
completeExternalScroll
public void completeExternalScroll(String commandId, long count)
Description copied from interface:BulkServiceCompletes a running bulk computation having an external scroller.- Specified by:
completeExternalScrollin interfaceBulkService- Parameters:
commandId- the command idcount- the total number of elements produced by the external scroller
-
submitTransactional
public String submitTransactional(BulkCommand command)
Description copied from interface:BulkServiceSubmits aBulkCommandthat will be processed asynchronously only if the transaction commits successfully (nothing will be submitted in case of transaction rollback). Note that theAsyncService.getStatus(Serializable)will return an unknown state until transaction is committed.- Specified by:
submitTransactionalin interfaceBulkService- Parameters:
command- the command to submit- Returns:
- a unique bulk command identifier
-
registerSynchronization
protected boolean registerSynchronization(javax.transaction.Synchronization sync) throws javax.transaction.RollbackException- Throws:
javax.transaction.RollbackException
-
beforeCompletion
public void beforeCompletion()
- Specified by:
beforeCompletionin interfacejavax.transaction.Synchronization
-
afterCompletion
public void afterCompletion(int status)
- Specified by:
afterCompletionin interfacejavax.transaction.Synchronization
-
-