Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Service does not start(OSGI Bundle with declarative Service does not start)
Service does not start [message #523179] Thu, 25 March 2010 12:57 Go to next message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Hi

Maybe somebody can help me:

I have written three bundles:

1. ch.eugster.colibri.persistence.server
2. ch.eugster.colibri.persistence.server.postgresql
3. test.ch.eugster.colibri.persistence.server

where

1 is the Service (Interface: name=ServerService)
2. the component Implementation of the Service (as a Declarative Service)
3. Test Bundle to see what happens

When I start the configuration with Equinox in Eclipse 3.5.2 on Windows all three bundles are loaded

on ss on the commandline all bundled are shown active:

osgi> ss server

Framework is launched.

id State Bundle
87 ACTIVE ch.eugster.colibri.persistence.server_1.0.0.v20100325
88 ACTIVE test.ch.eugster.colibri.persistence.server_1.0.0.v20100324
91 ACTIVE ch.eugster.colibri.persistence.server.postgresql_1.0.0.v2010 0325

with services (objectClass=*Server*) the service is shown up on the commandline

osgi> services (objectClass=*Server*)
{ch.eugster.colibri.persistence.server.service.ServerService }={component.name=ch.eugster.colibri.persistence.server.post gresql, component.id=3, service.id=52}
Registered by bundle: ch.eugster.colibri.persistence.server.postgresql_1.0.0.v2010 0325 [91]
No bundles using service.

So Bundle 2 seemes to be activated but neither the bind nor the activate Method of the implementation Class are called.

What's going wrong?

Manifest of Implementation Bundle

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Postgresql Server
Bundle-SymbolicName: ch.eugster.colibri.persistence.server.postgresql
Bundle-Version: 1.0.0.v20100325
Bundle-Vendor: Christian Eugster
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: ch.eugster.colibri.persistence.server.model,
ch.eugster.colibri.persistence.server.service,
ch.eugster.log.service,
org.osgi.framework;version="1.3.0",
org.osgi.service.component;version="1.1.0"
Require-Bundle: javax.persistence;bundle-version="2.0.0",
org.eclipse.persistence.antlr;bundle-version="2.0.1",
org.eclipse.persistence.asm;bundle-version="2.0.1",
org.eclipse.persistence.core;bundle-version="2.0.1",
org.eclipse.persistence.jpa;bundle-version="2.0.1",
org.eclipse.osgi.services;bundle-version="3.2.0"
Bundle-ClassPath: lib/postgresql-8.4-701.jdbc4.jar
Service-Component: OSGI-INF/service-component.xml

service-component.xlm of Implementation Bundle

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="ch.eugster.colibri.persistence.server.postgresql">
<implementation class=" ch.eugster.colibri.persistence.server.postgresql.PostgresqlS erviceImpl "/>
<service>
<provide interface="ch.eugster.colibri.persistence.server.service.ServerService "/>
</service>
<reference bind="setPersistenceProvider" cardinality="1..1" interface="javax.persistence.spi.PersistenceProvider" name="persistenceProvider" policy="static" unbind="unsetPersistenceProvider"/>
<reference bind="setLogFileWriter" cardinality="1..1" interface="ch.eugster.log.service.LogFileWriter" name="logFileWriter" policy="static" unbind="unsetLogFileWriter"/>
</scr:component>


Implementation Class

package ch.eugster.colibri.persistence.server.postgresql;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.spi.PersistenceProvider;

import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.osgi.service.component.ComponentContext;
import org.postgresql.Driver;

import ch.eugster.colibri.persistence.server.service.ServerService;
import ch.eugster.log.service.LogFileWriter;

public class PostgresqlServiceImpl implements ServerService
{
private EntityManager entityManager;

private LogFileWriter logFileWriter;

private org.eclipse.persistence.jpa.osgi.PersistenceProvider persistenceProvider;

public PostgresqlServiceImpl()
{

}

public EntityManager getEntityManager()
{
return this.entityManager;
}

protected void activate(final ComponentContext componentContext)
{
final Map<String, Object> properties = this.getProperties();
this.persistenceProvider.createEntityManagerFactory("ch.eugster.colibri.persistence.cache ", properties);
final EntityManagerFactory factory = this.persistenceProvider.createEntityManagerFactory(
"ch.eugster.colibri.persistence.cache", properties);
this.entityManager = factory.createEntityManager();
if (this.logFileWriter != null)
{
final String driver = properties.get(PersistenceUnitProperties.JDBC_DRIVER).toStri ng();
final String url = properties.get(PersistenceUnitProperties.JDBC_URL).toString( );
final String username = properties.get(PersistenceUnitProperties.JDBC_USER).toString ();
final String password = properties.get(PersistenceUnitProperties.JDBC_PASSWORD).toSt ring();
this.logFileWriter.println("Server Manager aktiviert (Treiber: " + driver + ", URL: " + url
+ ", Benutzername: " + username + ", Passwort: " + password + ")");
}
}

protected void deactivate(final ComponentContext componentContext)
{
this.entityManager.close();
this.logFileWriter.println("Datenbankverbindung Postgresql deaktiviert.");
}

protected void setLogFileWriter(final LogFileWriter logFileWriter)
{
this.logFileWriter = logFileWriter;
}

protected void setPersistenceProvider(final PersistenceProvider persistenceProvider)
{
this.persistenceProvider = (org.eclipse.persistence.jpa.osgi.PersistenceProvider) persistenceProvider;
}

protected void unsetLogFileWriter(final LogFileWriter logFileWriter)
{
this.logFileWriter = null;
}

protected void unsetPersistenceProvider(final PersistenceProvider persistenceProvider)
{
this.persistenceProvider = null;
}

private Map<String, Object> getProperties()
{
final Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PersistenceUnitProperties.JDBC_DRIVER, Driver.class.getName());
properties.put(PersistenceUnitProperties.JDBC_URL, "jdbc:postgresql:colibri");
properties.put(PersistenceUnitProperties.JDBC_USER, "colibri");
properties.put(PersistenceUnitProperties.JDBC_PASSWORD, "colibri");
properties.put(PersistenceUnitProperties.CLASSLOADER, this.getClass().getClassLoader());

properties.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.CREATE_ONLY);
properties
.put(PersistenceUnitProperties.DDL_GENERATION_MODE, PersistenceUnitProperties.DDL_DATABASE_GENERATION);

return properties;
}
}



Re: Service does not start [message #523220 is a reply to message #523179] Thu, 25 March 2010 15:08 Go to previous messageGo to next message
Oliver Vesper is currently offline Oliver VesperFriend
Messages: 42
Registered: July 2009
Member
> osgi> services (objectClass=*Server*)
> {ch.eugster.colibri.persistence.server.service.ServerService
> }={component.name=ch.eugster.colibri.persistence.server.post gresql,
> component.id=3, service.id=52}
> Registered by bundle:
> ch.eugster.colibri.persistence.server.postgresql_1.0.0.v2010 0325 [91]
> No bundles using service.
>
> So Bundle 2 seemes to be activated but neither the bind nor the
> activate Method of the implementation Class are called.
>
> What's going wrong?

Your service's dependencies are satisfied as it shows up as a registered
service. A possible explanation for the situation you're facing is that
there is nobody using your service (as the services command already
printed out). You did not configure your component to be activated
immediately (which can be achieved by adding immediate="true" to your
component definition) and if nobody wants to use your service it will
not be activated before.

HTH,
Oliver
Re: Service does not start [message #523405 is a reply to message #523179] Fri, 26 March 2010 10:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kai.edinger.drexler-software.de

Am 25.03.2010 13:57, schrieb Christian Eugster:
> Hi
> Maybe somebody can help me:
> I have written three bundles:
>
> 1. ch.eugster.colibri.persistence.server
> 2. ch.eugster.colibri.persistence.server.postgresql
> 3. test.ch.eugster.colibri.persistence.server
> where
>
> 1 is the Service (Interface: name=ServerService)
> 2. the component Implementation of the Service (as a Declarative Service)
> 3. Test Bundle to see what happens
>
> When I start the configuration with Equinox in Eclipse 3.5.2 on Windows
> all three bundles are loaded
>
> on ss on the commandline all bundled are shown active:
>
> osgi> ss server
>
> Framework is launched.
>
> id State Bundle
> 87 ACTIVE ch.eugster.colibri.persistence.server_1.0.0.v20100325
> 88 ACTIVE test.ch.eugster.colibri.persistence.server_1.0.0.v20100324
> 91 ACTIVE ch.eugster.colibri.persistence.server.postgresql_1.0.0.v2010 0325
>
> with services (objectClass=*Server*) the service is shown up on the
> commandline
> osgi> services (objectClass=*Server*)
> {ch.eugster.colibri.persistence.server.service.ServerService
> }={component.name=ch.eugster.colibri.persistence.server.post gresql,
> component.id=3, service.id=52}
> Registered by bundle:
> ch.eugster.colibri.persistence.server.postgresql_1.0.0.v2010 0325 [91]
> No bundles using service.
>
> So Bundle 2 seemes to be activated but neither the bind nor the activate
> Method of the implementation Class are called.
>
> What's going wrong?
>

Another tipp: Is the ds-Plugin activted? Or use the ls command to see
which service component are exists and statified.

Kai
Re: Service does not start [message #523581 is a reply to message #523179] Fri, 26 March 2010 22:27 Go to previous messageGo to next message
Jens Muehlenhoff is currently offline Jens MuehlenhoffFriend
Messages: 20
Registered: July 2009
Junior Member
Christian Eugster wrote:
> id State Bundle
> 87 ACTIVE ch.eugster.colibri.persistence.server_1.0.0.v20100325
> 88 ACTIVE
> test.ch.eugster.colibri.persistence.server_1.0.0.v20100324
> 91 ACTIVE
> ch.eugster.colibri.persistence.server.postgresql_1.0.0.v2010 0325
>
> with services (objectClass=*Server*) the service is shown up on the
> commandline
> osgi> services (objectClass=*Server*)
> {ch.eugster.colibri.persistence.server.service.ServerService
> }={component.name=ch.eugster.colibri.persistence.server.post gresql,
> component.id=3, service.id=52}
> Registered by bundle:
> ch.eugster.colibri.persistence.server.postgresql_1.0.0.v2010 0325 [91]
> No bundles using service.

Looks like the service was correctly loaded by the framework.

You could enable more logging by adding "-consoleLog" to your starting parameters. Prehaps then
there are some more information. Next step could by surround your code (just for testin) with

try {
System.out.println("start...");
} catch(Throwable e) {
e.printStackTrace();
}

Then you can see if an exception was thrown. I had such trouble with not seen exceptions.

By the way, why are you assuming your methods aren't called by the framework?

Hope that helps.

Jens
Re: Service does not start [message #524064 is a reply to message #523179] Tue, 30 March 2010 14:12 Go to previous message
Christian Eugster is currently offline Christian EugsterFriend
Messages: 203
Registered: July 2009
Location: St. Gallen Switzerland
Senior Member
Thank you all for your hints. They were really helpfull. My own logging did not show anything but reviewing the .log in the .metadata directory often helps.
Previous Topic:SCR and Config Admin: Warning message if no config is avaliable
Next Topic:there are no categorized items
Goto Forum:
  


Current Time: Tue Apr 23 14:39:59 GMT 2024

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

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

Back to the top