Class AbstractSession

  • All Implemented Interfaces:
    Session
    Direct Known Subclasses:
    FFmpegSession, FFprobeSession

    public abstract class AbstractSession
    extends java.lang.Object
    implements Session
    Abstract session implementation which includes common features shared by FFmpeg and FFprobe sessions.
    • Field Detail

      • sessionIdGenerator

        protected static final java.util.concurrent.atomic.AtomicLong sessionIdGenerator
        Generates unique ids for sessions.
      • DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT

        public static final int DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT
        Defines how long default "getAll" methods wait, in milliseconds.
        See Also:
        Constant Field Values
      • sessionId

        protected final long sessionId
        Session identifier.
      • executeCallback

        protected final ExecuteCallback executeCallback
        Session specific execute callback function.
      • logCallback

        protected final LogCallback logCallback
        Session specific log callback function.
      • createTime

        protected final java.util.Date createTime
        Date and time the session was created.
      • startTime

        protected java.util.Date startTime
        Date and time the session was started.
      • endTime

        protected java.util.Date endTime
        Date and time the session has ended.
      • arguments

        protected final java.lang.String[] arguments
        Command arguments as an array.
      • logs

        protected final java.util.List<Log> logs
        Log entries received for this session.
      • logsLock

        protected final java.lang.Object logsLock
        Log entry lock.
      • future

        protected java.util.concurrent.Future<?> future
        Future created for sessions executed asynchronously.
      • returnCode

        protected ReturnCode returnCode
        Return code for the completed sessions.
      • failStackTrace

        protected java.lang.String failStackTrace
        Stack trace of the error received while trying to execute this session.
      • logRedirectionStrategy

        protected final LogRedirectionStrategy logRedirectionStrategy
        Session specific log redirection strategy.
    • Constructor Detail

      • AbstractSession

        public AbstractSession​(java.lang.String[] arguments,
                               ExecuteCallback executeCallback,
                               LogCallback logCallback,
                               LogRedirectionStrategy logRedirectionStrategy)
        Creates a new abstract session.
        Parameters:
        arguments - command arguments
        executeCallback - session specific execute callback function
        logCallback - session specific log callback function
        logRedirectionStrategy - session specific log redirection strategy
    • Method Detail

      • getExecuteCallback

        public ExecuteCallback getExecuteCallback()
        Description copied from interface: Session
        Returns the session specific execute callback function.
        Specified by:
        getExecuteCallback in interface Session
        Returns:
        session specific execute callback function
      • getLogCallback

        public LogCallback getLogCallback()
        Description copied from interface: Session
        Returns the session specific log callback function.
        Specified by:
        getLogCallback in interface Session
        Returns:
        session specific log callback function
      • getSessionId

        public long getSessionId()
        Description copied from interface: Session
        Returns the session identifier.
        Specified by:
        getSessionId in interface Session
        Returns:
        session identifier
      • getCreateTime

        public java.util.Date getCreateTime()
        Description copied from interface: Session
        Returns session create time.
        Specified by:
        getCreateTime in interface Session
        Returns:
        session create time
      • getStartTime

        public java.util.Date getStartTime()
        Description copied from interface: Session
        Returns session start time.
        Specified by:
        getStartTime in interface Session
        Returns:
        session start time
      • getEndTime

        public java.util.Date getEndTime()
        Description copied from interface: Session
        Returns session end time.
        Specified by:
        getEndTime in interface Session
        Returns:
        session end time
      • getDuration

        public long getDuration()
        Description copied from interface: Session
        Returns the time taken to execute this session.
        Specified by:
        getDuration in interface Session
        Returns:
        time taken to execute this session in milliseconds or zero (0) if the session is not over yet
      • getArguments

        public java.lang.String[] getArguments()
        Description copied from interface: Session
        Returns command arguments as an array.
        Specified by:
        getArguments in interface Session
        Returns:
        command arguments as an array
      • getCommand

        public java.lang.String getCommand()
        Description copied from interface: Session
        Returns command arguments as a concatenated string.
        Specified by:
        getCommand in interface Session
        Returns:
        command arguments as a concatenated string
      • getAllLogs

        public java.util.List<Log> getAllLogs​(int waitTimeout)
        Description copied from interface: Session
        Returns all log entries generated for this session. If there are asynchronous messages that are not delivered yet, this method waits for them until the given timeout.
        Specified by:
        getAllLogs in interface Session
        Parameters:
        waitTimeout - wait timeout for asynchronous messages in milliseconds
        Returns:
        list of log entries generated for this session
      • getAllLogs

        public java.util.List<Log> getAllLogs()
        Returns all log entries generated for this session. If there are asynchronous messages that are not delivered yet, this method waits for them until DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT expires.
        Specified by:
        getAllLogs in interface Session
        Returns:
        list of log entries generated for this session
      • getLogs

        public java.util.List<Log> getLogs()
        Description copied from interface: Session
        Returns all log entries delivered for this session. Note that if there are asynchronous log messages that are not delivered yet, this method will not wait for them and will return immediately.
        Specified by:
        getLogs in interface Session
        Returns:
        list of log entries received for this session
      • getAllLogsAsString

        public java.lang.String getAllLogsAsString​(int waitTimeout)
        Description copied from interface: Session
        Returns all log entries generated for this session as a concatenated string. If there are asynchronous messages that are not delivered yet, this method waits for them until the given timeout.
        Specified by:
        getAllLogsAsString in interface Session
        Parameters:
        waitTimeout - wait timeout for asynchronous messages in milliseconds
        Returns:
        all log entries generated for this session as a concatenated string
      • getAllLogsAsString

        public java.lang.String getAllLogsAsString()
        Returns all log entries generated for this session as a concatenated string. If there are asynchronous messages that are not delivered yet, this method waits for them until DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT expires.
        Specified by:
        getAllLogsAsString in interface Session
        Returns:
        all log entries generated for this session as a concatenated string
      • getLogsAsString

        public java.lang.String getLogsAsString()
        Description copied from interface: Session
        Returns all log entries delivered for this session as a concatenated string. Note that if there are asynchronous log messages that are not delivered yet, this method will not wait for them and will return immediately.
        Specified by:
        getLogsAsString in interface Session
        Returns:
        list of log entries received for this session
      • getOutput

        public java.lang.String getOutput()
        Description copied from interface: Session
        Returns the log output generated while running the session.
        Specified by:
        getOutput in interface Session
        Returns:
        log output generated
      • getState

        public SessionState getState()
        Description copied from interface: Session
        Returns the state of the session.
        Specified by:
        getState in interface Session
        Returns:
        state of the session
      • getReturnCode

        public ReturnCode getReturnCode()
        Description copied from interface: Session
        Returns the return code for this session. Note that return code is only set for sessions that end with COMPLETED state. If a session is not started, still running or failed then this method returns null.
        Specified by:
        getReturnCode in interface Session
        Returns:
        the return code for this session if the session is COMPLETED, null if session is not started, still running or failed
      • getFailStackTrace

        public java.lang.String getFailStackTrace()
        Description copied from interface: Session
        Returns the stack trace of the exception received while executing this session.

        The stack trace is only set for sessions that end with FAILED state. For sessions that has COMPLETED state this method returns null.

        Specified by:
        getFailStackTrace in interface Session
        Returns:
        stack trace of the exception received while executing this session, null if session is not started, still running or completed
      • thereAreAsynchronousMessagesInTransmit

        public boolean thereAreAsynchronousMessagesInTransmit()
        Description copied from interface: Session
        Returns whether there are still asynchronous messages being transmitted for this session or not.
        Specified by:
        thereAreAsynchronousMessagesInTransmit in interface Session
        Returns:
        true if there are still asynchronous messages being transmitted, false otherwise
      • addLog

        public void addLog​(Log log)
        Description copied from interface: Session
        Adds a new log entry for this session.
        Specified by:
        addLog in interface Session
        Parameters:
        log - log entry
      • getFuture

        public java.util.concurrent.Future<?> getFuture()
        Description copied from interface: Session
        Returns the future created for this session, if it is executed asynchronously.
        Specified by:
        getFuture in interface Session
        Returns:
        future that runs this session asynchronously
      • cancel

        public void cancel()
        Description copied from interface: Session
        Cancels running the session.
        Specified by:
        cancel in interface Session
      • waitForAsynchronousMessagesInTransmit

        protected void waitForAsynchronousMessagesInTransmit​(int timeout)
        Waits for all asynchronous messages to be transmitted until the given timeout.
        Parameters:
        timeout - wait timeout in milliseconds