Skip to content

Commit

Permalink
Changed to CompositeMessage (https://issues.redhat.com/browse/JGRP-2848)
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Nov 14, 2024
1 parent 84a36ca commit cd731b7
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/org/jgroups/CompositeMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.*;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -44,6 +41,11 @@ public CompositeMessage(Address dest, Message ... messages) {
add(messages);
}

public CompositeMessage(Address dest, Collection<Message> messages) {
super(dest);
add(messages);
}


public Supplier<Message> create() {return CompositeMessage::new;}
public short getType() {return collapse? Message.BYTES_MSG : Message.COMPOSITE_MSG;}
Expand Down Expand Up @@ -84,6 +86,12 @@ public CompositeMessage add(Message ... messages) {
return this;
}

public CompositeMessage add(Collection<Message> messages) {
ensureCapacity(index + messages.size());
for(Message msg: messages)
msgs[index++]=Objects.requireNonNull(ensureSameDest(msg));
return this;
}

public <T extends Message> T get(int index) {
return (T)msgs[index];
Expand Down Expand Up @@ -134,7 +142,7 @@ public void writePayload(DataOutput out) throws IOException {
for(int i=0; i < index; i++) {
Message msg=msgs[i];
out.writeShort(msg.getType());
msg.writeTo(out);
msg.writeToNoAddrs(src(), out);
}
}
}
Expand All @@ -147,6 +155,11 @@ public void readPayload(DataInput in) throws IOException, ClassNotFoundException
short type=in.readShort();
msgs[i]=MessageFactory.create(type);
msgs[i].readFrom(in);
Message msg=MessageFactory.create(type).setDest(getDest());
if(msg.getSrc() == null)
msg.setSrc(src());
msg.readFrom(in);
msgs[i]=msg;
}
}
}
Expand Down

0 comments on commit cd731b7

Please sign in to comment.