Package com.arthenica.ffmpegkit
Class AbstractSession
- java.lang.Object
-
- com.arthenica.ffmpegkit.AbstractSession
-
- All Implemented Interfaces:
Session
- Direct Known Subclasses:
FFmpegSession,FFprobeSession,MediaInformationSession
public abstract class AbstractSession extends java.lang.Object implements Session
Abstract session implementation which includes common features shared byFFmpeg,FFprobeandMediaInformationsessions.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String[]argumentsCommand arguments as an array.protected java.util.DatecreateTimeDate and time the session was created.static intDEFAULT_TIMEOUT_FOR_ASYNCHRONOUS_MESSAGES_IN_TRANSMITDefines how long default "getAll" methods wait, in milliseconds.protected java.util.DateendTimeDate and time the session has ended.protected java.lang.StringfailStackTraceStack trace of the error received while trying to execute this session.protected java.util.concurrent.Future<?>futureFuture created for sessions executed asynchronously.protected LogCallbacklogCallbackSession specific log callback.protected LogRedirectionStrategylogRedirectionStrategySession specific log redirection strategy.protected java.util.List<Log>logsLog entries received for this session.protected java.lang.ObjectlogsLockLog entry lock.protected ReturnCodereturnCodeReturn code for the completed sessions.protected longsessionIdSession identifier.protected static java.util.concurrent.atomic.AtomicLongsessionIdGeneratorGenerates unique ids for sessions.protected java.util.DatestartTimeDate and time the session was started.protected SessionStatestateState of the session.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSession(java.lang.String[] arguments, LogCallback logCallback, LogRedirectionStrategy logRedirectionStrategy)Creates a new abstract session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLog(Log log)Adds a new log entry for this session.voidcancel()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.StringgetAllLogsAsString()Returns all log entries generated for this session as a concatenated string.java.lang.StringgetAllLogsAsString(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.StringgetCommand()Returns command arguments as a concatenated string.java.util.DategetCreateTime()Returns session create time.longgetDuration()Returns the time taken to execute this session.java.util.DategetEndTime()Returns session end time.java.lang.StringgetFailStackTrace()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.LogCallbackgetLogCallback()Returns the session specific log callback.LogRedirectionStrategygetLogRedirectionStrategy()Returns session specific log redirection strategy.java.util.List<Log>getLogs()Returns all log entries delivered for this session.java.lang.StringgetLogsAsString()Returns all log entries delivered for this session as a concatenated string.java.lang.StringgetOutput()Returns the log output generated while running the session.ReturnCodegetReturnCode()Returns the return code for this session.longgetSessionId()Returns the session identifier.java.util.DategetStartTime()Returns session start time.SessionStategetState()Returns the state of the session.booleanthereAreAsynchronousMessagesInTransmit()Returns whether there are still asynchronous messages being transmitted for this session or not.protected voidwaitForAsynchronousMessagesInTransmit(int timeout)Waits for all asynchronous messages to be transmitted until the given timeout.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.arthenica.ffmpegkit.Session
isFFmpeg, isFFprobe, isMediaInformation
-
-
-
-
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.
-
logCallback
protected final LogCallback logCallback
Session specific log callback.
-
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
protected AbstractSession(java.lang.String[] arguments, LogCallback logCallback, LogRedirectionStrategy logRedirectionStrategy)Creates a new abstract session.- Parameters:
arguments- command argumentslogCallback- session specific log callbacklogRedirectionStrategy- session specific log redirection strategy
-
-
Method Detail
-
getLogCallback
public LogCallback getLogCallback()
Description copied from interface:SessionReturns the session specific log callback.- Specified by:
getLogCallbackin interfaceSession- Returns:
- session specific log callback
-
getSessionId
public long getSessionId()
Description copied from interface:SessionReturns the session identifier.- Specified by:
getSessionIdin interfaceSession- Returns:
- session identifier
-
getCreateTime
public java.util.Date getCreateTime()
Description copied from interface:SessionReturns session create time.- Specified by:
getCreateTimein interfaceSession- Returns:
- session create time
-
getStartTime
public java.util.Date getStartTime()
Description copied from interface:SessionReturns session start time.- Specified by:
getStartTimein interfaceSession- Returns:
- session start time
-
getEndTime
public java.util.Date getEndTime()
Description copied from interface:SessionReturns session end time.- Specified by:
getEndTimein interfaceSession- Returns:
- session end time
-
getDuration
public long getDuration()
Description copied from interface:SessionReturns the time taken to execute this session.- Specified by:
getDurationin 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:SessionReturns command arguments as an array.- Specified by:
getArgumentsin interfaceSession- Returns:
- command arguments as an array
-
getCommand
public java.lang.String getCommand()
Description copied from interface:SessionReturns command arguments as a concatenated string.- Specified by:
getCommandin interfaceSession- Returns:
- command arguments as a concatenated string
-
getAllLogs
public java.util.List<Log> getAllLogs(int waitTimeout)
Description copied from interface:SessionReturns 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:
getAllLogsin 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_TRANSMITexpires.- Specified by:
getAllLogsin interfaceSession- Returns:
- list of log entries generated for this session
-
getLogs
public java.util.List<Log> getLogs()
Description copied from interface:SessionReturns 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:SessionReturns 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:
getAllLogsAsStringin 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_TRANSMITexpires.- Specified by:
getAllLogsAsStringin interfaceSession- Returns:
- all log entries generated for this session as a concatenated string
-
getLogsAsString
public java.lang.String getLogsAsString()
Description copied from interface:SessionReturns 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:
getLogsAsStringin interfaceSession- Returns:
- list of log entries received for this session
-
getOutput
public java.lang.String getOutput()
Description copied from interface:SessionReturns the log output generated while running the session.
-
getState
public SessionState getState()
Description copied from interface:SessionReturns the state of the session.
-
getReturnCode
public ReturnCode getReturnCode()
Description copied from interface:SessionReturns 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:
getReturnCodein 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:SessionReturns 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:
getFailStackTracein 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:SessionReturns session specific log redirection strategy.- Specified by:
getLogRedirectionStrategyin interfaceSession- Returns:
- session specific log redirection strategy
-
thereAreAsynchronousMessagesInTransmit
public boolean thereAreAsynchronousMessagesInTransmit()
Description copied from interface:SessionReturns whether there are still asynchronous messages being transmitted for this session or not.- Specified by:
thereAreAsynchronousMessagesInTransmitin interfaceSession- Returns:
- true if there are still asynchronous messages being transmitted, false otherwise
-
addLog
public void addLog(Log log)
Description copied from interface:SessionAdds a new log entry for this session.It is invoked internally by
FFmpegKitlibrary methods. Must not be used by user applications.
-
getFuture
public java.util.concurrent.Future<?> getFuture()
Description copied from interface:SessionReturns the future created for this session, if it is executed asynchronously.
-
cancel
public void cancel()
Description copied from interface:SessionCancels 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
-
-