<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Efim Smykov</title>
    <description>The latest articles on DEV Community by Efim Smykov (@nutrymaco).</description>
    <link>https://dev.to/nutrymaco</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1035905%2Fccb33164-3a76-495a-870f-1d76160679db.jpeg</url>
      <title>DEV Community: Efim Smykov</title>
      <link>https://dev.to/nutrymaco</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nutrymaco"/>
    <language>en</language>
    <item>
      <title>Using ArC outside Quarkus</title>
      <dc:creator>Efim Smykov</dc:creator>
      <pubDate>Mon, 20 Mar 2023 09:30:00 +0000</pubDate>
      <link>https://dev.to/nutrymaco/using-arc-outside-quarkus-3pep</link>
      <guid>https://dev.to/nutrymaco/using-arc-outside-quarkus-3pep</guid>
      <description>&lt;h2&gt;
  
  
  What is ArC
&lt;/h2&gt;

&lt;p&gt;ArC is build time oriented implementation of &lt;a href="https://jakarta.ee/specifications/cdi/2.0/"&gt;CDI 2.0 - Contexts and Dependency Injection specification&lt;/a&gt;. ArC created by Quarkus team and used for DI in Quarkus. In this topic we will try use it not in Quarkus application. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to use it
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Bean definition
&lt;/h3&gt;

&lt;p&gt;Because ArC based on CDI, for defining beans we will use standard annotations &lt;code&gt;@ApplicationScoped&lt;/code&gt; for defining bean and &lt;code&gt;@Inject&lt;/code&gt; for injecting beans into each other. It will look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.inject.Inject&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;javax.enterprise.context.ApplicationScoped&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@ApplicationScoped&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ServiceImpl&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Inject&lt;/span&gt;
    &lt;span class="nc"&gt;Service2&lt;/span&gt; &lt;span class="n"&gt;service2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Bean processing
&lt;/h3&gt;

&lt;p&gt;Entry point for processing beans is &lt;code&gt;BeanProcessor&lt;/code&gt;. It can be created via builder. And then we can use method &lt;code&gt;process&lt;/code&gt;, which will resolve beans and generate resources for fast application startup. &lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Maven plugin
&lt;/h3&gt;

&lt;p&gt;We will be using ArC in &lt;a href="https://maven.apache.org"&gt;Maven&lt;/a&gt; application. To modify build process we need to create plugin.  We need to have access to application &lt;code&gt;.class&lt;/code&gt; files and all compile and runtime dependencies. It looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;com.nutrymaco.arc.maven.plugin&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.apache.maven.plugin.AbstractMojo&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.apache.maven.plugins.annotations.LifecyclePhase&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.apache.maven.plugins.annotations.Mojo&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.apache.maven.plugins.annotations.Parameter&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.apache.maven.plugins.annotations.ResolutionScope&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.apache.maven.project.MavenProject&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@Mojo&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"build"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;defaultPhase&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LifecyclePhase&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;PACKAGE&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;requiresDependencyResolution&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ResolutionScope&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;COMPILE_PLUS_RUNTIME&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;threadSafe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BuildMojo&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;AbstractMojo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Parameter&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;defaultValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"${project}"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;readonly&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;required&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;MavenProject&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// build logic&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Bean processing
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;BeanProcessor&lt;/code&gt; need index for all classes that needed our application. So we use &lt;a href="https://smallrye.io/jandex/jandex/3.0.5/index.html"&gt;Jandex&lt;/a&gt; for creating index of all classes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Indexer&lt;/span&gt; &lt;span class="n"&gt;indexer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Indexer&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// add all .class files to index&lt;/span&gt;
&lt;span class="n"&gt;indexJar&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getArtifact&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;getFile&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;indexer&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Artifact&lt;/span&gt; &lt;span class="n"&gt;artifact&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;project&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getArtifacts&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;indexJar&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;artifact&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getFile&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;indexer&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;Index&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;indexer&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;complete&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we can create &lt;code&gt;BeanProcessor&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;BeanProcessor&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;builder&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setApplicationIndex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setComputingBeanArchiveIndex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setImmutableBeanArchiveIndex&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setGenerateSources&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setOutput&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;JarResourceOutput&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;generatedJarCreator&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setTransformUnproxyableClasses&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;JarResourceOutput&lt;/code&gt; writes generated by ArC classes and &lt;a href="https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html"&gt;service provider&lt;/a&gt; files into JAR&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getType&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;JAVA_CLASS:&lt;/span&gt;
        &lt;span class="n"&gt;jar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addFile&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;".class"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getData&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;SERVICE_PROVIDER:&lt;/span&gt;
        &lt;span class="n"&gt;jar&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;addFile&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"META-INF"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                  &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"services"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                  &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;resolve&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()).&lt;/span&gt;&lt;span class="na"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
            &lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getData&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nl"&gt;JAVA_SOURCE:&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Runtime
&lt;/h3&gt;

&lt;p&gt;In main class we should initialize container and then we can request for beans.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppMain&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arc&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;initialize&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;select&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;serve&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;As the result we add build time DI for our application. For that we created maven plugin in which we use&lt;code&gt;BeanProcessor&lt;/code&gt; for processing bean definitions. Then in runtime we initialize container using &lt;code&gt;Arc.initialize()&lt;/code&gt;. You can use it like this or use &lt;a href="https://quarkus.io"&gt;Quarkus&lt;/a&gt; to get more performance optimizations and features without extra actions like creating plugins.&lt;/p&gt;

</description>
      <category>quarkus</category>
      <category>microservices</category>
      <category>java</category>
      <category>maven</category>
    </item>
    <item>
      <title>Sidecar pattern use cases</title>
      <dc:creator>Efim Smykov</dc:creator>
      <pubDate>Fri, 17 Mar 2023 09:30:00 +0000</pubDate>
      <link>https://dev.to/nutrymaco/sidecar-pattern-use-cases-5bki</link>
      <guid>https://dev.to/nutrymaco/sidecar-pattern-use-cases-5bki</guid>
      <description>&lt;h2&gt;
  
  
  Sidecar pattern use cases
&lt;/h2&gt;

&lt;p&gt;Essence of pattern is that you have &lt;strong&gt;main&lt;/strong&gt; container and &lt;strong&gt;sidecar&lt;/strong&gt; container. They run on the same Pod, so they share networking and storage resources. Let’s discuss in what cases it can be useful. &lt;/p&gt;

&lt;h3&gt;
  
  
  Proxy server
&lt;/h3&gt;

&lt;p&gt;Sidecar pattern behave like proxy for main container. It does not perform any business logic. For example, you can add HTTPS to your old service without changing service itself.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9bllZxO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k21irj9mvwd0hoybti8n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9bllZxO9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k21irj9mvwd0hoybti8n.png" alt="sidecar container as proxy server" width="289" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Dynamic configuration
&lt;/h3&gt;

&lt;p&gt;Sidecar container acts like API for changing configuration. Service, in turn, should have some mechanism to fetch changes. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2_Dr7a12--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/huflhybcvycz9qz2p3hu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2_Dr7a12--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/huflhybcvycz9qz2p3hu.png" alt="sidecar container as configuration manager" width="312" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Reusable functionality
&lt;/h3&gt;

&lt;p&gt;Sometimes it is useful to extract some common (more likely technical) service logic into separate container. You can implement, for example, resource monitoring service once and use it for all services, regardless technologies they based on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fQv1E6PW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bba0glz0gbckteezpl8c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fQv1E6PW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bba0glz0gbckteezpl8c.png" alt="sidecar container as monitoring service" width="289" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Extending service API
&lt;/h3&gt;

&lt;p&gt;You can implement new API in separate service and deploy it as sidecar. It is useful if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you have not access to application sources&lt;/li&gt;
&lt;li&gt;application based on legacy technologies&lt;/li&gt;
&lt;li&gt;application sources are too legacy to try change it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---iqJ1AxO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y7eyisxjvu34w8ow3881.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---iqJ1AxO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y7eyisxjvu34w8ow3881.png" alt="sidecar container extends application API" width="289" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Basically, Sidecar pattern is useful when you can’t modify container, but want to implement some new functionality or want to implement some reusable technology-agnostic functionality.&lt;/p&gt;

</description>
      <category>cloud</category>
      <category>kubernetes</category>
      <category>patterns</category>
    </item>
    <item>
      <title>Why () -&gt; {throw e} is more Supplier than Runnable</title>
      <dc:creator>Efim Smykov</dc:creator>
      <pubDate>Sun, 12 Mar 2023 21:00:00 +0000</pubDate>
      <link>https://dev.to/nutrymaco/why-throw-e-is-more-supplier-than-runnable-53d8</link>
      <guid>https://dev.to/nutrymaco/why-throw-e-is-more-supplier-than-runnable-53d8</guid>
      <description>&lt;p&gt;Recently, while writing test, I encountered enexpected (for myself) Java behaviour. In simplified form, the situation was as in the code below. I expected that the &lt;code&gt;testRunnable&lt;/code&gt; would invoke &lt;code&gt;run(Runnable)&lt;/code&gt; method, but instead &lt;code&gt;run(Supplier)&lt;/code&gt; was invoked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;testRunnable&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;RuntimeException&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;});&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Supplier&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;?&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;supplier&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;supplier&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="n"&gt;runnable&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;runnable&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But it is not a bug, &lt;code&gt;run(Supplier)&lt;/code&gt; was chosen because it has &lt;strong&gt;more specific signature&lt;/strong&gt;. There is method for this - &lt;code&gt;com.sun.tools.javac.comp.Resolve#signatureMoreSpecific&lt;/code&gt;. In simplified form it looks like code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;signatureMoreSpecific&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Method&lt;/span&gt; &lt;span class="n"&gt;m1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Method&lt;/span&gt; &lt;span class="n"&gt;m2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;methodInstance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;instantiate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;methodInstance&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How this method works will be clearer with more obvious example. Let’s say we have method &lt;code&gt;print(String)&lt;/code&gt; and &lt;code&gt;print(Object)&lt;/code&gt;. Then we try to instantiate &lt;code&gt;print(Object)&lt;/code&gt; with &lt;code&gt;String&lt;/code&gt; argument. Obviously it will be instantiated successfully. Then we try instantiate &lt;code&gt;print(String)&lt;/code&gt; with &lt;code&gt;Object&lt;/code&gt; argument. It will fail, because we can’t pass &lt;code&gt;Object&lt;/code&gt; in method which consume &lt;code&gt;String&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;signatureMoreSpecific&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"print(String)"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"print(Object)"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;instantiate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"print(Object)"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"String"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;  &lt;span class="kc"&gt;true&lt;/span&gt;

&lt;span class="nf"&gt;signatureMoreSpecific&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"print(Object)"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"print(String)"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;instantiate&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"print(String)"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Object"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;fail&lt;/span&gt;
    &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;  &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So method signature is more specific if it can be passed into other method and signature of this method can’t be passed into first method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Method&lt;/span&gt; &lt;span class="nf"&gt;mostSpecific&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Method&lt;/span&gt; &lt;span class="n"&gt;m1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Method&lt;/span&gt; &lt;span class="n"&gt;m2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;m1SignatureMoreSpecific&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;signatureMoreSpecific&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m2&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  
  &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;m2SignatureMoreSpecfic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;signatureMoreSpecific&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m1&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m1SignatureMoreSpecific&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;m2SignatureMoreSpecific&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// …&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt; 
  &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nf"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m1SignatureMoreSpecific&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;m1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nf"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m2SignatureMoreSpecific&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;m2&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Static proxies in Quarkus</title>
      <dc:creator>Efim Smykov</dc:creator>
      <pubDate>Sat, 11 Mar 2023 23:10:36 +0000</pubDate>
      <link>https://dev.to/nutrymaco/static-proxies-in-quarkus-4ebf</link>
      <guid>https://dev.to/nutrymaco/static-proxies-in-quarkus-4ebf</guid>
      <description>&lt;p&gt;In previous &lt;a href="https://dev.to/nutrymaco/how-quarkus-use-build-time-to-start-your-application-faster-50n"&gt;post&lt;/a&gt;, Quarkus build process was described and how it helps to do DI in build time. In this post we discuss standard approaches for proxy creation and how Quarkus does it. &lt;/p&gt;

&lt;h2&gt;
  
  
  CDI and interceptors
&lt;/h2&gt;

&lt;p&gt;All Quarkus applications use &lt;a href="https://jakarta.ee/specifications/cdi/"&gt;CDI - Contexts and Dependency Injection&lt;/a&gt;. It has annotation for declarative creating interceptor. As a result for target class creating proxy with interceptor logic. But how proxy is created depends on implementation. &lt;/p&gt;

&lt;h2&gt;
  
  
  How proxy can be created
&lt;/h2&gt;

&lt;p&gt;First, let’s see example of interceptor. &lt;code&gt;GreeterInterceptor&lt;/code&gt; - interceptor and &lt;code&gt;WorkService&lt;/code&gt;, &lt;code&gt;ServiceImpl&lt;/code&gt;, and &lt;code&gt;FinalService&lt;/code&gt; - bean classes which will be proxied.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GreeterInterceptor&lt;/code&gt; interceptor - printing greeting from intercepted bean&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Greeter&lt;/span&gt;
&lt;span class="nd"&gt;@Interceptor&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GreeterInterceptor&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@AroundInvoke&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;InvocationContext&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello from "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getTarget&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;proceed&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;WorkService&lt;/code&gt; bean - not implementing any interfaces&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Singleton&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WorkService&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Greeter&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I'm doing work"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ServiceImpl&lt;/code&gt; bean - implement interface &lt;code&gt;Service&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Singleton&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ServiceImpl&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Greeter&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I'm doing work"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;FinalService&lt;/code&gt; bean - not implementing interfaces, has &lt;strong&gt;final&lt;/strong&gt; modifier&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Singleton&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FinalService&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Greeter&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;serve&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I'm doing work"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Dynamic proxy
&lt;/h3&gt;

&lt;p&gt;Dynamic proxy is a proxy created at runtime. There is 2 way to do this: bytecode generation and &lt;a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/reflect/Proxy.html"&gt;Java Dynamic Proxy Class API&lt;/a&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  Java Dynamic Proxy Class API
&lt;/h4&gt;

&lt;p&gt;With this API you can create proxy via code like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;InvocationHandler&lt;/span&gt; &lt;span class="n"&gt;handler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MyInvocationHandler&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;proxy&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Method&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Throwable&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// proxy logic&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;Service&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Service&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;Proxy&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;newProxyInstance&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
                        &lt;span class="nc"&gt;Service&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getClassLoader&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt;
                        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Class&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;?&amp;gt;[]&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Service&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt; &lt;span class="o"&gt;},&lt;/span&gt;
                        &lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Main limitation of this API, that you can only create proxy for interfaces, so it can only be used for &lt;code&gt;ServiceImpl&lt;/code&gt; bean in our examples. &lt;/p&gt;

&lt;h4&gt;
  
  
  Runtime bytecode generation
&lt;/h4&gt;

&lt;p&gt;This approach can be implemented using bytecode generation libs such as &lt;a href="https://github.com/cglib/cglib"&gt;cglib&lt;/a&gt; (but they do not support JDK17+) or &lt;a href="https://bytebuddy.net/#/"&gt;ByteBuddy&lt;/a&gt;. With bytecode generation you can create proxy for &lt;code&gt;WorkService&lt;/code&gt; and &lt;code&gt;ServiceImpl&lt;/code&gt; from our examples. But bytecode generation can’t help if target class is final like &lt;code&gt;FinalService&lt;/code&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Proxy creation in Quarkus
&lt;/h3&gt;

&lt;p&gt;Unlike in cases described above Quarkus knows which class need proxy at build time. So bytecode for proxy can be &lt;strong&gt;generated at build time&lt;/strong&gt; without wasting resources at runtime, so it called a &lt;strong&gt;static proxy&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Also Quarkus can modify bytecode of classes with &lt;code&gt;final&lt;/code&gt; modifier, so they can be proxied. As a result Quarkus can create proxy for all our examples - &lt;code&gt;WorkService&lt;/code&gt; (ordinary class), &lt;code&gt;ServiceImpl&lt;/code&gt; (implementing interface) and &lt;code&gt;FinalService&lt;/code&gt; (class with &lt;code&gt;final&lt;/code&gt; modifier). &lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;In this topic we discussed main approaches for creating proxy - bytecode generation and Java Dynamic Proxy Class API. Quarkus combines bytecode generation, bytecode transformation and knowledge about all classes to generate proxy at build time. Thereby giving better perfomance at runtime and possibility for creating proxy for final classes.&lt;/p&gt;

</description>
      <category>quarkus</category>
      <category>cdi</category>
      <category>java</category>
      <category>bytecode</category>
    </item>
    <item>
      <title>How Quarkus use build time to start your application faster</title>
      <dc:creator>Efim Smykov</dc:creator>
      <pubDate>Tue, 28 Feb 2023 22:31:08 +0000</pubDate>
      <link>https://dev.to/nutrymaco/how-quarkus-use-build-time-to-start-your-application-faster-50n</link>
      <guid>https://dev.to/nutrymaco/how-quarkus-use-build-time-to-start-your-application-faster-50n</guid>
      <description>&lt;p&gt;In this topic, we will try to undestand basics of how Quarkus augments application. We will cover how build process works, structure of resulted artifact and how it is launched.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Quarkus
&lt;/h2&gt;

&lt;p&gt;Quarkus is framework for Java (primary) and Kotlin with focus on the cloud development.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are benefits of Quarkus
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Quick startup&lt;/li&gt;
&lt;li&gt;Low memory consumption&lt;/li&gt;
&lt;li&gt;Build time DI resolution&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Quarkus build application
&lt;/h2&gt;

&lt;p&gt;At build time (also referred to as deployment time), Quarkus does most of the work. Let's establish the basics of how Quarkus builds our application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Quarkus application build flow
&lt;/h3&gt;

&lt;p&gt;Once all application classes are compiled, Quarkus build starts. During bootstrap, it prepares for the build, e.g. resolves all application dependencies. Next, Quarkus performs deployment (build) and produces an artifact. Let's take a closer look at each step related to Quarkus.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsf02hydcgse6cf9hzjr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsf02hydcgse6cf9hzjr.png" alt="Quarkus application build flow (JVM mode)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Bootstrap phase
&lt;/h3&gt;

&lt;p&gt;Before run build Quarkus does:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Resolve application dependencies.&lt;/li&gt;
&lt;li&gt;Build build chain.&lt;/li&gt;
&lt;li&gt;Produce initial build items into build chain.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Core build components
&lt;/h3&gt;

&lt;p&gt;Build process consists from two basic blocks build step and build item.&lt;/p&gt;

&lt;h4&gt;
  
  
  Build item
&lt;/h4&gt;

&lt;p&gt;They can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;initial and non-initial&lt;/li&gt;
&lt;li&gt;simple and multi&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Initial Build Items
&lt;/h4&gt;

&lt;p&gt;Initial build items are created and passed to the build chain by Quarkus and cannot be produced by build steps.&lt;br&gt;
For example, the &lt;code&gt;LaunchModeBuildItem&lt;/code&gt; indicates the launch type, such as production, development, or testing.&lt;/p&gt;

&lt;h4&gt;
  
  
  Simple build item
&lt;/h4&gt;

&lt;p&gt;Can only be produced in one instance (and by only one &lt;strong&gt;build step&lt;/strong&gt;)&lt;br&gt;
For example, the &lt;code&gt;CombinedIndexBuildItem&lt;/code&gt; contains index, which build from the application classes and dependencies that contain a certain marker file.&lt;/p&gt;

&lt;h5&gt;
  
  
  Multi build item
&lt;/h5&gt;

&lt;p&gt;Can be produced any amount of time by any amount of &lt;strong&gt;build steps&lt;/strong&gt;&lt;br&gt;
For example, the &lt;code&gt;AdditionalBeanBuildItem&lt;/code&gt; is produced by extensions to dynamically specify a bean.&lt;/p&gt;

&lt;h4&gt;
  
  
  Build step
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Method with &lt;code&gt;@BuildStep&lt;/code&gt; annotation.&lt;/li&gt;
&lt;li&gt;Consume build items.&lt;/li&gt;
&lt;li&gt;Produce build items by returning a value from a method or using &lt;code&gt;BuildProducer&amp;lt;BuildItem&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Can be recorded and invoked at application startup.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Build step recording
&lt;/h4&gt;

&lt;p&gt;The build step recording process works as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A proxy is created for the recorder passed in method using an &lt;code&gt;InvocationHandler&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The proxy records all invocation information.&lt;/li&gt;
&lt;li&gt;Also proxy is created for all returned values from the invoked methods.&lt;/li&gt;
&lt;li&gt;Bytecode to be invoked at application startup is recorded based on the information gathered by the proxies.&lt;/li&gt;
&lt;li&gt;Recorded bytecode produced as &lt;code&gt;StaticBytecodeRecorderBuildItem&lt;/code&gt; or &lt;code&gt;MainBytecodeRecorderBuildItem&lt;/code&gt; and collected in &lt;code&gt;MainClassBuildStep&lt;/code&gt; where runner class is generated.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;InvocationHandler&lt;/code&gt; dummy implementation:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;InvocationHandler&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;br&gt;&lt;br&gt;
  &lt;span class="nd"&gt;@Override&lt;/span&gt;&lt;br&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;proxy&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Method&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Throwable&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="c1"&gt;// do something on method invocation&lt;/span&gt;&lt;br&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;&lt;br&gt;
&lt;span class="o"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  (Simplified) Build process&lt;br&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Build chain model
&lt;/h4&gt;

&lt;p&gt;The resulting build chain can be represented as an oriented graph, with build items and build steps as nodes. Quarkus determines which build steps do not depend on any other build steps and starts their execution. After they have finished, it counts down the counter at the dependent build steps; if the counter equals 0, they start execution. All executions are done in parallel.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pre DI build phase
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmzxm0gulu1k9ti5fkor.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frmzxm0gulu1k9ti5fkor.png" alt="Pre DI build phase"&gt;&lt;/a&gt;&lt;br&gt;
This scheme illustrates how Quarkus collects bean archives for dependency injection (DI). The process begins by collecting all archives, regardless of whether they contain beans or not. Next, Quarkus selects the bean archives from the collected archives.&lt;/p&gt;

&lt;p&gt;Initially, collect all application classes. In case of a multi-module application, only classes in the main application module are indexed at this step, while others are treated as dependencies.&lt;/p&gt;

&lt;p&gt;Next, the &lt;code&gt;ApplicationArchiveBuildStep&lt;/code&gt; processes all application dependencies. Dependencies are indexed if they meet at least one of the following criteria:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dependency contains one of the specified marker files, such as &lt;code&gt;META-INF/jandex.idx&lt;/code&gt; or &lt;code&gt;META-INF/beans.xml&lt;/code&gt;. Additional marker files can be specified using the &lt;code&gt;AdditionalApplicationArchiveMarkerBuildItem&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Dependency is included in one of the produced &lt;code&gt;IndexDependencyBuildItem&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Dependency is included in one of the initial &lt;code&gt;AdditionalApplicationArchiveBuildItem&lt;/code&gt; build items, which cannot be produced by the user.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also Quarkus index all classes specified in &lt;code&gt;AdditionalIndexedClassBuildItem&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;These archives combined into &lt;code&gt;CombinedIndexBuildItem&lt;/code&gt;, which consumed by &lt;code&gt;BeanArchiveProcessor&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then &lt;code&gt;BeanArchiveProcessor&lt;/code&gt; create bean archives index. Archive is treated as a bean archive if it meets at least one of the following criteria:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Archive contains &lt;code&gt;META-INF/beans.xml&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Archive contains at least one class with bean defining annotation, for example &lt;code&gt;@ApplicationScoped&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Archive specified as bean archive in &lt;code&gt;BeanArchivePredicateBuildItem&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  DI build phase
&lt;/h4&gt;

&lt;p&gt;During build time, Quarkus performs the following tasks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Resolves all injection points.&lt;/li&gt;
&lt;li&gt;Generates &lt;a href="https://dev.to/nutrymaco/static-proxies-in-quarkus-4ebf"&gt;static proxies&lt;/a&gt; for beans to avoid reflection.&lt;/li&gt;
&lt;li&gt;Generates bytecode to set up DI at application startup.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Create artifact phase
&lt;/h4&gt;

&lt;p&gt;Result artifact generated in &lt;code&gt;JarResultBuildStep&lt;/code&gt;. Quarkus has several artifact formats. For JVM default and recommended is &lt;strong&gt;fast-jar&lt;/strong&gt;. It has followed structure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fssz6ig22az2auf0dydsf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fssz6ig22az2auf0dydsf.png" alt="Build a structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How Quarkus starts application
&lt;/h2&gt;

&lt;p&gt;Quarkus offers several launch modes, but here we will focus only on the production mode.&lt;/p&gt;

&lt;p&gt;To start the application in production mode, launch the &lt;code&gt;target/quarkus-app/quarkus-run.jar&lt;/code&gt; JAR. The QuarkusEntryPoint main class will be loaded from &lt;code&gt;lib/boot/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The next step is for &lt;code&gt;QuarkusEntryPoint&lt;/code&gt; to read the &lt;code&gt;quarkus-application.dat&lt;/code&gt; file, from which it creates the &lt;code&gt;RunnerClassLoader&lt;/code&gt;, the class loader for the Quarkus application. Using the information from &lt;code&gt;quarkus-application.dat&lt;/code&gt;, the &lt;code&gt;RunnerClassLoader&lt;/code&gt; will attempt to load a class from the parent class loader (JVM class loader) or from indexed jars, which is faster than the JVM class loader.&lt;/p&gt;

&lt;p&gt;Then, the generated &lt;code&gt;ApplicationImpl&lt;/code&gt; runs, where the static block contains static recordings, and the start method contains runtime recordings. It looks something like this:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;p&gt;&lt;span class="c1"&gt;// $FF: synthetic class&lt;/span&gt;&lt;br&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ApplicationImpl&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Application&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;br&gt;
  &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Logger&lt;/span&gt; &lt;span class="no"&gt;LOG&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;br&gt;
  &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;StartupContext&lt;/span&gt; &lt;span class="no"&gt;STARTUP_CONTEXT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;ApplicationImpl&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;&lt;br&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;br&gt;
  &lt;span class="c1"&gt;// invoke static recordings&lt;/span&gt;&lt;br&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;doStart&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;var1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="c1"&gt;// invoke runtime recordings&lt;/span&gt;&lt;br&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;doStop&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="no"&gt;STARTUP_CONTEXT&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;close&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;&lt;br&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getName&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;br&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"simple-app"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;br&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;&lt;br&gt;
&lt;span class="o"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Summary&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;We covered class indexing, build-time preparation for dependency injection, artifact structure, and application startup. While there are other important topics such as native executable creation, more advanced overview of dependency injection, and server implementation, it would be best to address them separately.&lt;/p&gt;

</description>
      <category>quarkus</category>
      <category>cloud</category>
      <category>java</category>
      <category>optimization</category>
    </item>
  </channel>
</rss>
