CRecordGetTargetInfo
Fetch information about a registered target.
Get information about one or more targets. SYSTEM Optional: request information about a single target ID. Optional: request information about some target IDs. True = request information about all registered targets. An array of records of type TARGET_INFO
Example of use of the class CRecordGetTargetInfo (after generating)
There are three ways to fetch information about targets by message. The first option: we get the information for a single target.
private void getTargetInfoForOneTarget(@NotNull final IId aNamespaceId, @NotNull final IId aTargetId) throws CException { final CEnvelope env = CEnvelope.forLocalNanoService(CWellKnownNID.SYSTEM); final CRecord record = CRecordGetTargetInfo.create(); CRecordGetTargetInfo.setNamespaceId(record, aNamespaceId); CRecordGetTargetInfo.setTid(record, aTargetId); sendRequest(env, record); }
The second option: we fetch information about multiple targets.
private void getTargetInfoForMultipleTargets(@NotNull final IId aNamespaceId, @NotNull final IId[] aTargetIds) throws CException { final CEnvelope env = CEnvelope.forLocalNanoService(CWellKnownNID.SYSTEM); final CRecord record = CRecordGetTargetInfo.create(); CRecordGetTargetInfo.setNamespaceId(record, aNamespaceId); CRecordGetTargetInfo.setTids(record, aTargetIds); sendRequest(env, record); }
The third option: we fetch information about all targets in the namespace.
private void getTargetInfoForAllTargets(@NotNull final IId aNamespaceId) throws CException { final CEnvelope env = CEnvelope.forLocalNanoService(CWellKnownNID.SYSTEM); final CRecord record = CRecordGetTargetInfo.create(); CRecordGetTargetInfo.setNamespaceId(record, aNamespaceId); CRecordGetTargetInfo.setAllTargets(record, true); sendRequest(env, record); }
To catch the reply, we need a message handler. We add it in the constructor of the message handler registry.
// constructor:
addMessageHandler(CRecordGetTargetInfo.ID,
this::asyncGetTargetInfo);
Regardless of which option is chosen, the answer is always handled in the same way:
private boolean asyncGetTargetInfo(@NotNull final CEnvelope aEnvelope, @NotNull final CRecord aRecord) { if (aEnvelope.isAnswer()) { final int rc = aEnvelope.getResultCode(); if (rc == CResultCode.SUCCESS) { final CRecord[] targets = CRecordGetTargetInfo.getTargets(aRecord, null); for (final CRecord target : targets) { final IId tid = CRecordDataTargetInfo.getTid(target, null); final String className = CRecordDataTargetInfo.getClassName(target, ""); final String classSimpleName = CRecordDataTargetInfo.getClassSimpleName(target, ""); final IId qid = CRecordDataTargetInfo.getQid(target, null); // ... } // ... } return true; } return false; }