use of com.tvd12.calabash.persist.action.PersistActionType in project calabash by youngmonkeys.
the class PersistActionHandlingLoop method handleQueue0.
protected void handleQueue0(String mapName, PersistActionQueue queue) {
Object mapPersist = mapPersistManager.getMapPersist(mapName);
List<PersistAction> actions = queue.polls();
List<PersistAction> sameActions = null;
PersistActionType currentActionType = null;
int size = actions.size();
int last = size - 1;
for (int i = 0; i < actions.size(); i++) {
PersistAction action = actions.get(i);
PersistActionType actionType = action.getType();
if (currentActionType == null) {
currentActionType = actionType;
sameActions = new ArrayList<>();
}
boolean sameType = currentActionType.sames(actionType);
if (sameType) {
sameActions.add(action);
}
if (!sameType || i == last) {
PersistActionBulkBuilder builder = actionBulkFactory.newBulkBuilder(currentActionType);
PersistActionBulk bulk = builder.mapPersist(mapPersist).actions(sameActions).build();
currentActionType = actionType;
sameActions = new ArrayList<>();
PersistActionBulkQueue bulkQueue = bulkTicketQueues.getQueue(mapName);
// noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (bulkQueue) {
boolean empty = bulkQueue.isEmpty();
bulkQueue.add(bulk);
if (empty) {
bulkTicketQueues.addTicket(bulkQueue);
}
}
}
}
}
Aggregations