Class MessageQueueManager

java.lang.Object
io.goobi.viewer.controller.mq.MessageQueueManager

@Singleton @Startup public class MessageQueueManager extends Object
Manages handling of messages by their respective MessageHandlers. Main method is handle(ViewerMessage message) which accepts a ViewerMessage and calls a MessageHandler instance to process the message, returning a MessageStatus result. #handle may either be called directly to handle the message instantly, or from a MessageQueue
Author:
Florian Alpers
  • Field Details

  • Constructor Details

  • Method Details

    • init

      @PostConstruct public void init()
    • shutdown

      @PreDestroy public void shutdown()
    • addToQueue

      public String addToQueue(ViewerMessage message) throws MessageQueueException
      Adds the message to the internal message queue to be handled later.
      Parameters:
      message - message to add to the queue
      Returns:
      Message ID
      Throws:
      MessageQueueException
    • getQueueForMessageType

      public static String getQueueForMessageType(String taskName)
    • notifyMessageQueueStateUpdate

      public static void notifyMessageQueueStateUpdate()
      Sends a notification to the "messageQueueState" WebSocket to update message lists in the admin backend.
    • handle

      public MessageStatus handle(ViewerMessage message)
      Finds the appropriate MessageHandler for a message, lets the handler handle the message and update the message in the database.
      Parameters:
      message - message to dispatch to its handler
      Returns:
      the result of the handler calling the message
    • initializeMessageServer

      public boolean initializeMessageServer()
    • initializeMessageServer

      public boolean initializeMessageServer(String address, int namingPort, int protocolPort)
    • createRegistry

      public void createRegistry(int namingPort, RMIServerSocketFactory serverFactory) throws RemoteException
      Throws:
      RemoteException
    • closeMessageServer

      public void closeMessageServer()
    • getMessageById

      public Optional<ViewerMessage> getMessageById(String messageId)
    • getBroker

      public org.apache.activemq.broker.BrokerService getBroker()
    • isQueueRunning

      public boolean isQueueRunning()
      Checks if the queue has been successfully initialized.
      Returns:
      true if the queue is running
    • setQueueRunning

      public void setQueueRunning(boolean running)
    • countMessagesInQueue

      public Map<String,Integer> countMessagesInQueue(String queueName)
    • getQueueSize

      public long getQueueSize(String queueName)
      Returns the number of messages currently in the given queue, read from broker JMX metadata (DestinationViewMBean.getQueueSize()). Unlike countMessagesInQueue(String) this opens no client connection and does not enumerate the queue, so it stays cheap even for a large backlog and is safe to call on every page render.
      Parameters:
      queueName - name of the queue
      Returns:
      the queue size, or 0 if the broker is unavailable or the size cannot be read
    • getTotalQueueSize

      public long getTotalQueueSize()
      Sums getQueueSize(String) across all QUEUE_NAMES. Cheap enough to call frequently (e.g. the admin topbar background-task monitor) because it reads broker metadata rather than browsing messages.
      Returns:
      total number of messages across all queues; 0 if the broker is unavailable
    • countMessagesBefore

      public int countMessagesBefore(String queueName, String messageType, String messageId)
    • startConnection

      public org.apache.activemq.ActiveMQConnection startConnection() throws JMSException
      Throws:
      JMSException
    • getConnection

      public org.apache.activemq.ActiveMQConnection getConnection() throws JMSException
      Throws:
      JMSException
    • pauseQueue

      public boolean pauseQueue(String queueName)
    • resumeQueue

      public boolean resumeQueue(String queueName)
    • clearQueue

      public boolean clearQueue(String queueName)
    • getWaitingMessages

      public List<ViewerMessage> getWaitingMessages(String messageType)
    • deleteMessage

      public boolean deleteMessage(ViewerMessage ticket)
    • deleteMessage

      public boolean deleteMessage(String taskName, String messageId)
    • deleteMessages

      public int deleteMessages(String type)
    • hasConfig

      public boolean hasConfig()
    • getListeners

      public List<DefaultQueueListener> getListeners()