src/share/jaxws_classes/com/sun/org/glassfish/external/probe/provider/StatsProviderManager.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 2009, 2010, 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  */
    28 package com.sun.org.glassfish.external.probe.provider;
    30 import java.util.Vector;
    32 /**
    33  *
    34  * @author abbagani
    35  */
    36 public class StatsProviderManager {
    38    private StatsProviderManager(){
    39    }
    42    public static boolean register(String configElement, PluginPoint pp,
    43                                     String subTreeRoot, Object statsProvider) {
    44         return (register(pp, configElement, subTreeRoot, statsProvider, null));
    45    }
    47    public static boolean register(PluginPoint pp, String configElement,
    48                                   String subTreeRoot, Object statsProvider,
    49                                   String invokerId) {
    50         StatsProviderInfo spInfo =
    51             new StatsProviderInfo(configElement, pp, subTreeRoot, statsProvider, invokerId);
    53         return registerStatsProvider(spInfo);
    54    }
    56    public static boolean register(String configElement, PluginPoint pp,
    57                                     String subTreeRoot, Object statsProvider,
    58                                     String configLevelStr) {
    59         return(register(configElement, pp, subTreeRoot, statsProvider, configLevelStr, null));
    60    }
    62    public static boolean register(String configElement, PluginPoint pp,
    63                                     String subTreeRoot, Object statsProvider,
    64                                     String configLevelStr, String invokerId) {
    65         StatsProviderInfo spInfo =
    66             new StatsProviderInfo(configElement, pp, subTreeRoot, statsProvider, invokerId);
    67         spInfo.setConfigLevel(configLevelStr);
    69         return registerStatsProvider(spInfo);
    70    }
    72    private static boolean registerStatsProvider(StatsProviderInfo spInfo) {
    73       //Ideally want to start this in a thread, so we can reduce the startup time
    74       if (spmd == null) {
    75           //Make an entry into the toBeRegistered map
    76           toBeRegistered.add(spInfo);
    77       } else {
    78           spmd.register(spInfo);
    79           return true;
    80       }
    81        return false;
    82    }
    84    public static boolean unregister(Object statsProvider) {
    85       //Unregister the statsProvider if the delegate is not null
    86       if (spmd == null) {
    87           for (StatsProviderInfo spInfo : toBeRegistered) {
    88               if (spInfo.getStatsProvider() == statsProvider) {
    89                   toBeRegistered.remove(spInfo);
    90                   break;
    91               }
    92           }
    94       } else {
    95           spmd.unregister(statsProvider);
    96           return true;
    97       }
    98        return false;
    99    }
   102    public static boolean hasListeners(String probeStr) {
   103       //See if the probe has any listeners registered
   104       if (spmd == null) {
   105           return false;
   106       } else {
   107           return spmd.hasListeners(probeStr);
   108       }
   109    }
   112    public static void setStatsProviderManagerDelegate(
   113                                     StatsProviderManagerDelegate lspmd) {
   114       //System.out.println("in StatsProviderManager.setStatsProviderManagerDelegate ***********");
   115       if (lspmd == null) {
   116           //Should log and throw an exception
   117           return;
   118       }
   120       //Assign the Delegate
   121       spmd = lspmd;
   123       //System.out.println("Running through the toBeRegistered array to call register ***********");
   125       //First register the pending StatsProviderRegistryElements
   126       for (StatsProviderInfo spInfo : toBeRegistered) {
   127           spmd.register(spInfo);
   128       }
   130       //Now that you registered the pending calls, Clear the toBeRegistered store
   131       toBeRegistered.clear();
   132    }
   134    //variables
   135    static StatsProviderManagerDelegate spmd; // populate this during our initilaization process
   136    static Vector<StatsProviderInfo> toBeRegistered = new Vector();
   137 }

mercurial