@ Nonnull public static ESuccess executeWorkItem ( @ Nonnull final IPDStorageManager aStorageMgr , @ Nonnull final IIndexerWorkItem aWorkItem , @ Nonnegative final int nRetryCount , @ Nonnull final Consumer < ? super IIndexerWorkItem > aSuccessHandler , @ Nonnull final Consumer < ? super IIndexerWorkItem > aFailureHandler ) { LOGGER . info ( "Execute work item " + aWorkItem . getLogText ( ) + " - " + ( nRetryCount > 0 ? "retry #" + nRetryCount : "initial try" ) ) ; try { final IParticipantIdentifier aParticipantID = aWorkItem . getParticipantID ( ) ; ESuccess eSuccess ; switch ( aWorkItem . getType ( ) ) { case CREATE_UPDATE : { // Get BI from participant (e.g. from SMP) final PDExtendedBusinessCard aBI = PDMetaManager . getBusinessCardProvider ( ) . getBusinessCard ( aParticipantID ) ; if ( aBI == null ) { // No/invalid extension present - no need to try again eSuccess = ESuccess . FAILURE ; } else { // Got data - put in storage eSuccess = aStorageMgr . createOrUpdateEntry ( aParticipantID , aBI , aWorkItem . getAsMetaData ( ) ) ; } break ; } case DELETE : { // Only mark as deleted eSuccess = aStorageMgr . markEntryDeleted ( aParticipantID , aWorkItem . getAsMetaData ( ) ) ; break ; } case SYNC : { // Get BI from participant (e.g. from SMP) final PDExtendedBusinessCard aBI = PDMetaManager . getBusinessCardProvider ( ) . getBusinessCard ( aParticipantID ) ; if ( aBI == null ) { // No/invalid extension present - delete from index eSuccess = aStorageMgr . markEntryDeleted ( aParticipantID , aWorkItem . getAsMetaData ( ) ) ; } else { // Got data - put in storage eSuccess = aStorageMgr . createOrUpdateEntry ( aParticipantID , aBI , aWorkItem . getAsMetaData ( ) ) ; } break ; } default : throw new IllegalStateException ( "Unsupported work item type: " + aWorkItem ) ; } if ( eSuccess . isSuccess ( ) ) { // Item handled - remove from overall list aSuccessHandler . accept ( aWorkItem ) ; // And we're done return ESuccess . SUCCESS ; } // else error storing data } catch ( final Exception ex ) { LOGGER . error ( "Error in executing work item " + aWorkItem . getLogText ( ) , ex ) ; // Fall through } // Invoke failure handler aFailureHandler . accept ( aWorkItem ) ; return ESuccess . FAILURE ; }
This method is responsible for executing the specified work item depending on its type .