@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (key_ != null) { output.writeMessage(1, getKey()); } if (value_ != null) { output.writeMessage(2, getValue()); } unknownFields.writeTo(output); }
@java.lang.Override public int getSerializedSize() { int size = memoizedSize; if (size != -1) return size; size = 0; if (key_ != null) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(1, getKey()); } if (value_ != null) { size += com.google.protobuf.CodedOutputStream .computeMessageSize(2, getValue()); } size += unknownFields.getSerializedSize(); memoizedSize = size; return size; }
@Override public Result<RegionAPI.PutAllResponse> process(ProtobufSerializationService serializationService, RegionAPI.PutAllRequest putAllRequest, MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException, DecodingException { String regionName = putAllRequest.getRegionName(); RegionAPI.PutAllResponse.Builder builder = RegionAPI.PutAllResponse.newBuilder(); SecureCache cache = messageExecutionContext.getSecureCache(); Map<Object, Object> entries = new HashMap<>(putAllRequest.getEntryList().size()); putAllRequest.getEntryList() .forEach(entry -> entries.put(serializationService.decode(entry.getKey()), serializationService.decode(entry.getValue()))); cache.putAll(regionName, entries, (key, exception) -> addError(builder, serializationService.encode(key), exception)); return Success.of(builder.build()); }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.Entry)) { return super.equals(obj); } org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.Entry other = (org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.Entry) obj; boolean result = true; result = result && (hasKey() == other.hasKey()); if (hasKey()) { result = result && getKey() .equals(other.getKey()); } result = result && (hasValue() == other.hasValue()); if (hasValue()) { result = result && getValue() .equals(other.getValue()); } result = result && unknownFields.equals(other.unknownFields); return result; }
@Override public Map<K, V> getAll(Collection<K> keys) throws IOException { Map<K, V> values = new HashMap<>(); RegionAPI.GetAllRequest.Builder getAllRequest = RegionAPI.GetAllRequest.newBuilder(); getAllRequest.setRegionName(name); for (K key : keys) { getAllRequest.addKey(valueEncoder.encodeValue(key)); } Message request = Message.newBuilder().setGetAllRequest(getAllRequest).build(); Message message = protobufChannel.sendRequest(request, MessageTypeCase.GETALLRESPONSE); final RegionAPI.GetAllResponse getAllResponse = message.getGetAllResponse(); Map<Object, String> failures = new HashMap<>(); if (getAllResponse.getFailuresCount() > 0) { for (BasicTypes.KeyedError keyedError : getAllResponse.getFailuresList()) { failures.put(valueEncoder.decodeValue(keyedError.getKey()), keyedError.getError().getMessage()); } throw new IOException("Unable to process the following keys: " + failures); } for (BasicTypes.Entry entry : getAllResponse.getEntriesList()) { values.put((K) valueEncoder.decodeValue(entry.getKey()), (V) valueEncoder.decodeValue(entry.getValue())); } return values; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); if (hasKey()) { hash = (37 * hash) + KEY_FIELD_NUMBER; hash = (53 * hash) + getKey().hashCode(); } if (hasValue()) { hash = (37 * hash) + VALUE_FIELD_NUMBER; hash = (53 * hash) + getValue().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@Test public void singleNullKey() throws Exception { HashSet<BasicTypes.EncodedValue> testKeys = new HashSet<>(); testKeys.add(serializationService.encode(NO_VALUE_PRESENT_FOR_THIS_KEY)); RegionAPI.GetAllRequest getAllRequest = ProtobufRequestUtilities.createGetAllRequest(TEST_REGION, testKeys); Result result = operationHandler.process(serializationService, getAllRequest, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); assertTrue(result instanceof Success); RegionAPI.GetAllResponse message = (RegionAPI.GetAllResponse) result.getMessage(); assertEquals(1, message.getEntriesCount()); assertEquals(null, serializationService.decode(message.getEntries(0).getValue())); assertEquals(NO_VALUE_PRESENT_FOR_THIS_KEY, message.getEntries(0).getKey().getStringResult()); verify(regionStub, times(1)).get(NO_VALUE_PRESENT_FOR_THIS_KEY); }
@Override public Result<RegionAPI.PutIfAbsentResponse> process( ProtobufSerializationService serializationService, RegionAPI.PutIfAbsentRequest request, MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException, ConnectionStateException, EncodingException, DecodingException { final String regionName = request.getRegionName(); final BasicTypes.Entry entry = request.getEntry(); Object decodedValue = serializationService.decode(entry.getValue()); Object decodedKey = serializationService.decode(entry.getKey()); final Object oldValue = messageExecutionContext.getSecureCache().putIfAbsent(regionName, decodedKey, decodedValue); return Success.of(RegionAPI.PutIfAbsentResponse.newBuilder() .setOldValue(serializationService.encode(oldValue)).build()); } }
private Map<String, String> convertEntryListToMap(List<BasicTypes.Entry> entriesList) { Map<String, String> result = new HashMap<>(); for (BasicTypes.Entry entry : entriesList) { BasicTypes.EncodedValue encodedKey = entry.getKey(); assertEquals(BasicTypes.EncodedValue.ValueCase.STRINGRESULT, encodedKey.getValueCase()); String key = encodedKey.getStringResult(); BasicTypes.EncodedValue encodedValue = entry.getValue(); assertEquals(BasicTypes.EncodedValue.ValueCase.STRINGRESULT, encodedValue.getValueCase()); String value = encodedValue.getStringResult(); result.put(key, value); } return result; } }
@Override public Result<RegionAPI.PutResponse> process(ProtobufSerializationService serializationService, RegionAPI.PutRequest request, MessageExecutionContext messageExecutionContext) throws InvalidExecutionContextException, DecodingException { String regionName = request.getRegionName(); BasicTypes.Entry entry = request.getEntry(); Object decodedValue = serializationService.decode(entry.getValue()); Object decodedKey = serializationService.decode(entry.getKey()); SecureCache cache = messageExecutionContext.getSecureCache(); cache.put(regionName, decodedKey, decodedValue); return Success.of(RegionAPI.PutResponse.newBuilder().build()); } }
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.EncodedValue key = 1;</code> */ public org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.EncodedValueOrBuilder getKeyOrBuilder() { return getKey(); }
public Builder mergeFrom(org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.Entry other) { if (other == org.apache.geode.internal.protocol.protobuf.v1.BasicTypes.Entry.getDefaultInstance()) return this; if (other.hasKey()) { mergeKey(other.getKey()); } if (other.hasValue()) { mergeValue(other.getValue()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }