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 Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,137 @@ 1.4 +/* 1.5 + * Copyright (c) 2009, 2010, 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 + 1.30 + 1.31 +package com.sun.org.glassfish.external.probe.provider; 1.32 + 1.33 +import java.util.Vector; 1.34 + 1.35 +/** 1.36 + * 1.37 + * @author abbagani 1.38 + */ 1.39 +public class StatsProviderManager { 1.40 + 1.41 + private StatsProviderManager(){ 1.42 + } 1.43 + 1.44 + 1.45 + public static boolean register(String configElement, PluginPoint pp, 1.46 + String subTreeRoot, Object statsProvider) { 1.47 + return (register(pp, configElement, subTreeRoot, statsProvider, null)); 1.48 + } 1.49 + 1.50 + public static boolean register(PluginPoint pp, String configElement, 1.51 + String subTreeRoot, Object statsProvider, 1.52 + String invokerId) { 1.53 + StatsProviderInfo spInfo = 1.54 + new StatsProviderInfo(configElement, pp, subTreeRoot, statsProvider, invokerId); 1.55 + 1.56 + return registerStatsProvider(spInfo); 1.57 + } 1.58 + 1.59 + public static boolean register(String configElement, PluginPoint pp, 1.60 + String subTreeRoot, Object statsProvider, 1.61 + String configLevelStr) { 1.62 + return(register(configElement, pp, subTreeRoot, statsProvider, configLevelStr, null)); 1.63 + } 1.64 + 1.65 + public static boolean register(String configElement, PluginPoint pp, 1.66 + String subTreeRoot, Object statsProvider, 1.67 + String configLevelStr, String invokerId) { 1.68 + StatsProviderInfo spInfo = 1.69 + new StatsProviderInfo(configElement, pp, subTreeRoot, statsProvider, invokerId); 1.70 + spInfo.setConfigLevel(configLevelStr); 1.71 + 1.72 + return registerStatsProvider(spInfo); 1.73 + } 1.74 + 1.75 + private static boolean registerStatsProvider(StatsProviderInfo spInfo) { 1.76 + //Ideally want to start this in a thread, so we can reduce the startup time 1.77 + if (spmd == null) { 1.78 + //Make an entry into the toBeRegistered map 1.79 + toBeRegistered.add(spInfo); 1.80 + } else { 1.81 + spmd.register(spInfo); 1.82 + return true; 1.83 + } 1.84 + return false; 1.85 + } 1.86 + 1.87 + public static boolean unregister(Object statsProvider) { 1.88 + //Unregister the statsProvider if the delegate is not null 1.89 + if (spmd == null) { 1.90 + for (StatsProviderInfo spInfo : toBeRegistered) { 1.91 + if (spInfo.getStatsProvider() == statsProvider) { 1.92 + toBeRegistered.remove(spInfo); 1.93 + break; 1.94 + } 1.95 + } 1.96 + 1.97 + } else { 1.98 + spmd.unregister(statsProvider); 1.99 + return true; 1.100 + } 1.101 + return false; 1.102 + } 1.103 + 1.104 + 1.105 + public static boolean hasListeners(String probeStr) { 1.106 + //See if the probe has any listeners registered 1.107 + if (spmd == null) { 1.108 + return false; 1.109 + } else { 1.110 + return spmd.hasListeners(probeStr); 1.111 + } 1.112 + } 1.113 + 1.114 + 1.115 + public static void setStatsProviderManagerDelegate( 1.116 + StatsProviderManagerDelegate lspmd) { 1.117 + //System.out.println("in StatsProviderManager.setStatsProviderManagerDelegate ***********"); 1.118 + if (lspmd == null) { 1.119 + //Should log and throw an exception 1.120 + return; 1.121 + } 1.122 + 1.123 + //Assign the Delegate 1.124 + spmd = lspmd; 1.125 + 1.126 + //System.out.println("Running through the toBeRegistered array to call register ***********"); 1.127 + 1.128 + //First register the pending StatsProviderRegistryElements 1.129 + for (StatsProviderInfo spInfo : toBeRegistered) { 1.130 + spmd.register(spInfo); 1.131 + } 1.132 + 1.133 + //Now that you registered the pending calls, Clear the toBeRegistered store 1.134 + toBeRegistered.clear(); 1.135 + } 1.136 + 1.137 + //variables 1.138 + static StatsProviderManagerDelegate spmd; // populate this during our initilaization process 1.139 + static Vector<StatsProviderInfo> toBeRegistered = new Vector(); 1.140 +}