StatefulKnowledgeSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
int fired;
if ( max != -1 && agendaFilter != null ) {
fired = ((StatefulKnowledgeSessionImpl) ksession).session.fireAllRules( new StatefulKnowledgeSessionImpl.AgendaFilterWrapper( agendaFilter ), max );
} else if ( max != -1 ) {
fired = ksession.fireAllRules( max );
} else if ( agendaFilter != null ) {
fired = ((StatefulKnowledgeSessionImpl) ksession).session.fireAllRules( new StatefulKnowledgeSessionImpl.AgendaFilterWrapper( agendaFilter ) );
} else {
fired = ksession.fireAllRules();
}