use of org.apache.sling.discovery.TopologyEventListener in project sling by apache.
the class TestInitDelayingTopologyEventListener method testConstructor.
@Test
public void testConstructor() throws Exception {
final TopologyEventListener delegate = new TopologyEventListener() {
@Override
public void handleTopologyEvent(TopologyEvent event) {
// nothing here atm
}
};
final Scheduler scheduler = createScheduler();
try {
new InitDelayingTopologyEventListener(-1, delegate, scheduler);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(0, delegate, scheduler);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(1, null, scheduler);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(-1, delegate, scheduler, null);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(0, delegate, scheduler, null);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(1, null, scheduler, null);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(-1, delegate, scheduler, logger);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(0, delegate, scheduler, logger);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
try {
new InitDelayingTopologyEventListener(1, null, scheduler, logger);
fail("should complain");
} catch (IllegalArgumentException re) {
// ok
}
}
use of org.apache.sling.discovery.TopologyEventListener in project sling by apache.
the class ViewStateManagerImpl method enqueueForAll.
/** Internal helper method that sends a given event to a list of listeners **/
private void enqueueForAll(final List<TopologyEventListener> audience, final TopologyEvent event) {
logger.info("enqueueForAll: sending topologyEvent {}, to all ({}) listeners", EventHelper.toShortString(event), audience.size());
for (Iterator<TopologyEventListener> it = audience.iterator(); it.hasNext(); ) {
TopologyEventListener topologyEventListener = it.next();
enqueue(topologyEventListener, event, false);
}
logger.trace("enqueueForAll: sent topologyEvent {}, to all ({}) listeners", event, audience.size());
}
use of org.apache.sling.discovery.TopologyEventListener in project sling by apache.
the class DiscoveryWithSyncTokenTest method testTwoNodes.
@Test
public void testTwoNodes() throws Throwable {
logger.info("testTwoNodes: start");
FullJR2VirtualInstanceBuilder b1 = new FullJR2VirtualInstanceBuilder();
b1.setDebugName("i1").newRepository("/var/twon/", true);
b1.setConnectorPingInterval(1).setMinEventDelay(1).setConnectorPingTimeout(60);
VirtualInstance i1 = b1.build();
instances.add(i1);
i1.bindTopologyEventListener(new TopologyEventListener() {
@Override
public void handleTopologyEvent(TopologyEvent event) {
logger.info("GOT EVENT: " + event);
}
});
FullJR2VirtualInstanceBuilder b2 = new FullJR2VirtualInstanceBuilder();
b2.setDebugName("i2").useRepositoryOf(i1);
b2.setConnectorPingInterval(1).setMinEventDelay(1).setConnectorPingTimeout(60);
VirtualInstance i2 = b2.build();
instances.add(i2);
i1.heartbeatsAndCheckView();
i2.heartbeatsAndCheckView();
i1.heartbeatsAndCheckView();
i2.heartbeatsAndCheckView();
Thread.sleep(999);
//TODO: finalize test
}
use of org.apache.sling.discovery.TopologyEventListener in project sling by apache.
the class NoClusterDiscoveryService method bindTopologyEventListener.
@SuppressWarnings("unused")
private void bindTopologyEventListener(final TopologyEventListener listener) {
logger.debug("Binding TopologyEventListener {}", listener);
boolean inform = true;
synchronized (lock) {
final List<TopologyEventListener> currentList = new ArrayList<TopologyEventListener>(Arrays.asList(listeners));
currentList.add(listener);
this.listeners = currentList.toArray(new TopologyEventListener[currentList.size()]);
if (this.currentTopologyView != null) {
listener.handleTopologyEvent(new TopologyEvent(Type.TOPOLOGY_INIT, null, this.currentTopologyView));
}
}
}
use of org.apache.sling.discovery.TopologyEventListener in project sling by apache.
the class NoClusterDiscoveryService method createNewView.
private void createNewView(final Type eventType, boolean inform) {
final TopologyEventListener[] registeredServices;
final TopologyView newView;
final TopologyView oldView;
synchronized (lock) {
// invalidate old view
if (this.currentTopologyView != null) {
this.currentTopologyView.invalidate();
oldView = currentTopologyView;
} else {
oldView = null;
}
final InstanceDescription myInstanceDescription = new InstanceDescriptionImpl(this.settingsService.getSlingId(), this.cachedProperties);
this.currentTopologyView = new TopologyViewImpl(myInstanceDescription);
registeredServices = this.listeners;
newView = this.currentTopologyView;
if (inform) {
for (final TopologyEventListener da : registeredServices) {
da.handleTopologyEvent(new TopologyEvent(eventType, oldView, newView));
}
}
}
}
Aggregations