Package org.scale7.cassandra.pelops.pool

Examples of org.scale7.cassandra.pelops.pool.CommonsBackedPool$ConnectionFactory


        assertNull("The factory should not have created the pool at this point", factoryBean.getObject());

        try {
            factoryBean.afterPropertiesSet();

            CommonsBackedPool pool = (CommonsBackedPool) factoryBean.getObject();
            assertNotNull("The factory didn't initialize the pool", pool);
            assertTrue("The factory didn't use the provided operand policy instance", operandPolicy == pool.getOperandPolicy());
            assertTrue("The factory didn't use the provided config instance", policy == pool.getPolicy());
            assertTrue("The factory didn't use the provided config instance", cluster == pool.getCluster());
            assertTrue("The factory didn't use the provided node selection instance", nodeSelectionStrategy == pool.getNodeSelectionStrategy());
            assertTrue("The factory didn't use the provided node suspension instance", nodeSuspensionStrategy == pool.getNodeSuspensionStrategy());
            assertTrue("The factory didn't use the provided connection validator instance", connectionValidator == pool.getConnectionValidator());
        } finally {
            factoryBean.destroy();
        }
    }
View Full Code Here


                {
                    logger.info("Initializing connection pool for keyspace {}, host {},port {}.", keyspace,
                            cassandraHost.getHost(), cassandraHost.getPort());
                }

                Policy policy = PelopsUtils.getPoolConfigPolicy(cassandraHost);

                // Add pool with specified policy. null means default operand
                // policy.
                Pelops.addPool(poolName, cluster, keyspace, policy, null);
                hostPools.put(cassandraHost, Pelops.getDbConnPool(poolName));
View Full Code Here

            keyspace = (String) props.get(PersistenceProperties.KUNDERA_KEYSPACE);
        }
        String poolName = PelopsUtils.generatePoolName(cassandraHost.getHost(), cassandraHost.getPort(), keyspace);
        Cluster cluster = new Cluster(cassandraHost.getHost(), new IConnection.Config(cassandraHost.getPort(), true,
                -1, PelopsUtils.getAuthenticationRequest(cassandraHost.getUser(), cassandraHost.getPassword())), false);
        Policy policy = PelopsUtils.getPoolConfigPolicy(cassandraHost);
        try
        {
            Pelops.addPool(poolName, cluster, keyspace, policy, null);
            hostPools.put(cassandraHost, Pelops.getDbConnPool(poolName));
            return true;
View Full Code Here

         */
        private final class ShufflingCompare implements Comparator<Object>
        {
            public int compare(Object o1, Object o2)
            {
                Policy policy1 = ((CommonsBackedPool) ((IThriftPool) o1)).getPolicy();
                Policy policy2 = ((CommonsBackedPool) ((IThriftPool) o2)).getPolicy();

                int activeConnections1 = ((CommonsBackedPool) ((IThriftPool) o1)).getConnectionsActive();
                int activeConnections2 = ((CommonsBackedPool) ((IThriftPool) o2)).getConnectionsActive();

                return (policy1.getMaxActivePerNode() - activeConnections1)
                        - (policy2.getMaxActivePerNode() - activeConnections2);
            }
View Full Code Here

     * @param puProperties
     * @return the pool config policy
     */
    public static Policy getPoolConfigPolicy(com.impetus.client.cassandra.service.CassandraHost cassandraHost)
    {
        Policy policy = new Policy();
        if (cassandraHost.getMaxActive() > 0)
        {
            policy.setMaxActivePerNode(cassandraHost.getMaxActive());
        }
        if (cassandraHost.getMaxIdle() > 0)
        {
            policy.setMaxIdlePerNode(cassandraHost.getMaxIdle());
        }
        if (cassandraHost.getMinIdle() > 0)
        {
            policy.setMinIdlePerNode(cassandraHost.getMinIdle());
        }
        if (cassandraHost.getMaxTotal() > 0)
        {
            policy.setMaxTotal(cassandraHost.getMaxTotal());
        }
        return policy;
    }
View Full Code Here

        assertFalse("column TTL is not in the expected state", column.isSetTtl());
    }

    @Test
    public void testWriteColumnsWithDeleteIfNullFromConstructor() throws Exception {
        IThriftPool pool = new DebuggingPool(getCluster(), KEYSPACE, new OperandPolicy(3, true));

        Bytes rowKey = Bytes.fromLong(Long.MAX_VALUE);

        Bytes colName1 = Bytes.fromInt(1);
        Bytes colName2 = Bytes.fromInt(2);

        Mutator mutator = pool.createMutator();
        assertTrue("Mutator is not in a valid state for this test", mutator.deleteIfNull);
        List<Column> columns = mutator.newColumnList(
                mutator.newColumn(colName1, (Bytes) null),
                mutator.newColumn(colName2, Bytes.fromInt(1))
        );
        mutator.writeColumns(CF, rowKey, columns);

        // make sure there is at least one deletion
        boolean isOneDeletion = false;
        for (Mutation mutation : mutator.getMutationList(CF, rowKey)) {
            if (mutation.isSetDeletion()) {
                isOneDeletion = true;
                break;
            }
        }

        assertTrue("There should be one deletion", isOneDeletion);

        pool.shutdown();
    }
View Full Code Here

        if (logger.isInfoEnabled())
        {
            // logger.info("Initializing pelops client for persistence unit {}",
            // persistenceUnit);
        }
        IThriftPool pool = getPoolUsingPolicy();
        return new PelopsClient(indexManager, reader, this, persistenceUnit, externalProperties, pool, kunderaMetadata,
                timestampGenerator);
    }
View Full Code Here

        throw new KunderaException("All hosts are down. please check servers manully.");
    }

    IPooledConnection getConnection(IThriftPool pool)
    {
        IThriftPool iThriftPool = pool;
        boolean success = false;
        while (!success)
        {
            success = true;
            if (iThriftPool != null)
            {
                Node[] nodes = ((CommonsBackedPool) iThriftPool).getCluster().getNodes();
                String host = nodes[0].getAddress();
                int thriftPort = ((CommonsBackedPool) iThriftPool).getCluster().getConnectionConfig().getThriftPort();
                CassandraHost cassandraHost = ((CassandraHostConfiguration) configuration).getCassandraHost(
                        nodes[0].getAddress(), ((CommonsBackedPool) pool).getCluster().getConnectionConfig()
                                .getThriftPort());
                if (cassandraHost.isTestOnBorrow())
                {
                    if (cassandraHost.isTestOnBorrow() && CassandraUtilities.verifyConnection(host, thriftPort))
                    {
                        // logger.info("Returning connection of {} :{} .",
                        // nodes[0].getAddress(), thriftPort);
                        return iThriftPool.getConnection();
                    }
                    removePool(iThriftPool);
                }
                else
                {
                    // logger.info("Returning connection of {} :{} .",
                    // nodes[0].getAddress(), thriftPort);
                    return iThriftPool.getConnection();
                }
                removePool(iThriftPool);
            }
            success = false;
            iThriftPool = getPoolUsingPolicy();
View Full Code Here

        throw new KunderaException("All hosts are down. please check servers manully.");
    }

    Mutator getMutator(IThriftPool pool)
    {
        IThriftPool iThriftPool = pool;
        boolean success = false;
        while (!success)
        {
            success = true;
            if (iThriftPool != null)
            {
                Node[] nodes = ((CommonsBackedPool) iThriftPool).getCluster().getNodes();
                String host = nodes[0].getAddress();
                int thriftPort = ((CommonsBackedPool) iThriftPool).getCluster().getConnectionConfig().getThriftPort();
                CassandraHost cassandraHost = ((CassandraHostConfiguration) configuration).getCassandraHost(
                        nodes[0].getAddress(), ((CommonsBackedPool) pool).getCluster().getConnectionConfig()
                                .getThriftPort());
                if (cassandraHost.isTestOnBorrow())
                {
                    if (cassandraHost.isTestOnBorrow() && CassandraUtilities.verifyConnection(host, thriftPort))
                    {
                        // logger.info("Returning mutator of {} :{} .",
                        // nodes[0].getAddress(), thriftPort);
                        return Pelops.createMutator(PelopsUtils.getPoolName(iThriftPool));
                    }
                    removePool(iThriftPool);
                }
                else
                {
                    return iThriftPool.createMutator();
                }
            }
            success = false;
            iThriftPool = getPoolUsingPolicy();
        }
View Full Code Here

        throw new KunderaException("All hosts are down. please check servers manully.");
    }

    Selector getSelector(IThriftPool pool)
    {
        IThriftPool iThriftPool = pool;
        boolean success = false;
        while (!success)
        {
            if (iThriftPool != null)
            {
View Full Code Here

TOP

Related Classes of org.scale7.cassandra.pelops.pool.CommonsBackedPool$ConnectionFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.