Package org.scale7.cassandra.pelops.pool

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


        {
            CassandraHost cassandraHost = (CassandraHost) host;
            String poolName = PelopsUtils.generatePoolName(cassandraHost.getHost(), cassandraHost.getPort(), keyspace);
            if (CassandraUtilities.verifyConnection(cassandraHost.getHost(), cassandraHost.getPort()))
            {
                Cluster cluster = new Cluster(cassandraHost.getHost(), new IConnection.Config(cassandraHost.getPort(),
                        true, -1, PelopsUtils.getAuthenticationRequest(cassandraHost.getUser(),
                                cassandraHost.getPassword())), false);

                if (logger.isInfoEnabled())
                {
View Full Code Here


        if (keyspace == null)
        {
            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);
View Full Code Here

     */
    @Test
    public void testInitWithDownedNode() throws Exception {
        final int timeout = 2000;
        final int allowedDeviation = 10; // allowed timeout deviation in percentage
        Cluster cluster = new Cluster(new String[] {RPC_LISTEN_ADDRESS, "192.0.2.0"}, new IConnection.Config(RPC_PORT, true, timeout), false);

        CommonsBackedPool.Policy config = new CommonsBackedPool.Policy();
        config.setTimeBetweenScheduledMaintenanceTaskRunsMillis(-1); // disable the background thread
        config.setMaxActivePerNode(1);

View Full Code Here

    }

    colFamilyDefs = columnDefinitions;

    keyspaceManager = new KeyspaceManager(cluster);
    columnFamilyManager = new ColumnFamilyManager(cluster, KEYSPACE);

    List<KsDef> keyspaces = keyspaceManager.getKeyspaceNames();
    for (KsDef ksDef : keyspaces)
      if (ksDef.name.equals(KEYSPACE)) {
        keyspaceManager.dropKeyspace(KEYSPACE);
View Full Code Here

      Thread.sleep(2000);
    }

    colFamilyDefs = columnDefinitions;

    keyspaceManager = new KeyspaceManager(cluster);
    columnFamilyManager = new ColumnFamilyManager(cluster, KEYSPACE);

    List<KsDef> keyspaces = keyspaceManager.getKeyspaceNames();
    for (KsDef ksDef : keyspaces)
      if (ksDef.name.equals(KEYSPACE)) {
View Full Code Here

     *            A HashMap of field/value pairs to insert in the record
     * @return Zero on success, a non-zero error code on error
     */
    public int insert(String table, String key, HashMap<String, ByteIterator> values)
    {
        Mutator mutator =
                Pelops.createMutator(_host + ":" + _port + ":" + _keyspace);
        try
        {
            List<Column> columns = new ArrayList<Column>();
            for (Map.Entry<String, ByteIterator> entry : values.entrySet())
            {
                Column col = new Column();
                col.setName(ByteBuffer.wrap(entry.getKey().getBytes("UTF-8")));
                col.setValue(ByteBuffer.wrap(entry.getValue().toArray()));
                col.setTimestamp(System.currentTimeMillis());

                columns.add(col);
            }

            mutator.writeColumns(column_family, Bytes.fromUTF8(key), columns);
            mutator.execute(writeConsistencyLevel);

            return Ok;
        }
        catch (Exception e)
        {
View Full Code Here

        if (invertedIndexingApplicable)
        {
            String indexColumnFamily = CassandraIndexHelper.getInvertedIndexTableName(entityMetadata.getTableName());

            Mutator mutator = pelopsClient.getMutator();

            List<ThriftRow> indexThriftyRows = ((PelopsDataHandler) cdHandler).toIndexThriftRow(node.getData(),
                    entityMetadata, indexColumnFamily);

            for (ThriftRow thriftRow : indexThriftyRows)
            {

                List<Column> thriftColumns = thriftRow.getColumns();
                List<SuperColumn> thriftSuperColumns = thriftRow.getSuperColumns();
                if (thriftColumns != null && !thriftColumns.isEmpty())
                {
                    // Bytes.fromL
                    mutator.writeColumns(thriftRow.getColumnFamilyName(), Bytes.fromByteBuffer(CassandraUtilities
                            .toBytes(thriftRow.getId(), thriftRow.getId().getClass())), Arrays.asList(thriftRow
                            .getColumns().toArray(new Column[0])));
                }

                if (thriftSuperColumns != null && !thriftSuperColumns.isEmpty())
                {
                    for (SuperColumn sc : thriftSuperColumns)
                    {
                        mutator.writeSubColumns(thriftRow.getColumnFamilyName(), Bytes
                                .fromByteBuffer(CassandraUtilities.toBytes(thriftRow.getId(), thriftRow.getId()
                                        .getClass())), Bytes.fromByteArray(sc.getName()), sc.getColumns());
                    }
                }
            }
            mutator.execute(consistencyLevel);
            indexThriftyRows = null;
        }
    }
View Full Code Here

     * @param mutator
     */
    public void deleteColumn(String indexColumnFamily, String rowKey, byte[] superColumnName, String persistenceUnit,
            ConsistencyLevel consistencyLevel, byte[] columnName)
    {
        Mutator mutator = pelopsClient.getMutator();
        mutator.deleteColumn(indexColumnFamily, rowKey, Bytes.fromByteArray(superColumnName));
        mutator.execute(consistencyLevel);
    }
View Full Code Here

    /**
     * Persists records into Join Table
     */
    public void persistJoinTable(JoinTableData joinTableData)
    {
        Mutator mutator = clientFactory.getMutator(pool);

        String joinTableName = joinTableData.getJoinTableName();
        String invJoinColumnName = joinTableData.getInverseJoinColumnName();
        Map<Object, Set<Object>> joinTableRecords = joinTableData.getJoinTableRecords();
        EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata,
                joinTableData.getEntityClass());

        if (isCql3Enabled(entityMetadata))
        {
            Cassandra.Client conn = null;
            Object pooledConnection = null;
            pooledConnection = getConnection();
            conn = (org.apache.cassandra.thrift.Cassandra.Client) getConnection(pooledConnection);
            persistJoinTableByCql(joinTableData, conn);
        }
        else
        {
            for (Object key : joinTableRecords.keySet())
            {
                Set<Object> values = joinTableRecords.get(key);

                List<Column> columns = new ArrayList<Column>();

                Class columnType = null;
                for (Object value : values)
                {
                    Column column = new Column();
                    column.setName(PropertyAccessorFactory.STRING.toBytes(invJoinColumnName
                            + Constants.JOIN_COLUMN_NAME_SEPARATOR + value.toString()));
                    column.setValue(PropertyAccessorHelper.getBytes(value));
                    column.setTimestamp(generator.getTimestamp());
                    columnType = value.getClass();
                    columns.add(column);
                }

                createIndexesOnColumns(entityMetadata, joinTableName, columns, columnType);

                mutator.writeColumns(joinTableName, Bytes.fromByteArray(PropertyAccessorHelper.getBytes(key)),
                        Arrays.asList(columns.toArray(new Column[0])));
            }
        }
        if (log.isInfoEnabled())
        {
            log.info(" Persisted data with join table column family {}", joinTableData.getJoinTableName());
        }
        mutator.execute(getConsistencyLevel());
    }
View Full Code Here

                if (tf.getColumnFamilyName().equals(metadata.getTableName()))
                {
                    addRelationsToThriftRow(metadata, tf, rlHolders);
                }
                Mutator mutator = clientFactory.getMutator(pool);
                if (metadata.isCounterColumnType())
                {
                    if (log.isInfoEnabled())
                    {
                        log.info("Persisting counter column family record for row key {}", tf.getId());
                    }
                    List<CounterColumn> thriftCounterColumns = tf.getCounterColumns();
                    List<CounterSuperColumn> thriftCounterSuperColumns = tf.getCounterSuperColumns();
                    if (thriftCounterColumns != null && !thriftCounterColumns.isEmpty())
                    {
                        mutator.writeCounterColumns(tf.getColumnFamilyName(),
                                Bytes.fromByteBuffer(CassandraUtilities.toBytes(tf.getId(), tf.getId().getClass())),
                                Arrays.asList(tf.getCounterColumns().toArray(new CounterColumn[0])));
                    }

                    if (thriftCounterSuperColumns != null && !thriftCounterSuperColumns.isEmpty())
                    {
                        for (CounterSuperColumn sc : thriftCounterSuperColumns)
                        {
                            mutator.writeSubCounterColumns(
                                    tf.getColumnFamilyName(),
                                    Bytes.fromByteBuffer(CassandraUtilities.toBytes(tf.getId(), tf.getId().getClass())),
                                    Bytes.fromByteArray(sc.getName()), sc.getColumns());
                        }
                    }
                }
                else
                {
                    List<Column> thriftColumns = tf.getColumns();
                    List<SuperColumn> thriftSuperColumns = tf.getSuperColumns();
                    if (thriftColumns != null && !thriftColumns.isEmpty())
                    {
                        // Bytes.from
                        mutator.writeColumns(tf.getColumnFamilyName(),
                                Bytes.fromByteBuffer(CassandraUtilities.toBytes(tf.getId(), tf.getId().getClass())),
                                tf.getColumns());
                    }

                    if (thriftSuperColumns != null && !thriftSuperColumns.isEmpty())
                    {
                        for (SuperColumn sc : thriftSuperColumns)
                        {
                            if (log.isInfoEnabled())
                            {
                                log.info("Persisting super column family record for row key {}", tf.getId());
                            }

                            mutator.writeSubColumns(
                                    tf.getColumnFamilyName(),
                                    Bytes.fromByteBuffer(CassandraUtilities.toBytes(tf.getId(), tf.getId().getClass())),
                                    Bytes.fromByteArray(sc.getName()), sc.getColumns());
                        }
                    }
                }
                mutator.execute(getConsistencyLevel());
            }
            tfRows = null;
            if (isTtlPerRequest())
            {
                getTtlValues().clear();
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.