Close
Tutorials    
Snapshot   
Basic usage

Calling function

In this example we will call a simple function to calculate a premium. Premium value is based on input data as follows:

  • base premium per day,
  • insurance duration in days.

Function returns a final premium amount.

Formula given:

premium = premium per day * duration in days;

Definition of the demo.insurance.calcpremium is as follows:

To call function simply inject Hyperon Engine (part of Hyperon Runtime Library) into your Spring Component/Service:

@Autowired
private HyperonEngine engine;

prepare a context:

HyperonContext ctx = new HyperonContext(
    "policy.premiumPerDay", "200",
    "policy.startDate","2017-01-01",
    "policy.endDate",  "2017-01-03" // 3 days duration
);

and execute call method:

BigDecimal premium = (BigDecimal) engine.call("demo.insurance.calcpremium", ctx);
logger.info("premium: {}", premium);

Please mind that while executing function we do not directly pass function arguments, e.g. policy.premiumPerDay, policy.startDate, policy.endDate. Hyperon Engine will query context for only necessary input data (with lazing querying approach). The responsibility of the context is to answer those queries.

To design robust contexts read carefully Context concept and Implementing execution context.

The output will be as follows:

1) Loading and compiling of the function

( main)[MpFunctionProvider] - loading function, uid=demo.insurance.calcpremium
( main)[FunctionJdbcDao] - enter getFunction, code=demo.insurance.calcpremium, ver=null, sid=0
( main)[FunctionJdbcDao] - leave getFunction, found=MpRhinoFunction#86602/86705[demo.insurance.calcpremium 2017-03-15 18:10:50.231]

2) Debug output from the function itself

( main)[RhinoLogger] - days: 3.0

3) Final value

( main)[SampleComponent] - premium: 600

Loading and compiling (1) is done only once. Subsequent call to a function would go straight to execution.

More tutorials

Basic usage