private void removeOrphanedResources(AuthzSubject overlord) {
   final Collection<Resource> resources = resourceManager.getOrphanedResources();
   if (!resources.isEmpty()) {
     log.info("cleaning up " + resources.size() + " orphaned resources");
   }
   for (final Resource r : resources) {
     try {
       resourceManager.removeResource(overlord, r);
     } catch (VetoException e) {
       log.error(e, e);
     }
   }
 }
 public void processEvents(List<ResourcesCleanupZevent> events) {
   log.info("starting removeDeletedResources");
   final StopWatch watch = new StopWatch();
   final Collection<String> typeNames = new ArrayList<String>();
   for (final ResourcesCleanupZevent e : events) {
     if (e instanceof ResourceTypeCleanupZevent) {
       typeNames.addAll(((ResourceTypeCleanupZevent) e).getTypeNames());
     }
   }
   if (events != null && !events.isEmpty()) {
     try {
       Map<Integer, List<AppdefEntityID>> agentCache = buildAsyncDeleteAgentCache(events);
       removeDeletedResources(agentCache, typeNames);
       final AuthzSubject overlord = authzSubjectManager.getOverlordPojo();
       if (!typeNames.isEmpty()) {
         resourceManager.removeResourceTypes(typeNames);
       }
       removeOrphanedPlatforms(overlord);
       removeOrphanedServers(overlord);
       removeOrphanedServices(overlord);
       removeOrphanedAlertDefs();
       removeOrphanedResourceGroupMembers();
       removeOrphanedAudits();
       removeOrphanedEscalationStates(overlord);
       removeOrphanedResources(overlord);
     } catch (Exception e) {
       log.error("removeDeletedResources failed", e);
     }
   }
   log.info("completed removeDeletedResources " + watch);
 }