siddhi icon indicating copy to clipboard operation
siddhi copied to clipboard

ability to provide factory to create an extension

Open ramith opened this issue 7 years ago • 5 comments
trafficstars

Description: Currently only way (that I know of ) to register extensions with siddhi is through siddhiManager.setExtension("functionName", MyFunctionExtension.class); I see that with in siddhi then it will create a instance of the class provided.

I suggest lets improve this scheme by allowing users to supply a factory to create an instance of the extension. what I'm suggesting is something like : https://github.com/LMAX-Exchange/disruptor/blob/master/src/main/java/com/lmax/disruptor/EventFactory.java

Suggested Labels: improvement, feature Suggested Assignees: suho Affected Product Version: 4.x.x

OS, DB, other environment details and versions:
N/A Steps to reproduce: N/A

Related Issues: N/A

ramith avatar Apr 18 '18 11:04 ramith

any updates @suhothayan @mohanvive @dilini-muthumala ?

ramith avatar Feb 18 '19 10:02 ramith

Hi Ramith. The initial decision to go with simple class loading is to make siddhi extension creation easy, and with annotations, we will be able to define its behavior of the class previously. if you want to create specific classes for each subtype you can follow the approach used here https://github.com/siddhi-io/siddhi/blob/master/modules/siddhi-core/src/main/java/org/wso2/siddhi/core/query/selector/attribute/aggregator/MaxAttributeAggregator.java Is there any specific reason why you are suggesting to move to a factory based approach?

suhothayan avatar Feb 20 '19 18:02 suhothayan

Hi Suho, one of the pattern I would like to have is demonstrated here ( obviously following code doesn't work. but can be made to work if we have a mechanism similar to what we suggested). This makes sense when we try to bridge/embed Siddhi into another runtime, where we want to use functionality/components that are exists/part-of that runtime (e.g. Spring)

@Component 
class MyFunctionFactory implements ProposedSiddhiFactoryInterface {

    /* Will create an function. note that instances of this class
  (and any instances created by the factory can also be) is managed by Spring runtime.  
Therefore it has the access to any services/beans/components/functionality etc, 
that exists in the runtime. */ 
  Function create() {
  
  }
}

---------------------------------------------

@Component
class AnalyticsEngine 
{
   @AutoWired
   MyFunctionFactory myFunctionFactory;
  
  @PostConstruct
   void init() {
       siddhiManager.setExtension("functionName", myFunctionFactory); 
   }

}

Why we want to do this is because there are some functionality we have already written as spring components/services/data which we want to use with siddhi. Right now I'm not aware of a clean way to make this happen without what I proposed here. If there is any please let me know.

ramith avatar Mar 12 '19 06:03 ramith

BTW, I'm not asking to deprecate current way of doing. I'm just asking to may be overload the existing method/api or introduce a new method like I proposed.

ramith avatar Mar 12 '19 06:03 ramith

@suhothayan any updates?

ramith avatar Mar 26 '19 06:03 ramith