com.hammurapi.reasoning.spi
Annotation Type Const


@Target(value=METHOD)
@Retention(value=SOURCE)
public @interface Const

This annotation indicates that invocation of annotated method doesn't change observable (by rules) object model state. E.g. invocation of the method can result in lazy loading of parts of the model, but this state change is not observable by model clients (i.e. rules). This annotation is intended to be used in Java 5+ by rules pre-compilers. Rules pre-compilers can perform execution optimizations such as chaining of conditions on methods with this annotation. For some cases, e.g. plain field getters, this annotation can be injected into sources by automated code analysis tools. Optional cost attribute indicates relative cost of invocation of annotated method.

Author:
Pavel

Optional Element Summary
 double cost
          Cost of method invocation.
 

cost

public abstract double cost
Cost of method invocation. Rules pre-compilers can use this information to optimize sequence of operands in condition evaluation. E.g. if cost of invocation Foo.getUnitPrice() is 5 and cost of Foo.getWeight() is 3 then pre-compiler can optimize (foo.getUnitPrice()<20 && foo.getWeight()>50) to (foo.getWeight()>50 && foo.getUnitPrice()<20) in order to invoke cheaper method first and potentially avoid invocation of more expensive method. In this example difference in methods costs is small and distribution of price and weight can cause this optimization result in more expensive calculation in average, e.g. all instances are heavier than 50 and only 5% are cheaper than 20. Cost can be calculated by collecting performance data.

Returns:
Invocation cost.
Default:
1.0