Search in sources :

Example 1 with CompilationData

use of org.drools.compiler.kie.builder.impl.KieModuleCache.CompilationData in project drools by kiegroup.

the class AbstractKieModule method getCompilationCache.

@Override
public CompilationCache getCompilationCache(String kbaseName) {
    // Map< DIALECT, Map< RESOURCE, List<BYTECODE> > >
    CompilationCache cache = compilationCache.get(kbaseName);
    if (cache == null) {
        byte[] fileContents = getBytes(KieBuilderImpl.getCompilationCachePath(releaseId, kbaseName));
        if (fileContents != null) {
            ExtensionRegistry registry = KieModuleCacheHelper.buildRegistry();
            try {
                Header _header = KieModuleCacheHelper.readFromStreamWithHeaderPreloaded(new ByteArrayInputStream(fileContents), registry);
                if (!Drools.isCompatible(_header.getVersion().getVersionMajor(), _header.getVersion().getVersionMinor(), _header.getVersion().getVersionRevision())) {
                    // if cache has been built with an incompatible version avoid to use it
                    log.warn("The compilation cache has been built with an incompatible version. " + "You should recompile your project in order to use it with current release.");
                    return null;
                }
                KModuleCache _cache = KModuleCache.parseFrom(_header.getPayload());
                cache = new CompilationCache();
                for (CompilationData _data : _cache.getCompilationDataList()) {
                    for (CompDataEntry _entry : _data.getEntryList()) {
                        cache.addEntry(_data.getDialect(), _entry.getId(), _entry.getData().toByteArray());
                    }
                }
                compilationCache.put(kbaseName, cache);
            } catch (Exception e) {
                log.error("Unable to load compilation cache... ", e);
            }
        }
    }
    return cache;
}
Also used : KModuleCache(org.drools.compiler.kie.builder.impl.KieModuleCache.KModuleCache) CompilationData(org.drools.compiler.kie.builder.impl.KieModuleCache.CompilationData) CompDataEntry(org.drools.compiler.kie.builder.impl.KieModuleCache.CompDataEntry) Header(org.drools.compiler.kie.builder.impl.KieModuleCache.Header) ByteArrayInputStream(java.io.ByteArrayInputStream) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Aggregations

ExtensionRegistry (com.google.protobuf.ExtensionRegistry)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 CompDataEntry (org.drools.compiler.kie.builder.impl.KieModuleCache.CompDataEntry)1 CompilationData (org.drools.compiler.kie.builder.impl.KieModuleCache.CompilationData)1 Header (org.drools.compiler.kie.builder.impl.KieModuleCache.Header)1 KModuleCache (org.drools.compiler.kie.builder.impl.KieModuleCache.KModuleCache)1