/** * Aggregate updates for each write locations. Whenever write as well as append updates for the * same location exists, the updates are not consistent. * * @param pluginAgg */ public void aggregateWrite(PluginAggregationAPI pluginAgg) { Set<Location> writeLocsToAggregate = pluginAgg.getLocsWithAnyAction(WRITE_ACTION); Set<Location> appendLocsToAggregate = pluginAgg.getLocsWithAnyAction(APPEND_ACTION); for (Location writeLoc : writeLocsToAggregate) { // if regular update affects this location if (pluginAgg.regularUpdatesAffectsLoc(writeLoc)) { pluginAgg.handleInconsistentAggregationOnLocation(writeLoc, this); } else { Element locValue = null; // mark at least one inconsistent update for (Update update : pluginAgg.getLocUpdates(writeLoc)) { if (WRITE_ACTION.equals(update.action)) { // different values for the same location if (locValue != null && locValue.equals(update.value)) pluginAgg.flagUpdate(update, Flag.FAILED, this); else { locValue = update.value; // append and write within the same step for the same location if (appendLocsToAggregate.contains(writeLoc)) { pluginAgg.flagUpdate(update, Flag.FAILED, this); } else { pluginAgg.flagUpdate(update, Flag.SUCCESSFUL, this); } } if (!(update.value instanceof ListElement)) { pluginAgg.addResultantUpdate( new Update( writeLoc, new ListElement(Arrays.asList(new Element[] {update.value})), update.action, update.agents, update.sources), this); } else { pluginAgg.addResultantUpdate(update, this); } } } } } }
/** * Aggregate updates for the print location. * * @param pluginAgg */ public void aggregatePrint(PluginAggregationAPI pluginAgg) { // all locations on which contain print actions Set<Location> locsToAggregate = pluginAgg.getLocsWithAnyAction(PRINT_ACTION); Set<Element> contributingAgents = new HashSet<Element>(); Set<ScannerInfo> contributingNodes = new HashSet<ScannerInfo>(); // for all locations to aggregate for (Location l : locsToAggregate) { if (PRINT_OUTPUT_FUNC_LOC.name.equals(l.name)) { String outputResult = ""; // if regular update affects this location if (pluginAgg.regularUpdatesAffectsLoc(l)) { pluginAgg.handleInconsistentAggregationOnLocation(l, this); } else { for (Update update : pluginAgg.getLocUpdates(l)) { if (update.action.equals(PRINT_ACTION)) { outputResult += update.value.toString() + "\n"; // flag update aggregation as successful for this update pluginAgg.flagUpdate(update, Flag.SUCCESSFUL, this); contributingAgents.addAll(update.agents); contributingNodes.addAll(update.sources); } } } pluginAgg.addResultantUpdate( new Update( PRINT_OUTPUT_FUNC_LOC, new StringElement(outputResult), Update.UPDATE_ACTION, contributingAgents, contributingNodes), this); } } }
/** * Aggregate updates for each append location. Whenever write as well as append updates for the * same location exists, the updates are not consistent. * * @param pluginAgg */ public void aggregateAppend(PluginAggregationAPI pluginAgg) { Set<Location> writeLocsToAggregate = pluginAgg.getLocsWithAnyAction(WRITE_ACTION); Set<Location> appendLocsToAggregate = pluginAgg.getLocsWithAnyAction(APPEND_ACTION); for (Location appendLoc : appendLocsToAggregate) { // if regular update affects this location if (pluginAgg.regularUpdatesAffectsLoc(appendLoc)) { pluginAgg.handleInconsistentAggregationOnLocation(appendLoc, this); } else { // mark at least one inconsistent update for (Update update : pluginAgg.getLocUpdates(appendLoc)) { if (APPEND_ACTION.equals(update.action)) { // append and write within the same step for the same location if (writeLocsToAggregate.contains(appendLoc)) { pluginAgg.flagUpdate(update, Flag.FAILED, this); } else { pluginAgg.flagUpdate(update, Flag.SUCCESSFUL, this); } pluginAgg.addResultantUpdate(update, this); } } } } }