Package EDU.oswego.cs.dl.util.concurrent

Examples of EDU.oswego.cs.dl.util.concurrent.Semaphore


        nodeInfo = aNodeInfo;
        threadPool = aThreadPool;
        clockPool = aClockPool;
       
        replacerResolver = new MsgReplacerResolver();
        topologyMonitor = new Semaphore(1);
        endPointView = new NodeEndPointViewImpl();
       
        streamManager = newStreamManager();
        referenceableManager = newReferenceableManager();
        endPointProxyFactory = newEndPointProxyFactory();
View Full Code Here


         // Bisocket callback client invoker doesn't share socket pools because of the danger
         // that two distinct callback servers could have the same "artifical" port.
         pool = new LinkedList();
         log.debug("Creating semaphore with size " + maxPoolSize);
         semaphore = new Semaphore(maxPoolSize);
         return;
      }

      // Client on client side.
      super.handleConnect();
View Full Code Here

         if (pool == null)
         {
            pool = new LinkedList();
            connectionPools.put(address, pool);
            log.debug("Creating semaphore with size " + maxPoolSize);
            semaphore = new Semaphore(maxPoolSize);
            semaphores.put(address, semaphore);
           
            if (trace)
            {
               synchronized (pool)
View Full Code Here

         if (pool == null)
         {
            pool = new LinkedList();
            connectionPools.put(address, pool);
            log.debug("Creating semaphore with size " + maxPoolSize);
            semaphore = new Semaphore(maxPoolSize);
            semaphores.put(address, semaphore);
           
            if (trace)
            {
               synchronized (pool)
View Full Code Here

         if (pool == null)
         {
            pool = new LinkedList();
            connectionPools.put(address, pool);
            log.debug("Creating semaphore with size " + maxPoolSize);
            semaphore = new Semaphore(maxPoolSize);
            semaphores.put(address, semaphore);
           
            if (trace)
            {
               synchronized (pool)
View Full Code Here

         // Bisocket callback client invoker doesn't share socket pools because of the danger
         // that two distinct callback servers could have the same "artifical" port.
         pool = new LinkedList();
         log.debug("Creating semaphore with size " + maxPoolSize);
         semaphore = new Semaphore(maxPoolSize);
         return;
      }

      // Client on client side.
      super.handleConnect();
View Full Code Here

        
         PojoCache[] caches = new PojoCache[count + 1];
         caches[0] = cacheA;
        
         // Create a semaphore and take all its tickets
         Semaphore semaphore = new Semaphore(count);        
         for (int i = 0; i < count; i++) {
            semaphore.acquire();
         }  
        
         // Create stressor threads that will block on the semaphore
                 
         for (int i = 0; i < count; i++)
         {
            stressors[i] = new CacheStressor(semaphore, names[i], sync);
            caches[i + 1] = stressors[i].getTreeCache();
            stressors[i].getTreeCache().put("/" + names[i], null);
         }
         for (int i = 0; i < count; i++)
         {
            stressors[i].start();
            // Give each one a chance to stabilize
            TestingUtil.sleepThread(100);
         }
        
         // Make sure everyone's views are in sync
         TestingUtil.blockUntilViewsReceived(caches, 60000);
        
         // Repeat the basic test two times in order to involve inactivation
         for (int x = 0; x < 2; x++)
         {
//            if (x > 0)
//            {
               // Reset things by inactivating the region
               // and enabling the stressors
               for (int i = 0; i < count; i++)
               {
                  cacheA.inactivateRegion("/" + names[i]);
                  log.info("TEST: Run " + x + "-- /" + names[i] + " inactivated on A");
                  stressors[i].startPuts();
               }
//            }
           
            // Release the semaphore to allow the threads to start work
            semaphore.release(count);
           
            // Sleep to ensure the threads get all the semaphore tickets
            // and to ensure puts are actively in progress
            TestingUtil.sleepThread(300);
           
            // Activate cacheA
            for (int i = 0; i < count; i++)
            {
               log.info("TEST: Activating /" + names[i] + " on A");
               cacheA.activateRegion("/" + names[i]);
               // Stop the stressor so we don't pollute cacheA's state
               // with too many messages sent after activation -- we want
               // to compare transferred state with the sender
               stressors[i].stopPuts();
               log.info("TEST: Run " + x + "-- /" + names[i] + " activated on A");
               // Reacquire one semaphore ticket
               boolean acquired = semaphore.attempt(60000);
               if (!acquired)
                  fail("failed to acquire semaphore " + names[i]);
               log.info("TEST: Run " + x + "-- acquired semaphore from " + names[i]);
              
               // Pause to allow other work to proceed
View Full Code Here

      CacheActivator[] activators = new CacheActivator[count];
     
     
      try {
         // Create a semaphore and take all its tickets
         Semaphore semaphore = new Semaphore(count);        
         for (int i = 0; i < count; i++) {
            semaphore.acquire();
         }  
        
         // Create activation threads that will block on the semaphore
         TreeCache[] caches = new TreeCache[count];
         for (int i = 0; i < count; i++) {
            activators[i] = new CacheActivator(semaphore, names[i], sync);
            caches[i] = activators[i].getTreeCache();
            activators[i].start();
         }
        
         // Make sure everyone is in sync
         TestingUtil.blockUntilViewsReceived(caches, 60000);
        
         // Release the semaphore to allow the threads to start work
         semaphore.release(count);
        
         // Sleep to ensure the threads get all the semaphore tickets
         TestingUtil.sleepThread(1000);
        
         // Reacquire the semaphore tickets; when we have them all
         // we know the threads are done        
         for (int i = 0; i < count; i++) {
            boolean acquired = semaphore.attempt(60000);
            if (!acquired)
               fail("failed to acquire semaphore " + i);
         }

         // Sleep to allow any async calls to clear
View Full Code Here

      CacheActivator[] activators = new CacheActivator[count];
     
     
      try {
         // Create a semaphore and take all its tickets
         Semaphore semaphore = new Semaphore(count);        
         for (int i = 0; i < count; i++) {
            semaphore.acquire();
         }  
        
         // Create activation threads that will block on the semaphore
         TreeCacheMBean[] caches = new TreeCacheMBean[count];
         for (int i = 0; i < count; i++) {
            activators[i] = new CacheActivator(semaphore, names[i], sync);
            caches[i] = activators[i].getTreeCache();
            activators[i].start();
         }
        
         // Make sure everyone is in sync
         TestingUtil.blockUntilViewsReceived(caches, 60000);
        
         // Release the semaphore to allow the threads to start work
         semaphore.release(count);
        
         // Sleep to ensure the threads get all the semaphore tickets
          TestingUtil.sleepThread((long)1000);

          // Reacquire the semaphore tickets; when we have them all
         // we know the threads are done        
         for (int i = 0; i < count; i++) {
            boolean acquired = semaphore.attempt(60000);
            if (!acquired)
               fail("failed to acquire semaphore " + i);
         }

         // Sleep to allow any async calls to clear
View Full Code Here

        
         TreeCacheMBean[] caches = new TreeCacheMBean[count + 1];
         caches[0] = cacheA;
        
         // Create a semaphore and take all its tickets
         Semaphore semaphore = new Semaphore(count);        
         for (int i = 0; i < count; i++) {
            semaphore.acquire();
         }  
        
         // Create stressor threads that will block on the semaphore
                 
         for (int i = 0; i < count; i++)
         {
            stressors[i] = new CacheStressor(semaphore, names[i], sync);
            caches[i + 1] = stressors[i].getTreeCache();
            stressors[i].start();
         }
        
         // Make sure everyone's views are in sync
         TestingUtil.blockUntilViewsReceived(caches, 60000);
        
         // Repeat the basic test four times
         //for (int x = 0; x < 4; x++)
         for (int x = 0; x < 1; x++)
         {
            if (x > 0)
            {
               // Reset things by inactivating the region
               // and enabling the stressors
               for (int i = 0; i < count; i++)
               {
                  cacheA.inactivateRegion("/" + names[i]);
                  System.out.println("Run " + x + "-- /" + names[i] + " inactivated on A");
                  stressors[i].startPuts();
               }
            }
           
            // Release the semaphore to allow the threads to start work
            semaphore.release(count);
           
            // Sleep to ensure the threads get all the semaphore tickets
            // and to ensure puts are actively in progress
             TestingUtil.sleepThread((long)300);

             // Activate cacheA
            for (int i = 0; i < count; i++)
            {
//              System.out.println("Activating /" + names[i] + " on A");
               cacheA.activateRegion("/" + names[i]);
               // Stop the stressor so we don't pollute cacheA's state
               // with too many messages sent after activation -- we want
               // to compare transferred state with the sender
               stressors[i].stopPuts();
               System.out.println("Run " + x + "-- /" + names[i] + " activated on A");
               // Reacquire one semaphore ticket
               boolean acquired = semaphore.attempt(60000);
               if (!acquired)
                  fail("failed to acquire semaphore " + i);
              
               // Pause to allow other work to proceed
                TestingUtil.sleepThread((long)100);
View Full Code Here

TOP

Related Classes of EDU.oswego.cs.dl.util.concurrent.Semaphore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.