use of org.apache.sling.discovery.InstanceDescription in project sling by apache.
the class ViewStateManagerImpl method handleNewView.
/* (non-Javadoc)
* @see org.apache.sling.discovery.commons.providers.impl.ViewStateManager#handleNewView(org.apache.sling.discovery.commons.providers.BaseTopologyView)
*/
@Override
public void handleNewView(final BaseTopologyView newView) {
logger.trace("handleNewView: start, newView={}", newView);
if (newView == null) {
throw new IllegalArgumentException("newView must not be null");
}
if (!newView.isCurrent()) {
logger.debug("handleNewView: newView is not current - calling handleChanging.");
handleChanging();
// false;
return;
}
// paranoia-testing:
InstanceDescription localInstance = newView.getLocalInstance();
if (localInstance == null) {
throw new IllegalStateException("newView does not contain the local instance - hence cannot be current");
}
if (!localInstance.isLocal()) {
throw new IllegalStateException("newView's local instance is not isLocal - very unexpected - hence cannot be current");
}
// cancel any potentially ongoing sync
if (consistencyService != null) {
consistencyService.cancelSync();
}
logger.debug("handleNewView: newView is current, so trying with minEventDelayHandler...");
if (minEventDelayHandler != null) {
if (minEventDelayHandler.handlesNewView(newView)) {
// true;
return;
} else {
logger.debug("handleNewView: event delaying not applicable this time, invoking hanldeNewViewNonDelayed next.");
}
} else {
logger.debug("handleNewView: minEventDelayHandler not set, invoking hanldeNewViewNonDelayed...");
}
handleNewViewNonDelayed(newView);
}
use of org.apache.sling.discovery.InstanceDescription in project sling by apache.
the class TopologyHelper method clone.
public static DefaultClusterView clone(DefaultClusterView original) {
DefaultClusterView c = new DefaultClusterView(original.getId());
Iterator<InstanceDescription> it = original.getInstances().iterator();
while (it.hasNext()) {
DefaultInstanceDescription id = (DefaultInstanceDescription) it.next();
c.addInstanceDescription(cloneWOClusterView(id));
}
return c;
}
use of org.apache.sling.discovery.InstanceDescription in project sling by apache.
the class AbstractSingleInstanceTest method testGetters.
@Test
public void testGetters() throws UndefinedClusterViewException, InterruptedException {
logger.info("testGetters: start");
assertNotNull(instance);
logger.info("sling id=" + instance.getSlingId());
try {
instance.getClusterViewService().getLocalClusterView();
// SLING-5030
fail("should complain");
} catch (UndefinedClusterViewException e) {
// ok
}
instance.heartbeatsAndCheckView();
// wait 4000ms for the vote to happen
Thread.sleep(4000);
assertNotNull(instance.getClusterViewService().getLocalClusterView());
ClusterView cv = instance.getClusterViewService().getLocalClusterView();
logger.info("cluster view: id=" + cv.getId());
assertNotNull(cv.getId());
assertNotSame(cv.getId(), "");
List<InstanceDescription> instances = cv.getInstances();
assertNotNull(instances);
assertTrue(instances.size() == 1);
InstanceDescription myInstance = instances.get(0);
assertNotNull(myInstance);
assertTrue(myInstance.getClusterView() == cv);
logger.info("instance id: " + myInstance.getSlingId());
assertEquals(instance.getSlingId(), myInstance.getSlingId());
Map<String, String> properties = myInstance.getProperties();
assertNotNull(properties);
assertNull(myInstance.getProperty("foo"));
assertTrue(myInstance.isLeader());
assertTrue(myInstance.isLocal());
logger.info("testGetters: end");
}
use of org.apache.sling.discovery.InstanceDescription in project sling by apache.
the class InstancesDiffTest method testIsInClusterView.
@Test
public void testIsInClusterView() throws Exception {
ClusterView clusterView = clusterView("viewId");
Collection<InstanceDescription> instances = new InstancesDiff(Arrays.asList(new Instance("one", true, false, Collections.<String, String>emptyMap(), "otherView"), new Instance("two", false, true, Collections.<String, String>emptyMap(), "viewId")), empty()).all(true).isInClusterView(clusterView).get();
TestCase.assertEquals(1, instances.size());
TestCase.assertEquals("two", instances.iterator().next().getSlingId());
}
Aggregations