17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate * 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate package com.sun.solaris.service.pools; 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate import java.util.List; 317c478bd9Sstevel@tonic-gate import java.util.ArrayList; 327c478bd9Sstevel@tonic-gate import java.util.Map; 337c478bd9Sstevel@tonic-gate import java.util.HashMap; 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate /** 367c478bd9Sstevel@tonic-gate * The <code>Configuration</code> class represents a pools configuration. 377c478bd9Sstevel@tonic-gate */ 387c478bd9Sstevel@tonic-gate public class Configuration extends Element 397c478bd9Sstevel@tonic-gate { 407c478bd9Sstevel@tonic-gate /** 417c478bd9Sstevel@tonic-gate * Indicates whether the configuration represents a usable 427c478bd9Sstevel@tonic-gate * configuration. 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate private boolean _valid = false; 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate /** 477c478bd9Sstevel@tonic-gate * A reference to the native libpool object represented by 487c478bd9Sstevel@tonic-gate * this instance. 497c478bd9Sstevel@tonic-gate */ 507c478bd9Sstevel@tonic-gate private long _this; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /** 537c478bd9Sstevel@tonic-gate * The name of this instance. 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate private String name; 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate /** 587c478bd9Sstevel@tonic-gate * The cache of elements known to this configuration. 597c478bd9Sstevel@tonic-gate */ 607c478bd9Sstevel@tonic-gate private Map elements; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /** 637c478bd9Sstevel@tonic-gate * The key of the configuration. 647c478bd9Sstevel@tonic-gate */ 657c478bd9Sstevel@tonic-gate private String key; 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /** 687c478bd9Sstevel@tonic-gate * Constructor 697c478bd9Sstevel@tonic-gate * @param location The location of the configuration. 707c478bd9Sstevel@tonic-gate * @param perms The OR'd permissions used when opening this 717c478bd9Sstevel@tonic-gate * configuration. 727c478bd9Sstevel@tonic-gate * @exception PoolsException The error message generated by 737c478bd9Sstevel@tonic-gate * libpool. 747c478bd9Sstevel@tonic-gate */ Configuration(String location, int perms)757c478bd9Sstevel@tonic-gate public Configuration(String location, int perms) throws PoolsException 767c478bd9Sstevel@tonic-gate { 777c478bd9Sstevel@tonic-gate if (((_this = PoolInternal.pool_conf_alloc())) == 0) 787c478bd9Sstevel@tonic-gate throw new PoolsException(); 797c478bd9Sstevel@tonic-gate _conf = this; 807c478bd9Sstevel@tonic-gate open(location, perms); 817c478bd9Sstevel@tonic-gate elements = new HashMap(); 827c478bd9Sstevel@tonic-gate } 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /** 857c478bd9Sstevel@tonic-gate * Reclaim the memory allocated for this configuration by the C 867c478bd9Sstevel@tonic-gate * proxy. 877c478bd9Sstevel@tonic-gate * 887c478bd9Sstevel@tonic-gate * @throws Throwable If freeing this configuration fails. 897c478bd9Sstevel@tonic-gate */ finalize()907c478bd9Sstevel@tonic-gate protected void finalize() throws Throwable 917c478bd9Sstevel@tonic-gate { 927c478bd9Sstevel@tonic-gate try 937c478bd9Sstevel@tonic-gate { 947c478bd9Sstevel@tonic-gate close(); 957c478bd9Sstevel@tonic-gate if (_this != 0) { 967c478bd9Sstevel@tonic-gate PoolInternal.pool_conf_free(_this); 977c478bd9Sstevel@tonic-gate _this = 0; 987c478bd9Sstevel@tonic-gate } 997c478bd9Sstevel@tonic-gate } 1007c478bd9Sstevel@tonic-gate finally 1017c478bd9Sstevel@tonic-gate { 1027c478bd9Sstevel@tonic-gate super.finalize(); 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /** 1077c478bd9Sstevel@tonic-gate * Returns a pointer to the native configuration, wrapped by this 1087c478bd9Sstevel@tonic-gate * instance. 1097c478bd9Sstevel@tonic-gate * 1107c478bd9Sstevel@tonic-gate * @return the configuration pointer. 1117c478bd9Sstevel@tonic-gate */ getConf()1127c478bd9Sstevel@tonic-gate final long getConf() 1137c478bd9Sstevel@tonic-gate { 1147c478bd9Sstevel@tonic-gate return (_this); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /** 1187c478bd9Sstevel@tonic-gate * Opens the configuration at the supplied location and with the 1197c478bd9Sstevel@tonic-gate * supplied permissions. 1207c478bd9Sstevel@tonic-gate * 1217c478bd9Sstevel@tonic-gate * @throws PoolsException if there is an error opening the 1227c478bd9Sstevel@tonic-gate * configuration. 1237c478bd9Sstevel@tonic-gate */ open(String location, int perms)1247c478bd9Sstevel@tonic-gate public void open(String location, int perms) throws PoolsException 1257c478bd9Sstevel@tonic-gate { 1267c478bd9Sstevel@tonic-gate if (_valid == false) { 1277c478bd9Sstevel@tonic-gate if (PoolInternal.pool_conf_open(getConf(), location, 1287c478bd9Sstevel@tonic-gate perms) != PoolInternal.PO_SUCCESS) { 1297c478bd9Sstevel@tonic-gate throw new PoolsException(); 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate _valid = true; 1327c478bd9Sstevel@tonic-gate name = getStringProperty("system.name"); 1337c478bd9Sstevel@tonic-gate key = "system." + name; 1347c478bd9Sstevel@tonic-gate } 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /** 1387c478bd9Sstevel@tonic-gate * Closes the configuration. 1397c478bd9Sstevel@tonic-gate * 1407c478bd9Sstevel@tonic-gate */ close()1417c478bd9Sstevel@tonic-gate public void close() 1427c478bd9Sstevel@tonic-gate { 1437c478bd9Sstevel@tonic-gate if (_valid == true) { 1447c478bd9Sstevel@tonic-gate elements.clear(); 1457c478bd9Sstevel@tonic-gate PoolInternal.pool_conf_close(getConf()); 1467c478bd9Sstevel@tonic-gate name = key = null; 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate _valid = false; 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /** 1527c478bd9Sstevel@tonic-gate * Returns the location of the configuration. 1537c478bd9Sstevel@tonic-gate * 1547c478bd9Sstevel@tonic-gate * @return the location of the configuration. 1557c478bd9Sstevel@tonic-gate */ getLocation()1567c478bd9Sstevel@tonic-gate public String getLocation() 1577c478bd9Sstevel@tonic-gate { 1587c478bd9Sstevel@tonic-gate return (PoolInternal.pool_conf_location(getConf())); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /** 1627c478bd9Sstevel@tonic-gate * Returns the status of the configuration. 1637c478bd9Sstevel@tonic-gate * 1647c478bd9Sstevel@tonic-gate * @return the status of the configuration. 1657c478bd9Sstevel@tonic-gate */ status()1667c478bd9Sstevel@tonic-gate public int status() 1677c478bd9Sstevel@tonic-gate { 1687c478bd9Sstevel@tonic-gate return (PoolInternal.pool_conf_status(getConf())); 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate /** 1727c478bd9Sstevel@tonic-gate * Remove the configuration. 1737c478bd9Sstevel@tonic-gate * 174*99308ed0SPeter Tribble * @throws PoolsException If the removal fails. 1757c478bd9Sstevel@tonic-gate */ remove()1767c478bd9Sstevel@tonic-gate public void remove() throws PoolsException 1777c478bd9Sstevel@tonic-gate { 1787c478bd9Sstevel@tonic-gate if (PoolInternal.pool_conf_remove(getConf()) != 1797c478bd9Sstevel@tonic-gate PoolInternal.PO_SUCCESS) 1807c478bd9Sstevel@tonic-gate throw new PoolsException(); 1817c478bd9Sstevel@tonic-gate } 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate /** 1847c478bd9Sstevel@tonic-gate * Rollback the configuration, undoing any changes which have been 1857c478bd9Sstevel@tonic-gate * made since the last commit or (if there are no commits) since the 1867c478bd9Sstevel@tonic-gate * configuration was opened. 1877c478bd9Sstevel@tonic-gate * 188*99308ed0SPeter Tribble * @throws PoolsException If the rollback fails. 1897c478bd9Sstevel@tonic-gate */ rollback()1907c478bd9Sstevel@tonic-gate public void rollback() throws PoolsException 1917c478bd9Sstevel@tonic-gate { 1927c478bd9Sstevel@tonic-gate if (PoolInternal.pool_conf_rollback(getConf()) != 1937c478bd9Sstevel@tonic-gate PoolInternal.PO_SUCCESS) 1947c478bd9Sstevel@tonic-gate throw new PoolsException(); 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate /** 1987c478bd9Sstevel@tonic-gate * Commit the configuration, making any changes since the configuration 1997c478bd9Sstevel@tonic-gate * was last committed (or opened if there have been no prior commits) 2007c478bd9Sstevel@tonic-gate * permanent. 2017c478bd9Sstevel@tonic-gate * 202*99308ed0SPeter Tribble * @throws PoolsException If the commit fails. 2037c478bd9Sstevel@tonic-gate */ commit(int active)2047c478bd9Sstevel@tonic-gate public void commit(int active) throws PoolsException 2057c478bd9Sstevel@tonic-gate { 2067c478bd9Sstevel@tonic-gate if (PoolInternal.pool_conf_commit(getConf(), active) != 2077c478bd9Sstevel@tonic-gate PoolInternal.PO_SUCCESS) 2087c478bd9Sstevel@tonic-gate throw new PoolsException(); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate /** 2127c478bd9Sstevel@tonic-gate * Export the configuration, storing the current state of the 2137c478bd9Sstevel@tonic-gate * configuration at the supplied location in the supplied format. 2147c478bd9Sstevel@tonic-gate * 2157c478bd9Sstevel@tonic-gate * @param location The location of the export. 2167c478bd9Sstevel@tonic-gate * @param format The format of the export. 217*99308ed0SPeter Tribble * @throws PoolsException If the export fails. 2187c478bd9Sstevel@tonic-gate */ export(String location, int format)2197c478bd9Sstevel@tonic-gate public void export(String location, int format) throws PoolsException 2207c478bd9Sstevel@tonic-gate { 2217c478bd9Sstevel@tonic-gate if (PoolInternal.pool_conf_export(getConf(), location, format) 2227c478bd9Sstevel@tonic-gate != PoolInternal.PO_SUCCESS) 2237c478bd9Sstevel@tonic-gate throw new PoolsException(); 2247c478bd9Sstevel@tonic-gate } 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate /** 2277c478bd9Sstevel@tonic-gate * Validate the configuration, ensuring that the current state of the 2287c478bd9Sstevel@tonic-gate * configuration satisfies the supplied validation level. 2297c478bd9Sstevel@tonic-gate * 2307c478bd9Sstevel@tonic-gate * @param level The desired level of validation. 231*99308ed0SPeter Tribble * @throws PoolsException If the validation fails. 2327c478bd9Sstevel@tonic-gate */ validate(int level)2337c478bd9Sstevel@tonic-gate public void validate(int level) throws PoolsException 2347c478bd9Sstevel@tonic-gate { 2357c478bd9Sstevel@tonic-gate if (PoolInternal.pool_conf_validate(getConf(), level) 2367c478bd9Sstevel@tonic-gate != PoolInternal.PO_SUCCESS) 2377c478bd9Sstevel@tonic-gate throw new PoolsException(); 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate /** 2417c478bd9Sstevel@tonic-gate * Update the configuration, ensuring that the current state of the 2427c478bd9Sstevel@tonic-gate * configuration reflects that of the kernel. 2437c478bd9Sstevel@tonic-gate * 244*99308ed0SPeter Tribble * @throws PoolsException If the update fails. 2457c478bd9Sstevel@tonic-gate * @return a bitmap of the changed types. 2467c478bd9Sstevel@tonic-gate */ update()2477c478bd9Sstevel@tonic-gate public int update() throws PoolsException 2487c478bd9Sstevel@tonic-gate { 2497c478bd9Sstevel@tonic-gate return (PoolInternal.pool_conf_update(getConf())); 2507c478bd9Sstevel@tonic-gate } 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate /** 2537c478bd9Sstevel@tonic-gate * Create a pool with the supplied name. 2547c478bd9Sstevel@tonic-gate * 2557c478bd9Sstevel@tonic-gate * @param name The name of the PoolInternal. 256*99308ed0SPeter Tribble * @throws PoolsException If the pool creation fails. 2577c478bd9Sstevel@tonic-gate * @return a pool with the supplied name. 2587c478bd9Sstevel@tonic-gate */ createPool(String name)2597c478bd9Sstevel@tonic-gate public Pool createPool(String name) throws PoolsException 2607c478bd9Sstevel@tonic-gate { 2617c478bd9Sstevel@tonic-gate long aPool; 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate if ((aPool = PoolInternal.pool_create(getConf(), name)) == 0) { 2647c478bd9Sstevel@tonic-gate throw new PoolsException(); 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate Pool p = new Pool(this, aPool); 2677c478bd9Sstevel@tonic-gate elements.put(p.getKey(), p); 2687c478bd9Sstevel@tonic-gate return (p); 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate /** 2727c478bd9Sstevel@tonic-gate * Destroy the supplied PoolInternal. 2737c478bd9Sstevel@tonic-gate * 2747c478bd9Sstevel@tonic-gate * @param aPool The pool to be destroyed. 2757c478bd9Sstevel@tonic-gate * @throws PoolsException If the pool cannot be located. 2767c478bd9Sstevel@tonic-gate */ destroyPool(Pool aPool)2777c478bd9Sstevel@tonic-gate public void destroyPool(Pool aPool) throws PoolsException 2787c478bd9Sstevel@tonic-gate { 2797c478bd9Sstevel@tonic-gate elements.remove(aPool.getKey()); 2807c478bd9Sstevel@tonic-gate PoolInternal.pool_destroy(getConf(), aPool.getPool()); 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate /** 2847c478bd9Sstevel@tonic-gate * Get the pool with the supplied name. 2857c478bd9Sstevel@tonic-gate * 2867c478bd9Sstevel@tonic-gate * @param name The name of the pool to be found. 287*99308ed0SPeter Tribble * @throws PoolsException If the pool cannot be located. 2887c478bd9Sstevel@tonic-gate * @return a pool with the supplied name. 2897c478bd9Sstevel@tonic-gate */ getPool(String name)2907c478bd9Sstevel@tonic-gate public Pool getPool(String name) throws PoolsException 2917c478bd9Sstevel@tonic-gate { 2927c478bd9Sstevel@tonic-gate long aPool; 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate if ((aPool = PoolInternal.pool_get_pool(getConf(), name)) == 2957c478bd9Sstevel@tonic-gate 0) { 2967c478bd9Sstevel@tonic-gate throw new PoolsException(); 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate if (elements.containsKey("PoolInternal." + name)) 2997c478bd9Sstevel@tonic-gate return ((Pool) elements.get("PoolInternal." + name)); 3007c478bd9Sstevel@tonic-gate else { 3017c478bd9Sstevel@tonic-gate Pool p = new Pool(this, aPool); 3027c478bd9Sstevel@tonic-gate elements.put(p.getKey(), p); 3037c478bd9Sstevel@tonic-gate return (p); 3047c478bd9Sstevel@tonic-gate } 305*99308ed0SPeter Tribble } 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate /** 3087c478bd9Sstevel@tonic-gate * Get the proxy for the pool with the supplied name. 3097c478bd9Sstevel@tonic-gate * 3107c478bd9Sstevel@tonic-gate * @param name The name of the pool to be found. 311*99308ed0SPeter Tribble * @throws PoolsException If the pool cannot be located. 3127c478bd9Sstevel@tonic-gate * @return the proxy for the pool with the supplied name. 3137c478bd9Sstevel@tonic-gate */ checkPool(String name)3147c478bd9Sstevel@tonic-gate long checkPool(String name) throws PoolsException 3157c478bd9Sstevel@tonic-gate { 3167c478bd9Sstevel@tonic-gate long aPool; 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate if ((aPool = PoolInternal.pool_get_pool(getConf(), name)) == 3197c478bd9Sstevel@tonic-gate 0) { 3207c478bd9Sstevel@tonic-gate throw new PoolsException(); 3217c478bd9Sstevel@tonic-gate } 3227c478bd9Sstevel@tonic-gate return (aPool); 323*99308ed0SPeter Tribble } 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate /** 3267c478bd9Sstevel@tonic-gate * Get a list of pools which match the supplied selection criteria 3277c478bd9Sstevel@tonic-gate * in values. 3287c478bd9Sstevel@tonic-gate * 3297c478bd9Sstevel@tonic-gate * @param values A list of values to be used to qualify the search. 330*99308ed0SPeter Tribble * @throws PoolsException If there is an error executing the query. 3317c478bd9Sstevel@tonic-gate * @return a list of pools which match the supplied criteria 3327c478bd9Sstevel@tonic-gate */ getPools(List values)3337c478bd9Sstevel@tonic-gate public List getPools(List values) throws PoolsException 3347c478bd9Sstevel@tonic-gate { 3357c478bd9Sstevel@tonic-gate List pools; 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate if ((pools = PoolInternal.pool_query_pools(getConf(), values)) 3387c478bd9Sstevel@tonic-gate == null) { 33926d8ba22Sgarypen if (PoolInternal.pool_error() == 3407c478bd9Sstevel@tonic-gate PoolInternal.POE_INVALID_SEARCH) 3417c478bd9Sstevel@tonic-gate return new ArrayList(); 3427c478bd9Sstevel@tonic-gate else 3437c478bd9Sstevel@tonic-gate throw new PoolsException(); 3447c478bd9Sstevel@tonic-gate } 3457c478bd9Sstevel@tonic-gate ArrayList aList = new ArrayList(pools.size()); 3467c478bd9Sstevel@tonic-gate for (int i = 0; i < pools.size(); i++) 3477c478bd9Sstevel@tonic-gate aList.add(new Pool(this, 3487c478bd9Sstevel@tonic-gate ((Long)pools.get(i)).longValue())); 3497c478bd9Sstevel@tonic-gate return (aList); 3507c478bd9Sstevel@tonic-gate } 351*99308ed0SPeter Tribble 3527c478bd9Sstevel@tonic-gate /** 3537c478bd9Sstevel@tonic-gate * Create a resource with the supplied type and name. 3547c478bd9Sstevel@tonic-gate * 3557c478bd9Sstevel@tonic-gate * @param type The type of the resource. 3567c478bd9Sstevel@tonic-gate * @param name The name of the resource. 357*99308ed0SPeter Tribble * @throws PoolsException If the resource creation fails. 3587c478bd9Sstevel@tonic-gate * @return a resource of the supplied type and name. 3597c478bd9Sstevel@tonic-gate */ createResource(String type, String name)3607c478bd9Sstevel@tonic-gate public Resource createResource(String type, String name) 3617c478bd9Sstevel@tonic-gate throws PoolsException 3627c478bd9Sstevel@tonic-gate { 3637c478bd9Sstevel@tonic-gate long aResource; 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate if ((aResource = PoolInternal.pool_resource_create(getConf(), 3667c478bd9Sstevel@tonic-gate type, name)) == 0) { 3677c478bd9Sstevel@tonic-gate throw new PoolsException(); 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate Resource res = new Resource(this, aResource); 3707c478bd9Sstevel@tonic-gate elements.put(res.getKey(), res); 3717c478bd9Sstevel@tonic-gate return (res); 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate /** 3757c478bd9Sstevel@tonic-gate * Destroy the supplied resource. 3767c478bd9Sstevel@tonic-gate * 3777c478bd9Sstevel@tonic-gate * @param res The resource to be destroyed. 3787c478bd9Sstevel@tonic-gate * @throws PoolsException If the resource cannot be located. 3797c478bd9Sstevel@tonic-gate */ destroyResource(Resource res)3807c478bd9Sstevel@tonic-gate public void destroyResource(Resource res) throws PoolsException 3817c478bd9Sstevel@tonic-gate { 3827c478bd9Sstevel@tonic-gate elements.remove(res.getKey()); 3837c478bd9Sstevel@tonic-gate PoolInternal.pool_resource_destroy(getConf(), 3847c478bd9Sstevel@tonic-gate res.getResource()); 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate /** 3887c478bd9Sstevel@tonic-gate * Get the resource with the supplied name. 3897c478bd9Sstevel@tonic-gate * 3907c478bd9Sstevel@tonic-gate * @param type The type of the resource to be found. 3917c478bd9Sstevel@tonic-gate * @param name The name of the resource to be found. 392*99308ed0SPeter Tribble * @throws PoolsException If the resource cannot be located. 3937c478bd9Sstevel@tonic-gate * @return a resource with the supplied name. 3947c478bd9Sstevel@tonic-gate */ getResource(String type, String name)3957c478bd9Sstevel@tonic-gate public Resource getResource(String type, String name) 3967c478bd9Sstevel@tonic-gate throws PoolsException 3977c478bd9Sstevel@tonic-gate { 3987c478bd9Sstevel@tonic-gate long res; 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate if ((res = PoolInternal.pool_get_resource(getConf(), type, 4017c478bd9Sstevel@tonic-gate name)) == 0) { 4027c478bd9Sstevel@tonic-gate throw new PoolsException(); 4037c478bd9Sstevel@tonic-gate } 4047c478bd9Sstevel@tonic-gate if (elements.containsKey(type + "." + name)) 4057c478bd9Sstevel@tonic-gate return ((Resource) elements.get(type + "." + name)); 4067c478bd9Sstevel@tonic-gate else { 4077c478bd9Sstevel@tonic-gate Resource r = new Resource(this, res); 4087c478bd9Sstevel@tonic-gate elements.put(r.getKey(), r); 4097c478bd9Sstevel@tonic-gate return (r); 4107c478bd9Sstevel@tonic-gate } 411*99308ed0SPeter Tribble } 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate /** 4147c478bd9Sstevel@tonic-gate * Get the proxy for the resource with the supplied type and 4157c478bd9Sstevel@tonic-gate * name. 4167c478bd9Sstevel@tonic-gate * 4177c478bd9Sstevel@tonic-gate * @param type The type of the resource to be found. 4187c478bd9Sstevel@tonic-gate * @param name The name of the resource to be found. 419*99308ed0SPeter Tribble * @throws PoolsException If the resource cannot be located. 4207c478bd9Sstevel@tonic-gate * @return the proxy for the resource with the supplied name. 4217c478bd9Sstevel@tonic-gate */ checkResource(String type, String name)4227c478bd9Sstevel@tonic-gate long checkResource(String type, String name) throws PoolsException 4237c478bd9Sstevel@tonic-gate { 4247c478bd9Sstevel@tonic-gate long res; 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate if ((res = PoolInternal.pool_get_resource(getConf(), type, 4277c478bd9Sstevel@tonic-gate name)) == 0) { 4287c478bd9Sstevel@tonic-gate throw new PoolsException(); 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate return (res); 431*99308ed0SPeter Tribble } 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate /** 4347c478bd9Sstevel@tonic-gate * Get a list of resources which match the supplied selection criteria 4357c478bd9Sstevel@tonic-gate * in values. 4367c478bd9Sstevel@tonic-gate * 4377c478bd9Sstevel@tonic-gate * @param values A list of values to be used to qualify the search. 438*99308ed0SPeter Tribble * @throws PoolsException If there is an error executing the query. 4397c478bd9Sstevel@tonic-gate * @return a list of resources which match the supplied criteria 4407c478bd9Sstevel@tonic-gate */ getResources(List values)4417c478bd9Sstevel@tonic-gate public List getResources(List values) throws PoolsException 4427c478bd9Sstevel@tonic-gate { 4437c478bd9Sstevel@tonic-gate List resources; 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate if ((resources = PoolInternal.pool_query_resources(getConf(), 4467c478bd9Sstevel@tonic-gate values)) == null) { 44726d8ba22Sgarypen if (PoolInternal.pool_error() == 4487c478bd9Sstevel@tonic-gate PoolInternal.POE_INVALID_SEARCH) 4497c478bd9Sstevel@tonic-gate return new ArrayList(); 4507c478bd9Sstevel@tonic-gate else 4517c478bd9Sstevel@tonic-gate throw new PoolsException(); 4527c478bd9Sstevel@tonic-gate } 4537c478bd9Sstevel@tonic-gate ArrayList aList = new ArrayList(resources.size()); 4547c478bd9Sstevel@tonic-gate for (int i = 0; i < resources.size(); i++) 4557c478bd9Sstevel@tonic-gate aList.add(new Resource(this, 4567c478bd9Sstevel@tonic-gate ((Long)resources.get(i)).longValue())); 4577c478bd9Sstevel@tonic-gate return (aList); 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate 4607c478bd9Sstevel@tonic-gate /** 4617c478bd9Sstevel@tonic-gate * Get the component with the supplied name. 4627c478bd9Sstevel@tonic-gate * 4637c478bd9Sstevel@tonic-gate * @param type The type of the component to be found. 4647c478bd9Sstevel@tonic-gate * @param sys_id The sys_id of the component to be found. 465*99308ed0SPeter Tribble * @throws PoolsException If the component cannot be located. 4667c478bd9Sstevel@tonic-gate * @return a component with the supplied name. 4677c478bd9Sstevel@tonic-gate */ getComponent(String type, long sys_id)4687c478bd9Sstevel@tonic-gate public Component getComponent(String type, long sys_id) 4697c478bd9Sstevel@tonic-gate throws PoolsException 4707c478bd9Sstevel@tonic-gate { 4717c478bd9Sstevel@tonic-gate List props = new ArrayList(); 4727c478bd9Sstevel@tonic-gate Value ptype = new Value("type", type); 4737c478bd9Sstevel@tonic-gate Value psys_id = new Value(type + ".sys_id", sys_id); 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate props.add(ptype); 4767c478bd9Sstevel@tonic-gate props.add(psys_id); 4777c478bd9Sstevel@tonic-gate List comps = getComponents(props); 4787c478bd9Sstevel@tonic-gate ptype.close(); 4797c478bd9Sstevel@tonic-gate psys_id.close(); 4807c478bd9Sstevel@tonic-gate if (comps.size() != 1) 4817c478bd9Sstevel@tonic-gate throw new PoolsException(); 4827c478bd9Sstevel@tonic-gate return ((Component) comps.get(0)); 483*99308ed0SPeter Tribble } 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate /** 4867c478bd9Sstevel@tonic-gate * Get the component proxy with the supplied type and sys_id. 4877c478bd9Sstevel@tonic-gate * 4887c478bd9Sstevel@tonic-gate * @param type The type of the component to be found. 4897c478bd9Sstevel@tonic-gate * @param sys_id The sys_id of the component to be found. 490*99308ed0SPeter Tribble * @throws PoolsException If the component cannot be located. 4917c478bd9Sstevel@tonic-gate * @return a component with the supplied name. 4927c478bd9Sstevel@tonic-gate */ checkComponent(String type, long sys_id)4937c478bd9Sstevel@tonic-gate long checkComponent(String type, long sys_id) 4947c478bd9Sstevel@tonic-gate throws PoolsException 4957c478bd9Sstevel@tonic-gate { 4967c478bd9Sstevel@tonic-gate List props = new ArrayList(); 4977c478bd9Sstevel@tonic-gate Value ptype = new Value("type", type); 4987c478bd9Sstevel@tonic-gate Value psys_id = new Value(type + ".sys_id", sys_id); 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate props.add(ptype); 5017c478bd9Sstevel@tonic-gate props.add(psys_id); 5027c478bd9Sstevel@tonic-gate List comps = checkComponents(props); 5037c478bd9Sstevel@tonic-gate ptype.close(); 5047c478bd9Sstevel@tonic-gate psys_id.close(); 5057c478bd9Sstevel@tonic-gate if (comps.size() != 1) 5067c478bd9Sstevel@tonic-gate throw new PoolsException(); 5077c478bd9Sstevel@tonic-gate return (((Long)comps.get(0)).longValue()); 508*99308ed0SPeter Tribble } 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate /** 5117c478bd9Sstevel@tonic-gate * Get a list of components which match the supplied selection criteria 5127c478bd9Sstevel@tonic-gate * in values. 5137c478bd9Sstevel@tonic-gate * 5147c478bd9Sstevel@tonic-gate * @param values A list of values to be used to qualify the search. 515*99308ed0SPeter Tribble * @throws PoolsException If there is an error executing the query. 5167c478bd9Sstevel@tonic-gate * @return a list of components which match the supplied criteria 5177c478bd9Sstevel@tonic-gate */ getComponents(List values)5187c478bd9Sstevel@tonic-gate public List getComponents(List values) throws PoolsException 5197c478bd9Sstevel@tonic-gate { 5207c478bd9Sstevel@tonic-gate List components; 521*99308ed0SPeter Tribble 5227c478bd9Sstevel@tonic-gate if ((components = PoolInternal.pool_query_components(getConf(), 5237c478bd9Sstevel@tonic-gate values)) == null) { 52426d8ba22Sgarypen if (PoolInternal.pool_error() == 5257c478bd9Sstevel@tonic-gate PoolInternal.POE_INVALID_SEARCH) 5267c478bd9Sstevel@tonic-gate return new ArrayList(); 5277c478bd9Sstevel@tonic-gate else 5287c478bd9Sstevel@tonic-gate throw new PoolsException(); 5297c478bd9Sstevel@tonic-gate } 5307c478bd9Sstevel@tonic-gate ArrayList aList = new ArrayList(components.size()); 5317c478bd9Sstevel@tonic-gate for (int i = 0; i < components.size(); i++) { 5327c478bd9Sstevel@tonic-gate /* 5337c478bd9Sstevel@tonic-gate * Extract type information 5347c478bd9Sstevel@tonic-gate */ 5357c478bd9Sstevel@tonic-gate Value typeVal = new Value(name); 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate if (PoolInternal.pool_get_property(getConf(), 5387c478bd9Sstevel@tonic-gate ((Long)components.get(i)).longValue(), "type", 5397c478bd9Sstevel@tonic-gate typeVal.getValue()) == PoolInternal.POC_INVAL) 5407c478bd9Sstevel@tonic-gate throw new PoolsException(); 5417c478bd9Sstevel@tonic-gate if (typeVal == null) 5427c478bd9Sstevel@tonic-gate throw new PoolsException(); 5437c478bd9Sstevel@tonic-gate String type = typeVal.getString(); 5447c478bd9Sstevel@tonic-gate typeVal.close(); 5457c478bd9Sstevel@tonic-gate 5467c478bd9Sstevel@tonic-gate Value idValue = new Value(name); 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate if (PoolInternal.pool_get_property(getConf(), 5497c478bd9Sstevel@tonic-gate ((Long)components.get(i)).longValue(), 5507c478bd9Sstevel@tonic-gate type + ".sys_id", idValue.getValue()) == 5517c478bd9Sstevel@tonic-gate PoolInternal.POC_INVAL) 5527c478bd9Sstevel@tonic-gate throw new PoolsException(); 5537c478bd9Sstevel@tonic-gate if (idValue == null) 5547c478bd9Sstevel@tonic-gate throw new PoolsException(); 5557c478bd9Sstevel@tonic-gate long sys_id = idValue.getLong(); 5567c478bd9Sstevel@tonic-gate idValue.close(); 557*99308ed0SPeter Tribble 5587c478bd9Sstevel@tonic-gate if (elements.containsKey(type + "." + sys_id)) 5597c478bd9Sstevel@tonic-gate aList.add((Component)elements.get(type + "." + 5607c478bd9Sstevel@tonic-gate sys_id)); 5617c478bd9Sstevel@tonic-gate else 5627c478bd9Sstevel@tonic-gate aList.add(new Component(this, ((Long)components. 5637c478bd9Sstevel@tonic-gate get(i)).longValue())); 5647c478bd9Sstevel@tonic-gate } 5657c478bd9Sstevel@tonic-gate return (aList); 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate /** 5707c478bd9Sstevel@tonic-gate * Get a list of component proxies which match the supplied 5717c478bd9Sstevel@tonic-gate * selection criteria in values. 5727c478bd9Sstevel@tonic-gate * 5737c478bd9Sstevel@tonic-gate * @param values A list of values to be used to qualify the search. 574*99308ed0SPeter Tribble * @throws PoolsException If there is an error executing the query. 5757c478bd9Sstevel@tonic-gate * @return a list of component proxies which match the 5767c478bd9Sstevel@tonic-gate * supplied criteria 5777c478bd9Sstevel@tonic-gate */ checkComponents(List values)5787c478bd9Sstevel@tonic-gate List checkComponents(List values) throws PoolsException 5797c478bd9Sstevel@tonic-gate { 5807c478bd9Sstevel@tonic-gate List components; 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate if ((components = PoolInternal.pool_query_components(getConf(), 5837c478bd9Sstevel@tonic-gate values)) == null) { 58426d8ba22Sgarypen if (PoolInternal.pool_error() == 5857c478bd9Sstevel@tonic-gate PoolInternal.POE_INVALID_SEARCH) 5867c478bd9Sstevel@tonic-gate return new ArrayList(); 5877c478bd9Sstevel@tonic-gate else 5887c478bd9Sstevel@tonic-gate throw new PoolsException(); 5897c478bd9Sstevel@tonic-gate } 5907c478bd9Sstevel@tonic-gate return (components); 5917c478bd9Sstevel@tonic-gate } 5927c478bd9Sstevel@tonic-gate /** 5937c478bd9Sstevel@tonic-gate * Returns a descriptive string which describes the configuration. 5947c478bd9Sstevel@tonic-gate * 5957c478bd9Sstevel@tonic-gate * @param deep Whether the information should contain information about 5967c478bd9Sstevel@tonic-gate * all contained elements. 5977c478bd9Sstevel@tonic-gate * @return a descriptive string which describes the configuration. 5987c478bd9Sstevel@tonic-gate */ getInformation(int deep)5997c478bd9Sstevel@tonic-gate public String getInformation(int deep) 6007c478bd9Sstevel@tonic-gate { 6017c478bd9Sstevel@tonic-gate return (PoolInternal.pool_conf_info(_conf.getConf(), deep)); 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate /** 6057c478bd9Sstevel@tonic-gate * Returns a string representation of this configuration. 6067c478bd9Sstevel@tonic-gate * 6077c478bd9Sstevel@tonic-gate * @return a string representation of this configuration. 6087c478bd9Sstevel@tonic-gate */ toString()6097c478bd9Sstevel@tonic-gate public String toString() 6107c478bd9Sstevel@tonic-gate { 6117c478bd9Sstevel@tonic-gate StringBuffer buf = new StringBuffer(); 6127c478bd9Sstevel@tonic-gate 6137c478bd9Sstevel@tonic-gate buf.append("system: "); 6147c478bd9Sstevel@tonic-gate buf.append(name); 6157c478bd9Sstevel@tonic-gate return (buf.toString()); 6167c478bd9Sstevel@tonic-gate } 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate /** 6197c478bd9Sstevel@tonic-gate * Indicates whether some other Configuration is "equal to this one. 6207c478bd9Sstevel@tonic-gate * @param o the reference object with which to compare. 6217c478bd9Sstevel@tonic-gate * @return <code>true</code> if this object is the same as the 6227c478bd9Sstevel@tonic-gate * o argument; <code>false</code> otherwise. 6237c478bd9Sstevel@tonic-gate * @see #hashCode() 6247c478bd9Sstevel@tonic-gate */ equals(Object o)6257c478bd9Sstevel@tonic-gate public boolean equals(Object o) 6267c478bd9Sstevel@tonic-gate { 6277c478bd9Sstevel@tonic-gate if (o == this) 6287c478bd9Sstevel@tonic-gate return (true); 6297c478bd9Sstevel@tonic-gate if (!(o instanceof Configuration)) 6307c478bd9Sstevel@tonic-gate return (false); 6317c478bd9Sstevel@tonic-gate Configuration other = (Configuration) o; 6327c478bd9Sstevel@tonic-gate if (name.compareTo(other.getName()) != 0) 6337c478bd9Sstevel@tonic-gate return (false); 6347c478bd9Sstevel@tonic-gate return (true); 6357c478bd9Sstevel@tonic-gate } 6367c478bd9Sstevel@tonic-gate 6377c478bd9Sstevel@tonic-gate /** 6387c478bd9Sstevel@tonic-gate * Returns a hash code value for the object. This method is 6397c478bd9Sstevel@tonic-gate * supported for the benefit of hashtables such as those provided by 6407c478bd9Sstevel@tonic-gate * <code>java.util.Hashtable</code>. 6417c478bd9Sstevel@tonic-gate * 6427c478bd9Sstevel@tonic-gate * @return a hash code value for this object. 6437c478bd9Sstevel@tonic-gate * @see #equals(java.lang.Object) 6447c478bd9Sstevel@tonic-gate * @see java.util.Hashtable 6457c478bd9Sstevel@tonic-gate */ hashCode()6467c478bd9Sstevel@tonic-gate public int hashCode() 6477c478bd9Sstevel@tonic-gate { 6487c478bd9Sstevel@tonic-gate return name.hashCode(); 6497c478bd9Sstevel@tonic-gate } 650*99308ed0SPeter Tribble 6517c478bd9Sstevel@tonic-gate /** 6527c478bd9Sstevel@tonic-gate * Return the pointer to this configuration as an element. 6537c478bd9Sstevel@tonic-gate * 6547c478bd9Sstevel@tonic-gate * @return The pointer to the native configuration which this object 6557c478bd9Sstevel@tonic-gate * wraps. 656*99308ed0SPeter Tribble * @throws PoolsException If there is an error converting the native 6577c478bd9Sstevel@tonic-gate * configuration pointer to a native elem pointer. 6587c478bd9Sstevel@tonic-gate */ getElem()6597c478bd9Sstevel@tonic-gate protected long getElem() throws PoolsException 6607c478bd9Sstevel@tonic-gate { 6617c478bd9Sstevel@tonic-gate long elem; 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate if ((elem = PoolInternal.pool_conf_to_elem(getConf())) == 0) 6647c478bd9Sstevel@tonic-gate throw new PoolsException(); 6657c478bd9Sstevel@tonic-gate return (elem); 6667c478bd9Sstevel@tonic-gate } 6677c478bd9Sstevel@tonic-gate 6687c478bd9Sstevel@tonic-gate /** 669*99308ed0SPeter Tribble * Return the name of the configuration. 6707c478bd9Sstevel@tonic-gate */ getName()6717c478bd9Sstevel@tonic-gate String getName() 6727c478bd9Sstevel@tonic-gate { 6737c478bd9Sstevel@tonic-gate return (name); 6747c478bd9Sstevel@tonic-gate } 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate /** 6777c478bd9Sstevel@tonic-gate * Return the key of the configuration. 6787c478bd9Sstevel@tonic-gate */ getKey()6797c478bd9Sstevel@tonic-gate String getKey() 6807c478bd9Sstevel@tonic-gate { 6817c478bd9Sstevel@tonic-gate return (key); 6827c478bd9Sstevel@tonic-gate } 6837c478bd9Sstevel@tonic-gate } 684