2016-10-18 45 views
0

什麼是檢查以下條件的最佳方式待定: 由於PID是在一個特定的中間消息事件懸而未決。的Activiti:如何檢查當前流程實例在給定的中間消息事件

,我已經嘗試了一些事情:

Execution execution = runtimeService.createExecutionQuery().processInstanceId(<pId>) 
       .activityId(<messageEventName>).singleResult(); 
if(null!=execution){ 
//I have got assurance that this pId is pending with this messageEventName currently 
} 

中間消息事件的我bmp.xml代碼:

<intermediateCatchEvent id="messageintermediatecatchevent1" name="MessageCatchEvent"> 
    <messageEventDefinition messageRef="actionOnPendingLR"></messageEventDefinition> 
    </intermediateCatchEvent> 

我的Java代碼:

private Execution checkIfProcessPendingOnPendingLRMessage(UserAction request) throws Exception { 
    String pId = request.getProcessInstanceId(); 
    Execution execution = null; 
    String messageName = "messageintermediatecatchevent1"; 
    try { 
     execution = runtimeService.createExecutionQuery().processInstanceId(pId) 
       .activityId(messageName).singleResult(); 
    } catch (Exception exe) { 
     logger.error("supplied process instance is not matching on the state in which it is pending" + pId, exe); 
    } 

    if (execution == null) { 
     throw new RuntimeException(
       "Couldn't find waiting process instance with id '" + pId + "' for message '" + messageName + "'"); 
    } 
    return execution; 

} 

& &檢查

(null!=checkIfProcessPendingOnPendingLRMessage(request)) //in main method. 

任何人都可以確認這是正確的代碼/方法來實現我的目標。否則請分享正確的方法。

回答

1

在特定情況下對一個具體的過程中,你可以使用.activitiId(),即指定BPMN元素的ID(你的情況messageintermediatecatchevent1),而不是它的認購消息的名稱。該技術用於activiti用戶指南中的messageReceived元素。但這不是個好主意,因爲你的進程可能會在不同的intermediateMessageCatchingEvents中等待這條消息,並且元素可以稍後重命名。

相反.activitiId的(),你應該使用.messageEventSubscriptionName()。

在更一般的情況下,而不是.singleresult(),您可以用.LIST()並分析它的長度。雖然0和1是顯而易見的,但在您的進程中等待消息的多個執行是可能被區別對待的可能性。

而且這是檢查業務鍵或某些過程變量,而不是具體進程號的好主意。

P.S.請注意,正在處理的消息的名稱/ ID可能不同。 AFAIK .messageEventSubscriptionName使用消息的名稱,而不是id。

相關問題