public void registerActivity(@Nonnull final JID userJid)
    {
        // Only tracking it for the local cluster node, as those are the only users for which this node will monitor activity anyway
        mutex.writeLock().lock();
        try {
            if (XMPPServer.getInstance().isLocal(userJid)) {
                final Map<JID, Set<Occupant>> localOccupants = localOccupantsByNode.get((XMPPServer.getInstance().getNodeID()));
                if (localOccupants != null) {
                    final Set<Occupant> localOccupantsForUser = localOccupants.get(userJid);
                    if (localOccupantsForUser != null) {
                        localOccupantsForUser.forEach(occupant -> occupant.setLastActive(Instant.now()));
                    }
                }
            } else {
                final Set<Occupant> federatedOccupantsForUser = federatedOccupants.get(userJid);
                if (federatedOccupantsForUser != null) {
                    federatedOccupantsForUser.forEach(occupant -> occupant.setLastActive(Instant.now()));
                }
            }
        } finally {
            mutex.writeLock().unlock();
        }
    }
@Test
    public void testRegisterActivity() throws Exception
    {
        // Setup test fixture.
        final OccupantManager occupantManager = new OccupantManager(mockService);
        final JID roomJID = new JID("room", mockService.getServiceDomain(), null);
        final JID userJID = new JID("johndoe", "example.org", null);
        final String nickname = "John Doe";
        final Duration pause = Duration.ofMillis(10);

        // Execute system under test.
        occupantManager.occupantJoined(roomJID, userJID, nickname);
        final Instant start = Instant.now();
        Thread.sleep(pause.toMillis());
        occupantManager.registerActivity(userJID);

        // Verify results.
        final Instant lastActive = occupantManager.getLocalOccupants().iterator().next().getLastActive();
        assertTrue(Duration.between(start, lastActive).compareTo(pause) >= 0);
    }