Package com.arthenica.ffmpegkit
Class AbstractSession
- java.lang.Object
-
- com.arthenica.ffmpegkit.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 byFFmpeg
andFFprobe
sessions.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String[]
arguments
Command arguments as an array.protected java.util.Date
createTime
Date and time the session was created.static int
DEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT
Defines how long default "getAll" methods wait, in milliseconds.protected java.util.Date
endTime
Date and time the session has ended.protected ExecuteCallback
executeCallback
Session specific execute callback function.protected java.lang.String
failStackTrace
Stack trace of the error received while trying to execute this session.protected java.util.concurrent.Future<?>
future
Future created for sessions executed asynchronously.protected LogCallback
logCallback
Session specific log callback function.protected LogRedirectionStrategy
logRedirectionStrategy
Session specific log redirection strategy.protected java.util.List<Log>
logs
Log entries received for this session.protected java.lang.Object
logsLock
Log entry lock.protected ReturnCode
returnCode
Return code for the completed sessions.protected long
sessionId
Session identifier.protected static java.util.concurrent.atomic.AtomicLong
sessionIdGenerator
Generates unique ids for sessions.protected java.util.Date
startTime
Date and time the session was started.protected SessionState
state
State of the session.
-
Constructor Summary
Constructors Constructor Description AbstractSession(java.lang.String[] arguments, ExecuteCallback executeCallback, LogCallback logCallback, LogRedirectionStrategy logRedirectionStrategy)
Creates a new abstract session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLog(Log log)
Adds a new log entry for this session.void
cancel()
Cancels running the session.java.util.List<Log>
getAllLogs()
Returns all log entries generated for this session.java.util.List<Log>
getAllLogs(int waitTimeout)
Returns all log entries generated for this session.java.lang.String
getAllLogsAsString()
Returns all log entries generated for this session as a concatenated string.java.lang.String
getAllLogsAsString(int waitTimeout)
Returns all log entries generated for this session as a concatenated string.java.lang.String[]
getArguments()
Returns command arguments as an array.java.lang.String
getCommand()
Returns command arguments as a concatenated string.java.util.Date
getCreateTime()
Returns session create time.long
getDuration()
Returns the time taken to execute this session.java.util.Date
getEndTime()
Returns session end time.ExecuteCallback
getExecuteCallback()
Returns the session specific execute callback function.java.lang.String
getFailStackTrace()
Returns the stack trace of the exception received while executing this session.java.util.concurrent.Future<?>
getFuture()
Returns the future created for this session, if it is executed asynchronously.LogCallback
getLogCallback()
Returns the session specific log callback function.LogRedirectionStrategy
getLogRedirectionStrategy()
Returns session specific log redirection strategy.java.util.List<Log>
getLogs()
Returns all log entries delivered for this session.java.lang.String
getLogsAsString()
Returns all log entries delivered for this session as a concatenated string.java.lang.String
getOutput()
Returns the log output generated while running the session.ReturnCode
getReturnCode()
Returns the return code for this session.long
getSessionId()
Returns the session identifier.java.util.Date
getStartTime()
Returns session start time.SessionState
getState()
Returns the state of the session.boolean
thereAreAsynchronousMessagesInTransmit()
Returns whether there are still asynchronous messages being transmitted for this session or not.protected void
waitForAsynchronousMessagesInTransmit(int timeout)
Waits for all asynchronous messages to be transmitted until the given timeout.
-
-
-
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.
-
state
protected SessionState state
State of the session.
-
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 argumentsexecuteCallback
- session specific execute callback functionlogCallback
- session specific log callback functionlogRedirectionStrategy
- 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 interfaceSession
- 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 interfaceSession
- Returns:
- session specific log callback function
-
getSessionId
public long getSessionId()
Description copied from interface:Session
Returns the session identifier.- Specified by:
getSessionId
in interfaceSession
- Returns:
- session identifier
-
getCreateTime
public java.util.Date getCreateTime()
Description copied from interface:Session
Returns session create time.- Specified by:
getCreateTime
in interfaceSession
- Returns:
- session create time
-
getStartTime
public java.util.Date getStartTime()
Description copied from interface:Session
Returns session start time.- Specified by:
getStartTime
in interfaceSession
- Returns:
- session start time
-
getEndTime
public java.util.Date getEndTime()
Description copied from interface:Session
Returns session end time.- Specified by:
getEndTime
in interfaceSession
- 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 interfaceSession
- 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 interfaceSession
- 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 interfaceSession
- 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 interfaceSession
- 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 untilDEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT
expires.- Specified by:
getAllLogs
in interfaceSession
- 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.
-
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 interfaceSession
- 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 untilDEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMIT
expires.- Specified by:
getAllLogsAsString
in interfaceSession
- 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 interfaceSession
- 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.
-
getState
public SessionState getState()
Description copied from interface:Session
Returns the 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 interfaceSession
- 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 interfaceSession
- Returns:
- stack trace of the exception received while executing this session, null if session is not started, still running or completed
-
getLogRedirectionStrategy
public LogRedirectionStrategy getLogRedirectionStrategy()
Description copied from interface:Session
Returns session specific log redirection strategy.- Specified by:
getLogRedirectionStrategy
in interfaceSession
- Returns:
- session specific log redirection strategy
-
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 interfaceSession
- 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.
-
getFuture
public java.util.concurrent.Future<?> getFuture()
Description copied from interface:Session
Returns the future created for this session, if it is executed asynchronously.
-
cancel
public void cancel()
Description copied from interface:Session
Cancels running the 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
-
-