staticabstractclass FieldTracer { publicfinalvoid notifyFieldAccess(
Executable method, long location, Class<?> f_klass, Object target, Field f) {
System.out.println("FieldTracer: " + this.getClass());
System.out.println("\tACCESS of " + f + " on object of" + " type: " + (target == null ? null : target.getClass()) + " in method " + method);
handleFieldAccess(method, location, f_klass, target, f);
}
publicfinalvoid notifyFieldModify(
Executable method, long location, Class<?> f_klass, Object target, Field f, Object value) {
System.out.println("FieldTracer: " + this.getClass());
System.out.println("\tMODIFY of " + f + " on object of" + " type: " + (target == null ? null : target.getClass()) + " in method " + method + ". New value: " + value + " (type: " + value.getClass() + ")");
handleFieldModify(method, location, f_klass, target, f, value);
}
publicvoid handleFieldAccess(Executable m, long l, Class<?> fk, Object t, Field f) {} publicvoid handleFieldModify(Executable m, long l, Class<?> fk, Object t, Field f, Object v) {}
}
privatestaticclass TestError extends Error { privatestaticfinallong serialVersionUID = 0; public TestError(String s) { super(s); }
} staticclass DoNothingFieldTracer extends FieldTracer {} staticclass ThrowReadFieldTracer extends FieldTracer {
@Override publicvoid handleFieldAccess(Executable m, long l, Class<?> fk, Object t, Field f) { thrownew TestError("Throwing error during access");
}
} staticclass ThrowWriteFieldTracer extends FieldTracer {
@Override publicvoid handleFieldModify(Executable m, long l, Class<?> fk, Object t, Field f, Object v) { thrownew TestError("Throwing error during modify");
}
} staticclass ModifyDuringReadAndWriteFieldTracer extends FieldTracer {
@Override publicvoid handleFieldModify(Executable m, long l, Class<?> fk, Object t, Field f, Object v) { // NB This is only safe because the agent doesn't send recursive access/modification events up // to the java layer here.
((TestClass1)t).xyz += 100;
}
@Override publicvoid handleFieldAccess(Executable m, long l, Class<?> fk, Object t, Field f) { // NB This is only safe because the agent doesn't send recursive access/modification events up // to the java layer here.
((TestClass1)t).xyz += 10;
}
}
staticclass ModifyDuringWriteFieldTracer extends FieldTracer {
@Override publicvoid handleFieldModify(Executable m, long l, Class<?> fk, Object t, Field f, Object v) { // NB This is only safe because the agent doesn't send recursive access/modification events up // to the java layer here.
((TestClass1)t).xyz += 200;
}
}
staticclass ModifyDuringReadFieldTracer extends FieldTracer {
@Override publicvoid handleFieldAccess(Executable m, long l, Class<?> fk, Object t, Field f) { // NB This is only safe because the agent doesn't send recursive access/modification events up // to the java layer here.
((TestClass1)t).xyz += 20;
}
}
publicstaticvoid notifyFieldModify(
Executable m, long location, Class<?> f_klass, Object target, Field f, Object value) { if (TRACE != null) {
TRACE.notifyFieldModify(m, location, f_klass, target, f, value);
}
}
publicstaticvoid notifyFieldAccess(
Executable m, long location, Class<?> f_klass, Object target, Field f) { if (TRACE != null) {
TRACE.notifyFieldAccess(m, location, f_klass, target, f);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.