-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
Comments
Passing a generic lambda expression as an event parameter instead of this |
Hi There, Can I work on this project? |
Hey @chapaith |
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 adata
attribute that is define asObject
and can store any possible value from any class. Inside the processEvent method, to know what type of event was received, it is used aswitch
statement to check thetag
attribute. That allows to guess what the type of object inside thedata
attribute is, requiring an unchecked typecast that may generate runtimeClassCastException
. There is no way to enforcedata
of an event with a giventag
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 thedata
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 asHost
,Vm
orCloudlet
. 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 aSimEvent
object to have, when it is tagged with a specific value for thetag
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 specializedSimEvent
child classes such asCloudletEvent
,VmEvent
,HostEvent
,DatacenterBrokerEvent
andDatacenterEvent
.Then the general method should just call an overloaded version such as
processEvent(VmEvent evt)
orprocessEvent(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. TheCloudSimTags
may be removed. Since objects such as brokers can have different events, we can specialize the class even more withBrokerShutDownEvent
, 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.
The text was updated successfully, but these errors were encountered: