1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 * ident "%Z%%M% %I% %E% SMI" 27 */ 28 29 package com.sun.solaris.service.kstat; 30 31 /** 32 * <code>kstat</code> controlling object. Allows kstats to be looked up 33 * so they can later be sampled. 34 */ 35 public final class KstatCtl 36 { 37 static { 38 System.loadLibrary("jkstat"); KstatCtl.init()39 KstatCtl.init(); 40 } 41 42 /** 43 * Pointer to a <code>kstat_ctl_t</code>. 44 */ 45 private long kctl; 46 47 /** 48 * Invokes <code>kstat_open(3KSTAT)</code>. The returned object 49 * should be explicitly finalized when it's no longer needed. 50 */ KstatCtl()51 public KstatCtl() 52 { 53 kctl = open(); 54 assert(kctl != 0); 55 } 56 57 /** 58 * Calls <code>kstat_close(3KSTAT)</code>. 59 */ finalize()60 public void finalize() 61 { 62 close(kctl); 63 kctl = 0; 64 } 65 66 /** 67 * Invokes <code>kstat_open(3KSTAT)</code>. 68 */ open()69 private native long open(); 70 71 /** 72 * Invokes <code>kstat_close(3KSTAT)</code>. 73 */ close(long kctl)74 private native int close(long kctl); 75 76 /** 77 * Invokes <code>kstat_lookup(3KSTAT)</code> and returns a Kstat 78 * for any result, or null if none is found. 79 */ lookup(String module, int instance, String name)80 public native Kstat lookup(String module, int instance, String name); 81 82 /** 83 * Invokes <code>kstat_chain_update(3KSTAT)</code>. 84 * 85 * @throws KstatChainUpdateException if the native function 86 * returns -1. 87 */ chainUpdate()88 public native void chainUpdate() throws KstatChainUpdateException; 89 90 /** 91 * Initialize cached class, method, and field IDs. 92 */ init()93 private static native void init(); 94 } 95