-
Notifications
You must be signed in to change notification settings - Fork 685
Polling 2.0
Jira: http://www.mulesoft.org/jira/browse/MULE-6872
Forum discussion: http://forum.mulesoft.org/mulesoft/topics/_3_5_m1_mule_polling_improvements
The main motivation of this feature is to generate a Management service of polls and create an unique way to do polling in mule.
- As a user, I want to execute a given flow :(every hour regardless of the day/week, on Monday, Weds, Friday at 12 AM, Every 5 minutes)
- As a user, I want to be able to try out my poll: (I do not have to wait for the next poll to execute (which may be a day away) to test what will happen, I do not get confused about what is happening because polls continue to execute while I'm trying to debug what is happening)
- As a user, I want to be able to test my poll: (I want to run a unit test that executes a poll, I want to start a test without having polls running.)
- As an extension developer, I want better APIs to start, stop and execute polls.
- As a user, I want to prevent poll executions from executing concurrently
- As an extension developer I want to start/stop/run my polls
- As an extension developer I want to enrich with notifications of the poll execution.
- As a developer I want to provide a new scheduler beside poll via any mule extension
This spec is divided in two parts:
- Mule API definition
- XML definition
Nowadays we don't have a mule API in order to manage the schedulers, this implies that are features that we cannot perform or are hard to develop.
The scheduler is the one who triggers a task based on its configuration. The relationship is one scheduler one task.
The scheduler allows users to schedule its task on demand. The schedule timing depends on the scheduler or its task. scheduling a task on deman doesn't mean that the task is going to be executed immediately.
public interface Scheduler extends Stoppable, Startable, NamebleObject
{
void schedule() throws MuleException;
}
In order be able to hook the creation of a Scheduler (to change/wrap its implementation) a Scheduler is created by a Scheduler factory. The SchedulerFactory guaranties that every time a Scheduler is created all the scheduler post processors that are registered in the MuleRegistry are going to be executed.
A SchedulerFactoryPostProcessor is an object registered in the MuleRegistry that is going to be executed every time a Scheduler is created by a SchedulerFactory.
The SchedulerFactoryPostProcessor can be:
- Registered by Spring bean or mule module extension via mule configuration (xml)
- Registered as a bootstrap extension
- Registered manually in the MuleRegistry.
public interface SchedulerFactoryPostProcessor
{
Scheduler process(Scheduler scheduler);
}
Mule Registry will now have methods for register/unregister and lookup Schedulers.
public interface MuleRegistry
{
void registerScheduler(Scheduler scheduler);
void unregisterScheduler(String name);
Collection<Scheduler> lookupScheduler(Predicate<String> predicate);
}
Covered scenarios:
- I do not have to wait for the next poll to execute (which may be a day away) to test what will happen
- As an extension developer, I want better APIs to start, stop and execute polls.
- As an extension user I want to start/stop/run my polls
This class shows how an extension developer can stop/start/execute a poll element in a flow. This can be created for exampe by Cloudhub or MMC to start/stop/execute polls by demand. Actually, this class is an Mule agent service.
public class MyPollingService extends AbstractService{
public void executePoll(String appName, final String flowName) throws MuleException
{
MuleContext context = getContext(appName);
MuleRegistry registry = context.getRegistry();
Collection<Scheduler> schedulers = registry.lookupSchedulers(PollPredicate.flowNamePredicate(flowName));
for ( Scheduler scheduler : schedulers ){
scheduler.schedule();
}
}
}
- I do not get confused about what is happening because polls continue to execute while I'm trying to debug what is happening
- I want to start a test without having polls running.
- As an extension developer I want to change the polling strategy on runtime
- As an extension developer I want to enrich with notifications of the poll execution.
This class is a boostrap extension that implements a SchedulerFactoryPostProcessor, this extensions wraps the scheduler implementation so it does not start when it should.
public class BoostrapExtension implements SchedulerFactoryPostProcessor
{
@Override
public Scheduler process(final Scheduler scheduler)
{
return new Scheduler()
{
@Override
public void execute() throws MuleException
{
scheduler.execute();
}
@Override
public void start() throws MuleException
{
// Do Nothing
}
@Override
public void stop() throws MuleException
{
// Do Nothing
}
};
}
}
- Simplifies Stopping/Starting and executing Schedulers
- PollSchedulerFactory allows hooks based on usage and not redefinition (an example of this is the EndpointFactory)
- Simplifies the way we can run a scheduler
- Eliminates internally poll as an inbound endpoint.
- Allows poll to receive different scheduling strategies
- Interface Backward compatible.
- All the interfaces are not aware about the task that is going to be executed.
- Uses the MuleRegistry as container of Schedulers which might be confusing sometimes.
- It changes the concept of poll as an inbound endpoint and Abstract Receiver. Which is bad because it breaks backward compatibility on the implementation details but it might be necessary as it makes no sense for a poll to be a MessageReceiver as it is Connectable (which makes no sense for poll to be connectable)
We will probably deprecate some clases for poll and we are not going to support them anymore, I consider that is a minor risk if we provide better interfaces and remove legacy code.
WE HAVE TWO OPTIONS FOR XML CHANGES. Both of them will allow to deprecate quartz module and allow users to use a single poll element that will be configurable enough to define the scheduling strategy and synchronization.
We define poll as the standar to do polling:
<flow name="test">
<poll frequency="1000">
<!-- message source here -->
</poll>
</flow>
<flow name="test">
<poll frequency="1000"/>
<mp>
</flow>
If the poll needs to be executed but it haven't finished what should we do?
<flow name="test">
<poll>
<schedulers:simple frequency="" collision-strategy="parallel/queue/ignore"/>
</poll>
<mp>
</flow>
- parallel: Execute polls in parallel (if it is already running then trigger the event in parallel)
- queue: If the poll is running queue the next event.
- ignore: if the poll is running ignore the incoming event.
Now the quartz module will allow users to define a polling strategy that can be used by poll, and deprecate the quartz inbound endpoint.
<flow name="test">
<poll>
<schedulers:cron expression="" collision-strategy="parallel/queue/ignore"/>
<!-- message source here -->
</poll>
</flow>
- Supports backward compatibility.
- Low Documentation impact.
- The Poll element code is not good. If we want to have a good code quality we need to do a lot of refactoring around that and break code backward compatibility.
There is no migration guide, we support backward compatibility.
We deprecate poll and quartz inbound endpoint.
<flow name="test">
<trigger>
<schedulers:cron expression="" collision-strategy="parallel/queue/ignore"/>
</trigger>
</flow>
Tigger element is to dispatch a flow, not to consume a message source.
- We will have a new element which code is aligned across all products.
- Simplifies the usage of a scheduler
- Is more aligned on what users want to do (which is executing flows given a scheduler configuration)
- Its name makes more sense
- Mule's code will be backward compatible.
- Requires less Mule core changes.
- Requires migration guidelines in CH so users need to know that if they are going to deploy a new app with mule 3.5.0 they need to change the poll element to trigger.
- Cloudhub will need to listen a new type of notification for scheduled elements (no longer inbound endpoints)
- Studio will need to provide a new element
This is a risky feature. A lot of refactoring regarding poll management/polling receivers. We need to consider this a refactoring feature that will add some new functionalities.
We need to document:
- All the deprecations.
- API usage
- We need to define the UI for Studio. (just to provide a better UI for poll and improve usability)
- CH needs to change the current poll functionality for Multitenancy (low effort)
- Munit will allow to run polls and stop them without hacking spring (decrease maintenance effort)