List of usage examples for org.apache.commons.lang3.tuple MutablePair setRight
public void setRight(final R right)
From source file:com.yahoo.pulsar.broker.service.Consumer.java
/** * Dispatch a list of entries to the consumer. * * @return a promise that can be use to track when all the data has been written into the socket *//*from w ww . ja v a2 s . c o m*/ public Pair<ChannelPromise, Integer> sendMessages(final List<Entry> entries) { final ChannelHandlerContext ctx = cnx.ctx(); final MutablePair<ChannelPromise, Integer> sentMessages = new MutablePair<ChannelPromise, Integer>(); final ChannelPromise writePromise = ctx.newPromise(); sentMessages.setLeft(writePromise); if (entries.isEmpty()) { if (log.isDebugEnabled()) { log.debug("[{}] List of messages is empty, triggering write future immediately for consumerId {}", subscription, consumerId); } writePromise.setSuccess(); sentMessages.setRight(0); return sentMessages; } sentMessages.setRight(updatePermitsAndPendingAcks(entries)); ctx.channel().eventLoop().execute(() -> { for (int i = 0; i < entries.size(); i++) { Entry entry = entries.get(i); PositionImpl pos = (PositionImpl) entry.getPosition(); MessageIdData.Builder messageIdBuilder = MessageIdData.newBuilder(); MessageIdData messageId = messageIdBuilder.setLedgerId(pos.getLedgerId()) .setEntryId(pos.getEntryId()).build(); ByteBuf metadataAndPayload = entry.getDataBuffer(); // skip checksum by incrementing reader-index if consumer-client doesn't support checksum verification if (cnx.getRemoteEndpointProtocolVersion() < ProtocolVersion.v6.getNumber()) { readChecksum(metadataAndPayload); } // stats msgOut.recordEvent(metadataAndPayload.readableBytes()); if (log.isDebugEnabled()) { log.debug("[{}] Sending message to consumerId {}, entry id {}", subscription, consumerId, pos.getEntryId()); } // We only want to pass the "real" promise on the last entry written ChannelPromise promise = ctx.voidPromise(); if (i == (entries.size() - 1)) { promise = writePromise; } ctx.write(Commands.newMessage(consumerId, messageId, metadataAndPayload), promise); messageId.recycle(); messageIdBuilder.recycle(); } ctx.flush(); }); return sentMessages; }
From source file:com.datatorrent.contrib.kafka.AbstractKafkaInputOperator.java
@Override public void emitTuples() { if (currentWindowId <= windowDataManager.getLargestCompletedWindow()) { return;// w w w .j ava2 s . co m } int count = consumer.messageSize() + ((pendingMessage != null) ? 1 : 0); if (maxTuplesPerWindow > 0) { count = Math.min(count, maxTuplesPerWindow - emitCount); } KafkaConsumer.KafkaMessage message = null; for (int i = 0; i < count; i++) { if (pendingMessage != null) { message = pendingMessage; pendingMessage = null; } else { message = consumer.pollMessage(); } // If the total size transmitted in the window will be exceeded don't transmit anymore messages in this window // Make an exception for the case when no message has been transmitted in the window and transmit at least one // message even if the condition is violated so that the processing doesn't get stuck if ((emitCount > 0) && ((maxTotalMsgSizePerWindow - emitTotalMsgSize) < message.msg.size())) { pendingMessage = message; break; } emitTuple(message); emitCount++; emitTotalMsgSize += message.msg.size(); offsetStats.put(message.kafkaPart, message.offSet); MutablePair<Long, Integer> offsetAndCount = currentWindowRecoveryState.get(message.kafkaPart); if (offsetAndCount == null) { currentWindowRecoveryState.put(message.kafkaPart, new MutablePair<Long, Integer>(message.offSet, 1)); } else { offsetAndCount.setRight(offsetAndCount.right + 1); } } }
From source file:bwem.map.MapImpl.java
public MutablePair<AreaId, AreaId> findNeighboringAreas(final WalkPosition p) { final MutablePair<AreaId, AreaId> result = new MutablePair<>(null, null); final WalkPosition[] deltas = { new WalkPosition(0, -1), new WalkPosition(-1, 0), new WalkPosition(+1, 0), new WalkPosition(0, +1) }; for (final WalkPosition delta : deltas) { if (getData().getMapData().isValid(p.add(delta))) { final AreaId areaId = getData().getMiniTile(p.add(delta), CheckMode.NO_CHECK).getAreaId(); if (areaId.intValue() > 0) { if (result.getLeft() == null) { result.setLeft(areaId); } else if (!result.getLeft().equals(areaId)) { if (result.getRight() == null || ((areaId.intValue() < result.getRight().intValue()))) { result.setRight(areaId); }// w ww . j ava 2 s . c o m } } } } return result; }
From source file:bwem.map.MapInitializerImpl.java
@Override public Altitude setAltitudesAndGetUpdatedHighestAltitude(final Altitude currentHighestAltitude, final TerrainData terrainData, final List<MutablePair<WalkPosition, Altitude>> deltasByAscendingAltitude, final List<MutablePair<WalkPosition, Altitude>> activeSeaSideList, final int altitudeScale) { Altitude updatedHighestAltitude = currentHighestAltitude; for (final MutablePair<WalkPosition, Altitude> deltaAltitude : deltasByAscendingAltitude) { final WalkPosition d = deltaAltitude.getLeft(); final Altitude altitude = deltaAltitude.getRight(); for (int i = 0; i < activeSeaSideList.size(); ++i) { final MutablePair<WalkPosition, Altitude> current = activeSeaSideList.get(i); if (altitude.intValue() - current.getRight().intValue() >= 2 * altitudeScale) { // optimization : once a seaside miniTile verifies this condition, // we can throw it away as it will not generate min altitudes anymore Utils.fastErase(activeSeaSideList, i--); } else { final WalkPosition[] deltas = { new WalkPosition(d.getX(), d.getY()), new WalkPosition(-d.getX(), d.getY()), new WalkPosition(d.getX(), -d.getY()), new WalkPosition(-d.getX(), -d.getY()), new WalkPosition(d.getY(), d.getX()), new WalkPosition(-d.getY(), d.getX()), new WalkPosition(d.getY(), -d.getX()), new WalkPosition(-d.getY(), -d.getX()) }; for (final WalkPosition delta : deltas) { final WalkPosition w = current.getLeft().add(delta); if (terrainData.getMapData().isValid(w)) { final MiniTile miniTile = ((TerrainDataInitializer) terrainData).getMiniTile_(w, CheckMode.NO_CHECK); if (((MiniTileImpl) miniTile).isAltitudeMissing()) { if (updatedHighestAltitude != null && updatedHighestAltitude.intValue() > altitude.intValue()) { throw new IllegalStateException(); }// w w w.j a v a 2s. co m updatedHighestAltitude = altitude; current.setRight(altitude); ((MiniTileImpl) miniTile).setAltitude(altitude); } } } } } } return updatedHighestAltitude; }
From source file:nl.b3p.viewer.config.services.ArcGISService.java
private void updateLayers(final ArcGISService update, final ArcGISFeatureSource linkedFS, final UpdateResult result) { /* This is a lot simpler than WMS, because layers always have an id * (name in WMS and our Layer object) *//*from ww w .jav a 2s.c o m*/ Map<String, Layer> updatedLayersById = new HashMap(); SimpleFeatureType ft; for (Layer updateLayer : update.layersById.values()) { MutablePair<Layer, UpdateResult.Status> layerStatus = result.getLayerStatus() .get(updateLayer.getName()); Layer updatedLayer = null; if (layerStatus == null) { // New layer ft = updateLayer.getFeatureType(); if (updateLayer.getFeatureType() != null) { if (linkedFS != null) { updateLayer.setFeatureType( linkedFS.addOrUpdateFeatureType(updateLayer.getName(), ft, new MutableBoolean())); } else { // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); } } result.getLayerStatus().put(updateLayer.getName(), new MutablePair(updateLayer, UpdateResult.Status.NEW)); updatedLayer = updateLayer; } else { assert (layerStatus.getRight() == UpdateResult.Status.MISSING); Layer old = layerStatus.getLeft(); old.setParent(null); old.update(updateLayer, additionalUpdatableDetails); layerStatus.setRight(UpdateResult.Status.UNMODIFIED); // Do not overwrite manually set feature source if (old.getFeatureType() == null || old.getFeatureType().getFeatureSource().getLinkedService() == this) { if (updateLayer.getFeatureType() == null) { // If was set before the old feature type will be removed // later when all orphan MISSING layers are removed if (old.getFeatureType() != null) { layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(null); } else { if (linkedFS != null) { MutableBoolean updated = new MutableBoolean(false); ft = linkedFS.addOrUpdateFeatureType(updateLayer.getName(), updateLayer.getFeatureType(), updated); if (old.getFeatureType() == null || updated.isTrue()) { layerStatus.setRight(UpdateResult.Status.UPDATED); } } else { ft = updateLayer.getFeatureType(); // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(ft); } } updatedLayer = old; } // will be filled in setLayerTree() updatedLayer.getChildren().clear(); updatedLayer.setParent(null); updatedLayer.setService(this); updatedLayersById.put(updateLayer.getName(), updatedLayer); } setLayerTree(getTopLayer(), updatedLayersById, update.childrenByLayerId); }
From source file:nl.b3p.viewer.config.services.ArcIMSService.java
private void updateLayers(final ArcIMSService update, final ArcXMLFeatureSource linkedFS, final UpdateResult result) { /* This is a lot simpler than WMS, because layers always have an id * (name in WMS and our Layer object) * //from w w w . ja va 2 s.c o m * And even simpler than ArcGIS because layers have no tree structure. */ getTopLayer().getChildren().clear(); SimpleFeatureType ft; for (Layer updateLayer : update.getTopLayer().getChildren()) { MutablePair<Layer, UpdateResult.Status> layerStatus = result.getLayerStatus() .get(updateLayer.getName()); Layer updatedLayer; if (layerStatus == null) { // New layer ft = updateLayer.getFeatureType(); if (updateLayer.getFeatureType() != null) { if (linkedFS != null) { linkedFS.addOrUpdateFeatureType(updateLayer.getName(), ft, new MutableBoolean()); } else { // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); } } result.getLayerStatus().put(updateLayer.getName(), new MutablePair(updateLayer, UpdateResult.Status.NEW)); updatedLayer = updateLayer; } else { assert (layerStatus.getRight() == UpdateResult.Status.MISSING); Layer old = layerStatus.getLeft(); old.update(updateLayer); layerStatus.setRight(UpdateResult.Status.UNMODIFIED); // Do not overwrite manually set feature source if (old.getFeatureType() == null || old.getFeatureType().getFeatureSource().getLinkedService() == this) { if (updateLayer.getFeatureType() == null) { // If was set before the old feature type will be removed // later when all orphan MISSING layers are removed if (old.getFeatureType() != null) { layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(null); } else { if (linkedFS != null) { MutableBoolean updated = new MutableBoolean(false); ft = linkedFS.addOrUpdateFeatureType(updateLayer.getName(), updateLayer.getFeatureType(), updated); if (old.getFeatureType() == null || updated.isTrue()) { layerStatus.setRight(UpdateResult.Status.UPDATED); } } else { ft = updateLayer.getFeatureType(); // New FeatureSource to be persisted ft.getFeatureSource().setLinkedService(this); layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(ft); } } updatedLayer = old; } assert updatedLayer.getChildren().isEmpty(); updatedLayer.setService(this); updatedLayer.setParent(getTopLayer()); getTopLayer().getChildren().add(updatedLayer); } }
From source file:nl.b3p.viewer.config.services.UpdatableFeatureSource.java
/** * Update this featuresource// w ww. j a v a 2 s . c o m */ public FeatureSourceUpdateResult update() throws Exception { final FeatureSourceUpdateResult result = new FeatureSourceUpdateResult(this); try { List<SimpleFeatureType> newFeatureTypes = this .createFeatureTypes(result.getWaitPageStatus().subtask("", 80)); //update and add the new featuretypes. for (SimpleFeatureType newFt : newFeatureTypes) { MutableBoolean updated = new MutableBoolean(); this.addOrUpdateFeatureType(newFt.getTypeName(), newFt, updated); MutablePair<SimpleFeatureType, UpdateResult.Status> ftResult = result.getFeatureTypeStatus() .get(newFt.getTypeName()); if (ftResult == null) { result.getFeatureTypeStatus().put(newFt.getTypeName(), new MutablePair(newFt, UpdateResult.Status.NEW)); } else { if (updated.isTrue()) { log.info("Feature type: " + newFt.getTypeName() + " updated"); ftResult.setRight(UpdateResult.Status.UPDATED); } else { ftResult.setRight(UpdateResult.Status.UNMODIFIED); } } } //remove featuretypes when not there Iterator<SimpleFeatureType> it = this.getFeatureTypes().iterator(); while (it.hasNext()) { SimpleFeatureType oldFt = it.next(); boolean stillExists = false; for (SimpleFeatureType newFt : newFeatureTypes) { if (newFt.getTypeName().equals(oldFt.getTypeName())) { stillExists = true; break; } } if (!stillExists) { it.remove(); } } result.setStatus(UpdateResult.Status.UPDATED); } catch (Exception e) { result.failedWithException(e); } return result; }
From source file:nl.b3p.viewer.config.services.WMSService.java
/** * Internal update method for layers. Update result.layerStatus() which * currently has all layers set to MISSING. New layers are set to NEW, with * a clone plucked from the updated service tree. Existing layers are set to * UNMODIFIED or UPDATED (Layer entities modified) * <p>//from www. ja va 2 s . com * Duplicate layers are not updated (will be removed later). * <p> * Grouping layers (no name) are ignored. */ private void updateLayers(final WMSService update, final Map<String, WFSFeatureSource> linkedFSesByURL, final Set<SimpleFeatureType> updatedFeatureTypes, final UpdateResult result) { final WMSService updatingWMSService = this; update.getTopLayer().accept(new Layer.Visitor() { @Override public boolean visit(Layer l) { if (l.getName() == null) { // Grouping layer only return true; } MutablePair<Layer, UpdateResult.Status> layerStatus = result.getLayerStatus().get(l.getName()); if (layerStatus == null) { // New layer, pluck a copy from the tree that will be made // persistent. // Plucking a clone is necessary because the children // and parent will be set on this instance later on and we // need the original children to traverse the updated service // tree while doing that l = l.pluckCopy(); result.getLayerStatus().put(l.getName(), new MutablePair(l, UpdateResult.Status.NEW)); if (l.getFeatureType() != null) { // We may already have an updated previously persistent // FeatureType / FeatureSource // New FeatureSources were added to the linkedFSesByURL // map in updateWFS() WFSFeatureSource fs = linkedFSesByURL.get(l.getFeatureType().getFeatureSource().getUrl()); l.setFeatureType(fs.getFeatureType(l.getFeatureType().getTypeName())); } } else { if (layerStatus.getRight() != UpdateResult.Status.MISSING) { // Already processed, ignore duplicate layer return true; } Layer old = layerStatus.getLeft(); // Pluck from old tree old.setParent(null); old.getChildren().clear(); // The layer properties are ignored for update status, only // its featuretype determines changed boolean old.update(l); layerStatus.setRight(UpdateResult.Status.UNMODIFIED); // Only update feature type if not manually set to feature // type of feature source not automatically created by loading // this service (has linkedService set to updatingWMSService) if (old.getFeatureType() == null || old.getFeatureType().getFeatureSource().getLinkedService() == updatingWMSService) { // FeatureType instance may be the same (already updated in // updateWFS(), or a new FeatureType (put in linkedFSesByURL // map by the same method) if (l.getFeatureType() != null) { WFSFeatureSource fs = linkedFSesByURL .get(l.getFeatureType().getFeatureSource().getUrl()); boolean wasNull = old.getFeatureType() == null; old.setFeatureType(fs.getFeatureType(l.getFeatureType().getTypeName())); if (wasNull || updatedFeatureTypes.contains(old.getFeatureType())) { layerStatus.setRight(UpdateResult.Status.UPDATED); } } else { if (old.getFeatureType() != null) { layerStatus.setRight(UpdateResult.Status.UPDATED); } old.setFeatureType(null); } } } return true; } }); }
From source file:nl.basjes.parse.useragent.servlet.ParseService.java
private Pair<String, String> prefixSplitter(String input) { MutablePair<String, String> result = new MutablePair<>("", input); if (input.startsWith("Device")) { result.setLeft("Device"); result.setRight(input.replaceFirst("Device", "")); } else if (input.startsWith("OperatingSystem")) { result.setLeft("Operating System"); result.setRight(input.replaceFirst("OperatingSystem", "")); } else if (input.startsWith("LayoutEngine")) { result.setLeft("Layout Engine"); result.setRight(input.replaceFirst("LayoutEngine", "")); } else if (input.startsWith("Agent")) { result.setLeft("Agent"); result.setRight(input.replaceFirst("Agent", "")); }/*ww w. jav a 2s . c o m*/ return result; }
From source file:org.apache.apex.malhar.contrib.kinesis.AbstractKinesisInputOperator.java
/** * Implement InputOperator Interface.//w ww .j a va 2 s .co m */ @Override public void emitTuples() { if (currentWindowId <= windowDataManager.getLargestCompletedWindow()) { return; } int count = consumer.getQueueSize(); if (maxTuplesPerWindow > 0) { count = Math.min(count, maxTuplesPerWindow - emitCount); } for (int i = 0; i < count; i++) { Pair<String, Record> data = consumer.pollRecord(); String shardId = data.getFirst(); String recordId = data.getSecond().getSequenceNumber(); emitTuple(data); MutablePair<String, Integer> shardOffsetAndCount = currentWindowRecoveryState.get(shardId); if (shardOffsetAndCount == null) { currentWindowRecoveryState.put(shardId, new MutablePair<String, Integer>(recordId, 1)); } else { shardOffsetAndCount.setRight(shardOffsetAndCount.right + 1); } shardPosition.put(shardId, recordId); } emitCount += count; }