"[-size <msg size (in bytes)] [-file_name <filename>] [-write] [-read]");
}
void start(String props, int num_msgs, int size, String file_name, boolean write) throws Exception {
Message msg;
Protocol transport;
byte[] buf=new byte[size];
Address local_addr;
View view;
if(file_name != null) {
if(write)
out=new DataOutputStream(new FileOutputStream(file_name));
else
in=new DataInputStream(new FileInputStream(file_name));
}
ch=new JChannel(props);
ch.setReceiver(new ExtendedReceiverAdapter());
ch.connect("demo");
tp=PERF_TP.getInstance();
local_addr=ch.getAddress();
Vector members=new Vector();
members.add(local_addr);
view=new View(local_addr, 0, members);
ch.down(new Event(Event.BECOME_SERVER));
ch.down(new Event(Event.VIEW_CHANGE, view));
if(write) {
tp.setExpectedMessages(num_msgs);
for(int i=0; i < num_msgs; i++) {
msg=new Message(null, local_addr, buf);
ch.send(msg);
if(out != null)
msg.writeTo(out);
if(i % 1000 == 0)
System.out.println("sent " + i + " messages");
}
}
else {
List msgs=new LinkedList();
List protocols=ch.getProtocolStack().getProtocols();
transport=(Protocol)protocols.get(protocols.size() -1);
int i=0;
while(true) {
msg=new Message();
try {
msg.readFrom(in);
msgs.add(msg);
}
catch(EOFException eof) {
break;
}
}
num_msgs=msgs.size();
System.out.println("read " + num_msgs + " msgs from file");
tp.setExpectedMessages(msgs.size()); // this starts the time
for(Iterator it=msgs.iterator(); it.hasNext();) {
msg=(Message)it.next();
i++;
transport.up(new Event(Event.MSG, msg));
if(i % 10000 == 0) {
System.out.println("passed up " + i + " messages");
}
}
}