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

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


    }


    public void testSubscriptionPauseResume() 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);
            }
        };

        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


        try {
           
            PacketData data = new PacketData(packet);
            short requestId = data.readShort();
           
            Slot responseSlot = (Slot) requestMap.get(new Short(requestId));
            responseSlot.put(packet);
           
        } catch (IOException e) {
            super.onPacketError(e);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
View Full Code Here

    }

    public Packet request(Packet request, long timeout) throws IOException {
       
        Short requestId = new Short(getNextRequestId());
        Slot responseSlot = new Slot();
        requestMap.put(requestId, responseSlot);
       
        Packet header = createHeaderPacket(REQUEST, requestId.shortValue());       
        Packet packet = AppendedPacket.join(header, request);
       
        synchronized(writeMutex) {
            super.write(packet);
        }
       
        try {
           
            if( timeout == WAIT_FOREVER_TIMEOUT ) {
                return (Packet) responseSlot.take();               
            } else if (timeout == NO_WAIT_TIMEOUT ) {
                return (Packet) responseSlot.poll(1);                               
            } else {
                return (Packet) responseSlot.poll(timeout);                               
            }
           
        } catch (InterruptedException e) {
            throw new InterruptedIOException(e.getMessage());
        } finally {
View Full Code Here

        // Test disconnect. This will be fatal for most channels, but reliable
        // channels
        // should be able to recover from it. In any case transportConnected
        // should be false
        // immediately after the disconnect
        final Slot disconnectEvent = new Slot();
        sender.addTransportStatusEventListener(new TransportStatusEventListener() {
                public void statusChanged(TransportStatusEvent e) {
                    if( e.getChannelStatus() == TransportStatusEvent.DISCONNECTED ) {
                        try {
                            disconnectEvent.offer(e, 1000);
                        } catch (InterruptedException e1) {
                        }
                    }
                }
            });
        sender.forceDisconnect();

        assertNotNull("Should have received state change notification", disconnectEvent.poll(1000*30));
        assertFalse("Should be disconnected", sender.isTransportConnected());
        //there could ber exceptions thrown - which are valid for a force disconnect
        //so clear them so tearDown() will pass
        exceptions.clear();
    }
View Full Code Here

   {
      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(queue1);
 
        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();
 
        MessageProducer prod = session.createProducer(queue1);
        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());
      }
     finally
     {
View Full Code Here

 
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
        MessageConsumer cons = session.createConsumer(queue1);
 
        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(queue1);
        prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        TextMessage m = session.createTextMessage("one");
        prod.send(m);
 
        TextMessage rm = (TextMessage)slot.poll(5000);
 
        assertEquals("one", rm.getText());
      }
     finally
     {
View Full Code Here

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

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

 
        final MessageConsumer cons = session.createConsumer(queue1);
 
        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();
 
        MessageProducer prod = session.createProducer(queue1);
        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());
      }
     finally
     {
View Full Code Here

 
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
        MessageConsumer cons = session.createConsumer(queue1);
 
        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(queue1);
        prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        TextMessage m = session.createTextMessage("one");
        prod.send(m);
 
        TextMessage rm = (TextMessage)slot.poll(5000);
 
        assertEquals("one", rm.getText());
      }
     finally
     {
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.