class CheckProcessesEnded implements JavaDelegate {

    @Override
    public void execute(DelegateExecution execution) throws Exception {
        @SuppressWarnings("unchecked")
        List<String> processIds = (List<String>) execution.getVariable(variableWithProcessIds);

        List<String> ended = Lists.newArrayList(Iterables.filter(processIds, new Predicate<String>() {
            @Override
            public boolean apply(String processInstanceId) {
                ProcessInstance instance = runtimeService.createProcessInstanceQuery()
                    .processInstanceId(processInstanceId).singleResult();

                return instance == null || instance.isEnded();
            }
        }));

        boolean done = (processIds.size() == ended.size());
        execution.setVariable(resultVariable, done);

        if (done) {
            LOG.info("All background processes ENDED: {}", processIds);
        } else {
            if (LOG.isInfoEnabled()) {
                LOG.info("Still waiting for: {}", Sets.difference(ImmutableSet.copyOf(processIds),
                    ImmutableSet.copyOf(ended)));
            }
        }
    }

    public  CheckProcessesEnded(RuntimeService runtimeService, String variableWithProcessIds,
                               String resultVariable);

}