void sendMessages() throws Exception { if (num_threads > 1 && num_msgs % num_threads != 0) { System.err.println( "num_msgs (" + num_msgs + " ) has to be divisible by num_threads (" + num_threads + ")"); return; } System.out.println( "sending " + num_msgs + " messages (" + Util.printBytes(msg_size) + ") to " + remote + ": oob=" + oob + ", " + num_threads + " sender thread(s)"); ByteBuffer buf = ByteBuffer.allocate(Global.BYTE_SIZE + Global.LONG_SIZE).put(START).putLong(num_msgs); Message msg = new Message(null, buf.array()); // msg.writeTo(output); ExposedByteArrayOutputStream out_stream = new ExposedByteArrayOutputStream((int) (msg.size())); ExposedDataOutputStream dos = new ExposedDataOutputStream(out_stream); byte flags = 0; dos.writeShort(Version.version); // write the version if (msg.getDest() == null) flags += (byte) 2; dos.writeByte(flags); msg.writeTo(dos); Buffer buffer = new Buffer(out_stream.getRawBuffer(), 0, out_stream.size()); output_lock.lock(); // need to sync if we have more than 1 sender try { // msg.writeTo(output); output.writeInt(buffer.getLength()); output.write(buffer.getBuf(), buffer.getOffset(), buffer.getLength()); } finally { output_lock.unlock(); } int msgs_per_sender = num_msgs / num_threads; Sender[] senders = new Sender[num_threads]; for (int i = 0; i < senders.length; i++) senders[i] = new Sender(msgs_per_sender, msg_size, num_msgs / 10); for (Sender sender : senders) sender.start(); for (Sender sender : senders) sender.join(); output.flush(); System.out.println("done sending " + num_msgs + " to " + remote); }