Hi - Please help! I have a multi-threaded application that involves three threads: Filter, EventRecognizer, and Checker. Initially the application communicated successfully using PipeStreaming with DataStreaming. Now I want to communicate non-primitive objects, so I am changing the communication to be PipeStreaming with ObjectStreaming. Unfortunately the execution freezes somewhere between communication of Filter to EventRecognizer, I think?K ?? any ideas and/or suggestions? Why is this happening? How do I fix it? I have attached some bits of the application code below. Any ideas/suggestions to get this working would be most appreciated. Unfortunately, the code is quite detailed so I did my best to extract the causing parts. Feel free to contact me at natalieabowles@hotmail.com as well. Thank you!
[i] /** This method performs 3 jobs * 1. It initialize communication channel to an event recognizer. * 2. It sets the size of buffers and other configurations based on * run-time parameters * 3. It generates a filter thread. A filter thread performs book-keeping of * address/name table and actuall communication for making low overhead * to original program */[/i] [b]static public void ??[/b]??init(String host, int port, int period, boolean deltaValue){ [i]// Communication channel // If initialization is already performed, do not do it again[/i] ??[b]??if??[/b]??( initDone ) { return;}
initDone = true;
[b]try { if [/b](port == 0 && host == null) sout = Pipe.filterEROutput; [b] else {[/b] s = new Socket(host,port); sout = s.getOutputStream(); }
[i]// For efficiency, use BufferedOutput[/i] [b]////oStream = new DataOutputStream(sout); oStream = new ObjectOutputStream(sout);[/b]
/* Usa: Check for timestamps */ System.out.println("Filter:period -> "+period); ??[b]??try{[/b] ////oStream = new DataOutputStream( oStream = new ObjectOutputStream( new FileOutputStream(filename,false)); ??[b]??if[/b](period != 0 ) new TimeStamp(period); SendMethods.delta = deltaValue; }catch(IOException e) { System.out.println("I Caught this IOException in Filter.java: " + e); System.err.println("In init(String), " + e); } } public static void init(int period, boolean deltaValue) { // general output stream if( initDone ) { return;} initDone = true;
/* Usa: Check for timestamps */ System.out.println("Filter:period -> "+period);
if( period != 0 ) new TimeStamp(period); SendMethods.delta = deltaValue; }
[i]/** This method is used for giving inputstream and output stream to the * target application. targetClass should be fully qualified class name. parameter is is ignored */[/i] ??[b]??public static void[/b] hook(String targetClass, String[] args, InputStream is, OutputStream os) { ??[b]??try{ ////oStream = new DataOutputStream(os); oStream = new ObjectOutputStream(os);[/b] Class targetApp = Class.forName(targetClass);
Method main = targetApp.getMethod("main", new Class[] {Class.forName("[Ljava.lang.String;")}); main.invoke(null, new Object[] { args}); oStream.close(); }catch (IOException ioe) { System.out.println("I Caught this IOException in Filter.java: " + ioe); } catch(Exception e) {System.err.println(e);System.exit(-1); }
??[b]??protected final int[/b] MAX_HEIGHT; // maximum height in tree ??[b]??public final static int[/b] startID = PedlInstrObject.startID; OutputStream outStream; InputStream inputStream;
[i]// For reducing the run-time cost of creating an object of ErChkObject, // I create the object once then change the contents of the // object every time. [/i] ??[b]??protected[/b] ErChkObject obj ; ??[b]??protected[/b] InterfaceERChecker exportTBL;
[b]try { ////events_conds_out = new DataOutputStream(outStream); events_conds_out = new ObjectOutputStream(outStream);
////primitiveIn = new DataInputStream(inStream); primitiveIn = new ObjectInputStream(inStream); } catch [/b](IOException ioe) { System.out.println("I Caught this IOException in EventRecognizer.java: " + ioe); } hasTimeStamp = objMonEntities.isTimeStampRequired(); exportTBL = new InterfaceERChecker( exportEvents,exportConditions,hasTimeStamp);
MAX_HEIGHT = parseTree.getHeight(); }
[b]public void[/b] run() { [b]int dataType; int varId=0;[/b]
[b]String[/b] type = null; [b]byte[][/b] ba = new byte[200]; [b]Object[/b] value = null;
initializeSymbolTbl();
ObjectOutputStream oOut = new ObjectOutputStream(outStream); oOut.writeObject(exportTBL); oOut.flush();
[b]for(;;)[/b] {
[b]varId = primitiveIn.readByte();[/b]
// Special id sections such as time stamps [b]switch[/b](varId ) { case 0: System.err.println( "Something wrong happens; ID 0 is received!"); break; case 1: currentTargetTime += period; continue; default: }
[b]switch[/b](dataType) { case DataTypes.SHORT: value = getObjectValue(primitiveIn.readShort()); updateSymbolTBL(varId,value); break; case DataTypes.INT: value = getObjectValue(primitiveIn.readInt()); updateSymbolTBL(varId,value); break; case DataTypes.LONG: value = getObjectValue(primitiveIn.readLong()); updateSymbolTBL(varId,value); break; case DataTypes.FLOAT: value = getObjectValue(primitiveIn.readFloat()); updateSymbolTBL(varId,value); break; case DataTypes.DOUBLE: value = getObjectValue(primitiveIn.readDouble()); updateSymbolTBL(varId,value); break; case DataTypes.BYTE: value = getObjectValue(primitiveIn.readByte()); updateSymbolTBL(varId,value); break; case DataTypes.CHAR: value = getObjectValue(primitiveIn.readChar()); updateSymbolTBL(varId,value); break; case DataTypes.BOOLEAN: // From Nov 27, method start/end is informed through // boolean, not string temp = primitiveIn.readBoolean(); [b]if[/b]( varId < // Execution point numExecPoints+startID) { value = temp ? "end of " + monExecPoints.elementAt( varId - startID) : "start of "+monExecPoints.elementAt(varId - startID); //System.out.println(varId+":"+value); [b]} else[/b] value = getObjectValue(temp);
updateSymbolTBL(varId,value); break; case DataTypes.STRING: // Execution Point value = primitiveIn.readUTF(); updateSymbolTBL(varId,value); break; default: }
evaluateBackward(varId, value);
sendSignals();
}
}[b] catch[/b](EOFException e){ System.out.println("ER: Trace is completely read."); [b]try[/b]{outStream.flush();} [b]catch[/b](IOException ioe) {System.err.println(ioe);} System.exit(0); } [b]catch[/b](IOException e){ if (e.getMessage().equals("Pipe broken") || e.getMessage().equals("Write end dead")) { System.out.println("ER: Trace is completely read."); [b]try{[/b] outStream.flush(); } [b]catch[/b](IOException ioe) {System.err.println(ioe);} } [b]else[/b] e.printStackTrace(); } } [i]/** * Given snapshot object from the filter, it checks what events * happen or what conditions are satisfied. Then it sends detected * events and conditions to the run-time checker[/i] */ [b]Object[/b] getObjectValue(short s) { return (new Short(s)); } [b]Object[/b] getObjectValue(int i) { return (new Integer(i)); } [b]Object[/b] getObjectValue(long l) { return (new Long(l)); } [b]Object[/b] getObjectValue(float f) { return (new Float(f)); } [b]Object[/b] getObjectValue(double d) { return (new Double(d)); } [b]Object[/b] getObjectValue(char c) { return (new Character(c)); } [b]Object[/b] getObjectValue(boolean b) { return (new Boolean(b)); } [b]Object[/b] getObjectValue(int varId, byte b) { return (new Byte(b)); } [b]Object[/b] getObjectValue(int varId, String s) { return s; }
[b]void[/b] updateSymbolTBL(int varId, Object value) { if( - startID < varId && varId < startID ) { System.err.println("varId:" + varId + " must not be in the reserved index range " +"(-"+startID+", "+startID+") at updateSymbolTBL()!"); } String varName = null; [b]int _varId = varId >= 0 ? varId - startID : - varId - startID;[/b]
for(int i=0; i < numOccurredEvents; i++) { values = occurredEventValues[i];
// Currently, only update(x) contains a value vector which // contains only 1 value. endM and startM should have a // value vector, but not yet implemented // Other types of events have null as a value vector if( values.isEmpty() ) { typeEventValue = DataTypes.NONE; } else { value = values.elementAt(0);
if( value instanceof Integer) typeEventValue = DataTypes.INT; else if( value instanceof Short) typeEventValue = DataTypes.SHORT; else if( value instanceof Long) typeEventValue = DataTypes.LONG; else if( value instanceof Float) typeEventValue = DataTypes.FLOAT; else if( value instanceof Double) typeEventValue = DataTypes.DOUBLE; else if( value instanceof Byte) typeEventValue = DataTypes.BYTE; else if( value instanceof Character) typeEventValue = DataTypes.CHAR; else if( value instanceof Boolean) typeEventValue = DataTypes.BOOLEAN; else if( value instanceof String) typeEventValue = DataTypes.STRING; else if( value instanceof ThreeValued) typeEventValue = DataTypes.UNDEF; else System.err.println(value + " is not primitive numeric type nor String"); } [b]try{[/b]
events_conds_out.writeByte(typeEventValue); [b]switch[/b](typeEventValue) { case DataTypes.NONE: // No value break; case DataTypes.SHORT: events_conds_out.writeShort(((Short)value).shortValue()); break; case DataTypes.INT: events_conds_out.writeInt(((Integer)value).intValue()); break; case DataTypes.LONG: events_conds_out.writeLong(((Long)value).longValue()); break; case DataTypes.FLOAT: events_conds_out.writeFloat(((Float)value).floatValue()); break; case DataTypes.DOUBLE: events_conds_out.writeDouble( ((Double)value).doubleValue()); break; case DataTypes.BYTE: events_conds_out.writeByte(((Byte)value).byteValue()); break; case DataTypes.CHAR: events_conds_out.writeChar( ((Character)value).charValue()); break; case DataTypes.BOOLEAN: events_conds_out.writeBoolean( ((Boolean)value).booleanValue()); break; case DataTypes.UNDEF: // false is dumb value events_conds_out.writeBoolean(false); break; case DataTypes.STRING: events_conds_out.writeObject((String)value); break; default: System.err.println( "Incorrect type of value of event " + ev.getName() + " " + typeEventValue); } //System.err.println(occurredEventNames[i]+":"+values+"-"+num++ +"-:" + currentTargetTime); // Deactivating events for next time instance se = (SymtabEntry)symbolTbl.get( occurredEventNames[i]); ((SimpleNode)se.getValue()).setValue(new EventType(false)); } catch(IOException e1) { System.err.println(e1); } }