Example #1
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);
   }
 }