Package org.jgroups

Examples of org.jgroups.Message


     * into the send queue and let one or more worker threads handle it. A worker thread
     * then removes the Message from the send queue, performs a conversion and adds the
     * modified Message to the send queue of the layer below it, by calling Down).
     */
    public Object down(Event evt) {
        Message msg;
        Address dest_addr;


        switch(evt.getType()) {

        case Event.MSG:
            if(done) {
                break;
            }
            msg=(Message)evt.getArg();
            dest_addr=msg.getDest();
            if(dest_addr == null)
                num_msgs++;
            if(num_msgs >= expected_msgs) {
                stop=System.currentTimeMillis();
                synchronized(this) {
View Full Code Here


        return null;
    }


    public Object up(Event evt) {
        Message msg;
        Address dest_addr;
        switch(evt.getType()) {

        case Event.MSG:
            if(done) {
                if(log.isWarnEnabled()) log.warn("all done (discarding msg)");
                break;
            }
            msg=(Message)evt.getArg();
            dest_addr=msg.getDest();
            if(dest_addr == null)
                num_msgs++;
            if(num_msgs >= expected_msgs) {
                stop=System.currentTimeMillis();
                synchronized(this) {
View Full Code Here

        c3.connect("NAKACK_OOB_Test");

        assert c3.getView().getMembers().size() == 3 : "view is " + c3.getView() + ", expected view of 3 members";

        for(int i=1; i <=5; i++) {
            Message msg=new Message(null, null, new Long(i));
            if(i == 4)
                msg.setFlag(Message.OOB);
            System.out.println("-- sending message #" + i);
            c1.send(msg);
            Util.sleep(100);
        }
View Full Code Here

    @SuppressWarnings("unchecked")
    public Object down(Event evt) {
        switch(evt.getType()) {
            case Event.MSG:
                Message msg=(Message)evt.getArg();
                if(msg.isFlagSet(Message.NO_FC))
                    break;
                int length=msg.getLength();
                if(length == 0)
                    break;
                return handleDownMessage(evt, msg, length);
            case Event.CONFIG:
                handleConfigEvent((Map<String,Object>)evt.getArg());
View Full Code Here

            case Event.MSG:

                // JGRP-465. We only deal with msgs to avoid having to use a concurrent collection; ignore views,
                // suspicions, etc which can come up on unusual threads.
                Message msg=(Message)evt.getArg();
                if(msg.isFlagSet(Message.NO_FC))
                    break;
                FcHeader hdr=(FcHeader)msg.getHeader(this.id);
                if(hdr != null) {
                    switch(hdr.type) {
                        case FcHeader.REPLENISH:
                            num_credit_responses_received++;
                            handleCredit(msg.getSrc(), (Number)msg.getObject());
                            break;
                        case FcHeader.CREDIT_REQUEST:
                            num_credit_requests_received++;
                            Address sender=msg.getSrc();
                            Long sent_credits=(Long)msg.getObject();
                            if(sent_credits != null)
                                handleCreditRequest(received, sender, sent_credits.longValue());
                            break;
                        default:
                            log.error("header type " + hdr.type + " not known");
                            break;
                    }
                    return null; // don't pass message up
                }

                Address sender=msg.getSrc();
                long new_credits=adjustCredit(received, sender, msg.getLength());
               
                // JGRP-928: changed ignore_thread to a ThreadLocal: multiple threads can access it with the
                // introduction of the concurrent stack
                if(ignore_synchronous_response)
                    ignore_thread.set(true);
View Full Code Here

        Number number;
        if(credit < Integer.MAX_VALUE)
            number=(int)credit;
        else
            number=credit;
        Message msg=new Message(dest, null, number);
        msg.setFlag(Message.OOB);
        msg.putHeader(this.id, REPLENISH_HDR);
        down_prot.down(new Event(Event.MSG, msg));
        num_credit_responses_sent++;
    }
View Full Code Here

     * @param credits_left The number of bytes (of credits) left for dest
     */
    private void sendCreditRequest(final Address dest, Long credits_left) {
        if(log.isTraceEnabled())
            log.trace("sending credit request to " + dest);
        Message msg=new Message(dest, null, credits_left);
        msg.putHeader(this.id, CREDIT_REQUEST_HDR);
        down_prot.down(new Event(Event.MSG, msg));
        num_credit_requests_sent++;
    }
View Full Code Here


    private static Message createBigMessage(int size) {
        byte[] buf=new byte[size];
        for(int i=0; i < buf.length; i++) buf[i]=(byte)'x';
        return new Message(null, null, buf);
    }
View Full Code Here


    public void testRegularMessages() throws Exception {
        FragReceiver frag_receiver=new FragReceiver(this);
        ProtocolTester t=new ProtocolTester("FRAG2(frag_size=" + FRAG_SIZE + ')', frag_receiver);
        Message big_msg;
        IpAddress local_addr=new IpAddress(5555);

        System.out.println("\nProtocol for protocol tester: " + t.getProtocolSpec() + '\n');

        for(int i=0; i < NUM_MSGS; i++) {
            big_msg=createBigMessage(MSG_SIZE);
            big_msg.setSrc(local_addr);
            System.out.println("sending msg #" + i + " [" + big_msg.getLength() + " bytes]");
            frag_receiver.down(new Event(Event.MSG, big_msg));
            Util.sleep(10);
        }
        t.stop();
    }
View Full Code Here


    public void testMessagesWithOffsets() throws Exception {
        FragReceiver frag_receiver=new FragReceiver(this);
        ProtocolTester t=new ProtocolTester("FRAG2(frag_size=" + FRAG_SIZE + ')', frag_receiver);
        Message big_msg;
        IpAddress local_addr=new IpAddress(5555);

        System.out.println("\nProtocol for protocol tester: " + t.getProtocolSpec() + '\n');

        byte[] big_buffer=new byte[(int)(MSG_SIZE * NUM_MSGS)];

        int offset=0;

        for(int i=0; i < NUM_MSGS; i++) {
            big_msg=new Message(null, null, big_buffer, offset, MSG_SIZE);
            big_msg.setSrc(local_addr);
            System.out.println("sending msg #" + i + " [" + big_msg.getLength() + " bytes]");
            frag_receiver.down(new Event(Event.MSG, big_msg));
            Util.sleep(10);
            offset+=MSG_SIZE;
        }
        t.stop();
View Full Code Here

TOP

Related Classes of org.jgroups.Message

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.