Package org.osgi.service.log

Examples of org.osgi.service.log.LogService


        addRollback(new RollbackCommitAction(session));

        AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
        AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
        BundleContext context = session.getBundleContext();
        LogService log = session.getLog();

        ResourceInfoImpl[] orderedTargetResources = target.getOrderedResourceInfos();
        for (int i = orderedTargetResources.length - 1; i >= 0; i--) {
            ResourceInfoImpl resourceInfo = orderedTargetResources[i];
            String path = resourceInfo.getPath();
            if (source.getResourceInfoByPath(path) == null) {
                ServiceReference ref = target.getResourceProcessor(path);
                if (ref != null) {
                    ResourceProcessor resourceProcessor = (ResourceProcessor) context.getService(ref);
                    if (resourceProcessor != null) {
                        try {
                            if (m_commitCommand.addResourceProcessor(resourceProcessor)) {
                                resourceProcessor.begin(session);
                            }
                            resourceProcessor.dropped(path);
                        }
                        catch (Exception e) {
                            log.log(LogService.LOG_WARNING, "Not allowed to drop resource '" + path + "'", e);
                        }
                    }
                }
            }
        }
View Full Code Here


    protected void doExecute(DeploymentSessionImpl session) throws Exception {
        AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
        AbstractDeploymentPackage targetPackage = session.getTargetAbstractDeploymentPackage();
        BundleContext context = session.getBundleContext();
        LogService log = session.getLog();

        Map expectedBundles = new HashMap();
        AbstractInfo[] bundleInfos = (AbstractInfo[]) source.getBundleInfos();
        for (int i = 0; i < bundleInfos.length; i++) {
            AbstractInfo bundleInfo = bundleInfos[i];
View Full Code Here

        // Allow proper rollback in case the drop fails...
        addRollback(new RollbackCommitAction(session));

        AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
        BundleContext context = session.getBundleContext();
        LogService log = session.getLog();

        // Collect all unique paths of all processed resources...
        Set resourceProcessors = new HashSet();

        ResourceInfoImpl[] orderedTargetResources = target.getOrderedResourceInfos();
        for (int i = orderedTargetResources.length - 1; i >= 0; i--) {
            ResourceInfoImpl resourceInfo = orderedTargetResources[i];

            String rpName = resourceInfo.getResourceProcessor();
            String path = resourceInfo.getPath();

            if (resourceProcessors.contains(rpName)) {
                // Already seen this RP; continue on the next one...
                continue;
            }

            // Keep track of which resource processors we've seen already...
            resourceProcessors.add(rpName);

            ServiceReference ref = target.getResourceProcessor(path);
            if (ref == null) {
                log.log(LogService.LOG_ERROR, "Failed to find resource processor for '" + rpName + "'!");
                throw new DeploymentException(DeploymentException.CODE_PROCESSOR_NOT_FOUND, "Failed to find resource processor '" + rpName + "'!");
            }

            ResourceProcessor resourceProcessor = (ResourceProcessor) context.getService(ref);
            if (resourceProcessor == null) {
                log.log(LogService.LOG_ERROR, "Failed to find resource processor for '" + rpName + "'!");
                throw new DeploymentException(DeploymentException.CODE_PROCESSOR_NOT_FOUND, "Failed to find resource processor '" + rpName + "'!");
            }

            try {
                if (m_commitCommand.addResourceProcessor(resourceProcessor)) {
                    resourceProcessor.begin(session);
                }
                resourceProcessor.dropAllResources();
            }
            catch (Exception e) {
                log.log(LogService.LOG_ERROR, "Failed to drop all resources for resource processor '" + rpName + "'!", e);
                throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Failed to drop all resources for resource processor '" + rpName + "'!", e);
            }
        }
    }
View Full Code Here

public class StopBundleCommand extends Command {

    protected void doExecute(DeploymentSessionImpl session) throws Exception {
        String stopUnaffectedBundle = System.getProperty("org.apache.felix.deploymentadmin.stopunaffectedbundle", "true");

        LogService log = session.getLog();

        AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
        BundleInfo[] bundleInfos = target.getOrderedBundleInfos();
        for (int i = 0; i < bundleInfos.length; i++) {
            if (isCancelled()) {
                throw new DeploymentException(DeploymentException.CODE_CANCELLED);
            }
            String symbolicName = bundleInfos[i].getSymbolicName();
            Bundle bundle = target.getBundle(symbolicName);
            if (bundle != null) {
                if ("false".equalsIgnoreCase(stopUnaffectedBundle) && omitBundleStop(session, symbolicName)) {
                    continue;
                }
                if (isFragmentBundle(bundle)) {
                    log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + symbolicName + "'");
                } else {
                    addRollback(new StartBundleRunnable(session, bundle));
                    try {
                        bundle.stop();
                    }
                    catch (Exception e) {
                        log.log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "'", e);
                    }
                }
            } else {
                log.log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "' because it was not present in the framework");
            }
        }
    }
View Full Code Here

    protected void doExecute(DeploymentSessionImpl session) throws Exception {
        AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
        PackageAdmin packageAdmin = session.getPackageAdmin();
        RefreshPackagesListener listener = new RefreshPackagesListener();
        LogService log = session.getLog();

        session.getBundleContext().addFrameworkListener(listener);
        packageAdmin.refreshPackages(null);
        m_refreshMonitor.waitForRefresh();
        session.getBundleContext().removeFrameworkListener(listener);

        // start source bundles
        BundleInfoImpl[] bundleInfos = source.getOrderedBundleInfos();
        for (int i = 0; i < bundleInfos.length; i++) {
            BundleInfoImpl bundleInfoImpl = bundleInfos[i];
            if (!bundleInfoImpl.isCustomizer()) {
                String symbolicName = bundleInfoImpl.getSymbolicName();

                Bundle bundle = source.getBundle(symbolicName);
                if (bundle != null) {
                    if (isFragmentBundle(bundle)) {
                        log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + symbolicName + "'");
                    } else {
                        try {
                            bundle.start();
                        }
                        catch (Exception be) {
                            log.log(LogService.LOG_WARNING, "Could not start bundle '" + symbolicName + "'", be);
                        }
                    }
                } else {
                    log.log(LogService.LOG_WARNING, "Could not start bundle '" + symbolicName + "' because it is not present in the framework");
                }
            }
        }
    }
View Full Code Here

            // Only print the message if logging is enabled and
            // the message level is less than or equal to the log
            // level.
            if ((logLevel > 0) && (msgLevel <= logLevel))
            {
                LogService log = getLogService();
                if (log != null)
                {
                    log.log(msgLevel, message, throwable);
                }
                else
                {
                    super.log(logLevel, msgLevel, message, throwable);
                }
View Full Code Here

        private LogService getLogService()
        {
            ServiceReference ref = context.getServiceReference(LogService.class.getName());
            if (ref != null)
            {
                LogService log = (LogService) context.getService(ref);
                return log;
            }
            return null;
        }
View Full Code Here

     * @param level     the level of the message.
     * @param msg       the message to log
     * @param exception the exception attached to the message
     */
    private void dispatch(int level, String msg, Throwable exception) {
        LogService log = null;
        ServiceReference ref = null;
        try {
            // Security Check
            if (SecurityHelper.hasPermissionToGetService(LogService.class.getName(), m_context)) {
                ref = m_context.getServiceReference(LogService.class.getName());
            } else {
                Extender.getIPOJOBundleContext().getServiceReference(LogService.class.getName());
            }

            if (ref != null) {
                log = (LogService) m_context.getService(ref);
            }
        } catch (IllegalStateException e) {
            // Handle the case where the iPOJO bundle is stopping, or the log service already ran away.
        }

        if (log == null) {
            log = m_defaultLogger;
        }

        String name = m_name;
        if (name == null) {
            name = "";
        }

        String message = String.format("%s %s : %s", getLogHeaderForLevel(level), name, msg);
        switch (level) {
            case DEBUG:
                log.log(LogService.LOG_DEBUG, message, exception);
                break;
            case INFO:
                log.log(LogService.LOG_INFO, message, exception);
                break;
            case WARNING:
                log.log(LogService.LOG_WARNING, message, exception);
                break;
            case ERROR:
                log.log(LogService.LOG_ERROR, message, exception);
                break;
            default:
                log.log(LogService.LOG_INFO, message, exception);
                break;
        }

        if (ref != null) {
            m_context.ungetService(ref);
View Full Code Here

    return buffer;
  }

  protected StringBuffer log(int logLevel, StringBuffer buffer) {
    if (buffer.indexOf("\n") != -1) { // any new newlines to output?
      LogService log = (LogService) ciShellContext.getService(LogService.class.getName());

      int lastGoodIndex = 0;
      int fromIndex = 0;
      // print out each new line
      while (fromIndex != -1 && fromIndex < buffer.length()) {
        int toIndex = buffer.indexOf("\n", fromIndex);

        if (toIndex != -1) {
          String message = buffer.substring(fromIndex, toIndex);

          if (log == null) {
            // This will probably never come up, but if it does
            // we'll still get some output.
            System.out.println(message);
          } else {
            log.log(logLevel, message);
          }
          fromIndex = toIndex + 1;
          lastGoodIndex = toIndex + 1;
        } else {
          fromIndex = -1;
View Full Code Here

  public Long getInternalId() {
    return internalId;
  }

  protected void log(int logLevel, String message, Throwable exception) {
    LogService logger = (LogService) Activator.getCiShellContext()
        .getService(LogService.class.getName());

    if (logger != null) {
      logger.log(this.serviceReference, logLevel, message, exception);
    } else {
      exception.printStackTrace();
    }
  }
View Full Code Here

TOP

Related Classes of org.osgi.service.log.LogService

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.