Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [virgo-dev] Configuration of bundles

I tried to implement this in a simple mode. But it does not work, more information provided below.

Below is the complete code.

===START CODE===

package my.package

import java.util.Dictionary;
import java.util.Hashtable;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Activator implements BundleActivator, ManagedService {

  private static Logger log = LoggerFactory.getLogger(Activator.class);

  private static String PID = "pjotr.configtest";

  private ServiceRegistration registration;

  @Override
  public void start(BundleContext context) throws Exception {
    log.info("LOGTRACKER starting bundle");
    Dictionary props = new Hashtable();
    props.put(Constants.SERVICE_PID, PID);
    registration = context.registerService(ManagedService.class.getName(), this, props);
  }

  @Override
  public void stop(BundleContext context) throws Exception {
    registration.unregister();
    log.info("LOGTRACKER Bundle stopped!");
  }

  @Override
  public void updated(Dictionary config) throws ConfigurationException {
    log.info("LOGTRACKER Update config: {}", config);
  }
}

=== END CODE===


This is the log when I first install and start the bundle (LOGTRACKER Update Config: null), so the update gives the expected result as there is no configuration deployed yet. Then at 22:00:10 I put the pjotr.configtest.properties into the pickup directory, and it is triggered and installed. But there is some error at 22:20:10.647 (*ERROR* Cannot use configuration pjotr.configtest for [org.osgi.service.cm.M
anagedService, id=146, bundle=36]: Configuration bound to bundle file:lib/kernel/org.eclipse.virgo.kernel.deployer-2.1.0.RC1-incubation.jar). 

No "LOGTRACKER Update Config" came as I would have expected, what is the error here? According to documentation I have read, and also the post by Dmitry, this should work. But it is not.


=== START LOG.LOG ===

[2010-11-02 22:18:48.830]  TCP Connection(5)-127.0.0.1 my.package.Activator                         LOGTRACKER starting bundle 
[2010-11-02 22:18:48.832] Configuration Updater        cmy.package.Activator                         LOGTRACKER Update config: null [2010-11-02 22:18:48.833]  TCP Connection(5)-127.0.0.1 org.eclipse.virgo.kernel.core.internal.BundleStartTracker         Non-Spring DM powered bundle 'my.package_0.0.1 [64]' ha
s started. Driving signals '[org.eclipse.virgo.kernel.install.artifact.internal.AbstractInstallArtifact$StateMonitorSignal@23dae5f1]'. [2010-11-02 22:18:48.833] start-signalling-1           org.eclipse.virgo.kernel.core.internal.BundleStartTracker         Driving signal 'org.eclipse.virgo.kernel.install.artifact.internal.AbstractI
nstallArtifact$StateMonitorSignal@23dae5f1' [2010-11-02 22:18:48.833] start-signalling-1           o.e.v.k.i.artifact.internal.bundle.BundleThreadContextManager     Thread context class loader 'sun.misc.Launcher$AppClassLoader@77cde100' push
ed and set to 'KernelBundleClassLoader: [bundle=my.package_0.0.1]' [2010-11-02 22:18:48.864] start-signalling-1           org.eclipse.virgo.medic.eventlog.default                         DE0005I Started bundle 'my.package' version '0.0.1'. 
[2010-11-02 22:18:48.864] start-signalling-1           o.e.v.k.i.artifact.internal.bundle.BundleThreadContextManager     Thread context class loader 'KernelBundleClassLoader: [bundle=my.package_0.0.1]' popped and set to 'sun.misc.Launcher$AppClassLoader@77cde100' 
[2010-11-02 22:18:48.868]  TCP Connection(5)-127.0.0.1 o.e.v.k.i.artifact.internal.bundle.BundleThreadContextManager     Thread context class loader 'KernelBundleClassLoader: [bundle=my.package_0.0.1]' popped and set to 'KernelBundleClassLoader: [bundle=my.package_0.0.1]' 
[2010-11-02 22:18:48.868]  TCP Connection(5)-127.0.0.1 o.e.v.k.i.artifact.internal.bundle.BundleThreadContextManager     Thread context class loader 'KernelBundleClassLoader: [bundle=my.package_0.0.1]' popped and set to 'sun.misc.Launcher$AppClassLoader@77cde100' 
[2010-11-02 22:20:10.600] fs-watcher                   org.eclipse.virgo.medic.eventlog.default                         HD0001I Hot deployer processing 'CREATED' event for file 'pjotr.configtest.properties'. 
[2010-11-02 22:20:10.600] fs-watcher                   o.e.virgo.kernel.deployer.hot.HotDeploymentFileSystemListener     ApplicationDeploying path '/Users/pjotr/virgo/virgo-web-server-2.1.0.RC1-inc
ubation/pickup/pjotr.configtest.properties'. [2010-11-02 22:20:10.623] fs-watcher                   o.e.v.k.m.i.deployer.ModelInstallArtifactLifecycleListener        Processing installing event for configuration 'pjotr.configtest' version '0.
0.0' 
[2010-11-02 22:20:10.628] fs-watcher                   org.eclipse.virgo.medic.eventlog.default                         DE0000I Installing configuration 'pjotr.configtest' version '0.0.0'. 
[2010-11-02 22:20:10.629] fs-watcher                   o.e.virgo.kernel.userregion.internal.quasi.DependencyCalculator   Calculating missing dependencies of bundle(s) '{}' 
[2010-11-02 22:20:10.632] fs-watcher                   o.e.virgo.kernel.userregion.internal.quasi.DependencyCalculator   The dependencies of '[]' are '[]' 
[2010-11-02 22:20:10.637] fs-watcher                   org.eclipse.virgo.medic.eventlog.default                         DE0001I Installed configuration 'pjotr.configtest' version '0.0.0'. 
[2010-11-02 22:20:10.640] fs-watcher                   o.e.v.k.i.a.internal.AtomicInstallArtifactLifecycleListener       No atomic parent of configuration 'pjotr.configtest' version '0.0.0' in scop
e 'null' to propagate starting event to 
[2010-11-02 22:20:10.644] fs-watcher                   org.eclipse.virgo.medic.eventlog.default                         DE0004I Starting configuration 'pjotr.configtest' version '0.0.0'. 
[2010-11-02 22:20:10.647] Configuration Updater        System.err                                                        *ERROR* Cannot use configuration pjotr.configtest for [org.osgi.service.cm.M
anagedService, id=146, bundle=36]: Configuration bound to bundle file:lib/kernel/org.eclipse.virgo.kernel.deployer-2.1.0.RC1-incubation.jar 
[2010-11-02 22:20:10.647] Configuration Updater        o.e.v.k.m.internal.configurationadmin.ModelConfigurationListener  Processing update event for 'pjotr.configtest' 
[2010-11-02 22:20:10.651] fs-watcher                   org.eclipse.virgo.medic.eventlog.default                         DE0005I Started configuration 'pjotr.configtest' version '0.0.0'. 

=== END LOG.LOG ===





On 2 nov 2010, at 21.02, Dmitry Sklyut wrote:

> Simple answer is "Yes".
> 
> With the code sample that you provided, your config properties file must be named: "my_unique_pid.properties".
> 
> Drop that file into pickup and it will be deployed as ConfigurationAdmin configuration and your ManagedService will be updated with correct configuration.
> 
> You can also use a ConfigurationListener and postone publishing your service (not ManagedService) till configuration that you are looking for is available.
> 
> Dmitry
> 
> On Tue, Nov 2, 2010 at 2:56 PM, Peter Lauri <peter.lauri@xxxxxx> wrote:
> Hi,
> 
> I have a bundle that is providing a service that needs to be configured before it starts. As I have understood it there are two approaches, one is to use the ManagedService and one is to use the ConfigurationAdmin. However, how do this map to Virgo? If I put a properties file to "pickup" that will be deployed as a configuration artifact. Should that map directly to the ManagedService.update() call?
> 
>     Hashtable<String, String> prop = new Hashtable<String, String>();
>     prop.put(Constants.SERVICE_PID, "my_unique_pid");
>     this.managedServiceRegistration = bundleContext.registerService(ManagedService.class.getName(), this, prop);
> 
> /Peter
> 
> _______________________________________________
> virgo-dev mailing list
> virgo-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/virgo-dev
> 
> 
> _______________________________________________
> virgo-dev mailing list
> virgo-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/virgo-dev



Back to the top