@SuppressWarnings("unchecked") public static DynamicComposite setEqualityFlag( DynamicComposite composite, ComponentEquality eq ) { if ( composite.isEmpty() ) { return composite; } int i = composite.size() - 1; @SuppressWarnings("rawtypes") Component c = composite.getComponent( i ); composite.setComponent( i, c.getValue(), c.getSerializer(), c.getComparator(), eq ); return composite; }
public static Map<String, Object> deserializeEntityProperties( Row<UUID, String, ByteBuffer> row ) { if ( row == null ) { return null; } ColumnSlice<String, ByteBuffer> slice = row.getColumnSlice(); if ( slice == null ) { return null; } return deserializeEntityProperties( slice.getColumns(), true, false ); }
public static Object deserialize( ByteBuffer bytes ) { List<Object> objects = DynamicComposite.fromByteBuffer( bytes ); if ( objects.size() > 0 ) { return objects.get( 0 ); } return null; }
public static <K, V> Map<K, V> asMap( List<HColumn<K, V>> columns ) { if ( columns == null ) { return null; } Map<K, V> column_map = new LinkedHashMap<K, V>(); for ( HColumn<K, V> column : columns ) { K column_name = column.getName(); column_map.put( column_name, column.getValue() ); } return column_map; }
@Override public Set<String> getQueueCounterNames( String queuePath ) throws Exception { Set<String> names = new HashSet<String>(); Keyspace ko = cass.getApplicationKeyspace( applicationId ); SliceQuery<String, String, ByteBuffer> q = createSliceQuery( ko, se, se, be ); q.setColumnFamily( QueuesCF.QUEUE_DICTIONARIES.toString() ); q.setKey( CassandraPersistenceUtils.key( getQueueId( queuePath ), DICTIONARY_COUNTERS ).toString() ); q.setRange( null, null, false, ALL_COUNT ); List<HColumn<String, ByteBuffer>> columns = q.execute().get().getColumns(); for ( HColumn<String, ByteBuffer> column : columns ) { names.add( column.getName() ); } return names; }
/** * Get the bounds for the queue * * @return The bounds for the queue */ public QueueBounds getQueueBounds( UUID queueId ) { try { ColumnSlice<String, UUID> result = HFactory.createSliceQuery( ko, ue, se, ue ).setKey( queueId ) .setColumnNames( QUEUE_NEWEST, QUEUE_OLDEST ) .setColumnFamily( QUEUE_PROPERTIES.getColumnFamily() ).execute() .get(); if ( result != null && result.getColumnByName( QUEUE_OLDEST ) != null && result.getColumnByName( QUEUE_NEWEST ) != null ) { return new QueueBounds( result.getColumnByName( QUEUE_OLDEST ).getValue(), result.getColumnByName( QUEUE_NEWEST ).getValue() ); } } catch ( Exception e ) { logger.error( "Error getting oldest queue message ID", e ); } return null; }
public boolean hasOutstandingTransactions( UUID queueId, UUID consumerId ) { SliceQuery<ByteBuffer, UUID, UUID> q = createSliceQuery( ko, be, ue, ue ); q.setColumnFamily( CONSUMER_QUEUE_TIMEOUTS.getColumnFamily() ); q.setKey( getQueueClientTransactionKey( queueId, consumerId ) ); q.setRange( null, null, false, 1 ); return q.execute().get().getColumns().size() > 0; }
public Map<String, Long> getQueueCounters( UUID queueId ) throws Exception { Map<String, Long> counters = new HashMap<String, Long>(); Keyspace ko = cass.getApplicationKeyspace( applicationId ); SliceCounterQuery<UUID, String> q = createCounterSliceQuery( ko, ue, se ); q.setColumnFamily( COUNTERS.getColumnFamily() ); q.setRange( null, null, false, ALL_COUNT ); QueryResult<CounterSlice<String>> r = q.setKey( queueId ).execute(); for ( HCounterColumn<String> column : r.get().getColumns() ) { counters.put( column.getName(), column.getValue() ); } return counters; }
public Set<String> getAllColumnNames( Keyspace ko, Object columnFamily, Object key ) throws Exception { List<HColumn<String, ByteBuffer>> columns = getAllColumns( ko, columnFamily, key ); Set<String> set = new LinkedHashSet<String>(); for ( HColumn<String, ByteBuffer> column : columns ) { set.add( column.getName() ); } return set; }
/** * Get the position in the queue for the given appId, consumer and queu * * @param queueId The queueId * @param consumerId The consumerId */ public UUID getConsumerQueuePosition( UUID queueId, UUID consumerId ) { HColumn<UUID, UUID> result = HFactory.createColumnQuery( ko, ue, ue, ue ).setKey( consumerId ).setName( queueId ) .setColumnFamily( CONSUMERS.getColumnFamily() ).execute().get(); if ( result != null ) { return result.getValue(); } return null; }
public DynamicComposite getIndexComposite() { return new DynamicComposite( code, value, getQueueId(), getQueuePath(), timestampUuid ); } }
public void setColumn( Keyspace ko, Object columnFamily, Object key, Object columnName, Object columnValue, int ttl ) throws Exception { if ( db_logger.isTraceEnabled() ) { db_logger.trace( "setColumn cf={} key={} name={} value={}", columnFamily, key, columnName, columnValue ); } ByteBuffer name_bytes = null; if ( columnName instanceof List ) { name_bytes = DynamicComposite.toByteBuffer( ( List<?> ) columnName ); } else { name_bytes = bytebuffer( columnName ); } ByteBuffer value_bytes = null; if ( columnValue instanceof List ) { value_bytes = DynamicComposite.toByteBuffer( ( List<?> ) columnValue ); } else { value_bytes = bytebuffer( columnValue ); } HColumn<ByteBuffer, ByteBuffer> col = createColumn( name_bytes, value_bytes, be, be ); if ( ttl != 0 ) { col.setTtl( ttl ); } Mutator<ByteBuffer> m = CountingMutator.createFlushingMutator( ko, be ); m.insert( bytebuffer( key ), columnFamily.toString(), col ); }
public static void addDeleteToMutator( Mutator<ByteBuffer> m, Object columnFamily, Object key, Object columnName, long timestamp ) throws Exception { logBatchOperation( "Delete", columnFamily, key, columnName, null, timestamp ); if ( columnName instanceof List<?> ) { columnName = DynamicComposite.toByteBuffer( ( List<?> ) columnName ); } m.addDeletion( bytebuffer( key ), columnFamily.toString(), bytebuffer( columnName ), be, timestamp ); }
public static Map<String, ByteBuffer> getColumnMap( List<HColumn<String, ByteBuffer>> columns ) { Map<String, ByteBuffer> column_map = new TreeMap<String, ByteBuffer>( String.CASE_INSENSITIVE_ORDER ); if ( columns != null ) { for ( HColumn<String, ByteBuffer> column : columns ) { String column_name = column.getName(); column_map.put( column_name, column.getValue() ); } } return column_map; }
/** Load the messages into an array list */ protected List<Message> loadMessages( Collection<UUID> messageIds, boolean reversed ) { Rows<UUID, String, ByteBuffer> messageResults = createMultigetSliceQuery( ko, ue, se, be ).setColumnFamily( MESSAGE_PROPERTIES.getColumnFamily() ) .setKeys( messageIds ) .setRange( null, null, false, ALL_COUNT ).execute().get(); List<Message> messages = new ArrayList<Message>( messageIds.size() ); for ( Row<UUID, String, ByteBuffer> row : messageResults ) { Message message = deserializeMessage( row.getColumnSlice().getColumns() ); if ( message != null ) { messages.add( message ); } } Collections.sort( messages, new RequestedOrderComparator( messageIds ) ); return messages; }
@Override public Message getMessage( UUID messageId ) { SliceQuery<UUID, String, ByteBuffer> q = createSliceQuery( cass.getApplicationKeyspace( applicationId ), ue, se, be ); q.setColumnFamily( MESSAGE_PROPERTIES.getColumnFamily() ); q.setKey( messageId ); q.setRange( null, null, false, ALL_COUNT ); QueryResult<ColumnSlice<String, ByteBuffer>> r = q.execute(); ColumnSlice<String, ByteBuffer> slice = r.get(); List<HColumn<String, ByteBuffer>> results = slice.getColumns(); return deserializeMessage( results ); }
@Override public Map<String, Long> getEntityCounters( UUID entityId ) throws Exception { Map<String, Long> counters = new HashMap<String, Long>(); Keyspace ko = cass.getApplicationKeyspace( applicationId ); SliceCounterQuery<UUID, String> q = createCounterSliceQuery( ko, ue, se ); q.setColumnFamily( ENTITY_COUNTERS.toString() ); q.setRange( null, null, false, ALL_COUNT ); //Adding graphite metrics Timer.Context timeEntityCounters = entGetEntityCountersTimer.time(); QueryResult<CounterSlice<String>> r = q.setKey( entityId ).execute(); timeEntityCounters.stop(); for ( HCounterColumn<String> column : r.get().getColumns() ) { counters.put( column.getName(), column.getValue() ); } return counters; }
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 ); }
public static Queue deserializeQueue( List<HColumn<String, ByteBuffer>> columns ) { Queue queue = null; Map<String, Object> properties = new HashMap<String, Object>(); for ( HColumn<String, ByteBuffer> column : columns ) { if ( QUEUE_PROPERTIES.containsKey( column.getName() ) ) { properties .put( column.getName(), object( QUEUE_PROPERTIES.get( column.getName() ), column.getValue() ) ); } else { properties.put( column.getName(), JsonUtils.fromByteBuffer( column.getValue() ) ); } } if ( !properties.isEmpty() ) { queue = new Queue( properties ); } return queue; }
public Queue getQueue( String queuePath, UUID queueId ) { SliceQuery<UUID, String, ByteBuffer> q = createSliceQuery( cass.getApplicationKeyspace( applicationId ), ue, se, be ); q.setColumnFamily( QUEUE_PROPERTIES.getColumnFamily() ); q.setKey( queueId ); q.setRange( null, null, false, ALL_COUNT ); QueryResult<ColumnSlice<String, ByteBuffer>> r = q.execute(); ColumnSlice<String, ByteBuffer> slice = r.get(); List<HColumn<String, ByteBuffer>> results = slice.getColumns(); return deserializeQueue( results ); }