GNDMS 0.6.0
RESTful verison of GNDMS
Classes | Public Member Functions | Protected Member Functions | Private Attributes

de.zib.gndms.logic.action.ProcessBuilderAction Class Reference

Wrapper around ProcessBuilder that allows piping into the process and collecting all output in a string builder. More...

Inherits de::zib::gndms::logic::action::AbstractAction< Integer >.

List of all members.

Classes

class  InputCollector
 An InputCollector collects the incoming stream from an process and sends it to an receiver. More...
class  OutputCollector
 An OutputCollector collects the process' outgoing streams and sends them to their corresponding receivers. More...

Public Member Functions

void initialize ()
Integer execute ()
StringBuilder getOutputReceiver ()
 Returns the output receiver.
void setOutputReceiver (final StringBuilder outputReceiverParam)
 Sets the output receiver.
StringBuilder getErrorReceiver ()
 Returns the error receiver.
void setErrorReceiver (final StringBuilder errorReceiverParam)
 Sets the error receiver.
ProcessBuilder getProcessBuilder ()
void setProcessBuilder (final ProcessBuilder processBuilderParam)

Protected Member Functions

abstract void writeProcessStdIn (final @NotNull BufferedOutputStream stream) throws IOException
void storeProcessStdOut (String line)
 Stores the process' outgoing streams from a process.
void storeProcessStdErr (String line)
 Stores the process' outgoing error stream into the error receiver.

Private Attributes

StringBuilder outputReceiver
StringBuilder errorReceiver
ProcessBuilder processBuilder

Detailed Description

Wrapper around ProcessBuilder that allows piping into the process and collecting all output in a string builder.

Author:
try ste fan pla nti kow zib
Version:
$Id$

User: stepn Date: 21.10.2008 Time: 15:05:18


Member Function Documentation

Integer de.zib.gndms.logic.action.ProcessBuilderAction.execute ( )
Returns:
                             {
        final FillOnce<Throwable> cause = new FillOnce<Throwable>(true);
        final FillOnce<Process> proc = new FillOnce<Process>(false);
        final FillOnce<Thread> mainThread = new FillOnce<Thread>(false);

        try {
            mainThread.set(Thread.currentThread());
            final Thread inputProvider = new Thread(new InputCollector(cause, proc, mainThread));
            final Thread outputCollector =
                      new Thread(new OutputCollector(cause, proc, mainThread, false));
            final Thread errorCollector =
                      new Thread(new OutputCollector(cause, proc, mainThread, true));

            inputProvider.start();
            outputCollector.start();
            errorCollector.start();

            final Process process = processBuilder.start();
            proc.set(process);

                inputProvider.join();
                errorCollector.join();
            outputCollector.join();

                return process.waitFor();
        }
        catch (IOException e) {
            throw new RuntimeException(e);
        }
        catch (InterruptedException e) {
            if (cause.has())
                throw new RuntimeException(cause.get());
            else
                throw new RuntimeException(e);
        }
    }
StringBuilder de.zib.gndms.logic.action.ProcessBuilderAction.getErrorReceiver ( )

Returns the error receiver.

Returns:
the error receiver
                                                {
                return errorReceiver;
        }
StringBuilder de.zib.gndms.logic.action.ProcessBuilderAction.getOutputReceiver ( )

Returns the output receiver.

Returns:
the output receiver
                                             {
        return outputReceiver;
    }
void de.zib.gndms.logic.action.ProcessBuilderAction.setErrorReceiver ( final StringBuilder  errorReceiverParam)

Sets the error receiver.

Parameters:
errorReceiverParamthe error receiver to be set
                                                                             {
                errorReceiver = errorReceiverParam;
        }
void de.zib.gndms.logic.action.ProcessBuilderAction.setOutputReceiver ( final StringBuilder  outputReceiverParam)

Sets the output receiver.

Parameters:
outputReceiverParamthe output receiver to be set
                                                                           {
        outputReceiver = outputReceiverParam;
    }
void de.zib.gndms.logic.action.ProcessBuilderAction.storeProcessStdErr ( String  line) [protected]

Stores the process' outgoing error stream into the error receiver.

Parameters:
linethe outgoing error String to be stored from a process
                                                       {
                getErrorReceiver().append(line);
                getErrorReceiver().append('\n');
        }
void de.zib.gndms.logic.action.ProcessBuilderAction.storeProcessStdOut ( String  line) [protected]

Stores the process' outgoing streams from a process.

Messages will be stored in the outputreceiver as well as in the errorReceiver

Parameters:
linethe outgoing String to be stored from a process
                                                       {
                getOutputReceiver().append(line);
                getOutputReceiver().append('\n');
                getErrorReceiver().append(line);
                getErrorReceiver().append('\n');
        }

The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables