Skip to content

Commit

Permalink
Added Example with manual Service registration
Browse files Browse the repository at this point in the history
Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>
  • Loading branch information
juergen-albert committed Jan 15, 2024
1 parent 36587b8 commit 1a7a31e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion org.gecko.playground.ds.simple/bnd.bnd
@@ -1,2 +1,3 @@
-buildpath: \
org.gecko.playground;version=project
org.gecko.playground;version=project,\
org.osgi.framework
Expand Up @@ -10,6 +10,10 @@ public ConsoleLog () {
System.out.println("ConsoleLog created");
}

public ConsoleLog (String source) {
System.out.println("ConsoleLog created by " + source);
}

@Override
public void logMessage(String message) {
System.out.println("LOG : " + message);
Expand Down
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2012 - 2024 Data In Motion and others.
* All rights reserved.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Data In Motion - initial API and implementation
*/
package org.gecko.playground.ds.simple.activator;

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

import org.gecko.playground.ds.simple.ConsoleLog;
import org.gecko.playground.log.Log;
import org.osgi.annotation.bundle.Header;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;

@Header(name = "Bundle-Activator", value = "org.gecko.playground.ds.simple.activator.Activator")
public class Activator implements BundleActivator {

private ServiceRegistration<Log> registerService;

/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
System.out.println("Test");

Dictionary<String, String> props = new Hashtable<>();
props.put("some prop", "via Activator" );

ConsoleLog log = new ConsoleLog("Activator");

registerService = context.registerService(Log.class, log, props);
}

/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext context) throws Exception {
registerService.unregister();
}

}

0 comments on commit 1a7a31e

Please sign in to comment.