[Hello, world!] Remember storm-starter's miserable debugging experience in a well-known IDE, hellostorm-starter

Source: Internet
Author: User

[Hello, world!] Remember storm-starter's miserable debugging experience in a well-known IDE, hellostorm-starter
Background

I recently received such a question:

Storm generates a message tree based on the Topology when processing messages. How does Storm track each message, ensure that messages are not lost, and implement the message resend mechanism?

Although I have replied, I want to check the source code of storm. If it is so static, debug it. Well, create a local environment for debugging.

Let's take a look at the maven build:

mvn -f pom.xml clean install

After storm compilation and packaging is completed, storm-starter compilation and packaging is followed. Everything went well. Let's take a look:

${STORM_HOME}/bin/storm jar ${STORM_JAR} ${STORM_STARTER_JAR} storm.starter.WordCountTopology

The result is successful. It's not a hello world!

Create a local environment and import the storm-starter source code to Intellij IDEA in maven mode. Note that From this time on, we will start to feel sad.

Hello, world!

After I imported the IDE, I was very interested.F5And then:

This Nima said it was a tough fight!

Depends on the dependency"Suitable for all"Ah, ClassPath"Suitable for all"Ah, otherwise the compilation will fail. It will run for Mao! No! Start! Come!

This is the same operation. It is appropriate in eclipse to run a variety of tasks. Why did Mao go wrong in Intellij IDEA?

How exceptions are generated

Well, now that you are a fan of the well-known IDE, you must be ashamed and brave.
Then, let's see how exceptions are generated.

As shown in the figure above, exceptions are basically summarized.NoClassDefFoundThe generated path.

The exception details are as follows:

Note:

  • JVM_GetClassDelaredMethodsIs the method in JVM. Find the entry function.mainThis method is called.
  • Next, this method calls the process of verifying the bytecode:verify_code.
  • Found usefulbacktype.storm.topology.IRichBoltInterface..classFile:
    If we runjava -cp . xxx, Through-cpOr-classpathParameter specifiedclasspath, Then this.classWill be found. Then enterparse.

  • Sadly, IDEA running or Debugging commandsf5->run, Nobacktype.storm.topology.IRichBolt.classJar packagestorm-core.jarAdd classpath...

So, since there is a search*.classThe process is as follows:

Briefly describe:

How to handle exceptions

Okay, the exception is generated clearly. There is another problem, that__pending_exceptionWhen will it be processed?
See:

A brief description is provided:

Why is my face beaten?

Here, the nature and handling of exceptions are clear.
Below is a simple summary:

/* Pseudo code */main/* main */-> createJVM ()/* Create JVM */-> loadMainClass () /* load the specified $ mainClass file. This is a class file */-> findMethod ("main")/* Find the main method in $ mainClass, the main */-> getMethodFromJVM ()/* of the program written in java is not cached. Ask the JVM */-> classLoader. loadFromFile ()/* Find in classpath. class file */-> not found, set NoClassDefFound exception.

However, why does Intellij IDEA not setstorm-core.jarIncludeclasspathWhat about it?

In other words: Why is the face beaten ??

The reason for face recognition is simple:
1.F5->run, Make/compile/build first, and then run.
2. Set the dependent scopeprovidedThis setting only adds the dependent jar package to the classpath during the compilation stage. In the runtime stage, the jar package is not added to the classpath.

The solution is also very simple:

If mvn is not used, but debugging/running in IDE, select the scope of the dependent jar packagecompileWell, you won't be beaten!

Check whether it is correct?

Postscript

End.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.