Service does not start [message #523179] |
Thu, 25 March 2010 12:57 |
Christian Eugster 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 #523405 is a reply to message #523179] |
Fri, 26 March 2010 10:29 |
Eclipse User |
|
|
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03193 seconds