Class JobQueueProxy<U extends StatusBean>

java.lang.Object
org.eclipse.scanning.event.JobQueueProxy<U>
All Implemented Interfaces:
AutoCloseable, IBeanClass<U>, IConnection, IJobQueue<U>, IURIConnection

public final class JobQueueProxy<U extends StatusBean> extends Object implements IJobQueue<U>
  • Field Details

  • Constructor Details

  • Method Details

    • getRunningAndCompleted

      public List<U> getRunningAndCompleted() throws EventException
      Description copied from interface: IJobQueue
      Return a list of beans whose jobs are either running or completed. The list is ordered by submission time, not necessarily the ordering of the JMS queue.
      Specified by:
      getRunningAndCompleted in interface IJobQueue<U extends StatusBean>
      Returns:
      running and completed beans
      Throws:
      EventException - if the set of running and completed beans cannot be returned for any reason
    • getRunningAndCompleted

      public List<U> getRunningAndCompleted(String optionalArgument) throws EventException
      Description copied from interface: IJobQueue
      Returns either the list returned by IJobQueue.getRunningAndCompleted() or a sublist of that list, limited by the argument. Currently the optional argument may be a non-negative integer in which case if the number of submitted + running + completed scans exceeds the argument, completed scans are removed until either none remain or the number of scans being returned is less than the argument. If a scan is running it must always be returned. If any String that would not parse to a non-negative integer is passed, then the argument is taken to be unlimited, and this method should return IJobQueue.getRunningAndCompleted()
      Specified by:
      getRunningAndCompleted in interface IJobQueue<U extends StatusBean>
      Parameters:
      optionalArgument - a String representation of a non-negative integer ("0", "1", "2"...)
      Returns:
      list containing the running bean and optionally some completed beans
      Throws:
      EventException
    • clearQueue

      public void clearQueue() throws EventException
      Description copied from interface: IJobQueue
      Removes all pending jobs from the submission queue.
      Specified by:
      clearQueue in interface IJobQueue<U extends StatusBean>
      Throws:
      EventException - if the queue cannot be cleared for any reason
    • clearRunningAndCompleted

      public void clearRunningAndCompleted() throws EventException
      Description copied from interface: IJobQueue
      Clears the set of beans for running and completed jobs.
      Specified by:
      clearRunningAndCompleted in interface IJobQueue<U extends StatusBean>
      Throws:
      EventException - if the set of running and completed
    • clearRunningAndCompleted

      public void clearRunningAndCompleted(boolean bool) throws EventException
      Description copied from interface: IJobQueue
      Clears the set of beans for running and completed jobs, with an optional argument for whether to clear the currently running scan (if there is one)
      Specified by:
      clearRunningAndCompleted in interface IJobQueue<U extends StatusBean>
      Throws:
      EventException - if the set of running and completed
    • disconnect

      public void disconnect() throws EventException
      Description copied from interface: IConnection
      Call to disconnect any resources which we no longer need. The resource may have timed out so it might not be connected, in that case it silently returns. Note, that the method IConnection.close(), inherited from AutoCloseable calls this method, which means that if an object of a class implementing IConnection is used with a try-with-resources block this method will be called automatically when exiting that block.
      Specified by:
      disconnect in interface IConnection
      Throws:
      EventException - if resource could not be disconnected.
    • submit

      public void submit(U bean) throws EventException
      Only called when a StatusBean is re-submitted, not on initial submit (see SubmitScanSection.submit()) or from mscan (old or new) Therefore, probably want to refresh the queue of all clients watching the JobQueueImpl
      Specified by:
      submit in interface IJobQueue<U extends StatusBean>
      Parameters:
      bean - bean to add
      Throws:
      EventException
    • moveForward

      public boolean moveForward(U bean) throws EventException
      Description copied from interface: IJobQueue
      Moves the given bean towards the head of the submission queue if possible, i.e. it will be processed sooner.
      Specified by:
      moveForward in interface IJobQueue<U extends StatusBean>
      Parameters:
      bean -
      Returns:
      true if the bean could be moved, false otherwise
      Throws:
      EventException
    • moveBackward

      public boolean moveBackward(U bean) throws EventException
      Description copied from interface: IJobQueue
      Moves the given bean towards the tail of the submission queue if possible, i.e. it will be processed later.
      Specified by:
      moveBackward in interface IJobQueue<U extends StatusBean>
      Parameters:
      bean -
      Returns:
      true if the bean could be moved, false otherwise
      Throws:
      EventException
    • remove

      public boolean remove(U bean) throws EventException
      Description copied from interface: IJobQueue
      Removes the bean from the submission queue if present. If the bean has been moved to the set of running and completed jobs, it will not be removed.
      Specified by:
      remove in interface IJobQueue<U extends StatusBean>
      Parameters:
      bean - bean to remove
      Returns:
      true if the bean was removed, false otherwise, i.e. the bean was not present
      Throws:
      EventException
    • removeCompleted

      public boolean removeCompleted(U bean) throws EventException
      Description copied from interface: IJobQueue
      Remove the given bean from the set of beans for running and completed jobs (the status set).
      Specified by:
      removeCompleted in interface IJobQueue<U extends StatusBean>
      Parameters:
      bean - bean to remove
      Returns:
      true if the bean was removed, false otherwise, i.e. the bean was not present
      Throws:
      EventException
    • replace

      public boolean replace(U bean) throws EventException
      Description copied from interface: IJobQueue
      Replace the bean in the submission queue with the given bean, if present. If the bean has been moved to the set of running and completed jobs, it will not be removed. A bean will replace another if it has the same unique id as returned by IdBean.getUniqueId()
      Specified by:
      replace in interface IJobQueue<U extends StatusBean>
      Parameters:
      bean - bean to remove
      Returns:
      true if the bean was replaced, false otherwise, i.e. the bean was not present
      Throws:
      EventException
    • getSubmissionQueue

      public List<U> getSubmissionQueue() throws EventException
      Description copied from interface: IJobQueue
      Get a copy of the current submission queue as a list of beans.
      Specified by:
      getSubmissionQueue in interface IJobQueue<U extends StatusBean>
      Returns:
      the submission queue
      Throws:
      EventException - if the submission queue cannot be returned for any reason
    • setRunner

      public void setRunner(IProcessCreator<U> process) throws EventException
      Description copied from interface: IJobQueue
      Set the consumer process to run for each job.
      Specified by:
      setRunner in interface IJobQueue<U extends StatusBean>
      Parameters:
      process -
      Throws:
      EventException - if the alive topic cannot be sent
    • start

      public void start() throws EventException
      Description copied from interface: IJobQueue
      Starts the consumer in new thread and return. Similar to Thread.start() You must set the runner before calling this method
      Specified by:
      start in interface IJobQueue<U extends StatusBean>
      Throws:
      EventException
    • stop

      public void stop() throws EventException
      Description copied from interface: IJobQueue
      Ask the consumer to stop
      Specified by:
      stop in interface IJobQueue<U extends StatusBean>
      Throws:
      EventException
    • awaitStart

      public void awaitStart() throws InterruptedException
      Description copied from interface: IJobQueue
      Awaits the start of the job queue's consumer thread. Mostly useful for testing.
      Specified by:
      awaitStart in interface IJobQueue<U extends StatusBean>
      Throws:
      InterruptedException
    • awaitStop

      public void awaitStop() throws InterruptedException
      Description copied from interface: IJobQueue
      Awaits the job queue's consumer thread having stopped. Mostly useful for testing.
      Specified by:
      awaitStop in interface IJobQueue<U extends StatusBean>
      Throws:
      InterruptedException
    • run

      public void run() throws EventException
      Description copied from interface: IJobQueue
      Starts the job queue's consumer thread and blocks. Similar to Thread.run() You must set the runner by calling IJobQueue.setRunner(IProcessCreator) before calling this method.
      Specified by:
      run in interface IJobQueue<U extends StatusBean>
      Throws:
      EventException
    • pause

      public void pause() throws EventException
      Description copied from interface: IJobQueue
      Pauses the job queue's consumer thread if running. It will not process any more jobs until it resumes. Currently running jobs are not affected.
      Specified by:
      pause in interface IJobQueue<U extends StatusBean>
      Throws:
      EventException
    • resume

      public void resume() throws EventException
      Description copied from interface: IJobQueue
      Resumes the job queue's consumer thread if paused. It will resume processing jobs.
      Specified by:
      resume in interface IJobQueue<U extends StatusBean>
      Throws:
      EventException
    • isPaused

      public boolean isPaused()
      Description copied from interface: IJobQueue
      Returns whether the job queue's consumer thread is paused.
      Specified by:
      isPaused in interface IJobQueue<U extends StatusBean>
      Returns:
      true if the consumer thread is paused, false otherwise
    • cleanUpCompleted

      public void cleanUpCompleted() throws EventException
      Description copied from interface: IJobQueue
      Cleans up the set of beans for running and completed job by removing certain beans. Specifically, the beans that are removed are those that meet one of the following criteria:
      • have status Status.FAILED or Status.NONE;
      • have a status indicating that they are running (i.e. Status.isRunning() is true) and are older than the maximum running age (by default, two days);
      • have a status indicating that they are final (i.e. Status.isFinal() is true) and are older than the maximum complete age (by default, one week);
      • Additionally jobs that are not started or paused will have their status set to Status.FAILED;

      This method is intended to be called on starting the consumer.

      Specified by:
      cleanUpCompleted in interface IJobQueue<U extends StatusBean>
      Throws:
      EventException
    • pauseJob

      public void pauseJob(U bean) throws EventException
      Description copied from interface: IJobQueue
      If a process for the given bean exists and is running, pauses it. If the bean is still in the submission queue, then instead defers the bean, allowing other scans to be run first.
      Specified by:
      pauseJob in interface IJobQueue<U extends StatusBean>
      Parameters:
      bean - bean whose process to pause.
      Throws:
      EventException
    • resumeJob

      public void resumeJob(U bean) throws EventException
      Description copied from interface: IJobQueue
      If a process for the given bean exists and is paused, resumes it.
      Specified by:
      resumeJob in interface IJobQueue<U extends StatusBean>
      Parameters:
      bean - bean whose process to resume.
      Throws:
      EventException
    • terminateJob

      public void terminateJob(U bean) throws EventException
      Description copied from interface: IJobQueue
      If the process for the given bean exists and is running or paused, terminates it. If the bean is still in the submission queue then instead when the consumer thread removes it from the queue it will set its status to Status.TERMINATED, add the bean to the set of running and completed jobs. It will not create a process for it.
      Specified by:
      terminateJob in interface IJobQueue<U extends StatusBean>
      Parameters:
      bean - bean whose process to terminate
      Throws:
      EventException
    • getRunner

      public IProcessCreator<U> getRunner()
      Description copied from interface: IJobQueue
      Returns the IProcessCreator used as a factory to create IBeanProcess for each bean as they are removed from the submission queue by the consumer thread.
      Specified by:
      getRunner in interface IJobQueue<U extends StatusBean>
      Returns:
      the process creator
    • getCommandTopicName

      public String getCommandTopicName()
      Description copied from interface: IJobQueue
      The topic used to run commands like terminate the running process and get the consumer to stop.
      Specified by:
      getCommandTopicName in interface IJobQueue<U extends StatusBean>
      Returns:
      topic name
    • getCommandAckTopicName

      public String getCommandAckTopicName()
      Description copied from interface: IJobQueue
      The topic used by the consumer to send acknowledgements for commands received on the command topic.
      Specified by:
      getCommandAckTopicName in interface IJobQueue<U extends StatusBean>
      Returns:
      command acknowledgement topic name
    • getQueueStatusTopicName

      public String getQueueStatusTopicName()
      Description copied from interface: IJobQueue
      If set, the name of the topic that the job queue's consumer topic publishes QueueStatusBeans to, to indicate that it is running.
      Specified by:
      getQueueStatusTopicName in interface IJobQueue<U extends StatusBean>
      Returns:
      the queue status topic name, may be null
    • getJobQueueId

      public UUID getJobQueueId()
      Description copied from interface: IJobQueue
      The UUID which uniquely defines this job queue.
      Specified by:
      getJobQueueId in interface IJobQueue<U extends StatusBean>
      Returns:
      job queue id
    • getQueueStatus

      public QueueStatus getQueueStatus()
      Description copied from interface: IJobQueue
      Returns the QueueStatus indicating whether the job queue's consumer thread is QueueStatus.RUNNING, QueueStatus.PAUSED or QueueStatus.STOPPED.
      Specified by:
      getQueueStatus in interface IJobQueue<U extends StatusBean>
      Returns:
      the current status of the queue.
    • addQueueStatusListener

      public void addQueueStatusListener(IJobQueue.IQueueStatusListener listener)
      Specified by:
      addQueueStatusListener in interface IJobQueue<U extends StatusBean>
    • removeQueueStatusListener

      public void removeQueueStatusListener(IJobQueue.IQueueStatusListener listener)
      Specified by:
      removeQueueStatusListener in interface IJobQueue<U extends StatusBean>
    • getName

      public String getName()
      Specified by:
      getName in interface IJobQueue<U extends StatusBean>
    • setName

      public void setName(String name)
      Specified by:
      setName in interface IJobQueue<U extends StatusBean>
    • isActive

      public boolean isActive()
      Description copied from interface: IJobQueue
      Returns if the job queue is active. This is true as long as the consumer thread is not QueueStatus.STOPPED, i.e. it is QueueStatus.RUNNING or QueueStatus.PAUSED.
      Specified by:
      isActive in interface IJobQueue<U extends StatusBean>
      Returns:
      true if the consumer is active
    • isPauseOnStart

      public boolean isPauseOnStart()
      Description copied from interface: IJobQueue
      Returns whether the job queue's consumer thread will start in a paused state if the submission queue is non-empty. If the submission queue is empty this flag will have no effect.
      Specified by:
      isPauseOnStart in interface IJobQueue<U extends StatusBean>
      Returns:
      true if the consumer thread should start paused with a non-empty submission queue, false otherwise
    • setPauseOnStart

      public void setPauseOnStart(boolean pauseOnStart)
      Description copied from interface: IJobQueue
      Sets whether the job queue's consumer thread should start in a paused state if the submission queue is non-empty. If the submission queue is empty this flag will have no effect. Note this must be called before the consumer thread is stared.
      Specified by:
      setPauseOnStart in interface IJobQueue<U extends StatusBean>
      Parameters:
      pauseOnStart - true if the consumer thread should start paused with a non-empty submission queue, false otherwise
    • getBeanClass

      public Class<U> getBeanClass()
      Description copied from interface: IBeanClass
      Class of bean usually extending StatusBean
      Specified by:
      getBeanClass in interface IBeanClass<U extends StatusBean>
      Returns:
      class or null
    • setBeanClass

      public void setBeanClass(Class<U> beanClass)
      Description copied from interface: IBeanClass
      Class of bean usually extending StatusBean It is not compulsory to set the bean class unless trying to deserialize messages sent by older versions of the connector service.
      Specified by:
      setBeanClass in interface IBeanClass<U extends StatusBean>
    • defer

      public void defer(U bean) throws EventException
      Description copied from interface: IJobQueue
      Sets the given bean (which must be Status.SUBMITTED to be deferred, not to be run until it is undeferred.
      Specified by:
      defer in interface IJobQueue<U extends StatusBean>
      Parameters:
      bean - bean whose process to resume.
      Throws:
      EventException
    • undefer

      public void undefer(U bean) throws EventException
      Description copied from interface: IJobQueue
      Allow a submitted, deferred bean to be run when it is reached again.
      Specified by:
      undefer in interface IJobQueue<U extends StatusBean>
      Parameters:
      bean - bean whose process to resume.
      Throws:
      EventException
    • getConnectorService

      public IEventConnectorService getConnectorService()
      Description copied from interface: IURIConnection
      The underlyng service which the uri is connected using
      Specified by:
      getConnectorService in interface IURIConnection
    • getSession

      protected javax.jms.Session getSession() throws javax.jms.JMSException
      Throws:
      javax.jms.JMSException
    • getQueueSession

      protected javax.jms.QueueSession getQueueSession() throws javax.jms.JMSException
      Throws:
      javax.jms.JMSException
    • createQueue

      protected javax.jms.Queue createQueue(String queueName) throws javax.jms.JMSException
      Creates and returns a queue of the given name
      Parameters:
      queueName -
      Returns:
      Throws:
      javax.jms.JMSException
    • getUri

      public URI getUri()
      Description copied from interface: IURIConnection
      The URI of this connection.
      Specified by:
      getUri in interface IURIConnection
      Returns:
    • getSubmitQueueName

      public String getSubmitQueueName()
    • getStatusTopicName

      public String getStatusTopicName()
    • setStatusTopicName

      public void setStatusTopicName(String statusTopicName)
    • isForSameObject

      protected boolean isForSameObject(Object qbean, Object bean)
      A utility method to test if a bean from the queue represents the same bean as that given . This is done by comparing their uniqueIds, if present, and falls back on using Object.equals(Object)
      Parameters:
      qbean -
      bean -
      Returns:
      true if the two beans represent the same object, false otherwise
    • isConnected

      public boolean isConnected()
      Description copied from interface: IConnection
      Returns whether this connection is connected. This method returns true until disconnect is called, even if the connection is created lazily.
      Specified by:
      isConnected in interface IConnection
      Returns:
      true if connected, false otherwise
    • setConnected

      protected void setConnected(boolean connected)