CRecordFileStoreGetFileInfo

The message retrieves information about a file stored in a FileStore.

This message belongs to the FileStore API. However, when it is sent to the FileRegistry, 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.",
  "isService": "true",
  "namespaces": "SYSTEM",
  "slots": [
    {
      "key": "1",
      "name": "FILE",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "RECORD",
      "description": "A single file record."
    }
  ]
}

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;
    }
}