1 3 package org.jgroups.tests; 4 5 9 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 import org.jgroups.Message; 13 import org.jgroups.conf.ClassConfigurator; 14 import org.jgroups.protocols.*; 15 import org.jgroups.stack.IpAddress; 16 import org.jgroups.util.Buffer; 17 import org.jgroups.util.Util; 18 19 import java.net.InetAddress ; 20 import java.util.LinkedList ; 21 22 23 public class MessageListStreamableTest { 24 static final Log log=LogFactory.getLog(MessageListStreamableTest.class); 25 26 public MessageListStreamableTest() { 27 } 28 29 30 public static void main(String [] args) throws Exception { 31 boolean add_headers=false; 32 InetAddress addr=InetAddress.getLocalHost(); 33 int num=10000; 34 35 for(int i=0; i < args.length; i++) { 36 if("-add_headers".equals(args[i])) { 37 add_headers=true; 38 continue; 39 } 40 if("-num".equals(args[i])) { 41 num=Integer.parseInt(args[++i]); 42 continue; 43 } 44 help(); 45 return; 46 } 47 48 Buffer buf; 49 LinkedList list=new LinkedList (); 50 ClassConfigurator.getInstance(true); 51 long start=System.currentTimeMillis(); 52 long stop; 53 for(int i=0; i < num; i++) { 54 Message m=new Message(new IpAddress(addr, 5555), new IpAddress(addr, 6666), new byte[256]); 55 if(add_headers) 56 addHeaders(m); 57 list.add(m); 58 } 59 60 start=System.currentTimeMillis(); 61 buf=Util.msgListToByteBuffer(list); 62 stop=System.currentTimeMillis(); 63 System.out.println("Marshalling a message list of " + list.size() + " elements took " + (stop - start) + "ms."); 64 65 start=System.currentTimeMillis(); 66 LinkedList list2=Util.byteBufferToMessageList(buf.getBuf(), buf.getOffset(), buf.getLength()); 67 stop=System.currentTimeMillis(); 68 System.out.println("Unmarshalling a message list of " + list2.size() + " elements took " + (stop - start) + "ms."); 69 } 70 71 74 static void addHeaders(Message msg) { 75 msg.putHeader("UDP", new UdpHeader("MyGroup")); 76 msg.putHeader("PING", new PingHeader(PingHeader.GET_MBRS_REQ, null)); 77 msg.putHeader("FD_SOCK", new FD_SOCK.FdHeader()); 78 msg.putHeader("VERIFY_SUSPECT", new VERIFY_SUSPECT.VerifyHeader()); 79 msg.putHeader("STABLE", new org.jgroups.protocols.pbcast.STABLE.StableHeader()); 80 msg.putHeader("NAKACK", new org.jgroups.protocols.pbcast.NakAckHeader()); 81 msg.putHeader("UNICAST", new UNICAST.UnicastHeader()); 82 msg.putHeader("FRAG", new FragHeader()); 83 msg.putHeader("GMS", new org.jgroups.protocols.pbcast.GMS.GmsHeader()); 84 } 85 86 87 static void help() { 88 System.out.println("MessageSerializationTest [-help] [-add_headers] [-num <iterations>] " + 89 "[-use_magic] [-use_streamable]"); 90 } 91 } 92 | Popular Tags |