Search in sources :

Example 1 with TopologyEventListener

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
    }
}
Also used : Scheduler(org.apache.sling.commons.scheduler.Scheduler) TopologyEvent(org.apache.sling.discovery.TopologyEvent) TopologyEventListener(org.apache.sling.discovery.TopologyEventListener) Test(org.junit.Test)

Example 2 with TopologyEventListener

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());
}
Also used : TopologyEventListener(org.apache.sling.discovery.TopologyEventListener)

Example 3 with TopologyEventListener

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
}
Also used : FullJR2VirtualInstanceBuilder(org.apache.sling.discovery.impl.setup.FullJR2VirtualInstanceBuilder) TopologyEvent(org.apache.sling.discovery.TopologyEvent) TopologyEventListener(org.apache.sling.discovery.TopologyEventListener) VirtualInstance(org.apache.sling.discovery.base.its.setup.VirtualInstance) Test(org.junit.Test)

Example 4 with TopologyEventListener

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));
        }
    }
}
Also used : TopologyEvent(org.apache.sling.discovery.TopologyEvent) ArrayList(java.util.ArrayList) TopologyEventListener(org.apache.sling.discovery.TopologyEventListener)

Example 5 with TopologyEventListener

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));
            }
        }
    }
}
Also used : TopologyEvent(org.apache.sling.discovery.TopologyEvent) InstanceDescription(org.apache.sling.discovery.InstanceDescription) TopologyView(org.apache.sling.discovery.TopologyView) TopologyEventListener(org.apache.sling.discovery.TopologyEventListener)

Aggregations

TopologyEventListener (org.apache.sling.discovery.TopologyEventListener)13 TopologyEvent (org.apache.sling.discovery.TopologyEvent)10 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)3 PersistenceException (org.apache.sling.api.resource.PersistenceException)3 DiscoveryService (org.apache.sling.discovery.DiscoveryService)3 InstanceDescription (org.apache.sling.discovery.InstanceDescription)3 TopologyView (org.apache.sling.discovery.TopologyView)3 URL (java.net.URL)2 Collection (java.util.Collection)2 Map (java.util.Map)2 Activate (org.apache.felix.scr.annotations.Activate)2 LoginException (org.apache.sling.api.resource.LoginException)2 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)2 DefaultTopologyView (org.apache.sling.discovery.base.commons.DefaultTopologyView)2 InitDelayingTopologyEventListener (org.apache.sling.discovery.commons.InitDelayingTopologyEventListener)2 DefaultClusterView (org.apache.sling.discovery.commons.providers.DefaultClusterView)2 DefaultInstanceDescription (org.apache.sling.discovery.commons.providers.DefaultInstanceDescription)2 ClusterSyncService (org.apache.sling.discovery.commons.providers.spi.ClusterSyncService)2