All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgroups.protocols.HDRS Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 32.0.0.Final
Show newest version

package org.jgroups.protocols;

import org.jgroups.Event;
import org.jgroups.Message;
import org.jgroups.Header;
import org.jgroups.conf.ClassConfigurator;
import org.jgroups.annotations.Unsupported;
import org.jgroups.stack.Protocol;
import org.jgroups.util.MessageBatch;

import java.util.Map;


/**
 * Example of a protocol layer. Contains no real functionality, can be used as a template.
 */
@Unsupported
public class HDRS extends Protocol {

    private static void printMessage(Message msg, String label) {
        StringBuilder sb=new StringBuilder();
        sb.append(label).append(":\n");
        Map hdrs=msg.getHeaders();
        sb.append(print(msg, hdrs));
        System.out.println(sb);
    }

    private static String print(Message msg, Map hdrs) {
        StringBuilder sb=new StringBuilder();
        int hdrs_size=0;
        for(Map.Entry entry: hdrs.entrySet()) {
            Class clazz=ClassConfigurator.getProtocol(entry.getKey());
            String name=clazz != null? clazz.getSimpleName() : null;
            Header hdr=entry.getValue();
            int size=hdr.size();
            hdrs_size+=size;
            sb.append(name).append(": ").append(" ").append(size).append(" bytes\n");
        }
        sb.append("headers=").append(hdrs_size).append(", total msg size=").append(msg.size());
        sb.append(", msg payload=").append(msg.getLength()).append("\n");
        return sb.toString();
    }




    public Object up(Event evt) {
        if(evt.getType() == Event.MSG) {
            Message msg=(Message)evt.getArg();
            printMessage(msg, "up");
        }
        return up_prot.up(evt); // Pass up to the layer above us
    }

    public void up(MessageBatch batch) {
        for(Message msg: batch)
            printMessage(msg, "up");
        if(!batch.isEmpty())
            up_prot.up(batch);
    }

    public Object down(Event evt) {
        if(evt.getType() == Event.MSG) {
            Message msg=(Message)evt.getArg();
            printMessage(msg, "down");
        }

        return down_prot.down(evt);  // Pass on to the layer below us
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy