Package org.hornetq.rest.queue

Examples of org.hornetq.rest.queue.QueueConsumer


      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

      if (destroyWhenIdle != null) deleteWhenIdle = destroyWhenIdle.booleanValue();

      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, selector, timeout, deleteWhenIdle);
         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)
         {
            QueueConsumer.setConsumeNextLink(serviceManager.getLinkStrategy(), builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/auto-ack/" + consumer.getId(), "-1");
         }
         else
         {
            AcknowledgedQueueConsumer.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, String selector, long timeout, boolean deleteWhenIdle)
           throws HornetQException
   {
      QueueConsumer consumer;
      if (autoAck)
      {
         SubscriptionResource subscription = new SubscriptionResource(sessionFactory, subscriptionName, subscriptionName, serviceManager, selector, durable, timeout);
         subscription.setDurable(durable);
         subscription.setDeleteWhenIdle(deleteWhenIdle);
View Full Code Here

      return internalHeadAutoAckSubscription(uriInfo, consumerId);
   }

   private Response internalHeadAutoAckSubscription(UriInfo uriInfo, String consumerId)
   {
       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))
      {
         QueueConsumer tmp = null;
         try
         {
            tmp = createConsumer(true, autoAck, subscriptionId, null, consumerTimeoutSeconds * 1000, false);
         }
         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
      {
         throw new WebApplicationException(Response.status(405)
View Full Code Here

      internalDeleteSubscription(consumerId);
   }

   private void internalDeleteSubscription(String consumerId)
   {
      QueueConsumer consumer = queueConsumers.remove(consumerId);
      if (consumer == null)
      {
         String msg = "Failed to match a subscription to URL " + consumerId;
         throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND)
                  .entity(msg)
                  .type("text/plain").build());
      }
      consumer.shutdown();
      deleteSubscriberQueue(consumer);
   }
View Full Code Here

   }


   public void testTimeout(String target)
   {
      QueueConsumer consumer = queueConsumers.get(target);
      Subscription subscription = (Subscription)consumer;
      if (consumer == null) return;
      synchronized (consumer)
      {
         if (System.currentTimeMillis() - consumer.getLastPingTime() > subscription.getTimeout())
         {
            HornetQRestLogger.LOGGER.shutdownRestSubscription(consumer.getId());
            consumer.shutdown();
            queueConsumers.remove(consumer.getId());
            serviceManager.getTimeoutTask().remove(consumer.getId());
            if (subscription.isDeleteWhenIdle()) deleteSubscriberQueue(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.