Exemplo n.º 1
0
                    "utils": ["UserException", "HH", "form_date"],
                    "templater": ["render", "on_start_report", "get_report"],
                },
            )

        elif inv.hasParameter("run_shutdown"):
            shutdown_contract = Contract.getNonCoreContract("shutdown")
            shutdown_contract.callFunction("on_shut_down", [Monad.getContext()])
            source.appendChild(MonadMessage("Shut down successfully.").toXml(doc))

        elif inv.hasParameter("run_startup"):
            startup_contract = Contract.getNonCoreContract("startup")
            startup_contract.callFunction("on_start_up", [Monad.getContext()])
        elif inv.hasParameter("cancel_backend"):
            backend_pid = inv.getLong("backend_pid")
            con = Hiber.session().connection()
            stmt = con.createStatement()
            stmt.execute("select pg_terminate_backend(" + str(backend_pid) + ")")
            stmt.close()
            Hiber.commit()
            source.appendChild(MonadMessage("Cancelled backend.").toXml(doc))

    df = DecimalFormat("###,###,###,###,##0")
    runtime = Runtime.getRuntime()
    source.setAttribute("free-memory", df.format(runtime.freeMemory()))
    source.setAttribute("max-memory", df.format(runtime.maxMemory()))
    source.setAttribute("total-memory", df.format(runtime.totalMemory()))
    source.setAttribute("available-processors", str(runtime.availableProcessors()))

    source.setAttribute("system-load-average", str(ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage()))
Exemplo n.º 2
0
def jython_start(ctx):
    from net.sf.chellow.billing import Contract
    from net.sf.chellow.monad import Hiber
    from org.python.util import PythonInterpreter
    from java.io import LineNumberReader, File, FileReader
    from org.python.core import PyString

    interp = PythonInterpreter()

    sys_state = interp.getSystemState()

    lib_path = ctx.getRealPath("/WEB-INF/lib-python")
    if lib_path is not None:
        lib_dir = File(lib_path)
        if lib_dir.exists():
            sys_state.path.append(PyString(lib_path))

            # Now check for .pth files in lib-python and process each one

            for lib_content in lib_dir.list():
                if lib_content.endswith(".pth"):
                    line_reader = None
                    try:
                        line_reader = LineNumberReader(
                            FileReader(File(lib_path, lib_content)))

                        line = line_reader.readLine()

                        while line is not None:
                            line = line.strip()

                            if len(line) == 0:
                                continue

                            if line.startswith("#"):
                                continue

                            if line.startswith("import"):
                                efunc = getattr(interp, 'exec')
                                efunc(line)
                                continue

                            archive_file = File(lib_path, line)

                            archive_real_path = archive_file.getAbsolutePath()

                            sys_state.path.append(PyString(archive_real_path))
                            line = line_reader.readLine()
                    finally:
                        line_reader.close()

    for contract_name in LIBS:
        contract = Contract.getNonCoreContract(contract_name)
        nspace = LibDict()
        nspace['db_id'] = contract.id
        exec(contract.getChargeScript(), nspace)
        for k, v in nspace.iteritems():
            if not hasattr(nspace, k):
                setattr(nspace, k, v)
        ctx.setAttribute("net.sf.chellow." + contract_name, nspace)

    Hiber.close()