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

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


    private Slot result;
    private int timeout;

    public StubNotificationConsumer() {
        this(new Slot());
    }
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

   }

   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);
            }
         }
      }, "Closer").start();

      log.info("attempting to close ...");

      // valve cannot be closed at this time
      Object o = slot.poll(5000);
      assertNotNull(o);
      assertEquals("CLOSED", o);
   }
View Full Code Here

      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)
            {
               log.error(e);
            }
         }
      }, "LoneCloser").start();


      Thread.sleep(5000);
      log.info("valve should be closed by now ...");
      Object o = loneSlot.poll(3000);
      assertNotNull(o);
      assertEquals("CLOSED", o);

      for(int i = 0; i < THREAD_COUNT; i++)
      {
View Full Code Here

   {
      private Slot slot;

      SimpleMessageListener()
      {
         slot = new Slot();
      }
View Full Code Here

   // Constructors --------------------------------------------------

   ClusterEventNotificationListener()
   {
      viewChange = new Slot();
      failoverCompleted = new Slot();
   }
View Full Code Here

public class JCAContainerWithoutSpringTest extends TestCase {
   
    public void testSendReceiveWithVMConnection() throws Exception {
       
        final Slot messageSlot = new Slot();
       
        final MessageListener bean = new MessageListener() {
            public void onMessage(Message message) {
                System.out.println(message);
                try {
                    messageSlot.offer(message, 1000);
                } catch (InterruptedException e) {
                }
            }           
        };

        JCAContainer jcac = new JCAContainer();
        jcac.setBeanFactory(new BeanFactory() {
            public Object getBean(String name) throws BeansException {
                return bean;
            }
            public Object getBean(String name, Class clazz) throws BeansException {
                return bean;
            }
            public boolean containsBean(String name) {
                return true;
            }
            public boolean isSingleton(String name) throws NoSuchBeanDefinitionException {
                return true;
            }
            public String[] getAliases(String name) throws NoSuchBeanDefinitionException {
                return null;
            }
            public Class getType(String arg0) throws NoSuchBeanDefinitionException {
                return null;
            }
        });

        ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();
        ra.setServerUrl("vm://localhost");
        ra.setBrokerXmlConfig("org/activemq/jca/broker-vmpersistence.xml");
        ra.setUseEmbeddedBroker(Boolean.TRUE);

        jcac.setResourceAdapter(ra);

        SpringWorkManager wm = new SpringWorkManager();
        wm.afterPropertiesSet();

        jcac.setWorkManager(wm);

        jcac.afterPropertiesSet();

        ActiveMQActivationSpec spec = new ActiveMQActivationSpec();
        spec.setDestinationType(Queue.class.getName());
        spec.setDestination("GauntletWorkQueue");
        spec.validate();

        JCAConnector connector = jcac.addConnector();
        connector.setActivationSpec(spec);
        connector.setRef("test");
        connector.setBeanFactory(jcac.getBeanFactory());
        connector.afterPropertiesSet();
       
        // Fire a test message into the broker.
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
        Connection connection = factory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("GauntletWorkQueue");
        MessageProducer producer = session.createProducer(queue);
        producer.send(session.createTextMessage("test"));
        System.out.println("Message sent");
        connection.close();
       
        // Assert the message got there:
        assertNotNull(messageSlot.poll(1000*5));       
       
    }
View Full Code Here

   {
      private Slot slot;

      SimpleMessageListener()
      {
         slot = new Slot();
      }
View Full Code Here

    private Slot result;
    private int timeout;

    public StubNotificationConsumer() {
        this(new Slot());
    }
View Full Code Here

        assertNotNull(message);
    }

    public void testSubscribe() throws JMSException, InterruptedException {

        final Slot result = new Slot();
        ActiveMQNotificationBroker broker = new ActiveMQNotificationBroker() {
            protected org.activemq.ws.notification.NotificationConsumer createNotificationConsumer(EndpointReferenceType consumerReference) {
                return new StubNotificationConsumer(result);
            }
        };

        addSubscription(broker);
        sendNotification(broker);

        NotifyDocument subNotifyDoc = (NotifyDocument) result.poll(2000);
        System.out.println("Got Notify: "+subNotifyDoc);

        assertValidMessage(subNotifyDoc);
    }
View Full Code Here

TOP

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

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.