Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 Philip Helger ( philip[at]helger[dot]com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package com.helger.appbasics.longrun;
Abstract long running job.

Philip Helger
 public abstract class AbstractLongRunningJob extends AbstractJob implements ILongRunningJob
   private static final Logger s_aLogger = LoggerFactory.getLogger (AbstractLongRunningJob.class);

Predefined key into the job data map
   private static final String KEY_LONG_RUNNING_JOB_ID = "$ph-longrunningjobid";

Get the ID of the current user who executes the job.

aJobDataMap The current job data map. Never null.
The user ID to be used. May be null but it is recommended to deliver "guest" or the like instead.
   protected abstract String getCurrentUserID (@Nonnull final JobDataMap aJobDataMap);


The LongRunningJobManager to be used. May not return null.
   protected abstract LongRunningJobManager getLongRunningJobManager ();
   protected void beforeExecute (@Nonnull final JobDataMap aJobDataMap)
     final String sUserID = getCurrentUserID (aJobDataMap);
     final String sLongRunningJobID = getLongRunningJobManager ().startJob (thissUserID);
     // Store in JobDataMap
     aJobDataMap.put (sLongRunningJobID);
     super.beforeExecute (aJobDataMap);
   protected void afterExecute (@Nonnull final JobDataMap aJobDataMap, @Nonnull final ESuccess eExecSuccess)
     // End long running job before the request scope is closed
       // Get long running job ID from JobDataMap
       final String sLongRunningJobID = aJobDataMap.getString ();
       if (sLongRunningJobID != null)
         // Create the main result
         final LongRunningJobResult aJobResult = createResult ();
         getLongRunningJobManager ().endJob (sLongRunningJobIDeExecSuccessaJobResult);
         .error ("Failed to retrieve long running job ID from JobDataMap " + aJobDataMap);
     catch (final Throwable t)
       .error ("Failed to end long running job"t);
       // Notify custom exception handler
       triggerCustomExceptionHandler (tgetClass ().getName (), thistrue);
    super.afterExecute (aJobDataMapeExecSuccess);
New to GrepCode? Check out our FAQ X