Skip to content

Commit

Permalink
[BZ-801093] cancel the job handle related with a canceled activation …
Browse files Browse the repository at this point in the history
…+ check if the agenda has been halted
  • Loading branch information
mariofusco committed Aug 31, 2012
1 parent ed6b8c5 commit aed459f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Expand Up @@ -994,7 +994,7 @@ public boolean isTimeIncluded(long timestamp) {
assertEquals( 3, list.size() );
}

@Test @Ignore
@Test
public void testTimerWithNot() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Timer_With_Not.drl" ) ) );
Expand All @@ -1012,7 +1012,7 @@ public void testTimerWithNot() throws Exception {
assertEquals( 2, workingMemory.getFactCount() );
}

@Test @Ignore
@Test
public void testHaltWithTimer() throws Exception {
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_Halt_With_Timer.drl" ) ) );
Expand Down
Expand Up @@ -596,6 +596,7 @@ public void cancelActivation(final LeftTuple leftTuple,
final Activation activation,
final RuleTerminalNode rtn ) {
AgendaItem item = (AgendaItem) activation;
item.cancel();
item.removeAllBlockersAndBlocked( this );

if ( isDeclarativeAgenda() && activation.getFactHandle() == null ) {
Expand Down Expand Up @@ -1377,6 +1378,10 @@ public void halt() {
notifyHalt();
}

public boolean isHalted() {
return halt.get();
}

public ConsequenceExceptionHandler getConsequenceExceptionHandler() {
return this.legacyConsequenceExceptionHandler;
}
Expand Down
Expand Up @@ -146,6 +146,8 @@ public int fireAllRules(AgendaFilter agendaFilter,
* execution though.
*/
public void halt();

public boolean isHalted();

public void notifyHalt();

Expand Down
17 changes: 15 additions & 2 deletions drools-core/src/main/java/org/drools/common/Scheduler.java
Expand Up @@ -82,16 +82,29 @@ public static class ActivationTimerJob implements Job {
public void execute(JobContext ctx) {
InternalAgenda agenda = ( InternalAgenda ) ((ActivationTimerJobContext)ctx).getAgenda();
ScheduledAgendaItem item = ((ActivationTimerJobContext)ctx).getScheduledAgendaItem();


if (agenda.isHalted()) {
item.getJobHandle().setCancel( true );
return;
}

agenda.fireActivation( item );

if ( item.isCanceled() ) {
item.getJobHandle().setCancel( true );
}

if ( ((ActivationTimerJobContext)ctx).getTrigger().hasNextFireTime() == null ) {
agenda.getScheduledActivationsLinkedList().remove( item );
} else {
// the activation has been rescheduled, the Agenda would have set it's activated to false
// so reset the activated to true here
item.setActivated( true );
}
agenda.getWorkingMemory().fireAllRules();

if (!agenda.isHalted()) {
agenda.getWorkingMemory().fireAllRules();
}
}
}

Expand Down

0 comments on commit aed459f

Please sign in to comment.