flogo-lib
flogo-lib copied to clipboard
Shared objects across activities
Shared resources or objects, such as connections should be shared across activities, thus avoiding the need to reestablish connections for every activity (MQTT publish for example).
Basically the activities can belong to several flows, not all of which will have the same configuration for something like an MQTT client. The solution to this would be to have a "shared resource" in which activities that use the same configuration can reference
Reference #111
As suggested in #111 in this comment, different scopes of shared resources could be implemented, being the activity attributes a natural one, and flow and application level two more that may be interesting.
Some thoughts: Working on another project I thought that context
could be used for this. A ctx could be passed though activity.Init()
and trigger.Init()
to populate it with the shared resources. Then this context would be passed to trigger.Start()
instead of creating a new one from context.Background()
and it should also be passed to trigger.Stop()
and activity.Eval()
.
Thanks Adirio. Shortly I'm going to start looking into both how best to share resources and also possible activity initialization based on both app and the particular action/flow it belongs to. I'll keep you posted.
I've realised that what you are passing to activity.Eval()
, despite being named activity.Context
it is not a context.Context
as I was expecting (similar to the extra abstraction layer you are using on trigger.NewContext
). Is the activity.Context
an abstraction layer over context.Context
or is it a completely different thing? Because my thought was based on the fact that you were already passing some kind of context.Context
to activity.Eval()
.