Unable to insert events to esper
-
- Posts: 16
- Joined: Tue Jun 14, 2016 2:02 am
Unable to insert events to esper
Hello All,
Based on Northwind example, I'm trying to create an event into esper once my readzone monitoring service is invoked. Unfortunately, I'm facing a class not found exception while putting an event to esper. I tried adding the event class file manually to the build path but that didn't help either
ERROR com.espertech.esper.core.service.StatementResultServiceImpl:392 - Unexpected exception invoking listener update method on listener class '' : NoClassDefFoundError : org/rifidi/app/rfidintel/event/ArriveEvent
java.lang.NoClassDefFoundError: org/rifidi/app/rfidintel/event/ArriveEvent
Caused by: java.lang.ClassNotFoundException: org.rifidi.app.rfidintel.event.ArriveEvent cannot be found by org.rifidi.edge_5.9.4
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:439)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:573)
at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:99)
My source code looks like this
--------------------------
My App
--------------------------
public class RFIDIntelApp extends AbstractRifidiApp {
/** The service for monitoring arrival and departure events */
private List<ReadZoneSubscriber> subscriberList;
private ReadZoneMonitoringService readZoneMonitoringService;
public RFIDIntelApp(String group, String name) {
super(group, name);
System.out.println("Group:- "+group+" name "+name);
}
/*
* (non-Javadoc)
*
* @see org.rifidi.edge.api.AbstractRifidiApp#_start()
*/
@Override
public void _start() {
super._start();
System.out.println("Test Hello world start");
/* ReadZone zone = super.getReadZones().get("generic");
List<ReadZone> readzonelist = new LinkedList<ReadZone>();
readzonelist.add(zone);
RFIDIntelSubscriber sub = new RFIDIntelSubscriber();
this.subscriberList = new LinkedList<ReadZoneSubscriber>();
this.subscriberList.add(sub);
this.readZoneMonitoringService.subscribe(sub,
readzonelist, 1.0f, TimeUnit.SECONDS);*/
addEventType(ArriveEvent.class);
//try {
System.out.println("Thread sleeping for 10s");
//Thread.sleep(10000);
System.out.println("Thread active now");
//} catch (InterruptedException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
//}
RFIDIntelSubscriber sub = new RFIDIntelSubscriber(this);
this.subscriberList = new LinkedList<ReadZoneSubscriber>();
this.subscriberList.add(sub);
this.readZoneMonitoringService.subscribe(sub);
StatementAwareUpdateListener arrivalListener = new StatementAwareUpdateListener() {
@Override
public void update(EventBean[] arg0, EventBean[] arg1,
EPStatement arg2, EPServiceProvider arg3) {
if (arg0 != null) {
System.out.println("Total no of tags seen in last 30 seconds "+arg0[0].get("count(arrived.tag.tag.ID)"));
}
}
};
addStatement("select arrived.tag.tag.ID from ArriveEvent.win:time(30 sec) as arrived",arrivalListener);
}
/*
* (non-Javadoc)
*
* @see org.rifidi.edge.api.AbstractRifidiApp#_stop()
*/
@Override
public void _stop() {
System.out.println("Test Hello world stop");
for (ReadZoneSubscriber s : this.subscriberList) {
this.readZoneMonitoringService.unsubscribe(s);
}
}
public void sendArrivedEvent(ArriveEvent event) {
System.out.println("Before Send event ");
this.sendEvent(event);
System.out.println("After Send event");
}
/*
* (non-Javadoc)
*
* @see org.rifidi.edge.api.AbstractRifidiApp#initialize()
*/
@Override
public void initialize() {
System.out.println("Test Hello world initialization1");
}
/**
* Called by spring. This method injects the ReadZoneMonitoringService into
* the application.
*
* @param rzms
*/
public void setReadZoneMonitoringService(ReadZoneMonitoringService rzms) {
System.out.println("Readzone monitoring service called successfully.");
this.readZoneMonitoringService = rzms;
}
}
----------------------------
Subscriber
----------------------------
public class RFIDIntelSubscriber implements ReadZoneSubscriber {
private RFIDIntelApp app;
/**
* Constructor
*
* @param conn
* The database connection
*/
public RFIDIntelSubscriber(RFIDIntelApp app) {
this.app = app;
}
/*
* (non-Javadoc)
*
* @see
* org.rifidi.edge.api.service.tagmonitor.ReadZoneSubscriber#tagArrived(
* org.rifidi.edge.notification.TagReadEvent)
*/
@Override
public void tagArrived(TagReadEvent tag) {
System.out.println("TAG ARRIVED ID: " + tag.getTag().getFormattedID());
System.out.println("TAG ARRIVED Reader name: " + tag.getReaderID());
System.out.println("TAG ARRIVED Antenna name: " + tag.getAntennaID());
System.out.println("TAG ARRIVED TIME: " + tag.getTimestamp());
if(this.app != null)
{
System.out.println("App not null");
this.app.sendArrivedEvent(new ArriveEvent(tag));
}
else
{
System.out.println("App null");
}
}
/*
* (non-Javadoc)
*
* @see
* org.rifidi.edge.api.service.tagmonitor.ReadZoneSubscriber#tagDeparted
* (org.rifidi.edge.notification.TagReadEvent)
*/
@Override
public void tagDeparted(TagReadEvent tag) {
//System.out.println("TAG DEPARTED ID: " + tag.getTag().getFormattedID());
//System.out.println("TAG DEPARTED TIME: " + tag.getTimestamp());
}
}
--------------
Event
--------------
public class ArriveEvent {
/** The tag that arrived */
private final TagReadEvent tag;
/**
* @param tag
*/
public ArriveEvent(TagReadEvent tag) {
//super();
System.out.println("Arrive event");
this.tag = tag;
}
/**
* @return the tag
*/
public TagReadEvent getTag() {
return tag;
}
}
Any thoughts/suggestions?
Thanks
Karthik
Based on Northwind example, I'm trying to create an event into esper once my readzone monitoring service is invoked. Unfortunately, I'm facing a class not found exception while putting an event to esper. I tried adding the event class file manually to the build path but that didn't help either
ERROR com.espertech.esper.core.service.StatementResultServiceImpl:392 - Unexpected exception invoking listener update method on listener class '' : NoClassDefFoundError : org/rifidi/app/rfidintel/event/ArriveEvent
java.lang.NoClassDefFoundError: org/rifidi/app/rfidintel/event/ArriveEvent
Caused by: java.lang.ClassNotFoundException: org.rifidi.app.rfidintel.event.ArriveEvent cannot be found by org.rifidi.edge_5.9.4
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:439)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:573)
at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:99)
My source code looks like this
--------------------------
My App
--------------------------
public class RFIDIntelApp extends AbstractRifidiApp {
/** The service for monitoring arrival and departure events */
private List<ReadZoneSubscriber> subscriberList;
private ReadZoneMonitoringService readZoneMonitoringService;
public RFIDIntelApp(String group, String name) {
super(group, name);
System.out.println("Group:- "+group+" name "+name);
}
/*
* (non-Javadoc)
*
* @see org.rifidi.edge.api.AbstractRifidiApp#_start()
*/
@Override
public void _start() {
super._start();
System.out.println("Test Hello world start");
/* ReadZone zone = super.getReadZones().get("generic");
List<ReadZone> readzonelist = new LinkedList<ReadZone>();
readzonelist.add(zone);
RFIDIntelSubscriber sub = new RFIDIntelSubscriber();
this.subscriberList = new LinkedList<ReadZoneSubscriber>();
this.subscriberList.add(sub);
this.readZoneMonitoringService.subscribe(sub,
readzonelist, 1.0f, TimeUnit.SECONDS);*/
addEventType(ArriveEvent.class);
//try {
System.out.println("Thread sleeping for 10s");
//Thread.sleep(10000);
System.out.println("Thread active now");
//} catch (InterruptedException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
//}
RFIDIntelSubscriber sub = new RFIDIntelSubscriber(this);
this.subscriberList = new LinkedList<ReadZoneSubscriber>();
this.subscriberList.add(sub);
this.readZoneMonitoringService.subscribe(sub);
StatementAwareUpdateListener arrivalListener = new StatementAwareUpdateListener() {
@Override
public void update(EventBean[] arg0, EventBean[] arg1,
EPStatement arg2, EPServiceProvider arg3) {
if (arg0 != null) {
System.out.println("Total no of tags seen in last 30 seconds "+arg0[0].get("count(arrived.tag.tag.ID)"));
}
}
};
addStatement("select arrived.tag.tag.ID from ArriveEvent.win:time(30 sec) as arrived",arrivalListener);
}
/*
* (non-Javadoc)
*
* @see org.rifidi.edge.api.AbstractRifidiApp#_stop()
*/
@Override
public void _stop() {
System.out.println("Test Hello world stop");
for (ReadZoneSubscriber s : this.subscriberList) {
this.readZoneMonitoringService.unsubscribe(s);
}
}
public void sendArrivedEvent(ArriveEvent event) {
System.out.println("Before Send event ");
this.sendEvent(event);
System.out.println("After Send event");
}
/*
* (non-Javadoc)
*
* @see org.rifidi.edge.api.AbstractRifidiApp#initialize()
*/
@Override
public void initialize() {
System.out.println("Test Hello world initialization1");
}
/**
* Called by spring. This method injects the ReadZoneMonitoringService into
* the application.
*
* @param rzms
*/
public void setReadZoneMonitoringService(ReadZoneMonitoringService rzms) {
System.out.println("Readzone monitoring service called successfully.");
this.readZoneMonitoringService = rzms;
}
}
----------------------------
Subscriber
----------------------------
public class RFIDIntelSubscriber implements ReadZoneSubscriber {
private RFIDIntelApp app;
/**
* Constructor
*
* @param conn
* The database connection
*/
public RFIDIntelSubscriber(RFIDIntelApp app) {
this.app = app;
}
/*
* (non-Javadoc)
*
* @see
* org.rifidi.edge.api.service.tagmonitor.ReadZoneSubscriber#tagArrived(
* org.rifidi.edge.notification.TagReadEvent)
*/
@Override
public void tagArrived(TagReadEvent tag) {
System.out.println("TAG ARRIVED ID: " + tag.getTag().getFormattedID());
System.out.println("TAG ARRIVED Reader name: " + tag.getReaderID());
System.out.println("TAG ARRIVED Antenna name: " + tag.getAntennaID());
System.out.println("TAG ARRIVED TIME: " + tag.getTimestamp());
if(this.app != null)
{
System.out.println("App not null");
this.app.sendArrivedEvent(new ArriveEvent(tag));
}
else
{
System.out.println("App null");
}
}
/*
* (non-Javadoc)
*
* @see
* org.rifidi.edge.api.service.tagmonitor.ReadZoneSubscriber#tagDeparted
* (org.rifidi.edge.notification.TagReadEvent)
*/
@Override
public void tagDeparted(TagReadEvent tag) {
//System.out.println("TAG DEPARTED ID: " + tag.getTag().getFormattedID());
//System.out.println("TAG DEPARTED TIME: " + tag.getTimestamp());
}
}
--------------
Event
--------------
public class ArriveEvent {
/** The tag that arrived */
private final TagReadEvent tag;
/**
* @param tag
*/
public ArriveEvent(TagReadEvent tag) {
//super();
System.out.println("Arrive event");
this.tag = tag;
}
/**
* @return the tag
*/
public TagReadEvent getTag() {
return tag;
}
}
Any thoughts/suggestions?
Thanks
Karthik
Re: Unable to insert events to esper
did you create event classes and import them
Northwind example
https://transcends.svn.cloudforge.com/r ... northwind/
see NorthwindApp.java and org/rifidi/edge/northwind/events/ package
I believe this is teh important snippet to register event classes with esper
public void _start() {
// The _start method is called after the initialize method. In this
// method you want to define your ReadZones and define your subscribers.
// This is also a good place to create your esper statements and
// listeners.
super._start();
/* These statements register the events we will use */
addEventType(DockDoorArrivedEvent.class);
addEventType(DockDoorDepartedEvent.class);
addEventType(WeighStationDepartedEvent.class);
addEventType(WeighStationArrivedEvent.class);
Northwind example
https://transcends.svn.cloudforge.com/r ... northwind/
see NorthwindApp.java and org/rifidi/edge/northwind/events/ package
I believe this is teh important snippet to register event classes with esper
public void _start() {
// The _start method is called after the initialize method. In this
// method you want to define your ReadZones and define your subscribers.
// This is also a good place to create your esper statements and
// listeners.
super._start();
/* These statements register the events we will use */
addEventType(DockDoorArrivedEvent.class);
addEventType(DockDoorDepartedEvent.class);
addEventType(WeighStationDepartedEvent.class);
addEventType(WeighStationArrivedEvent.class);
-
- Posts: 16
- Joined: Tue Jun 14, 2016 2:02 am
Re: Unable to insert events to esper
Yes. I've created events and imported them.
I've also added the following code to register the events to esper
addEventType(ArriveEvent.class);
I felt like the events are taking some time to get registered and used thread.sleep(10000) after the above code. But that didn't help me either. I face this "classNotFoundException" whenever I try to send the tagRead event(sent by the read zone subscriber to my app) to esper from my custom rifidi app.
Probably, the addEventType(ArriveEvent.class) is still not registering my event to esper ?
I've also added the following code to register the events to esper
addEventType(ArriveEvent.class);
I felt like the events are taking some time to get registered and used thread.sleep(10000) after the above code. But that didn't help me either. I face this "classNotFoundException" whenever I try to send the tagRead event(sent by the read zone subscriber to my app) to esper from my custom rifidi app.
Probably, the addEventType(ArriveEvent.class) is still not registering my event to esper ?
Re: Unable to insert events to esper
Try exporting your packages in your manifest "runtime" tab. It may be that the edge plugin can't see them if those aren't there.
-Matt
-Matt
-
- Posts: 16
- Joined: Tue Jun 14, 2016 2:02 am
Re: Unable to insert events to esper
Thanks a lot Matt. It worked.
-
- Posts: 16
- Joined: Tue Jun 14, 2016 2:02 am
Re: Unable to insert events to esper
Just have a few questions subject to esper
1. Under what circumstances, do we define and implement a custom event type (via a POJO) ? I believe the same stuff can be accomplished by using TagReadEvent without having to register an event in the esper and defining a POJO for custom event type.
2. Do we always need a subscribing monitoring service (for ex:- ReadZoneMonitoringService) to put an event into the esper ?
1. Under what circumstances, do we define and implement a custom event type (via a POJO) ? I believe the same stuff can be accomplished by using TagReadEvent without having to register an event in the esper and defining a POJO for custom event type.
2. Do we always need a subscribing monitoring service (for ex:- ReadZoneMonitoringService) to put an event into the esper ?
Re: Unable to insert events to esper
1. I'd recommend using a custom event type if:
a. The standard event types don't do what you want, or
b. you only want your code or a specific portion of your code to react to that particular event. If you insert, say, a TagReadEvent that may cause code elsewhere in the system to react to that event, which you may or may not want.
2. No, you don't need a subscriber to insert an event into esper, though if we are talking custom events it is likely no one will be listening to them unless you have another subscriber elsewhere.
-Matt
a. The standard event types don't do what you want, or
b. you only want your code or a specific portion of your code to react to that particular event. If you insert, say, a TagReadEvent that may cause code elsewhere in the system to react to that event, which you may or may not want.
2. No, you don't need a subscriber to insert an event into esper, though if we are talking custom events it is likely no one will be listening to them unless you have another subscriber elsewhere.
-Matt
-
- Posts: 16
- Joined: Tue Jun 14, 2016 2:02 am
Re: Unable to insert events to esper
1. I'm not sure if I understood your statement correctly.
Say for example, I've 2 rifidi custom apps which both sends a tagReadEvent to esper. Does a tagReadEvent sent to esper from one rifidi could trigger the listener in other rifidi app in addition to its own listener? Is that what you meant?
2. If I don't insert the tagReadEvent into esper via a subscriber, my following listener isn't getting invoked at all when a bunch of tags kept near a reader for some time. Can you provide some example on how is this listener can be invoked w/o subscriber ?
StatementAwareUpdateListener arrivalListener = new StatementAwareUpdateListener() {
@Override
public void update(EventBean[] arg0, EventBean[] arg1,
EPStatement arg2, EPServiceProvider arg3) {
if (arg0 != null) {
System.out.println("Total no of tags seen in last 30 seconds "+arg0[0].get("count(arrived.tag.ID)"));
}
}
};
addStatement("select count(arrived.tag.ID) from TagReadEvent.win:time(30 sec) as arrived having count(arrived.tag.ID) > 3",arrivalListener);
Thanks
Say for example, I've 2 rifidi custom apps which both sends a tagReadEvent to esper. Does a tagReadEvent sent to esper from one rifidi could trigger the listener in other rifidi app in addition to its own listener? Is that what you meant?
2. If I don't insert the tagReadEvent into esper via a subscriber, my following listener isn't getting invoked at all when a bunch of tags kept near a reader for some time. Can you provide some example on how is this listener can be invoked w/o subscriber ?
StatementAwareUpdateListener arrivalListener = new StatementAwareUpdateListener() {
@Override
public void update(EventBean[] arg0, EventBean[] arg1,
EPStatement arg2, EPServiceProvider arg3) {
if (arg0 != null) {
System.out.println("Total no of tags seen in last 30 seconds "+arg0[0].get("count(arrived.tag.ID)"));
}
}
};
addStatement("select count(arrived.tag.ID) from TagReadEvent.win:time(30 sec) as arrived having count(arrived.tag.ID) > 3",arrivalListener);
Thanks
Re: Unable to insert events to esper
1. Yes. Any event sent in will trigger anyone else looking for that particular event if it matches their statement. This is more theoretical than practical -- I doubt any reasonable code written would actually do something unexpected. If you are worried, just use custom events. It isn't that much code to write and register one.
2. Northwind sends in an event sans subscriber, you could check that. Also I don't know exactly what you are doing with that listener, but I should point out that the events that are directly being inserted into esper by readers are ReadCycles(which contain 1-N TagReadEvents), not TagReadEvents directly. So if that is what you are looking for, bear that in mind.
If you need more specific help for your app, one of the services we sell is consulting. You can email markus@transcends.co if you are interested in that.
2. Northwind sends in an event sans subscriber, you could check that. Also I don't know exactly what you are doing with that listener, but I should point out that the events that are directly being inserted into esper by readers are ReadCycles(which contain 1-N TagReadEvents), not TagReadEvents directly. So if that is what you are looking for, bear that in mind.
If you need more specific help for your app, one of the services we sell is consulting. You can email markus@transcends.co if you are interested in that.
Who is online
Users browsing this forum: No registered users and 7 guests