@@ -0,0 +1,1499 @@
+package eu.qualimaster.common.switching;%0D%0A%0D%0Aimport java.io.IOException;%0D%0Aimport java.net.Socket;%0D%0Aimport java.net.UnknownHostException;%0D%0A%0D%0Aimport com.esotericsoftware.kryo.io.Output;%0D%0A%0D%0A/**%0D%0A * Sends tuples via network.%0D%0A * @author Cui Qin%0D%0A *%0D%0A */%0D%0Apublic class TupleSender %7B%0D%0A    private String host;%0D%0A    private int port;%0D%0A    private Socket socket;%0D%0A    private Output output;%0D%0A    /**%0D%0A     * Creates a tuple sender.%0D%0A     * @param host the host to be connected%0D%0A     * @param port the port to be connected%0D%0A     */%0D%0A    public TupleSender(String host, int port) %7B%0D%0A        this.host = host;%0D%0A        this.port = port;%0D%0A    %7D%0D%0A    /**%0D%0A     * Connects the host server.%0D%0A     * @return true if connected, otherwise false%0D%0A     */%0D%0A    private boolean connect() %7B%0D%0A        Socket s = null;%0D%0A        if (null == socket) %7B%0D%0A            try %7B%0D%0A                s = new Socket(host, port);%0D%0A                output = new Output(s.getOutputStream());%0D%0A                socket = s;%0D%0A            %7D catch (UnknownHostException e) %7B%0D%0A                e.printStackTrace();%0D%0A            %7D catch (IOException e) %7B%0D%0A                e.printStackTrace();%0D%0A            %7D%0D%0A        %7D%0D%0A        return null != socket;%0D%0A    %7D%0D%0A    /**%0D%0A     * Sends the data bytes.%0D%0A     * @param bytes the bytes to be sent%0D%0A     */%0D%0A    public void send(byte%5B%5D bytes) %7B%0D%0A        if (connect()) %7B%0D%0A            output.writeInt(bytes.length);%0D%0A            output.writeBytes(bytes);%0D%0A            output.flush();%0D%0A        %7D%0D%0A    %7D%0D%0A    %0D%0A%7D%0D%0A

Send tuple via network