Search in sources :

Example 1 with MDSProcessorOutput

use of org.motechproject.mds.annotations.internal.MDSProcessorOutput in project motech by motech.

the class MdsBundleWatcher method processSingleBundle.

private void processSingleBundle(final Bundle bundle) {
    SchemaHolder schemaHolder = lockAndGetSchema();
    final MDSProcessorOutput output = process(bundle, schemaHolder);
    if (hasNonEmptyOutput(output)) {
        TransactionTemplate tmpl = new TransactionTemplate(transactionManager);
        tmpl.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                schemaChangeLockManager.acquireLock(MdsBundleWatcher.class.getName() + " - saving output of bundle processing");
                processAnnotationScanningResults(output);
                schemaChangeLockManager.releaseLock(MdsBundleWatcher.class.getName() + " - saving output of bundle processing");
            }
        });
        schemaHolder = lockAndGetSchema();
        // if we found annotations, we will refresh the bundle in order to start weaving the
        // classes it exposes
        refreshBundle(bundle, schemaHolder);
    }
}
Also used : MDSProcessorOutput(org.motechproject.mds.annotations.internal.MDSProcessorOutput) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 2 with MDSProcessorOutput

use of org.motechproject.mds.annotations.internal.MDSProcessorOutput in project motech by motech.

the class MdsBundleWatcher method start.

// called by the initializer after the initial entities bundle was generated
public void start() {
    LOGGER.info("Scanning for MDS annotations");
    bundlesToRefresh = new ArrayList<>();
    StopWatch stopWatch = new StopWatch();
    SchemaHolder schemaHolder = lockAndGetSchema();
    final List<MDSProcessorOutput> mdsProcessorOutputs = processInstalledBundles(schemaHolder);
    stopWatch.start();
    new TransactionTemplate(transactionManager).execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            schemaChangeLockManager.acquireLock(MdsBundleWatcher.class.getName() + " - start annotation processing");
            for (MDSProcessorOutput output : mdsProcessorOutputs) {
                processAnnotationScanningResults(output);
            }
            schemaChangeLockManager.releaseLock(MdsBundleWatcher.class.getName() + " - start annotation processing");
        }
    });
    stopWatch.stop();
    LOGGER.info("Annotation processing finished in {} ms", stopWatch.getTime());
    // classes it exposes
    if (!bundlesToRefresh.isEmpty()) {
        LOGGER.info("Starting bundle refresh process");
        schemaHolder = lockAndGetSchema();
        LOGGER.info("Refreshing bundles: {}", bundlesToRefresh);
        StopWatchHelper.restart(stopWatch);
        refreshBundles(bundlesToRefresh, schemaHolder);
        stopWatch.stop();
        LOGGER.info("Bundle refresh finished in {} ms", stopWatch.getTime());
    } else {
        LOGGER.info("No bundles to refresh, proceeding");
    }
    bundleContext.addBundleListener(this);
}
Also used : MDSProcessorOutput(org.motechproject.mds.annotations.internal.MDSProcessorOutput) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) StopWatch(org.apache.commons.lang.time.StopWatch)

Example 3 with MDSProcessorOutput

use of org.motechproject.mds.annotations.internal.MDSProcessorOutput in project motech by motech.

the class EditableLookupsLoaderTest method prepareOutput.

private void prepareOutput() {
    EntityProcessorOutput entityProcessorOutput = new EntityProcessorOutput();
    entityProcessorOutput.setEntityProcessingResult(prepareEntityDto());
    List<EntityProcessorOutput> entityProcessorOutputs = new ArrayList<>();
    entityProcessorOutputs.add(entityProcessorOutput);
    output = new MDSProcessorOutput(entityProcessorOutputs, new HashMap<>(), bundle);
}
Also used : MDSProcessorOutput(org.motechproject.mds.annotations.internal.MDSProcessorOutput) EntityProcessorOutput(org.motechproject.mds.annotations.internal.EntityProcessorOutput) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 4 with MDSProcessorOutput

use of org.motechproject.mds.annotations.internal.MDSProcessorOutput in project motech by motech.

the class MdsBundleWatcher method processInstalledBundles.

private List<MDSProcessorOutput> processInstalledBundles(SchemaHolder schemaHolder) {
    List<MDSProcessorOutput> outputs = new ArrayList<>();
    for (Bundle bundle : bundleContext.getBundles()) {
        MDSProcessorOutput output = process(bundle, schemaHolder);
        if (hasNonEmptyOutput(output)) {
            outputs.add(output);
            bundlesToRefresh.add(bundle);
        }
    }
    return outputs;
}
Also used : MDSProcessorOutput(org.motechproject.mds.annotations.internal.MDSProcessorOutput) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList)

Aggregations

MDSProcessorOutput (org.motechproject.mds.annotations.internal.MDSProcessorOutput)4 ArrayList (java.util.ArrayList)2 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)2 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)2 HashMap (java.util.HashMap)1 StopWatch (org.apache.commons.lang.time.StopWatch)1 EntityProcessorOutput (org.motechproject.mds.annotations.internal.EntityProcessorOutput)1 Bundle (org.osgi.framework.Bundle)1