Ejemplo n.º 1
0
  public static String parsePlaceHolder(String path, ServletContext sc) {
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();

    if (path == null) return null;
    if (path.indexOf('{') != -1) {
      if (StringUtil.startsWith(path, '{')) {

        // Web Root
        if (path.startsWith("{web-root")) {
          if (path.startsWith("}", 9))
            path =
                frp.getResource(ReqRspUtil.getRootPath(sc))
                    .getRealResource(path.substring(10))
                    .toString();
          else if (path.startsWith("-dir}", 9))
            path =
                frp.getResource(ReqRspUtil.getRootPath(sc))
                    .getRealResource(path.substring(14))
                    .toString();
          else if (path.startsWith("-directory}", 9))
            path =
                frp.getResource(ReqRspUtil.getRootPath(sc))
                    .getRealResource(path.substring(20))
                    .toString();

        } else path = SystemUtil.parsePlaceHolder(path);
      }

      if ((path.indexOf("{web-context-hash}")) != -1) {
        String id = hash(sc);
        path = StringUtil.replace(path, "{web-context-hash}", id, false);
      }
    }
    return path;
  }
Ejemplo n.º 2
0
  private static Resource getDeployDirectory(Config config) {
    Resource dir = ConfigWebUtil.getConfigServerDirectory(config);
    if (dir == null || !dir.isWriteable() || !dir.isReadable())
      dir =
          ResourceUtil.toResource(
              CFMLEngineFactory.getClassLoaderRoot(SystemUtil.getLoaderClassLoader()));

    return dir;
  }
Ejemplo n.º 3
0
 private static Resource getBinDirectory(Config config) {
   Resource dir = ConfigWebUtil.getConfigServerDirectory(config);
   if (dir == null || !dir.isWriteable() || !dir.isReadable())
     dir =
         ResourceUtil.toResource(
             CFMLEngineFactory.getClassLoaderRoot(SystemUtil.getLoaderClassLoader()));
   else {
     dir = dir.getRealResource("bin");
     if (!dir.exists()) dir.mkdir();
   }
   return dir;
 }
Ejemplo n.º 4
0
  private static Resource createToolsJar(Config config) throws IOException {
    Resource dir = getDeployDirectory(config);

    String os = "bsd"; // used for Mac OS X
    if (SystemUtil.isWindows()) {
      os = "windows";
    } else if (SystemUtil.isLinux()) { // not MacOSX
      os = "linux";
    } else if (SystemUtil.isSolaris()) {
      os = "solaris";
    }
    String name = "tools-" + os + "-" + TOOLS_VERSION + ".jar";
    Resource trg = dir.getRealResource(name);

    if (!trg.exists() || trg.length() == 0) {

      InputStream jar = InfoImpl.class.getResourceAsStream("/resource/lib/" + name);
      IOUtil.copy(jar, trg, true);
    }
    return trg;
  }
Ejemplo n.º 5
0
  private static void addAttachIfNecessary(Config config, Log log) {

    String srcName = null, trgName = null;
    String archBits = (SystemUtil.getJREArch() == SystemUtil.ARCH_64) ? "64" : "32";

    // Windows
    if (SystemUtil.isWindows()) {
      trgName = "attach.dll";
      srcName = "windows" + archBits + "/" + trgName;
    }
    // Linux
    else if (SystemUtil.isLinux()) {
      trgName = "libattach.so";
      srcName = "linux" + archBits + "/" + trgName;
    }
    // Solaris
    else if (SystemUtil.isSolaris()) {
      trgName = "libattach.so";
      srcName = "solaris" + archBits + "/" + trgName;
    }
    // Mac OSX
    else if (SystemUtil.isMacOSX()) {
      trgName = "libattach.dylib";
      srcName = "macosx" + archBits + "/" + trgName;
    }

    if (srcName != null) {

      // create dll if necessary
      Resource binDir = getBinDirectory(config);
      Resource trg = binDir.getRealResource(trgName);
      if (!trg.exists() || trg.length() == 0) {
        log.info("Instrumentation", "deploy /resource/bin/" + srcName + " to " + trg);
        InputStream src = InfoImpl.class.getResourceAsStream("/resource/bin/" + srcName);
        try {
          IOUtil.copy(src, trg, true);
        } catch (IOException e) {
          log.log(Log.LEVEL_ERROR, "Instrumentation", e);
        }
      }

      // set directory to library path
      SystemUtil.addLibraryPathIfNoExist(binDir, log);
    }
  }
Ejemplo n.º 6
0
  public void run() {
    PageContextImpl pci = (PageContextImpl) pc;
    Thread thread = pc.getThread();
    pci.stop(t);
    int count = 0;
    if (thread.isAlive()) {
      do {
        if (count > 0 && log != null) {
          LogUtil.log(
              log,
              Log.LEVEL_ERROR,
              "",
              "could not stop the thread on the first approach",
              thread.getStackTrace());
        }
        if (count++ > 10) break; // should never happen
        try {
          thread.stop(t);
        } catch (UnsupportedOperationException uoe) {
          LogUtil.log(
              log,
              Log.LEVEL_ERROR,
              "",
              "Thread.stop(Throwable) is not supported by this JVM and failed with UnsupportedOperationException",
              thread.getStackTrace());
          thread.stop();
        }
        SystemUtil.sleep(1000);
      } while (thread.isAlive() && pci.isInitialized());
    }

    if (count > 10 && log != null) {
      LogUtil.log(log, Log.LEVEL_ERROR, "", "could not stop the thread", thread.getStackTrace());
      aprint.e(thread.getStackTrace());
    }
  }
Ejemplo n.º 7
0
  @Override
  public void run() {
    // scheduleThread.start();
    boolean firstRun = true;
    List<ControlerThread> threads = new ArrayList<ControlerThread>();
    CFMLFactoryImpl factories[] = null;
    while (state.active()) {
      // sleep
      SystemUtil.sleep(interval);

      factories = toFactories(factories, contextes);
      // start the thread that calls control
      ControlerThread ct =
          new ControlerThread(this, factories, firstRun, configServer.getLog("application"));
      ct.start();
      threads.add(ct);

      if (threads.size() > 10 && lastMinuteInterval + 60000 < System.currentTimeMillis())
        configServer
            .getLog("application")
            .info("controller", threads.size() + " active controller threads");

      // now we check all threads we have
      Iterator<ControlerThread> it = threads.iterator();
      long time;
      while (it.hasNext()) {
        ct = it.next();
        // print.e(ct.hashCode());
        time = System.currentTimeMillis() - ct.start;
        // done
        if (ct.done >= 0) {
          if (time > 10000)
            configServer
                .getLog("application")
                .info("controller", "controler took " + ct.done + "ms to execute sucessfully.");
          it.remove();
        }
        // failed
        else if (ct.t != null) {
          LogUtil.log(configServer.getLog("application"), Log.LEVEL_ERROR, "controler", ct.t);
          it.remove();
        }
        // stop it!
        else if (time > TIMEOUT) {
          SystemUtil.stop(ct);
          // print.e(ct.getStackTrace());
          if (!ct.isAlive()) {
            configServer
                .getLog("application")
                .error(
                    "controller",
                    "controler thread [" + ct.hashCode() + "] forced to stop after " + time + "ms");
            it.remove();
          } else {
            LogUtil.log(
                configServer.getLog("application"),
                Log.LEVEL_ERROR,
                "controler",
                "was not able to stop controller thread running for " + time + "ms",
                ct.getStackTrace());
          }
        }
      }

      if (factories.length > 0) firstRun = false;
    }
  }
Ejemplo n.º 8
0
 public String getHash() {
   return SystemUtil.hash(getServletContext());
 }
Ejemplo n.º 9
0
  private void writeOut(
      PageContext pc, DumpData data, Writer writer, boolean expand, boolean inside)
      throws IOException {

    if (data == null) return;
    if (!(data instanceof DumpTable)) {
      writer.write(StringUtil.escapeHTML(data.toString()));
      return;
    }
    DumpTable table = (DumpTable) data;

    // prepare data
    DumpRow[] rows = table.getRows();
    int cols = 0;
    for (int i = 0; i < rows.length; i++)
      if (rows[i].getItems().length > cols) cols = rows[i].getItems().length;

    TemplateLine tl = null;
    if (!inside) tl = SystemUtil.getCurrentContext();
    String context = tl == null ? "" : tl.toString();

    if (rows.length == 1 && rows[0].getItems().length == 2) {
      DumpData d = rows[0].getItems()[1];
      if (!(d instanceof DumpTable)) {
        writer.write(StringUtil.escapeHTML(d.toString()));
        return;
      }
    }

    writer.write(
        "<table  cellpadding=\"1\" cellspacing=\"0\" "
            + (table.getWidth() != null ? " width=\"" + table.getWidth() + "\"" : "")
            + ""
            + (table.getHeight() != null ? " height=\"" + table.getHeight() + "\"" : "")
            + " border=\"1\">");

    // header
    if (!StringUtil.isEmpty(table.getTitle())) {
      writer.write("<tr><td title=\"" + context + "\" colspan=\"" + cols + "\">");
      // isSetContext=true;
      String contextPath = "";
      pc = ThreadLocalPageContext.get(pc);
      if (pc != null) {
        contextPath = pc.getHttpServletRequest().getContextPath();
        if (contextPath == null) contextPath = "";
      }
      writer.write(
          "<b>"
              + (!StringUtil.isEmpty(table.getTitle()) ? table.getTitle() : "")
              + "</b>"
              + (!StringUtil.isEmpty(table.getComment()) ? "<br>" + table.getComment() : "")
              + "</td></tr>");
    }

    // items
    DumpData value;
    for (int i = 0; i < rows.length; i++) {
      writer.write("<tr>");
      DumpData[] items = rows[i].getItems();
      // int comperator=1;
      for (int y = 0; y < cols; y++) {
        if (y <= items.length - 1) value = items[y];
        else value = new SimpleDumpData("&nbsp;");
        // comperator*=2;
        if (value == null) value = new SimpleDumpData("null");
        // else if(value.equals(""))value="&nbsp;";
        if (!inside) {
          writer.write("<td title=\"" + context + "\">");
        } else writer.write("<td>");
        writeOut(pc, value, writer, expand, true);
        writer.write("</td>");
      }
      writer.write("</tr>");
    }

    // footer
    writer.write("</table>");
  }