Intro
It’s quite nice to work and develop some tools, but the basis should be learned first, and here there is a small but good/required list of courses to do.
It’s quite nice to work and develop some tools, but the basis should be learned first, and here there is a small but good/required list of courses to do.
Ok, quick stuff, just reading about Undertow, I didn’t know it was so flexible actually.
There is basically two way to use undertow, and in fact, I already made a post about the first way here, the idea is simple: use the Builder API after we create the handler we want as in here. The listener on the example is created for the port 8080, i.e. bind to localhost.
The builder will default values for performance-related stuff, as a number of threads and buffers.
public class HelloWorldServer {
public static void main(final String[] args) {
Undertow server = Undertow.builder() //Undertow builder
.addHttpListener(8080, "localhost") //Listener binding
.setHandler(new HttpHandler() { //Default Handler
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain"); //Response Headers
exchange.getResponseSender().send("Hello World"); //Response Sender
}
}).build();
server.start();
}
}
Otherwise, the second way to do stuff is by manually assembling stuff to create a server.
The main steps are described here:
From a variety of reasons, we plan to move from WebSphere to Jboss, but just following the guide here that we will be able to do it. There will be things that will need to be adapted – keep in my the following:
As rule, we have to follow the basic steps
1) port over the server side resources.
2) create JBoss deployment descriptors.
3) install the application
4) resolve anything that does not conform to or violates the JEE spec.
[1] https://docs.jboss.org/author/display/AS72/How+do+I+migrate+my+application+from+WebSphere+to+AS+7
Learning from Benjamin Evans and James Gough, on java was really good, the video is not open I guess, but can be accessed on O’Reilly platform.
They highlight the fact that performance is never alone, you always learning together. Starting with cache misses, and other basic issues they build upon that.
[1]https://www.oreilly.com/learning/practical-java-performance-tuning
Today I’ll describe two tools for GC: GCViwer and JMeter.
-Xloggc:/whatever/Downloads/LOG.log -verbose:gc
> in the server configuration as shown here Garbagecat
This is a tool for quite look up on GC files. Just download the source and run mvn clean install and it’s all done.
Here below is one of my experiments with a gc.log file in the GC viewer. Just used [viewer] [log.file] and it will pop up:

JVM tuning is not a magic trick. So JMeter is a way to stop the gambling and magic and do some metrics based on load simulations, so then we can tune the JVM options for the optional.
Well, the JEPS 158, Java 9, introduces a unified logger mechanism.
The source or GCViwer.
The JMeter can be found here
“Formal semantics can avoid stupid errors, for example, programs that give different results for different for different compilers version.” – Prof Grigore Rosu.
K-framework, from the Runtime Verification team, and by the group of Prof Grigore Rosu at University Urbana Campaign.
K-framework is a language to describe other languages.
His main idea is to use the k-framework to verify smart contracts.
Youtube interview with Prof Grigore Rosu
On JBoss the Broker was HornetQ and for JBoss 7 the Broker is actually ActiveMQ Artemis. Interesting switch.
Someone asked about the fact that sometimes the verbs are out of order in my posts. Even missing verbs. Well, full disclosure here, I’m dyslexic and the more I learn German the worse my English gets. As my Italian degrades my French too. I don’t know why. Thanks, Grammarly.
Undertow is a lightweight server that is a subsystem of JBoss.
The source code is here: https://github.com/undertow-io/ and it’s quite interesting to see java code again, after a long time with python/c++.
Undertow documentation is pretty neat and can be found here. It states that the core part of Undertow is the lightweight async handlers.
There are many tutorials on the internet but the ones I recommended are: this and this, especially Baeldung tutorial.
package com.baeldung.undertow;
import io.undertow.Undertow;
import io.undertow.Handlers;
import io.undertow.server.handlers.PathHandler;
import io.undertow.servlet.Servlets;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
import java.io.IOException;
import io.undertow.server.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import io.undertow.util.Headers;
public class SimpleServer {
static void simpleHandler(HttpServerExchange exchange)
{
exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, “text/plain”);
exchange.getResponseSender().send(“Adding Handler!”);
}
public static void main(String[] args) throws Exception
{
int port = 8080;
/*
* “localhost” will ONLY listen on local host.
* If you want the server reachable from the outside you need to set “0.0.0.0”
*/
String host = “localhost”;
/*
* This web server has a single handler with no routing.
* ALL urls are handled by the helloWorldHandler.
*/
//Undertow server = Undertow.builder()
// Add the helloWorldHandler as a method reference.
// .addHttpListener(port, host, SimpleServer::simpleHandler)
// .build();
//Deploy Get
DeploymentInfo servletBuilder = Servlets.deployment().setClassLoader(SimpleServer.class.getClassLoader())
.setDeploymentName(“myapp”).setContextPath(“/myapp”)
.addServlets(Servlets.servlet(“myservlet”,
new HttpServlet() {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().write(“Hello World!”);
}
}.getClass()).addMapping(“/myservlet”));
DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
manager.deploy();
PathHandler path = Handlers.path(Handlers.redirect(“/myapp”)).addPrefixPath(“/myapp”, manager.start());
Undertow server = Undertow.builder().addHttpListener(port, host).setHandler(path).build();
//logger.debug(“starting on http://” + host + “:” + port);
server.start();
}
/* Version of setBufferSize – TomCat*/
/*@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setBufferSize(bufferSize);
resp.setContentType(“text/plain”);
resp.setCharacterEncoding(“UTF-8”);
resp.setContentLength(responseSize);
PrintWriter pw = resp.getWriter();
for (int i = 0; i < responseSize; i++) {
pw.append(‘X’);
}
}*/
}
Byteman helps to insert code and change stuff on the run – after compiling, therefore – Java Code. This is quite interesting.
Byteman can be downloaded from here and have some good tutorials here
Well, we just run java with the agent:
java -javaagent:/path/byteman.jar=script:myrule.btm [-jar] [application] [arguments]
WARNING THE -JAR AND THE APPLICATION ARE THE LAST ARGUMENTS!
RULE Make it me
CLASS Hello
METHOD main
AT ENTRY
IF TRUE
DO args[0] = “Andrew”;
ENDRULE
This rule is gonna replace the first argument in args by Andrew, who is the guy that made the presentation.
This rule basically creates a stack trace of 20 lines when the invocation of the init method of ClientSocketFactory.
Other apps can be used combined with Byteman so then we can see more stuff, Thermostat is a good one. I’ll add more on this later.
[1] Byteman.jboss.org
[2] Andrew Dinn youtube vide on DevNation 2016
[3] Programmer’s Guide is quite interesting and clarifying especially for traceStack.