Package io.token.tpp.util
Class Util
- java.lang.Object
-
- io.token.util.Util
-
- io.token.tpp.util.Util
-
public abstract class Util extends io.token.util.Util
Utility methods.
-
-
Field Summary
Fields Modifier and Type Field Description static io.token.proto.common.alias.AliasProtos.Alias
TOKEN
The token alias.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static io.token.proto.common.security.SecurityProtos.Key
getSigningKey(io.token.proto.common.member.MemberProtos.Member member, io.token.proto.common.security.SecurityProtos.Signature signature)
Get the key corresponding to a signature.static java.util.Map<java.lang.String,java.lang.String>
parseQueryString(java.lang.String queryString)
Returns map of query string parameters, given a query string.static <T> T
retryWithExponentialBackoff(long timeoutMs, long waitTimeMs, double backOffFactor, long maxWaitTimeMs, java.util.concurrent.Callable<T> function, java.util.function.Predicate<T> retryIf)
Repetitively run a function until the result of the function is acceptable (defined byretryIf
predicate) or the total wait time exceeds the requested amount (timeoutMs
).static <T> T
retryWithExponentialBackoffNoThrow(long timeoutMs, long waitTimeMs, double backOffFactor, long maxWaitTimeMs, java.util.concurrent.Callable<T> function, java.util.function.Predicate<T> retryIf)
Repetitively run a function until the result of the function is acceptable (defined byretryIf
predicate) or the total wait time exceeds the requested amount (timeoutMs
).static java.lang.String
urlDecode(java.lang.String string)
URL decodes a string.static java.lang.String
urlEncode(java.lang.String string)
URL encodes a string.static void
verifySignature(io.token.proto.common.member.MemberProtos.Member member, com.google.protobuf.Message payload, io.token.proto.common.security.SecurityProtos.Signature signature)
Verify the signature of the payload.
-
-
-
Method Detail
-
parseQueryString
public static java.util.Map<java.lang.String,java.lang.String> parseQueryString(java.lang.String queryString)
Returns map of query string parameters, given a query string.- Parameters:
queryString
- query string- Returns:
- map of parameters in query string
-
urlEncode
public static java.lang.String urlEncode(java.lang.String string)
URL encodes a string.- Parameters:
string
- to encode- Returns:
- encoded string
-
urlDecode
public static java.lang.String urlDecode(java.lang.String string)
URL decodes a string.- Parameters:
string
- to decode- Returns:
- decoded string
-
verifySignature
public static void verifySignature(io.token.proto.common.member.MemberProtos.Member member, com.google.protobuf.Message payload, io.token.proto.common.security.SecurityProtos.Signature signature)
Verify the signature of the payload.- Parameters:
member
- memberpayload
- payloadsignature
- signature
-
getSigningKey
public static io.token.proto.common.security.SecurityProtos.Key getSigningKey(io.token.proto.common.member.MemberProtos.Member member, io.token.proto.common.security.SecurityProtos.Signature signature)
Get the key corresponding to a signature.- Parameters:
member
- membersignature
- signature- Returns:
- signing key if member owns it.
-
retryWithExponentialBackoff
public static <T> T retryWithExponentialBackoff(long timeoutMs, long waitTimeMs, double backOffFactor, long maxWaitTimeMs, java.util.concurrent.Callable<T> function, java.util.function.Predicate<T> retryIf) throws java.lang.Exception
Repetitively run a function until the result of the function is acceptable (defined byretryIf
predicate) or the total wait time exceeds the requested amount (timeoutMs
). Returns the last result of the function, acceptable or not (in the case of timeout).- Type Parameters:
T
- the type of the esult of thefunction
- Parameters:
timeoutMs
- a maximum total waiting time between retrieswaitTimeMs
- initial wait time before retrybackOffFactor
- a factor by which the wait time is multiplied after each retrymaxWaitTimeMs
- max wait time between retriesfunction
- function that should be calledretryIf
- a boolean function that checks the result of thefunction
and returns true if need to retry- Returns:
- last result of the
function
- Throws:
java.lang.Exception
- whatever checked exceptionsfunction
throwsjava.lang.InterruptedException
- if any thread has interrupted the current threadjava.lang.IllegalArgumentException
- if any of the time arguments or thebackOffFactor
is negative
-
retryWithExponentialBackoffNoThrow
public static <T> T retryWithExponentialBackoffNoThrow(long timeoutMs, long waitTimeMs, double backOffFactor, long maxWaitTimeMs, java.util.concurrent.Callable<T> function, java.util.function.Predicate<T> retryIf) throws java.lang.InterruptedException
Repetitively run a function until the result of the function is acceptable (defined byretryIf
predicate) or the total wait time exceeds the requested amount (timeoutMs
). Returns the last result of the function, acceptable or not (in the case of timeout).
To be used for functions that do not throw checked exceptions.- Type Parameters:
T
- the type of the esult of thefunction
- Parameters:
timeoutMs
- a maximum total waiting time between retrieswaitTimeMs
- initial wait time before retrybackOffFactor
- a factor by which the wait time is multiplied after each retrymaxWaitTimeMs
- max wait time between retriesfunction
- function that should be calledretryIf
- a boolean function that checks the result of thefunction
and returns true if need to retry- Returns:
- last result of the
function
- Throws:
java.lang.InterruptedException
- if any thread has interrupted the current threadjava.lang.IllegalArgumentException
- if any of the time arguments or thebackOffFactor
is negative
-
-