diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /jdisc_core_test/test_bundles/my-bundle-activator |
Publish
Diffstat (limited to 'jdisc_core_test/test_bundles/my-bundle-activator')
4 files changed, 86 insertions, 0 deletions
diff --git a/jdisc_core_test/test_bundles/my-bundle-activator/.gitignore b/jdisc_core_test/test_bundles/my-bundle-activator/.gitignore new file mode 100644 index 00000000000..3cc25b51fc4 --- /dev/null +++ b/jdisc_core_test/test_bundles/my-bundle-activator/.gitignore @@ -0,0 +1,2 @@ +/pom.xml.build +/target diff --git a/jdisc_core_test/test_bundles/my-bundle-activator/pom.xml b/jdisc_core_test/test_bundles/my-bundle-activator/pom.xml new file mode 100644 index 00000000000..e9c3ea85b40 --- /dev/null +++ b/jdisc_core_test/test_bundles/my-bundle-activator/pom.xml @@ -0,0 +1,36 @@ +<?xml version="1.0"?> +<!-- Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.yahoo.vespa.jdisc_core</groupId> + <artifactId>test_bundles</artifactId> + <version>6-SNAPSHOT</version> + </parent> + <artifactId>my-bundle-activator</artifactId> + <version>6-SNAPSHOT</version> + <packaging>bundle</packaging> + <name>${project.artifactId}</name> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-Activator> + com.yahoo.jdisc.bundle.MyBundleActivator + </Bundle-Activator> + <Export-Package> + com.yahoo.jdisc.bundle + </Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/jdisc_core_test/test_bundles/my-bundle-activator/src/main/java/com/yahoo/jdisc/bundle/MyBundleActivator.java b/jdisc_core_test/test_bundles/my-bundle-activator/src/main/java/com/yahoo/jdisc/bundle/MyBundleActivator.java new file mode 100644 index 00000000000..a7e4984a367 --- /dev/null +++ b/jdisc_core_test/test_bundles/my-bundle-activator/src/main/java/com/yahoo/jdisc/bundle/MyBundleActivator.java @@ -0,0 +1,39 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.jdisc.bundle; + +import com.yahoo.jdisc.service.CurrentContainer; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; + +/** + * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + */ +public class MyBundleActivator implements BundleActivator { + + private ServiceRegistration registration; + + @Override + public void start(BundleContext ctx) throws Exception { + ServiceReference seviceRef = ctx.getServiceReference(CurrentContainer.class.getName()); + if (seviceRef == null) { + throw new IllegalStateException("Service reference '" + CurrentContainer.class.getName() + "' not found."); + } + Object service = ctx.getService(seviceRef); + if (service == null) { + throw new IllegalStateException("Service '" + CurrentContainer.class.getName() + "' not found."); + } + if (!(service instanceof CurrentContainer)) { + throw new IllegalStateException("Expected " + CurrentContainer.class + ", got " + service.getClass() + "."); + } + registration = ctx.registerService(MyService.class.getName(), new MyService(), null); + } + + @Override + public void stop(BundleContext ctx) throws Exception { + if (registration != null) { + registration.unregister(); + } + } +} diff --git a/jdisc_core_test/test_bundles/my-bundle-activator/src/main/java/com/yahoo/jdisc/bundle/MyService.java b/jdisc_core_test/test_bundles/my-bundle-activator/src/main/java/com/yahoo/jdisc/bundle/MyService.java new file mode 100644 index 00000000000..b6fc6877a02 --- /dev/null +++ b/jdisc_core_test/test_bundles/my-bundle-activator/src/main/java/com/yahoo/jdisc/bundle/MyService.java @@ -0,0 +1,9 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.jdisc.bundle; + +/** + * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a> + */ +public class MyService { + +} |