Package dijjer.io.comm

Examples of dijjer.io.comm.MessageType


public class MessageTest extends TestCase {

  public static final String VERSION = "$Id: MessageTest.java,v 1.9 2005/04/12 13:04:15 sanity Exp $";

  public void testMessage() throws Exception {
    MessageType request = new MessageType("Request");
    request.addField("boolean", Boolean.class);
    request.addField("byte", Byte.class);
    request.addField("short", Short.class);
    request.addField("int", Integer.class);
    request.addField("string", String.class);
    request.addField("buffer", Buffer.class);
    request.addLinkedListField("list", String.class);
    Message m1 = new Message(request);
    m1.set("boolean", true);
    m1.set("byte", (byte) 15);
    m1.set("short", (short) 32);
    m1.set("int", (int) 64);
    m1.set("string", "gnirts");
    Buffer b = new Buffer(new byte[10]);
    m1.set("buffer", b);
    LinkedList ll = new LinkedList();
    ll.add("one");
    ll.add("two");
    ll.add("three");
    m1.set("list", ll);
    System.out.println("Original: " + m1);
    DatagramPacket dp = m1.encodeToPacket();
    Message m2 = Message.decodeFromPacket(dp);
    System.out.println("Decoded: " + m2);
    MessageFilter filter1 = MessageFilter.create(1000, request).setField("string", "abacus");
    MessageFilter filter2 = MessageFilter.create(1000, request).setField("string", "gnirts");
    assertFalse(filter1.match(m2));
    assertTrue(filter2.match(m2));

    request.unregister();
   
    MessageType shortRequest = new MessageType("Request");
    shortRequest.addField("boolean", Boolean.class);
    shortRequest.addField("byte", Byte.class);
    shortRequest.addField("short", Short.class);
    shortRequest.addField("int", Integer.class);
   
    Message m3 = Message.decodeFromPacket(dp);
    System.out.println("Short decoded: "+m3);
   
    Message m4 = new Message(shortRequest);
    m4.set("boolean", true);
    m4.set("byte", (byte) 15);
    m4.set("short", (short) 32);
    m4.set("int", (int) 64);
   
    DatagramPacket dp2 = m4.encodeToPacket();
   
    shortRequest.unregister();
   
    request = new MessageType("Request");
    request.addField("boolean", Boolean.class);
    request.addField("byte", Byte.class);
    request.addField("short", Short.class);
    request.addField("int", Integer.class);
    request.addField("string", String.class);
View Full Code Here


    public void testManager() throws Exception {

        final Peer source = new Peer(Inet4Address.getLocalHost(), (short) 5555);
        final Peer dest = new Peer(Inet4Address.getLocalHost(), (short) 5556);
        final MessageType ping = DMT.ping;
        final MessageType pong = DMT.pong;
        final UdpSocketManager sourceUSM = new UdpSocketManager((short) 5555);
        final UdpSocketManager destUSM = new UdpSocketManager((short) 5556);
        ping.addField("id", Integer.class);
        pong.addField("id", Integer.class);
        // Sender
        Misc.startThread(new Runnable() {
            public void run() {
                int id = 0;
                for(int i=0;i<15;i++) {
View Full Code Here

TOP

Related Classes of dijjer.io.comm.MessageType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.