-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into tsc_unit_test_fix
Signed-off-by: Sagar Upadhyaya <sagar.upadhyaya.121@gmail.com>
- Loading branch information
Showing
12 changed files
with
607 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 194 additions & 23 deletions
217
plugins/cache-ehcache/src/main/java/org/opensearch/cache/store/disk/EhcacheDiskCache.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
server/src/main/java/org/opensearch/common/cache/serializer/BytesReferenceSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.cache.serializer; | ||
|
||
import org.opensearch.core.common.bytes.BytesArray; | ||
import org.opensearch.core.common.bytes.BytesReference; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* A serializer which transforms BytesReference to byte[]. | ||
* The type of BytesReference is NOT preserved after deserialization, but nothing in opensearch should care. | ||
*/ | ||
public class BytesReferenceSerializer implements Serializer<BytesReference, byte[]> { | ||
// This class does not get passed to ehcache itself, so it's not required that classes match after deserialization. | ||
|
||
public BytesReferenceSerializer() {} | ||
|
||
@Override | ||
public byte[] serialize(BytesReference object) { | ||
return BytesReference.toBytes(object); | ||
} | ||
|
||
@Override | ||
public BytesReference deserialize(byte[] bytes) { | ||
if (bytes == null) { | ||
return null; | ||
} | ||
return new BytesArray(bytes); | ||
} | ||
|
||
@Override | ||
public boolean equals(BytesReference object, byte[] bytes) { | ||
return Arrays.equals(serialize(object), bytes); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
server/src/main/java/org/opensearch/common/cache/serializer/Serializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.cache.serializer; | ||
|
||
/** | ||
* Defines an interface for serializers, to be used by pluggable caches. | ||
* T is the class of the original object, and U is the serialized class. | ||
*/ | ||
public interface Serializer<T, U> { | ||
/** | ||
* Serializes an object. | ||
* @param object A non-serialized object. | ||
* @return The serialized representation of the object. | ||
*/ | ||
U serialize(T object); | ||
|
||
/** | ||
* Deserializes bytes into an object. | ||
* @param bytes The serialized representation. | ||
* @return The original object. | ||
*/ | ||
T deserialize(U bytes); | ||
|
||
/** | ||
* Compares an object to a serialized representation of an object. | ||
* @param object A non-serialized objet | ||
* @param bytes Serialized representation of an object | ||
* @return true if representing the same object, false if not | ||
*/ | ||
boolean equals(T object, U bytes); | ||
} |
9 changes: 9 additions & 0 deletions
9
server/src/main/java/org/opensearch/common/cache/serializer/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
/** A package for serializers used in caches. */ | ||
package org.opensearch.common.cache.serializer; |
Oops, something went wrong.