private ServiceResponse<KieScannerResource> startScanner(
     String id, KieScannerResource resource, KieContainerInstance kci) {
   if (kci.getScanner() == null) {
     ServiceResponse<KieScannerResource> response = createScanner(id, kci);
     if (ResponseType.FAILURE.equals(response.getType())) {
       return response;
     }
   }
   if (KieScannerStatus.STOPPED.equals(mapStatus(kci.getScanner().getStatus()))
       && resource.getPollInterval() != null) {
     kci.getScanner().start(resource.getPollInterval());
     return new ServiceResponse<KieScannerResource>(
         ServiceResponse.ResponseType.SUCCESS,
         "Kie scanner successfuly created.",
         new KieScannerResource(mapStatus(kci.getScanner().getStatus())));
   } else if (!KieScannerStatus.STOPPED.equals(mapStatus(kci.getScanner().getStatus()))) {
     return new ServiceResponse<KieScannerResource>(
         ServiceResponse.ResponseType.FAILURE,
         "Invalid kie scanner status: " + mapStatus(kci.getScanner().getStatus()),
         new KieScannerResource(mapStatus(kci.getScanner().getStatus())));
   } else if (resource.getPollInterval() == null) {
     return new ServiceResponse<KieScannerResource>(
         ServiceResponse.ResponseType.FAILURE,
         "Invalid polling interval: " + resource.getPollInterval(),
         new KieScannerResource(mapStatus(kci.getScanner().getStatus())));
   }
   return new ServiceResponse<KieScannerResource>(
       ServiceResponse.ResponseType.FAILURE,
       "Unknown error starting scanner. Scanner was not started." + resource,
       new KieScannerResource(mapStatus(kci.getScanner().getStatus())));
 }
 public ServiceResponse<KieScannerResource> getScannerInfo(String id) {
   try {
     KieContainerInstance kci = (KieContainerInstance) context.getContainer(id);
     if (kci != null && kci.getKieContainer() != null) {
       InternalKieScanner scanner = kci.getScanner();
       KieScannerResource info = null;
       if (scanner != null) {
         info = new KieScannerResource(mapStatus(scanner.getStatus()));
       } else {
         info = new KieScannerResource(KieScannerStatus.DISPOSED);
       }
       return new ServiceResponse<KieScannerResource>(
           ServiceResponse.ResponseType.SUCCESS, "Scanner info successfully retrieved", info);
     } else {
       return new ServiceResponse<KieScannerResource>(
           ServiceResponse.ResponseType.FAILURE, "Unknown container " + id + ".");
     }
   } catch (Exception e) {
     logger.error("Error retrieving scanner info for container '" + id + "'.", e);
     return new ServiceResponse<KieScannerResource>(
         ServiceResponse.ResponseType.FAILURE,
         "Error retrieving scanner info for container '"
             + id
             + "': "
             + e.getClass().getName()
             + ": "
             + e.getMessage());
   }
 }
 private ServiceResponse<KieScannerResource> disposeScanner(
     String id, KieScannerResource resource, KieContainerInstance kci) {
   if (kci.getScanner() == null) {
     return new ServiceResponse<KieScannerResource>(
         ServiceResponse.ResponseType.SUCCESS,
         "Invalid call. Scanner already disposed. ",
         new KieScannerResource(KieScannerStatus.DISPOSED));
   }
   if (KieScannerStatus.STARTED.equals(mapStatus(kci.getScanner().getStatus()))
       || KieScannerStatus.SCANNING.equals(mapStatus(kci.getScanner().getStatus()))) {
     ServiceResponse<KieScannerResource> response = stopScanner(id, resource, kci);
     if (ResponseType.FAILURE.equals(response.getType())) {
       return response;
     }
   }
   kci.getScanner().shutdown();
   kci.setScanner(null);
   return new ServiceResponse<KieScannerResource>(
       ServiceResponse.ResponseType.SUCCESS,
       "Kie scanner successfuly shutdown.",
       new KieScannerResource(KieScannerStatus.DISPOSED));
 }
 private ServiceResponse<KieScannerResource> createScanner(String id, KieContainerInstance kci) {
   if (kci.getScanner() == null) {
     InternalKieScanner scanner =
         (InternalKieScanner) KieServices.Factory.get().newKieScanner(kci.getKieContainer());
     kci.setScanner(scanner);
     return new ServiceResponse<KieScannerResource>(
         ServiceResponse.ResponseType.SUCCESS,
         "Kie scanner successfuly created.",
         new KieScannerResource(mapStatus(scanner.getStatus())));
   } else {
     return new ServiceResponse<KieScannerResource>(
         ServiceResponse.ResponseType.FAILURE,
         "Error creating the scanner for container " + id + ". Scanner already exists.");
   }
 }
 private ServiceResponse<KieScannerResource> stopScanner(
     String id, KieScannerResource resource, KieContainerInstance kci) {
   if (kci.getScanner() == null) {
     return new ServiceResponse<KieScannerResource>(
         ServiceResponse.ResponseType.FAILURE,
         "Invalid call. Scanner is not instantiated. ",
         new KieScannerResource(KieScannerStatus.DISPOSED));
   }
   if (KieScannerStatus.STARTED.equals(mapStatus(kci.getScanner().getStatus()))
       || KieScannerStatus.SCANNING.equals(mapStatus(kci.getScanner().getStatus()))) {
     kci.getScanner().stop();
     return new ServiceResponse<KieScannerResource>(
         ServiceResponse.ResponseType.SUCCESS,
         "Kie scanner successfuly stopped.",
         new KieScannerResource(mapStatus(kci.getScanner().getStatus())));
   } else {
     return new ServiceResponse<KieScannerResource>(
         ServiceResponse.ResponseType.FAILURE,
         "Invalid kie scanner status: " + mapStatus(kci.getScanner().getStatus()),
         new KieScannerResource(mapStatus(kci.getScanner().getStatus())));
   }
 }