package Sequenic.T2; import java.io.IOException; import java.io.ObjectInputStream; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; import Sequenic.T2.Engines.Util; import Sequenic.T2.Seq.ReportersPool; import Sequenic.T2.Seq.Trace; import Sequenic.T2.StreamTraces.TraceFilter; public class SelectiveSequentialExecutor extends SelectiveParallelExecutor { public SelectiveSequentialExecutor() { } @Override public int execute(String fname, TraceFilter filter) throws InterruptedException, ClassNotFoundException { try { return execute(fname, filter, true); } catch (IOException e) { throw new Error(e); } } @Override public int execute(String trFile, Callable filter, boolean execute) throws InterruptedException, ClassNotFoundException { try { return execute(trFile, filter.call(), execute); } catch (Exception e) { if(e instanceof InterruptedException) throw (InterruptedException) e; if(e instanceof ClassNotFoundException) throw (ClassNotFoundException) e; throw new Error(e); } } private int execute(String fname, TraceFilter filter, boolean execute) throws IOException, ClassNotFoundException { final ObjectInputStream ois = TrFile.initIn(fname); TrFile main = (TrFile) ois.readObject(); final Class c = Class.forName(main.CUTname); final Pool p = (Pool) Util.mkAnInstance(main.poolClassName); final List classinv = new ArrayList(); final ReportersPool nullReporter = ReportersPool.NULLreporter; for (String cowner : main.classinvariantOwners) { classinv.add(Util.getClassINV(Class.forName(cowner))); } int size = ois.readInt(); int count = 0; if(size>0 || size==-2) { while(true) { Trace t = Trace.alternativeSerializationRead(ois); if(t==null) break; if(filter.add(t)) count++; if(execute) t.exec(c, p, classinv, t.diverging, false, nullReporter); if(--size==0) break; } } ois.close(); return count; } @Override public void close() throws IOException{} }