1 /*
   2  * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.logging;
  27 
  28 import java.lang.reflect.InvocationTargetException;
  29 import java.lang.reflect.Method;
  30 import java.util.ArrayList;
  31 import java.util.List;
  32 
  33 public class PulseLogger {
  34 
  35     public static final boolean PULSE_LOGGING_ENABLED;
  36 
  37     private static final Logger[] loggers;
  38 
  39     static {
  40         List<Logger> list = new ArrayList();
  41         Logger logger = PrintLogger.getInstance();
  42         if (logger != null) {
  43             list.add(logger);
  44         }
  45 
  46 //        // Another optional logger could be added as follows:
  47 //        try {
  48 //            Class klass = Class.forName("com.sun.javafx.logging.OtherLogger");
  49 //            if (klass != null) {
  50 //                Method method = klass.getDeclaredMethod("getInstance");
  51 //                logger = (Logger) method.invoke(null);
  52 //                if (logger != null) {
  53 //                    list.add(logger);
  54 //                }
  55 //            }
  56 //        }
  57 //        catch (NoClassDefFoundError | ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
  58 //            // Ignore
  59 //        }
  60 
  61         loggers = list.toArray(new Logger[list.size()]);
  62         PULSE_LOGGING_ENABLED = loggers.length > 0;
  63     }
  64 
  65     public static void pulseStart() {
  66         for (Logger logger: loggers) {
  67             logger.pulseStart();
  68         }
  69     }
  70 
  71     public static void pulseEnd() {
  72         for (Logger logger: loggers) {
  73             logger.pulseEnd();
  74         }
  75     }
  76 
  77     public static void renderStart() {
  78         for (Logger logger: loggers) {
  79             logger.renderStart();
  80         }
  81     }
  82 
  83     public static void renderEnd() {
  84         for (Logger logger: loggers) {
  85             logger.renderEnd();
  86         }
  87     }
  88 
  89     public static void addMessage(String message) {
  90         for (Logger logger: loggers) {
  91             logger.addMessage(message);
  92         }
  93     }
  94 
  95     public static void incrementCounter(String counter) {
  96         for (Logger logger: loggers) {
  97             logger.incrementCounter(counter);
  98         }
  99     }
 100 
 101     public static void newPhase(String name) {
 102         for (Logger logger: loggers) {
 103             logger.newPhase(name);
 104         }
 105     }
 106 
 107     public static void newInput(String name) {
 108         for (Logger logger: loggers) {
 109             logger.newInput(name);
 110         }
 111     }
 112 }