Ask is moving to Stack Overflow and Serverfault.com! Please use the "opendaylight" tag on either of these sites. This site is now in Read-Only mode

0

How does a bundle start ?start(),Activator,ComponentActivatorAbstractBase,BundleActivator

asked 2015-08-26 07:57:30 -0800

Eric gravatar image

updated 2015-08-26 07:59:36 -0800

Hello everyone, I have common question that almost all of the new developers may be puzzling. How does a bundle start ?If you know OSGi,It is may be easier,but the class ComponentActivatorAbstractBase stops me from go forwarding.In the class,there is method,named start(),implementions for BundleActivator's start().In the start() method of ComponentActivatorAbstractBase, as below:

   public void start(BundleContext context) {
    try {
        this.dm = new DependencyManager(context);

        logger.trace("Activating");

        // Now create Global components
        Object[] imps = **getGlobalImplementations()**;
        if (imps != null) {
            for (int i = 0; i < imps.length; i++) {
                Object key = imps[i];
                Component c = this.dbGlobalInstances.get(key);
                if (c == null) {
                    try {
                        c = this.dm.createComponent();
                        c.addStateListener(new ListenerComponentStates());
                        // Now let the derived class to configure the
                        // dependencies it wants
                        configureGlobalInstance(c, imps[i]);
                        // Set the implementation so the component
                        // can manage its lifesycle
                        if (c.getService() == null) {
                            logger.trace("Setting implementation to: {}",
                                    imps[i]);
                            c.setImplementation(imps[i]);
                        }

                        // Now add the component to the dependency
                        // Manager which will immediately start
                        // tracking the dependencies
                        this.dm.add(c);
                    } catch (Exception nex) {
                        logger.error("During creation of a Global "
                                + "instance caught exception: " + nex
                                + "\nStacktrace:"
                                + stackToString(nex.getStackTrace()));
                    }

                    //Now lets keep track in our shadow database of the
                    //association
                    if (c != null)
                        this.dbGlobalInstances.put(key, c);
                } else {
                    logger.error("I have been asked again to create an "
                            + "instance " + " Global for object: "
                            + imps[i] + "when i already have it!!");
                }
            }
        }

The bold part getGlobalImplementations() will return a null value,whatever in the class ComponentActivatorAbstractBase or in the class Activator,as bellow:

protected Object[] getGlobalImplementations() {
    return null;
}

How should I understand this? But in fact we usual override getImplementations(),

public Object[] getImplementations() {
    Object[] res = { LoadBalancerService.class };//***Here will return a non-null Object array***
    return res;
}

There is another question,in the start(),there is an invoking of init(),the init() method is required to be overriden by the derived class for customization,but in the Activator,this is not happen,however,it occurs in the main class(refer to the LoadBalanceService of sal),it's really right?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-08-28 04:02:52 -0800

I would suggest not to use a bundle Activator and the legacy DependencyManager - there are easier ways to create singletons and do dependency injection. You can use blueprint or declarative services which are OSGi standard specs or the ODL-proprietary config system.

edit flag offensive delete publish link more

Comments

OK,when I begin to write the app in the controller,it is the version of Hydrogen,so I check the codes of the controller.In the examples of controller,they almost use this way to complete a bundle.But its logic make me puzzled.

Eric ( 2015-08-28 23:39:55 -0800 )edit
Login/Signup to Answer

Stats

Asked: 2015-08-26 07:57:30 -0800

Seen: 193 times

Last updated: Aug 28 '15