use of org.jgroups.Event in project hibernate-orm by hibernate.
the class TestDisconnectHandler method down.
@Override
public Object down(Event evt) {
switch(evt.getType()) {
case Event.SET_LOCAL_ADDRESS:
localAddress = (Address) evt.getArg();
log.trace("Set address " + localAddress);
break;
case Event.CONNECT:
case Event.CONNECT_WITH_STATE_TRANSFER:
case Event.CONNECT_USE_FLUSH:
case Event.CONNECT_WITH_STATE_TRANSFER_USE_FLUSH:
log.trace("Connecting on " + localAddress);
// we need to pass the message from below GMS (let's say regular FD* protocols
connected.add(getFD());
break;
case Event.DISCONNECT:
log.trace("Disconnecting on " + localAddress);
connected.remove(getFD());
// reduce view ack collection timeout to minimum, since we don't want to wait anymore
GMS gms = (GMS) getProtocolStack().findProtocol(GMS.class);
gms.setViewAckCollectionTimeout(1);
for (Protocol other : connected) {
executor.execute(() -> {
log.trace("Suspecting " + localAddress + " on " + other);
Event suspectEvent = new Event(Event.SUSPECT, localAddress);
other.up(suspectEvent);
other.down(suspectEvent);
});
}
break;
}
return super.down(evt);
}
use of org.jgroups.Event in project geode by apache.
the class JGroupsMessenger method start.
@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void start() {
// create the configuration XML string for JGroups
String properties = this.jgStackConfig;
long start = System.currentTimeMillis();
// start the jgroups channel and establish the membership ID
boolean reconnecting = false;
try {
Object oldChannel = services.getConfig().getTransport().getOldDSMembershipInfo();
if (oldChannel != null) {
logger.debug("Reusing JGroups channel from previous system", properties);
myChannel = (JChannel) oldChannel;
// scrub the old channel
ViewId vid = new ViewId(new JGAddress(), 0);
View jgv = new View(vid, new ArrayList<>());
this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
UUID logicalAddress = (UUID) myChannel.getAddress();
if (logicalAddress instanceof JGAddress) {
((JGAddress) logicalAddress).setVmViewId(-1);
}
reconnecting = true;
} else {
logger.debug("JGroups configuration: {}", properties);
checkForIPv6();
InputStream is = new ByteArrayInputStream(properties.getBytes("UTF-8"));
myChannel = new JChannel(is);
}
} catch (Exception e) {
throw new GemFireConfigException("unable to create jgroups channel", e);
}
// give the stats to the jchannel statistics recorder
StatRecorder sr = (StatRecorder) myChannel.getProtocolStack().findProtocol(StatRecorder.class);
if (sr != null) {
sr.setServices(services);
}
Transport transport = (Transport) myChannel.getProtocolStack().getTransport();
transport.setMessenger(this);
nackack2HeaderId = ClassConfigurator.getProtocolId(NAKACK2.class);
try {
myChannel.setReceiver(null);
myChannel.setReceiver(new JGroupsReceiver());
if (!reconnecting) {
// apache g***** (whatever we end up calling it)
myChannel.connect("AG");
}
} catch (Exception e) {
myChannel.close();
throw new SystemConnectException("unable to create jgroups channel", e);
}
if (JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK) {
JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK = false;
throw new SystemConnectException("failing for test");
}
establishLocalAddress();
logger.info("JGroups channel {} (took {}ms)", (reconnecting ? "reinitialized" : "created"), System.currentTimeMillis() - start);
}
use of org.jgroups.Event in project geode by apache.
the class JGroupsMessenger method establishLocalAddress.
private void establishLocalAddress() {
UUID logicalAddress = (UUID) myChannel.getAddress();
logicalAddress = logicalAddress.copy();
IpAddress ipaddr = (IpAddress) myChannel.down(new Event(Event.GET_PHYSICAL_ADDRESS));
if (ipaddr != null) {
this.jgAddress = new JGAddress(logicalAddress, ipaddr);
} else {
UDP udp = (UDP) myChannel.getProtocolStack().getTransport();
try {
Method getAddress = UDP.class.getDeclaredMethod("getPhysicalAddress");
getAddress.setAccessible(true);
ipaddr = (IpAddress) getAddress.invoke(udp, new Object[0]);
this.jgAddress = new JGAddress(logicalAddress, ipaddr);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
logger.info("Unable to find getPhysicallAddress method in UDP - parsing its address instead");
}
// if (this.jgAddress == null) {
// String addr = udp.getLocalPhysicalAddress();
// int cidx = addr.lastIndexOf(':'); // IPv6 literals might have colons
// String host = addr.substring(0, cidx);
// int jgport = Integer.parseInt(addr.substring(cidx+1, addr.length()));
// try {
// this.jgAddress = new JGAddress(logicalAddress, new IpAddress(InetAddress.getByName(host),
// jgport));
// } catch (UnknownHostException e) {
// myChannel.disconnect();
// throw new SystemConnectException("unable to initialize jgroups address", e);
// }
// }
}
// install the address in the JGroups channel protocols
myChannel.down(new Event(Event.SET_LOCAL_ADDRESS, this.jgAddress));
DistributionConfig config = services.getConfig().getDistributionConfig();
boolean isLocator = (services.getConfig().getTransport().getVmKind() == DistributionManager.LOCATOR_DM_TYPE) || !services.getConfig().getDistributionConfig().getStartLocator().isEmpty();
// establish the DistributedSystem's address
DurableClientAttributes dca = null;
if (config.getDurableClientId() != null) {
dca = new DurableClientAttributes(config.getDurableClientId(), config.getDurableClientTimeout());
}
MemberAttributes attr = new MemberAttributes(-1, /* dcPort - not known at this time */
OSProcess.getId(), services.getConfig().getTransport().getVmKind(), -1, /* view id - not known at this time */
config.getName(), MemberAttributes.parseGroups(config.getRoles(), config.getGroups()), dca);
localAddress = new InternalDistributedMember(jgAddress.getInetAddress(), jgAddress.getPort(), config.getEnableNetworkPartitionDetection(), isLocator, attr);
// add the JGroups logical address to the GMSMember
UUID uuid = this.jgAddress;
GMSMember gmsMember = (GMSMember) localAddress.getNetMember();
gmsMember.setUUID(uuid);
gmsMember.setMemberWeight((byte) (services.getConfig().getMemberWeight() & 0xff));
gmsMember.setNetworkPartitionDetectionEnabled(services.getConfig().getDistributionConfig().getEnableNetworkPartitionDetection());
}
use of org.jgroups.Event in project geode by apache.
the class JGroupsMessenger method filterIncomingMessage.
void filterIncomingMessage(DistributionMessage m) {
switch(m.getDSFID()) {
case JOIN_RESPONSE:
JoinResponseMessage jrsp = (JoinResponseMessage) m;
if (jrsp.getRejectionMessage() == null && services.getConfig().getTransport().isMcastEnabled()) {
byte[] serializedDigest = jrsp.getMessengerData();
ByteArrayInputStream bis = new ByteArrayInputStream(serializedDigest);
DataInputStream dis = new DataInputStream(bis);
try {
Digest digest = new Digest();
digest.readFrom(dis);
logger.trace("installing JGroups message digest {}", digest);
this.myChannel.getProtocolStack().getTopProtocol().down(new Event(Event.MERGE_DIGEST, digest));
jrsp.setMessengerData(null);
} catch (Exception e) {
logger.fatal("Unable to read JGroups messaging digest", e);
}
}
break;
default:
break;
}
}
use of org.jgroups.Event in project geode by apache.
the class JGroupsMessenger method installView.
@Override
public void installView(NetView v) {
this.view = v;
if (this.jgAddress.getVmViewId() < 0) {
this.jgAddress.setVmViewId(this.localAddress.getVmViewId());
}
List<JGAddress> mbrs = new ArrayList<>(v.size());
mbrs.addAll(v.getMembers().stream().map(JGAddress::new).collect(Collectors.toList()));
ViewId vid = new ViewId(new JGAddress(v.getCoordinator()), v.getViewId());
View jgv = new View(vid, new ArrayList<>(mbrs));
logger.trace("installing JGroups view: {}", jgv);
this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
addressesWithIoExceptionsProcessed.clear();
if (encrypt != null) {
encrypt.installView(v);
}
synchronized (scheduledMcastSeqnos) {
for (DistributedMember mbr : v.getCrashedMembers()) {
scheduledMcastSeqnos.remove(mbr);
}
for (DistributedMember mbr : v.getShutdownMembers()) {
scheduledMcastSeqnos.remove(mbr);
}
}
}
Aggregations