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 long
ABORTED_TTL_SECONDS
static String
BULK_KV_STORE_NAME
static String
BULK_LOG_MANAGER_NAME
Deprecated.static String
COMMAND_PREFIX
static String
COMMAND_STREAM
static Name
COMMAND_STREAM_NAME
static long
COMPLETED_IN_ERROR_TTL_SECONDS
static long
COMPLETED_TTL_SECONDS
static String
DONE_STREAM
static Name
DONE_STREAM_NAME
static String
EXCLUSIVE_PREFIX
protected static long
EXCLUSIVE_TTL_SECONDS
protected Map<String,BulkCommand>
externalCommands
protected AtomicLong
externalScrollerCounter
protected static ThreadLocal<Boolean>
isEnlisted
static String
PRODUCE_IMMEDIATE_OPTION
static String
RECORD_CODEC
Deprecated.static String
STATUS_PREFIX
static String
STATUS_STREAM
static Name
STATUS_STREAM_NAME
protected static ThreadLocal<List<BulkCommand>>
transactionCommands
-
Constructor Summary
Constructors Constructor Description BulkServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BulkStatus
abort(String commandId)
Aborts an asynchronous task.void
afterCompletion(int status)
void
appendExternalBucket(BulkBucket bucket)
Sends aBulkBucket
to the right bulk action.boolean
await(String commandId, Duration duration)
Waits for completion of given bulk command.boolean
await(Duration duration)
Waits for completion of all bulk commands.void
beforeCompletion()
protected void
checkIfScrollerExists(BulkCommand command)
void
completeExternalScroll(String commandId, long count)
Completes a running bulk computation having an external scroller.BulkCommand
getCommand(String commandId)
Returns the command or null if the command is not found or aborted.KeyValueStore
getKvStore()
Map<String,Serializable>
getResult(String commandId)
Retrieves the command execution result.BulkStatus
getStatus(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 boolean
registerSynchronization(javax.transaction.Synchronization sync)
byte[]
setCommand(BulkCommand command)
Stores the command in the kv store, returns the encoded command.protected void
setExclusive(BulkCommand command)
byte[]
setStatus(BulkStatus status)
Stores the status in the kv store returns the encoded statusprotected String
submit(String shardKey, String key, byte[] bytes)
String
submit(BulkCommand command)
Submits aBulkCommand
that will be processed asynchronously, even if the current transaction rolls back (the method is not transactional).String
submitTransactional(BulkCommand command)
Submits aBulkCommand
that 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:BulkService
Submits aBulkCommand
that will be processed asynchronously, even if the current transaction rolls back (the method is not transactional).- Specified by:
submit
in 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:AsyncService
Returns the status of a task.- Specified by:
getStatus
in 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:BulkService
Returns the command or null if the command is not found or aborted.- Specified by:
getCommand
in interfaceBulkService
-
abort
public BulkStatus abort(String commandId)
Description copied from interface:AsyncService
Aborts an asynchronous task. Service should try to cancel the task, if not possible it must try to stop it.- Specified by:
abort
in interfaceAsyncService<String,BulkStatus,Map<String,Serializable>>
-
getResult
public Map<String,Serializable> getResult(String commandId)
Description copied from interface:AsyncService
Retrieves the command execution result.- Specified by:
getResult
in 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:BulkService
Waits for completion of given bulk command.- Specified by:
await
in interfaceBulkService
- Parameters:
commandId
- the command to waitduration
- the duration to wait- Returns:
true
if bulk command completed orfalse
if 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:BulkService
Waits for completion of all bulk commands.- Specified by:
await
in interfaceBulkService
- Parameters:
duration
- the duration to wait- Returns:
true
if all bulk commands completed orfalse
if one or more has not finished after the timeout- Throws:
InterruptedException
-
getStatuses
public List<BulkStatus> getStatuses(String username)
Description copied from interface:BulkService
Gets the list of action statuses triggered by the given user.- Specified by:
getStatuses
in interfaceBulkService
- Parameters:
username
- the user name- Returns:
- the list of statuses
-
appendExternalBucket
public void appendExternalBucket(BulkBucket bucket)
Description copied from interface:BulkService
Sends aBulkBucket
to the right bulk action.This method is useful to produce bucket externally when using an external scroller.
- Specified by:
appendExternalBucket
in interfaceBulkService
- Parameters:
bucket
- the bucket to send to a bulk action
-
completeExternalScroll
public void completeExternalScroll(String commandId, long count)
Description copied from interface:BulkService
Completes a running bulk computation having an external scroller.- Specified by:
completeExternalScroll
in 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:BulkService
Submits aBulkCommand
that 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:
submitTransactional
in 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:
beforeCompletion
in interfacejavax.transaction.Synchronization
-
afterCompletion
public void afterCompletion(int status)
- Specified by:
afterCompletion
in interfacejavax.transaction.Synchronization
-
-