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

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/org/glassfish/external/probe/provider/StatsProviderManager.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,135 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.org.glassfish.external.probe.provider;
    1.30 +
    1.31 +import java.util.Vector;
    1.32 +
    1.33 +/**
    1.34 + *
    1.35 + * @author abbagani
    1.36 + */
    1.37 +public class StatsProviderManager {
    1.38 +
    1.39 +   private StatsProviderManager(){
    1.40 +   }
    1.41 +
    1.42 +
    1.43 +   public static boolean register(String configElement, PluginPoint pp,
    1.44 +                                    String subTreeRoot, Object statsProvider) {
    1.45 +        return (register(pp, configElement, subTreeRoot, statsProvider, null));
    1.46 +   }
    1.47 +
    1.48 +   public static boolean register(PluginPoint pp, String configElement,
    1.49 +                                  String subTreeRoot, Object statsProvider,
    1.50 +                                  String invokerId) {
    1.51 +        StatsProviderInfo spInfo =
    1.52 +            new StatsProviderInfo(configElement, pp, subTreeRoot, statsProvider, invokerId);
    1.53 +
    1.54 +        return registerStatsProvider(spInfo);
    1.55 +   }
    1.56 +
    1.57 +   public static boolean register(String configElement, PluginPoint pp,
    1.58 +                                    String subTreeRoot, Object statsProvider,
    1.59 +                                    String configLevelStr) {
    1.60 +        return(register(configElement, pp, subTreeRoot, statsProvider, configLevelStr, null));
    1.61 +   }
    1.62 +
    1.63 +   public static boolean register(String configElement, PluginPoint pp,
    1.64 +                                    String subTreeRoot, Object statsProvider,
    1.65 +                                    String configLevelStr, String invokerId) {
    1.66 +        StatsProviderInfo spInfo =
    1.67 +            new StatsProviderInfo(configElement, pp, subTreeRoot, statsProvider, invokerId);
    1.68 +        spInfo.setConfigLevel(configLevelStr);
    1.69 +
    1.70 +        return registerStatsProvider(spInfo);
    1.71 +   }
    1.72 +
    1.73 +   private static boolean registerStatsProvider(StatsProviderInfo spInfo) {
    1.74 +      //Ideally want to start this in a thread, so we can reduce the startup time
    1.75 +      if (spmd == null) {
    1.76 +          //Make an entry into the toBeRegistered map
    1.77 +          toBeRegistered.add(spInfo);
    1.78 +      } else {
    1.79 +          spmd.register(spInfo);
    1.80 +          return true;
    1.81 +      }
    1.82 +       return false;
    1.83 +   }
    1.84 +
    1.85 +   public static boolean unregister(Object statsProvider) {
    1.86 +      //Unregister the statsProvider if the delegate is not null
    1.87 +      if (spmd == null) {
    1.88 +          for (StatsProviderInfo spInfo : toBeRegistered) {
    1.89 +              if (spInfo.getStatsProvider() == statsProvider) {
    1.90 +                  toBeRegistered.remove(spInfo);
    1.91 +                  break;
    1.92 +              }
    1.93 +          }
    1.94 +
    1.95 +      } else {
    1.96 +          spmd.unregister(statsProvider);
    1.97 +          return true;
    1.98 +      }
    1.99 +       return false;
   1.100 +   }
   1.101 +
   1.102 +
   1.103 +   public static boolean hasListeners(String probeStr) {
   1.104 +      //See if the probe has any listeners registered
   1.105 +      if (spmd == null) {
   1.106 +          return false;
   1.107 +      } else {
   1.108 +          return spmd.hasListeners(probeStr);
   1.109 +      }
   1.110 +   }
   1.111 +
   1.112 +
   1.113 +   public static void setStatsProviderManagerDelegate(
   1.114 +                                    StatsProviderManagerDelegate lspmd) {
   1.115 +      //System.out.println("in StatsProviderManager.setStatsProviderManagerDelegate ***********");
   1.116 +      if (lspmd == null) {
   1.117 +          //Should log and throw an exception
   1.118 +          return;
   1.119 +      }
   1.120 +
   1.121 +      //Assign the Delegate
   1.122 +      spmd = lspmd;
   1.123 +
   1.124 +      //System.out.println("Running through the toBeRegistered array to call register ***********");
   1.125 +
   1.126 +      //First register the pending StatsProviderRegistryElements
   1.127 +      for (StatsProviderInfo spInfo : toBeRegistered) {
   1.128 +          spmd.register(spInfo);
   1.129 +      }
   1.130 +
   1.131 +      //Now that you registered the pending calls, Clear the toBeRegistered store
   1.132 +      toBeRegistered.clear();
   1.133 +   }
   1.134 +
   1.135 +   //variables
   1.136 +   static StatsProviderManagerDelegate spmd; // populate this during our initilaization process
   1.137 +   static Vector<StatsProviderInfo> toBeRegistered = new Vector();
   1.138 +}

mercurial