List of usage examples for java.util Properties size
@Override public int size()
From source file:org.jboss.tools.foundation.core.properties.internal.VersionProviderTest.java
@Test public void testLoadProperties() throws Exception { URI propertiesURI = new File("data/jbosstools-versions.properties").toURI(); Properties props = VersionPropertiesProvider.loadProperties(propertiesURI, null); assertNotNull(props);/* w ww . java 2 s . c o m*/ assertTrue(props.size() > 0); }
From source file:com.netflix.iep.dynprop.RemoteConfigurationSource.java
private Properties getProperties() throws IOException { AbstractConfiguration config = ConfigurationManager.getConfigInstance(); String vip = config.getString(VIP, "atlas_archaius-main:7001"); List<String> hosts = getHostsForVip(vip, config.getBoolean(USE_IP, false)); int numAttempts = config.getInt(NUM_RETRIES, 2) + 1; for (int i = 1; i <= numAttempts; ++i) { String host = hosts.get(i % hosts.size()); String url = "http://" + host + "/api/v1/property" + "?asg=" + getAsgName() + "&instanceId=" + getInstanceId() + "&zone=" + getZone(); logger.debug("attempt {} of {}, requesting properties from: {}", i, numAttempts, url); try {//from w w w . java 2s .com URLConnection con = new URL(url).openConnection(); con.setConnectTimeout(config.getInt(CONNECT_TIMEOUT, 1000)); con.setReadTimeout(config.getInt(READ_TIMEOUT, 5000)); Properties props = new Properties(); try (InputStream in = con.getInputStream()) { props.load(in); } logger.debug("fetched {} properties from: {}", props.size(), url); return props; } catch (IOException e) { String msg = String.format("attempt %d of %d failed, url: %s", i, numAttempts, url); if (i == numAttempts) { logger.error(msg, e); throw e; } else { logger.warn(msg, e); } } } // Shouldn't get here throw new IllegalStateException("failed to get properties"); }
From source file:com.toolsverse.etl.sql.connection.PooledAliasConnectionProvider.java
@Override protected Connection createConnection(Alias alias) throws Exception { java.sql.Driver driver = (java.sql.Driver) Class.forName(alias.getJdbcDriverClass()).newInstance(); DriverManager.registerDriver(driver); org.apache.commons.dbcp.ConnectionFactory connectionFactory = null; Properties props = Utils.getProperties(alias.getParams()); String userId = alias.getUserId(); String password = alias.getPassword(); String url = alias.getUrl();/*from ww w . ja va2s .com*/ if (props.size() > 0) { if (!Utils.isNothing(userId)) { props.put("user", userId); if (!Utils.isNothing(password)) props.put("password", password); } connectionFactory = new DriverManagerConnectionFactory(url, props); } else connectionFactory = new DriverManagerConnectionFactory(url, userId, password); ObjectPool connectionPool = new GenericObjectPool(null, _config); @SuppressWarnings("unused") PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); PoolingDataSource poolingDataSource = new PoolingDataSource(connectionPool); return poolingDataSource.getConnection(); }
From source file:de.vandermeer.skb.mvn.pm.ProjectManager.java
/** * Loads the build version file of the main project. * @throws IllegalArgumentException if any load operation failed (for instance file not found, IO error) *///from w w w . jav a2 s.c om protected void loadBuildVersions() { //if build versions are defined, load them File buildVersionFile = new File( this.configDir.toString() + File.separator + PmConstants.BUILD_VERSIONS_FILE); try { Properties buildVersions = new Properties(); // getLog().info("build versions file: " + buildVersionFile); buildVersions.load(new FileReader(buildVersionFile)); if (buildVersions.size() > 0) { this.mc.setBuildVersions(buildVersions); } } catch (FileNotFoundException e) { // getLog().warn("- cannot do dependency coordination, build-versions file does not exist: <" + buildVersionFile + ">"); } catch (IOException ioex) { throw new IllegalArgumentException( "could not read existing build-versions file, got IOException <" + ioex.getMessage() + ">"); } catch (Exception ex) { throw new IllegalArgumentException(ex.getMessage()); } }
From source file:org.wso2.carbon.identity.entitlement.policy.publisher.AbstractPolicyPublisherModule.java
public void init(Properties properties) { List<PublisherPropertyDTO> propertyDTOs = new ArrayList<PublisherPropertyDTO>(); if (properties == null || properties.size() == 0) { properties = loadProperties();//from w ww .ja v a 2 s.com } if (properties != null) { for (Map.Entry<Object, Object> entry : properties.entrySet()) { Map attributeMap; Object value = entry.getValue(); if (value instanceof Map) { attributeMap = (Map) value; } else { return; } PublisherPropertyDTO dto = new PublisherPropertyDTO(); dto.setModule(getModuleName()); dto.setId((String) entry.getKey()); if (attributeMap.get(DISPLAY_NAME) != null) { dto.setDisplayName((String) attributeMap.get(DISPLAY_NAME)); } else { log.error("Invalid policy publisher configuration : Display name can not be null"); } if (attributeMap.get(ORDER) != null) { dto.setDisplayOrder(Integer.parseInt((String) attributeMap.get(ORDER))); } if (attributeMap.get(REQUIRED) != null) { dto.setRequired(Boolean.parseBoolean((String) attributeMap.get(REQUIRED))); } if (attributeMap.get(SECRET) != null) { dto.setSecret(Boolean.parseBoolean((String) attributeMap.get(SECRET))); } propertyDTOs.add(dto); } } PublisherPropertyDTO preDefined1 = new PublisherPropertyDTO(); preDefined1.setId(PolicyPublisher.SUBSCRIBER_ID); preDefined1.setModule(getModuleName()); preDefined1.setDisplayName(PolicyPublisher.SUBSCRIBER_DISPLAY_NAME); preDefined1.setRequired(true); preDefined1.setDisplayOrder(0); propertyDTOs.add(preDefined1); PublisherDataHolder holder = new PublisherDataHolder(getModuleName()); holder.setPropertyDTOs(propertyDTOs.toArray(new PublisherPropertyDTO[propertyDTOs.size()])); EntitlementServiceComponent.getEntitlementConfig() .addModulePropertyHolder(PolicyPublisherModule.class.getName(), holder); }
From source file:org.jboss.tools.foundation.core.properties.internal.VersionProviderTest.java
@Test public void testLoadCachedProperties() throws Exception { File buildDir = new File("bin"); if (!buildDir.exists() || !buildDir.isDirectory()) { buildDir = new File("target"); }/*from ww w. j av a2s. c o m*/ File targetDir = new File(buildDir, "remotelocation"); FileUtils.deleteDirectory(targetDir); targetDir.mkdirs(); FileUtils.copyFileToDirectory(new File("data/jbosstools-versions.properties"), targetDir); File remoteFile = new File(targetDir, "jbosstools-versions.properties"); assertTrue(remoteFile.exists()); URI propertiesURI = remoteFile.toURI(); Properties props = VersionPropertiesProvider.loadProperties(propertiesURI, monitor); assertNotNull(props); assertTrue(props.size() > 0); remoteFile.delete(); assertFalse(remoteFile.exists()); Properties cache = VersionPropertiesProvider.loadProperties(propertiesURI, monitor); assertNotNull(cache); assertEquals(props, cache); }
From source file:org.fornax.toolsupport.sculptor.maven.plugin.GeneratorMojoTest.java
public void testUpdateStatusFile() throws Exception { GeneratorMojo mojo = createMojo(createProject("test2")); List<File> files = new ArrayList<File>(); files.add(new File(mojo.getProject().getBasedir(), ONE_SHOT_GENERATED_FILE)); files.add(new File(mojo.getProject().getBasedir(), GENERATED_FILE)); assertTrue(mojo.updateStatusFile(files)); Properties statusFileProps = new Properties(); statusFileProps.load(new FileReader(mojo.getStatusFile())); assertEquals(2, statusFileProps.size()); assertEquals("e747f800870423a6c554ae2ec80aeeb6", statusFileProps.getProperty(ONE_SHOT_GENERATED_FILE)); assertEquals("7d436134142a2e69dfc98eb9f22f5907", statusFileProps.getProperty(GENERATED_FILE)); }
From source file:org.apache.sqoop.repository.JdbcRepositoryProvider.java
@Override public void configurationChanged() { LOG.info("Begin JdbcRepository reconfiguring."); JdbcRepositoryContext oldRepoContext = repoContext; repoContext = new JdbcRepositoryContext(SqoopConfiguration.getInstance().getContext()); // reconfigure jdbc handler String newJdbcHandlerClassName = repoContext.getHandlerClassName(); if (newJdbcHandlerClassName == null || newJdbcHandlerClassName.trim().length() == 0) { throw new SqoopException(RepositoryError.JDBCREPO_0001, newJdbcHandlerClassName); }/*from w w w . j a v a2s. c o m*/ String oldJdbcHandlerClassName = oldRepoContext.getHandlerClassName(); if (!newJdbcHandlerClassName.equals(oldJdbcHandlerClassName)) { LOG.warn("Repository JDBC handler cannot be replaced at the runtime. " + "You might need to restart the server."); } // reconfigure jdbc driver String newJdbcDriverClassName = repoContext.getDriverClass(); if (newJdbcDriverClassName == null || newJdbcDriverClassName.trim().length() == 0) { throw new SqoopException(RepositoryError.JDBCREPO_0003, newJdbcDriverClassName); } String oldJdbcDriverClassName = oldRepoContext.getDriverClass(); if (!newJdbcDriverClassName.equals(oldJdbcDriverClassName)) { LOG.warn("Repository JDBC driver cannot be replaced at the runtime. " + "You might need to restart the server."); } // reconfigure max connection connectionPool.setMaxActive(repoContext.getMaximumConnections()); // reconfigure the url of repository String connectUrl = repoContext.getConnectionUrl(); String oldurl = oldRepoContext.getConnectionUrl(); if (connectUrl != null && !connectUrl.equals(oldurl)) { LOG.warn( "Repository URL cannot be replaced at the runtime. " + "You might need to restart the server."); } // if connection properties or transaction isolation option changes boolean connFactoryChanged = false; // compare connection properties if (!connFactoryChanged) { Properties oldProp = oldRepoContext.getConnectionProperties(); Properties newProp = repoContext.getConnectionProperties(); if (newProp.size() != oldProp.size()) { connFactoryChanged = true; } else { for (Object key : newProp.keySet()) { if (!newProp.getProperty((String) key).equals(oldProp.getProperty((String) key))) { connFactoryChanged = true; break; } } } } // compare the transaction isolation option if (!connFactoryChanged) { String oldTxOption = oldRepoContext.getTransactionIsolation().toString(); String newTxOption = repoContext.getTransactionIsolation().toString(); if (!newTxOption.equals(oldTxOption)) { connFactoryChanged = true; } } if (connFactoryChanged) { // try to reconfigure connection factory try { LOG.info("Reconfiguring Connection Factory."); Properties jdbcProps = repoContext.getConnectionProperties(); ConnectionFactory connFactory = new DriverManagerConnectionFactory(connectUrl, jdbcProps); new PoolableConnectionFactory(connFactory, connectionPool, statementPool, handler.validationQuery(), false, false, repoContext.getTransactionIsolation().getCode()); } catch (IllegalStateException ex) { // failed to reconfigure connection factory LOG.warn("Repository connection cannot be reconfigured currently. " + "You might need to restart the server."); } } // ignore the create schema option, because the repo url is not allowed to change LOG.info("JdbcRepository reconfigured."); }
From source file:com.redhat.rhn.common.conf.test.ConfigTest.java
public void testNamespaceProperties() throws Exception { Properties prop = c.getNamespaceProperties("web"); assertTrue(prop.size() >= 8); for (Iterator i = prop.keySet().iterator(); i.hasNext();) { String key = (String) i.next(); assertTrue(key.startsWith("web")); }/*from w ww .j av a2 s.co m*/ }
From source file:net.padlocksoftware.padlock.license.LicenseImplTest.java
/** * Test of getProperties method, of class LicenseImpl. *//*from www. jav a 2 s. co m*/ public void testGetProperties() { System.out.println("getProperties"); LicenseImpl instance = new LicenseImpl(); Properties result = instance.getProperties(); assertEquals(0, result.size()); Map<String, String> propertyMap = new HashMap<String, String>(); propertyMap.put("property1", "value1"); propertyMap.put("property2", "value2"); propertyMap.put("property3", "value3"); for (String key : propertyMap.keySet()) { instance.addProperty(key, propertyMap.get(key)); } result = instance.getProperties(); assertEquals(propertyMap.size(), result.size()); for (String property : LicenseImpl.propertyNames(result)) { String expectedValue = propertyMap.get(property); String resultValue = result.getProperty(property); assertEquals(expectedValue, resultValue); } }