From: Önder G. <ond...@gm...> - 2011-04-27 14:32:37
|
Hello all, I have a strange problem about watchers in Repast. I have a class called Neuron. And I have another class that watches this agent like below: @Watch(watcheeClassName = "demo.Neuron", watcheeFieldNames = "potential", query = "colocated", triggerCondition = "$watchee.getPotential() > " + Spike.FIRING_THRESHOLD, whenToTrigger = WatcherTriggerSchedule.IMMEDIATE) public void monitorINeuronResponses(Neuron watcheeNeuron) { ....} This code is working fine. However, today I needed to create two subclasses of Neuron class: INeuron and RNeuron. Some agents are INeuron and some others are RNeuron instances. I remain the watch mechanism same. But when I run the code it says: java.lang.ClassCastException: demo.INeuron cannot be cast to demo.RNeuron at Synthetic$BooleanExpression1.execute(Synthetic$BooleanExpression1.java) at repast.simphony.engine.watcher.query.AndBooleanCondition.execute(AndBooleanCondition.java:27) at repast.simphony.engine.watcher.ImmediateExecutor.scheduleExecution(ImmediateExecutor.java:30) at repast.simphony.engine.watcher.Notifier2.triggered(Notifier2.java:136) at repast.simphony.engine.watcher.WatcherTrigger.notify(WatcherTrigger.java:112) at repast.simphony.engine.watcher.WatcherTrigger.triggered(WatcherTrigger.java:126) at singlemotorunit.Neuron.setPotential(Neuron.java:384) at singlemotorunit.Neuron.innervate(Neuron.java:170) at singlemotorunit.WiringViewer$ACExciteAfferentNeuronsRandomly.execute(WiringViewer.java:211) at repast.simphony.engine.schedule.DefaultAction.execute(DefaultAction.java:38) at repast.simphony.engine.schedule.ScheduleGroup.executeList(ScheduleGroup.java:184) at repast.simphony.engine.schedule.ScheduleGroup.execute(ScheduleGroup.java:201) at repast.simphony.engine.schedule.Schedule.execute(Schedule.java:352) at verm.RepastRunner.step(RepastRunner.java:90) at verm.AbstractScenarioTest.runScenarioForOnce(AbstractScenarioTest.java:67) at test.singlemotorunit.scenario03.ScenarioTest.runTest(ScenarioTest.java:18) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59) at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98) at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79) at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87) at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77) at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42) at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) This is so strange, because in my demo, when I use only one type of class (either INeuron or RNeuron), there is no problem. But when I create agents from both classes there is always problem. I suppose the RePast framework detects one of them as a main element in the Context object I created. Shall I do something when creating the context object? I also tried changing the watch mechanism to watch INeuron agent but, the field I use for watching is defined in the super class (Neuron), and I need to repeat the same in order to make it work. Can anyone help me? Best regards, Önder. |