Package org.jboss.jms.client

Examples of org.jboss.jms.client.FailoverValve



   // You can have multiple threads trying to close the valve at the same time.
   public void testMultipleThreadsClosingValve() throws Exception
   {
      FailoverValve valve = new FailoverValve();

      ValveThread threads[] = new ValveThread[100];

      for (int i = 0; i < threads.length; i++)
      {
View Full Code Here


   // Validate weird usages that are supposed to throw exceptions
   public void testValidateExceptions() throws Exception
   {
      try
      {
         FailoverValve  valve = new FailoverValve ();
         valve.open();
         valve.close();
         valve.close(); // closing without opening should throw an exception
         fail("Valve.close didn't generate an exception on an extra close, Valve is not safe!");
      }
      catch (Throwable e)
      {
         //e.printStackTrace();
      }

      try
      {
         FailoverValve valve = new FailoverValve ();
         valve.enter();
         valve.leave();
         valve.leave(); // extra leave call, should throw an exception
         fail("Valve.close didn't generate an exception, Valve is not safe!");
      }
      catch (Throwable e)
      {
         //e.printStackTrace();
View Full Code Here

   }

   public void testSimpleClose() throws Exception
   {
      final FailoverValve valve = new FailoverValve(2000);
      final Slot slot = new Slot();

      // prevent the valve from being possible to close

      valve.enter();

      new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               valve.close();
               slot.put("CLOSED");
            }
            catch(InterruptedException e)
            {
               log.error(e);
            }
         }
      }, "Closer").start();

      log.info("attempting to close for 5 secs ...");

      // valve cannot be closed at this time
      Object o = slot.poll(5000);
      assertNull(o);

      // exit the valve
      valve.leave();
      o = slot.take();
      assertNotNull(o);
      assertEquals("CLOSED", o);
   }
View Full Code Here

      assertEquals("CLOSED", o);
   }

   public void testSimpleClose2() throws Exception
   {
      final FailoverValve valve = new FailoverValve(2000);
      final Slot slot = new Slot();

      // flip-flop the valve

      valve.enter();
      valve.leave();

      new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               valve.close();
               slot.put("CLOSED");
            }
            catch(InterruptedException e)
            {
               log.error(e);
View Full Code Here


   public void testConcurrentClose() throws Exception
   {
      int THREAD_COUNT = 10;
      final FailoverValve valve = new FailoverValve(10000);
      final Slot[] slot = new Slot[THREAD_COUNT];

      // prevent the valve from being possible to close

      log.info("entering the valve");

      valve.enter();

      // attempt to close the valve from 10 concurrent threads
      for(int i = 0; i < THREAD_COUNT; i++)
      {
         slot[i] = new Slot();
         final int ii = i;

         new Thread(new Runnable()
         {
            public void run()
            {
               try
               {
                  log.info("attempting to close");
                  valve.close();
                  log.info("First thread could close the valve");
                  slot[ii].put("CLOSED");
                  valve.open();
                  log.info("Firs thread opened the Valve");
               }
               catch(InterruptedException e)
               {
                  log.error(e);
               }
            }
         }, "Closer(" + i + ")").start();

      }

      // wait a second so they'll attempt closing
      log.info("sleeping for 2 seconds");
      Thread.sleep(2000);
      log.info("slept");

      // make sure none closed the valve

      for(int i = 0; i < THREAD_COUNT; i++)
      {
         Object o = slot[i].peek();
         assertNull(o);
      }

      log.info("leaving the valve");
      valve.leave();

      // the valve should be "closeable", so all waiting threads, plus a new one, should be able
      // to close it

      final Slot loneSlot = new Slot();

      new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               log.info("attempting to close");
               valve.close();
               log.info("Second thread could close the valve");
               loneSlot.put("CLOSED");
            }
            catch(InterruptedException e)
            {
View Full Code Here

TOP

Related Classes of org.jboss.jms.client.FailoverValve

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.