src/share/classes/sun/jvmstat/perfdata/monitor/PerfDataBufferImpl.java

Print this page




  49 
  50     /**
  51      * A Map of monitor objects found in the instrumentation buffer.
  52      */
  53     protected Map<String, Monitor> monitors;
  54 
  55     /**
  56      * The Local Java Virtual Machine Identifier for this buffer.
  57      */
  58     protected int lvmid;
  59 
  60     /**
  61      * A Map of monitor object names to aliases as read in from the alias map
  62      * file.
  63      */
  64     protected Map<String, ArrayList<String>> aliasMap;
  65 
  66     /**
  67      * A cache of resolved monitor aliases.
  68      */
  69     protected Map aliasCache;
  70 
  71 
  72     /**
  73      * Constructor.
  74      *
  75      * @param buffer the ByteBuffer containing the instrumentation data.
  76      * @param lvmid the Local Java Virtual Machine Identifier for this
  77      *              instrumentation buffer.
  78      */
  79     protected PerfDataBufferImpl(ByteBuffer buffer, int lvmid) {
  80         this.buffer = buffer;
  81         this.lvmid = lvmid;
  82         this.monitors = new TreeMap<String, Monitor>();
  83         this.aliasMap = new HashMap<String, ArrayList<String>>();
  84         this.aliasCache = new HashMap();
  85     }
  86 
  87     /**
  88      * Get the Local Java Virtual Machine Identifier, or <em>lvmid</em>
  89      * for the target JVM associated with this instrumentation buffer.
  90      *
  91      * @return int - the lvmid
  92      */
  93     public int getLocalVmId() {
  94         return lvmid;
  95     }
  96 
  97     /**
  98      * Get a copy of the raw instrumentation data.
  99      * This method is used to get a copy of the current bytes in the
 100      * instrumentation buffer. It is generally used for transporting
 101      * those bytes over the network.
 102      *
 103      * @return byte[] - a copy of the bytes in the instrumentation buffer.
 104      */


 183 
 184         try {
 185             aliasParser.parse(aliasMap);
 186 
 187         } catch (IOException e) {
 188             System.err.println("Error processing " + filename + ": "
 189                                + e.getMessage());
 190         } catch (SyntaxException e) {
 191             System.err.println("Syntax error parsing " + filename + ": "
 192                                + e.getMessage());
 193         }
 194     }
 195 
 196     /**
 197      * Find the Monitor object for the named counter by using one of its
 198      * aliases.
 199      */
 200     protected Monitor findByAlias(String name) {
 201         assert Thread.holdsLock(this);
 202 
 203         Monitor  m = (Monitor)aliasCache.get(name);
 204         if (m == null) {
 205             ArrayList al = aliasMap.get(name);
 206             if (al != null) {
 207                 for (Iterator i = al.iterator(); i.hasNext() && m == null; ) {
 208                     String alias = (String)i.next();
 209                     m = monitors.get(alias);
 210                 }
 211             }
 212         }
 213         return m;
 214     }
 215 
 216 
 217     /**
 218      * Find a named Instrumentation object.
 219      *
 220      * This method will look for the named instrumentation object in the
 221      * instrumentation exported by this Java Virtual Machine. If an
 222      * instrumentation object with the given name exists, a Monitor interface
 223      * to that object will be return. Otherwise, the method returns
 224      * <tt>null</tt>. The method will map requests for instrumention objects
 225      * using old names to their current names, if applicable.
 226      *
 227      *
 228      *


 270      *                the given pattern. If no instrumentation objects have`
 271      *                names matching the given pattern, then an empty List
 272      *                is returned.
 273      * @throws MonitorException Thrown if an error occurs while communicating
 274      *                          with the target Java Virtual Machine.
 275      * @see java.util.regex.Pattern
 276      */
 277     public List<Monitor> findByPattern(String patternString)
 278                 throws MonitorException, PatternSyntaxException {
 279 
 280         synchronized(this) {
 281             if (monitors.isEmpty()) {
 282                 buildMonitorMap(monitors);
 283             } else {
 284                 getNewMonitors(monitors);
 285             }
 286         }
 287 
 288         Pattern pattern = Pattern.compile(patternString);
 289         Matcher matcher = pattern.matcher("");
 290         List<Monitor> matches = new ArrayList<Monitor>();
 291 
 292         Set monitorSet = monitors.entrySet();
 293 
 294         for (Iterator i = monitorSet.iterator(); i.hasNext(); /* empty */) {
 295             Map.Entry me = (Map.Entry)i.next();
 296             String name = (String)me.getKey();
 297             Monitor m = (Monitor)me.getValue();
 298 
 299             // apply pattern to monitor item name
 300             matcher.reset(name);
 301 
 302             // if the pattern matches, then add monitor to list
 303             if (matcher.lookingAt()) {
 304                  matches.add((Monitor)me.getValue());
 305             }
 306         }
 307         return matches;
 308     }
 309 
 310     /**
 311      * Get a list of the inserted and removed monitors since last called.
 312      *
 313      * @return MonitorStatus - the status of available Monitors for the
 314      *                         target Java Virtual Machine.
 315      * @throws MonitorException Thrown if communications errors occur
 316      *                          while communicating with the target.
 317      */
 318     public MonitorStatus getMonitorStatus() throws MonitorException {
 319         synchronized(this) {
 320             if (monitors.isEmpty()) {
 321                 buildMonitorMap(monitors);
 322             }
 323             return getMonitorStatus(monitors);
 324         }




  49 
  50     /**
  51      * A Map of monitor objects found in the instrumentation buffer.
  52      */
  53     protected Map<String, Monitor> monitors;
  54 
  55     /**
  56      * The Local Java Virtual Machine Identifier for this buffer.
  57      */
  58     protected int lvmid;
  59 
  60     /**
  61      * A Map of monitor object names to aliases as read in from the alias map
  62      * file.
  63      */
  64     protected Map<String, ArrayList<String>> aliasMap;
  65 
  66     /**
  67      * A cache of resolved monitor aliases.
  68      */
  69     protected Map<String, Monitor> aliasCache;
  70 
  71 
  72     /**
  73      * Constructor.
  74      *
  75      * @param buffer the ByteBuffer containing the instrumentation data.
  76      * @param lvmid the Local Java Virtual Machine Identifier for this
  77      *              instrumentation buffer.
  78      */
  79     protected PerfDataBufferImpl(ByteBuffer buffer, int lvmid) {
  80         this.buffer = buffer;
  81         this.lvmid = lvmid;
  82         this.monitors = new TreeMap<>();
  83         this.aliasMap = new HashMap<>();
  84         this.aliasCache = new HashMap<>();
  85     }
  86 
  87     /**
  88      * Get the Local Java Virtual Machine Identifier, or <em>lvmid</em>
  89      * for the target JVM associated with this instrumentation buffer.
  90      *
  91      * @return int - the lvmid
  92      */
  93     public int getLocalVmId() {
  94         return lvmid;
  95     }
  96 
  97     /**
  98      * Get a copy of the raw instrumentation data.
  99      * This method is used to get a copy of the current bytes in the
 100      * instrumentation buffer. It is generally used for transporting
 101      * those bytes over the network.
 102      *
 103      * @return byte[] - a copy of the bytes in the instrumentation buffer.
 104      */


 183 
 184         try {
 185             aliasParser.parse(aliasMap);
 186 
 187         } catch (IOException e) {
 188             System.err.println("Error processing " + filename + ": "
 189                                + e.getMessage());
 190         } catch (SyntaxException e) {
 191             System.err.println("Syntax error parsing " + filename + ": "
 192                                + e.getMessage());
 193         }
 194     }
 195 
 196     /**
 197      * Find the Monitor object for the named counter by using one of its
 198      * aliases.
 199      */
 200     protected Monitor findByAlias(String name) {
 201         assert Thread.holdsLock(this);
 202 
 203         Monitor  m = aliasCache.get(name);
 204         if (m == null) {
 205             ArrayList<String> al = aliasMap.get(name);
 206             if (al != null) {
 207                 for (Iterator<String> i = al.iterator(); i.hasNext() && m == null; ) {
 208                     String alias = i.next();
 209                     m = monitors.get(alias);
 210                 }
 211             }
 212         }
 213         return m;
 214     }
 215 
 216 
 217     /**
 218      * Find a named Instrumentation object.
 219      *
 220      * This method will look for the named instrumentation object in the
 221      * instrumentation exported by this Java Virtual Machine. If an
 222      * instrumentation object with the given name exists, a Monitor interface
 223      * to that object will be return. Otherwise, the method returns
 224      * <tt>null</tt>. The method will map requests for instrumention objects
 225      * using old names to their current names, if applicable.
 226      *
 227      *
 228      *


 270      *                the given pattern. If no instrumentation objects have`
 271      *                names matching the given pattern, then an empty List
 272      *                is returned.
 273      * @throws MonitorException Thrown if an error occurs while communicating
 274      *                          with the target Java Virtual Machine.
 275      * @see java.util.regex.Pattern
 276      */
 277     public List<Monitor> findByPattern(String patternString)
 278                 throws MonitorException, PatternSyntaxException {
 279 
 280         synchronized(this) {
 281             if (monitors.isEmpty()) {
 282                 buildMonitorMap(monitors);
 283             } else {
 284                 getNewMonitors(monitors);
 285             }
 286         }
 287 
 288         Pattern pattern = Pattern.compile(patternString);
 289         Matcher matcher = pattern.matcher("");
 290         List<Monitor> matches = new ArrayList<>();
 291 
 292         Set<Map.Entry<String,Monitor>> monitorSet = monitors.entrySet();
 293 
 294         for (Iterator<Map.Entry<String, Monitor>> i = monitorSet.iterator(); i.hasNext(); /* empty */) {
 295             Map.Entry<String, Monitor> me = i.next();
 296             String name = me.getKey();
 297             Monitor m = me.getValue();
 298 
 299             // apply pattern to monitor item name
 300             matcher.reset(name);
 301 
 302             // if the pattern matches, then add monitor to list
 303             if (matcher.lookingAt()) {
 304                  matches.add(me.getValue());
 305             }
 306         }
 307         return matches;
 308     }
 309 
 310     /**
 311      * Get a list of the inserted and removed monitors since last called.
 312      *
 313      * @return MonitorStatus - the status of available Monitors for the
 314      *                         target Java Virtual Machine.
 315      * @throws MonitorException Thrown if communications errors occur
 316      *                          while communicating with the target.
 317      */
 318     public MonitorStatus getMonitorStatus() throws MonitorException {
 319         synchronized(this) {
 320             if (monitors.isEmpty()) {
 321                 buildMonitorMap(monitors);
 322             }
 323             return getMonitorStatus(monitors);
 324         }