Java Code Examples for org.apache.flink.util.OptionalFailure#getUnchecked()

The following examples show how to use org.apache.flink.util.OptionalFailure#getUnchecked() . 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: AccumulatorHelper.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Merge two collections of accumulators. The second will be merged into the
 * first.
 *
 * @param target
 *            The collection of accumulators that will be updated
 * @param toMerge
 *            The collection of accumulators that will be merged into the
 *            other
 */
public static void mergeInto(Map<String, OptionalFailure<Accumulator<?, ?>>> target, Map<String, Accumulator<?, ?>> toMerge) {
	for (Map.Entry<String, Accumulator<?, ?>> otherEntry : toMerge.entrySet()) {
		OptionalFailure<Accumulator<?, ?>> ownAccumulator = target.get(otherEntry.getKey());
		if (ownAccumulator == null) {
			// Create initial counter (copy!)
			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> otherEntry.getValue().clone()));
		}
		else if (ownAccumulator.isFailure()) {
			continue;
		}
		else {
			Accumulator<?, ?> accumulator = ownAccumulator.getUnchecked();
			// Both should have the same type
			compareAccumulatorTypes(otherEntry.getKey(),
				accumulator.getClass(), otherEntry.getValue().getClass());
			// Merge target counter with other counter

			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> mergeSingle(accumulator, otherEntry.getValue().clone())));
		}
	}
}
 
Example 2
Source File: AccumulatorHelper.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Merge two collections of accumulators. The second will be merged into the
 * first.
 *
 * @param target
 *            The collection of accumulators that will be updated
 * @param toMerge
 *            The collection of accumulators that will be merged into the
 *            other
 */
public static void mergeInto(Map<String, OptionalFailure<Accumulator<?, ?>>> target, Map<String, Accumulator<?, ?>> toMerge) {
	for (Map.Entry<String, Accumulator<?, ?>> otherEntry : toMerge.entrySet()) {
		OptionalFailure<Accumulator<?, ?>> ownAccumulator = target.get(otherEntry.getKey());
		if (ownAccumulator == null) {
			// Create initial counter (copy!)
			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> otherEntry.getValue().clone()));
		}
		else if (ownAccumulator.isFailure()) {
			continue;
		}
		else {
			Accumulator<?, ?> accumulator = ownAccumulator.getUnchecked();
			// Both should have the same type
			compareAccumulatorTypes(otherEntry.getKey(),
				accumulator.getClass(), otherEntry.getValue().getClass());
			// Merge target counter with other counter

			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> mergeSingle(accumulator, otherEntry.getValue().clone())));
		}
	}
}
 
Example 3
Source File: AccumulatorHelper.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Merge two collections of accumulators. The second will be merged into the
 * first.
 *
 * @param target
 *            The collection of accumulators that will be updated
 * @param toMerge
 *            The collection of accumulators that will be merged into the
 *            other
 */
public static void mergeInto(Map<String, OptionalFailure<Accumulator<?, ?>>> target, Map<String, Accumulator<?, ?>> toMerge) {
	for (Map.Entry<String, Accumulator<?, ?>> otherEntry : toMerge.entrySet()) {
		OptionalFailure<Accumulator<?, ?>> ownAccumulator = target.get(otherEntry.getKey());
		if (ownAccumulator == null) {
			// Create initial counter (copy!)
			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> otherEntry.getValue().clone()));
		}
		else if (ownAccumulator.isFailure()) {
			continue;
		}
		else {
			Accumulator<?, ?> accumulator = ownAccumulator.getUnchecked();
			// Both should have the same type
			compareAccumulatorTypes(otherEntry.getKey(),
				accumulator.getClass(), otherEntry.getValue().getClass());
			// Merge target counter with other counter

			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> mergeSingle(accumulator, otherEntry.getValue().clone())));
		}
	}
}
 
Example 4
Source File: JobExecutionResult.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the accumulator with the given name. Returns {@code null}, if no accumulator with
 * that name was produced.
 *
 * @param accumulatorName The name of the accumulator.
 * @param <T> The generic type of the accumulator value.
 * @return The value of the accumulator with the given name.
 */
@SuppressWarnings("unchecked")
public <T> T getAccumulatorResult(String accumulatorName) {
	OptionalFailure<Object> result = this.accumulatorResults.get(accumulatorName);
	if (result != null) {
		return (T) result.getUnchecked();
	} else {
		return null;
	}
}