1.2.
Component
Up one level
Advice
Try to keep components simple; a component should do one thing and not many things. This makes it easier to test it and it also increases the chances that such a components can be re-used.
If we think of a model as a directed graph, components are the nodes in such a graph. The edges are wired out and in properties.
Concept
The method doCalculation is executed once only per iteration and period. No loops are possible for a component.
Execution is triggered by the framework: If all wired in channels have received their information doCalculation is executed. Afterwards the packets prepared in the out channels is sent to following components.
Step by step example
We create a component providing a premium value to other components. The premium will be the product of number of policies and the price per policy parameter.
- Create a new Groovy or Java class in the corresponding package. (Line 1, 5)
(Domain classes can be found in src/groovy/org/pillarone/modelling/domain) - The class has to extend org.pillarone.riskanalytics.core.components.Component (Line 2, 5)
- The
class has two parameters parmNumberOfPolicy and parmPricePerPolicy
(Line 6, 7) The order in which the parameters are defined is also the
order how they will be displayed in the UI. If parameters are inherited
from superclasses, the parameters of the superclass are displayed first.
- The class has an output channel outPremium (Line 8) in order to send premium information to other components.
- Premium has to be calculated (Line 10), wrapped in a packet and added to the output channel (Line 11)
1: package org.pillarone.modelling.domain.underwriting
2: import org.pillarone.modelling.components.Component
3: import org.pillarone.modelling.packets.PacketList
4: import org.pillarone.modelling.packets.Premium
5: class PremiumCalculation extends Component {
6: double parmNumberOfPolicy
7: double parmPricePerPolicy
8: PacketList<Premium> outPremium = new PacketList(Premium)
9: void doCalculation() {
10: double premium = parmNumberOfPolicy * parmPricePerPolicy
11: outPremium << new Premium(value: premium)
12: }
13: }
Let's say we want another component providing index information which influences the price per policy. In order to cover this use case we write a component with extended functionality:
- Add an additional input channel inIndex (Line 5)
- Adjust
the premium calculation: build the product of all received indices
(Line 8 - 10) and adjust the price per policy accordingly (Line 11)
1: package org.pillarone.modelling.domain.underwriting
2: import org.pillarone.modelling.packets.PacketList
3: import org.pillarone.modelling.packets.Index
4: class PremiumCalculationWithIndex extends PremiumCalculation {
5: PacketList<Index> inIndex = new PacketList(Index)
6: void doCalculation() {
7: double level = 1.0
8: for (Index idx in inIndex) {
9: level *= idx.value
10: }
11: double pricePerPolicy = parmPricePerPolicy * level
12: double premium = parmNumberOfPolicy * pricePerPolicy
13: outPremium << new Premium(value: premium)
14: }
15: }
For the sake of completeness the following listings contain the Index and Premium classes:
1: package org.pillarone.modelling.packets
2: class Premium extends Packet {
3: double value
4: }
1: package org.pillarone.modelling.packets
2: class Index extends Packet {
3: double value
4: }

