Package org.hornetq.rest.queue

Examples of org.hornetq.rest.queue.QueueConsumer


   @Override
   public void testTimeout(String target)
   {
      synchronized (timeoutLock)
      {
         QueueConsumer consumer = queueConsumers.get(target);
         if (consumer == null) return;
         synchronized (consumer)
         {
            if (System.currentTimeMillis() - consumer.getLastPingTime() > consumerTimeoutSeconds * 1000)
            {
               log.warn("shutdown REST consumer because of session timeout for: " + consumer.getId());
               consumer.shutdown();
               queueConsumers.remove(consumer.getId());
               serviceManager.getTimeoutTask().remove(consumer.getId());
            }
         }
      }
   }
View Full Code Here


                                      @Context UriInfo uriInfo)
   {
      if (subscriptionName != null)
      {
         // see if this is a reconnect
         QueueConsumer consumer = queueConsumers.get(subscriptionName);
         if (consumer != null)
         {
            boolean acked = consumer instanceof AcknowledgedSubscriptionResource;
            acked = !acked;
            if (acked != autoAck)
            {
               throw new WebApplicationException(
                       Response.status(412).entity("Consumer already exists and ack-modes don't match.").type("text/plain").build()
               );
            }
            Subscription sub = (Subscription) consumer;
            if (sub.isDurable() != durable)
            {
               throw new WebApplicationException(
                       Response.status(412).entity("Consumer already exists and durability doesn't match.").type("text/plain").build()
               );
            }
            Response.ResponseBuilder builder = Response.noContent();
            if (autoAck)
            {
               headAutoAckSubscriptionResponse(uriInfo, consumer, builder);
               consumer.setSessionLink(builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/auto-ack/" + consumer.getId());
            }
            else
            {
               headAcknowledgedConsumerResponse(uriInfo, (AcknowledgedQueueConsumer) consumer, builder);
               consumer.setSessionLink(builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/acknowledged/" + consumer.getId());
            }
            return builder.build();
         }
      }
      else
      {
         subscriptionName = generateSubscriptionName();
      }
      ClientSession session = null;
      try
      {
         // if this is not a reconnect, create the subscription queue
         if (!subscriptionExists(subscriptionName))
         {
            session = sessionFactory.createSession();

            if (durable)
            {
               session.createQueue(destination, subscriptionName, true);
            }
            else
            {
               session.createTemporaryQueue(destination, subscriptionName);
            }
         }
         QueueConsumer consumer = createConsumer(durable, autoAck, subscriptionName);
         queueConsumers.put(consumer.getId(), consumer);
         serviceManager.getTimeoutTask().add(this, consumer.getId());

         UriBuilder location = uriInfo.getAbsolutePathBuilder();
         if (autoAck) location.path("auto-ack");
         else location.path("acknowledged");
         location.path(consumer.getId());
         Response.ResponseBuilder builder = Response.created(location.build());
         if (autoAck)
         {
            SubscriptionResource.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/auto-ack/" + consumer.getId(), "-1");
         }
         else
         {
            AcknowledgedSubscriptionResource.setAcknowledgeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/acknowledged/" + consumer.getId(), "-1");

         }
         return builder.build();

      }
View Full Code Here

   }

   protected QueueConsumer createConsumer(boolean durable, boolean autoAck, String subscriptionName)
           throws HornetQException
   {
      QueueConsumer consumer;
      if (autoAck)
      {
         SubscriptionResource subscription = new SubscriptionResource(sessionFactory, subscriptionName, subscriptionName, serviceManager);
         subscription.setDurable(durable);
         consumer = subscription;
View Full Code Here

   @Path("auto-ack/{consumer-id}")
   @HEAD
   public Response headAutoAckSubscription(@PathParam("consumer-id") String consumerId,
                                           @Context UriInfo uriInfo) throws Exception
   {
      QueueConsumer consumer = findAutoAckSubscription(consumerId);
      Response.ResponseBuilder builder = Response.noContent();
      headAutoAckSubscriptionResponse(uriInfo, consumer, builder);

      return builder.build();
   }
View Full Code Here

   @Path("auto-ack/{subscription-id}")
   public QueueConsumer findAutoAckSubscription(
           @PathParam("subscription-id") String subscriptionId)
   {
      QueueConsumer consumer = queueConsumers.get(subscriptionId);
      if (consumer == null)
      {
         consumer = recreateTopicConsumer(subscriptionId, true);
      }
      return consumer;
View Full Code Here

   @Path("acknowledged/{subscription-id}")
   public QueueConsumer findAcknoledgeSubscription(
           @PathParam("subscription-id") String subscriptionId)
   {
      QueueConsumer consumer = queueConsumers.get(subscriptionId);
      if (consumer == null)
      {
         consumer = recreateTopicConsumer(subscriptionId, false);
      }
      return consumer;
View Full Code Here

   }

   private QueueConsumer recreateTopicConsumer(String subscriptionId, boolean autoAck)
   {
      QueueConsumer consumer;
      if (subscriptionExists(subscriptionId))
      {
         synchronized (timeoutLock)
         {
            QueueConsumer tmp = null;
            try
            {
               tmp = createConsumer(true, autoAck, subscriptionId);
            }
            catch (HornetQException e)
            {
               throw new RuntimeException(e);
            }
            consumer = queueConsumers.putIfAbsent(subscriptionId, tmp);
            if (consumer == null)
            {
               consumer = tmp;
               serviceManager.getTimeoutTask().add(this, subscriptionId);
            }
            else
            {
               tmp.shutdown();
            }
         }
      }
      else
      {
View Full Code Here

   @Path("auto-ack/{subscription-id}")
   @DELETE
   public void deleteSubscription(
           @PathParam("subscription-id") String consumerId)
   {
      QueueConsumer consumer = queueConsumers.remove(consumerId);
      if (consumer == null)
      {
         String msg = "Failed to match a subscription to URL " + consumerId;
         //System.out.println(msg);
         throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
                 .entity(msg)
                 .type("text/plain").build());
      }
      consumer.shutdown();
      deleteSubscriberQueue(consumer);

   }
View Full Code Here

      this.destination = destination;
   }

   public boolean testTimeout(String target, boolean autoShutdown)
   {
      QueueConsumer consumer = queueConsumers.get(target);
      Subscription subscription = (Subscription)consumer;
      if (consumer == null) return false;
      if (System.currentTimeMillis() - consumer.getLastPingTime() > subscription.getTimeout())
      {
         HornetQRestLogger.LOGGER.shutdownRestSubscription(consumer.getId());
         if(autoShutdown)
         {
            shutdown(consumer);
         }
         return true;
View Full Code Here

      }
   }

   public void shutdown(String target)
   {
      QueueConsumer consumer = queueConsumers.get(target);
      if (consumer == null) return;
      shutdown(consumer);
   }
View Full Code Here

TOP

Related Classes of org.hornetq.rest.queue.QueueConsumer

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.