@Override public String from(Key<E> from) { return from.getName(); } };
@Override public String toString() { return segment.getName() + "[" + id + "]"; }
@Override public String toString() { return index.getName() + "->" + name; }
@Override public UUID from(Key<E> from) { return UUID.fromString(from.getName()); } };
@Override protected Map<S, T> wrap(Map<Key<T>, T> base) throws Exception { Map<S, T> result = new LinkedHashMap<S, T>(base.size() * 2); for (Map.Entry<Key<T>, T> entry: base.entrySet()) { Object mapKey = entry.getKey().getName() != null ? entry.getKey().getName() : entry.getKey().getId(); result.put((S)mapKey, entry.getValue()); } return result; } };
/** * Helper method to compute the shard number index from an instance of {@link Key} of type {@link CounterShardData}. * This method assumes that the "name" field of a counter shard key will end in a dash, followed by the shard * index. * * @param counterShardDataKey * @return */ public static Integer computeShardIndex(final Key<CounterShardData> counterShardDataKey) { Preconditions.checkNotNull(counterShardDataKey); final String key = counterShardDataKey.getName(); int lastDashIndex = key.lastIndexOf("-"); final String shardIndexAsString = key.substring((lastDashIndex + 1), key.length()); return Integer.valueOf(shardIndexAsString); }
@Override public LuceneIndex newInstance(Key<LuceneIndex> key) { return new LuceneIndex(key.getName()); } }
/** * Param-based Constructor * * @param counterShardDataKey */ public CounterShardData(final Key<CounterShardData> counterShardDataKey) { Preconditions.checkNotNull(counterShardDataKey); setId(counterShardDataKey.getName()); }
public ResourceId getFormId() { return ResourceId.valueOf(formKey.getName()); }
public ResourceId getFormId() { return ResourceId.valueOf(formKey.getName()); }
public SegmentHunk newHunk() { hunkCount++; log.debug("Created Hunk '{}-{}-{}'.", index.getName(), name, hunkCount); return new SegmentHunk(getKey(), hunkCount); }
/** * Create a {@link Key Key<CounterShardData>}. Keys for this entity are not "parented" so that they can be added * under high volume load in a given application. Note that CounterData will be in a namespace specific. * * @param counterDataKey * @param shardNumber * @return */ public static Key<CounterShardData> key(final Key<CounterData> counterDataKey, final int shardNumber) { // Preconditions checked by #constructCounterShardIdentifier return Key.create(CounterShardData.class, constructCounterShardIdentifier(counterDataKey.getName(), shardNumber)); }
/** * Method used for testing purpose useful for printing segment information. * @param segment The segment to print * @param name The name of the hunk to print * @param index The index of the hunk to print */ protected void logSegment(Segment segment, String name, int index) { Objectify objectify = ofy(); final SegmentHunk hunk = objectify.load().key(newSegmentHunkKey(name, index)).now(); hunk.bytes = Arrays.copyOfRange(hunk.bytes, 0, (int) (hunk.bytes.length % (segment.length / hunk.id))); log.info("Hunk '{}-{}-{}' with length {}, Value={}", indexKey.getName(), name, hunk.id, hunk.bytes.length, new String(hunk.bytes)); } /*
@Override public String[] listAll() { final Objectify objectify = ofy(); final List<Key<Segment>> keys = objectify.load().type(Segment.class).ancestor(indexKey).keys().list(); String[] names = new String[keys.size()]; int i = 0; for (Key<Segment> name : keys) names[i++] = name.getName(); return names; } /**
@Test public void getterTest() throws Exception { final Key<CounterData> counterDataKey = CounterData.key(TEST_COUNTER1); final Key<CounterShardData> counterShardDataKey = CounterShardData.key(counterDataKey, 0); final UUID uuid = UUID.randomUUID(); final CounterShardOperationData counterShardOperationData = new CounterShardOperationData(counterShardDataKey, uuid, CounterOperationType.INCREMENT, 1L); assertThat(counterShardOperationData.getMutationAmount(), is(1L)); assertThat(counterShardOperationData.getCounterShardDataKey(), is(counterShardDataKey)); assertThat(counterShardOperationData.getId(), is(uuid.toString())); assertThat( counterShardOperationData.getCreationDateTime().isBefore(DateTime.now(DateTimeZone.UTC).plusSeconds(10)), is(true)); // TypedKey assertThat(counterShardOperationData.getTypedKey().getName(), is(uuid.toString())); assertThat(counterShardOperationData.getTypedKey().getParent().getName(), is(counterShardDataKey.getName())); // RawKey assertThat(counterShardOperationData.getKey().getName(), is(uuid.toString())); }