Skip to content

Processing

MohammadMehdi edited this page Jul 28, 2019 · 3 revisions

Processing

Processors in JCE, are made for executing and compiling commands with extra features.

BasicProcessor

Example

        String[] commands = {...};
        BasicProcessor basicProcessor = new BasicProcessor(commands);
        basicProcessor.start();

Feature: setOnEachProcessListener

setOnEachProcessListener is an interface that gives you command and processResult methods; you can see each one explanation below.

        ...
        basicProcessor.setOnEachProcessListener(new OnEachProcessListener() {
            @Override
            public void command(String command, int index) {
                
            }

            @Override
            public void processResult(String result, int index) {

            }
        });
        ...
Method Explanation
void command(String, int) gives you the command that is currently processing and invoke before starting execution of the command.
void processResult(String, int) gives you the result of processing that command.

Note: command(String, int) always invoke before processResult(String, int).
Note: index is the index of the command in the given array(String[]) in the constructors.

Feature: AfterProcess

AfterProcess is a runnable that runs after all commands processed. you can use the constructor or Setter method to set an AfterProcess.

        Runnable afterProcess = () -> System.out.println("Processing Finished");
        BasicProcessor basicProcessor = new BasicProcessor(commands,afterProcess); 
        // or
        basicProcessor.setAfterProcess(afterProcess);

TimerProcessor

TimerProcessor is identical with BasicProcessor and also have timing feature. it's obvious from the name though.😬 It only has one constructor and accepts the commands and ExceedTimeInMillis.

        String[] commands = {...};
        int exceedTimeInMillis = 500;
        TimerProcessor timerProcessor = new TimerProcessor(commands,exceedTimeInMillis);
        timerProcessor.start();
Clone this wiki locally