/** * <p> * Obtains an immutable pair of from two objects inferring the generic * types. * </p> * * <p> * This factory allows the pair to be created using inference to obtain the * generic types. * </p> * * @param <L> * the left element type * @param <R> * the right element type * @param left * the left element, may be null * @param right * the right element, may be null * @return a pair formed from the two parameters, not null * @since 1.4 */ public static <L, R> Pair<L, R> of(final L left, final R right) { return new Pair<L, R>(left, right); }
public ObjectPool<PoolableConnector> getPool() { if (apiConfiguration.isConnectorPoolingSupported()) { if (null == connectorPoolKey) { Pair<ConnectorPoolManager.ConnectorPoolKey, ObjectPool<PoolableConnector>> pool = ConnectorPoolManager.getPool(apiConfiguration, connectorInfo); connectorPoolKey = pool.getKey(); return pool.getValue(); } else { ObjectPool<PoolableConnector> pool = ConnectorPoolManager.getPool(connectorPoolKey); if (null == pool) { // Pair<ConnectorPoolManager.ConnectorPoolKey, ObjectPool<PoolableConnector>> poolPair = ConnectorPoolManager.getPool(apiConfiguration, connectorInfo); connectorPoolKey = poolPair.getKey(); pool = poolPair.getValue(); } return pool; } } else { return null; } }
private static Pair<ConnectorPoolKey, ObjectPool<PoolableConnector>> getPool2( final APIConfigurationImpl impl, final LocalConnectorInfoImpl localInfo) throws InstantiationException, IllegalAccessException { // determine if this connector wants generic connector pooling.. if (impl.isConnectorPoolingSupported()) { ConnectorPoolKey key = new ConnectorPoolKey(impl.getConnectorInfo().getConnectorKey(), impl .getConfigurationProperties(), impl.getConnectorPoolConfiguration()); // get the pool associated.. ObjectPool<PoolableConnector> pool = POOLS.get(key); // create a new pool if it doesn't exist.. if (pool == null) { LOG.info("Creating new pool: {0}", impl.getConnectorInfo().getConnectorKey()); // this instance is strictly used for the pool.. pool = new ObjectPool<>( new ConnectorPoolHandler(impl, localInfo), impl.getConnectorPoolConfiguration()); // add back to the map of POOLS.. ObjectPool<PoolableConnector> previousPool = POOLS.putIfAbsent(key, pool); // Use the pool made by other thread if (previousPool != null) { pool = previousPool; } } return Pair.of(key, pool); } else if (!localInfo.isConfigurationStateless()) { return Pair.of(new ConnectorPoolKey(impl.getConnectorInfo().getConnectorKey(), impl .getConfigurationProperties(), impl.getConnectorPoolConfiguration()), null); } return Pair.of(null, null); }
public ObjectPool<PoolableConnector> getPool() { if (apiConfiguration.isConnectorPoolingSupported()) { if (null == connectorPoolKey) { Pair<ConnectorPoolManager.ConnectorPoolKey, ObjectPool<PoolableConnector>> pool = ConnectorPoolManager.getPool(apiConfiguration, connectorInfo); connectorPoolKey = pool.getKey(); return pool.getValue(); } else { ObjectPool<PoolableConnector> pool = ConnectorPoolManager.getPool(connectorPoolKey); if (null == pool) { // Pair<ConnectorPoolManager.ConnectorPoolKey, ObjectPool<PoolableConnector>> poolPair = ConnectorPoolManager.getPool(apiConfiguration, connectorInfo); connectorPoolKey = poolPair.getKey(); pool = poolPair.getValue(); } return pool; } } else { return null; } }
private static Pair<ConnectorPoolKey, ObjectPool<PoolableConnector>> getPool2( final APIConfigurationImpl impl, final LocalConnectorInfoImpl localInfo) throws InstantiationException, IllegalAccessException { // determine if this connector wants generic connector pooling.. if (impl.isConnectorPoolingSupported()) { ConnectorPoolKey key = new ConnectorPoolKey(impl.getConnectorInfo().getConnectorKey(), impl .getConfigurationProperties(), impl.getConnectorPoolConfiguration()); // get the pool associated.. ObjectPool<PoolableConnector> pool = POOLS.get(key); // create a new pool if it doesn't exist.. if (pool == null) { LOG.info("Creating new pool: {0}", impl.getConnectorInfo().getConnectorKey()); // this instance is strictly used for the pool.. pool = new ObjectPool<>( new ConnectorPoolHandler(impl, localInfo), impl.getConnectorPoolConfiguration()); // add back to the map of POOLS.. ObjectPool<PoolableConnector> previousPool = POOLS.putIfAbsent(key, pool); // Use the pool made by other thread if (previousPool != null) { pool = previousPool; } } return Pair.of(key, pool); } else if (!localInfo.isConfigurationStateless()) { return Pair.of(new ConnectorPoolKey(impl.getConnectorInfo().getConnectorKey(), impl .getConfigurationProperties(), impl.getConnectorPoolConfiguration()), null); } return Pair.of(null, null); }
/** * <p> * Obtains an immutable pair of from two objects inferring the generic * types. * </p> * * <p> * This factory allows the pair to be created using inference to obtain the * generic types. * </p> * * @param <L> * the left element type * @param <R> * the right element type * @param left * the left element, may be null * @param right * the right element, may be null * @return a pair formed from the two parameters, not null * @since 1.4 */ public static <L, R> Pair<L, R> of(final L left, final R right) { return new Pair<L, R>(left, right); }
private Pair<Bundle, List<ConnectorInfo>> processBundle(Bundle bundle, List<ManifestEntry> list) { Pair<Bundle, List<ConnectorInfo>> result = null; try { List<ConnectorInfo> info = createConnectorInfo(bundle, list); if (!info.isEmpty()) { result = new Pair<>(bundle, info); } } catch (Throwable t) { LOG.error("ConnectorBundel {} loading failed.", bundle.getSymbolicName(), t); } return result; }
@Test public void hash() { Set<Pair<Integer, Integer>> set = new HashSet<>(); for (int i = 0; i < 20; i++) { Pair<Integer, Integer> pair = new Pair<>(i, i + 1); Pair<Integer, Integer> tst = new Pair<>(i, i + 1); set.add(pair); assertTrue(set.contains(tst)); } // check that each pair is unique.. assertEquals(20, set.size()); } }