Search in sources :

Example 1 with PersistAction

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);
}
Also used : PersistSaveManyAction(com.tvd12.calabash.persist.action.PersistSaveManyAction) HashMap(java.util.HashMap) PersistSaveOneAction(com.tvd12.calabash.persist.action.PersistSaveOneAction) EntityMapPersist(com.tvd12.calabash.persist.EntityMapPersist) PersistAction(com.tvd12.calabash.persist.action.PersistAction)

Example 2 with PersistAction

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);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) PersistAction(com.tvd12.calabash.persist.action.PersistAction) BytesMapPersist(com.tvd12.calabash.persist.BytesMapPersist) HashSet(java.util.HashSet)

Example 3 with PersistAction

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);
}
Also used : PersistSaveManyAction(com.tvd12.calabash.persist.action.PersistSaveManyAction) HashMap(java.util.HashMap) PersistSaveOneAction(com.tvd12.calabash.persist.action.PersistSaveOneAction) PersistAction(com.tvd12.calabash.persist.action.PersistAction) BytesMapPersist(com.tvd12.calabash.persist.BytesMapPersist) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with PersistAction

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);
}
Also used : MapPersistSetting(com.tvd12.calabash.persist.setting.MapPersistSetting)

Example 5 with PersistAction

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);
                }
            }
        }
    }
}
Also used : PersistAction(com.tvd12.calabash.persist.action.PersistAction) PersistActionType(com.tvd12.calabash.persist.action.PersistActionType)

Aggregations

PersistAction (com.tvd12.calabash.persist.action.PersistAction)5 BytesMapPersist (com.tvd12.calabash.persist.BytesMapPersist)2 EntityMapPersist (com.tvd12.calabash.persist.EntityMapPersist)2 PersistSaveManyAction (com.tvd12.calabash.persist.action.PersistSaveManyAction)2 PersistSaveOneAction (com.tvd12.calabash.persist.action.PersistSaveOneAction)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 EntityMapPersistSetting (com.tvd12.calabash.local.setting.EntityMapPersistSetting)1 PersistActionType (com.tvd12.calabash.persist.action.PersistActionType)1 MapPersistSetting (com.tvd12.calabash.persist.setting.MapPersistSetting)1 Map (java.util.Map)1 Set (java.util.Set)1