use of org.jgroups.View in project camel by apache.
the class JGroupsFilters method dropNonCoordinatorViews.
/**
* Creates predicate rejecting messages that are instances of {@code org.jgroups.View}, but have not been received
* by the coordinator JGroups node. This filter is useful for keeping only view messages indicating that receiving
* endpoint is a master node.
*
* @return predicate filtering out non-coordinator view messages.
*/
public static Predicate dropNonCoordinatorViews() {
return new Predicate() {
@Override
public boolean matches(Exchange exchange) {
Object body = exchange.getIn().getBody();
LOG.debug("Filtering message {}.", body);
if (body instanceof View) {
View view = (View) body;
Address coordinatorNodeAddress = view.getMembers().get(COORDINATOR_NODE_INDEX);
Address channelAddress = exchange.getIn().getHeader(HEADER_JGROUPS_CHANNEL_ADDRESS, Address.class);
LOG.debug("Comparing endpoint channel address {} against the coordinator node address {}.", channelAddress, coordinatorNodeAddress);
return channelAddress.equals(coordinatorNodeAddress);
}
LOG.debug("Body {} is not an instance of org.jgroups.View . Skipping filter.", body);
return false;
}
};
}
use of org.jgroups.View 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.View 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);
}
}
}
use of org.jgroups.View in project JGroups by belaban.
the class GossipRouterTest method testLateStart.
/**
* Tests the following scenario (http://jira.jboss.com/jira/browse/JGRP-682):
* - First node is started with tunnel.xml, cannot connect
* - Second node is started *with* GossipRouter
* - Now first node should be able to connect and first and second node should be able to merge into a group
* - SUCCESS: a view of 2
*/
public void testLateStart() throws Exception {
final Lock lock = new ReentrantLock();
final Condition cond = lock.newCondition();
AtomicBoolean done = new AtomicBoolean(false);
System.out.println("-- starting first channel");
a = createTunnelChannel("A");
a.setReceiver(new MyReceiver("c1", done, lock, cond));
a.connect("demo");
System.out.println("-- starting second channel");
b = createTunnelChannel("B");
b.setReceiver(new MyReceiver("c2", done, lock, cond));
b.connect("demo");
System.out.println("-- starting GossipRouter");
router = new GossipRouter(bind_addr_str, gossip_router_port);
router.start();
System.out.println("-- waiting for merge to happen --");
long target_time = System.currentTimeMillis() + 40000;
lock.lock();
try {
while (System.currentTimeMillis() < target_time && !done.get()) {
cond.await(1000, TimeUnit.MILLISECONDS);
}
} finally {
lock.unlock();
}
Util.sleep(500);
View view = a.getView();
System.out.println("view=" + view);
assert view.size() == 2 : "view=" + view;
Util.close(b, a);
}
use of org.jgroups.View in project JGroups by belaban.
the class INJECT_VIEWTest method checkViews.
private static void checkViews(JChannel[] channels, String channel_name, String... members) {
JChannel ch = findChannel(channel_name, channels);
View view = ch.getView();
assert view.size() == members.length : "view is " + view + ", members: " + Arrays.toString(members);
for (String member : members) {
Address addr = findAddress(member, channels);
assert view.getMembers().contains(addr) : "view " + view + " does not contain " + addr;
}
}
Aggregations