use of org.alfresco.repo.activities.feed.JobSettings in project alfresco-repository by Alfresco.
the class LocalFeedGridJob method execute.
public Serializable execute() throws Exception {
JobSettings js = getArgument();
if (logger.isDebugEnabled()) {
logger.debug(">>> Execute: nodehash '" + js.getJobTaskNode() + "' from seq '" + js.getMinSeq() + "' to seq '" + js.getMaxSeq() + "' on this node");
}
feedTaskProcessor.process(js.getJobTaskNode(), js.getMinSeq(), js.getMaxSeq(), js.getWebScriptsCtx());
// This job does not return any result.
return null;
}
use of org.alfresco.repo.activities.feed.JobSettings in project alfresco-repository by Alfresco.
the class LocalFeedTaskSplitter method split.
public Collection<FeedGridJob> split(int gridSize, Object o) throws Exception {
FeedTaskSplit feedSplitter = new FeedTaskSplit();
Collection<JobSettings> jobs = feedSplitter.split(gridSize, (JobSettings) o);
List<FeedGridJob> gridJobs = new ArrayList<FeedGridJob>(jobs.size());
for (JobSettings job : jobs) {
LocalFeedGridJob gridJob = new LocalFeedGridJob();
gridJob.setFeedTaskProcessor(feedTaskProcessor);
gridJob.setArgument(job);
gridJobs.add(gridJob);
}
return gridJobs;
// return (Collection<FeedGridJob>)feedSplitter.split(gridSize, (JobSettings)o, new LocalFeedGridJob());
}
use of org.alfresco.repo.activities.feed.JobSettings in project alfresco-repository by Alfresco.
the class LocalFeedGenerator method generate.
protected boolean generate() throws Exception {
final Long maxSequence = getPostDaoService().getMaxActivitySeq();
final Long minSequence = getPostDaoService().getMinActivitySeq();
final Integer maxNodeHash = getPostDaoService().getMaxNodeHash();
if ((maxSequence == null) || (minSequence == null) || (maxNodeHash == null)) {
return false;
}
// TODO ... or push this upto to job scheduler ... ?
AuthenticationUtil.runAs(new RunAsWork<Object>() {
public Object doWork() {
getWebScriptsCtx().setTicket(getAuthenticationService().getCurrentTicket());
return null;
}
}, // need web scripts to support System-level authentication ... see RepositoryContainer !
AuthenticationUtil.getSystemUserName());
// process the activity posts using the batch processor {@link BatchProcessor}
BatchProcessor.BatchProcessWorker<JobSettings> worker = new BatchProcessor.BatchProcessWorker<JobSettings>() {
@Override
public String getIdentifier(final JobSettings js) {
// TODO
StringBuilder sb = new StringBuilder("JobSettings ");
sb.append(js);
return sb.toString();
}
@Override
public void beforeProcess() throws Throwable {
}
@Override
public void afterProcess() throws Throwable {
}
@Override
public void process(final JobSettings js) throws Throwable {
final RetryingTransactionHelper txHelper = getTransactionService().getRetryingTransactionHelper();
txHelper.setMaxRetries(0);
txHelper.doInTransaction(new RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
int jobTaskNode = js.getJobTaskNode();
long minSeq = js.getMinSeq();
long maxSeq = js.getMaxSeq();
RepoCtx webScriptsCtx = js.getWebScriptsCtx();
// FeedTaskProcessor takes JobSettings parameters instead collection of ActivityPost. FeedTaskProcessor can be refactored.
feedTaskProcessor.process(jobTaskNode, minSeq, maxSeq, webScriptsCtx);
return null;
}
}, false, true);
}
};
// provides a JobSettings object
BatchProcessWorkProvider<JobSettings> provider = new BatchProcessWorkProvider<JobSettings>() {
private Long skip = minSequence;
private boolean hasMore = true;
@Override
public int getTotalEstimatedWorkSize() {
long size = maxSequence - minSequence + 1;
long remain = size % batchSize;
long workSize = (remain == 0) ? (size / batchSize) : (size / batchSize + 1);
return (int) workSize;
}
@Override
public Collection<JobSettings> getNextWork() {
if (!hasMore) {
return Collections.emptyList();
}
JobSettings js = new JobSettings();
js.setMinSeq(skip);
js.setMaxSeq(skip + batchSize - 1);
js.setJobTaskNode(maxNodeHash);
js.setWebScriptsCtx(getWebScriptsCtx());
skip += batchSize;
hasMore = skip > maxSequence ? false : true;
// One JobSettings object will be returned. Because FeedTaskProcessor fetches list activity posts by itself before processing.
List<JobSettings> result = new ArrayList<JobSettings>(1);
result.add(js);
return result;
}
};
final RetryingTransactionHelper txHelper = getTransactionService().getRetryingTransactionHelper();
txHelper.setMaxRetries(0);
// batchSize and loggingInterval parameters are equal 1 because provider always will provide collection with one JobSettings object.
// FeedTaskProcessor fetches list activity posts by itself before processing. It needs only JobSettings parameters. FeedTaskProcessor can be refactored.
new BatchProcessor<JobSettings>("LocalFeedGenerator", txHelper, provider, numThreads, 1, null, logger, 1).process(worker, true);
return true;
}
Aggregations