use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class JGroupsMessengerJUnitTest method createAddress.
/**
* creates an InternalDistributedMember address that can be used with the doctored JGroups
* channel. This includes a logical (UUID) address and a physical (IpAddress) address.
*
* @param port the UDP port to use for the new address
*/
private InternalDistributedMember createAddress(int port) {
GMSMember gms = new GMSMember("localhost", port);
gms.setUUID(UUID.randomUUID());
gms.setVmKind(DistributionManager.NORMAL_DM_TYPE);
gms.setVersionOrdinal(Version.CURRENT_ORDINAL);
return new InternalDistributedMember(gms);
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class JGroupsMessengerJUnitTest method testMemberWeightIsSerialized.
@Test
public void testMemberWeightIsSerialized() throws Exception {
HeapDataOutputStream out = new HeapDataOutputStream(500, Version.CURRENT);
InternalDistributedMember mbr = createAddress(8888);
((GMSMember) mbr.getNetMember()).setMemberWeight((byte) 40);
mbr.toData(out);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(out.toByteArray()));
mbr = new InternalDistributedMember();
mbr.fromData(in);
assertEquals(40, mbr.getNetMember().getMemberWeight());
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class JGroupsMessenger method serializeMessage.
byte[] serializeMessage(DistributionMessage gfmsg, HeapDataOutputStream out_stream) throws IOException {
GMSMember m = (GMSMember) this.localAddress.getNetMember();
m.writeEssentialData(out_stream);
DataSerializer.writeObject(gfmsg, out_stream);
return out_stream.toByteArray();
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class JGroupsMessenger method send.
private Set<InternalDistributedMember> send(DistributionMessage msg, boolean reliably) {
// perform the same jgroups messaging as in 8.2's GMSMembershipManager.send() method
// BUT: when marshalling messages we need to include the version of the product and
// localAddress at the beginning of the message. These should be used in the receiver
// code to create a versioned input stream, read the sender address, then read the message
// and set its sender address
DMStats theStats = services.getStatistics();
NetView oldView = this.view;
if (!myChannel.isConnected()) {
logger.info("JGroupsMessenger channel is closed - messaging is not possible");
throw new DistributedSystemDisconnectedException("Distributed System is shutting down");
}
filterOutgoingMessage(msg);
// the message's processor if necessary
if ((msg instanceof DirectReplyMessage) && msg.isDirectAck() && msg.getProcessorId() <= 0) {
((DirectReplyMessage) msg).registerProcessor();
}
InternalDistributedMember[] destinations = msg.getRecipients();
boolean allDestinations = msg.forAll();
boolean useMcast = false;
if (services.getConfig().getTransport().isMcastEnabled()) {
if (msg.getMulticast() || allDestinations) {
useMcast = services.getManager().isMulticastAllowed();
}
}
if (logger.isDebugEnabled() && reliably) {
String recips = useMcast ? "multicast" : Arrays.toString(msg.getRecipients());
logger.debug("sending via JGroups: [{}] recipients: {}", msg, recips);
}
JGAddress local = this.jgAddress;
if (useMcast) {
long startSer = theStats.startMsgSerialization();
Message jmsg = createJGMessage(msg, local, Version.CURRENT_ORDINAL);
theStats.endMsgSerialization(startSer);
Exception problem;
try {
jmsg.setTransientFlag(TransientFlag.DONT_LOOPBACK);
if (!reliably) {
jmsg.setFlag(Message.Flag.NO_RELIABILITY);
}
theStats.incSentBytes(jmsg.getLength());
logger.trace("Sending JGroups message: {}", jmsg);
myChannel.send(jmsg);
} catch (Exception e) {
logger.debug("caught unexpected exception", e);
Throwable cause = e.getCause();
if (cause instanceof ForcedDisconnectException) {
problem = (Exception) cause;
} else {
problem = e;
}
if (services.getShutdownCause() != null) {
Throwable shutdownCause = services.getShutdownCause();
// problem.
if (shutdownCause instanceof ForcedDisconnectException) {
problem = (Exception) shutdownCause;
} else {
Throwable ne = problem;
while (ne.getCause() != null) {
ne = ne.getCause();
}
ne.initCause(services.getShutdownCause());
}
}
final String channelClosed = LocalizedStrings.GroupMembershipService_CHANNEL_CLOSED.toLocalizedString();
// services.getManager().membershipFailure(channelClosed, problem);
throw new DistributedSystemDisconnectedException(channelClosed, problem);
}
} else // useMcast
{
// ! useMcast
int len = destinations.length;
// explicit list of members
List<GMSMember> calculatedMembers;
// == calculatedMembers.len
int calculatedLen;
if (len == 1 && destinations[0] == DistributionMessage.ALL_RECIPIENTS) {
// send to all
// Grab a copy of the current membership
NetView v = services.getJoinLeave().getView();
// Construct the list
calculatedLen = v.size();
calculatedMembers = new LinkedList<GMSMember>();
for (int i = 0; i < calculatedLen; i++) {
InternalDistributedMember m = (InternalDistributedMember) v.get(i);
calculatedMembers.add((GMSMember) m.getNetMember());
}
} else // send to all
{
// send to explicit list
calculatedLen = len;
calculatedMembers = new LinkedList<GMSMember>();
for (int i = 0; i < calculatedLen; i++) {
calculatedMembers.add((GMSMember) destinations[i].getNetMember());
}
}
// send to explicit list
Int2ObjectOpenHashMap<Message> messages = new Int2ObjectOpenHashMap<>();
long startSer = theStats.startMsgSerialization();
boolean firstMessage = true;
for (GMSMember mbr : calculatedMembers) {
short version = mbr.getVersionOrdinal();
if (!messages.containsKey(version)) {
Message jmsg = createJGMessage(msg, local, version);
messages.put(version, jmsg);
if (firstMessage) {
theStats.incSentBytes(jmsg.getLength());
firstMessage = false;
}
}
}
theStats.endMsgSerialization(startSer);
Collections.shuffle(calculatedMembers);
int i = 0;
for (GMSMember mbr : calculatedMembers) {
JGAddress to = new JGAddress(mbr);
short version = mbr.getVersionOrdinal();
Message jmsg = messages.get(version);
Exception problem = null;
try {
Message tmp = (i < (calculatedLen - 1)) ? jmsg.copy(true) : jmsg;
if (!reliably) {
jmsg.setFlag(Message.Flag.NO_RELIABILITY);
}
tmp.setDest(to);
tmp.setSrc(this.jgAddress);
logger.trace("Unicasting to {}", to);
myChannel.send(tmp);
} catch (Exception e) {
problem = e;
}
if (problem != null) {
Throwable cause = services.getShutdownCause();
if (cause != null) {
// problem.
if (cause instanceof ForcedDisconnectException) {
problem = (Exception) cause;
} else {
Throwable ne = problem;
while (ne.getCause() != null) {
ne = ne.getCause();
}
ne.initCause(cause);
}
}
final String channelClosed = LocalizedStrings.GroupMembershipService_CHANNEL_CLOSED.toLocalizedString();
// services.getManager().membershipFailure(channelClosed, problem);
throw new DistributedSystemDisconnectedException(channelClosed, problem);
}
}
// send individually
}
// (i.e., left the view), we signal it here.
if (msg.forAll()) {
return Collections.emptySet();
}
Set<InternalDistributedMember> result = new HashSet<>();
NetView newView = this.view;
if (newView != null && newView != oldView) {
for (InternalDistributedMember d : destinations) {
if (!newView.contains(d)) {
logger.debug("messenger: member has left the view: {} view is now {}", d, newView);
result.add(d);
}
}
}
return result;
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class JGroupsMessenger method deserializeMessage.
DistributionMessage deserializeMessage(DataInputStream in, short ordinal) throws ClassNotFoundException, IOException {
GMSMember m = new GMSMember();
m.readEssentialData(in);
DistributionMessage result = (DistributionMessage) DataSerializer.readObject(in);
setSender(result, m, ordinal);
return result;
}
Aggregations