Java Code Examples for com.datastax.driver.core.utils.UUIDs#unixTimestamp()
The following examples show how to use
com.datastax.driver.core.utils.UUIDs#unixTimestamp() .
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: ObjectMapper.java From Rhombus with MIT License | 5 votes |
public IndexUpdateRow getNextUpdateIndexRow(@Nullable IndexUpdateRowKey lastInstanceKey) throws IOException, JsonMappingException { CQLStatement cqlForNext = (lastInstanceKey == null) ? cqlGenerator.makeGetFirstEligibleIndexUpdate() : cqlGenerator.makeGetNextEligibleIndexUpdate(lastInstanceKey); ResultSet resultSet = cqlExecutor.executeSync(cqlForNext); if(resultSet.isExhausted()){ return null; } IndexUpdateRowKey nextInstanceKey = new IndexUpdateRowKey(resultSet.one()); CQLStatement cqlForRow = cqlGenerator.makeGetRowIndexUpdate(keyspaceDefinition.getName(), nextInstanceKey); resultSet = cqlExecutor.executeSync(cqlForRow); List<Row> results = resultSet.all(); if(results.size() == 0 ){ return null; } String objectName = results.get(0).getString("statictablename"); CDefinition def = keyspaceDefinition.getDefinitions().get(objectName); List<SortedMap<String,Object>> indexValueList = Lists.newArrayList(); List<UUID> ids = Lists.newArrayList(); for(Row update : results){ indexValueList.add(unpackIndexValuesFromJson(def,update.getString("indexvalues"))); ids.add(update.getUUID("id")); } return new IndexUpdateRow( objectName, results.get(0).getUUID("instanceid"), UUIDs.unixTimestamp(results.get(0).getUUID("id"))*1000, indexValueList, ids ); }
Example 2
Source File: Criteria.java From Rhombus with MIT License | 5 votes |
private String uuidToDateString(UUID uuid) { if(uuid == null) { return null; } else { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd:HH:mm:ssZ"); Date date = new Date(UUIDs.unixTimestamp(uuid)); return sdf.format(date); } }
Example 3
Source File: DataCenterForwarder.java From ts-reaktive with MIT License | 4 votes |
private static long getTimestamp(EventEnvelope e) { return UUIDs.unixTimestamp(TimeBasedUUID.class.cast(e.offset()).value()); }
Example 4
Source File: Functions.java From hawkular-metrics with Apache License 2.0 | 4 votes |
public static DataPoint<Double> getGaugeDataPoint(Row row) { return new DataPoint<>( UUIDs.unixTimestamp(row.getUUID(GAUGE_COLS.TIME.ordinal())), row.getDouble(GAUGE_COLS.VALUE.ordinal()), row.getMap(GAUGE_COLS.TAGS.ordinal(), String.class, String.class)); }
Example 5
Source File: Functions.java From hawkular-metrics with Apache License 2.0 | 4 votes |
public static DataPoint<Long> getCounterDataPoint(Row row) { return new DataPoint<>( UUIDs.unixTimestamp(row.getUUID(COUNTER_COLS.TIME.ordinal())), row.getLong(COUNTER_COLS.VALUE.ordinal()), row.getMap(COUNTER_COLS.TAGS.ordinal(), String.class, String.class)); }
Example 6
Source File: Functions.java From hawkular-metrics with Apache License 2.0 | 4 votes |
public static DataPoint<String> getStringDataPoint(Row row) { return new DataPoint<>( UUIDs.unixTimestamp(row.getUUID(STRING_COLS.TIME.ordinal())), row.getString(STRING_COLS.VALUE.ordinal()), row.getMap(STRING_COLS.TAGS.ordinal(), String.class, String.class)); }
Example 7
Source File: Functions.java From hawkular-metrics with Apache License 2.0 | 4 votes |
public static DataPoint<AvailabilityType> getAvailabilityDataPoint(Row row) { return new DataPoint<>( UUIDs.unixTimestamp(row.getUUID(AVAILABILITY_COLS.TIME.ordinal())), AvailabilityType.fromBytes(row.getBytes(AVAILABILITY_COLS.AVAILABILITY.ordinal())), row.getMap(COUNTER_COLS.TAGS.ordinal(), String.class, String.class)); }
Example 8
Source File: UpdateProcessor.java From Rhombus with MIT License | 4 votes |
protected void processRow(IndexUpdateRow row){ if(row.getIndexValues().size() == 0){ return; } if(row.getIndexValues().size() == 1){ //if this is older than the consistency horizon, just delete it Long consistencyHorizon = UUIDs.unixTimestamp(objectMapper.getTimeUUIDAtEndOfConsistencyHorizion()); if(row.getTimeStampOfMostCurrentUpdate() > consistencyHorizon){ objectMapper.deleteObsoleteUpdateIndexColumn(row.getRowKey(),row.getIds().get(0)); } return; } //make a list of all the updated indexes and subtract all the indexes that are current Map<String,Object> mostRecentUpdate = row.getIndexValues().get(0); row.getIndexValues().remove(0); row.getIds().remove(0); List<CIndex> listOfIndexesToDelete = Lists.newArrayList(); List<Map<String,Object>> listOfValuesToDelete = Lists.newArrayList(); for(Map<String,Object> update: row.getIndexValues()){ if(!areIndexValuesEqual(mostRecentUpdate, update)){ listOfValuesToDelete.add(update); listOfIndexesToDelete.addAll( getListOfEffectedIndexes(objectMapper.getKeyspaceDefinition().getDefinitions().get(row.getObjectName()), mostRecentUpdate, update ) ); } } //delete the list of indexes with a timestamp of the current update for(CIndex index : listOfIndexesToDelete){ for(Map<String,Object> values: listOfValuesToDelete){ //if any of the values are null we can skip it because its not actually a written index if(!areAnyValuesNull(values)){ objectMapper.deleteObsoleteIndex(row,index, values); } } } //now delete the processed update columns in this row for(UUID todelete: row.getIds()){ objectMapper.deleteObsoleteUpdateIndexColumn(row.getRowKey(),todelete); } }
Example 9
Source File: CObjectCQLGenerator.java From Rhombus with MIT License | 4 votes |
@NotNull protected static CQLStatementIterator makeCQLforList(String keyspace, CObjectShardList shardList, CDefinition def, SortedMap<String,Object> indexValues, CObjectOrdering ordering, @Nullable UUID start, @Nullable UUID end, Long limit, boolean inclusive, boolean countOnly, boolean allowFiltering) throws CQLGenerationException { // Get matching index from definition CIndex i = def.getIndex(indexValues, allowFiltering); if(i == null){ throw new CQLGenerationException(String.format("Could not find specified index on CDefinition %s",def.getName())); } // Determine client filters and fix index values Map<String, Object> clientFilters = null; if(i.getCompositeKeyList().size() < indexValues.keySet().size()) { clientFilters = Maps.newHashMap(); SortedMap<String, Object> newIndexValues = Maps.newTreeMap(); for(String key : indexValues.keySet()) { if(i.getCompositeKeyList().contains(key)) { newIndexValues.put(key, indexValues.get(key)); } else { // Index keys will always exactly match the criteria index values if allowFiltering is false, so this only happens if allowFiltering is true clientFilters.put(key, indexValues.get(key)); } } indexValues = newIndexValues; } boolean hasClientFilters = clientFilters != null && !clientFilters.isEmpty(); // Now validate the remaining index values if(!i.validateIndexKeys(indexValues)){ throw new CQLGenerationException(String.format("Cannot query index %s on CDefinition %s with the provided list of index values",i.getName(),def.getName())); } CQLStatement whereCQL = makeAndedEqualList(def,indexValues); String whereQuery = whereCQL.getQuery(); List<Object> values = new ArrayList<Object>(Arrays.asList(whereCQL.getValues())); if(start != null){ whereQuery += " AND id >" + (inclusive ? "= " : " ") + "?"; values.add(start); } if(end != null){ whereQuery += " AND id <" + (inclusive ? "= " : " ") + "?"; values.add(end); } // TODO Find some way to deal with limits on statements that allow filtering String limitCQL = ""; if(allowFiltering || limit > 0) { if(limit <= 0 || limit > MAX_CQL_STATEMENT_LIMIT) { limit = MAX_CQL_STATEMENT_LIMIT; } limitCQL = "LIMIT %d"; } // TODO: if we feel like it's worth the trouble, for count queries with client side filters, only select the fields needed to satisfy the filters // note that doing so will also require modifying ObjectMapper.mapResult() so it only maps fields that exist in the row String CQLTemplate = String.format( TEMPLATE_SELECT_WIDE, // If this was a count query and filtering was allowed and client filters weren't defined, just do a count query because we don't need to apply filters // Otherwise if this was a count query, but allowFiltering was true and we have client-side filters to apply, do a full row query so we can apply the filters countOnly && !(allowFiltering && hasClientFilters) ? "count(*)":"*", keyspace, makeTableName(def, i), "?", whereQuery, ordering, limitCQL); CQLStatement templateCQLStatement = CQLStatement.make(CQLTemplate, makeTableName(def, i), values.toArray()); Long startTime = (start == null) ? null : UUIDs.unixTimestamp(start); Long endTime = (end == null) ? null : UUIDs.unixTimestamp(end); CQLStatementIterator returnIterator = null; if((startTime != null && endTime != null) || (i.getShardingStrategy() instanceof ShardingStrategyNone)) { //the query is either bounded or unsharded, so we do not need to check the shardindex try { Range<Long> shardIdRange = i.getShardingStrategy().getShardKeyRange(startTime,endTime); returnIterator = new UnboundableCQLStatementIterator(shardIdRange, limit, ordering, templateCQLStatement, def.getName()); } catch(ShardStrategyException e){ throw new CQLGenerationException(e.getMessage()); } } else { //we have an unbounded query returnIterator = new BoundedLazyCQLStatementIterator( shardList.getShardIdList(def,indexValues,ordering,start,end), templateCQLStatement, limit, def.getName() ); } // Set the client filters on the returned iterator so the client can take care of them returnIterator.setClientFilters(clientFilters); return returnIterator; }