org.apache.commons.lang.mutable.MutableInt Java Examples

The following examples show how to use org.apache.commons.lang.mutable.MutableInt. 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: FlagMaker.java    From datawave with Apache License 2.0 7 votes vote down vote up
/**
 * Determine the number of unprocessed flag files in the flag directory
 * 
 * @param fc
 * @return the flag found for this ingest pool
 */
private int countFlagFileBacklog(final FlagDataTypeConfig fc) {
    final MutableInt fileCounter = new MutableInt(0);
    final FileFilter fileFilter = new WildcardFileFilter("*_" + fc.getIngestPool() + "_" + fc.getDataName() + "_*.flag");
    final FileVisitor<java.nio.file.Path> visitor = new SimpleFileVisitor<java.nio.file.Path>() {
        
        @Override
        public FileVisitResult visitFile(java.nio.file.Path path, BasicFileAttributes attrs) throws IOException {
            if (fileFilter.accept(path.toFile())) {
                fileCounter.increment();
            }
            return super.visitFile(path, attrs);
        }
    };
    try {
        Files.walkFileTree(Paths.get(fmc.getFlagFileDirectory()), visitor);
    } catch (IOException e) {
        // unable to get a flag count....
        log.error("Unable to get flag file count", e);
        return -1;
    }
    return fileCounter.intValue();
}
 
Example #2
Source File: RequestUtils.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
private static FilterQuery traverseFilterQueryAndPopulateMap(FilterQueryTree tree,
    Map<Integer, FilterQuery> filterQueryMap, MutableInt currentId) {
  int currentNodeId = currentId.intValue();
  currentId.increment();

  final List<Integer> f = new ArrayList<>();
  if (null != tree.getChildren()) {
    for (final FilterQueryTree c : tree.getChildren()) {
      final FilterQuery q = traverseFilterQueryAndPopulateMap(c, filterQueryMap, currentId);
      int childNodeId = q.getId();
      f.add(childNodeId);
      filterQueryMap.put(childNodeId, q);
    }
  }

  FilterQuery query = new FilterQuery();
  query.setColumn(tree.getColumn());
  query.setId(currentNodeId);
  query.setNestedFilterQueryIds(f);
  query.setOperator(tree.getOperator());
  query.setValue(tree.getValue());
  return query;
}
 
Example #3
Source File: TimelineMetricClusterAggregatorSecond.java    From ambari-metrics with Apache License 2.0 6 votes vote down vote up
protected void processLiveAppCountMetrics(Map<TimelineClusterMetric, MetricClusterAggregate> aggregateClusterMetrics,
                                          Map<String, MutableInt> appHostsCount, long timestamp) {

  for (Map.Entry<String, MutableInt> appHostsEntry : appHostsCount.entrySet()) {
    TimelineClusterMetric timelineClusterMetric = new TimelineClusterMetric(
      liveHostsMetricName, appHostsEntry.getKey(), null, timestamp);

    Integer numOfHosts = appHostsEntry.getValue().intValue();

    MetricClusterAggregate metricClusterAggregate = new MetricClusterAggregate(
      (double) numOfHosts, 1, null, (double) numOfHosts, (double) numOfHosts);

    metadataManagerInstance.getUuid(timelineClusterMetric, true);
    aggregateClusterMetrics.put(timelineClusterMetric, metricClusterAggregate);
  }
}
 
Example #4
Source File: AccumuloConnectionPool.java    From datawave with Apache License 2.0 6 votes vote down vote up
public List<Map<String,String>> getConnectionPoolStats(MutableInt maxTotal, MutableInt numActive, MutableInt maxIdle, MutableInt numIdle,
                MutableInt numWaiting) {
    
    ArrayList<Map<String,String>> t = new ArrayList<>();
    // no changes to underlying values while collecting metrics
    synchronized (connectorToTrackingMapMap) {
        // no changes to underlying values while collecting metrics
        synchronized (threadToTrackingMapMap) {
            // synchronize this last to prevent race condition for this lock underlying super type
            synchronized (this) {
                if (!threadToTrackingMapMap.isEmpty()) {
                    t.addAll(Collections.unmodifiableCollection(threadToTrackingMapMap.values()));
                }
                if (!connectorToTrackingMapMap.isEmpty()) {
                    t.addAll(Collections.unmodifiableCollection(connectorToTrackingMapMap.values()));
                }
                maxTotal.setValue(getMaxTotal());
                numActive.setValue(getNumActive());
                maxIdle.setValue(getMaxIdle());
                numIdle.setValue(getNumIdle());
                numWaiting.setValue(getNumWaiters());
            }
        }
    }
    return Collections.unmodifiableList(t);
}
 
Example #5
Source File: AccumuloConnectionFactoryBean.java    From datawave with Apache License 2.0 6 votes vote down vote up
@PermitAll
@JmxManaged
public int getConnectionUsagePercent() {
    double maxPercentage = 0.0;
    for (Entry<String,Map<Priority,AccumuloConnectionPool>> entry : pools.entrySet()) {
        for (Entry<Priority,AccumuloConnectionPool> poolEntry : entry.getValue().entrySet()) {
            // Don't include ADMIN priority connections when computing a usage percentage
            if (Priority.ADMIN.equals(poolEntry.getKey()))
                continue;
            
            MutableInt maxActive = new MutableInt();
            MutableInt numActive = new MutableInt();
            MutableInt numWaiting = new MutableInt();
            MutableInt unused = new MutableInt();
            poolEntry.getValue().getConnectionPoolStats(maxActive, numActive, unused, unused, numWaiting);
            
            double percentage = (numActive.doubleValue() + numWaiting.doubleValue()) / maxActive.doubleValue();
            if (percentage > maxPercentage) {
                maxPercentage = percentage;
            }
        }
    }
    return (int) (maxPercentage * 100);
}
 
Example #6
Source File: DiffHistoryDataState.java    From zeno with Apache License 2.0 6 votes vote down vote up
private <T> Map<Object, List<T>> groupObjectsByKey(FastBlobTypeDeserializationState<T> deserializationState, TypeDiffInstruction<T> instruction, Map<Object, MutableInt> countsByKey) {
    Map<Object, List<T>> groupsByKey = new HashMap<Object, List<T>>(countsByKey.size());

    for (T obj : deserializationState) {
        Object key = instruction.getKeyFromObject(obj);
        List<T> groupList = groupsByKey.get(key);
        if (groupList == null) {
            int count = countsByKey.get(key).intValue();
            groupList = new ArrayList<T>(count);
            groupsByKey.put(key, groupList);
        }

        groupList.add(obj);
    }
    return groupsByKey;
}
 
Example #7
Source File: FieldIndexCountingIteratorPerVisibility.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Given a Key to consume, update any necessary counters etc.
 *
 * @param key
 */
private void consume(Key key) {
    
    if (log.isTraceEnabled()) {
        log.trace("consume, key: " + key);
    }
    
    // update the visibility set
    MutableInt counter = this.currentVisibilityCounts.get(key.getColumnVisibility());
    if (counter == null) {
        this.currentVisibilityCounts.put(key.getColumnVisibility(), new MutableInt(1));
    } else {
        counter.increment();
    }
    
    // update current count
    this.count += 1;
    
    // set most recent timestamp
    this.maxTimeStamp = (this.maxTimeStamp > key.getTimestamp()) ? maxTimeStamp : key.getTimestamp();
}
 
Example #8
Source File: ReaderTextCSV.java    From systemds with Apache License 2.0 6 votes vote down vote up
@Override
public MatrixBlock readMatrixFromInputStream(InputStream is, long rlen, long clen, int blen, long estnnz) 
	throws IOException, DMLRuntimeException 
{
	//allocate output matrix block
	MatrixBlock ret = createOutputMatrixBlock(rlen, clen, (int)rlen, estnnz, true, false);
	
	//core read 
	long lnnz = readCSVMatrixFromInputStream(is, "external inputstream", ret, new MutableInt(0), rlen, clen, 
		blen, _props.hasHeader(), _props.getDelim(), _props.isFill(), _props.getFillValue(), true);
			
	//finally check if change of sparse/dense block representation required
	ret.setNonZeros( lnnz );
	ret.examSparsity();
	
	return ret;
}
 
Example #9
Source File: CasStatCounter.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
	this.docIt++;
	Optional<SourceDocumentInformation> sourceDocumentAnnotation = JCasUtils.getSourceDocumentAnnotation(aJCas);
	if(sourceDocumentAnnotation.isPresent())
		this.cumulatedFileSize += sourceDocumentAnnotation.get().getDocumentSize();
	FSIterator<Annotation> it =  aJCas.getAnnotationIndex().iterator();
	Annotation a;
	MutableInt i;
	while(it.hasNext()) {
		a = it.next();
		i = counters.get(a.getType().getShortName());
		if(i == null) 
			counters.put(a.getType().getShortName(), new MutableInt(1));
		else
			i.increment();
	}
	if(periodicStatEnabled && this.docIt % this.docPeriod == 0)
		try {
			traceToFile();
		} catch (IOException e) {
			throw new AnalysisEngineProcessException(e);
		}
}
 
Example #10
Source File: ReaderTextCSV.java    From systemds with Apache License 2.0 6 votes vote down vote up
@Override
public MatrixBlock readMatrixFromInputStream(InputStream is, long rlen, long clen, int blen, long estnnz) 
	throws IOException, DMLRuntimeException 
{
	//allocate output matrix block
	MatrixBlock ret = createOutputMatrixBlock(rlen, clen, (int)rlen, estnnz, true, false);
	
	//core read 
	long lnnz = readCSVMatrixFromInputStream(is, "external inputstream", ret, new MutableInt(0), rlen, clen, 
		blen, _props.hasHeader(), _props.getDelim(), _props.isFill(), _props.getFillValue(), true);
			
	//finally check if change of sparse/dense block representation required
	ret.setNonZeros( lnnz );
	ret.examSparsity();
	
	return ret;
}
 
Example #11
Source File: MutectDownsampler.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @param maxReadsPerAlignmentStart Maximum number of reads per alignment start position. Must be > 0
 * @param stride Length in bases constituting a single pool of reads to downsample
 */
public MutectDownsampler(final int maxReadsPerAlignmentStart,
                         final int maxSuspiciousReadsPerAlignmentStart,
                         final int stride) {
    // convert coverage per base to coverage per stride
    maxCoverage = maxReadsPerAlignmentStart <= 0 ? Integer.MAX_VALUE : (maxReadsPerAlignmentStart * stride);
    this.stride = ParamUtils.isPositive(stride, "stride must be > 0");
    maxSuspiciousReadsPerStride = maxSuspiciousReadsPerAlignmentStart <= 0 ? Integer.MAX_VALUE : stride * ParamUtils.isPositive(maxSuspiciousReadsPerAlignmentStart, "maxSuspiciousReadsPerAlignmentStart must be > 0");

    pendingReads = new ArrayList<>();
    finalizedReads = new ArrayList<>();
    rejectAllReadsInStride = false;
    suspiciousReadCount = new MutableInt(0);

    clearItems();
    resetStats();
}
 
Example #12
Source File: OrientationBiasReadCounts.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *  If the allele is not in the count mappings, then it is not counted.  No exception will be thrown
 *  Modifies count variables in place.
 *
 * @param pileupElement pileup overlapping the alleles
 * @param f1r2Counts a mapping of allele to f1r2 counts
 * @param f2r1Counts a mapping of allele to f2r1 counts
 */
private static void incrementCounts(final PileupElement pileupElement, final Map<Allele, MutableInt> f1r2Counts,
                                final Map<Allele, MutableInt> f2r1Counts, final Allele referenceAllele,
                                    final List<Allele> altAlleles, int minBaseQualityCutoff) {

    final Map<Allele, MutableInt> countMap = ReadUtils.isF2R1(pileupElement.getRead()) ? f2r1Counts : f1r2Counts;

    final Allele pileupAllele = GATKVariantContextUtils.chooseAlleleForRead(pileupElement, referenceAllele, altAlleles, minBaseQualityCutoff);

    if (pileupAllele == null) {
        return;
    }

    if (countMap.containsKey(pileupAllele)) {
        countMap.get(pileupAllele).increment();
    }
}
 
Example #13
Source File: ReaderTextLIBSVM.java    From systemds with Apache License 2.0 6 votes vote down vote up
@Override
public MatrixBlock readMatrixFromInputStream(InputStream is, long rlen, long clen, int blen, long estnnz) 
	throws IOException, DMLRuntimeException 
{
	//allocate output matrix block
	MatrixBlock ret = createOutputMatrixBlock(rlen, clen, (int)rlen, estnnz, true, false);
	
	//core read 
	long lnnz = readLIBSVMMatrixFromInputStream(is, "external inputstream", ret,
		new MutableInt(0), rlen, clen, blen);
	
	//finally check if change of sparse/dense block representation required
	ret.setNonZeros( lnnz );
	ret.examSparsity();
	
	return ret;
}
 
Example #14
Source File: ReaderTextLIBSVM.java    From systemds with Apache License 2.0 6 votes vote down vote up
private static long readLIBSVMMatrixFromInputStream( InputStream is, String srcInfo, MatrixBlock dest, MutableInt rowPos, 
		long rlen, long clen, int blen )
	throws IOException
{
	SparseRowVector vect = new SparseRowVector(1024);
	String value = null;
	int row = rowPos.intValue();
	long lnnz = 0;
	
	// Read the data
	try( BufferedReader br = new BufferedReader(new InputStreamReader(is)) ) {
		while( (value=br.readLine())!=null ) { //for each line
			String rowStr = value.toString().trim();
			lnnz += ReaderTextLIBSVM.parseLibsvmRow(rowStr, vect, (int)clen);
			dest.appendRow(row, vect);
			row++;
		}
	}
	
	rowPos.setValue(row);
	return lnnz;
}
 
Example #15
Source File: ReaderTextLIBSVM.java    From systemds with Apache License 2.0 6 votes vote down vote up
private static long readLIBSVMMatrixFromInputStream( InputStream is, String srcInfo, MatrixBlock dest, MutableInt rowPos, 
		long rlen, long clen, int blen )
	throws IOException
{
	SparseRowVector vect = new SparseRowVector(1024);
	String value = null;
	int row = rowPos.intValue();
	long lnnz = 0;
	
	// Read the data
	try( BufferedReader br = new BufferedReader(new InputStreamReader(is)) ) {
		while( (value=br.readLine())!=null ) { //for each line
			String rowStr = value.toString().trim();
			lnnz += ReaderTextLIBSVM.parseLibsvmRow(rowStr, vect, (int)clen);
			dest.appendRow(row, vect);
			row++;
		}
	}
	
	rowPos.setValue(row);
	return lnnz;
}
 
Example #16
Source File: CronServiceTest.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCronTriggerExecutionTime() throws Exception {

	MutableInt ref = new MutableInt();
	Runnable test = newIncrementingRunnable(ref);

	// should run on second # 0 and every 2 seconds
	// execute on 0, 2, 4...

	cronService.schedule(test, "0/2 * * * * ?");
	sleep(5);
	int count = ref.intValue();
	assertEquals(count, 3);
}
 
Example #17
Source File: CronServiceTest.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
private static Runnable newIncrementingRunnable(final MutableInt ref) {
	return new Runnable() {
		@Override
		public void run() {
			if (ref != null) {
				ref.increment();
			}
		}
	};
}
 
Example #18
Source File: CronServiceTest.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCancelRunnableUsingRunnableReference() throws Exception {
	final MutableInt val = new MutableInt();
	Runnable test = new Runnable() {
		@Override
		public void run() {
			val.increment();
			cronService.cancel(this);
		}
	};
	cronService.schedule(test, "0/2 * * * * ?");
	sleep(5);
	assertEquals(val.intValue(), 1);
}
 
Example #19
Source File: TypeDiffOperation.java    From zeno with Apache License 2.0 5 votes vote down vote up
private boolean decrement(Map<Object, MutableInt> map, Object obj) {
    MutableInt i = map.get(obj);
    if(i == null) {
        return false;
    }

    i.decrement();

    if(i.intValue() == 0) {
        map.remove(obj);
    }

    return true;
}
 
Example #20
Source File: RunatoriumReward.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void addPvpKillsByRace(Race race, int points) {
	MutableInt racePoints = getPvpKillsByRace(race);
	racePoints.add(points);
	if (racePoints.intValue() < 0) {
		racePoints.setValue(0);
	}
}
 
Example #21
Source File: TenantEventsProvider.java    From tasmo with Apache License 2.0 5 votes vote down vote up
public void loadModel(TenantId tenantId) {
    ChainedVersion currentVersion = eventsProvider.getCurrentEventsVersion(tenantId);
    if (currentVersion == ChainedVersion.NULL) {
        versionedEventsModels.put(tenantId, new VersionedEventsModel(currentVersion, null));
    } else {
        VersionedEventsModel currentVersionedEventModel = versionedEventsModels.get(tenantId);
        if (currentVersionedEventModel == null
            || !currentVersionedEventModel.getVersion().equals(currentVersion)) {

            final MutableInt errors = new MutableInt();
            final EventsModel newEventsModel = new EventsModel();
            List<ObjectNode> events = eventsProvider.getEvents(new EventsProcessorId(tenantId, "NotBeingUsedYet"));
            for (ObjectNode event : events) {
                try {
                    newEventsModel.addEvent(event);
                } catch (Exception x) {
                    LOG.error("Failed to load event for " + event, x);
                    throw new RuntimeException("Failed to load (" + errors.longValue() + ") event/s. ");
                }
            }
            versionedEventsModels.put(tenantId, new VersionedEventsModel(currentVersion, newEventsModel));

        } else {
            LOG.debug("Didn't reload because event model versions are equal.");
        }
    }
}
 
Example #22
Source File: RunatoriumReward.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void addPointsByRace(Race race, int points) {
	MutableInt racePoints = getPointsByRace(race);
	racePoints.add(points);
	if (racePoints.intValue() < 0) {
		racePoints.setValue(0);
	}
}
 
Example #23
Source File: KamarBattlefieldReward.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void addPointsByRace(Race race, int points) {
	MutableInt racePoints = getPointsByRace(race);
	racePoints.add(points);
	if (racePoints.intValue() < 0) {
		racePoints.setValue(0);
	}
}
 
Example #24
Source File: SteelWallBastionBattlefieldReward.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void addPointsByRace(Race race, int points) {
	MutableInt racePoints = getPointsByRace(race);
	racePoints.add(points);
	if (racePoints.intValue() < 0) {
		racePoints.setValue(0);
	}
}
 
Example #25
Source File: SteelWallBastionBattlefieldReward.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public SteelWallBastionBattlefieldReward(Integer mapId, int instanceId, WorldMapInstance instance) {
	super(mapId, instanceId);
	this.instance = instance;
	asmodiansPoints = new MutableInt(3800);
	elyosPoins = new MutableInt(3800);
	asmodiansPvpKills = new MutableInt(0);
	elyosPvpKills = new MutableInt(0);
	winnerPoints = 3000;
	looserPoints = 2500;
	capPoints = 30000;
	bonusTime = 12000;
	buffId = 12;
}
 
Example #26
Source File: BalaurMarchingRouteReward.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void addPointsByRace(Race race, int points) {
	MutableInt racePoints = getPointsByRace(race);
	racePoints.add(points);
	if (racePoints.intValue() < 0) {
		racePoints.setValue(0);
	}
}
 
Example #27
Source File: BalaurMarchingRouteReward.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void addPvpKillsByRace(Race race, int points) {
	MutableInt racePoints = getPvpKillsByRace(race);
	racePoints.add(points);
	if (racePoints.intValue() < 0) {
		racePoints.setValue(0);
	}
}
 
Example #28
Source File: KamarBattlefieldReward.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public void addPvpKillsByRace(Race race, int points) {
	MutableInt racePoints = getPvpKillsByRace(race);
	racePoints.add(points);
	if (racePoints.intValue() < 0) {
		racePoints.setValue(0);
	}
}
 
Example #29
Source File: KamarBattlefieldReward.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
public MutableInt getPvpKillsByRace(Race race) {
	switch (race) {
		case ELYOS:
			return elyosPvpKills;
		case ASMODIANS:
			return asmodiansPvpKills;
		default:
			break;
	}
	return null;
}
 
Example #30
Source File: CronServiceTest.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCancelRunnableUsingJobDetails() throws Exception {
	final MutableInt val = new MutableInt();
	Runnable test = new Runnable() {
		@Override
		public void run() {
			val.increment();
			cronService.cancel(cronService.getRunnables().get(this));
		}
	};
	cronService.schedule(test, "0/2 * * * * ?");
	sleep(5);
	assertEquals(val.intValue(), 1);
}