001: // $Id: MessageListStreamableTest.java,v 1.2 2005/04/13 13:02:39 belaban Exp $
002:
003: package org.jgroups.tests;
004:
005: /**
006: * @author Bela Ban
007: * @version $Id: MessageListStreamableTest.java,v 1.2 2005/04/13 13:02:39 belaban Exp $
008: */
009:
010: import org.apache.commons.logging.Log;
011: import org.apache.commons.logging.LogFactory;
012: import org.jgroups.Message;
013: import org.jgroups.conf.ClassConfigurator;
014: import org.jgroups.protocols.*;
015: import org.jgroups.stack.IpAddress;
016: import org.jgroups.util.Buffer;
017: import org.jgroups.util.Util;
018:
019: import java.net.InetAddress;
020: import java.util.LinkedList;
021:
022: public class MessageListStreamableTest {
023: static final Log log = LogFactory
024: .getLog(MessageListStreamableTest.class);
025:
026: public MessageListStreamableTest() {
027: }
028:
029: public static void main(String[] args) throws Exception {
030: boolean add_headers = false;
031: InetAddress addr = InetAddress.getLocalHost();
032: int num = 10000;
033:
034: for (int i = 0; i < args.length; i++) {
035: if ("-add_headers".equals(args[i])) {
036: add_headers = true;
037: continue;
038: }
039: if ("-num".equals(args[i])) {
040: num = Integer.parseInt(args[++i]);
041: continue;
042: }
043: help();
044: return;
045: }
046:
047: Buffer buf;
048: LinkedList list = new LinkedList();
049: ClassConfigurator.getInstance(true);
050: long start = System.currentTimeMillis();
051: long stop;
052: for (int i = 0; i < num; i++) {
053: Message m = new Message(new IpAddress(addr, 5555),
054: new IpAddress(addr, 6666), new byte[256]);
055: if (add_headers)
056: addHeaders(m);
057: list.add(m);
058: }
059:
060: start = System.currentTimeMillis();
061: buf = Util.msgListToByteBuffer(list);
062: stop = System.currentTimeMillis();
063: System.out.println("Marshalling a message list of "
064: + list.size() + " elements took " + (stop - start)
065: + "ms.");
066:
067: start = System.currentTimeMillis();
068: LinkedList list2 = Util.byteBufferToMessageList(buf.getBuf(),
069: buf.getOffset(), buf.getLength());
070: stop = System.currentTimeMillis();
071: System.out.println("Unmarshalling a message list of "
072: + list2.size() + " elements took " + (stop - start)
073: + "ms.");
074: }
075:
076: /**
077: * Adds some dummy headers to the message
078: */
079: static void addHeaders(Message msg) {
080: msg.putHeader("UDP", new UdpHeader("MyGroup"));
081: msg.putHeader("PING", new PingHeader(PingHeader.GET_MBRS_REQ,
082: null));
083: msg.putHeader("FD_SOCK", new FD_SOCK.FdHeader());
084: msg.putHeader("VERIFY_SUSPECT",
085: new VERIFY_SUSPECT.VerifyHeader());
086: msg.putHeader("STABLE",
087: new org.jgroups.protocols.pbcast.STABLE.StableHeader());
088: msg.putHeader("NAKACK",
089: new org.jgroups.protocols.pbcast.NakAckHeader());
090: msg.putHeader("UNICAST", new UNICAST.UnicastHeader());
091: msg.putHeader("FRAG", new FragHeader());
092: msg.putHeader("GMS",
093: new org.jgroups.protocols.pbcast.GMS.GmsHeader());
094: }
095:
096: static void help() {
097: System.out
098: .println("MessageSerializationTest [-help] [-add_headers] [-num <iterations>] "
099: + "[-use_magic] [-use_streamable]");
100: }
101: }
|