Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 International Business Machines Corp.
   * 
   * See the NOTICE file distributed with this work for additional information
   * regarding copyright ownership. 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
   * 
   *   http://www.apache.org/licenses/LICENSE-2.0
  * 
  * 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.ibm.jbatch.container.impl;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
 
 public class BatchKernelImpl implements IBatchKernelService {
 
 	private final static String sourceClass = BatchKernelImpl.class.getName();
 	private final static Logger logger = Logger.getLogger();
 
 	private Set<LonginstanceIdExecutingSet = new HashSet<Long>();
 
 	ServicesManager servicesManager = ServicesManagerImpl.getInstance();
 
 
 
 
 	private BatchSecurityHelper batchSecurity = null;
 
 	private BatchJobUtil batchJobUtil = null;
 
 	public BatchKernelImpl() {
 
 		// registering our implementation of the util class used to purge by apptag
 	}
 
 		if ( == null) { 
 		}
 		return ;
 	}
	public void init(IBatchConfig pgcConfigthrows BatchContainerServiceException {
	}
	public void shutdown() throws BatchContainerServiceException {
		// TODO Auto-generated method stub
	}
	public IJobExecution startJob(String jobXMLthrows JobStartException {
		return startJob(jobXMLnull);
	}
	public IJobExecution startJob(String jobXMLProperties jobParametersthrows JobStartException {
		String method = "startJob";
			.entering(methodnew Object[] { jobXMLjobParameters != null ? jobParameters : "<null>" });
		}
		RuntimeJobExecution jobExecution = JobExecutionHelper.startJob(jobXMLjobParameters);
		// TODO - register with status manager
			.fine("JobExecution constructed: " + jobExecution);
		}
		BatchWorkUnit batchWork = new BatchWorkUnit(thisjobExecution);
		.executeTask(batchWorknull);
			.exiting(methodjobExecution);
		}
		return jobExecution.getJobOperatorJobExecution();
	}
	public void stopJob(long executionIdthrows NoSuchJobExecutionExceptionJobExecutionNotRunningException {
		IThreadRootController controller = this..get(executionId);
		if (controller == null) {
			String msg = "JobExecution with execution id of " + executionId + "is not running.";
			.warning("stopJob(): " + msg);
		}
		controller.stop();
	}
		String method = "restartJob";
		}
		Properties dummyPropObj = new Properties();
		return this.restartJob(executionIddummyPropObj);
	}
		String method = "restartJob";
		}
		RuntimeJobExecution jobExecution = 
				JobExecutionHelper.restartJob(executionIdjobOverrideProps);
			.fine("JobExecution constructed: " + jobExecution);
		}
		BatchWorkUnit batchWork = new BatchWorkUnit(thisjobExecution);
		.executeTask(batchWorknull);
			.exiting(methodjobExecution);
		}
		return jobExecution.getJobOperatorJobExecution();
	}
	public void jobExecutionDone(RuntimeJobExecution jobExecution) {
			.fine("JobExecution done with batchStatus: " + jobExecution.getBatchStatus() + " , getting ready to invoke callbacks for JobExecution: " + jobExecution.getExecutionId());
		}
			.fine("Done invoking callbacks for JobExecution: " + jobExecution.getExecutionId());
		}
		// Remove from executionId, instanceId map,set after job is done        
		// AJM: ah - purge jobExecution from map here and flush to DB?
		// edit: no long want a 2 tier for the jobexecution...do want it for step execution
		// renamed method to flushAndRemoveStepExecution
	}
	public IJobExecution getJobExecution(long executionIdthrows NoSuchJobExecutionException {
		/*
		 *  Keep logging on finest for apps like TCK which do polling
		 */
		.finest("Entering " +  + ".getJobExecution(), executionId = " + executionId);
		IJobExecution retVal = JobExecutionHelper.getPersistedJobOperatorJobExecution(executionId);
		.finest("Exiting " +  + ".getJobExecution(), retVal = " + retVal);
		return retVal;
	}
	public void startGeneratedJob(BatchWorkUnit batchWork) {
		String method = "startGeneratedJob";
			.entering(methodnew Object[] { batchWork });
		}
		//This call is non-blocking
			.exiting(methodnew Object[] { batchWork });
		}
	}
	public int getJobInstanceCount(String jobName) {
		int jobInstanceCount = 0;
		return jobInstanceCount;
	}
	public JobInstance getJobInstance(long executionId){
		return JobExecutionHelper.getJobInstance(executionId);
	}


Build a list of batch work units and set them up in STARTING state but don't start them yet.
		List<JSLJobjobModels = config.getJobModels();
		Properties[] partitionPropertiesArray = config.getPartitionProperties();
		List<BatchPartitionWorkUnitbatchWorkUnits = new ArrayList<BatchPartitionWorkUnit>(jobModels.size());
		int instance = 0;
		for (JSLJob parallelJob  : jobModels){
			Properties partitionProps = (partitionPropertiesArray == null) ? null : partitionPropertiesArray[instance];    			
				.finer("Starting execution for jobModel = " + parallelJob.toString());
			}
			RuntimeJobExecution jobExecution = JobExecutionHelper.startPartition(parallelJobpartitionProps);
				.fine("JobExecution constructed: " + jobExecution);
			}
			BatchPartitionWorkUnit batchWork = new BatchPartitionWorkUnit(thisjobExecutionconfig);
			batchWorkUnits.add(batchWork);
			instance++;
		}
		return batchWorkUnits;
	}
		List<JSLJobjobModels = config.getJobModels();
		Properties[] partitionProperties = config.getPartitionProperties();
		List<BatchPartitionWorkUnitbatchWorkUnits = new ArrayList<BatchPartitionWorkUnit>(jobModels.size());
		//for now let always use a Properties array. We can add some more convenience methods later for null properties and what not
		int instance = 0;
		for (JSLJob parallelJob  : jobModels){
			Properties partitionProps = (partitionProperties == null) ? null : partitionProperties[instance];    
			try {
				long execId = getMostRecentExecutionId(parallelJob);
				RuntimeJobExecution jobExecution = null;
				try {		
					jobExecution = JobExecutionHelper.restartPartition(execIdparallelJobpartitionProps);
					String errorMsg = "Caught NoSuchJobExecutionException but this is an internal JobExecution so this shouldn't have happened: execId =" + execId;
					.severe(errorMsg);
					throw new IllegalStateException(errorMsge);
				}
					.fine("JobExecution constructed: " + jobExecution);
				}
				BatchPartitionWorkUnit batchWork = new BatchPartitionWorkUnit(thisjobExecutionconfig);
				batchWorkUnits.add(batchWork);
				.fine("This execution already completed: " + parallelJob.getId());
			}
			instance++;
		}
		return batchWorkUnits;
	}
	public void  restartGeneratedJob(BatchWorkUnit batchWorkthrows JobRestartException {
		String method = "restartGeneratedJob";
			.entering(methodnew Object[] { batchWork });
		}
		//This call is non-blocking
			.exiting(methodbatchWork);
		}
	}
		JSLJob parallelJob = config.getJobModel();
		RuntimeFlowInSplitExecution execution = JobExecutionHelper.startFlowInSplit(parallelJob);
			.fine("JobExecution constructed: " + execution);
		}
		BatchFlowInSplitWorkUnit batchWork = new BatchFlowInSplitWorkUnit(thisexecutionconfig);
		return batchWork;
	}
	private long getMostRecentExecutionId(JSLJob jobModel) {
		//There can only be one instance associated with a subjob's id since it is generated from an unique
		//job instance id. So there should be no way to directly start a subjob with particular
		List<LonginstanceIds = .jobOperatorGetJobInstanceIds(jobModel.getId(), 0, 2);
		// Maybe we should blow up on '0' too?
		if (instanceIds.size() > 1) {
			String errorMsg = "Found " + instanceIds.size() + " entries for instance id = " + jobModel.getId() + ", which should not have happened.  Blowing up."
			.severe(errorMsg);
			throw new IllegalStateException(errorMsg);
		}
		Long execId = .;
		for (IJobExecution partitionExec : partitionExecs ) {
			if (partitionExec.getExecutionId() > execId ) {
				execId = partitionExec.getExecutionId();
			}
		}
		return execId;
	}
		String method = "buildOnRestartFlowInSplitWorkUnit";
		JSLJob jobModel = config.getJobModel();
			.entering(methodjobModel);
		}
		long execId = getMostRecentExecutionId(jobModel);
		RuntimeFlowInSplitExecution jobExecution = null;
		try {		
			jobExecution = JobExecutionHelper.restartFlowInSplit(execIdjobModel);
			String errorMsg = "Caught NoSuchJobExecutionException but this is an internal JobExecution so this shouldn't have happened: execId =" + execId;
			.severe(errorMsg);
			throw new IllegalStateException(errorMsge);
		}
			.fine("JobExecution constructed: " + jobExecution);
		}
		BatchFlowInSplitWorkUnit batchWork = new BatchFlowInSplitWorkUnit(thisjobExecutionconfig);
		return batchWork;
	}
		long execId = jobExecution.getExecutionId();
		long instanceId = jobExecution.getInstanceId();
		String errorPrefix = "Tried to execute with Job executionId = " + execId + " and instanceId = " + instanceId + " ";
		if (.get(execId) != null) {
			String errorMsg = errorPrefix + "but executionId is already currently executing.";
			.warning(errorMsg);
			throw new IllegalStateException(errorMsg);
else if (.contains(instanceId)) {
			String errorMsg = errorPrefix + "but another execution with this instanceId is already currently executing.";
			.warning(errorMsg);
			throw new IllegalStateException(errorMsg);
else {
			.put(jobExecution.getExecutionId(), controller);
		}
	}
	public boolean isExecutionRunning(long executionId) {
	}
New to GrepCode? Check out our FAQ X