forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part 1 of modifying ehcache to take serializable Key
- Loading branch information
Peter Alfonsi
committed
Oct 16, 2023
1 parent
ec729d0
commit 990ba9c
Showing
7 changed files
with
129 additions
and
39 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
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
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
54 changes: 54 additions & 0 deletions
54
server/src/main/java/org/opensearch/indices/EhcacheKey.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,54 @@ | ||
/* | ||
* 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.indices; | ||
|
||
import org.opensearch.common.io.stream.BytesStreamOutput; | ||
import org.opensearch.core.common.bytes.BytesReference; | ||
import org.opensearch.core.common.io.stream.BytesStreamInput; | ||
import org.opensearch.core.common.io.stream.Writeable; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.Arrays; | ||
|
||
public class EhcacheKey implements Serializable { | ||
// the IndicesRequestCache.Key is not Serializable, but it is Writeable. | ||
// We use the output stream's bytes in this wrapper class and implement the appropriate interfaces/methods. | ||
// Unfortunately it's not possible to define this class as EhcacheKey<K> and use that as ehcache keys, | ||
// because of type erasure. However, the only context EhcacheKey objects would be compared to one another | ||
// is when they are used for the same cache, so they will always refer to the same K. | ||
private byte[] bytes; | ||
|
||
public EhcacheKey(Writeable key) throws IOException { | ||
BytesStreamOutput os = new BytesStreamOutput(); // Should we pass in an expected size? If so, how big? | ||
key.writeTo(os); | ||
this.bytes = BytesReference.toBytes(os.bytes()); | ||
} | ||
|
||
public byte[] getBytes() { | ||
return this.bytes; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == this) { | ||
return true; | ||
} | ||
if (!(o instanceof EhcacheKey)) { | ||
return false; | ||
} | ||
EhcacheKey other = (EhcacheKey) o; | ||
return Arrays.equals(this.bytes, other.bytes); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(this.bytes); | ||
} | ||
} |
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