Re: [Dev] Occurring more callbacks after the initial run of the android app-Siddhi

2015-11-04 Thread Lakini Senanayaka
Hi Lasantha,

Thank you for the clarifications.I have added same stream again and again
to the same siddhi  manager instance.
I fixed it and now the app is working fine.

Thanks

On Tue, Nov 3, 2015 at 5:28 PM, Lasantha Fernando  wrote:

>
>
> On 3 November 2015 at 16:09, Lakini Senanayaka  wrote:
>
>> Hi Lasantha,
>>
>> This is the class I'm calling and instantiate the CEP object.
>>
>> package org.wso2.edgeanalyticsservice1;
>>
>> import android.app.Service;
>> import android.content.Intent;
>> import android.os.IBinder;
>> import android.util.Log;
>>
>> /**
>>  * This class implements IEdgeAnalyticService.aidl interface
>>  */
>> public class EdgeAnalyticsService extends Service {
>>
>> private CEP mCep;
>> private TaskManager taskManager=null;
>>
>> public EdgeAnalyticsService() {
>> mCep = new CEP();
>> }
>>
>> @Override
>> public void onCreate() {
>> }
>>
>> /** Returns the IBinder object for the connection */
>> @Override
>> public IBinder onBind(Intent intent) {
>> taskManager=null;
>> return mBinder;
>> }
>>
>> @Override
>> public int onStartCommand(Intent intent, int flags, int startId) {
>> return Service.START_STICKY;
>> }
>>
>> @Override
>> public boolean onUnbind (Intent intent){
>> return false;
>> }
>>
>> @Override
>> public void onDestroy() {
>> stopSelf();
>> }
>>
>> /** Implementation of methods in the IEdgeAnalyticsService interface */
>> public final IEdgeAnalyticsService.Stub mBinder = new 
>> IEdgeAnalyticsService.Stub() {
>>
>> IEdgeAnalyticServiceCallback mIEdgeAnalyticServiceCallback=null;
>>
>> @Override
>> public void getServiceNormal(String type, String streamDefinition, 
>> String stream, String query, String 
>> callbackFunctionName,IEdgeAnalyticServiceCallback cb) {
>>
>> mIEdgeAnalyticServiceCallback = cb;
>>
>>
>> /** Add the details to CEP if the Client is Type1 */
>> if (type.equalsIgnoreCase("TYPE1")) {
>> mCep.cepAddDetails(getApplicationContext(), 
>> streamDefinition, stream, query, callbackFunctionName, cb);
>> }
>>
>> /** Add the details to CEP if the Client is 
>> Type2-LOCATION_SERVICE */
>> else if (type.equalsIgnoreCase("LOCATION_SERVICE")) {
>> mCep.cepAddDetails(getApplicationContext(), "define stream 
>> LocationStream (latitude double,longitude double); ", "LocationStream", 
>> query, callbackFunctionName,cb);
>> taskManager = new 
>> TaskManager(getApplicationContext(),"LocationStream",mIEdgeAnalyticServiceCallback,mCep);
>> taskManager.initializeServiceType(type);
>> }
>>
>> /** Add the details to CEP if the Client is 
>> Type2-HUMIDITY_SERVICE */
>> else if (type.equalsIgnoreCase("HUMIDITY_SERVICE")) {
>> mCep.cepAddDetails(getApplicationContext(), "define stream 
>> HumidityStream (humidity float); ", "HumidityStream", query, 
>> callbackFunctionName, cb);
>> taskManager = new 
>> TaskManager(getApplicationContext(),"HumidityStream",mIEdgeAnalyticServiceCallback,mCep);
>> taskManager.initializeServiceType(type);
>> }
>>
>> /** Add the details to CEP if the Client is 
>> Type2-TEMPERATURE_SERVICE */
>> else if (type.equalsIgnoreCase("TEMPERATURE_SERVICE")) {
>> mCep.cepAddDetails(getApplicationContext(), "define stream 
>> temperatureStream (tempValue float); ", "temperatureStream", query, 
>> callbackFunctionName,cb);
>> taskManager = new 
>> TaskManager(getApplicationContext(),"temperatureStream",mIEdgeAnalyticServiceCallback,mCep);
>> taskManager.initializeServiceType(type);
>> }
>>
>> /** Add the details to CEP if the Client is 
>> Type2-INTENSITY_SERVICE*/
>> else if (type.equalsIgnoreCase("INTENSITY_SERVICE")) {
>> Log.d("client","INTENSITY SERVICE");
>> mCep.cepAddDetails(getApplicationContext(), "define stream 
>> lightIntensityStream (lightValue double); ", "lightIntensityStream", query, 
>> callbackFunctionName, cb);
>> taskManager = new 
>> TaskManager(getApplicationContext(),"lightIntensityStream",mIEdgeAnalyticServiceCallback,mCep);
>> taskManager.initializeServiceType(type);
>>
>> }
>> }
>>
>> //get servicePatterns
>> @Override
>> public void getServicePattern(String type, String streamDefinition, 
>> String stream, String query1,String query2 ,String 
>> callbackFunctionName1,String 
>> callbackFunctionName2,IEdgeAnalyticServiceCallback cb) {
>>
>> mIEdgeAnalyticServiceCallback = cb;
>>
>> /** Add the details to CEP if the Client is Type1 */
>> if (type.equalsIgnoreCase("TYPE1")) {
>> mCep.ce

Re: [Dev] Occurring more callbacks after the initial run of the android app-Siddhi

2015-11-03 Thread Lasantha Fernando
On 3 November 2015 at 16:09, Lakini Senanayaka  wrote:

> Hi Lasantha,
>
> This is the class I'm calling and instantiate the CEP object.
>
> package org.wso2.edgeanalyticsservice1;
>
> import android.app.Service;
> import android.content.Intent;
> import android.os.IBinder;
> import android.util.Log;
>
> /**
>  * This class implements IEdgeAnalyticService.aidl interface
>  */
> public class EdgeAnalyticsService extends Service {
>
> private CEP mCep;
> private TaskManager taskManager=null;
>
> public EdgeAnalyticsService() {
> mCep = new CEP();
> }
>
> @Override
> public void onCreate() {
> }
>
> /** Returns the IBinder object for the connection */
> @Override
> public IBinder onBind(Intent intent) {
> taskManager=null;
> return mBinder;
> }
>
> @Override
> public int onStartCommand(Intent intent, int flags, int startId) {
> return Service.START_STICKY;
> }
>
> @Override
> public boolean onUnbind (Intent intent){
> return false;
> }
>
> @Override
> public void onDestroy() {
> stopSelf();
> }
>
> /** Implementation of methods in the IEdgeAnalyticsService interface */
> public final IEdgeAnalyticsService.Stub mBinder = new 
> IEdgeAnalyticsService.Stub() {
>
> IEdgeAnalyticServiceCallback mIEdgeAnalyticServiceCallback=null;
>
> @Override
> public void getServiceNormal(String type, String streamDefinition, 
> String stream, String query, String 
> callbackFunctionName,IEdgeAnalyticServiceCallback cb) {
>
> mIEdgeAnalyticServiceCallback = cb;
>
>
> /** Add the details to CEP if the Client is Type1 */
> if (type.equalsIgnoreCase("TYPE1")) {
> mCep.cepAddDetails(getApplicationContext(), streamDefinition, 
> stream, query, callbackFunctionName, cb);
> }
>
> /** Add the details to CEP if the Client is 
> Type2-LOCATION_SERVICE */
> else if (type.equalsIgnoreCase("LOCATION_SERVICE")) {
> mCep.cepAddDetails(getApplicationContext(), "define stream 
> LocationStream (latitude double,longitude double); ", "LocationStream", 
> query, callbackFunctionName,cb);
> taskManager = new 
> TaskManager(getApplicationContext(),"LocationStream",mIEdgeAnalyticServiceCallback,mCep);
> taskManager.initializeServiceType(type);
> }
>
> /** Add the details to CEP if the Client is 
> Type2-HUMIDITY_SERVICE */
> else if (type.equalsIgnoreCase("HUMIDITY_SERVICE")) {
> mCep.cepAddDetails(getApplicationContext(), "define stream 
> HumidityStream (humidity float); ", "HumidityStream", query, 
> callbackFunctionName, cb);
> taskManager = new 
> TaskManager(getApplicationContext(),"HumidityStream",mIEdgeAnalyticServiceCallback,mCep);
> taskManager.initializeServiceType(type);
> }
>
> /** Add the details to CEP if the Client is 
> Type2-TEMPERATURE_SERVICE */
> else if (type.equalsIgnoreCase("TEMPERATURE_SERVICE")) {
> mCep.cepAddDetails(getApplicationContext(), "define stream 
> temperatureStream (tempValue float); ", "temperatureStream", query, 
> callbackFunctionName,cb);
> taskManager = new 
> TaskManager(getApplicationContext(),"temperatureStream",mIEdgeAnalyticServiceCallback,mCep);
> taskManager.initializeServiceType(type);
> }
>
> /** Add the details to CEP if the Client is 
> Type2-INTENSITY_SERVICE*/
> else if (type.equalsIgnoreCase("INTENSITY_SERVICE")) {
> Log.d("client","INTENSITY SERVICE");
> mCep.cepAddDetails(getApplicationContext(), "define stream 
> lightIntensityStream (lightValue double); ", "lightIntensityStream", query, 
> callbackFunctionName, cb);
> taskManager = new 
> TaskManager(getApplicationContext(),"lightIntensityStream",mIEdgeAnalyticServiceCallback,mCep);
> taskManager.initializeServiceType(type);
>
> }
> }
>
> //get servicePatterns
> @Override
> public void getServicePattern(String type, String streamDefinition, 
> String stream, String query1,String query2 ,String 
> callbackFunctionName1,String 
> callbackFunctionName2,IEdgeAnalyticServiceCallback cb) {
>
> mIEdgeAnalyticServiceCallback = cb;
>
> /** Add the details to CEP if the Client is Type1 */
> if (type.equalsIgnoreCase("TYPE1")) {
> mCep.cepAddDetails(getApplicationContext(), streamDefinition, 
> stream, query1, query2, callbackFunctionName1,callbackFunctionName2,cb);
> }
>
> else if (type.equalsIgnoreCase("LOCATION_SERVICE")) {
> mCep.cepAddDetails(getApplicationContext(), "define stream 
> LocationStream (latitude double,longitude double); ", "LocationStream", 
> q

Re: [Dev] Occurring more callbacks after the initial run of the android app-Siddhi

2015-11-03 Thread Lakini Senanayaka
Hi Lasantha,

This is the class I'm calling and instantiate the CEP object.

package org.wso2.edgeanalyticsservice1;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

/**
 * This class implements IEdgeAnalyticService.aidl interface
 */
public class EdgeAnalyticsService extends Service {

private CEP mCep;
private TaskManager taskManager=null;

public EdgeAnalyticsService() {
mCep = new CEP();
}

@Override
public void onCreate() {
}

/** Returns the IBinder object for the connection */
@Override
public IBinder onBind(Intent intent) {
taskManager=null;
return mBinder;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return Service.START_STICKY;
}

@Override
public boolean onUnbind (Intent intent){
return false;
}

@Override
public void onDestroy() {
stopSelf();
}

/** Implementation of methods in the IEdgeAnalyticsService interface */
public final IEdgeAnalyticsService.Stub mBinder = new
IEdgeAnalyticsService.Stub() {

IEdgeAnalyticServiceCallback mIEdgeAnalyticServiceCallback=null;

@Override
public void getServiceNormal(String type, String
streamDefinition, String stream, String query, String
callbackFunctionName,IEdgeAnalyticServiceCallback cb) {

mIEdgeAnalyticServiceCallback = cb;


/** Add the details to CEP if the Client is Type1 */
if (type.equalsIgnoreCase("TYPE1")) {
mCep.cepAddDetails(getApplicationContext(),
streamDefinition, stream, query, callbackFunctionName, cb);
}

/** Add the details to CEP if the Client is
Type2-LOCATION_SERVICE */
else if (type.equalsIgnoreCase("LOCATION_SERVICE")) {
mCep.cepAddDetails(getApplicationContext(), "define
stream LocationStream (latitude double,longitude double); ",
"LocationStream", query, callbackFunctionName,cb);
taskManager = new
TaskManager(getApplicationContext(),"LocationStream",mIEdgeAnalyticServiceCallback,mCep);
taskManager.initializeServiceType(type);
}

/** Add the details to CEP if the Client is
Type2-HUMIDITY_SERVICE */
else if (type.equalsIgnoreCase("HUMIDITY_SERVICE")) {
mCep.cepAddDetails(getApplicationContext(), "define
stream HumidityStream (humidity float); ", "HumidityStream", query,
callbackFunctionName, cb);
taskManager = new
TaskManager(getApplicationContext(),"HumidityStream",mIEdgeAnalyticServiceCallback,mCep);
taskManager.initializeServiceType(type);
}

/** Add the details to CEP if the Client is
Type2-TEMPERATURE_SERVICE */
else if (type.equalsIgnoreCase("TEMPERATURE_SERVICE")) {
mCep.cepAddDetails(getApplicationContext(), "define
stream temperatureStream (tempValue float); ", "temperatureStream",
query, callbackFunctionName,cb);
taskManager = new
TaskManager(getApplicationContext(),"temperatureStream",mIEdgeAnalyticServiceCallback,mCep);
taskManager.initializeServiceType(type);
}

/** Add the details to CEP if the Client is
Type2-INTENSITY_SERVICE*/
else if (type.equalsIgnoreCase("INTENSITY_SERVICE")) {
Log.d("client","INTENSITY SERVICE");
mCep.cepAddDetails(getApplicationContext(), "define
stream lightIntensityStream (lightValue double); ",
"lightIntensityStream", query, callbackFunctionName, cb);
taskManager = new
TaskManager(getApplicationContext(),"lightIntensityStream",mIEdgeAnalyticServiceCallback,mCep);
taskManager.initializeServiceType(type);

}
}

//get servicePatterns
@Override
public void getServicePattern(String type, String
streamDefinition, String stream, String query1,String query2 ,String
callbackFunctionName1,String
callbackFunctionName2,IEdgeAnalyticServiceCallback cb) {

mIEdgeAnalyticServiceCallback = cb;

/** Add the details to CEP if the Client is Type1 */
if (type.equalsIgnoreCase("TYPE1")) {
mCep.cepAddDetails(getApplicationContext(),
streamDefinition, stream, query1, query2,
callbackFunctionName1,callbackFunctionName2,cb);
}

else if (type.equalsIgnoreCase("LOCATION_SERVICE")) {
mCep.cepAddDetails(getApplicationContext(), "define
stream LocationStream (latitude double,longitude double); ",
"LocationStream",
query1,query2,callbackFunctionName1,callbackFunctionName2,cb);
taskManager = new
TaskManager(getApplicationContext(),"LocationStream",mIEdgeAnalyticServiceCallback,mCep);
taskManager.initializeServiceType(type);
}

/** Add the details to CEP if the Client is
Type2-HUMIDI

Re: [Dev] Occurring more callbacks after the initial run of the android app-Siddhi

2015-11-03 Thread Lasantha Fernando
Hi Lakini,

It seems multiple Siddhi managers are getting instantiated and each siddhi
manager is running without being shut down. Can you point to the code where
the CEP class is instantiated?

Also, you can try a singleton pattern for the CEP class and do some checks
when adding the queries or adopt a similar approach to avoid the issue of
multiple queries running.

Thanks,
Lasantha

On 3 November 2015 at 15:31, Lakini Senanayaka  wrote:

> adding Dev@wso2
>
> On Tue, Nov 3, 2015 at 3:25 PM, Lakini Senanayaka  wrote:
>
>> Hi,
>>
>> I have implemented a service using Siddhi 2.1.0.
>> This is my Service class which deals with siddhimanager.
>>
>> package org.wso2.edgeanalyticsservice1;
>>
>> import android.content.Context;
>>
>> import org.wso2.siddhi.core.SiddhiManager;
>> import org.wso2.siddhi.core.event.Event;
>> import org.wso2.siddhi.core.stream.input.InputHandler;
>> import org.wso2.siddhi.core.stream.output.StreamCallback;
>> import org.wso2.siddhi.core.util.EventPrinter;
>>
>> /**
>>  * This class create from the build in sensors and inject
>>  * to the EdgeAnalytics Service for processing on a query passed.
>>  */
>> public class CEP {
>>
>> private SiddhiManager mSiddhiManager;
>> private IEdgeAnalyticServiceCallback mCallb = null;
>>
>> /** Initialize the SiddhiManager Instance */
>> public CEP() {
>> mSiddhiManager = new SiddhiManager();
>> }
>>
>> /** Add extra details to the SiddhiManager object  */
>> public void cepAddDetails(final Context context, String 
>> streamDefinition, String stream, final String query, final String 
>> callbackFunction,IEdgeAnalyticServiceCallback cb) {
>> mCallb=cb;
>>
>> /** Define the stream to the Siddhi Manager  */
>> mSiddhiManager.defineStream(streamDefinition);
>>
>> /** Define the query to the Siddhi Manager  */
>> mSiddhiManager.addQuery(query);
>>
>> /** Define the scallback details to the Siddhi Manager  */
>> mSiddhiManager.addCallback(callbackFunction, new StreamCallback() {
>> public void receive(Event[] events) {
>> EventPrinter.print(events);
>> try {
>> mCallb.addCallBack("Passed!! " );
>> } catch (Exception e) {
>> e.printStackTrace();
>> }
>> }
>> });
>> }
>>
>> /** Add extra details to the SiddhiManager object  */
>> public void cepAddDetails(final Context context, String 
>> streamDefinition, String stream, final String query1, final String 
>> query2,final String callbackFunction1,final String 
>> callbackFunction2,IEdgeAnalyticServiceCallback cb) {
>> //todo:Check the pattern queries
>>
>> mCallb=cb;
>>
>> /** Define the stream to the Siddhi Manager  */
>> mSiddhiManager.defineStream(streamDefinition);
>>
>> /** Define the query to the Siddhi Manager  */
>> mSiddhiManager.addQuery(query1);
>> mSiddhiManager.addQuery(query2);
>>
>> /** Define the scallback details to the Siddhi Manager  */
>> mSiddhiManager.addCallback(callbackFunction1, new StreamCallback() {
>> public void receive(Event[] events) {
>> EventPrinter.print(events);
>> try {
>> mCallb.addCallBack("callback1");
>> } catch (Exception e) {
>> e.printStackTrace();
>> }
>> }
>> });
>>
>> mSiddhiManager.addCallback(callbackFunction2, new StreamCallback() {
>> public void receive(Event[] events) {
>> EventPrinter.print(events);
>> try {
>> mCallb.addCallBack("callback2");
>> } catch (Exception e) {
>> e.printStackTrace();
>> }
>> }
>> });
>> }
>>
>> /** Analyse single data and send the notification back to client through 
>> callbacks */
>> public void analyseTheData(String value, String stream, 
>> IEdgeAnalyticServiceCallback cb) {
>>
>> String[] dataCollection=value.split(",");
>> String[] value_type=null;
>> Object[] x =new Object[dataCollection.length];
>>
>> /** Identify the data types which the client sends. */
>> for(int i=0;i> {
>> value_type=dataCollection[i].split("-");
>> x[i]=0;
>> switch (value_type[1]) {
>> case "double":
>> x[i]=Double.parseDouble(value_type[0]);
>> break;
>> case "float":
>> x[i]=Float.parseFloat(value_type[0]);
>> break;
>> case "int":
>> x[i]=Integer.parseInt(value_type[0]);
>> break;
>> case "string":
>> x[i]=value_type[0];
>> break;
>> 

Re: [Dev] Occurring more callbacks after the initial run of the android app-Siddhi

2015-11-03 Thread Lakini Senanayaka
adding Dev@wso2

On Tue, Nov 3, 2015 at 3:25 PM, Lakini Senanayaka  wrote:

> Hi,
>
> I have implemented a service using Siddhi 2.1.0.
> This is my Service class which deals with siddhimanager.
>
> package org.wso2.edgeanalyticsservice1;
>
> import android.content.Context;
>
> import org.wso2.siddhi.core.SiddhiManager;
> import org.wso2.siddhi.core.event.Event;
> import org.wso2.siddhi.core.stream.input.InputHandler;
> import org.wso2.siddhi.core.stream.output.StreamCallback;
> import org.wso2.siddhi.core.util.EventPrinter;
>
> /**
>  * This class create from the build in sensors and inject
>  * to the EdgeAnalytics Service for processing on a query passed.
>  */
> public class CEP {
>
> private SiddhiManager mSiddhiManager;
> private IEdgeAnalyticServiceCallback mCallb = null;
>
> /** Initialize the SiddhiManager Instance */
> public CEP() {
> mSiddhiManager = new SiddhiManager();
> }
>
> /** Add extra details to the SiddhiManager object  */
> public void cepAddDetails(final Context context, String streamDefinition, 
> String stream, final String query, final String 
> callbackFunction,IEdgeAnalyticServiceCallback cb) {
> mCallb=cb;
>
> /** Define the stream to the Siddhi Manager  */
> mSiddhiManager.defineStream(streamDefinition);
>
> /** Define the query to the Siddhi Manager  */
> mSiddhiManager.addQuery(query);
>
> /** Define the scallback details to the Siddhi Manager  */
> mSiddhiManager.addCallback(callbackFunction, new StreamCallback() {
> public void receive(Event[] events) {
> EventPrinter.print(events);
> try {
> mCallb.addCallBack("Passed!! " );
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> });
> }
>
> /** Add extra details to the SiddhiManager object  */
> public void cepAddDetails(final Context context, String streamDefinition, 
> String stream, final String query1, final String query2,final String 
> callbackFunction1,final String callbackFunction2,IEdgeAnalyticServiceCallback 
> cb) {
> //todo:Check the pattern queries
>
> mCallb=cb;
>
> /** Define the stream to the Siddhi Manager  */
> mSiddhiManager.defineStream(streamDefinition);
>
> /** Define the query to the Siddhi Manager  */
> mSiddhiManager.addQuery(query1);
> mSiddhiManager.addQuery(query2);
>
> /** Define the scallback details to the Siddhi Manager  */
> mSiddhiManager.addCallback(callbackFunction1, new StreamCallback() {
> public void receive(Event[] events) {
> EventPrinter.print(events);
> try {
> mCallb.addCallBack("callback1");
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> });
>
> mSiddhiManager.addCallback(callbackFunction2, new StreamCallback() {
> public void receive(Event[] events) {
> EventPrinter.print(events);
> try {
> mCallb.addCallBack("callback2");
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
> });
> }
>
> /** Analyse single data and send the notification back to client through 
> callbacks */
> public void analyseTheData(String value, String stream, 
> IEdgeAnalyticServiceCallback cb) {
>
> String[] dataCollection=value.split(",");
> String[] value_type=null;
> Object[] x =new Object[dataCollection.length];
>
> /** Identify the data types which the client sends. */
> for(int i=0;i {
> value_type=dataCollection[i].split("-");
> x[i]=0;
> switch (value_type[1]) {
> case "double":
> x[i]=Double.parseDouble(value_type[0]);
> break;
> case "float":
> x[i]=Float.parseFloat(value_type[0]);
> break;
> case "int":
> x[i]=Integer.parseInt(value_type[0]);
> break;
> case "string":
> x[i]=value_type[0];
> break;
> default:
> break;
>}
>}
>
> InputHandler inputHandler = mSiddhiManager.getInputHandler(stream);
>try
>{
>inputHandler.send(x);
>}
>catch (InterruptedException e) {
>e.printStackTrace();
>}
> }
> }
>
> I have set a timer and I'm passing data to the siddhi stream.
> When I run this app for the first time it gives only one callback and
> working fine.But After I run the same app again and again it gives more
> callbacks