From: Lukas P. <pe...@us...> - 2002-09-03 17:45:14
|
Update of /cvsroot/javaprofiler/jpiimpl/net/sourceforge/javaprofiler/jpiimpl/connect In directory usw-pr-cvs1:/tmp/cvs-serv13878 Added Files: LibrarySettings.java Log Message: library settings --- NEW FILE: LibrarySettings.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License Version * 1.0 (the "License"). You may not use this file except in compliance with * the License. A copy of the License is available at http://www.sun.com/ * * The Original Code is the Java Profiler module. * The Initial Developers of the Original Code are Jan Stola, Pavel Vacha, * Michal Pise, Petr Luner, Lukas Petru and Marek Przeczek. * Portions created by Jan Stola are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Pavel Vacha are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Michal Pise are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Petr Luner are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Lukas Petru are Copyright (C) 2000-2001. All Rights Reserved. * Portions created by Marek Przeczek are Copyright (C) 2000-2001. All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.jpiimpl.connect; public class LibrarySettings { public final int ALLOC=1; public final int ALLOC_LEVEL=2; public final int ALLOC_LEVEL_OBJECT=26; public final int ALLOC_LEVEL_METHOD=27; public final int ALLOC_LEVEL_TRACE=28; public final int ALLOC_TRACE_DEPTH=3; public final int ALLOC_THREAD=4; public final int ALLOC_LINE=5; public final int CPU=6; public final int CPU_METHOD=7; public final int CPU_METHOD_EXACT=29; public final int CPU_METHOD_SAMPLING=30; public final int CPU_LEVEL=8; public final int CPU_LEVEL_METHOD=31; public final int CPU_LEVEL_TRACE=32; public final int CPU_TRACE_DEPTH=9; public final int CPU_THREAD=10; public final int CPU_LINE=11; public final int CPU_CALLTREE=12; public final int CPU_CALLTREE_LINE=13; public final int MON=14; public final int MON_LEVEL=15; public final int MON_LEVEL_METHOD=33; public final int MON_LEVEL_TRACE=34; public final int MON_TRACE_DEPTH=16; public final int MON_THREAD=17; public final int MON_LINE=18; public final int COMMUN_TYPE=19; public final int COMMUN_TYPE_SOCKET=35; public final int COMMUN_TYPE_SHMEM=36; public final int COMMUN_HOST=20; public final int COMMUN_PORT=21; public final int COMMUN_SHMEM_ID=22; public final int COMMUN_SHMEM_SIZE=23; public final int CONNECT_MODE=24; public final int CONNECT_MODE_SERVER=37; public final int CONNECT_MODE_CLIENT=38; public final int VERBOSE=25; private Object[] properties; LibrarySettings() { // all is disabled after constructor is called properties=new Object[26]; properties[ALLOC]=new Boolean(false); properties[ALLOC_THREAD]=new Boolean(true); properties[ALLOC_LINE]=new Boolean(true); properties[CPU]=new Boolean(false); properties[CPU_THREAD]=new Boolean(true); properties[CPU_LINE]=new Boolean(true); properties[CPU_CALLTREE]=new Boolean(false); properties[CPU_CALLTREE_LINE]=new Boolean(false); properties[MON]=new Boolean(false); properties[MON_THREAD]=new Boolean(true); properties[MON_LINE]=new Boolean(true); properties[VERBOSE]=new Boolean(true); properties[ALLOC_LEVEL]=new Integer(ALLOC_LEVEL_TRACE); properties[ALLOC_TRACE_DEPTH]=new Integer(2); properties[CPU_METHOD]=new Integer(CPU_METHOD_SAMPLING); properties[CPU_LEVEL]=new Integer(CPU_LEVEL_TRACE); properties[CPU_TRACE_DEPTH]=new Integer(2); properties[MON_LEVEL]=new Integer(MON_LEVEL_TRACE); properties[MON_TRACE_DEPTH]=new Integer(2); properties[COMMUN_TYPE]=new Integer(COMMUN_TYPE_SOCKET); properties[COMMUN_PORT]=new Integer(25595); properties[COMMUN_SHMEM_SIZE]=new Integer(262144); properties[CONNECT_MODE]=new Integer(CONNECT_MODE_SERVER); properties[COMMUN_HOST]="127.0.0.1"; properties[COMMUN_SHMEM_ID]="com"; } public void enableProperty(int prop) { enableProperty(prop, true); } public void enableProperty(int prop, boolean enable) { Object val=getProperty(prop); if (val instanceof Boolean) properties[prop]=new Boolean(enable); else throw new IllegalArgumentException("Not a boolean property."); } public void setProperty(int prop, int val) { Object old=getProperty(prop); if (old instanceof Integer) { checkConstrained(prop, val); properties[prop]=new Integer(val); } else throw new IllegalArgumentException("Not an int property."); } public void setProperty(int prop, String val) { Object old=getProperty(prop); if (old instanceof String) properties[prop]=val; else throw new IllegalArgumentException("Not a String property."); } private void checkConstrained(int prop, int val) throws IllegalArgumentException { boolean valid=false; switch (prop) { case ALLOC_LEVEL: valid = val==ALLOC_LEVEL_OBJECT || val==ALLOC_LEVEL_METHOD || val==ALLOC_LEVEL_TRACE; break; case CPU_METHOD: valid = val==CPU_METHOD_EXACT || val==CPU_METHOD_SAMPLING; break; case CPU_LEVEL: valid = val==CPU_LEVEL_METHOD || val==CPU_LEVEL_TRACE; break; case MON_LEVEL: valid = val==MON_LEVEL_METHOD || val==MON_LEVEL_TRACE; break; case COMMUN_TYPE: valid = val==COMMUN_TYPE_SOCKET || val==COMMUN_TYPE_SHMEM; break; case CONNECT_MODE: checkConstrained(prop, val); valid = val==CONNECT_MODE_SERVER || val==CONNECT_MODE_CLIENT; break; default: valid=true; break; } if (!valid) throw new IllegalArgumentException("Constrained property."); } public boolean getBooleanProperty(int prop) { Object val=getProperty(prop); if (val instanceof Boolean) return ((Boolean) val).booleanValue(); throw new IllegalArgumentException("Not a boolean property."); } public int getIntProperty (int prop) { Object val=getProperty(prop); if (val instanceof Integer) return ((Integer) val).intValue(); throw new IllegalArgumentException("Not an int property."); } public String getStringProperty (int prop) { Object val=getProperty(prop); if (val instanceof String) return (String) val; throw new IllegalArgumentException("Not a String property."); } public Object getProperty(int prop) { if (prop < properties.length) { Object val=properties[prop]; if (val!=null) return val; } throw new IllegalArgumentException(); } public Class getPropertyType(int prop) { return getProperty(prop).getClass(); } public String getAsText(int prop) { Class type=getPropertyType(prop); if (type==Boolean.class) return getBooleanProperty(prop) ? "on" : "off"; else if (type==int.class) { int val=getIntProperty(prop); switch (prop) { case ALLOC_LEVEL_OBJECT: return "object"; case ALLOC_LEVEL_METHOD: return "method"; case ALLOC_LEVEL_TRACE: return "trace"; case CPU_METHOD_EXACT: return "exact"; case CPU_METHOD_SAMPLING: return "sampling"; case CPU_LEVEL_METHOD: return "method"; case CPU_LEVEL_TRACE: return "trace"; case MON_LEVEL_METHOD: return "method"; case MON_LEVEL_TRACE: return "trace"; case COMMUN_TYPE_SOCKET: return "socket"; case COMMUN_TYPE_SHMEM: return "shmem"; case CONNECT_MODE_SERVER: return "server"; case CONNECT_MODE_CLIENT: return "client"; } return String.valueOf(val); } else return getStringProperty(prop); } public String toString() { StringBuffer buf=new StringBuffer(); if (getBooleanProperty(ALLOC)!=true) buf.append("alloc=off,"); else { if (getIntProperty(ALLOC_LEVEL)!=ALLOC_LEVEL_TRACE) buf.append("alloc_level="+getAsText(ALLOC_LEVEL)+","); if (getIntProperty(ALLOC_TRACE_DEPTH)!=2) buf.append("alloc_trace_depth="+getAsText(ALLOC_TRACE_DEPTH)+ ","); if (getBooleanProperty(ALLOC_THREAD)!=true) buf.append("alloc_thread=off,"); if (getBooleanProperty(ALLOC_LINE)!=true) buf.append("alloc_line=off,"); } if (getBooleanProperty(CPU)!=true) buf.append("cpu=off,"); else { if (getIntProperty(CPU_METHOD)!=CPU_METHOD_SAMPLING) buf.append("cpu_method="+getAsText(CPU_METHOD)+","); if (getIntProperty(CPU_LEVEL)!=CPU_LEVEL_TRACE) buf.append("cpu_level="+getAsText(CPU_LEVEL)+","); if (getIntProperty(CPU_TRACE_DEPTH)!=2) buf.append("cpu_trace_depth="+getAsText(CPU_TRACE_DEPTH)+ ","); if (getBooleanProperty(CPU_THREAD)!=true) buf.append("cpu_thread=off,"); if (getBooleanProperty(CPU_LINE)!=true) buf.append("cpu_line=off,"); if (getBooleanProperty(CPU_CALLTREE)!=true) buf.append("cpu_calltree=off,"); if (getBooleanProperty(CPU_CALLTREE_LINE)!=false) buf.append("cpu_calltree_line=on,"); } if (getBooleanProperty(MON)!=true) buf.append("mon=off,"); else { if (getIntProperty(MON_LEVEL)!=MON_LEVEL_TRACE) buf.append("mon_level="+getAsText(MON_LEVEL)+","); if (getIntProperty(MON_TRACE_DEPTH)!=2) buf.append("mon_trace_depth="+getAsText(MON_TRACE_DEPTH)+ ","); if (getBooleanProperty(MON_THREAD)!=true) buf.append("mon_thread=off,"); if (getBooleanProperty(MON_LINE)!=true) buf.append("mon_line=off,"); } if (getIntProperty(COMMUN_TYPE)!=COMMUN_TYPE_SOCKET) buf.append("commun_type="+getAsText(COMMUN_TYPE)+","); buf.append("commun_shmem_id="+getAsText(COMMUN_SHMEM_ID)+","); if (getIntProperty(COMMUN_SHMEM_SIZE)!=262144) buf.append("commun_shmem_size="+getAsText(COMMUN_SHMEM_SIZE)+"," ); else { buf.append("commun_host="+getAsText(COMMUN_HOST)+","); if (getIntProperty(COMMUN_PORT)!=25595) buf.append("commun_port="+getAsText(COMMUN_PORT)+","); if (getIntProperty(CONNECT_MODE)!=CONNECT_MODE_SERVER) buf.append("connect_mode="+getAsText(CONNECT_MODE)+","); } if (getBooleanProperty(VERBOSE)!=true) buf.append("verbose=off,"); return buf.toString(); } } /* * $Log: LibrarySettings.java,v $ * Revision 1.1 2002/09/03 17:45:11 petrul * library settings * */ |