This looks like good content for a KB on OT :) Samisa...
On Fri, Jan 22, 2010 at 8:06 PM, Amila Suriarachchi <[email protected]> wrote: > hi, > > When implementing the LDAP carbon component I got the requirement to deploy > the LDAP carbon component before > User core component. The other requirement was that the User core component > should wait only if the LDAP component present. > > There was a similar work done by Sameera to deploy Axis2 bundle and Axis2 > modules before the carbon core. So I used the same > method but implemented it in a generic manner so that any one can use it. > > The only thing I wrote was a bundle Activator which can be extended by any > component which need others to start before it. > > public abstract class BundleCheckActivator implements BundleActivator { > > private static final Log log = > LogFactory.getLog(BundleCheckActivator.class); > > private String DEPLOY_BEFORE_PREFIX = "DeployBefore"; > > public void start(final BundleContext bundleContext) throws Exception { > > // check for the services should deploy before this if there > exists. > // if there are such services we wait for such bundles to deploy > and gets the notification > // through a service listner. > > // first check whether there are such services and they have > already deployed. > String requiredItem = null; > final List<String> pendingBundles = new ArrayList<String>(); > for (Bundle bundle : bundleContext.getBundles()) { > requiredItem = (String) > bundle.getHeaders().get(DEPLOY_BEFORE_PREFIX + getName()); > if ((requiredItem != null) && (bundle.getState() != > Bundle.ACTIVE)) { > // i.e this bundle should start before the user manager but > yet has not started > pendingBundles.add(requiredItem); > } > } > > if (pendingBundles.isEmpty()) { > startDeploy(bundleContext); > } else { > BundleListener bundleListener = new BundleListener() { > public void bundleChanged(BundleEvent bundleEvent) { > synchronized (pendingBundles) { > if (bundleEvent.getType() == BundleEvent.STARTED) { > String requiredItem = > (String) > bundleEvent.getBundle().getHeaders().get(DEPLOY_BEFORE_PREFIX + getName()); > pendingBundles.remove(requiredItem); > if (pendingBundles.isEmpty()) { > // now start the deployment > bundleContext.removeBundleListener(this); > try { > startDeploy(bundleContext); > } catch (Exception e) { > log.error("Can not start the bundle ", > e); > } > } > } > } > } > }; > bundleContext.addBundleListener(bundleListener); > } > } > > public abstract void startDeploy(BundleContext bundleContext) throws > Exception; > > public abstract String getName(); > > } > > here in the actual Activator code can implement the startBundle method and > should give a name for that bundle. > > Then any module which should before this bundle should have a header with > name -- DeployBefore + bundleName > > eg. For ldap component this can be done by adding following entry to > pom.xml > <DeployBeforeUserCore>directoryServer</DeployBeforeUserCore> > > thanks, > Amila. > > _______________________________________________ > Carbon-dev mailing list > [email protected] > https://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev > > -- Samisa Abeysinghe Director, Engineering - WSO2 Inc. http://www.wso2.com/ - "lean . enterprise . middleware"
_______________________________________________ Carbon-dev mailing list [email protected] https://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
