org.apache.commons.lang3.tuple.MutablePair Java Examples

The following examples show how to use org.apache.commons.lang3.tuple.MutablePair. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PartialCallGraph.java    From fasten with Apache License 2.0 6 votes vote down vote up
/**
 * Given a call graph and a CHA it creates a map of external calls and their call type. This map
 * indicates the source methods by their unique within artifact id existing in the cha, target
 * methods by their {@link FastenURI}, and a map that indicates the call type.
 * @param cg  {@link ComputedCallGraph}
 * @param cha A Map of {@link ObjectType} and {@link RevisionCallGraph.Type}
 * @return A map that each each entry of it is a {@link Pair} of source method's id, and target
 *     method's {@link FastenURI} as key and a map that shows call types as value. call types
 *     map's key is the name of JVM call type and the value is number of invocation by this call
 *     type for this specific edge.
 */
private Map<Pair<Integer, FastenURI>, Map<String, String>> getExternalCalls(
    final ComputedCallGraph cg,
    final Map<ObjectType, OPALType> cha) {
    List<UnresolvedMethodCall> v = new ArrayList<>();

    final var externlCalls = cg.unresolvedMethodCalls();
    final Map<Pair<Integer, FastenURI>, Map<String, String>> result = new HashMap<>();

    for (final var externalCall : JavaConverters.asJavaIterable(externlCalls)) {

        final var call = new MutablePair<>(
            cha.get(externalCall.caller().declaringClassFile().thisType()).getMethods()
                .get(externalCall.caller()),
            getTargetURI(externalCall));
        final var typeOfCall =
            externalCall.caller().instructionsOption().get()[externalCall.pc()].mnemonic();
        putCall(result, call, typeOfCall);
    }

    return result;
}
 
Example #2
Source File: CommentsNodeImpl.java    From Diorite with MIT License 6 votes vote down vote up
@Override
public void trim()
{
    for (Iterator<Entry<String, MutablePair<String, CommentsNodeImpl>>> iterator = this.dataMap.entrySet().iterator(); iterator.hasNext(); )
    {
        Entry<String, MutablePair<String, CommentsNodeImpl>> entry = iterator.next();
        MutablePair<String, CommentsNodeImpl> value = entry.getValue();
        CommentsNodeImpl right = value.getRight();
        if (right != null)
        {
            right.trim();
        }
        if (((right == null) || right.dataMap.isEmpty()) && (value.getLeft() == null))
        {
            iterator.remove();
            continue;
        }
        if (right == null)
        {
            continue;
        }
        right.trim();
    }
}
 
Example #3
Source File: WidgetOutputOperator.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
public void process(HashMap<String, Number> pieNumbers)
{
  @SuppressWarnings("unchecked")
  HashMap<String, Object>[] result = (HashMap<String, Object>[])Array.newInstance(HashMap.class, pieNumbers.size());

  int j = 0;
  for (Entry<String, Number> e : pieNumbers.entrySet()) {
    result[j] = new HashMap<>();
    result[j].put("label", e.getKey());
    result[j++].put("value", e.getValue());
  }
  if (operator.isWebSocketConnected) {
    HashMap<String, Object> schemaObj = new HashMap<>();
    schemaObj.put("type", "piechart");
    schemaObj.put("n", operator.nInPie);
    operator.wsoo.input.process(new MutablePair<String, Object>(operator.getFullTopic(operator.pieChartTopic, schemaObj), result));
  } else {
    operator.coo.input.process(pieNumbers);
  }
}
 
Example #4
Source File: CommentsNodeImpl.java    From Diorite with MIT License 6 votes vote down vote up
@Override
@Nullable
public String getComment(String path)
{
    MutablePair<String, CommentsNodeImpl> nodePair = this.dataMap.get(path);
    if (nodePair != null)
    {
        String comment = nodePair.getLeft();
        if (comment != null)
        {
            return comment;
        }
    }
    MutablePair<String, CommentsNodeImpl> anyNodePair = this.dataMap.get(ANY);
    if (anyNodePair != null)
    {
        return anyNodePair.getKey();
    }
    return null;
}
 
Example #5
Source File: WidgetOutputOperator.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
public void process(TimeSeriesData[] tuple)
{
  @SuppressWarnings({"unchecked", "rawtypes"})
  HashMap<String, Number>[] timeseriesMapData = new HashMap[tuple.length];
  int i = 0;
  for (TimeSeriesData data : tuple) {
    HashMap<String, Number> timeseriesMap = Maps.newHashMapWithExpectedSize(2);
    timeseriesMap.put("timestamp", data.time);
    timeseriesMap.put("value", data.data);
    timeseriesMapData[i++] = timeseriesMap;
  }

  if (operator.isWebSocketConnected) {
    HashMap<String, Object> schemaObj = new HashMap<>();
    schemaObj.put("type", "timeseries");
    schemaObj.put("minValue", operator.timeSeriesMin);
    schemaObj.put("maxValue", operator.timeSeriesMax);
    operator.wsoo.input.process(new MutablePair<String, Object>(operator.getFullTopic( operator.timeSeriesTopic, schemaObj), timeseriesMapData));
  } else {
    operator.coo.input.process(tuple);
  }
}
 
Example #6
Source File: CommentsNodeImpl.java    From Diorite with MIT License 6 votes vote down vote up
@Override
public CommentsNodeImpl getNode(String path)
{
    MutablePair<String, CommentsNodeImpl> nodePair = this.dataMap.get(path);
    CommentsNodeImpl node = (nodePair == null) ? null : nodePair.getRight();
    if (node == null)
    {
        MutablePair<String, CommentsNodeImpl> anyNodePair = this.dataMap.get(ANY);
        node = (anyNodePair == null) ? null : anyNodePair.getRight();
        if (node == null)
        {
            CommentsNodeImpl commentsNode = new CommentsNodeImpl(this);
            if (nodePair != null)
            {
                nodePair.setRight(commentsNode);
            }
            else
            {
                this.dataMap.put(path, new MutablePair<>(null, commentsNode));
            }
            return commentsNode;
        }
        return node;
    }
    return node;
}
 
Example #7
Source File: ReadUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Find the 0-based index within a read base array corresponding to a given 1-based position in the reference, along with the cigar operator of
 * the element containing that base.  If the reference coordinate occurs within a deletion, the first index after the deletion is returned.
 * Note that this treats soft-clipped bases as if they align with the reference, which is useful for hard-clipping reads with soft clips.
 *
 * @param alignmentStart        The soft start of the read on the reference
 * @param cigar                 The read's cigar
 * @param refCoord              The target reference coordinate
 * @return                      If the reference coordinate occurs before the read start or after the read end {@code CLIPPING_GOAL_NOT_REACHED};
 *                              if the reference coordinate falls within an alignment block of the read's cigar, the corresponding read coordinate;
 *                              if the reference coordinate falls within a deletion, the first read coordinate after the deletion.  Note: if the last cigar element is
 *                              a deletion (which isn't meaningful), it returns {@code CLIPPING_GOAL_NOT_REACHED}.
 */
public static Pair<Integer, CigarOperator> getReadIndexForReferenceCoordinate(final int alignmentStart, final Cigar cigar, final int refCoord) {
    if (refCoord < alignmentStart) {
        return new MutablePair<>(READ_INDEX_NOT_FOUND, null);
    }
    int firstReadPosOfElement = 0;              //inclusive
    int firstRefPosOfElement = alignmentStart;  //inclusive
    int lastReadPosOfElement = 0;               //exclusive
    int lastRefPosOfElement = alignmentStart;   //exclusive

    // advance forward through all the cigar elements until we bracket the reference coordinate
    for (final CigarElement element : cigar) {
        final CigarOperator operator = element.getOperator();
        firstReadPosOfElement = lastReadPosOfElement;
        firstRefPosOfElement = lastRefPosOfElement;
        lastReadPosOfElement += operator.consumesReadBases() ? element.getLength() : 0;
        lastRefPosOfElement += operator.consumesReferenceBases() || operator == CigarOperator.S ? element.getLength() : 0;

        if (firstRefPosOfElement <= refCoord && refCoord < lastRefPosOfElement) {   // refCoord falls within this cigar element
            final int readPosAtRefCoord = firstReadPosOfElement + (operator.consumesReadBases() ? ( refCoord - firstRefPosOfElement) : 0);
            return Pair.of(readPosAtRefCoord, operator);
        }
    }
    return new MutablePair<>(READ_INDEX_NOT_FOUND, null);
}
 
Example #8
Source File: RevisionCallGraph.java    From fasten with Apache License 2.0 6 votes vote down vote up
/**
 * Creates {@link Graph} for the given JSONObject.
 * @param graph JSONObject of a graph including its internal calls and external calls.
 */
public Graph(final JSONObject graph) {

    final var internalCalls = graph.getJSONArray("internalCalls");
    this.internalCalls = new ArrayList<>();
    final int numberOfArcs = internalCalls.length();
    for (int i = 0; i < numberOfArcs; i++) {
        final var pair = internalCalls.getJSONArray(i);
        this.internalCalls.add(Arrays.asList((Integer) pair.get(0), (Integer) pair.get(1)));
    }

    final var externalCalls = graph.getJSONArray("externalCalls");
    this.externalCalls = new HashMap<>();
    final int numberOfExternalArcs = externalCalls.length();
    for (int i = 0; i < numberOfExternalArcs; i++) {
        final var call = externalCalls.getJSONArray(i);
        final var callTypeJson = call.getJSONObject(2);
        final Map<String, String> callType = new HashMap<>();
        for (final var type : callTypeJson.keySet()) {
            final String number = callTypeJson.getString(type);
            callType.put(type, number);
        }
        this.externalCalls.put(new MutablePair<>(Integer.parseInt(call.getString(0)),
            FastenURI.create(call.getString(1))), callType);
    }
}
 
Example #9
Source File: ResourceRequestHandler.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Issue requests to AM RM Client again if previous container requests expired and were not allocated by Yarn
 * @param amRmClient
 * @param requestedResources
 * @param loopCounter
 * @param resourceRequestor
 * @param containerRequests
 * @param removedContainerRequests
 */
public void reissueContainerRequests(AMRMClient<ContainerRequest> amRmClient, Map<StreamingContainerAgent.ContainerStartRequest, MutablePair<Integer, ContainerRequest>> requestedResources, int loopCounter, ResourceRequestHandler resourceRequestor, List<ContainerRequest> containerRequests, List<ContainerRequest> removedContainerRequests)
{
  if (!requestedResources.isEmpty()) {
    for (Map.Entry<StreamingContainerAgent.ContainerStartRequest, MutablePair<Integer, ContainerRequest>> entry : requestedResources.entrySet()) {
      /*
       * Create container requests again if pending requests were not allocated by Yarn till timeout.
       */
      if ((loopCounter - entry.getValue().getKey()) > NUMBER_MISSED_HEARTBEATS) {
        StreamingContainerAgent.ContainerStartRequest csr = entry.getKey();
        LOG.debug("Request for container {} timed out. Re-requesting container", csr.container);
        removedContainerRequests.add(entry.getValue().getRight());
        ContainerRequest cr = resourceRequestor.createContainerRequest(csr, false);
        entry.getValue().setLeft(loopCounter);
        entry.getValue().setRight(cr);
        containerRequests.add(cr);
      }
    }
  }
}
 
Example #10
Source File: DeltaFIFO.java    From java with Apache License 2.0 6 votes vote down vote up
/**
 * List list.
 *
 * @return the list
 */
public List<Deque<MutablePair<DeltaType, KubernetesObject>>> list() {
  lock.readLock().lock();
  List<Deque<MutablePair<DeltaType, KubernetesObject>>> objects = new ArrayList<>();
  try {
    // TODO: make a generic deep copy utility
    for (Map.Entry<String, Deque<MutablePair<DeltaType, KubernetesObject>>> entry :
        items.entrySet()) {
      Deque<MutablePair<DeltaType, KubernetesObject>> copiedDeltas =
          new LinkedList<>(entry.getValue());
      objects.add(copiedDeltas);
    }
  } finally {
    lock.readLock().unlock();
  }
  return objects;
}
 
Example #11
Source File: OperatorUtil.java    From doctorkafka with Apache License 2.0 6 votes vote down vote up
public static MutablePair<Long, Long> getProcNetDevStats() throws Exception {
  ProcessBuilder ps = new ProcessBuilder("cat", "/proc/net/dev");
  Process pr = ps.start();
  pr.waitFor();

  BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
  String line;
  int counter = 0;
  long receivedBytes = 0;
  long outBytes = 0;

  while ((line = in.readLine()) != null) {
    System.out.println(counter + ": " + line);
    if (line.contains("eth0")) {
      String[] strs = line.split(" ");
      receivedBytes = Long.parseLong(strs[3]);
      outBytes = Long.parseLong(strs[41]);
      System.out.println(" inBytes = " + receivedBytes + "  outBytes = " + outBytes);
    }
    counter++;
  }
  in.close();

  MutablePair<Long, Long> result = new MutablePair<>(receivedBytes, outBytes);
  return result;
}
 
Example #12
Source File: AbstractKinesisInputOperator.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
/**
 * Implement InputOperator Interface.
 */
@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;
}
 
Example #13
Source File: GATKVariantContextUtils.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static Pair<int[],byte[]> getNumTandemRepeatUnits(final byte[] refBases, final byte[] altBases, final byte[] remainingRefContext) {
     /* we can't exactly apply same logic as in basesAreRepeated() to compute tandem unit and number of repeated units.
       Consider case where ref =ATATAT and we have an insertion of ATAT. Natural description is (AT)3 -> (AT)2.
     */

    byte[] longB;
    // find first repeat unit based on either ref or alt, whichever is longer
    if (altBases.length > refBases.length)
        longB = altBases;
    else
        longB = refBases;

    // see if non-null allele (either ref or alt, whichever is longer) can be decomposed into several identical tandem units
    // for example, -*,CACA needs to first be decomposed into (CA)2
    final int repeatUnitLength = findRepeatedSubstring(longB);
    final byte[] repeatUnit = Arrays.copyOf(longB, repeatUnitLength);

    final int[] repetitionCount = new int[2];
    // look for repetitions forward on the ref bases (i.e. starting at beginning of ref bases)
    int repetitionsInRef = findNumberOfRepetitions(repeatUnit, refBases, true);
    repetitionCount[0] = findNumberOfRepetitions(repeatUnit, ArrayUtils.addAll(refBases, remainingRefContext), true)-repetitionsInRef;
    repetitionCount[1] = findNumberOfRepetitions(repeatUnit, ArrayUtils.addAll(altBases, remainingRefContext), true)-repetitionsInRef;

    return new MutablePair<>(repetitionCount, repeatUnit);

}
 
Example #14
Source File: SharedVertexSequenceSplitter.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Return the longest suffix of bases shared among all provided vertices
 *
 * For example, if the vertices have sequences AC, CC, and ATC, this would return
 * a single C.  However, for ACC and TCC this would return CC.  And for AC and TG this
 * would return null;
 *
 * @param middleVertices a non-empty set of vertices
 * @return
 */
@VisibleForTesting
static Pair<SeqVertex, SeqVertex> commonPrefixAndSuffixOfVertices(final Collection<SeqVertex> middleVertices) {
    final List<byte[]> kmers = new ArrayList<>(middleVertices.size());

    int min = Integer.MAX_VALUE;
    for ( final SeqVertex v : middleVertices ) {
        kmers.add(v.getSequence());
        min = Math.min(min, v.getSequence().length);
    }

    final int prefixLen = GraphUtils.commonMaximumPrefixLength(kmers);
    final int suffixLen = GraphUtils.commonMaximumSuffixLength(kmers, min - prefixLen);

    final byte[] kmer = kmers.get(0);
    final byte[] prefix = Arrays.copyOfRange(kmer, 0, prefixLen);
    final byte[] suffix = Arrays.copyOfRange(kmer, kmer.length - suffixLen, kmer.length);
    return new MutablePair<>(new SeqVertex(prefix), new SeqVertex(suffix));
}
 
Example #15
Source File: SchemaTypeWizardBuilder.java    From syncope with Apache License 2.0 6 votes vote down vote up
@Override
protected Serializable onApplyInternal(final SchemaTO modelObject) {
    modelObject.getLabels().clear();
    modelObject.getLabels().putAll(translations.getObject().stream().
            filter(Objects::nonNull).
            filter(translation -> translation.getKey() != null).
            filter(translation -> translation.getValue() != null).
            collect(Collectors.toMap(MutablePair::getKey, MutablePair::getValue)));

    if (getOriginalItem() == null || StringUtils.isBlank(getOriginalItem().getKey())) {
        SchemaRestClient.create(schemaType, modelObject);
    } else {
        SchemaRestClient.update(schemaType, modelObject);
    }

    return null;
}
 
Example #16
Source File: DeltaFIFOTest.java    From java with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeltaFIFOResync() {
  V1Pod foo1 = new V1Pod().metadata(new V1ObjectMeta().name("foo1").namespace("default"));
  Cache cache = new Cache();
  DeltaFIFO deltaFIFO = new DeltaFIFO(Caches::deletionHandlingMetaNamespaceKeyFunc, cache);

  // sync after add
  cache.add(foo1);
  deltaFIFO.resync();

  Deque<MutablePair<DeltaFIFO.DeltaType, KubernetesObject>> deltas =
      deltaFIFO.getItems().get(Caches.deletionHandlingMetaNamespaceKeyFunc(foo1));

  assertEquals(1, deltas.size());
  assertEquals(foo1, deltas.peekLast().getRight());
  assertEquals(DeltaFIFO.DeltaType.Sync, deltas.peekLast().getLeft());
}
 
Example #17
Source File: VoxelShapeCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Cuboid6 getCuboid(VoxelShape shape) {
    MutablePair<AxisAlignedBB, Cuboid6> entry = getReverse(shape);
    if (entry.getRight() == null) {
        entry.setRight(new Cuboid6(// I hope this is okay, don't want to rely on AABB cache.
                shape.getStart(Direction.Axis.X), shape.getStart(Direction.Axis.Y), shape.getStart(Direction.Axis.Z),//
                shape.getEnd(Direction.Axis.X), shape.getEnd(Direction.Axis.Y), shape.getEnd(Direction.Axis.Z)//
        ));
    }
    return entry.getRight();
}
 
Example #18
Source File: ParameterHolder.java    From mnemonic with Apache License 2.0 5 votes vote down vote up
public ParameterHolder(A n, DurableType[] d, EntityFactoryProxy[] e) {
    this.allocator = n;
    this.autoReclaim = true;
    this.handler = 0;
    this.dpt = new MutablePair<DurableType[], EntityFactoryProxy[]>(d, e);
    this.rctx = null;
}
 
Example #19
Source File: ParameterHolder.java    From mnemonic with Apache License 2.0 5 votes vote down vote up
public ParameterHolder(A n) {
    this.allocator = n;
    this.autoReclaim = true;
    this.handler = 0;
    this.dpt = new MutablePair<DurableType[], EntityFactoryProxy[]>(new DurableType[]{}, null);
    this.rctx = null;
}
 
Example #20
Source File: VoxelShapeCache.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static MutablePair<AxisAlignedBB, Cuboid6> getReverse(VoxelShape shape) {
    MutablePair<AxisAlignedBB, Cuboid6> entry = shapeToBBCuboid.getIfPresent(shape);
    if (entry == null) {
        entry = new MutablePair<>();
        shapeToBBCuboid.put(shape, entry);
    }
    return entry;
}
 
Example #21
Source File: ApacheCommonsPairUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMutablePair_whenGetValue_shouldPass() {
    int key = 5;
    String value = "Five";

    MutablePair<Integer, String> mutablePair = new MutablePair<>(key, value);
    Assert.assertTrue(mutablePair.getKey() == key);
    Assert.assertEquals(mutablePair.getValue(), value);
}
 
Example #22
Source File: AppDataSingleSchemaDimensionStoreHDHTUpdateWithList.java    From examples with Apache License 2.0 5 votes vote down vote up
public void addAggregatorsInfo(int aggregatorID, int dimensionDescriptorID)
{
  if (aggregatorsInfo == null) {
    aggregatorsInfo = Lists.newArrayList();
  }
  aggregatorsInfo.add(new MutablePair<Integer, Integer>(aggregatorID, dimensionDescriptorID));
}
 
Example #23
Source File: OperatorUtil.java    From doctorkafka with Apache License 2.0 5 votes vote down vote up
public static MutablePair<Double, Double> getSysNetworkTraffic(long samplingWindowInMs)
    throws Exception {
  MutablePair<Long, Long> startNumbers = getProcNetDevStats();
  Thread.sleep(samplingWindowInMs);
  MutablePair<Long, Long> endNumbers = getProcNetDevStats();

  double inRate = (endNumbers.getKey() - startNumbers.getKey()) * 1000.0 / samplingWindowInMs;
  double outRate =
      (endNumbers.getValue() - startNumbers.getValue()) * 1000.0 / samplingWindowInMs;
  MutablePair<Double, Double> result = new MutablePair<>(inRate, outRate);
  return result;
}
 
Example #24
Source File: CommentsNodeImpl.java    From Diorite with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
Map<String, MutablePair<String, ?>> buildMap()
{
    Map<String, MutablePair<String, ?>> resultMap = new LinkedHashMap<>(this.dataMap.size());
    for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : this.dataMap.entrySet())
    {
        MutablePair<String, CommentsNodeImpl> value = entry.getValue();
        CommentsNodeImpl right = value.getRight();
        String left = value.getLeft();
        if ((right == null) && (left == null))
        {
            continue;
        }
        Map<String, MutablePair<String, ?>> rightMap = null;
        if (right != null)
        {
            rightMap = right.buildMap();
            if (rightMap.isEmpty())
            {
                rightMap = null;
                if (left == null)
                {
                    continue;
                }
            }
        }
        resultMap.put(entry.getKey(), new MutablePair<>(left, rightMap));
    }
    return resultMap;
}
 
Example #25
Source File: CommentsNodeImpl.java    From Diorite with MIT License 5 votes vote down vote up
@Override
public void join(CommentsNode toJoin_)
{
    if (toJoin_ instanceof EmptyCommentsNode)
    {
        return;
    }
    if (! (toJoin_ instanceof CommentsNodeImpl))
    {
        throw new IllegalArgumentException("Can't join to unknown node type.");
    }
    CommentsNodeImpl toJoin = (CommentsNodeImpl) toJoin_;
    for (Entry<String, MutablePair<String, CommentsNodeImpl>> entry : toJoin.dataMap.entrySet())
    {
        String nodeKey = entry.getKey();
        MutablePair<String, CommentsNodeImpl> pair = entry.getValue();
        String nodeComment = pair.getLeft();
        CommentsNodeImpl subNode = pair.getRight();

        if (nodeComment != null)
        {
            this.setComment(nodeKey, nodeComment);
        }
        if (subNode != null)
        {
            this.join(nodeKey, subNode);
        }
    }
}
 
Example #26
Source File: EventAggregator.java    From java with Apache License 2.0 5 votes vote down vote up
public synchronized MutablePair<V1Event, String> aggregate(V1Event event) {
  DateTime now = DateTime.now();

  MutablePair<String, String> aggregatedKeys = keyFunc.apply(event);
  String aggregatedKey = aggregatedKeys.getLeft();
  String localKey = aggregatedKeys.getRight();

  AggregatedRecord record;
  try {
    record = this.spammingCache.get(aggregatedKey, AggregatedRecord::new);
  } catch (ExecutionException e) {
    throw new IllegalStateException(e);
  }
  record.lastTimestamp = now;
  record.localKeys.add(localKey);

  if (record.localKeys.size() < this.maxEvents) {
    this.spammingCache.put(aggregatedKey, record);
    return new MutablePair<>(event, EventUtils.getEventKey(event));
  }
  record.localKeys.remove(record.localKeys.stream().findAny().get()); // remove any keys
  V1Event aggregatedEvent =
      new V1EventBuilder(event)
          .withMetadata(
              new V1ObjectMetaBuilder()
                  .withName(EventUtils.generateName(event.getInvolvedObject().getName(), now))
                  .withNamespace(event.getInvolvedObject().getNamespace())
                  .build())
          .withCount(1)
          .withFirstTimestamp(now)
          .withLastTimestamp(now)
          .withMessage(this.messageFunc.apply(event))
          .build();
  this.spammingCache.put(aggregatedKey, record);
  return new MutablePair<>(aggregatedEvent, aggregatedKey);
}
 
Example #27
Source File: AbstractKafkaInputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
public void emitTuples()
{
  if (currentWindowId <= windowDataManager.getLargestCompletedWindow()) {
    return;
  }
  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);
    }
  }
}
 
Example #28
Source File: ApacheCommonsPairUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMutablePair_whenSetValue_shouldPass() {
    int key = 6;
    String value = "Six";
    String newValue = "New Six";

    MutablePair<Integer, String> mutablePair = new MutablePair<>(key, value);
    Assert.assertTrue(mutablePair.getKey() == key);
    Assert.assertEquals(mutablePair.getValue(), value);
    mutablePair.setValue(newValue);
    Assert.assertEquals(mutablePair.getValue(), newValue);
}
 
Example #29
Source File: CommentsWriter.java    From Diorite with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void write(Map<String, MutablePair<String, ?>> map) throws IOException
{
    this.updateIndent(true);
    int keys = map.entrySet().size();
    int k = 0;
    for (Entry<String, MutablePair<String, ?>> entry : map.entrySet())
    {
        k += 1;
        MutablePair<String, ?> pair = entry.getValue();
        String comment = pair.getLeft();
        Map<String, MutablePair<String, ?>> rightMap = (Map<String, MutablePair<String, ?>>) pair.getRight();

        int rightKeys = (rightMap == null) ? 0 : rightMap.size();
        boolean newLine = keys > 3;
        if (comment != null)
        {
            this.writeComment(comment);
        }

        String key = entry.getKey();
        this.writeKey(key);
        if (rightMap != null)
        {
            this.write(rightMap);
        }
        if (newLine)
        {
            this.writeNewLine(false);
        }
    }
    this.writeNewLine(false);
    this.updateIndent(false);
}
 
Example #30
Source File: BlacklistBasedResourceRequestHandler.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private void recreateContainerRequest(Map<StreamingContainerAgent.ContainerStartRequest, MutablePair<Integer, ContainerRequest>> requestedResources, int loopCounter, ResourceRequestHandler resourceRequestor, List<ContainerRequest> removedContainerRequests)
{
  for (Map.Entry<StreamingContainerAgent.ContainerStartRequest, MutablePair<Integer, ContainerRequest>> entry : requestedResources.entrySet()) {
    if ((loopCounter - entry.getValue().getKey()) > NUMBER_MISSED_HEARTBEATS) {
      StreamingContainerAgent.ContainerStartRequest csr = entry.getKey();
      removedContainerRequests.add(entry.getValue().getRight());
      ContainerRequest cr = resourceRequestor.createContainerRequest(csr, false);
      if (cr.getNodes() != null && !cr.getNodes().isEmpty()) {
        addHostSpecificRequest(csr, cr);
      } else {
        otherContainerRequests.put(cr, csr);
      }
    }
  }
}