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 int
Execute this session.protected boolean
doInterrupt
(Thread thread) Interrupt execution.int
execute()
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.boolean
Interrupt the execution of this session.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:ConsoleSession
Get the owner, i.e., the console component that created this session.- Specified by:
getOwner
in interfaceConsoleSession<O,
R extends ConsoleRequest<R>> - Returns:
- owning component
-
getRequest
Description copied from interface:ConsoleSession
Get the request from which this session was created.- Specified by:
getRequest
in interfaceConsoleSession<O,
R extends ConsoleRequest<R>> - Returns:
- original request
-
execute
Description copied from interface:ConsoleSession
Execute 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:
execute
in 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:ConsoleSession
Interrupt 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 anInterruptedException
or 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:
interrupt
in 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
AbstractConsoleSession
just 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
- ifthread
is null
-