示例#1
0
 public void invalidateCache(ScriptCachingContext sctx) throws ScriptException {
   synchronized (lock0) {
     CachingContext ctx = getCachingContext(sctx);
     if (ctx == null) {
       return;
     }
     TenantWrapper tenant = tenants.get(ctx.getTenantId());
     tenant.removeCachingContext(sctx);
   }
 }
示例#2
0
 public Script getScriptObject(Reader scriptReader, ScriptCachingContext sctx)
     throws ScriptException {
   CachingContext ctx = getCachingContext(sctx);
   if (ctx == null) {
     return null;
   }
   // source file has been modified, so we recreate
   if (sctx.getSourceModifiedTime() > ctx.getSourceModifiedTime()) {
     cacheScript(scriptReader, sctx);
     ctx = getCachingContext(sctx);
   }
   return ctx.getScript();
 }
示例#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);
   }
 }
示例#4
0
 public boolean isOlder(ScriptCachingContext sctx) {
   CachingContext ctx = getCachingContext(sctx);
   return ctx == null || sctx.getSourceModifiedTime() > ctx.getSourceModifiedTime();
 }