Github user olegz commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/836#discussion_r74704726
  
    --- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/StandardProcessorNode.java
 ---
    @@ -1321,12 +1325,21 @@ public void run() {
                             this.unscheduled = true;
                         }
                         try {
    -                        if (activeThreadMonitorCallback.call()) {
    +                        if (scheduleState.isScheduled()) {
    +                            
schedulingAgent.unschedule(StandardProcessorNode.this, scheduleState);
    +                        }
    --- End diff --
    
    So, after further digging I see that invoking ```OnUnscheduled``` doesn't 
mean that the actual PN is unscheduled since we still need to invoke 
```getSchedulingAgent(procNode).unschedule(procNode, state);```.
    If so we probably have to encapsulate this better where call to 
```getSchedulingAgent(procNode).unschedule(procNode, state);``` should initiate 
call to @OnUnschedule```. 
    Also, I am not sure I like leaking ```SchedulingAgent``` into the 
ProcessNode, that is why the callback felt more appropriate. With that in mind 
and in spirit of current changes wouldn't this (see below for full 
implementation of run()) be the same?
    ```java
    scheduler.execute(new Runnable() {
                    boolean unscheduled = false;
                    @Override
                    public void run() {
                        if (!this.unscheduled){
                            
ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnUnscheduled.class, 
processor, processContext);
                            try {
                                this.unscheduled = 
activeThreadMonitorCallback.call();
                                if (this.unscheduled) {
                                    try (final NarCloseable nc = 
NarCloseable.withNarLoader()) {
                                        
ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnStopped.class, processor, 
processContext);
                                    }
                                    scheduledState.set(ScheduledState.STOPPED);
                                } else {
                                    scheduler.schedule(this, 100, 
TimeUnit.MILLISECONDS);
                                }
                            } catch (Exception e) {
                                LOG.warn("Failed while shutting down processor 
" + processor, e);
                            }
                        }
                    }
                });
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to