Class AbstractConsoleSession<O,R extends ConsoleRequest<R>>
- Type Parameters:
O- associated owner typeR- associated request type
- All Implemented Interfaces:
ConsoleSession<O,R>
- Direct Known Subclasses:
AbstractExecSession,AbstractShellSession
ConsoleSession implementations.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract intExecute this session.protected booleandoInterrupt(Thread thread) Interrupt execution.intexecute()Execute this session synchronously in the current thread.getOwner()Get the owner, i.e., the console component that created this session.Get the request from which this session was created.booleanInterrupt the execution of this session.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.dellroad.jct.core.ConsoleSession
getErrorStream, getInputStream, getOutputStream
-
Field Details
-
owner
-
request
-
-
Constructor Details
-
AbstractConsoleSession
Constructor.- Parameters:
owner- session ownerrequest- associated request- Throws:
IllegalArgumentException- if either parameter is null
-
-
Method Details
-
getOwner
Description copied from interface:ConsoleSessionGet the owner, i.e., the console component that created this session.- Specified by:
getOwnerin interfaceConsoleSession<O,R extends ConsoleRequest<R>> - Returns:
- owning component
-
getRequest
Description copied from interface:ConsoleSessionGet the request from which this session was created.- Specified by:
getRequestin interfaceConsoleSession<O,R extends ConsoleRequest<R>> - Returns:
- original request
-
execute
Description copied from interface:ConsoleSessionExecute this session synchronously in the current thread.Instances should ensure any associated resources are cleaned up when this method returns, whether normally or via thrown exception.
- Specified by:
executein interfaceConsoleSession<O,R extends ConsoleRequest<R>> - Returns:
- zero if successful, non-zero error code if an error occurred
- Throws:
InterruptedException- if execution is interrupted viaConsoleSession.interrupt()
-
interrupt
public boolean interrupt()Description copied from interface:ConsoleSessionInterrupt the execution of this session.This method no effect unless
ConsoleSession.execute()has been invoked and not yet returned.How this method is handled is up to the session: in general, it should cause the execution of
ConsoleSession.execute()to be interrupted, such thatConsoleSession.execute()then either throws anInterruptedExceptionor at least returns immediately. In general, it should have roughly the same effect as one would expect when pressing Control-C on a controlling terminal.- Specified by:
interruptin interfaceConsoleSession<O,R extends ConsoleRequest<R>> - Returns:
- true if execution was interrupted, false if it was not possible to interrupt execution
-
doExecute
Execute this session.This method is invoked by
execute()to do the actual work.- Returns:
- zero if successful, non-zero error code if an error occurred
- Throws:
InterruptedException- if the current thread is interrupted
-
doInterrupt
Interrupt execution.This method is invoked by
interrupt()to actually do whatever is needed to interrupt execution, but only ifexecute()is still executing.The implementation in
AbstractConsoleSessionjust invokesThread.interrupt()on the given thread.NOTE: When this method is invoked, the current instance will be locked.
- Parameters:
thread- the thread currently executingexecute()- Returns:
- true if execution was interrupted, false if it was not possible to interrupt execution
- Throws:
IllegalArgumentException- ifthreadis null
-