- All Implemented Interfaces:
IAssociative<Keyword,,ACell> IValidated,IWriteable,Map<Keyword,ACell>
Class representing the result of a Convex interaction (typically a query or transaction).
A Result is typically used to communicate the outcome of a query or a transaction from a peer to a client.
Contains:
- Message ID - used for message correlation
- Result value - Any CVM value as the result (may be an error message)
- Error Code - Error Code, or null if the Result was a success
- Log Records
- Additional info
-
Nested Class Summary
-
Field Summary
Fields inherited from class convex.core.data.ARecordGeneric
format, valuesFields inherited from class convex.core.data.ARecord
DEFAULT_VALUEFields inherited from class convex.core.data.ADataStructure
countFields inherited from class convex.core.data.ACell
cachedRef, memorySize -
Method Summary
Modifier and TypeMethodDescriptionstatic ResultbuildFromVector(AVector<ACell> values) static ResultCreate a Resultstatic ResultCreate a Resultstatic ResultCreate a Resultstatic Resultcreate(CVMLong id, ACell value, ACell errorCode, AVector<AVector<ACell>> log, AHashMap<Keyword, ACell> info) Create a Resultintencode(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.static Resultstatic Resultstatic ResultfromContext(CVMLong id, ResultContext rc) Constructs a Result from a Contextstatic ResultfromContext(Context ctx) Constructs a Result from a Context.static ResultConstructs a result from a caught exceptionReturns the Error Code from this Result.Gets the RecordFormat instance that describes this Record's layoutgetID()Returns the message ID for this result.getInfo()Returns the info for this Result.getLog()Returns the log for this Result.Returns the error source code from this Result (see CAD11).bytegetTag()Gets the tag byte for this record type.getTrace()Returns the stack trace for this result.<T extends ACell>
TgetValue()Returns the value for this result.static ResultReturns a Result representing a thread interrupt, AND sets the interrupt status on the current threadbooleanisError()Tests is the Result represents an Errorstatic ResultReads a Result from a Blob encoding.toJSON()Converts this result to a JSON representation.voidValidates the local structure and invariants of this cell.values()Gets a vector of values for this Record, in format-determined orderwithExtraInfo(Map<Keyword, ACell> extInfo) Updates result with a given message ID.Returns this Result with extra info fieldwithSource(Keyword source) protected ResultwithValues(AVector<ACell> newValues) Updates the record with a new set of values.Methods inherited from class convex.core.data.ARecordGeneric
encodeRaw, entryAt, equals, equals, get, getRef, getRefCount, updateRefsMethods inherited from class convex.core.data.ARecord
accumulateEntrySet, accumulateKeySet, accumulateValues, assoc, assocEntry, containsKey, containsValue, dissoc, dissoc, empty, entrySet, estimatedEncodingSize, forEach, get, getEntry, getEntryByHash, getKeyRefEntry, getKeys, getType, getValuesArray, isCanonical, isCVMValue, keySet, reduceEntries, reduceValues, toCanonical, toHashMapMethods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, containsValue, entryVector, filterValues, get, get, get, getElementRef, merge, print, put, putAll, remove, slice, sliceMethods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, isDataValue, isEmpty, size, toCVMStringMethods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, hashCode, isEmbedded, toString, validateMethods inherited from class convex.core.data.AObject
attachEncoding, print, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, size
-
Method Details
-
buildFromVector
-
create
Create a Result- Parameters:
id- ID of Result messagevalue- Result ValueerrorCode- Error Code (may be null for success)info- Additional info- Returns:
- Result instance
-
create
public static Result create(CVMLong id, ACell value, ACell errorCode, AVector<AVector<ACell>> log, AHashMap<Keyword, ACell> info) Create a Result- Parameters:
id- ID of Result messagevalue- Result ValueerrorCode- Error Code (may be null for success)log- Log entries created during transactioninfo- Additional info- Returns:
- Result instance
-
create
Create a Result- Parameters:
id- ID of Result messagevalue- Result ValueerrorCode- Error Code (may be null for success)- Returns:
- Result instance
-
create
Create a Result- Parameters:
id- ID of Result messagevalue- Result Value- Returns:
- Result instance
-
error
-
error
-
getID
Returns the message ID for this result. Message ID is an arbitrary ID assigned by a client requesting a transaction.- Returns:
- ID from this result
-
getValue
Returns the value for this result. The value is the result of transaction execution (may be an error message if the transaction failed)- Type Parameters:
T- Type of Value- Returns:
- ID from this result
-
getTrace
Returns the stack trace for this result. May be null- Returns:
- Trace vector from this result
-
getInfo
Returns the info for this Result. May be null- Returns:
- Info map from this result
-
withInfo
Returns this Result with extra info field- Parameters:
k- Information field keyv- Information field value- Returns:
- Updated result
-
withSource
-
getLog
Returns the log for this Result. May be an empty vector.- Returns:
- Log Vector from this Result
-
getErrorCode
Returns the Error Code from this Result. Normally this should be a Keyword. Will be null if no error occurred.- Returns:
- Error code from this result
-
getSource
Returns the error source code from this Result (see CAD11). This a Keyword. Will be null if :source info not available- Returns:
- Source code keyword from this result,. or null if not present / invalid
-
values
Description copied from class:ARecordGets a vector of values for this Record, in format-determined order -
withValues
Description copied from class:ARecordGenericUpdates the record with a new set of values. Returns this if and only if values vector is identical.- Specified by:
withValuesin classARecordGeneric- Parameters:
newValues- New values to use- Returns:
- Updated Record
-
validateCell
Description copied from class:ACellValidates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.- Overrides:
validateCellin classARecordGeneric- Throws:
InvalidDataException- If the Cell is invalid
-
encode
public int encode(byte[] bs, int pos) Description copied from class:ACellWrites this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.- Specified by:
encodein interfaceIWriteable- Specified by:
encodein classACell- Parameters:
bs- A byte array to which to write the encodingpos- The offset into the byte array- Returns:
- New position after writing
-
read
Reads a Result from a Blob encoding. Assumes tag byte already checked.- Parameters:
b- Blob to read frompos- Start position in Blob (location of tag byte)- Returns:
- New decoded instance
- Throws:
BadFormatException- In the event of any encoding error
-
isError
public boolean isError()Tests is the Result represents an Error- Returns:
- True if error, false otherwise
-
fromContext
Constructs a Result from a Context- Parameters:
id- Id for Resultrc- ResultContext instance from which to extract Result- Returns:
- New Result instance
-
withExtraInfo
-
fromContext
Constructs a Result from a Context. No ResultContext implies we are not in a top level transaction, so minimise work- Parameters:
ctx- Context- Returns:
- New Result instance
-
withID
Updates result with a given message ID. Used to tag Results for return to Clients- Parameters:
id- New Result message ID- Returns:
- Updated Result
-
getTag
public byte getTag()Description copied from class:ARecordGets the tag byte for this record type. The Tag is the byte used to identify the record in the binary encoding.- Specified by:
getTagin classARecordGeneric- Returns:
- Record tag byte
-
getFormat
Description copied from class:ARecordGets the RecordFormat instance that describes this Record's layout -
fromException
Constructs a result from a caught exception- Parameters:
e- Exception caught- Returns:
- Result instance representing the exception (will be an error)
-
interruptThread
Returns a Result representing a thread interrupt, AND sets the interrupt status on the current thread- Returns:
- Result instance representing an interruption
-
toJSON
Converts this result to a JSON representation. WARNING: some information may be lost because JSON is a terrible format.- Returns:
- JSON Object containing values from this Result
-