jdk/src/jdk.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AbstractMonitoredVm.java
changeset 25859 3317bb8137f4
parent 5506 202f599c92aa
child 34351 f30070a16a4b
equal deleted inserted replaced
25858:836adbf7a2cd 25859:3317bb8137f4
       
     1 /*
       
     2  * Copyright (c) 2004, 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 sun.jvmstat.perfdata.monitor;
       
    27 
       
    28 import java.util.List;
       
    29 import java.lang.reflect.*;
       
    30 import java.io.*;
       
    31 
       
    32 import sun.jvmstat.monitor.*;
       
    33 import sun.jvmstat.monitor.remote.*;
       
    34 import sun.jvmstat.monitor.event.VmListener;
       
    35 
       
    36 /**
       
    37  * Base class for all MonitoredVm implementations that utilize the
       
    38  * HotSpot PerfData instrumentation buffer as the communications
       
    39  * mechanism to the target Java Virtual Machine.
       
    40  *
       
    41  * @author Brian Doherty
       
    42  * @since 1.5
       
    43  */
       
    44 public abstract class AbstractMonitoredVm implements BufferedMonitoredVm {
       
    45 
       
    46     /**
       
    47      * The VmIdentifier for the target.
       
    48      */
       
    49     protected VmIdentifier vmid;
       
    50 
       
    51     /**
       
    52      * The shared memory instrumentation buffer for the target.
       
    53      */
       
    54     protected AbstractPerfDataBuffer pdb;
       
    55 
       
    56     /**
       
    57      * The sampling interval, if the instrumentation buffer is acquired
       
    58      * by sampling instead of shared memory mechanisms.
       
    59      */
       
    60     protected int interval;
       
    61 
       
    62     /**
       
    63      * Create an AbstractMonitoredVm instance.
       
    64      *
       
    65      * @param vmid the VmIdentifier for the target
       
    66      * @param interval the initial sampling interval
       
    67      */
       
    68     public AbstractMonitoredVm(VmIdentifier vmid, int interval)
       
    69            throws MonitorException {
       
    70         this.vmid = vmid;
       
    71         this.interval = interval;
       
    72     }
       
    73 
       
    74     /**
       
    75      * {@inheritDoc}
       
    76      */
       
    77     public VmIdentifier getVmIdentifier() {
       
    78         return vmid;
       
    79     }
       
    80 
       
    81     /**
       
    82      * {@inheritDoc}
       
    83      */
       
    84     public Monitor findByName(String name) throws MonitorException {
       
    85         return pdb.findByName(name);
       
    86     }
       
    87 
       
    88     /**
       
    89      * {@inheritDoc}
       
    90      */
       
    91     public List<Monitor> findByPattern(String patternString) throws MonitorException {
       
    92         return pdb.findByPattern(patternString);
       
    93     }
       
    94 
       
    95     /**
       
    96      * {@inheritDoc}
       
    97      */
       
    98     public void detach() {
       
    99         /*
       
   100          * no default action required because the detach operation for the
       
   101          * native byte buffer is managed by the sun.misc.Perf class.
       
   102          */
       
   103     }
       
   104 
       
   105 
       
   106     /* ---- Methods to support polled MonitoredVm Implementations ----- */
       
   107 
       
   108     /**
       
   109      * {@inheritDoc}
       
   110      */
       
   111     public void setInterval(int interval) {
       
   112         this.interval = interval;
       
   113     }
       
   114 
       
   115     /**
       
   116      * {@inheritDoc}
       
   117      */
       
   118     public int getInterval() {
       
   119         return interval;
       
   120     }
       
   121 
       
   122     /**
       
   123      * {@inheritDoc}
       
   124      */
       
   125     public void setLastException(Exception e) {
       
   126         // XXX: implement
       
   127     }
       
   128 
       
   129     /**
       
   130      * {@inheritDoc}
       
   131      */
       
   132     public Exception getLastException() {
       
   133         // XXX: implement
       
   134         return null;
       
   135     }
       
   136 
       
   137     /**
       
   138      * {@inheritDoc}
       
   139      */
       
   140     public void clearLastException() {
       
   141         // XXX: implement
       
   142     }
       
   143 
       
   144     /**
       
   145      * {@inheritDoc}
       
   146      */
       
   147     public boolean isErrored() {
       
   148         // XXX: implement
       
   149         return false;
       
   150     }
       
   151 
       
   152     /**
       
   153      * Get a list of the inserted and removed monitors since last called.
       
   154      *
       
   155      * @return MonitorStatus - the status of available Monitors for the
       
   156      *                         target Java Virtual Machine.
       
   157      * @throws MonitorException Thrown if communications errors occur
       
   158      *                          while communicating with the target.
       
   159      */
       
   160     public MonitorStatus getMonitorStatus() throws MonitorException {
       
   161         return pdb.getMonitorStatus();
       
   162     }
       
   163 
       
   164 
       
   165     /* --------------- Methods to support VmListeners ----------------- */
       
   166 
       
   167     /**
       
   168      * {@inheritDoc}
       
   169      */
       
   170     public abstract void addVmListener(VmListener l);
       
   171 
       
   172     /**
       
   173      * {@inheritDoc}
       
   174      */
       
   175     public abstract void removeVmListener(VmListener l);
       
   176 
       
   177 
       
   178     /* ---- Methods to support BufferedMonitoredVm Implementations ---- */
       
   179 
       
   180     /**
       
   181      * {@inheritDoc}
       
   182      */
       
   183     public byte[] getBytes() {
       
   184         return pdb.getBytes();
       
   185     }
       
   186 
       
   187     /**
       
   188      * {@inheritDoc}
       
   189      */
       
   190     public int getCapacity() {
       
   191         return pdb.getCapacity();
       
   192     }
       
   193 }