This discussion is archived
8 Replies Latest reply: Jun 7, 2013 4:14 AM by CharuTiwari RSS

CANT SET VALUE DURING THINK CYCLE

CharuTiwari Newbie
Currently Being Moderated
Hi All,

OPA 10.4

I have a global and an entity in 1:M.
I have to set a serial no. to all the instances of entity in a session depending on an external logic. For this I used a custom fuction which sets the value to the attribute "Serial no."
The error being thrown is "CANNOT SET VALUE DURING THINK CYCLE".

1)Please Suggest on a way to implement this logic.

2)Will INFERENCE LISTENER(IL) be helpful?.Since an inference listener sets the value before/after session, can I retrieve session and its data in my IL code if I use it after the session?


Thanks :)
  • 1. Re: CANT SET VALUE DURING THINK CYCLE
    BradTuckett Pro
    Currently Being Moderated
    A custom function is processed during the current inferencing cycle - if the custom function modified the session, then it would be changing the conditions that triggered itself - therefore a custom function cannot modify the session.

    The custom function returns the value for the current attribute only - so if you can determine the serial number of each attribute instance individually then you can use a custom function to set the serial number. If you want to set values for multiply attributes when the session is created, then what you probably want is a rulebase listener.

    Not sure what you mean about setting values before/after the session - the session exists as long as it is required, and will re-inference whenever input data is modified. What OPA component are you using to execute your session?
  • 2. Re: CANT SET VALUE DURING THINK CYCLE
    CharuTiwari Newbie
    Currently Being Moderated
    Thanks Brad,
    with before/after session I meant before/after inferencing cycle.
    So would I be able to use session data in the inferencing listener code for evaluation, if I call the Inferencing listener after the inferencing cycle?

    I am using a batch processor to execute. Batch processor is introduced in opa 10.4

    Edited by: Charu Tiwari on May 27, 2013 12:44 AM

    Edited by: Charu Tiwari on May 27, 2013 12:47 AM
  • 3. Re: CANT SET VALUE DURING THINK CYCLE
    frank.hampshire Expert
    Currently Being Moderated
    Charu Tiwari wrote:
    So would I be able to use session data in the inferencing listener code for evaluation, if I call the Inferencing listener after the inferencing cycle?
    If you use an inferencing listener, you will have access to all the session data (entities, attributes, relationships) in the event listener.

    Cheers
    Frank
  • 4. Re: CANT SET VALUE DURING THINK CYCLE
    Ian Clough Explorer
    Currently Being Moderated
    Why not use the custom function to calculate or retrieve the value for the serial # using whatever logic you like and the assign the value in the rule e.g. serialNo = customFunction(.....)
  • 5. Re: CANT SET VALUE DURING THINK CYCLE
    CharuTiwari Newbie
    Currently Being Moderated
    Thanks Frank :)

    @user12629736 : Yes, we can use custom function also but it will impact performance as the entire custom function code will be excecuted for every entity instances.

    Edited by: Charu Tiwari on May 29, 2013 11:36 PM
  • 6. Re: CANT SET VALUE DURING THINK CYCLE
    Ian Clough Explorer
    Currently Being Moderated
    A custom function isn't usually very expensive and it only gets invoked as often as is necessary, very similar to the built in functions.
  • 7. Re: CANT SET VALUE DURING THINK CYCLE
    CharuTiwari Newbie
    Currently Being Moderated
    Yes Friend I agree to you. But to my requirement, with custom function being called every time(For more than 10,000 entity instances in a session) and complex code behind it, Inferencing listener would suit best.
  • 8. Re: CANT SET VALUE DURING THINK CYCLE
    CharuTiwari Newbie
    Currently Being Moderated
    I have an inferencing listener implemented in java.
    The event in OPA rulebase that triggers it, is not getting raised. What can be the reasons?
    Though it is going into beginInferencing() and endinferencing(). But getting Null when trying to getName() of event.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points