me.prettyprint.hector.api.mutation.Mutator Java Examples

The following examples show how to use me.prettyprint.hector.api.mutation.Mutator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraPersistenceUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public static void addInsertToMutator( Mutator<ByteBuffer> m, Object columnFamily, Object key, Object columnName,
                                       Object columnValue, long timestamp ) {

    logBatchOperation( "Insert", columnFamily, key, columnName, columnValue, timestamp );

    if ( columnName instanceof List<?> ) {
        columnName = DynamicComposite.toByteBuffer( ( List<?> ) columnName );
    }
    if ( columnValue instanceof List<?> ) {
        columnValue = DynamicComposite.toByteBuffer( ( List<?> ) columnValue );
    }

    HColumn<ByteBuffer, ByteBuffer> column =
            createColumn( bytebuffer( columnName ), bytebuffer( columnValue ), timestamp, be, be );
    m.addInsertion( bytebuffer( key ), columnFamily.toString(), column );
}
 
Example #2
Source File: HectorPolicyManagerImpl.java    From ck with Apache License 2.0 6 votes vote down vote up
@Override
public void persist(PolicyDAO policy) {
    PolicyDAOImpl impl = getImpl(policy, PolicyDAOImpl.class);
    UUID policyID = impl.getPolicyID().getUUID();

    Mutator<UUID> m = Schema.POLICIES.createMutator(_keyspace);

    Schema.POLICIES.SHORT_NAME.addInsertion(m, policyID, policy.getShortName());
    Schema.POLICIES.DESCRIPTION.addInsertion(m, policyID, policy.getDescription());

    // We're saving changes, so update the edit time
    Schema.POLICIES.LAST_EDITED.addInsertion(m, policyID, new Date());

    // TODO: error handling? Throws HectorException.
    m.execute();
}
 
Example #3
Source File: CpEntityManager.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public void addSetToDictionary( EntityRef entityRef, String dictionaryName, Set<?> elementValues )
        throws Exception {

    if ( ( elementValues == null ) || elementValues.isEmpty() ) {
        return;
    }

    EntityRef entity = get( entityRef );

    UUID timestampUuid = UUIDUtils.newTimeUUID();
    Mutator<ByteBuffer> batch = createMutator( cass.getApplicationKeyspace( applicationId ), be );

    for ( Object elementValue : elementValues ) {
        batch = batchUpdateDictionary( batch, entity, dictionaryName, elementValue, null, false, timestampUuid );
    }

    //Adding graphite metrics
    Timer.Context timeAddingSetDictionary = entAddDictionarySetTimer.time();
    CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
    timeAddingSetDictionary.stop();
}
 
Example #4
Source File: AbstractSearch.java    From usergrid with Apache License 2.0 6 votes vote down vote up
/**
 * Write the updated client pointer
 *
 * @param lastReturnedId This is a null safe parameter. If it's null, this won't be written since it means we didn't
 * read any messages
 */
protected void writeClientPointer( UUID queueId, UUID consumerId, UUID lastReturnedId ) {
    // nothing to do
    if ( lastReturnedId == null ) {
        return;
    }

    // we want to set the timestamp to the value from the time uuid. If this is
    // not the max time uuid to ever be written
    // for this consumer, we want this to be discarded to avoid internode race
    // conditions with clock drift.
    long colTimestamp = UUIDUtils.getTimestampInMicros( lastReturnedId );

    Mutator<UUID> mutator = CountingMutator.createFlushingMutator( ko, ue );

    if ( logger.isDebugEnabled() ) {
        logger.debug( "Writing last client id pointer of '{}' for queue '{}' and consumer '{}' with timestamp '{}",
                        lastReturnedId, queueId, consumerId, colTimestamp
                );
    }

    mutator.addInsertion( consumerId, CONSUMERS.getColumnFamily(),
            createColumn( queueId, lastReturnedId, colTimestamp, ue, ue ) );

    mutator.execute();
}
 
Example #5
Source File: CpEntityManager.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public void incrementAggregateCounters( UUID userId, UUID groupId, String category, Map<String, Long> counters ) {

    // TODO shortcircuit
    if ( !skipAggregateCounters ) {
        long timestamp = cass.createTimestamp();
        Mutator<ByteBuffer> m = createMutator( cass.getApplicationKeyspace( applicationId ), be );
        counterUtils.batchIncrementAggregateCounters(
            m, applicationId, userId, groupId, null, category, counters, timestamp );

        //Adding graphite metrics
        Timer.Context timeIncrementCounters =entIncrementAggregateCountersTimer.time();
        CassandraPersistenceUtils.batchExecute( m, CassandraService.RETRY_COUNT );
        timeIncrementCounters.stop();
    }
}
 
Example #6
Source File: SecondaryIndexDeletionBuffer.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * Flushes the buffer.
 * 
 * @param mutator The mutator to fill with deletions.
 * @param columnFamilyName The column family (name) to delete from.
 * @param column The column to delete from.
 * @param serializer The serializer to use for the column.
 * @param dao the rdf index data access object.
 * @param <T> The type of the column key.
 * @return True if the buffer was flushed and at least one element was checked for deletion, false otherwise.
 * @throws DataAccessLayerException in case of data access failure.
 */
<T> boolean flush(
		final Mutator<byte[]> mutator, 
		final String columnFamilyName, 
		final T column, 
		final Serializer<T> serializer,
		final TripleIndexDAO dao) throws DataAccessLayerException {
	if (_candidates.size() == 0) {
		return false;
	}
	
	for (SecondaryIndexDeletionCandidate candidate : _candidates) {
		if (!dao.query(candidate.getQuery(), 1).hasNext()) {
			mutator.addDeletion(candidate.getRow(), columnFamilyName, column, serializer);
		}
	}
	
	return true;
}
 
Example #7
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public void batchUpdateQueuePropertiesIndexes( Mutator<ByteBuffer> batch, UUID publisherQueueId,
                                               String subscriberQueuePath, UUID subscriberQueueId,
                                               Map<String, Object> properties, UUID timestampUuid )
        throws Exception {

    for ( Map.Entry<String, Object> property : properties.entrySet() ) {

        if ( !Queue.QUEUE_PROPERTIES.containsKey( property.getKey() ) ) {

            QueueIndexUpdate indexUpdate =
                    batchStartQueueIndexUpdate( batch, subscriberQueuePath, subscriberQueueId, property.getKey(),
                            property.getValue(), timestampUuid );

            batchUpdateQueueIndex( indexUpdate, publisherQueueId );
        }
    }
}
 
Example #8
Source File: CounterUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
private void handleAggregateCounterRow( Mutator<ByteBuffer> m, String key, long column, long value,
                                        UUID applicationId ) {
    if ( logger.isTraceEnabled() ) {
        logger.trace( "HACR: aggregateRow for app {} with key {} column {} and value {}",
                applicationId, key, column, value );
    }
    if ( "o".equals( counterType ) || "p".equals( counterType ) ) {
        if ( m != null ) {
            HCounterColumn<Long> c = createCounterColumn( column, value, le );
            m.addCounter( bytebuffer( key ), APPLICATION_AGGREGATE_COUNTERS.toString(), c );
        }
    }
    if ( "n".equals( counterType ) || "p".equals( counterType ) ) {
        // create and add Count
        PrefixedSerializer ps =
                new PrefixedSerializer( applicationId, ue, se );
        batcher.add(
                new Count( APPLICATION_AGGREGATE_COUNTERS.toString(), ps.toByteBuffer( key ), column, value ) );
    }
}
 
Example #9
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a role to the role store.
 */
@Override
public void doAddRole(String roleName, String[] userList, boolean shared) throws UserStoreException {

    Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get());
    Composite composite = new Composite();
    composite.addComponent(roleName, stringSerializer);
    composite.addComponent(tenantIdString, stringSerializer);

    mutator.addInsertion(composite, CFConstants.UM_ROLES,
            HFactory.createColumn(CFConstants.UM_ROLE_NAME, roleName, stringSerializer, stringSerializer));
    mutator.addInsertion(composite, CFConstants.UM_ROLES,
            HFactory.createColumn(CFConstants.UM_TENANT_ID, tenantIdString, stringSerializer, stringSerializer));

    if (userList != null && userList.length > 0) {
        addRoleToUsersList(userList, roleName, mutator);
    }

    mutator.execute();
}
 
Example #10
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Maps the users to a role list. Adds the (username, tenantId) -> roleList
 * and (role, tenantId) -> userName
 *
 * @param userName The username of the user the roles need to be added to.
 * @param roleList The list of roles that needs to be mapped against the user.
 */
private void addUserToRoleList(String userName, String[] roleList) {

    Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get());

    if (roleList != null) {
        for (String role : roleList) {
            Composite key = new Composite();
            key.addComponent(userName, stringSerializer);
            key.addComponent(tenantIdString, stringSerializer);

            mutator.addInsertion(key, CFConstants.UM_USER_ROLE, HFactory.createColumn(role, role));

            Composite keyRole = new Composite();
            keyRole.addComponent(role, stringSerializer);
            keyRole.addComponent(tenantIdString, stringSerializer);

            mutator.addInsertion(keyRole, CFConstants.UM_ROLE_USER_INDEX, HFactory.createColumn(userName, userName));

        }
        mutator.execute();
    }
}
 
Example #11
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Maps the users to a role list. Adds the (username, tenantId) -> roleList
 * and (role, tenantId) -> userName
 *
 * @param userName The username of the user the roles need to be added to.
 * @param roleList The list of roles that needs to be mapped against the user.
 * @param mutator  Passes the mutator and returns it with the insert statements.
 */
private Mutator<Composite> addUserToRoleList(String userName, String[] roleList, Mutator<Composite> mutator) {
    if (roleList != null && mutator != null) {
        for (String role : roleList) {
            Composite key = new Composite();
            key.addComponent(userName, stringSerializer);
            key.addComponent(tenantIdString, stringSerializer);

            mutator.addInsertion(key, CFConstants.UM_USER_ROLE, HFactory.createColumn(role, role));

            Composite keyRole = new Composite();
            keyRole.addComponent(role, stringSerializer);
            keyRole.addComponent(tenantIdString, stringSerializer);

            mutator.addInsertion(keyRole, CFConstants.UM_ROLE_USER_INDEX, HFactory.createColumn(userName, userName));

        }
    }
    return mutator;
}
 
Example #12
Source File: CounterUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public void batchIncrementAggregateCounters( Mutator<ByteBuffer> m, UUID applicationId, UUID userId, UUID groupId,
                                             UUID queueId, String category, String name, long value,
                                             long counterTimestamp, long cassandraTimestamp ) {
    for ( CounterResolution resolution : CounterResolution.values() ) {
        if (logger.isTraceEnabled()) {
            logger.trace("BIAC for resolution {}", resolution);
        }

        batchIncrementAggregateCounters( m, userId, groupId, queueId, category, resolution, name, value,
                counterTimestamp, applicationId );

        if (logger.isTraceEnabled()) {
            logger.trace("DONE BIAC for resolution {}", resolution);
        }
    }
    batchIncrementEntityCounter( m, applicationId, name, value, cassandraTimestamp, applicationId );
    if ( userId != null ) {
        batchIncrementEntityCounter( m, userId, name, value, cassandraTimestamp, applicationId );
    }
    if ( groupId != null ) {
        batchIncrementEntityCounter( m, groupId, name, value, cassandraTimestamp, applicationId );
    }
}
 
Example #13
Source File: CassandraMetadataRepository.java    From archiva with Apache License 2.0 6 votes vote down vote up
protected void recordLicenses( String projectVersionMetadataKey, List<License> licenses )
{

    if ( licenses == null || licenses.isEmpty() )
    {
        return;
    }
    Mutator<String> licenseMutator = this.licenseTemplate.createMutator();

    for ( License license : licenses )
    {
        // we don't care about the key as the real used one with the projectVersionMetadata
        String keyLicense = UUID.randomUUID().toString();
        String cfLicense = cassandraArchivaManager.getLicenseFamilyName();

        addInsertion( licenseMutator, keyLicense, cfLicense, "projectVersionMetadataModel.key",
                      projectVersionMetadataKey );

        addInsertion( licenseMutator, keyLicense, cfLicense, NAME.toString(), license.getName() );

        addInsertion( licenseMutator, keyLicense, cfLicense, URL.toString(), license.getUrl() );

    }
    licenseMutator.execute();
}
 
Example #14
Source File: CpEntityManager.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void revokeRolePermission( String roleName, String permission ) throws Exception {
    roleName = roleName.toLowerCase();
    permission = permission.toLowerCase();
    long timestamp = cass.createTimestamp();
    Mutator<ByteBuffer> batch = createMutator( cass.getApplicationKeyspace( applicationId ), be);
    CassandraPersistenceUtils.addDeleteToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES,
        getRolePermissionsKey( roleName ), permission, timestamp );
    //Adding graphite metrics
    Timer.Context timeRevokeRolePermission = entRevokeRolePermissionsTimer.time();
    CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
    timeRevokeRolePermission.stop();
}
 
Example #15
Source File: ConsumerTransaction.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/** Delete the specified transaction */
private void deleteTransaction( UUID queueId, UUID consumerId, UUID transactionId )
{

    Mutator<ByteBuffer> mutator = CountingMutator.createFlushingMutator( ko, be );
    ByteBuffer key = getQueueClientTransactionKey( queueId, consumerId );

    mutator.addDeletion( key, CONSUMER_QUEUE_TIMEOUTS.getColumnFamily(), transactionId, ue,
            cass.createTimestamp() );

    mutator.execute();
}
 
Example #16
Source File: CassandraPersistenceUtils.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public static void addInsertToMutator( Mutator<ByteBuffer> m, Object columnFamily, Object key, Map<?, ?> columns,
                                       long timestamp ) throws Exception {

    for ( Entry<?, ?> entry : columns.entrySet() ) {
        addInsertToMutator( m, columnFamily, key, entry.getKey(), entry.getValue(), timestamp );
    }
}
 
Example #17
Source File: ConsumerTransaction.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * Delete all re-read transaction pointers
 *
 * @param pointers The list of transaction pointers
 * @param maxIndex The index to stop at (exclusive)
 * @param queueId The queue id
 * @param consumerId The consumer id
 */
protected void deleteTransactionPointers( List<TransactionPointer> pointers, int maxIndex, UUID queueId,
                                          UUID consumerId )
{

    if ( maxIndex == 0 || pointers.size() == 0 )
    {
        return;
    }

    Mutator<ByteBuffer> mutator = CountingMutator.createFlushingMutator( ko, be );
    ByteBuffer key = getQueueClientTransactionKey( queueId, consumerId );

    for ( int i = 0; i < maxIndex && i < pointers.size(); i++ )
    {
        UUID pointer = pointers.get( i ).expiration;

        if ( logger.isTraceEnabled() )
        {
            logger.trace( "Removing transaction pointer '{}' for queue '{}' and consumer '{}'",
                    pointer, queueId, consumerId
            );
        }

        mutator.addDeletion( key, CONSUMER_QUEUE_TIMEOUTS.getColumnFamily(), pointer, ue, cass.createTimestamp() );
    }

    mutator.execute();
}
 
Example #18
Source File: QueueIndexUpdate.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public QueueIndexUpdate( Mutator<ByteBuffer> batch, String queuePath, UUID queueId, String entryName,
                         Object entryValue, UUID timestampUuid ) {
    this.batch = batch;
    this.queuePath = queuePath;
    this.queueId = queueId;
    this.entryName = entryName;
    this.entryValue = entryValue;
    timestamp = getTimestampInMicros( timestampUuid );
    this.timestampUuid = timestampUuid;
}
 
Example #19
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void incrementAggregateQueueCounters( String queuePath, String category, String counterName, long value ) {
    long timestamp = cass.createTimestamp();
    Mutator<ByteBuffer> m = CountingMutator.createFlushingMutator( cass.getApplicationKeyspace( applicationId ),
            be );
    counterUtils.batchIncrementAggregateCounters( m, applicationId, null, null, getQueueId( queuePath ), category,
            counterName, value, timestamp );
    batchExecute( m, CassandraService.RETRY_COUNT );
}
 
Example #20
Source File: CountingMutator.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public <SN, N> Mutator<K> addSubDelete( final K key, final String cf, final SN sColumnName, final N columnName,
                                        final Serializer<SN> sNameSerializer, final Serializer<N> nameSerialer,
                                        final long clock ) {
    target.addSubDelete( key, cf, sColumnName, columnName, sNameSerializer, nameSerialer, clock );
    checkAndFlush();
    return this;
}
 
Example #21
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public QueueSet subscribeToQueues( String subscriberQueuePath, List<String> publisherQueuePaths ) {

    subscriberQueuePath = normalizeQueuePath( subscriberQueuePath );
    UUID subscriberQueueId = getQueueId( subscriberQueuePath );

    UUID timestampUuid = newTimeUUID();
    long timestamp = getTimestampInMicros( timestampUuid );

    Mutator<ByteBuffer> batch = CountingMutator.createFlushingMutator( cass.getApplicationKeyspace( applicationId ),
            be );

    QueueSet queues = new QueueSet();

    for ( String publisherQueuePath : publisherQueuePaths ) {

        publisherQueuePath = normalizeQueuePath( publisherQueuePath );
        UUID publisherQueueId = getQueueId( publisherQueuePath );

        batchSubscribeToQueue( batch, publisherQueuePath, publisherQueueId, subscriberQueuePath, subscriberQueueId,
                timestamp );

        try {
            Queue queue = getQueue( subscriberQueuePath, subscriberQueueId );

            batchUpdateQueuePropertiesIndexes( batch, publisherQueueId, subscriberQueuePath, subscriberQueueId,
                    queue.getProperties(), timestampUuid );
        }
        catch ( Exception e ) {
            logger.error( "Unable to update index", e );
        }

        queues.addQueue( publisherQueuePath, publisherQueueId );
    }

    batchExecute( batch, RETRY_COUNT );

    return queues;
}
 
Example #22
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public QueueSet removeSubscribersFromQueue( String publisherQueuePath, List<String> subscriberQueuePaths ) {

    publisherQueuePath = normalizeQueuePath( publisherQueuePath );
    UUID publisherQueueId = getQueueId( publisherQueuePath );

    UUID timestampUuid = newTimeUUID();
    long timestamp = getTimestampInMicros( timestampUuid );

    Mutator<ByteBuffer> batch = CountingMutator.createFlushingMutator( cass.getApplicationKeyspace( applicationId ),
            be );

    QueueSet queues = new QueueSet();

    for ( String subscriberQueuePath : subscriberQueuePaths ) {

        subscriberQueuePath = normalizeQueuePath( subscriberQueuePath );
        UUID subscriberQueueId = getQueueId( subscriberQueuePath );

        batchUnsubscribeFromQueue( batch, publisherQueuePath, publisherQueueId, subscriberQueuePath,
                subscriberQueueId, timestamp );

        try {
            Queue queue = getQueue( subscriberQueuePath, subscriberQueueId );

            batchUpdateQueuePropertiesIndexes( batch, publisherQueueId, subscriberQueuePath, subscriberQueueId,
                    emptyMapWithKeys( queue.getProperties() ), timestampUuid );
        }
        catch ( Exception e ) {
            logger.error( "Unable to update index", e );
        }

        queues.addQueue( subscriberQueuePath, subscriberQueueId );
    }

    batchExecute( batch, RETRY_COUNT );

    return queues;
}
 
Example #23
Source File: CountingMutator.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public <SN, N> Mutator<K> addCounterSubDeletion( final K key, final String cf,
                                                 final HCounterSuperColumn<SN, N> sc ) {
    target.addCounterSubDeletion( key, cf, sc );
    checkAndFlush();
    return this;
}
 
Example #24
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public QueueSet addSubscribersToQueue( String publisherQueuePath, List<String> subscriberQueuePaths ) {

    publisherQueuePath = normalizeQueuePath( publisherQueuePath );
    UUID publisherQueueId = getQueueId( publisherQueuePath );

    UUID timestampUuid = newTimeUUID();
    long timestamp = getTimestampInMicros( timestampUuid );

    Mutator<ByteBuffer> batch = CountingMutator.createFlushingMutator( cass.getApplicationKeyspace( applicationId ),
            be );

    QueueSet queues = new QueueSet();

    for ( String subscriberQueuePath : subscriberQueuePaths ) {

        subscriberQueuePath = normalizeQueuePath( subscriberQueuePath );
        UUID subscriberQueueId = getQueueId( subscriberQueuePath );

        batchSubscribeToQueue( batch, publisherQueuePath, publisherQueueId, subscriberQueuePath, subscriberQueueId,
                timestamp );

        try {
            Queue queue = getQueue( subscriberQueuePath, subscriberQueueId );

            batchUpdateQueuePropertiesIndexes( batch, publisherQueueId, subscriberQueuePath, subscriberQueueId,
                    queue.getProperties(), timestampUuid );
        }
        catch ( Exception e ) {
            logger.error( "Unable to update index", e );
        }

        queues.addQueue( subscriberQueuePath, subscriberQueueId );
    }

    batchExecute( batch, RETRY_COUNT );

    return queues;
}
 
Example #25
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public QueueSet unsubscribeFromQueue( String publisherQueuePath, String subscriberQueuePath ) {

    publisherQueuePath = normalizeQueuePath( publisherQueuePath );
    UUID publisherQueueId = getQueueId( publisherQueuePath );

    subscriberQueuePath = normalizeQueuePath( subscriberQueuePath );
    UUID subscriberQueueId = getQueueId( subscriberQueuePath );

    UUID timestampUuid = newTimeUUID();
    long timestamp = getTimestampInMicros( timestampUuid );

    Mutator<ByteBuffer> batch = CountingMutator.createFlushingMutator( cass.getApplicationKeyspace( applicationId ),
            be );

    batchUnsubscribeFromQueue( batch, publisherQueuePath, publisherQueueId, subscriberQueuePath, subscriberQueueId,
            timestamp );

    try {
        Queue queue = getQueue( subscriberQueuePath, subscriberQueueId );

        batchUpdateQueuePropertiesIndexes( batch, publisherQueueId, subscriberQueuePath, subscriberQueueId,
                emptyMapWithKeys( queue.getProperties() ), timestampUuid );
    }
    catch ( Exception e ) {
        logger.error( "Unable to update index", e );
    }

    batchExecute( batch, RETRY_COUNT );

    return new QueueSet().addQueue( subscriberQueuePath, subscriberQueueId );
}
 
Example #26
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public void batchUnsubscribeFromQueue( Mutator<ByteBuffer> batch, String publisherQueuePath, UUID publisherQueueId,
                                       String subscriberQueuePath, UUID subscriberQueueId, long timestamp ) {

    batch.addDeletion( bytebuffer( publisherQueueId ), QUEUE_SUBSCRIBERS.getColumnFamily(), subscriberQueuePath, se,
            timestamp );

    batch.addDeletion( bytebuffer( subscriberQueueId ), QUEUE_SUBSCRIPTIONS.getColumnFamily(), publisherQueuePath,
            se, timestamp );
}
 
Example #27
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public QueueSet subscribeToQueue( String publisherQueuePath, String subscriberQueuePath ) {

    publisherQueuePath = normalizeQueuePath( publisherQueuePath );
    UUID publisherQueueId = getQueueId( publisherQueuePath );

    subscriberQueuePath = normalizeQueuePath( subscriberQueuePath );
    UUID subscriberQueueId = getQueueId( subscriberQueuePath );

    UUID timestampUuid = newTimeUUID();
    long timestamp = getTimestampInMicros( timestampUuid );

    Mutator<ByteBuffer> batch = CountingMutator.createFlushingMutator( cass.getApplicationKeyspace( applicationId ),
            be );

    batchSubscribeToQueue( batch, publisherQueuePath, publisherQueueId, subscriberQueuePath, subscriberQueueId,
            timestamp );

    try {
        Queue queue = getQueue( subscriberQueuePath, subscriberQueueId );
        if ( queue != null ) {
            batchUpdateQueuePropertiesIndexes( batch, publisherQueueId, subscriberQueuePath, subscriberQueueId,
                    queue.getProperties(), timestampUuid );
        }
    }
    catch ( Exception e ) {
        logger.error( "Unable to update index", e );
    }

    batchExecute( batch, RETRY_COUNT );

    return new QueueSet().addQueue( subscriberQueuePath, subscriberQueueId );
}
 
Example #28
Source File: CpEntityManager.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public Message storeEventAsMessage(Mutator<ByteBuffer> m, Event event, long timestamp) {

        counterUtils.addEventCounterMutations(m, applicationId, event, timestamp);

        QueueManager q = queueManagerFactory.getQueueManager(applicationId);

        Message message = new Message();
        message.setType("event");
        message.setCategory(event.getCategory());
        message.setStringProperty("message", event.getMessage());
        message.setTimestamp(timestamp);
        q.postToQueue("events", message);

        return message;
    }
 
Example #29
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public void batchSubscribeToQueue( Mutator<ByteBuffer> batch, String publisherQueuePath, UUID publisherQueueId,
                                   String subscriberQueuePath, UUID subscriberQueueId, long timestamp ) {

    batch.addInsertion( bytebuffer( publisherQueueId ), QUEUE_SUBSCRIBERS.getColumnFamily(),
            createColumn( subscriberQueuePath, subscriberQueueId, timestamp, se, ue ) );

    batch.addInsertion( bytebuffer( subscriberQueueId ), QUEUE_SUBSCRIPTIONS.getColumnFamily(),
            createColumn( publisherQueuePath, publisherQueueId, timestamp, se, ue ) );
}
 
Example #30
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void incrementQueueCounter( String queuePath, String name, long value ) {
    long timestamp = cass.createTimestamp();
    Mutator<ByteBuffer> m = CountingMutator.createFlushingMutator( cass.getApplicationKeyspace( applicationId ),
            be );
    counterUtils.batchIncrementQueueCounter( m, getQueueId( queuePath ), name, value, timestamp, applicationId );
    batchExecute( m, CassandraService.RETRY_COUNT );
}