Examples of ServiceReference


Examples of org.osgi.framework.ServiceReference

  public void start(BundleContext bc) throws Exception {
    System.out.println(bc.getBundle().getHeaders()
                       .get(Constants.BUNDLE_NAME) +
                       " starting...");
    Activator.bc = bc;
    ServiceReference reference =
      bc.getServiceReference(DateService.class.getName());

    if(reference != null) {
      DateService service = (DateService)bc.getService(reference);
      System.out.println("Using DateService: formatting date: " +
View Full Code Here

Examples of org.osgi.framework.ServiceReference

      try {
        Vector vector = new Vector();
        for(Iterator it = activator.exportedServices.keySet().iterator();
            it.hasNext();)
          {
            ServiceReference sr         = (ServiceReference)it.next();
            String           name       = (String)sr.getProperty(KSoapAdmin.SOAP_SERVICE_NAME);
            vector.add(name);
          }

        return vector;
      } catch (RuntimeException e) {
View Full Code Here

Examples of org.osgi.framework.ServiceReference

    }
  }

  private void log(TrackedEventHandler handler, String txt)
  {
    ServiceReference sr = handler.getServiceReference();
    Activator.log.error(txt + "  Service.id="
        + sr.getProperty(Constants.SERVICE_ID) + "  bundle.id="
        + sr.getBundle().getBundleId() + "  bundle.name="
        + sr.getBundle().getSymbolicName() + "  topic=" + event.getTopic(), sr);
  }
View Full Code Here

Examples of org.osgi.framework.ServiceReference

    public int cmdShow(final Dictionary opts, final Reader in,
            final PrintWriter out, final Session session) {
        Integer res = (Integer) AccessController
                .doPrivileged(new PrivilegedAction() {
                    public Object run() {
                        ServiceReference sr = bc.getServiceReference(LOGREADER);
                        if (sr == null) {
                            out.println("Unable to get a LogReaderService");
                            return new Integer(1);
                        }
                        LogReaderService lr = (LogReaderService) bc
                                .getService(sr);
                        if (lr == null) {
                            out.println("Unable to get a LogReaderService");
                            return new Integer(1);
                        }

                        ArrayList bv = null;
                        String[] selection = (String[]) opts.get("bundle");
                        if (selection != null) {
                            Bundle[] b = bc.getBundles();
                            Util.selectBundles(b, selection);
                            bv = new ArrayList();
                            for (int i = 0; i < b.length; i++) {
                                if (b[i] != null) {
                                    bv.add(b[i]);
                                }
                            }
                        }

                        boolean fflag = opts.get("-f") != null;

                        String lflag = (String) opts.get("-l");
                        int level;
                        if (lflag != null) {
                            if (lflag.equalsIgnoreCase("error")) {
                                level = LogService.LOG_ERROR;
                            } else if (lflag.equalsIgnoreCase("warning")) {
                                level = LogService.LOG_WARNING;
                            } else if (lflag.equalsIgnoreCase("info")) {
                                level = LogService.LOG_INFO;
                            } else if (lflag.equalsIgnoreCase("debug")) {
                                level = LogService.LOG_DEBUG;
                            } else {
                                out.println("Unknown level: " + lflag);
                                return new Integer(1);
                            }
                        } else {
                            level = LogService.LOG_DEBUG;
                        }

                        String hflag = (String) opts.get("-h");
                        long startTime = 0;
                        if (hflag != null) {
                            try {
                                startTime = System.currentTimeMillis()
                                        - (long) (60 * 60 * 1000 * (new Double(
                                                hflag)).doubleValue());
                            } catch (NumberFormatException e) {
                                out
                                        .println("Illegal number of hours: "
                                                + hflag);
                                return new Integer(1);
                            }
                        }

                        String nflag = (String) opts.get("-n");
                        int count = Integer.MAX_VALUE;
                        if (nflag != null) {
                            try {
                                count = Integer.parseInt(nflag);
                            } catch (NumberFormatException e) {
                                out
                                        .println("Illegal number as count: "
                                                + nflag);
                                return new Integer(1);
                            }
                        }

                        Enumeration e = lr.getLog();
                        Vector lv = new Vector();
                        boolean rflag = opts.get("-r") == null;
                        while (e.hasMoreElements()) {
                            LogEntry le = (LogEntry) e.nextElement();
                            Bundle b = le.getBundle();
                            if (b == null && fflag || bv == null && !fflag
                                    || bv != null && bv.contains(b)) {
                                if (count-- <= 0) {
                                    break;
                                }
                                if (le.getLevel() > level) {
                                    continue;
                                }
                                if (le.getTime() < startTime) {
                                    break;
                                }
                                if (rflag) {
                                    lv.insertElementAt(le, 0);
                                } else {
                                    lv.addElement(le);
                                }
                            }
                        }

                        StringBuffer sb = new StringBuffer();
                        SimpleDateFormat tf = new SimpleDateFormat(
                                "MMM dd HH:mm:ss ");

                        for (e = lv.elements(); e.hasMoreElements();) {
                            LogEntry le = (LogEntry) e.nextElement();
                            sb.setLength(0);
                            sb.append(tf.format(new Date(le.getTime())));
                            pad(sb, 16);
                            switch (le.getLevel()) {
                            case LogService.LOG_INFO:
                                sb.append("INFO");
                                break;
                            case LogService.LOG_DEBUG:
                                sb.append("DEBUG");
                                break;
                            case LogService.LOG_WARNING:
                                sb.append("WARNING");
                                break;
                            case LogService.LOG_ERROR:
                                sb.append("ERROR");
                                break;
                            default:
                                sb.append("UNKNOWN");
                                break;
                            }
                            pad(sb, 23);
                            Bundle b = le.getBundle();
                            if (b != null) {
                                sb.append(" #" + b.getBundleId());
                                pad(sb, 28);
                                sb.append(Util.shortName(b));
                            } else {
                                sb.append(" FRAMEWORK");
                            }
                            pad(sb, 42);
                            sb.append(" - ");
                            sb.append(le.getMessage());
                            final ServiceReference leSr
                              = le.getServiceReference();
                            if (leSr != null) {
                              sb.append(", Service#");
                              sb.append(leSr.getProperty(Constants.SERVICE_ID));
                              sb.append(": ");
                              sb.append(Util.showServiceClasses(leSr));
                            }
                            out.println(sb.toString());
                            if (le.getException() != null
View Full Code Here

Examples of org.osgi.framework.ServiceReference

    private void insertPluginReference(ServiceReference serviceReference,
            int ranking, Vector pluginsVector) {
        int i;
        for (i = 0; i < pluginsVector.size(); ++i) {
            ServiceReference nextReference = (ServiceReference) pluginsVector
                    .elementAt(i);
            Long serviceId = (Long) nextReference.getProperty(SERVICE_ID);
            Integer rankingOfNextReference = (Integer) rankings.get(serviceId);
            if (ranking < rankingOfNextReference.intValue()) {
                break;
            }
        }
View Full Code Here

Examples of org.osgi.framework.ServiceReference

        }
    }

    private void removePluginReference(Object serviceId, Vector pluginsVector) {
        for (int i = 0; i < pluginsVector.size(); ++i) {
            ServiceReference serviceReference = (ServiceReference) pluginsVector
                    .elementAt(i);
            Long currentId = (Long) serviceReference.getProperty(SERVICE_ID);
            if (currentId.equals(serviceId)) {
                pluginsVector.removeElementAt(i);
                return;
            }
        }
View Full Code Here

Examples of org.osgi.framework.ServiceReference

            boolean allowModification) {
        String pid = (String)dictionary.get(SERVICE_PID);
        ConfigurationDictionary currentDictionary = dictionary;
        Enumeration e = plugins.elements();
        while (e.hasMoreElements()) {
            ServiceReference pluginReference = (ServiceReference) e
                    .nextElement();

            // Only call the plugin if no cm.target is specified or if it
            // matches the pid of the target service
            String cmTarget = (String) pluginReference.getProperty(CM_TARGET);
            if (cmTarget == null || cmTarget.equals(pid)) {
                ConfigurationPlugin plugin = (ConfigurationPlugin) Activator.bc
                        .getService(pluginReference);
                if (plugin == null) {
                    continue;
View Full Code Here

Examples of org.osgi.framework.ServiceReference

    this.bc = bc;
  }

  public void prepare() {
    try {
      ServiceReference ref = bc.getServiceReference(Control.class.getName());
      bundle = ref.getBundle();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

Examples of org.osgi.framework.ServiceReference

  Test7(BundleContext bc) {
    this.bc = bc;
  }
 
  public void prepare() {
    ServiceReference ref = bc.getServiceReference(Control.class.getName());
    bundle = ref.getBundle();
  }
View Full Code Here

Examples of org.osgi.framework.ServiceReference

    this.bc = bc;

    // all of these services are framework singleton internal services
    // thus, we take a shortcut and skip the service tracking

    ServiceReference sr = bc.getServiceReference(PackageAdmin.class
                                                 .getName());
    packageAdmin = null==sr ? null : (PackageAdmin) bc.getService(sr);

    sr = bc.getServiceReference(PermissionAdmin.class.getName());
    permissionAdmin = null==sr ? null : (PermissionAdmin) bc.getService(sr);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.