-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-5298 HotRod millisecond precision for lifespan/maxidle
* Propagated user defined TimeUnit via HotRod for lifespan and maxIdle * Added Test * Updated doc
- Loading branch information
1 parent
cbaf14a
commit c2d8c09
Showing
33 changed files
with
421 additions
and
259 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
39 changes: 39 additions & 0 deletions
39
client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/TimeUnitParam.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,39 @@ | ||
package org.infinispan.client.hotrod.impl; | ||
|
||
import java.util.EnumMap; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Time unit representation for HotRod | ||
* | ||
* @author gustavonalle | ||
* @since 8.0 | ||
*/ | ||
public class TimeUnitParam { | ||
|
||
private static final Map<TimeUnit, Byte> timeUnitToByte = new EnumMap<>(TimeUnit.class); | ||
|
||
static { | ||
timeUnitToByte.put(TimeUnit.SECONDS, (byte) 0); | ||
timeUnitToByte.put(TimeUnit.MILLISECONDS, (byte) 1); | ||
timeUnitToByte.put(TimeUnit.NANOSECONDS, (byte) 2); | ||
timeUnitToByte.put(TimeUnit.MICROSECONDS, (byte) 3); | ||
timeUnitToByte.put(TimeUnit.MINUTES, (byte) 4); | ||
timeUnitToByte.put(TimeUnit.HOURS, (byte) 5); | ||
timeUnitToByte.put(TimeUnit.DAYS, (byte) 6); | ||
} | ||
|
||
private static final byte TIME_UNIT_DEFAULT = (byte) 7; | ||
private static final byte TIME_UNIT_INFINITE = (byte) 8; | ||
|
||
private static byte encodeDuration(long duration, TimeUnit timeUnit) { | ||
return duration == 0 ? TIME_UNIT_DEFAULT : duration < 0 ? TIME_UNIT_INFINITE : timeUnitToByte.get(timeUnit); | ||
} | ||
|
||
public static byte encodeTimeUnits(long lifespan, TimeUnit lifespanTimeUnit, long maxIdle, TimeUnit maxIdleTimeUnit) { | ||
byte encodedLifespan = encodeDuration(lifespan, lifespanTimeUnit); | ||
byte encodedMaxIdle = encodeDuration(maxIdle, maxIdleTimeUnit); | ||
return (byte) (encodedLifespan << 4 | encodedMaxIdle); | ||
} | ||
} |
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
Oops, something went wrong.