CRecordFileStoreGetFileInfo
The message retrieves information about a file stored in a The File Store API.
This message belongs to the FileStore API. However, when it is sent to the The File Registry API, the FileRegistry selects a FileStore that hosts the requested file and forwards the message to that FileStore. In this way, the sender not only receives the file's data but also learns which FileStore it is stored in.
{
"id": "eddce1c9-070c-420b-b08a-709ac4ad8996",
"name": "FILE_STORE_GET_FILE_INFO",
"description": "Get the metadata for a file from a network file store.",
"isNanoService": "true",
"type": "REQUEST",
"namespaces": "SYSTEM",
"slots": [
{
"key": "1",
"name": "FILE",
"direction": "REQUEST",
"presenceConstraint": "MANDATORY",
"type": "RECORD",
"description": "A single file record."
}
]
}
Slot Description
| Key | Name | Direction | Presence Constraint | Type | Description |
|---|---|---|---|---|---|
| 1 | FILE | REQUEST | MANDATORY | RECORD | When a request is made, the hash and/or path of the file is stored in the CRecordFileStoreFile record. The recipient then fills in the remaining fields of the record for the response. |
Usage
Request
The payload of the record consists only of a record of type CRecordFileStoreFile.
In the request (outbound), the path and optionally the hash of the requested file are transmitted.
In the response (return), the record contains the remaining information about the requested file if successful.
final IId microServiceId = CIdFactory.fromObject("file.registry"); final CEnvelope env = CEnvelope.forMicroService(microServiceId); final CRecord record1 = CRecordFileStoreGetFileInfo.create(); final CRecord record2 = CRecordFileStoreFile.create(); CRecordFileStoreFile.setHash(record2, aHash); CRecordFileStoreFile.setPath(record2, aPath); CRecordFileStoreGetFileInfo.setFile(record1, record2); sendRequest(env, record1);
Catch the response
In the constructor:
addMessageHandler(CRecordFileStoreGetFileInfo.ID,
this::asyncFileStoreGetFileInfo);
Message handler
private boolean asyncFileStoreGetFileInfo(@NotNull final CEnvelope aEnvelope, @NotNull final CRecord aRecord) { if (aEnvelope.isAnswer()) { if (aEnvelope.getResult() .hasSuccess()) { final CRecord rec = CRecordFileStoreGetFileInfo.getFile(aRecord, null); if (rec != null) { // this is the address of the file store that offers the file final CTargetAddress sourceAddress = aEnvelope.getSender(); final String path = CRecordFileStoreFile.getPath(rec, null); final String hash = CRecordFileStoreFile.getHash(rec, null); final Instant timeOfLastModification = CRecordFileStoreFile.getTimeOfLastModification(rec, null); final long fileLength = CRecordFileStoreFile.getFileLength(rec, 0L); final Instant timeOfCreation = CRecordFileStoreFile.getTimeOfCreation(rec, null); //... } } return true; } else { return false; } }
Record Usage
In
One or more descriptions of these Records are stored in the JSON or XML format
as record.json or record.xml within a directory.
The Record Generator, an included Swing tool, generates helper classes from these files.
These classes can then be used to type-safely write or read messages.