Home | History | Annotate | Download | only in srm
      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 (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 /*
     22  * Copyright (c) 2001 by Sun Microsystems, Inc.
     23  * All rights reserved.
     24  *
     25  * Util.java
     26  */
     27 
     28 package com.sun.wbem.solarisprovider.srm;
     29 
     30 import javax.wbem.cim.*;
     31 
     32 import java.math.*;
     33 
     34 import java.util.PropertyResourceBundle;
     35 import java.io.InputStream;
     36 
     37 /**
     38  * Utility class
     39  * @author Sun Microsystems
     40  */
     41 class Util {
     42 
     43     public static String propertyUPDATETIME;
     44     public static String propertyRDSTIMEOUT;
     45     public static String propertyRDSINTERVAL;
     46     public static String propertyRDSDATABASE;
     47     public static String propertyKEEPALIVETIMEOUT;
     48     public static String propertyMSACCT;
     49     public static String propertyREADTIMEOUT;
     50     public static String propertyRDSLOGFILE;
     51 
     52 
     53     /**
     54      * Converts a java long into CIM UnsignedInt64 object.
     55      * @param l the long to be converted
     56      * @returns a CIM UnsignedInt64 object
     57      */
     58     public static UnsignedInt64 longToUI64(long l) {
     59         byte a[] = new byte[9];
     60 
     61         for (int i = 8; i > 0; i--, l >>= 8) {
     62             a[i] = (byte)(l & 0x0ff);
     63         }
     64         a[0] = 0;
     65         return new UnsignedInt64(a);
     66     }
     67 
     68     /**
     69      * Waits some milliseconds.
     70      *
     71      * @param ms time to wait in milliseconds
     72      */
     73     public static void napms(int ms) {
     74 	try {
     75 	    Thread.sleep(ms);
     76 	} catch (InterruptedException e) {}
     77     }
     78 
     79     private static final String classNameForResourceBundle =
     80     	    	"com.sun.wbem.solarisprovider.srm.Util";
     81     private static final String nameForResourceBundle =
     82     	    	"perfprovider.properties";
     83     private static final String nameForDebugPropertyLevel =
     84     	    	"ProviderDEBUGLEVEL";
     85     private static final String nameForDebugPropertyDevice =
     86     	    	"ProviderDEBUGDEVICE";
     87     private static final String nameForUPDATETIME =
     88     	    	"ProviderUPDATETIME";
     89     private static final String nameForRDSTIMEOUT =
     90     	    	"ProviderRDSTIMEOUT";
     91     private static final String nameForRDSINTERVAL =
     92     	    	"ProviderRDSINTERVAL";
     93     private static final String nameForRDSDATABASE =
     94     	    	"ProviderRDSDATABASE";
     95     private static final String nameForKEEPALIVETIMEOUT =
     96     	    	"ProviderKEEPALIVETIMEOUT";
     97     private static final String nameForMSACCT =
     98     	    	"ProviderMSACCT";
     99     private static final String nameForREADTIMEOUT=
    100     	    	"ProviderREADTIMEOUT";
    101     private static final String nameForRDSLOGFILE=
    102     	    	"ProviderRDSLOGFILE";
    103 
    104     // look for debug flag as a local resource
    105     static {
    106 	try {
    107 	    Class c = Class.forName(classNameForResourceBundle);
    108 
    109 	    InputStream is = c.getResourceAsStream(nameForResourceBundle);
    110 
    111 	    PropertyResourceBundle prb = new PropertyResourceBundle(is);
    112 
    113 	    try {
    114 		propertyUPDATETIME = prb.getString(nameForUPDATETIME);
    115 	    } catch (java.util.MissingResourceException x) {
    116 		;
    117 	    }
    118 
    119 	    try {
    120 		propertyRDSTIMEOUT = prb.getString(nameForRDSTIMEOUT);
    121 	    } catch (java.util.MissingResourceException x) {
    122 		;
    123 	    }
    124 
    125 	    try {
    126 		propertyRDSINTERVAL = prb.getString(nameForRDSINTERVAL);
    127 	    } catch (java.util.MissingResourceException x) {
    128 		;
    129 	    }
    130 
    131 	    try {
    132 		propertyRDSDATABASE = prb.getString(nameForRDSDATABASE);
    133 	    } catch (java.util.MissingResourceException x) {
    134 		;
    135 	    }
    136 
    137 	    try {
    138 		propertyKEEPALIVETIMEOUT =
    139 		    prb.getString(nameForKEEPALIVETIMEOUT);
    140 	    } catch (java.util.MissingResourceException x) {
    141 		;
    142 	    }
    143 
    144 	    try {
    145 		propertyMSACCT = prb.getString(nameForMSACCT);
    146 	    } catch (java.util.MissingResourceException x) {
    147 		;
    148 	    }
    149 
    150 	    try {
    151 		propertyREADTIMEOUT = prb.getString(nameForREADTIMEOUT);
    152 	    } catch (java.util.MissingResourceException x) {
    153 		;
    154 	    }
    155 
    156 	    try {
    157 		propertyRDSLOGFILE = prb.getString(nameForRDSLOGFILE);
    158 	    } catch (java.util.MissingResourceException x) {
    159 		;
    160 	    }
    161 	    String level = null;
    162 	    String device = null;
    163 
    164 	    try {
    165 		level = prb.getString(nameForDebugPropertyLevel);
    166 		device = prb.getString(nameForDebugPropertyDevice);
    167 	    } catch (java.util.MissingResourceException x) {
    168 		;
    169 	    }
    170 
    171 	    if ((device != null) && (device.equalsIgnoreCase("file"))) {
    172 	    	device = "perfprovider";
    173 	    }
    174 	    SRMDebug.traceOpen(level, device);
    175 	    SRMDebug.trace(SRMDebug.TRACE_ALL,
    176 		"Starting SRM provider trace level = "
    177 		+ level + ", device = " + device);
    178 
    179 	} catch (Exception x) {
    180 		;
    181 	}
    182     }
    183 
    184 }
    185