cancel
Showing results for 
Search instead for 
Did you mean: 

signalEventReceived & local variables

fritz128
Champ in-the-making
Champ in-the-making
I launch many subrocess by command:

for (int i = 0; i < count; i++) {
  signalEventReceived(signalName, executionId, subprocessVars);
}

I can't use multi-instance because I doesn't know the amount of subprocesses and I have to launch new subprocess on user request.

Problem:
Each subprocess contains the same set of variables, so they should be overriden by siblings subprocesses.
signalEventReceived(signalName, executionId, subprocessVars) writes to the global process context.
Question:

How to write local subprocess variables on subprocess start? Something like setVariableLocal.
12 REPLIES 12

fritz128
Champ in-the-making
Champ in-the-making
Sorry, there is mistake in code above. It should looks like:
<java>
for (int i = 0; i < count; i++) {
  runtimeService.signalEventReceived(signalName, executionId, subprocessVars);
}
</java>

trademak
Star Contributor
Star Contributor
Are you sending signal events in the same process instance? Could you explain a bit more the background of what you are trying to achieve?

Best regards,

fritz128
Champ in-the-making
Champ in-the-making
Yeah, I send signal events in the same process instance.
My workflow:
  I have some global process, for example, car lottery.  This process starts when manager push "Start Lottery" button. He can start many loterries simultaneously.
  To participate in this lottery user should go throught several stages of registration, attend on lottery, take a price (big or small, little price gives to all participants), and so on. So this task need to be moved to separate subprocess.

My code & problem:
  So, I don't know how many users will participate in lottery, I need to start subprocesses in for-loop:
<java>
//this handler proceed launching users's subprocesses for current lottery
public void handler(int loterryId, List<Integer> userIds) {
  ….
  Map<String, Object> subprocessVars = null;
  for (Integer userId : userIds) {
    subprocessVars = new HashMap<String, Object>();
    subprocessVars.put("lotteryId", lotteryId);
    subprocessVars.put("vacancyId", vacancyId);
    //PROBLEM: subprocessVars is written to global context, and if will be overriden by each subprocess!
    runtimeService.signalEventReceived(signalName, executionId, subprocessVars);
  }
}
</java>


trademak
Star Contributor
Star Contributor
I do need some more information. You say you have a sub process, but is it really? Is it an embedded sub process part of the global process or do you have a signal start event in a separate process definition? A process picture would help a lot to understand what you are trying to do.

Best regards,

fritz128
Champ in-the-making
Champ in-the-making
Yeah, I use embedded subprocess. Yes, embedded subprocess is a part of main process definition. My workflow
[img=http://s2.postimg.org/ioq6jynp1/Process.jpg]

My xml process definition
<code>
<signal id="participanSubprocess" name="participanSubprocess"/>
<process id="lotteryProcess"
  ….
  <userTask id="findParticipants" name="Find participants"/>
  <boundaryEvent id="launchSubprocess" attachedToRef="findParticipants" cancelActivity="false">
     <signalEventDefinition signalRef="participanSubprocess"/>
  </boundaryEvent>
   ……
  <subProcess id="participanSubprocess">
     …….
  </subProcess>
</process>
</code>

trademak
Star Contributor
Star Contributor
I think a signal event is not the right approach for this. Why don't you start a separate sub process with a call activity or a Java service task if more custom logic is required? Then every sub process has its own context.

Best regards,

fritz128
Champ in-the-making
Champ in-the-making
I have find no way to launch callActivity on user request. For example today user say: launch 3 subprocesses, tomorrow he will say: launch two additional subrocesses for current process and so on.
Can I lauch callActivity on event?

trademak
Star Contributor
Star Contributor
Yes if you add an event sub process you can.

Best regards,

fritz128
Champ in-the-making
Champ in-the-making
Yeah, but there are two essential points (from docummentation):
1. Activiti only supports interrupting Event Sub-Processes.
2. Activiti only supports Event Sub-Process triggered using an Error Start Event or Message Start Event.

As I understand, in my case that are drawbacks:
1. Interrupting means that when I start event subprocess from "find participants"-task, the "find participants"-task be completed (destroied).
2. Only message start event. I don't use JMS or something like it in my app. Ass I understand, the responsibility for delivering message lays on me, and I haven't any desire to use JMS.

Am I right about drawbacks above?