flink-instrumentation/workspace/flink-1.4.1-instrumented/flink-1.4.1/flink-contrib/flink-streaming-contrib/src/main/java/org/apache/flink/contrib/streaming/DataStreamUtils.java
/**
	 * Returns an iterator to iterate over the elements of the DataStream.
	 * @return The iterator
	 */
Returns an iterator to iterate over the elements of the DataStream.
@return The iterator
Returns an iterator to iterate over the elements of the DataStream . @return The iterator
public static <OUT> Iterator<OUT> collect(DataStream<OUT> stream) throws IOException {
		TypeSerializer<OUT> serializer = stream.getType().createSerializer(
				stream.getExecutionEnvironment().getConfig());
		SocketStreamIterator<OUT> iter = new SocketStreamIterator<OUT>(serializer);
		StreamExecutionEnvironment env = stream.getExecutionEnvironment();
		InetAddress clientAddress;
		if (env instanceof RemoteStreamEnvironment) {
			String host = ((RemoteStreamEnvironment) env).getHost();
			int port = ((RemoteStreamEnvironment) env).getPort();
			try {
				clientAddress = ConnectionUtils.findConnectingAddress(new InetSocketAddress(host, port), 2000, 400);
			}
			catch (Exception e) {
				throw new IOException("Could not determine an suitable network address to " +
						"receive back data from the streaming program.", e);
			}
		} else if (env instanceof LocalStreamEnvironment) {
			clientAddress = InetAddress.getLoopbackAddress();
		} else {
			try {
				clientAddress = InetAddress.getLocalHost();
			} catch (UnknownHostException e) {
				throw new IOException("Could not determine this machines own local address to " +
						"receive back data from the streaming program.", e);
			}
		}
		DataStreamSink<OUT> sink = stream.addSink(new CollectSink<OUT>(clientAddress, iter.getPort(), serializer));
		sink.setParallelism(1); 
		(new CallExecute(env, iter)).start();
		return iter;
	}
public static < OUT > Iterator < OUT > collect ( DataStream < OUT > stream ) throws IOException { TypeSerializer < OUT > serializer = stream . getType ( ) . createSerializer ( stream . getExecutionEnvironment ( ) . getConfig ( ) ) ; SocketStreamIterator < OUT > iter = new SocketStreamIterator < OUT > ( serializer ) ; StreamExecutionEnvironment env = stream . getExecutionEnvironment ( ) ; InetAddress clientAddress ; if ( env instanceof RemoteStreamEnvironment ) { String host = ( ( RemoteStreamEnvironment ) env ) . getHost ( ) ; int port = ( ( RemoteStreamEnvironment ) env ) . getPort ( ) ; try { clientAddress = ConnectionUtils . findConnectingAddress ( new InetSocketAddress ( host , port ) , 2000 , 400 ) ; } catch ( Exception e ) { throw new IOException ( "Could not determine an suitable network address to " + "receive back data from the streaming program." , e ) ; } } else if ( env instanceof LocalStreamEnvironment ) { clientAddress = InetAddress . getLoopbackAddress ( ) ; } else { try { clientAddress = InetAddress . getLocalHost ( ) ; } catch ( UnknownHostException e ) { throw new IOException ( "Could not determine this machines own local address to " + "receive back data from the streaming program." , e ) ; } } DataStreamSink < OUT > sink = stream . addSink ( new CollectSink < OUT > ( clientAddress , iter . getPort ( ) , serializer ) ) ; sink . setParallelism ( 1 ) ; ( new CallExecute ( env , iter ) ) . start ( ) ; return iter ; }
Returns an iterator to iterate over the elements of the DataStream.
Returns an iterator to iterate over the elements of the DataStream .
//Find out what IP of us should be given to CollectSink, that it will be able to connect to // It would not work if multiple instances would connect to the same port