How to pass in parameters to a clockTickListener()?

6 views
Skip to first unread message

Chigozie Asikaburu

unread,
Apr 1, 2020, 11:43:01 PM4/1/20
to CloudSim Plus
I'm using the simulation.addOnClockTickListener() to add clockTickListeners that will be notified when of any clock tick. I wanted to pass parameters in my clockTickListeners method. I tried doing something like this: 

private void clockTickListener(final EventInfo info, List<Cloudlet> cloudletList) {

    if (info.getTime() == currentCloudletArrival) {
    // create cloudlets at this time       
    }
}

Although I'm unsure how to define the lambda expression for addOnClockTickListener(). I tried doing something like:

simulation.addOnClockTickListener(cloudletList3 -> clockTickListener(null, (List<Cloudlet>) cloudletList3));

I'm thinking this is probably not right. Your example in RandomCloudletsArrivalExample just used a method reference like so: 

simulation.addOnClockTickListener(this::createRandomCloudlets);

I'm not sure what exactly this translates to as a normal lambda and how to properly pass parameters the clock tick listener method. Can this addOnClockTickListener be defined in any class and then just referenced as a static method in the class that is calling it? In other words does this method need to be defined and called in the class that's calling it like in all of your examples. 



Manoel Campos

unread,
Apr 2, 2020, 7:14:26 PM4/2/20
to clouds...@googlegroups.com
You don't pass additional parameters.
Anything you want needs to be gotten elsewhere.
If you want to access a cloudletList3, you just need to make it available, for instance,
as an attribute inside the same class where you included you listener,
that is usually inside your simulation scenario class.

For this onClockTickListener, the info parameter provides just the current clock time.
For other listeners you have more contextual information.

Manoel Campos da Silva Filho Software Engineer

Computer Science and Engineering Ph.D. Student at University of Beira Interior (Portugal)

Professor at Federal Institute of Education, Science and Technology of Tocantins (Brazil)

http://manoelcampos.com


 about.me


--
If you received an answer that worked for you, please be kind and reply to let everybody knows it worked.
http://cloudsimplus.org
---
You received this message because you are subscribed to the Google Groups "CloudSim Plus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloudsim-plu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloudsim-plus/06a6b723-0cbb-4bdb-af46-01342d8573c7%40googlegroups.com.

Chigozie Asikaburu

unread,
Apr 2, 2020, 7:24:11 PM4/2/20
to CloudSim Plus
Ok thanks. I was looking to make the method flexible with parameter inputs but I figured I shouldn't do this. Defining attributes in the same class works the same so I'll just keep doing that. 


On Thursday, April 2, 2020 at 7:14:26 PM UTC-4, Manoel Campos wrote:
You don't pass additional parameters.
Anything you want needs to be gotten elsewhere.
If you want to access a cloudletList3, you just need to make it available, for instance,
as an attribute inside the same class where you included you listener,
that is usually inside your simulation scenario class.

For this onClockTickListener, the info parameter provides just the current clock time.
For other listeners you have more contextual information.

Manoel Campos da Silva Filho Software Engineer

Computer Science and Engineering Ph.D. Student at University of Beira Interior (Portugal)

Professor at Federal Institute of Education, Science and Technology of Tocantins (Brazil)

http://manoelcampos.com


 about.me


On Thu, Apr 2, 2020 at 12:43 AM Chigozie Asikaburu <chigozie...@gmail.com> wrote:
I'm using the simulation.addOnClockTickListener() to add clockTickListeners that will be notified when of any clock tick. I wanted to pass parameters in my clockTickListeners method. I tried doing something like this: 

private void clockTickListener(final EventInfo info, List<Cloudlet> cloudletList) {

    if (info.getTime() == currentCloudletArrival) {
    // create cloudlets at this time       
    }
}

Although I'm unsure how to define the lambda expression for addOnClockTickListener(). I tried doing something like:

simulation.addOnClockTickListener(cloudletList3 -> clockTickListener(null, (List<Cloudlet>) cloudletList3));

I'm thinking this is probably not right. Your example in RandomCloudletsArrivalExample just used a method reference like so: 

simulation.addOnClockTickListener(this::createRandomCloudlets);

I'm not sure what exactly this translates to as a normal lambda and how to properly pass parameters the clock tick listener method. Can this addOnClockTickListener be defined in any class and then just referenced as a static method in the class that is calling it? In other words does this method need to be defined and called in the class that's calling it like in all of your examples. 



--
If you received an answer that worked for you, please be kind and reply to let everybody knows it worked.
http://cloudsimplus.org
---
You received this message because you are subscribed to the Google Groups "CloudSim Plus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clouds...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages