Last modified 16 years ago
Last modified on 07/28/09 14:36:43
Analysis
Overview
This task should provide the ability to have priority among operations. Currently, if a given event satisfy the filter conditions of several operations, there's no good way to specify the priority of the operations (which should be first, which should be second, if the first cannot handle the event, etc.)
Task requirements
- The operations must have a sort order key(equivalent to their priority).
- The sort key of an operation should be of type String.
- The sort key should be accessible through the interface OperationR3.
- The extension point will sort the registered extensions according to this key.
Task result
The result of this task should be:
- source code
Implementation idea
- Create an annotation which would mark that an existing operation has a sort order key.
- Add functionality to get the sortKey of an operation in the class org.sophie2.core.mvc.SimpleOperation.
- Using Reflection get the sort order key through the annotation if it is available for this operation
- otherwise assume that the sortKey is an empty string.
- This makes certain that all operations which have not provided a sortKey will have equal prioryty when they are rigisterred as extensions.
- Assure that the extension point will sort the registered extensions according to the sort order key.
- Override the method getSorter() from the class SophieExtensionPoint<T> in org.sophie2.core.mvc.CoreMvcModule, to provide a proper Comparator which would compare the operations acording to their sorKey if such is available.
Related
How to demo
- Run the test.
Design
- A new annotation will be introduced.
- Using this annotation an operation will define its sort order key and this assures that different operations which have similar event filters can have different priority.
- The annotation will have String sortKey();
- The interface org.sophie2.core.mvc.OperationR3 will be modified.
- A method getSortKey() will be added.
- It will return the sort order key of the current OperationR3 object.
- If the operation hasn't defined sortKey through the Sortable annotation the method will return an empty string, otherwise the method should return the corresponding sort order key.
- This is achieved in the following manner - we obtain the operationDef object - corresponding to the particular operation, then we get from the enumeration the appropriate enum field representing the current SimpleOperation and finally we obtain its sortkey if such is available.
- A method getSortKey() will be added.
- The class org.sophie2.core.mvc.CoreMvcModule will be modified.
- In the existing public static class OperationPoint which extends SophieExtensionPoint<OperationR3> we will overload the method getSorter() inherited from SophieExtensionPoint<T> located in org.sophie2.core.modularity.
- The method should return the result of compareTo applied to the keys.
- Follow this rule:
- Smaller sort key means higher priority.
- Exception case: empty sort key has lower priority than any other key.
Implementation
- Done according to design.
- Source code: branches/private/mitex/bobi/logic-priority
- Merged into the trunk in [4650].