Package org.jgroups.util

Examples of org.jgroups.util.ByteArrayDataOutputStream


    @Override
    protected void sendMcastDiscoveryRequest(Message msg) {
        try {
            if(msg.getSrc() == null)
                msg.setSrc(local_addr);
            ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(128);
            msg.writeTo(out);
            for(int i=bind_port; i <= bind_port+port_range; i++) {
                DatagramPacket packet=new DatagramPacket(out.buffer(), 0, out.position(), dest_addr, i);
                sock.send(packet);
            }
        }
        catch(Exception ex) {
            log.error("failed sending discovery request", ex);
View Full Code Here


        TpHeader hdr=(TpHeader)msg.getHeader(this.id);
        if(hdr == null)
            throw new Exception("message " + msg + " doesn't have a transport header, cannot route it");
        String group=cluster_name != null? cluster_name.toString() : null;

        ByteArrayDataOutputStream dos=new ByteArrayDataOutputStream((int)(msg.size() + 50));
        writeMessage(msg, dos, dest == null);

        if(stats) {
            num_msgs_sent++;
            num_bytes_sent+=dos.position();
        }
        List<RouterStub> stubs = stubManager.getStubs();
        if(dest == null)
            tunnel_policy.sendToAllMembers(stubs, group, dos.buffer(), 0, dos.position());
        else
            tunnel_policy.sendToSingleMember(stubs, group, dest, dos.buffer(), 0, dos.position());
    }
View Full Code Here

        TpHeader hdr=(TpHeader)msg.getHeader(this.id);
        if(hdr == null)
            throw new Exception("message " + msg + " doesn't have a transport header, cannot route it");
        String group=cluster_name != null? cluster_name.toString() : null;

        ByteArrayDataOutputStream dos=new ByteArrayDataOutputStream((int)(msg.size() + 50));
        writeMessage(msg, dos, dest == null);

        if(stats) {
            num_msgs_sent++;
            num_bytes_sent+=dos.position();
        }
        List<RouterStub> stubs = stubManager.getStubs();
        if(dest == null)
            tunnel_policy.sendToAllMembers(stubs, group, dos.buffer(), 0, dos.position());
        else
            tunnel_policy.sendToSingleMember(stubs, group, dest, dos.buffer(), 0, dos.position());
    }
View Full Code Here

        return 100.0* (1.0 - (new_length / (double)old_length));
    }

    private static Buffer marshal(Message msg) throws Exception {
        ByteArrayDataOutputStream dos=new ByteArrayDataOutputStream((int)(msg.size() + 50));
        Address dest=msg.getDest();
        boolean multicast=dest == null;
        writeMessage(msg, dos, multicast);
        return dos.getBuffer();
    }
View Full Code Here

            assert ex instanceof IndexOutOfBoundsException;
        }
    }

    public void testExpanding() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(1);
        for(int i='A'; i < 'A' + 20; i++)
            out.write(i);
        assert out.position() == 20;

        byte[] buffer=new byte[20];
        for(int i=0; i < 5; i++)
            out.write(buffer);
        assert out.position() == 120;
    }
View Full Code Here

            out.write(buffer);
        assert out.position() == 120;
    }

    public void testExpanding2() {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(1);
        out.write(new byte[]{'b', 'e', 'l', 'a'});

        out=new ByteArrayDataOutputStream(1);
        out.writeBoolean(true);
        out.writeBoolean(false);

        out=new ByteArrayDataOutputStream(1);
        out.writeShort(22);
        out.writeShort(23);

        out=new ByteArrayDataOutputStream(1);
        out.writeInt(23);
        out.writeInt(24);
    }
View Full Code Here

            assert eof_ex instanceof EOFException;
        }
    }

    public void testByte() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(Byte.MAX_VALUE * 2);
        for(short i=Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++)
            out.writeByte(i);

        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(short i=Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) {
            byte read=in.readByte();
            assert i == read;
        }
    }
View Full Code Here

            assert i == read;
        }
    }

    public void testUnsignedByte() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(20);
        byte[] bytes={-100, -50, 0, 1, 100, 127};
        for(byte b: bytes)
            out.writeByte(b);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(byte b: bytes) {
            int tmp=in.readUnsignedByte();
            assert tmp == (b & 0xff);
        }
    }
View Full Code Here

            assert tmp == (b & 0xff);
        }
    }

    public void testBoolean() throws Exception {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(2);
        out.writeBoolean(true);
        out.writeBoolean(false);
        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        assert in.readBoolean();
        assert !in.readBoolean();
    }
View Full Code Here

        assert in.readBoolean();
        assert !in.readBoolean();
    }

    public void testShort() throws IOException {
        ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(Short.MAX_VALUE * 4 + 10);
        for(int i=Short.MIN_VALUE; i <= Short.MAX_VALUE; i++)
            out.writeShort(i);

        ByteArrayDataInputStream in=new ByteArrayDataInputStream(out.buffer());
        for(int i=Short.MIN_VALUE; i <= Short.MAX_VALUE; i++) {
            short read=in.readShort();
            assert i == read;
        }
    }
View Full Code Here

TOP

Related Classes of org.jgroups.util.ByteArrayDataOutputStream

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.