CRecordFileRegistryGetFileInfo

With it, we retrieve information about available files. The key to the files is the provided relative path of the desired file.

This message is part of the FileRegistry API.

{
  "id": "18124fad-2724-4d9f-bc85-1b835fde5a8d",
  "name": "FILE_REGISTRY_GET_FILE_INFO",
  "description": "Get information about a file from the file registry.",
  "slots": [
    {
      "key": "path",
      "name": "PATH",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The relative path of the file."
    },
    {
      "key": "rec",
      "name": "FILE_INFO",
      "direction": "ANSWER",
      "mandatory": "false",
      "type": "RECORD_ARRAY",
      "description": "The information about files in the file registry.\nRecords are from type FILE_REGISTRY_FILE_INFO"
    }
  ]
}

Usage

Send a request to the FileRegistry microservice.

final IId microServiceId = CIdFactory.fromObject("file.registry");
final CEnvelope env = CEnvelope.forMicroService(microServiceId);

final CRecord record = CRecordFileRegistryGetFileInfo.create();
CRecordFileRegistryGetFileInfo.setPath(record,
                                       "lib\junit-4.10.jar");
sendRequest(env,
            record);

Receive the response.

// in constructor:
addMessageHandler(CRecordFileRegistryGetFileInfo.ID,
                  this::asyncGetFileInfo);

// fetch microservice data from reply
private boolean asyncGetFileInfo(@NotNull final CEnvelope aEnvelope,
                                 @NotNull final CRecord aRecord)
{
    if (aEnvelope.isAnswer())
    {
        if (aEnvelope.getResult()
                     .hasSuccess())
        {
            final CRecord[] arr = CRecordFileRegistryGetFileInfo.getFileInfo(aRecord,
                                                                             null);
            if (arr != null)
            {
                for (final CRecord rec : arr)
                {
                    final String path = CRecordFileRegistryFileInfo.getPath(rec,
                                                                            null);
                    final String hash = CRecordFileRegistryFileInfo.getHash(rec,
                                                                            null);
                    final Instant timeOfLastModification = CRecordFileRegistryFileInfo.getTimeOfLastModification(rec,
                                                                                                                 null);
                    final CTargetAddress sourceAddress = CRecordFileRegistryFileInfo.getSourceAddress(rec,
                                                                                                      null);

                    //...
                }
            }
        }
        return true;
    }
    else
    {
        return false;
    }
}

nyssr.net - Innovative Distributed System