Java Code Examples for org.apache.flink.types.LongValue#setValue()

The following examples show how to use org.apache.flink.types.LongValue#setValue() . 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: StreamNetworkPointToPointBenchmark.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Executes the latency benchmark with the given number of records.
 *
 * @param records
 * 		records to pass through the network stack
 * @param flushAfterLastEmit
 * 		whether to flush the {@link RecordWriter} after the last record
 */
public void executeBenchmark(long records, boolean flushAfterLastEmit) throws Exception {
	final LongValue value = new LongValue();
	value.setValue(0);

	CompletableFuture<?> recordsReceived = receiver.setExpectedRecord(records);

	for (int i = 1; i < records; i++) {
		recordWriter.emit(value);
	}
	value.setValue(records);
	recordWriter.broadcastEmit(value);
	if (flushAfterLastEmit) {
		recordWriter.flushAll();
	}

	recordsReceived.get(RECEIVER_TIMEOUT, TimeUnit.MILLISECONDS);
}
 
Example 2
Source File: LongRecordWriterThread.java    From flink with Apache License 2.0 6 votes vote down vote up
private void sendRecords(long records) throws IOException, InterruptedException {
	LongValue value = new LongValue(0);

	for (int i = 1; i < records; i++) {
		if (broadcastMode) {
			recordWriter.broadcastEmit(value);
		}
		else {
			recordWriter.emit(value);
		}
	}
	value.setValue(records);
	recordWriter.broadcastEmit(value);
	recordWriter.flushAll();

	finishSendingRecords();
}
 
Example 3
Source File: LongRecordWriterThread.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void sendRecords(long records) throws IOException, InterruptedException {
	LongValue value = new LongValue(0);

	for (int i = 1; i < records; i++) {
		if (broadcastMode) {
			recordWriter.broadcastEmit(value);
		}
		else {
			recordWriter.emit(value);
		}
	}
	value.setValue(records);
	recordWriter.broadcastEmit(value);
	recordWriter.flushAll();

	finishSendingRecords();
}
 
Example 4
Source File: StreamNetworkPointToPointBenchmark.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Executes the latency benchmark with the given number of records.
 *
 * @param records
 * 		records to pass through the network stack
 * @param flushAfterLastEmit
 * 		whether to flush the {@link RecordWriter} after the last record
 */
public void executeBenchmark(long records, boolean flushAfterLastEmit) throws Exception {
	final LongValue value = new LongValue();
	value.setValue(0);

	CompletableFuture<?> recordsReceived = receiver.setExpectedRecord(records);

	for (int i = 1; i < records; i++) {
		recordWriter.emit(value);
	}
	value.setValue(records);
	recordWriter.broadcastEmit(value);
	if (flushAfterLastEmit) {
		recordWriter.flushAll();
	}

	recordsReceived.get(RECEIVER_TIMEOUT, TimeUnit.MILLISECONDS);
}
 
Example 5
Source File: LongRecordWriterThread.java    From flink with Apache License 2.0 6 votes vote down vote up
private void sendRecords(long records) throws IOException, InterruptedException {
	LongValue value = new LongValue(0);

	for (int i = 1; i < records; i++) {
		if (broadcastMode) {
			recordWriter.broadcastEmit(value);
		}
		else {
			recordWriter.emit(value);
		}
	}
	value.setValue(records);
	recordWriter.broadcastEmit(value);
	recordWriter.flushAll();

	finishSendingRecords();
}
 
Example 6
Source File: StreamNetworkThroughputBenchmark.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the throughput benchmark with the given number of records.
 *
 * @param records to pass through the network stack
 */
public void executeBenchmark(long records, long timeout) throws Exception {
	final LongValue value = new LongValue();
	value.setValue(0);

	long lastRecord = records / writerThreads.length;
	CompletableFuture<?> recordsReceived = receiver.setExpectedRecord(lastRecord);

	for (LongRecordWriterThread writerThread : writerThreads) {
		writerThread.setRecordsToSend(lastRecord);
	}

	recordsReceived.get(timeout, TimeUnit.MILLISECONDS);
}
 
Example 7
Source File: StreamNetworkThroughputBenchmark.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the throughput benchmark with the given number of records.
 *
 * @param records to pass through the network stack
 */
public void executeBenchmark(long records, long timeout) throws Exception {
	final LongValue value = new LongValue();
	value.setValue(0);

	long lastRecord = records / writerThreads.length;
	CompletableFuture<?> recordsReceived = receiver.setExpectedRecord(lastRecord);

	for (LongRecordWriterThread writerThread : writerThreads) {
		writerThread.setRecordsToSend(lastRecord);
	}

	recordsReceived.get(timeout, TimeUnit.MILLISECONDS);
}
 
Example 8
Source File: TaskCancelAsyncProducerConsumerITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	LongValue current = new LongValue(0);

	try {
		while (true) {
			current.setValue(current.getValue() + 1);
			recordWriter.emit(current);
			recordWriter.flushAll();
		}
	} catch (Exception e) {
		ASYNC_PRODUCER_EXCEPTION = e;
	}
}
 
Example 9
Source File: TaskCancelAsyncProducerConsumerITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	LongValue current = new LongValue(0);

	try {
		while (true) {
			current.setValue(current.getValue() + 1);
			recordWriter.emit(current);
			recordWriter.flushAll();
		}
	} catch (Exception e) {
		ASYNC_PRODUCER_EXCEPTION = e;
	}
}
 
Example 10
Source File: DegreeAnnotationFunctions.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Vertex<K, LongValue> reduce(Vertex<K, LongValue> left, Vertex<K, LongValue> right)
		throws Exception {
	LongValue count = left.f1;
	count.setValue(count.getValue() + right.f1.getValue());
	return left;
}
 
Example 11
Source File: StreamNetworkThroughputBenchmark.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the throughput benchmark with the given number of records.
 *
 * @param records to pass through the network stack
 */
public void executeBenchmark(long records, long timeout) throws Exception {
	final LongValue value = new LongValue();
	value.setValue(0);

	long lastRecord = records / writerThreads.length;
	CompletableFuture<?> recordsReceived = receiver.setExpectedRecord(lastRecord);

	for (LongRecordWriterThread writerThread : writerThreads) {
		writerThread.setRecordsToSend(lastRecord);
	}

	recordsReceived.get(timeout, TimeUnit.MILLISECONDS);
}
 
Example 12
Source File: TaskCancelAsyncProducerConsumerITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	LongValue current = new LongValue(0);

	try {
		while (true) {
			current.setValue(current.getValue() + 1);
			recordWriter.emit(current);
			recordWriter.flushAll();
		}
	} catch (Exception e) {
		ASYNC_PRODUCER_EXCEPTION = e;
	}
}
 
Example 13
Source File: DegreeAnnotationFunctions.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public Vertex<K, LongValue> reduce(Vertex<K, LongValue> left, Vertex<K, LongValue> right)
		throws Exception {
	LongValue count = left.f1;
	count.setValue(count.getValue() + right.f1.getValue());
	return left;
}
 
Example 14
Source File: GraphUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public LongValue reduce(LongValue value1, LongValue value2)
		throws Exception {
	value1.setValue(value1.getValue() + value2.getValue());
	return value1;
}
 
Example 15
Source File: LongValueParser.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public int parseField(byte[] bytes, int startPos, int limit, byte[] delimiter, LongValue reusable) {

	if (startPos == limit) {
		setErrorState(ParseErrorState.EMPTY_COLUMN);
		return -1;
	}

	long val = 0;
	boolean neg = false;

	final int delimLimit = limit - delimiter.length + 1;

	this.result = reusable;
	
	if (bytes[startPos] == '-') {
		neg = true;
		startPos++;
		
		// check for empty field with only the sign
		if (startPos == limit || (startPos < delimLimit && delimiterNext(bytes, startPos, delimiter))) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_ORPHAN_SIGN);
			return -1;
		}
	}
	
	for (int i = startPos; i < limit; i++) {
		if (i < delimLimit && delimiterNext(bytes, i, delimiter)) {
			if (i == startPos) {
				setErrorState(ParseErrorState.EMPTY_COLUMN);
				return -1;
			}
			reusable.setValue(neg ? -val : val);
			return i + delimiter.length;
		}
		if (bytes[i] < 48 || bytes[i] > 57) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_ILLEGAL_CHARACTER);
			return -1;
		}
		val *= 10;
		val += bytes[i] - 48;

		// check for overflow / underflow
		if (val < 0) {
			// this is an overflow/underflow, unless we hit exactly the Long.MIN_VALUE
			if (neg && val == Long.MIN_VALUE) {
				reusable.setValue(Long.MIN_VALUE);
				
				if (i+1 >= limit) {
					return limit;
				} else if (i + 1 < delimLimit && delimiterNext(bytes, i + 1, delimiter)) {
					return i + 1 + delimiter.length;
				} else {
					setErrorState(ParseErrorState.NUMERIC_VALUE_OVERFLOW_UNDERFLOW);
					return -1;
				}
			}
			else {
				setErrorState(ParseErrorState.NUMERIC_VALUE_OVERFLOW_UNDERFLOW);
				return -1;
			}
		}
	}

	reusable.setValue(neg ? -val : val);
	return limit;
}
 
Example 16
Source File: LongValueSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public LongValue copy(LongValue from, LongValue reuse) {
	reuse.setValue(from.getValue());
	return reuse;
}
 
Example 17
Source File: LongValueSerializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public LongValue copy(LongValue from, LongValue reuse) {
	reuse.setValue(from.getValue());
	return reuse;
}
 
Example 18
Source File: LongValueParser.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public int parseField(byte[] bytes, int startPos, int limit, byte[] delimiter, LongValue reusable) {

	if (startPos == limit) {
		setErrorState(ParseErrorState.EMPTY_COLUMN);
		return -1;
	}

	long val = 0;
	boolean neg = false;

	final int delimLimit = limit - delimiter.length + 1;

	this.result = reusable;
	
	if (bytes[startPos] == '-') {
		neg = true;
		startPos++;
		
		// check for empty field with only the sign
		if (startPos == limit || (startPos < delimLimit && delimiterNext(bytes, startPos, delimiter))) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_ORPHAN_SIGN);
			return -1;
		}
	}
	
	for (int i = startPos; i < limit; i++) {
		if (i < delimLimit && delimiterNext(bytes, i, delimiter)) {
			if (i == startPos) {
				setErrorState(ParseErrorState.EMPTY_COLUMN);
				return -1;
			}
			reusable.setValue(neg ? -val : val);
			return i + delimiter.length;
		}
		if (bytes[i] < 48 || bytes[i] > 57) {
			setErrorState(ParseErrorState.NUMERIC_VALUE_ILLEGAL_CHARACTER);
			return -1;
		}
		val *= 10;
		val += bytes[i] - 48;

		// check for overflow / underflow
		if (val < 0) {
			// this is an overflow/underflow, unless we hit exactly the Long.MIN_VALUE
			if (neg && val == Long.MIN_VALUE) {
				reusable.setValue(Long.MIN_VALUE);
				
				if (i+1 >= limit) {
					return limit;
				} else if (i + 1 < delimLimit && delimiterNext(bytes, i + 1, delimiter)) {
					return i + 1 + delimiter.length;
				} else {
					setErrorState(ParseErrorState.NUMERIC_VALUE_OVERFLOW_UNDERFLOW);
					return -1;
				}
			}
			else {
				setErrorState(ParseErrorState.NUMERIC_VALUE_OVERFLOW_UNDERFLOW);
				return -1;
			}
		}
	}

	reusable.setValue(neg ? -val : val);
	return limit;
}
 
Example 19
Source File: GraphUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public LongValue reduce(LongValue value1, LongValue value2)
		throws Exception {
	value1.setValue(value1.getValue() + value2.getValue());
	return value1;
}
 
Example 20
Source File: GraphUtils.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public LongValue reduce(LongValue value1, LongValue value2)
		throws Exception {
	value1.setValue(value1.getValue() + value2.getValue());
	return value1;
}