Java Code Examples for java.util.concurrent.ConcurrentSkipListMap#get()

The following examples show how to use java.util.concurrent.ConcurrentSkipListMap#get() . 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: SegmentMemoryStore.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void aggregate(ConcurrentSkipListMap<String[], MeasureAggregator[]> cuboidAggBufMap, String[] dimensions,
        Object[] metricsValues) {
    MeasureAggregator[] aggrs = cuboidAggBufMap.get(dimensions);
    if (aggrs != null) {
        aggregateValues(aggrs, metricsValues);
    }

    if (aggrs == null) {
        MeasureAggregator[] newAggrs = newMetricsAggregators(parsedStreamingCubeInfo.metricsAggrFuncs);
        aggregateValues(newAggrs, metricsValues);
        aggrs = cuboidAggBufMap.putIfAbsent(dimensions, newAggrs);
        if (aggrs == null) {
            rowCount.incrementAndGet();
        } else {
            aggregateValues(aggrs, metricsValues);
        }
    }

}
 
Example 2
Source File: SegmentMemoryStore.java    From kylin with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void aggregate(ConcurrentSkipListMap<String[], MeasureAggregator[]> cuboidAggBufMap, String[] dimensions,
        Object[] metricsValues) {
    MeasureAggregator[] aggrs = cuboidAggBufMap.get(dimensions);
    if (aggrs != null) {
        aggregateValues(aggrs, metricsValues);
    }

    if (aggrs == null) {
        MeasureAggregator[] newAggrs = newMetricsAggregators(parsedStreamingCubeInfo.metricsAggrFuncs);
        aggregateValues(newAggrs, metricsValues);
        aggrs = cuboidAggBufMap.putIfAbsent(dimensions, newAggrs);
        if (aggrs == null) {
            rowCount.incrementAndGet();
        } else {
            aggregateValues(aggrs, metricsValues);
        }
    }

}
 
Example 3
Source File: ConcurrentSkipListMapTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * get(null) of nonempty map throws NPE
 */
public void testGet_NullPointerException() {
    ConcurrentSkipListMap c = map5();
    try {
        c.get(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 4
Source File: PropertyCollection.java    From vertexium with Apache License 2.0 5 votes vote down vote up
public synchronized void addProperty(Property property) {
    ConcurrentSkipListMap<String, ConcurrentSkipListSet<Property>> propertiesByKey = propertiesByNameAndKey.get(property.getName());
    if (propertiesByKey == null) {
        propertiesByKey = new ConcurrentSkipListMap<>();
        this.propertiesByNameAndKey.put(property.getName(), propertiesByKey);
    }
    ConcurrentSkipListSet<Property> properties = propertiesByKey.get(property.getKey());
    if (properties == null) {
        properties = new ConcurrentSkipListSet<>();
        propertiesByKey.put(property.getKey(), properties);
    }
    properties.add(property);
    this.propertiesList.add(property);
}
 
Example 5
Source File: ConcurrentSkipListMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * get(null) of nonempty map throws NPE
 */
public void testGet_NullPointerException() {
    ConcurrentSkipListMap c = map5();
    try {
        c.get(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 6
Source File: ProfileReportNewAPITest.java    From aparapi with Apache License 2.0 4 votes vote down vote up
public boolean singleThreadedSingleKernelReportObserverTestHelper(Device device, int size) {
  	final int runs = 100;
  	final int inputArray[] = new int[size];
  	final Basic1Kernel kernel = new Basic1Kernel();

  	int[] outputArray = null;
  	Range range = device.createRange(size, size);

  	ReportObserver observer = new ReportObserver(device, 1, runs);
  	observer.addAcceptedThreadId(Thread.currentThread().getId());
  	kernel.registerProfileReportObserver(observer);

for (int i = 0; i < runs; i++) {
	assertFalse("Report with id " + i + " shouldn't have been received yet", observer.receivedReportIds[i]);
}

  	long startOfExecution = System.currentTimeMillis();
  	try {
  		for (int i = 0; i < runs; i++) {
  			outputArray = Arrays.copyOf(inputArray, inputArray.length);
  			kernel.setInputOuputArray(outputArray);
  			kernel.execute(range);
  		}
  		long runTime = System.currentTimeMillis() - startOfExecution;
  		ConcurrentSkipListMap<Long, ThreadTestState> results = observer.getObservedThreadsIds();
  		ThreadTestState state = results.get(Thread.currentThread().getId());
  		assertNotNull("Reports should have been received for thread", state);

  		assertEquals("Number of profiling reports doesn't match the expected", runs, state.receivedReportsCount);
  		assertEquals("Aparapi Accumulated execution time doesn't match", kernel.getAccumulatedExecutionTimeAllThreads(device), state.accumulatedElapsedTime, 1e-10);
  		// FIXME failing: assertEquals("Test estimated accumulated time doesn't match within 200ms window", runTime, kernel.getAccumulatedExecutionTimeAllThreads(device), 200);
  		for (int i = 0; i < runs; i++) {
  			assertTrue("Report with id " + i + " wasn't received", observer.receivedReportIds[i]);
  		}
  		assertTrue(validateBasic1Kernel(inputArray, outputArray));
  	} finally {
  		kernel.registerProfileReportObserver(null);
  		kernel.dispose();
  	}

  	return true;
  }
 
Example 7
Source File: ProfileReportNewAPITest.java    From aparapi with Apache License 2.0 4 votes vote down vote up
public boolean multiThreadedSingleKernelReportObserverTestHelper(Device device, int size) throws InterruptedException, ExecutionException {
  	final int runs = 100;
  	final int javaThreads = 10;
  	final int inputArray[] = new int[size];
  	ExecutorService executorService = Executors.newFixedThreadPool(javaThreads);

  	final ReportObserver observer = new ReportObserver(device, javaThreads, runs);

for (int i = 0; i < runs; i++) {
	assertFalse("Report with id " + i + " shouldn't have been received yet", observer.receivedReportIds[i]);
}

  	final List<Basic1Kernel> kernels = new ArrayList<Basic1Kernel>(javaThreads);
  	for (int i = 0; i < javaThreads; i++) {
      	final Basic1Kernel kernel = new Basic1Kernel();
      	kernel.registerProfileReportObserver(observer);
      	kernels.add(kernel);
  	}

  	final ThreadResults[] results = new ThreadResults[javaThreads];
  	for (int i = 0; i < results.length; i++) {
  		results[i] = new ThreadResults();
  	}


  	boolean terminatedOk = multiThreadedSingleKernelReportObserverTestRunner(executorService, kernels, results,
  			inputArray, runs, javaThreads, device, observer, size);

  	assertTrue("Threads did not terminate correctly", terminatedOk);

  	double allThreadsAccumulatedTime = 0;
  	ConcurrentSkipListMap<Long, ThreadTestState> states = observer.getObservedThreadsIds();
  	assertEquals("Number of Java threads sending profile reports should match the number of JavaThreads", javaThreads, states.values().size());
  	for (int i = 0; i < javaThreads; i++) {
  		ThreadTestState state = states.get(results[i].threadId);
  		assertNotNull("Report should have been received for thread with index " + i, state);
  		assertEquals("Number of total iteration should match number of runs for thread with index " + i, runs, results[i].kernelCalls);
      	assertEquals("Number of received reports should match total number of calls for thread with index " + i, runs, state.receivedReportsCount);
      	assertEquals("Overall elapsed time received in reports doesn't match KernelDeviceProfile.Accumulator for threa with index " + i,
      			results[i].accumulatedExecutionTime, state.accumulatedElapsedTime, 1e-10);
      	allThreadsAccumulatedTime += state.accumulatedElapsedTime;
      	assertTrue("Thread index " + i + " kernel computation doesn't match the expected", validateBasic1Kernel(inputArray, results[i].outputArray));
      	//FIXME Find a better way of determining kernel execution time
      	//assertEquals("Runtime is not within 600ms of the kernel estimated", results[i].runTime, state.accumulatedElapsedTime, 600);
  	}

  	assertEquals("Overall kernel execution time doesn't match",
  			kernels.get(0).getAccumulatedExecutionTimeAllThreads(device), allThreadsAccumulatedTime, 1e10);

  	return true;
  }
 
Example 8
Source File: ICCProfile.java    From freeinternals with Apache License 2.0 4 votes vote down vote up
public void generateTreeNode(DefaultMutableTreeNode parentNode) {
    DefaultMutableTreeNode nodeHeader;
    DefaultMutableTreeNode nodeTagTable;
    int lastPos;
    int diff;

    parentNode.add(nodeHeader = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
            this.header.getStartPos(),
            this.header.getLength(),
            "Profile header")));
    this.header.generateTreeNode(nodeHeader);

    parentNode.add(nodeHeader = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
            lastPos = this.header.getStartPos() + this.header.getLength(),
            4,
            String.format("Tag count = %d", this.tagCount))));

    lastPos = lastPos + 4;

    ConcurrentSkipListMap<Long, RefItem> sortedMap = new ConcurrentSkipListMap<Long, RefItem>();
    for (int i = 0; i < this.tagTable.length; i++) {
        parentNode.add(nodeTagTable = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                lastPos + Tag.LENGTH * i,
                Tag.LENGTH,
                String.format("Tag[%d]", i))));
        this.tagTable[i].generateTreeNode(nodeTagTable);

        if (sortedMap.get(this.tagTable[i].Offset) == null) {
            RefItem refItem = new RefItem();
            refItem.i = i;
            refItem.tag = this.tagTable[i];
            sortedMap.put(refItem.tag.Offset, refItem);
        }
    }

    lastPos = lastPos + this.tagTable.length * Tag.LENGTH;
    for (RefItem ref : sortedMap.values()) {
        diff = (int) ((this.startPos + ref.tag.Offset) - lastPos);
        if (diff > 0) {
            UITool.generateTreeNodeDiff(
                    parentNode, lastPos, diff,
                    this.rawData, this.startPos);
        }

        parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
                this.startPos + (int) ref.tag.Offset,
                (int) ref.tag.Size,
                String.format("Data of Tag [%d]", ref.i))));
        lastPos = this.startPos + (int) ref.tag.Offset + (int) ref.tag.Size;
    }

    diff = (this.startPos + this.rawData.length) - lastPos;
    if (diff > 0) {
        UITool.generateTreeNodeDiff(
                parentNode, lastPos, diff,
                this.rawData, this.startPos);
    }
}
 
Example 9
Source File: AbstractGraphPanelVisualizer.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
protected synchronized AbstractGraphRow getNewRow(
        ConcurrentSkipListMap<String, AbstractGraphRow> model,
        int rowType,
        String label,
        int markerSize,
        boolean isBarRow,
        boolean displayLabel,
        boolean thickLines,
        boolean showInLegend,
        Color color,
        boolean canCompose) {
    AbstractGraphRow row;
    if (log.isDebugEnabled()) {
        log.debug("This AbstractGraphPanelVisualizer is an instance of [" + this.getClass().getName() + "]");
    }
    if (!model.containsKey(label)) {
        row = AbstractGraphRow.instantiateNewRow(rowType);
        row.setLabel(label);
        row.setMarkerSize(markerSize);
        row.setDrawBar(isBarRow);
        row.setDrawLine(!isBarRow);
        row.setDrawValueLabel(displayLabel);
        row.setDrawThickLines(thickLines);
        row.setShowInLegend(showInLegend);

        Color overrideColor = null;
        if (this.labelToColorMapping != null)
            overrideColor = labelToColorMapping.getColorForLabel(row.getLabel());
        if (log.isDebugEnabled())
            if (row != null) {
                log.debug("%#@ Found override color [" + (overrideColor == null ? "null" : overrideColor.toString()) + "]");
                log.debug("%#@ for label [" + row.getLabel() + "] color in-parm [" + (color == null ? "null" : color.toString()) + "]");
                log.debug("%#@ prev row.getColor() [" + (row.getColor() == null ? "null" : row.getColor().toString()) + "]");
            } else
                log.debug("%#@ Found null row displayLabel[" + displayLabel + "] and label [" + label + "]");

        row.setColor(overrideColor != null ? overrideColor : colors.getNextColor());
        if (log.isDebugEnabled())
            log.debug("%#@ new row.getColor() [" + (row.getColor() == null ? "null" : row.getColor().toString()) + "]");

        model.put(label, row);
        graphPanel.addRow(row);
        if (canCompose) {
            addRowToCompositeModels(getModel().getName(), row);
        }
    } else {
        row = model.get(label);
    }

    return row;
}