<Default Package>
Type integer
64-bit signed integer type.
Values of the integer type are negative, zero, and positive integers encoded as 64-bit signed two's complement binary integers. The lowest negative value that can be stored in a variable of type integer is -9223372036854775808 (or -263) and the highest positive value that can be stored is 9223372036854775807 (or 263 - 1). The default value is 0.
Integers can be parsed and they are routable and comparable. Integers are non-cyclic.
Integers have the following operators available on them:
< | Less-than comparison |
<= | Less-than or equal comparison |
= | Equal comparison |
!= | Not equal comparison |
> | Greater-than comparison |
>= | Greater-than or equals comparison |
+ | Unary integral identity |
- | Unary integral additive inverse |
+ | Integral addition |
- | Integral subtraction |
* | Integral multiplication |
/ | Integral division |
% | Integral remainder |
or | Bitwise or |
and | Bitwise and |
xor | Bitwise exclusive or |
not | Unary bitwise inverse |
>> | Bitwise shift right |
<< | Bitwise shift left |
An attempt to divide by zero (0) or to compute a remainder of zero will throw an exception. Overflows and underflows are ignored.
When you use the shift operators, the sign of a result value can differ from that of the operand value being shifted. When you use not, the sign of the result value will be the opposite of that of its operand.
Constant summary |
integer | MAX
Largest positive value an integer can take (263-1). |
integer | MIN
Largest negative value an integer can take (-263). |
MAX
integer MAX
Largest positive value an integer can take (263-1).
MIN
integer MIN
Largest negative value an integer can take (-263).
abs
integer abs()
Get the absolute value of this integer.
-
Returns:
- |x| where x is this integer.
canParse
boolean static canParse(string s)
Check if the string argument can be parsed as an integer.
-
Parameters:
-
s - The string to test for parseability.
-
Returns:
- True if and only if parse would return if called with the value s, false otherwise (i.e. if parse would throw a ParseException).
-
See Also:
-
integer#parse() - See the parse method for what is parseable.
getUnique
integer static getUnique()
Get a globally-unique integer.
Generates a unique integer in the scope of the correlator. It returns an integer that is unique for the correlator session's lifetime.
With correlator persistence enabled, the getUnique() counter is persisted and recovered so that it is not lost on a restart. Without persistence, when the correlator is shut down and restarted, then the integers returned might be the same as some or all of the values produced in the earlier session.
No guarantees about the value of the integer are made, other than being unique within a single correlator.
-
Returns:
- A unique integer.
-
See Also:
-
integer#incrementCounter() - Use incrementCounter if you want a monotonically increasing counter. Due to the increased predictability of the values returned by incrementCounter() and the fact they're unaffected by identifiers generated by other parts of the application, use of incrementCounter (with a suitable key) is recommended over getUnique() in situations where the value will be shared with components outside the correlator, such as for request-response identifiers passed to a connectivity plugin or adapter. This can make unit testing easier, and increases the chance of successfully reproducing application behaviour from an input log. However getUnique() is a great choice for identifiers that are not shared outside the correlator.
-
com.apama.correlator.Component#getComponentPhysicalId() - Combine this with the PhysicalId to get a number that is unique across a cluster of correlators.
hash
integer hash()
Get an integer hash representation of the underlying object.
This function will return an integer evenly distributed over the whole range suitable for partitioning or indexing of that structure. Multiple different object can resolve to the same hash value.
-
Returns:
- An integer respresentation of the underlying object.
incrementCounter
integer static incrementCounter(string key)
Increment and return the value of a named counter. Counters are useful as unique identifiers for request-response.
Generates a monotonically increasing integer for the specified string key, in the scope of this correlator instance. It returns an integer that is larger than the previously returned value in the correlator session's lifetime for the string key provided.
It is essential to ensure that the same key is used for calling incrementCounter in all situations where identifiers are generated in the same identifier namespace, otherwise there can be unwanted collisions between the generated identifiers. For the same reason, do not mix use of incrementCounter() and getUnique(). If you are producing an EPL API you should provide an EPL action that wraps creation of the required request/response identifiers to avoid mistakes by callers. If you are using an API that requires a request/response identifier, consult the documentation carefully to ensure you are generating identifiers in a consistent way throughout your application.
Assuming the guidance above is followed, use of incrementCounter (with a suitable key) is usually recommended over getUnique() in situations where the value will be shared with components outside the correlator, such as for request-response identifiers passed to a connectivity plugin or adapter. This is because of the increased predictability of the values returned by incrementCounter() and the fact they're unaffected by identifiers generated by other parts of the application. Predictable identifiers make unit testing easier, and also increase the chance of successfully reproducing application behaviour from an input log if needed.
With correlator persistence enabled, counters are persisted and recovered so that they are not lost on a restart. Without persistence, when the correlator is shut down and restarted, then the integers returned might be the same as some or all of the values produced in the earlier session.
Keep in mind that using this function with a large number of keys will result in a memory leak. Therefore the keys should be static rather than dynamic, and the total number of keys in use should be kept small.
-
Parameters:
-
key - The unique key identifying the counter to increment, for example "HTTPClientRequestId". To avoid the risk of collisions it is important to always use the exact same key for all identifiers used by a given API or connectivity plug-in. Where possible, create an EPL action to wrap creation of the identifier, to ensure it always happens in a consistent way and there is no danger of typos.
-
Returns:
- The next integer for the named counter. Returned values will be 1, 2, 3, and so on for each key. The returned numbers are 64-bit signed integers.
max
integer static max(integer a, integer b)
Return the larger of two integers.
-
Parameters:
-
a - The first number to compare.
-
b - The second number to compare.
-
Returns:
- The larger of a and b.
min
integer static min(integer a, integer b)
Return the smaller of two integers.
-
Parameters:
-
a - The first number to compare.
-
b - The second number to compare.
-
Returns:
- The smaller of a and b.
parse
integer static parse(string s)
Parse a string to an integer.
Inputs to this method must be of the form:
[PREFIX][SIGN][BASE]INTEGER[SUFFIX]
Where:
PREFIX is zero or more whitespace characters (space, tab).
SIGN is zero or one sign characters (+ or -).
BASE is either empty (for base 10), 0b/0B for base 2 (binary) or 0x/0X for base 16 (hex).
INTEGER is a a sequence of one or more digits according to the base (i.e. 0 or 1 for base 2, 0-9 for base 10 and 0-F for base 16).
SUFFIX is zero or more whitespace/line terminating characters (space, tab, carriage return, line feed).
For any string not conforming to the above conditions, a ParseException will be thrown.
-
Parameters:
-
s - The string to parse.
-
Returns:
- The integer corresponding to the string.
-
Throws:
- ParseException if the string cannot be parsed as an integer.
-
See Also:
-
string#toInteger() - string.toInteger for a less strict method to parse integers.
pow
integer pow(integer exp)
Calculate this number to the power of the exponent.
-
Parameters:
-
exp - The exponent to raise this integer to.
-
Returns:
- Returns iexp.
-
Throws:
- ArithmeticException if exp is negative.
rand
integer rand()
Generate a random number.
Returns a random integer value from 0 up to (but not including) the value of the variable the method was invoked on. If the operand is negative, then it returns a random integer from the value of the variable the method was invoked on up to 0. 0.rand() always returns 0.
Caution: This random number generator is verified not to be cryptographically strong. Therefore, it should not be used for purposes where a strong random number is required.
-
Returns:
- A random integer between 0 and n.
toDecimal
decimal toDecimal()
Convert this integer to a decimal.
-
Returns:
- The nearest representable decimal to this integer.
toFloat
float toFloat()
Convert this integer to a float.
-
Returns:
- The nearest representable float to this integer.
toString
string toString()
Convert this integer to a string.
-
Returns:
- This integer as a string of base-10 digits.