Accessing session values inside regular method using session API


I’m struggling to make use of the session API for retrieving the session values inside normal function within the feed() scope. I tried the below ways but no luck.

.exec(session => session.set(“start_time”,System.nonoTime)
.exec(new myAction(“test”, “${query}”))
.exec(session => session.set(“req_duration”,"System.nonoTime)

when I run the above snippet, the parameter ${query} is not substituted but I can see that value stored in a session. I tried the the following ways:

val s: Session = ???
.exec(new myAction(“test”, s.attributes.seq.apply(“query”).toString)

If I use this session API, I get the error " Exception in thread “main” Scala.NotImplementedError : An implementation is missing."

if I use this way,

exec((s: Session) => {
new myAction(“test”,s.attributes.seq.apply(“query”.toString))

I get no errors but it reports that " there were no requests sent during the simulation . No reports get generated" message.

So I need a way to access the session attributes inside the regular function. Appreciate your quick help on this. Thank you

What is myAction doing?

Substitution only happens when required by the compiler.
Please read the documentation:

Session API is also documented:

Hi Stephane,

Thanks for reply. I have gone through the documentation but seems I’m not clear on this. Can you please tell me some example on this. Thanks.

Hi John,

myAction is a plain java class which actually run some db script. This block of code is part of scenarioBuilder

def function1 : ChainBuilder

.exec(session => session.set(“start_time”,System.nonoTime)
.exec(new myAction(“test”, “${query}”))
.exec(session => session.set(“req_duration”,"System.nonoTime)

Have your myAction take an Expression[String] instead of a String.

No it is defined as String param. What is Expression[String]?

You REALLY have to read the documentation:

Does myAction do the database action immediately when new is called, as part of the constructor? Or does it return an object which gets called at run time when it is time to do the action?

@John : As it is an Action, it will only take place when it is time to do the action.
Meaning this could block the WHOLE scenario, for all users, which is a really, really bad idea…
Blocking operations need to be handled very carefully when working with Akka :slight_smile:

Hi John, Pierre,
Thanks for your update. MyAction is actually an extension of Action Builder. Its a custom implementation of actor like similar to http protocol. I can make it work without using feeder & sessions, but using for loop to construct the scenarioBuiler.

I think either I’m missing something or doing wrong when used feeders/sessions to buildup chain builder.

I really don’t understand how to use the session api in this case. Appreciate if you can show some light on this.