コード例 #1
0
 private CachingContext getCachingContext(ScriptCachingContext sctx) {
   TenantWrapper tenant = tenants.get(sctx.getTenantId());
   if (tenant == null) {
     return null;
   }
   return tenant.getCachingContext(sctx);
 }
コード例 #2
0
 private TenantWrapper initContexts(ScriptCachingContext sctx) {
   TenantWrapper tenant = tenants.get(sctx.getTenantId());
   if (tenant == null) {
     tenant = new TenantWrapper();
     tenants.put(sctx.getTenantId(), tenant);
   }
   ContextWrapper context = tenant.getContext(sctx);
   if (context == null) {
     context = new ContextWrapper(sctx.getContext());
     tenant.setContext(sctx, context);
   }
   PackageWrapper packageWrapper = context.getPackage(sctx.getPath());
   if (packageWrapper == null) {
     packageWrapper = new PackageWrapper();
     context.setPackage(sctx.getPath(), packageWrapper);
   }
   return tenant;
 }
コード例 #3
0
 public synchronized void cacheScript(Reader scriptReader, ScriptCachingContext sctx)
     throws ScriptException {
   if (scriptReader == null) {
     String msg = "Unable to find the Reader for script source in CachingContext";
     log.error(msg);
     throw new ScriptException(msg);
   }
   String className;
   TenantWrapper tenant = initContexts(sctx);
   CachingContext ctx = getCachingContext(sctx);
   if (ctx != null) {
     if (sctx.getSourceModifiedTime() <= ctx.getSourceModifiedTime()) {
       return;
     }
     className = ctx.getClassName();
     invalidateCache(sctx);
     ctx.setSourceModifiedTime(0L);
     ctx.setCacheUpdatedTime(0L);
   } else {
     className = getClassName(tenant, sctx);
     ctx = new CachingContext(sctx.getContext(), sctx.getPath(), sctx.getCacheKey());
     ctx.setTenantId(sctx.getTenantId());
     ctx.setContext(sctx.getContext());
     ctx.setPath(sctx.getPath());
     ctx.setCacheKey(sctx.getCacheKey());
     ctx.setClassName(className);
   }
   try {
     String scriptPath = sctx.getContext() + sctx.getPath() + sctx.getCacheKey();
     Object[] compiled =
         compiler.compileToClassFiles(
             HostObjectUtil.readerToString(scriptReader), scriptPath, 1, className);
     ctx.setScript(getScriptObject(compiled, sctx));
     ctx.setCacheUpdatedTime(System.currentTimeMillis());
     ctx.setSourceModifiedTime(sctx.getSourceModifiedTime());
     tenant.setCachingContext(ctx);
   } catch (Exception e) {
     throw new ScriptException(e);
   }
 }