Execute and wait an operation

From AIBenchWiki

Jump to: navigation, search

This example shows how to invoke an operation execution, and wait until it finishes


private void convert(String inputPdfPath, String outputPdfPath){
	
    ParamSpec[] paramsSpec = new ParamSpec[]{ 
        new ParamSpec("inputfile", File.class, new File(inputPdfPath), null),
        new ParamSpec("outputfile", File.class, new File(outputPdfPath), null)
    };

    //search a specific operation definition by name
    for (OperationDefinition op : Core.getInstance().getOperations()){
        if (op.getID().equals("operations.pdftotxt")){	
            final Object lockingObject = new Object();
            final List<Object> theResults = new ArrayList<Object>();
				
            ProgressHandler handler = new ProgressHandler(){
					
                public void validationError(Throwable t){}
                public void operationStart(Object progressBean, Object operationID){}
                public void operationError(Throwable t){}
										
                public void operationFinished(List<Object> results, List<ClipboardItem> clipboardItems){
									
                    theResults.addAll(results);
						
                    synchronized(lockingObject){
                        lockingObject.notify();
                    }
                }
            };

            synchronized(lockingObject){
                Core.getInstance().executeOperation(op, handler, paramsSpec); 
                try{
                    lockingObject.wait();
                }catch(InterruptedException e){
            }
        }
    }
}
Personal tools
Documentation