use of com.tvd12.calabash.persist.action.PersistAction in project calabash by youngmonkeys.
the class PersistSaveActionBulk method execute.
@Override
public void execute() {
Map<Object, Object> keyValues = new HashMap<>();
for (PersistAction action : actions) {
if (action.getType() == PersistActionType.SAVE_ONE) {
PersistSaveOneAction one = (PersistSaveOneAction) action;
keyValues.put(one.getKey(), one.getValue());
} else {
PersistSaveManyAction many = (PersistSaveManyAction) action;
keyValues.putAll(many.getKeyValues());
}
}
((EntityMapPersist) mapPersist).persist(keyValues);
}
use of com.tvd12.calabash.persist.action.PersistAction in project calabash by youngmonkeys.
the class PersistDeleteActionBulk method execute.
@Override
public void execute() {
Set keys = new HashSet<>();
for (PersistAction action : actions) {
if (action.getType() == PersistActionType.DELETE_ONE) {
keys.add(((PersistDeleteOneAction) action).getKey());
} else {
keys.addAll(((PersistDeleteManyAction) action).getKeys());
}
}
((BytesMapPersist) mapPersist).delete(keys);
}
use of com.tvd12.calabash.persist.action.PersistAction in project calabash by youngmonkeys.
the class PersistSaveActionBulk method execute.
@Override
public void execute() {
Map keyValues = new HashMap<>();
for (PersistAction action : actions) {
if (action.getType() == PersistActionType.SAVE_ONE) {
PersistSaveOneAction one = (PersistSaveOneAction) action;
keyValues.put(one.getKey(), one.getValue());
} else {
PersistSaveManyAction many = (PersistSaveManyAction) action;
keyValues.putAll(many.getKeyValues());
}
}
((BytesMapPersist) mapPersist).persist(keyValues);
}
use of com.tvd12.calabash.persist.action.PersistAction in project calabash by youngmonkeys.
the class SimpleBytesMapPersistExecutor method addPersistActionToQueue.
protected void addPersistActionToQueue(MapSetting setting, PersistAction action) {
String mapName = setting.getMapName();
MapPersistSetting persistSetting = setting.getPersistSetting();
long writeDelay = persistSetting.getWriteDelay();
PersistActionQueue queue = writeDelay > 0 ? actionQueueManager.getDelayedQueue(mapName) : actionQueueManager.getImmediateQueue(mapName);
queue.add(action);
}
use of com.tvd12.calabash.persist.action.PersistAction 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