Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new object-oriented, polymorphic and type-safe message passing mechanism #47

Closed
manoelcampos opened this issue Dec 19, 2016 · 3 comments
Labels
design Project's design improvement enhancement wontfix

Comments

@manoelcampos
Copy link
Collaborator

manoelcampos commented Dec 19, 2016

IMPROVEMENT

CloudSim Plus is a discrete event simulation framework that relies on tagged message passing to notify SimEntity objects when specific events happen.

Each SimEvent is tagged with a constant usually defined in CloudSimTags class and the processEvent method on every SimEntity receives the messages and process the desired ones.

Besides the tag attribute that classifies a message, the SimEvent class has a data attribute that is define as Object and can store any possible value from any class. Inside the processEvent method, to know what type of event was received, it is used a switch statement to check the tag attribute. That allows to guess what the type of object inside the data attribute is, requiring an unchecked typecast that may generate runtime ClassCastException. There is no way to enforce data of an event with a given tag to be of a required type. Further, when creating or extending a SimEntity, it is difficult to know what king of object it is supposed to be passed for the data attribute of a SimEvent.

The Issue #10 improved drastically the message passing mechanism that was usually passing an array of int for the SimEvent.data, instead of an actual object such as Host, Vm or Cloudlet. Using int arrays is even more difficult to know whose actual Object a specific ID in such an array is. There is no way to know that without questing throughout the code.

The Issue #10 tried to reduce such effort by providing documentation of what type of data it is expected a SimEvent object to have, when it is tagged with a specific value for the tag attribute. Despite this makes it easier to understand and extend the code, it doesn't solve the issues mentioned before.

This design also violates the Open/Closed Principle (OCP), it is not polymorphic and makes the code of the processEvent large and confusing. Every time a new tag is added, the SimEntity.processEvent method has to be changed to process this new tag.

Detailed information about how the feature should work

Instead of a general processEvent(SimEvent evt), we could use specialized SimEvent child classes such as CloudletEvent, VmEvent, HostEvent, DatacenterBrokerEvent and DatacenterEvent.
Then the general method should just call an overloaded version such as processEvent(VmEvent evt) or processEvent(HostEvent evt). This way, the correct version can be called directly and there will be no need for switch statements to check the type of the event and events won't need to be tagged anymore. The CloudSimTags may be removed. Since objects such as brokers can have different events, we can specialize the class even more with BrokerShutDownEvent, for instance.

An example scenario where this feature should be used

Final users can benefit from this improvement by allowing then to register for receiving notifications about any event that may happen during simulation execution in order to improve simulation monitoring. Currently, the introduced Listeners allow that but not for any possible event.

A brief explanation of why you think this feature is useful

It will make easier and safer to understand and extend the framework, will make the code compile time safe avoiding typecasts that my generate runtime exceptions. It will provide an improved design and less error prone code.

@manoelcampos manoelcampos added this to the CloudSim Plus 2.0 milestone Dec 19, 2016
@manoelcampos manoelcampos self-assigned this Dec 19, 2016
@manoelcampos manoelcampos modified the milestone: CloudSim Plus 2.0 Dec 20, 2016
@manoelcampos manoelcampos changed the title Implement new object-oriented, polymorphic message passing mechanism based on Design Patterns Implement new object-oriented, polymorphic and type-safe message passing mechanism based on Design Patterns Mar 15, 2017
@manoelcampos manoelcampos changed the title Implement new object-oriented, polymorphic and type-safe message passing mechanism based on Design Patterns Implement new object-oriented, polymorphic and type-safe message passing mechanism Apr 15, 2018
@manoelcampos manoelcampos removed this from the CloudSim Plus 4.0 milestone Aug 1, 2018
@manoelcampos manoelcampos removed their assignment Aug 29, 2018
@manoelcampos manoelcampos added the design Project's design improvement label Apr 5, 2019
@manoelcampos
Copy link
Collaborator Author

manoelcampos commented Nov 4, 2021

Passing a generic lambda expression as an event parameter instead of this data event field should be a type-safe way to process the event on reception.
The issue is that the sender would have to know how to process the event, instead of the destination.
This way won't make sense.

@chapaith
Copy link

Hi There, Can I work on this project?

@manoelcampos
Copy link
Collaborator Author

Hey @chapaith
Sorry for the late reply. I've been very busy lately.
This is a complicated issue that requires internal changes on the framework.
You can work on this but we need to discuss a proposed design first. Do you have anything in mind?

@manoelcampos manoelcampos closed this as not planned Won't fix, can't repro, duplicate, stale Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Project's design improvement enhancement wontfix
Projects
None yet
Development

No branches or pull requests

2 participants