Package org.jgroups

Examples of org.jgroups.Message


    @SuppressWarnings("unchecked")
    public Object up(Event evt) {
        switch(evt.getType()) {

            case Event.MSG:
                Message msg=(Message)evt.getArg();
                if(msg.isFlagSet(Message.NO_FC))
                    break;

                Address dest=msg.getDest();
                boolean multicast=dest == null || dest.isMulticastAddress();
                boolean handle_multicasts=handleMulticastMessage();
                FcHeader hdr=(FcHeader)msg.getHeader(this.id);
                boolean process=(handle_multicasts && multicast) || (!handle_multicasts && !multicast) || hdr != null;
                if(!process)
                    break;
               
                if(hdr != null) {
                    switch(hdr.type) {
                        case FcHeader.REPLENISH:
                            num_credit_responses_received++;
                            handleCredit(msg.getSrc(), (Long)msg.getObject());
                            break;
                        case FcHeader.CREDIT_REQUEST:
                            num_credit_requests_received++;
                            Address sender=msg.getSrc();
                            Long requested_credits=(Long)msg.getObject();
                            if(requested_credits != null)
                                handleCreditRequest(received, sender, requested_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



    protected void sendCredit(Address dest, long credits) {
        if(log.isTraceEnabled())
            if(log.isTraceEnabled()) log.trace("sending " + credits + " credits to " + dest);
        Message msg=new Message(dest, null, new Long(credits));
        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_needed The number of bytes (of credits) left for dest
     */
    protected void sendCreditRequest(final Address dest, Long credits_needed) {
        if(log.isTraceEnabled())
            log.trace("sending request for " + credits_needed + " credits to " + dest);
        Message msg=new Message(dest, null, credits_needed);
        msg.putHeader(this.id, CREDIT_REQUEST_HDR);
        down_prot.down(new Event(Event.MSG, msg));
        num_credit_requests_sent++;
    }
View Full Code Here

    public Object up(Event evt) {
        switch(evt.getType()) {

            case Event.MSG:
                Message msg=(Message)evt.getArg();
                // Do something with the event, e.g. extract the message and remove a header.
                // Optionally pass up
                break;
        }
View Full Code Here

                            members.addElement(new_members.elementAt(i));
                }
                return down_prot.down(evt);

            case Event.MSG:
                Message msg=(Message)evt.getArg();
                // Do something with the event, e.g. add a header to the message
                // Optionally pass down
                break;
        }
View Full Code Here

     * are used)
     * @param evt
     */
    public Object down(Event evt) {
        if(evt.getType() == Event.MSG) {
            Message msg=(Message)evt.getArg();
            int length=msg.getLength(); // takes offset/length (if set) into account
            if(length >= min_size) {
                byte[] payload=msg.getRawBuffer(); // here we get the ref so we can avoid copying
                byte[] compressed_payload=new byte[length];
                int compressed_size;
                Deflater deflater=null;
                try {
                    deflater=deflater_pool.take();
                    deflater.reset();
                    deflater.setInput(payload, msg.getOffset(), length);
                    deflater.finish();
                    deflater.deflate(compressed_payload);
                    compressed_size=deflater.getTotalOut();

                    if ( compressed_size < length ) { // JGRP-1000
                        byte[] new_payload=new byte[compressed_size];
                        System.arraycopy(compressed_payload, 0, new_payload, 0, compressed_size);
                        msg.setBuffer(new_payload);
                        msg.putHeader(this.id, new CompressHeader(length));
                        if(log.isTraceEnabled())
                            log.trace("compressed payload from " + length + " bytes to " + compressed_size + " bytes");
                    }
                    else {
                        if(log.isTraceEnabled())
View Full Code Here

     * If there is no header, we pass the message up. Otherwise we uncompress the payload to its original size.
     * @param evt
     */
    public Object up(Event evt) {
        if(evt.getType() == Event.MSG) {
            Message msg=(Message)evt.getArg();
            CompressHeader hdr=(CompressHeader)msg.getHeader(this.id);
            if(hdr != null) {
                byte[] compressed_payload=msg.getRawBuffer();
                if(compressed_payload != null && compressed_payload.length > 0) {
                    int original_size=hdr.original_size;
                    byte[] uncompressed_payload=new byte[original_size];
                    Inflater inflater=null;
                    try {
                        inflater=inflater_pool.take();
                        inflater.reset();
                        inflater.setInput(compressed_payload, msg.getOffset(), msg.getLength());
                        try {
                            inflater.inflate(uncompressed_payload);
                            if(log.isTraceEnabled())
                                log.trace("uncompressed " + compressed_payload.length + " bytes to " + original_size +
                                        " bytes");
                            // we need to copy: https://jira.jboss.org/jira/browse/JGRP-867
                            Message copy=msg.copy(false);
                            copy.setBuffer(uncompressed_payload);
                            return up_prot.up(new Event(Event.MSG, copy));
                            // msg.setBuffer(uncompressed_payload);
                        }
                        catch(DataFormatException e) {
                            if(log.isErrorEnabled()) log.error("exception on uncompression", e);
View Full Code Here

                corr.sendRequest(requestId, targetMembers, request_msg, options.getMode() == GET_NONE? null : this, options);
            }
            else {
                if(options.getAnycasting()) {
                    for(Address mbr: targetMembers) {
                        Message copy=request_msg.copy(true);
                        copy.setDest(mbr);
                        transport.send(copy);
                    }
                }
                else {
                    transport.send(request_msg);
View Full Code Here

        channel = new JChannel(props);
        modifyChannel(channel);
        channel.connect("testConnectSendMessage");

        channel.send(new Message(null, null, "payload"));

        Message msg = msgPromise.getResult(20000);
        assert msg != null;
        assert "payload".equals(msg.getObject());
    }
View Full Code Here

        channel.connect("testConnectSendMessageSecondGRDown");

        Util.sleep(1000);
        gr2.stop();

        channel.send(new Message(null, null, "payload"));

        View view = coordinator.getView();
        assert view.size() == 2;
        assert view.containsMember(coordinator.getLocalAddress());
        assert view.containsMember(channel.getLocalAddress());

        view = channel.getView();
        assert view.size() == 2;
        assert view.containsMember(coordinator.getLocalAddress());
        assert view.containsMember(channel.getLocalAddress());

        Message msg = msgPromise.getResult(20000);
        assert msg != null;
        assert "payload".equals(msg.getObject());

    }
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.