Search in sources :

Example 6 with ClusterSyncService

use of org.apache.sling.discovery.commons.providers.spi.ClusterSyncService in project sling by apache.

the class TestViewStateManager method testCancelSync.

@Test
public void testCancelSync() throws Exception {
    final List<Runnable> syncCallbacks = new LinkedList<Runnable>();
    mgr = new ViewStateManagerImpl(new ReentrantLock(), new ClusterSyncService() {

        @Override
        public void sync(BaseTopologyView view, Runnable callback) {
            synchronized (syncCallbacks) {
                syncCallbacks.add(callback);
            }
        }

        @Override
        public void cancelSync() {
            synchronized (syncCallbacks) {
                syncCallbacks.clear();
            }
        }
    });
    mgr.handleActivated();
    final DummyListener listener = new DummyListener();
    mgr.bind(listener);
    mgr.handleChanging();
    final BaseTopologyView view = new DummyTopologyView().addInstance();
    mgr.handleNewView(view);
    assertEquals(0, mgr.waitForAsyncEvents(1000));
    TestHelper.assertNoEvents(listener);
    synchronized (syncCallbacks) {
        assertEquals(1, syncCallbacks.size());
    }
    String id1 = UUID.randomUUID().toString();
    String id2 = UUID.randomUUID().toString();
    final BaseTopologyView view2 = TestHelper.newView(true, id1, id1, id1, id2);
    mgr.handleNewView(view2);
    assertEquals(0, mgr.waitForAsyncEvents(1000));
    TestHelper.assertNoEvents(listener);
    synchronized (syncCallbacks) {
        assertEquals(1, syncCallbacks.size());
        syncCallbacks.get(0).run();
        syncCallbacks.clear();
    }
    assertEquals(0, mgr.waitForAsyncEvents(1000));
    assertEvents(listener, EventHelper.newInitEvent(view2));
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) ClusterSyncService(org.apache.sling.discovery.commons.providers.spi.ClusterSyncService) DummyTopologyView(org.apache.sling.discovery.commons.providers.DummyTopologyView) LinkedList(java.util.LinkedList) BaseTopologyView(org.apache.sling.discovery.commons.providers.BaseTopologyView) Test(org.junit.Test)

Example 7 with ClusterSyncService

use of org.apache.sling.discovery.commons.providers.spi.ClusterSyncService in project sling by apache.

the class ClusterSyncServiceChain method chainedSync.

private void chainedSync(final BaseTopologyView view, final Runnable callback, final Iterator<ClusterSyncService> chainIt) {
    if (!chainIt.hasNext()) {
        logger.debug("doSync: done with sync chain, invoking callback");
        callback.run();
        return;
    }
    ClusterSyncService next = chainIt.next();
    next.sync(view, new Runnable() {

        @Override
        public void run() {
            chainedSync(view, callback, chainIt);
        }
    });
}
Also used : ClusterSyncService(org.apache.sling.discovery.commons.providers.spi.ClusterSyncService)

Aggregations

ClusterSyncService (org.apache.sling.discovery.commons.providers.spi.ClusterSyncService)7 ReentrantLock (java.util.concurrent.locks.ReentrantLock)4 BaseTopologyView (org.apache.sling.discovery.commons.providers.BaseTopologyView)4 URL (java.net.URL)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Random (java.util.Random)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 PersistenceException (org.apache.sling.api.resource.PersistenceException)2 InstanceDescription (org.apache.sling.discovery.InstanceDescription)2 TopologyEventListener (org.apache.sling.discovery.TopologyEventListener)2 DefaultTopologyView (org.apache.sling.discovery.base.commons.DefaultTopologyView)2 DefaultClusterView (org.apache.sling.discovery.commons.providers.DefaultClusterView)2 DefaultInstanceDescription (org.apache.sling.discovery.commons.providers.DefaultInstanceDescription)2 ViewStateManagerImpl (org.apache.sling.discovery.commons.providers.base.ViewStateManagerImpl)2 Before (org.junit.Before)2 LinkedList (java.util.LinkedList)1