view src/luan/modules/http/tools/Java_threads.luan @ 1353:8d95711f6615

replace java() with require "java"
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 20 Mar 2019 17:03:29 -0600
parents 299996e03876
children b84f60ebe196
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local Io = require "luan:Io.luan"
local Time = require "luan:Time.luan"
local Http = require "luan:http/Http.luan"
require "java"
local Thread = require "java:java.lang.Thread"


local Java_threads = {}

function Java_threads.respond()
	Io.stdout = Http.response.text_writer()

	local threads = Thread.getAllStackTraces()
	local threads = {}
	for thread, trace in Luan.pairs(Thread.getAllStackTraces()) do
		threads[#threads+1] = {
			trace = trace
			string = thread.toString()
			state = thread.getState()
		}
	end
%>
<!doctype html>
<html>
	<body>
		<h1>Java Threads</h1>
		<p><%=Http.request.headers["host"]%> - <%=Time.format(Time.now())%></p>
		<%
		local count = 0
		for _, thread in Luan.ipairs(threads) do
			%>
			<p><%=thread.string%> <%=thread.state%>
			<ul>
			<%
			local trace = thread.trace
			for i in Luan.range( 0 , trace.length - 1 ) do
				local line = trace[i].toString()
				%><li><%=line%></li><%
			end
			%>
			</ul></p>
			<%
			count = count + 1
		end
		%>
		<p><%=count%> threads found</p>

	</body>
</html>
<%
end

return Java_threads