Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Eclipse SmartHome » Exporting a Binding with custom Event to OpenHAB2.
Exporting a Binding with custom Event to OpenHAB2. [message #1707148] Wed, 02 September 2015 15:02 Go to next message
Tonis Tiganik is currently offline Tonis TiganikFriend
Messages: 7
Registered: August 2015
Junior Member
Hello again. I have finished implementing my binding with ESH. It works well when launched with ESH in Eclipse.

However we would like the binding to work with OpenHAB2 as well, so I have been trying to export it from ESH. Exporting straight from Eclipse(deployable plug-ins and fragments) gives me an error:

A cycle was detected when generating the classpath org.eclipse.smarthome.binding.hmhome_0.8.0.201509021741, org.eclipse.smarthome.config.core_0.8.0.201509021741, org.eclipse.smarthome.core_0.8.0.201509021741, org.eclipse.smarthome.test_0.8.0.201509021741, org.eclipse.smarthome.config.xml_0.8.0.201509021741, org.eclipse.smarthome.config.core_0.8.0.201509021741.

so I have been using mvn package to get the .jar file.

Adding the .jar to OpenHAB2 addons folder makes the binding work (mDNS discovery + creating a socket connection) until our binding needs to send our custom event.

This produces errors like this:


!ENTRY org.eclipse.equinox.ds 4 0 2015-09-02 17:27:17.607
!MESSAGE [SCR] Exception while activating instance org.eclipse.smarthome.core.thing.internal.ThingManager@5189de9c of component org.eclipse.smarthome.core.thing.internal.ThingManager  
!STACK 0
java.lang.reflect.InvocationTargetException
	at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:235)
	at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
	at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
	at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:343)
	at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:222)
	at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:914)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:464)
	at org.eclipse.equinox.internal.ds.InstanceProcess.registerService(InstanceProcess.java:536)
	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:260)
	at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:473)
	at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:217)
	at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:816)
	at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:783)
	at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: org/eclipse/smarthome/core/events/Event
	at org.eclipse.smarthome.binding.hmhome.internal.WifiModuleHandlerFactory.createHandler(WifiModuleHandlerFactory.java:47)
	at org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory.registerHandler(BaseThingHandlerFactory.java:103)
	at org.eclipse.smarthome.core.thing.internal.ThingManager.registerHandler(ThingManager.java:385)
	at org.eclipse.smarthome.core.thing.internal.ThingManager.registerHandler(ThingManager.java:352)
	at org.eclipse.smarthome.core.thing.internal.ThingManager.thingAdded(ThingManager.java:281)
	at org.eclipse.smarthome.core.thing.internal.ThingRegistryImpl.notifyTrackerAboutAllThingsAdded(ThingRegistryImpl.java:174)
	at org.eclipse.smarthome.core.thing.internal.ThingRegistryImpl.addThingTracker(ThingRegistryImpl.java:41)
	at org.eclipse.smarthome.core.thing.internal.ThingManager.activate(ThingManager.java:407)
	... 27 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.smarthome.core.events.Event cannot be found by org.eclipse.smarthome.binding.hmhome_0.8.0.201509021426
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:432)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:345)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:337)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 35 more
Root exception:
java.lang.NoClassDefFoundError: org/eclipse/smarthome/core/events/Event
	at org.eclipse.smarthome.binding.hmhome.internal.WifiModuleHandlerFactory.createHandler(WifiModuleHandlerFactory.java:47)
	at org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory.registerHandler(BaseThingHandlerFactory.java:103)
	at org.eclipse.smarthome.core.thing.internal.ThingManager.registerHandler(ThingManager.java:385)
	at org.eclipse.smarthome.core.thing.internal.ThingManager.registerHandler(ThingManager.java:352)
	at org.eclipse.smarthome.core.thing.internal.ThingManager.thingAdded(ThingManager.java:281)
	at org.eclipse.smarthome.core.thing.internal.ThingRegistryImpl.notifyTrackerAboutAllThingsAdded(ThingRegistryImpl.java:174)
	at org.eclipse.smarthome.core.thing.internal.ThingRegistryImpl.addThingTracker(ThingRegistryImpl.java:41)
	at org.eclipse.smarthome.core.thing.internal.ThingManager.activate(ThingManager.java:407)
	at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:235)
	at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
	at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
	at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:343)
	at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:222)
	at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:914)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127)
	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:464)
	at org.eclipse.equinox.internal.ds.InstanceProcess.registerService(InstanceProcess.java:536)
	at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:260)
	at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:473)
	at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:217)
	at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:816)
	at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:783)
	at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.eclipse.smarthome.core.events.Event cannot be found by org.eclipse.smarthome.binding.hmhome_0.8.0.201509021426
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:432)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:345)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:337)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 35 more


Does anyone know how to resolve these exceptions so our binding can work with OpenHAB2?



Also, I dont know if this is the result of the same issue or something else: After the first OpenHAB2 launch Thing handler factory is created once, but on subsequent launches the Thing manager goes into a loop, adding and removing my HandlerFactory for ~20 times until stopping with "removed". The NoClassDefFoundError is not visible in the terminal in this case, but I can see them in openhab2/runtime/server/configuration log files.

2015-09-02 17:47:48 [DEBUG] [.c.thing.internal.ThingManager:414 ] - Thing handler factory 'WifiModuleHandlerFactory' added
2015-09-02 17:47:48 [DEBUG] [.c.thing.internal.ThingManager:278 ] - Thing 'hm-home:wifi-module:010c06c192e74812b2' is tracked by ThingManager.
2015-09-02 17:47:48 [DEBUG] [.c.thing.internal.ThingManager:381 ] - Creating handler for thing 'hm-home:wifi-module:010c06c192e74812b2'.
2015-09-02 17:47:48 [DEBUG] [.c.thing.internal.ThingManager:439 ] - Thing handler factory 'WifiModuleHandlerFactory' removed
2015-09-02 17:47:48 [DEBUG] [.c.thing.internal.ThingManager:414 ] - Thing handler factory 'WifiModuleHandlerFactory' added
2015-09-02 17:47:48 [DEBUG] [.c.thing.internal.ThingManager:278 ] - Thing 'hm-home:wifi-module:010c06c192e74812b2' is tracked by ThingManager.
2015-09-02 17:47:48 [DEBUG] [.c.thing.internal.ThingManager:381 ] - Creating handler for thing 'hm-home:wifi-module:010c06c192e74812b2'.
2015-09-02 17:47:48 [DEBUG] [.c.thing.internal.ThingManager:439 ] - Thing handler factory 'WifiModuleHandlerFactory' removed
Re: Exporting a Binding with custom Event to OpenHAB2. [message #1707205 is a reply to message #1707148] Thu, 03 September 2015 06:24 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Hi,

the error is indeed quite strange. From the exception "java.lang.NoClassDefFoundError: org/eclipse/smarthome/core/events/Event" it seems that either the binding can not resolve the Event class or it is not there - which I could not believe.

What are you doing in the class WifiModuleHandlerFactory.java line 47?

For packaging in Eclipse you can close the "org.eclipse.smarthome.core.test" bundle. This should eliminate the circular dependency. It´s a bug in Eclipse, that it adds the fragment bundles to the dependency resolution when exporting it.

Regards

Dennis
Re: Exporting a Binding with custom Event to OpenHAB2. [message #1707235 is a reply to message #1707205] Thu, 03 September 2015 08:20 Go to previous messageGo to next message
Tonis Tiganik is currently offline Tonis TiganikFriend
Messages: 7
Registered: August 2015
Junior Member
Thanks for the response. I can now package in eclipse!

In WifiModuleHandlerFactory.java line 47 I'm returning a new WifiModuleHandler

    protected EventPublisher eventPublisher;

    @Override
    protected ThingHandler createHandler(Thing thing) {
        ThingTypeUID thingTypeUID = thing.getThingTypeUID();

        if (thingTypeUID.equals(THING_TYPE_WIFI_MODULE)) {
            >>>line 47>>>return new WifiModuleHandler(thing, eventPublisher);
        }

        return null;
    }


The EventPublisher is bound successfully(I logged the reference in openHAB2) via WifiModuleHandlerFactory.xml

   <reference bind="setEventPublisher" cardinality="1..1" interface="org.eclipse.smarthome.core.events.EventPublisher" 
           name="EventPublisher" policy="static" unbind="unsetEventPublisher"/>


Could this reference binding be the cause of the error?


EventPublisher reference binding was actually the one thing that I didn't know if I implemented properly. Maybe you should have a separate class for the EventPublisher? But in that case I don't know how to bind that separate class to my handler, since the handler is instantiated in code, not in xml.
Re: Exporting a Binding with custom Event to OpenHAB2. [message #1707236 is a reply to message #1707235] Thu, 03 September 2015 08:33 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Quote:
Could this reference binding be the cause of the error?


No the reference is OK. Everything looks good. Do you have the latest version of openHAB2? If the binding works in ESH, but fails with a NoClassDefFoundException in OH2, something must be wrong with the setup. But I have no idea what it might be.

For what purpose does your binding send own events?
Re: Exporting a Binding with custom Event to OpenHAB2. [message #1707247 is a reply to message #1707236] Thu, 03 September 2015 09:28 Go to previous messageGo to next message
Tonis Tiganik is currently offline Tonis TiganikFriend
Messages: 7
Registered: August 2015
Junior Member
I use openhab-2.0.0.alpha2-runtime from https://github.com/openhab/openhab2/releases/tag/2.0.0-alpha2. I do not touch the runtime folder or configure OH2 in any way except for adding the /addons folder with my binding.

We have hardware(our thing) that detects nearby devices. We want to notify ESH about these devices when they come or leave.
Re: Exporting a Binding with custom Event to OpenHAB2. [message #1707252 is a reply to message #1707247] Thu, 03 September 2015 10:11 Go to previous messageGo to next message
Tonis Tiganik is currently offline Tonis TiganikFriend
Messages: 7
Registered: August 2015
Junior Member
I imported my binding and ran the OH2 runtime with OH2 Eclipse IDE, and then it works, just like with ESH.
Re: Exporting a Binding with custom Event to OpenHAB2. [message #1707281 is a reply to message #1707252] Thu, 03 September 2015 13:03 Go to previous messageGo to next message
Dennis Nobel is currently offline Dennis NobelFriend
Messages: 166
Registered: September 2014
Senior Member
Quote:
I use openhab-2.0.0.alpha2-runtime from https://github.com/openhab/openhab2/releases/tag/2.0.0-alpha2.


Yes that it explains it. The alpha2 is too old. The eventing concept was refactored and merged after the release of alpha2. Please always use the latest development branch of openHAB2, at least if you use the latest ESH changes.
Re: Exporting a Binding with custom Event to OpenHAB2. [message #1707285 is a reply to message #1707281] Thu, 03 September 2015 13:19 Go to previous message
Tonis Tiganik is currently offline Tonis TiganikFriend
Messages: 7
Registered: August 2015
Junior Member
Thanks, got it working now!
Previous Topic:Introducing New Event Types
Next Topic:Remove Quartz in favour of ScheduledExecutorService
Goto Forum:
  


Current Time: Fri Apr 26 06:45:59 GMT 2024

Powered by FUDForum. Page generated in 0.03056 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top