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

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


   {
      ConnectionFactory cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
      Destination topic = (Destination)ic.lookup("/topic/ATopic");

      Connection conn = cf.createConnection();
      Slot slot = new Slot();

      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageConsumer consumer = session.createConsumer(topic);
      consumer.setMessageListener(new SimpleMessageListener(slot));

      conn.start();

      Connection conn2 = cf.createConnection();
      Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer prod = session2.createProducer(topic);
      Message m = session.createTextMessage("blah");

      prod.send(m);

      TextMessage rm = (TextMessage)slot.poll(5000);

      assertEquals("blah", rm.getText());

      // Only for JBoss Remoting > 2.0.0.Beta1
      long sleepTime = ServerInvoker.DEFAULT_TIMEOUT_PERIOD + 60000;
      log.info("sleeping " + (sleepTime / 60000) + " minutes");

      Thread.sleep(sleepTime);

      log.info("after sleep");

      // send the second message. In case of remoting timeout, the callback server won't forward
      // this message to the MessageCallbackHandler, and the test will fail

      Message m2 = session.createTextMessage("blah2");
      prod.send(m2);

      TextMessage rm2 = (TextMessage)slot.poll(5000);

      assertNotNull(rm2);
      assertEquals("blah2", rm2.getText());

      conn.close();
View Full Code Here


      final MessageConsumer cons = session.createConsumer(queue);

      conn.start();

      final Slot slot = new Slot();

      new Thread(new Runnable()
      {
         public void run()
         {
            try
            {
               Message m = cons.receive(5000);
               if (m != null)
               {
                  slot.put(m);
               }
            }
            catch(Exception e)
            {
               log.error("receive failed", e);
            }

         }
      }, "Receiving Thread").start();


      Thread.sleep(500);

      MessageProducer prod = session.createProducer(queue);
      prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

      TextMessage m = session.createTextMessage("message one");

      prod.send(m);

      TextMessage rm = (TextMessage)slot.poll(5000);

      assertEquals("message one", rm.getText());

      conn.close();
   }
View Full Code Here

      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageConsumer cons = session.createConsumer(queue);

      final Slot slot = new Slot();

      cons.setMessageListener(new MessageListener()
      {
         public void onMessage(Message m)
         {
            try
            {
               slot.put(m);
            }
            catch(InterruptedException e)
            {
               log.warn("got InterruptedException", e);
            }
         }
      });

      conn.start();

      MessageProducer prod = session.createProducer(queue);
      prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      TextMessage m = session.createTextMessage("one");
      prod.send(m);

      TextMessage rm = (TextMessage)slot.poll(5000);

      assertEquals("one", rm.getText());

      conn.close();
   }
View Full Code Here

   {
      private Slot slot;

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

   {
      private Slot slot;

      SimpleMessageListener()
      {
         slot = 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.servicemix.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

    }


    public void testSubscriptionPauseResume() throws JMSException, InterruptedException {

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

        EndpointReferenceType subRef = addSubscription(broker);
       
        // The sub should be running and we should be getting notifed now.
        sendNotification(broker);
        NotifyDocument subNotifyDoc = (NotifyDocument) result.poll(2000);
        assertNotNull(subNotifyDoc);
       
        // Pause the subscription.
        PauseSubscriptionDocument pauseRequest = PauseSubscriptionDocument.Factory.newInstance();
        pauseRequest.addNewPauseSubscription();
        broker.getSubscriptionManager().pauseSubcription(pauseRequest, subRef);       
       
        // The sub should be stopped and we should not be getting notifed now.
        sendNotification(broker);
        subNotifyDoc = (NotifyDocument) result.poll(2000);
        assertNull(subNotifyDoc);
       
        // Resume the subscription.
        ResumeSubscriptionDocument resumeRequest = ResumeSubscriptionDocument.Factory.newInstance();
        resumeRequest.addNewResumeSubscription();
        broker.getSubscriptionManager().resumeSubscription(resumeRequest, subRef);       
       
        // We should now get the message that was previously sent since the sub is now running.
        subNotifyDoc = (NotifyDocument) result.poll(2000);
        assertNotNull(subNotifyDoc);
    }
View Full Code Here

    private Slot result;
    private int timeout;

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

        System.out.println("Received inbound message: " + message);
    }

    public void testSubscribe() throws Exception {

        Slot result = new Slot();
        ActiveMQNotificationBroker broker = createBroker(result);

        addSubscription(broker);
        sendNotification(broker);

        List<NotificationMessageHolderType> notifyMessages = (List<NotificationMessageHolderType>) result.poll(2000);
        System.out.println("Got Notify: " + notifyMessages);

        assertValidMessage(notifyMessages);
    }
View Full Code Here

        assertValidMessage(notifyMessages);
    }

    public void testSubscriptionPauseResume() throws Exception {

        Slot result = new Slot();
        ActiveMQNotificationBroker broker = createBroker(result);

        EndpointReferenceType subRef = addSubscription(broker);

        // The sub should be running and we should be getting notifed now.
        sendNotification(broker);

        List<NotificationMessageHolderType> subNotifyDoc = (List<NotificationMessageHolderType>) result.poll(2000);
        assertNotNull(subNotifyDoc);

        // Pause the subscription.
        broker.getSubscriptionManager().pauseSubscription(subRef);

        // The sub should be stopped and we should not be getting notifed now.
        sendNotification(broker);
        subNotifyDoc = (List<NotificationMessageHolderType>) result.poll(2000);
        assertNull(subNotifyDoc);

        // Resume the subscription.
        broker.getSubscriptionManager().resumeSubscription(subRef);

        // We should now get the message that was previously sent since the sub
        // is now running.
        subNotifyDoc = (List<NotificationMessageHolderType>) result.poll(2000);
        assertNotNull(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.