2017-09-05 60 views
2

我在遇到一个java.lang.IllegalMonitorStateException,它在第一次execLinkedOp调用中只发生一次。我想我错过了一些Jason程序应该同步卡塔戈的功能。可能execLinkedOp正在重新生成一些上下文来修复下一次调用的条件。java.lang.IllegalMonitorStateException在CArtAgO(JaCaMo)执行execLinkedOp时第一次执行

以下论坛说,如果缺少同步(foo)调用,可能会发生此类问题。 http://www.jguru.com/faq/view.jsp?EID=128732

[counter] setValue invoked sucessfully! old: count(-1), received: -1 opid:opId(0,setValue,counter,robot) 
[robot] New is (-1) old number is: count(-1) 
[robot] Linking router and counter... 
TRACE: Camel Artifact 'listenCamelRoutes' is true 
DEBUG: Listening by reading the incoming queue... 
DEBUG: InOpRequest received! Artifact: router, inc2 
DEBUG: Adding in the inQueue: router: inc2 
DEBUG: Message added in the incoming queue! 
DEBUG: A message was founded in the incoming queue! Artifact:router, op:inc2, body [] 
DEBUG: Getting artifact id of router 
DEBUG: Executing inc2 without parameters. 
DEBUG: InOpRequest received! Artifact: counter, inc3 
DEBUG: Adding in the inQueue: counter: inc3 
DEBUG: Body received: [string...test...counter, 34] 
DEBUG: Parameters details: [string...test...counter, 34] 
DEBUG: Message added in the incoming queue! 
DEBUG: A message was founded in the incoming queue! Artifact:counter, op:inc3, body [string...test...counter, 34] 
DEBUG: Getting artifact id of counter 
DEBUG: artifact name/id/type: counter/7/artifacts.Counter 
DEBUG: Forwarding inc3 with following parameters: [string...test...counter, 34] 
[counter] Counter:inc3 called! A tick signal is going to be send. Parameters: string...test...counter, 34 
ERROR: Error on execLinkedOp with parameters! 
cartago.OperationException: execLinkedOp failed java.lang.IllegalMonitorStateException 
    at cartago.Artifact.execLinkedOp(Artifact.java:965) 
    at camelartifact.CamelArtifact.receiveMsg(CamelArtifact.java:128) 
    at camelartifact.CamelArtifact$ReadCmd.exec(CamelArtifact.java:203) 
    at cartago.Artifact.await(Artifact.java:832) 
    at camelartifact.CamelArtifact.setListenCamelRoute(CamelArtifact.java:69) 
    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:606) 
    at cartago.ArtifactOpMethod.exec(ArtifactOpMethod.java:39) 
    at cartago.Artifact.doOperation(Artifact.java:407) 
    at cartago.Artifact.access$200(Artifact.java:32) 
    at cartago.Artifact$ArtifactAdapter.doOperation(Artifact.java:1235) 
    at cartago.WorkspaceKernel.serveOperation(WorkspaceKernel.java:1045) 
    at cartago.WorkspaceKernel.access$000(WorkspaceKernel.java:49) 
    at cartago.WorkspaceKernel$EnvironmentController.run(WorkspaceKernel.java:1359) 
DEBUG: Forwarding with parameters done! 
DEBUG: InOpRequest received! Artifact: router, inc2 
DEBUG: Adding in the inQueue: router: inc2 
DEBUG: Message added in the incoming queue! 
DEBUG: A message was founded in the incoming queue! Artifact:router, op:inc2, body [] 
+0

您是否考虑咨询Javadoc? – EJP

+0

我没有在CArtAgO中找到任何有关它的信息,但他们通过一些例子显示了一些API的用法,他们真正避免使用外部线程来防止同步问题。 –

回答

3

提议Alessadro利玛窦,每java.lang.IllegalMonitorStateException你应该依赖的事实,你正试图从哪个不属于卡塔戈一个线程卡塔戈/伪代码中调用。

假设你有自己的线程T(外部于CArtAgO),它想访问一个调用某个公共方法(其目的是例如更新该工件的obs状态的工件),然后,从你刚才调用的线程代码:

art.beginExternalSession(); /* new primitive */ 
art.yourArtifactPublichMethod(); 
... 
art.yourArtifactPublichMethod(); 
art.endExternalSession(true); /* new primitive. true = every thing was OK, false in the case of failures */ 

其中art是对工件Java对象的直接引用。

package c4jtest; 

import cartago.*; 

class ExtThread extends Thread { 

    private ArtifactWithExtUse art; 

    public ExtThread(ArtifactWithExtUse art){ 
     this.art = art; 
    } 

    public void run(){ 
     while (true){ 
      try { 
       Thread.sleep(1000); 
       art.beginExternalSession(); 
       art.externalInc(); 
       art.endExternalSession(true); 
      } catch (Exception ex){ 
       art.endExternalSession(false); 
      } 
     } 
    } 

} 

public class ArtifactWithExtUse extends Artifact { 

    void init(){ 
     defineObsProperty("a",0); 
     new ExtThread(this).start(); 
    } 

    /* ext API */ 

    public void externalInc(){ 
     ObsProperty prop = this.getObsProperty("a"); 
     prop.updateValue(prop.intValue()+1); 
    } 

    @OPERATION void reset(){ 
     ObsProperty prop = this.getObsProperty("a"); 
     prop.updateValue(0); 
    } 

}