info.sswap.ontologies.exec.impl
Class ExecImpl

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by info.sswap.api.servlet.AbstractSSWAPServlet
              extended by info.sswap.ontologies.exec.impl.ExecImpl
All Implemented Interfaces:
Exec, HotboxPoller, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
ExecServlet

public class ExecImpl
extends AbstractSSWAPServlet
implements Exec, HotboxPoller

Implementation for ExecServlet.

See Also:
ExecServlet, Serialized Form

Field Summary
private static int BLOCK_SIZ
          Limits on user-supplied arguments: size, length, and number
private static int EOF
           
private  java.lang.String hotboxPath
          Optional "hotboxPath" as defined in web.xml.
(package private)  HotboxPoller hotboxPoller
          The hotbox poller; may be null if not invoked
private static int MAX_ARG_LENGTH
           
private static long MAX_BLOCKS
           
private static int MAX_NUM_ARGS
           
private  java.lang.String rdgPath
          "RDGPath" as defined in web.xml.
private static long serialVersionUID
           
private  java.io.File tmpDir
          Temporary working directory (TWD) for the executed process.
 
Fields inherited from class info.sswap.api.servlet.AbstractSSWAPServlet
remoteServiceURI, RRG_RETRIEVAL_SUFFIX
 
Constructor Summary
ExecImpl()
           
 
Method Summary
private  void close(java.io.OutputStream stdin, java.io.InputStream stdout, java.io.InputStream stderr)
          Close streams to release resources and flush output.
private  void fillPipe(java.io.InputStream inputStream, java.io.OutputStream stdin)
          Byte-count limited transferring of bytes from the inputStream to the outputStream.
 java.lang.String[] getCommandLine(java.lang.String commandLineStr)
          Basic parsing and sanity checking of the command line.
private  java.lang.String getStrValue(SSWAPNode sswapNode, java.net.URI ontologyPredicate)
          Get a String value from a property.
protected  void handleRequest(RIG rig)
          This method is marked protected solely for package access purposes and should not be called directly nor overridden.
 void init(javax.servlet.ServletConfig servletConfig)
          Internal initialization for HttpServlet.
 boolean isRunning()
          Check if the hotbox poller is running.
 void setEnvironment(java.util.Map<java.lang.String,java.lang.String> env)
          Set the process' execution environment.
 void setInterval(int sleepSeconds)
          Set the delay interval between directory scans.
 void start()
          Start the hotbox directory polling.
private  java.lang.Process startProcess(java.lang.String[] commandLine)
          Start the process.
 void stop()
          Stop the hotbox directory polling.
private  void validateArgs(java.lang.String[] args)
          Simple argument sanity checking.
 
Methods inherited from class info.sswap.api.servlet.AbstractSSWAPServlet
doGet, doPost, getTimeout, setTimeout
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

BLOCK_SIZ

private static final int BLOCK_SIZ
Limits on user-supplied arguments: size, length, and number

See Also:
Constant Field Values

MAX_BLOCKS

private static final long MAX_BLOCKS
See Also:
Constant Field Values

EOF

private static final int EOF
See Also:
Constant Field Values

MAX_ARG_LENGTH

private static final int MAX_ARG_LENGTH
See Also:
Constant Field Values

MAX_NUM_ARGS

private static final int MAX_NUM_ARGS
See Also:
Constant Field Values

rdgPath

private java.lang.String rdgPath
"RDGPath" as defined in web.xml. This is the path to the "public" directory where the RDF/XML RDGs reside.


hotboxPath

private java.lang.String hotboxPath
Optional "hotboxPath" as defined in web.xml. This is the directory that is polled (scanned every interval) for JSON files awaiting conversion to RDGs, to be placed in the public folder.


hotboxPoller

HotboxPoller hotboxPoller
The hotbox poller; may be null if not invoked


tmpDir

private java.io.File tmpDir
Temporary working directory (TWD) for the executed process. Each process invocation gets a new TWD; TWD is recursively deleted upon normal or exception exit.

Constructor Detail

ExecImpl

public ExecImpl()
Method Detail

init

public void init(javax.servlet.ServletConfig servletConfig)
          throws javax.servlet.ServletException
Internal initialization for HttpServlet. This method is marked public solely for package access purposes and should not be called directly nor overridden.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class AbstractSSWAPServlet
Parameters:
servletConfig - the ServletConfig object of the servlet
Throws:
javax.servlet.ServletException - on a servlet configuration error
See Also:
SSWAP, ServletConfig

handleRequest

protected final void handleRequest(RIG rig)
This method is marked protected solely for package access purposes and should not be called directly nor overridden.

Specified by:
handleRequest in class AbstractSSWAPServlet
Parameters:
rig - RIG invoking the service. This RIG should be edited and will become the basis for the RRG returned by the service. Best practice is to leave most of the RIG untouched, modifying only the SSWAPObject subgraphs.
See Also:
RIG, RRG, RequestEntityTooLargeException, ClientException

getCommandLine

public java.lang.String[] getCommandLine(java.lang.String commandLineStr)
                                  throws TooManyArgumentsException,
                                         ArgumentTooLongException
Description copied from interface: Exec
Basic parsing and sanity checking of the command line. Parsing implies deconstructing a single string into a string array analogous to the array argument passed to Java main(). Override this method to validate, sanitize, and otherwise change the command and the user arguments.

Specified by:
getCommandLine in interface Exec
Parameters:
commandLineStr - a concatenation of the RDG's exec:command and the RIG's exec:args.
Returns:
Java main() equivalent of command line arguments. The command itself must be the first element.
Throws:
TooManyArgumentsException - if the number of arguments exceeds a preset maximum
ArgumentTooLongException - if an argument exceeds a preset maximum

setEnvironment

public void setEnvironment(java.util.Map<java.lang.String,java.lang.String> env)
Description copied from interface: Exec
Set the process' execution environment. Override this method to set the execution environment. Default implementation is to clear the environment.

Specified by:
setEnvironment in interface Exec
Parameters:
env - the default environment ProcessBuilder environment
See Also:
ProcessBuilder.environment()

getStrValue

private java.lang.String getStrValue(SSWAPNode sswapNode,
                                     java.net.URI ontologyPredicate)
Get a String value from a property.

Parameters:
sswapNode - individual with the property
ontologyPredicate - predicate of the property
Returns:
first string value retrieved; empty string "" on any error

startProcess

private java.lang.Process startProcess(java.lang.String[] commandLine)
                                throws java.io.IOException
Start the process. This implies sending the command line to be exectued to the operating system.

Parameters:
commandLine - the command and its arguments to be executed
Returns:
the Process object for process control
Throws:
java.io.IOException - on any error to execute the process

validateArgs

private void validateArgs(java.lang.String[] args)
                   throws TooManyArgumentsException,
                          ArgumentTooLongException
Simple argument sanity checking.

Parameters:
args - array of arguments, not including the command itself
Throws:
TooManyArgumentsException - if the number of arguments exceeds a preset maximum
ArgumentTooLongException - if the length of any argument exceeds a preset maximum

fillPipe

private void fillPipe(java.io.InputStream inputStream,
                      java.io.OutputStream stdin)
               throws java.io.IOException
Byte-count limited transferring of bytes from the inputStream to the outputStream.

Parameters:
inputStream - data to read
stdin - stream to write
Throws:
java.io.IOException - on any error

close

private void close(java.io.OutputStream stdin,
                   java.io.InputStream stdout,
                   java.io.InputStream stderr)
Close streams to release resources and flush output.

Parameters:
stdin - output stream accepting data as input to send to process to execute
stdout - input stream for reading data from executed process
stderr - input stream for reading error messages from executed process

start

public void start()
Description copied from interface: HotboxPoller
Start the hotbox directory polling.

Specified by:
start in interface HotboxPoller

setInterval

public void setInterval(int sleepSeconds)
Description copied from interface: HotboxPoller
Set the delay interval between directory scans.

Specified by:
setInterval in interface HotboxPoller
Parameters:
sleepSeconds - number of seconds to wait between polling

stop

public void stop()
Description copied from interface: HotboxPoller
Stop the hotbox directory polling.

Specified by:
stop in interface HotboxPoller

isRunning

public boolean isRunning()
Description copied from interface: HotboxPoller
Check if the hotbox poller is running.

Specified by:
isRunning in interface HotboxPoller
Returns:
true if running; false if stopped; e.g., because it was never started or because it was stopped (interrupted).


Copyright (c) 2011, iPlant Collaborative, University of Arizona, Cold Spring Harbor Laboratories, University of Texas at Austin.