Package org.osgi.framework

Examples of org.osgi.framework.ServiceReference


     * Unschedules the execution of the Runnable Service of the {@link ServiceEvent}.
     *
     * @param event
     */
    protected void unscheduleRunnableService(ServiceEvent event) {
        ServiceReference reference = event.getServiceReference();
        String id = (String) reference.getProperty(KarafTimerTask.ID_PROPERTY);
        scheduler.unschedule(id);
    }
View Full Code Here


                Field contextField = function.getClass().getDeclaredField("context");
                Field referenceField = function.getClass().getDeclaredField("reference");
                contextField.setAccessible(true);
                referenceField.setAccessible(true);
                BundleContext context = (BundleContext) contextField.get(function);
                ServiceReference reference = (ServiceReference) referenceField.get(function);
                Object target = context.getService(reference);
                try {
                    if (target instanceof Function) {
                        function = (Function) target;
                    }
View Full Code Here

     * @param bundleContext
     * @param bundle
     * @return true if the bundle has start level minor than 50
     */
    public static boolean isASystemBundle(BundleContext bundleContext, Bundle bundle) {
        ServiceReference ref = bundleContext.getServiceReference(StartLevel.class.getName());
        if (ref != null) {
            StartLevel sl = (StartLevel) bundleContext.getService(ref);
            if (sl != null) {
                int level = sl.getBundleStartLevel(bundle);
                int sbsl = 49;
View Full Code Here

    public void setBundleStateListenerFactories(List<BundleStateListener.Factory> bundleStateListenerFactories) {
        this.bundleStateListenerFactories = bundleStateListenerFactories;
    }

    protected Object doExecute() throws Exception {
        ServiceReference ref = getBundleContext().getServiceReference(StartLevel.class.getName());
        StartLevel sl = null;
        if (ref != null) {
            sl = (StartLevel) getBundleContext().getService(ref);
        }
        if (sl == null) {
            System.out.println("StartLevel service is unavailable.");
        }

        ServiceReference pkgref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
        PackageAdmin admin = null;
        if (pkgref != null) {
            admin = (PackageAdmin) getBundleContext().getService(pkgref);
            if (admin == null) {
                System.out.println("PackageAdmin service is unavailable.");
View Full Code Here

@Command(scope = "osgi", name = "resolve", description = "Resolve bundle(s).")
public class ResolveBundle extends BundlesCommandOptional {

    protected void doExecute(List<Bundle> bundles) throws Exception {
        // Get package admin service.
        ServiceReference ref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
        if (ref == null) {
            System.out.println("PackageAdmin service is unavailable.");
            return;
        }
        try {
View Full Code Here

@Command(scope = "osgi", name = "refresh", description = "Refresh a bundle.")
public class RefreshBundle extends BundlesCommandOptional {

    protected void doExecute(List<Bundle> bundles) throws Exception {
        // Get package admin service.
        ServiceReference ref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
        if (ref == null) {
            System.out.println("PackageAdmin service is unavailable.");
            return;
        }
        try {
View Full Code Here

    @Argument(index = 1, name = "startLevel", description = "The bundles new start level", required = false, multiValued = false)
    Integer level;

    protected void doExecute(Bundle bundle) throws Exception {
        // Get package admin service.
        ServiceReference ref = getBundleContext().getServiceReference(StartLevel.class.getName());
        if (ref == null) {
            System.out.println("StartLevel service is unavailable.");
            return;
        }
        StartLevel sl = getService(StartLevel.class, ref);
View Full Code Here

        command = new EditCommand();
       
        context = EasyMock.createMock(BundleContext.class);
        command.setBundleContext(context);
       
        ServiceReference reference = createMock(ServiceReference.class);
        expect(context.getServiceReference(ConfigurationAdmin.class.getName())).andReturn(reference);
       
        admin = createMock(ConfigurationAdmin.class);
        expect(context.getService(reference)).andReturn(admin);
        expect(context.ungetService(reference)).andReturn(Boolean.TRUE);
View Full Code Here

    }

    private <T> List<T> getBeansFromOsgiService(Class<T> type) {
        List<T> list = new ArrayList<T>();
        try {
            ServiceReference refs[] = context.getServiceReferences(type.getName(), null);
            if (refs != null) {
                for (ServiceReference r : refs) {
                    if (type == ClassLoader.class
                        && checkCompatibleLocators
                        && !PropertyUtils.isTrue(r.getProperty(COMPATIBLE_LOCATOR_PROP))) {
View Full Code Here

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public class ServiceUtils {
    public static final <R, S, E extends Throwable> R usingService(BundleContext context, Class<S> clazz, ServiceOperation<R,S,E> operation) throws E {
        ServiceReference reference = context.getServiceReference(clazz.getName());
        if (reference != null) {
            @SuppressWarnings("unchecked")
            S service = (S) context.getService(reference);
            if (service != null) {
                try {
View Full Code Here

TOP

Related Classes of org.osgi.framework.ServiceReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.