Coder Social home page Coder Social logo

hotswapprojects / hotswapagentexamples Goto Github PK

View Code? Open in Web Editor NEW
48.0 48.0 40.0 323 KB

Example applications for HotswapAgent plugins

License: GNU General Public License v2.0

Java 82.82% Shell 2.05% HTML 13.93% CSS 0.20% Dockerfile 0.53% Kotlin 0.47%

hotswapagentexamples's People

Contributors

beiwei30 avatar dependabot[bot] avatar edudant avatar gdrouet avatar klaus7 avatar renfeng avatar skybber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hotswapagentexamples's Issues

Query on writing custom agent plugin

Hi there.

I'm investigating writing a custom plugin to allow hot reload of the Javalin framework. For now, I'm not trying to get anything production ready, just get my head round what is needed, but I'm struggling to get the agent to call my plugin even though it is initialised.

General Aim

I have a top level object call App which has a method call "reload". For now, all I want to do is make it so that if any class is changed, the reload method is called.

Setup

Okay. So I have a top level kotlin object called App

package io.javalin.hotswap

import io.javalin.Javalin

object App {
  private val server = Javalin.create()

  fun start(){
    server.start(7777)
    server.get("/",TestClass::home)
  }

  fun stop(){
    server.stop()
  }

  fun reload(){
    stop()
    start()
  }
}

fun main(args: Array<String>){
  App.start()
}

that makes reference to another object TestClass

package io.javalin.hotswap

import io.javalin.http.Context

object TestClass {
  fun home(ctx: Context){
    ctx.result("Hi there")
  }
}

What I want is for a change to TestClass (or any other class) to cause the reload method on App to be called

Plugin Implementation

I therefore implemented the following Plugin

@Plugin(
  name = "Reload Plugin",
  description = "Testing reload plugin",
  testedVersions = ["unknown"]
)
class ReloadPlugin {
  @OnClassLoadEvent(classNameRegexp = ".*")
  fun onClassReloaded() {
    logger.info("one or more classes reloaded")
  }

  companion object {
    val logger = AgentLogger.getLogger(ReloadPlugin::class.java)

    @JvmStatic
    @OnClassLoadEvent(classNameRegexp = "io.javalin.hotswap.App")
    fun onApplicationStart() {
      logger.info("reload plugin initialised")
      PluginManagerInvoker.buildInitializePlugin(ReloadPlugin::class.java)
    }
  }
}

Results

When I run the app in debug mode, I see the following

HOTSWAP AGENT: 11:59:40.349 DEBUG (org.hotswap.agent.annotation.handler.OnClassLoadedHandler) - Init for method public static final void io.javalin.hotswap.ReloadPlugin.onApplicationStart()
HOTSWAP AGENT: 11:59:40.350 DEBUG (org.hotswap.agent.util.HotswapTransformer) - Registering transformer for class regexp 'io.javalin.hotswap.App'.
HOTSWAP AGENT: 11:59:40.351 DEBUG (org.hotswap.agent.config.PluginRegistry) - Plugin registered class io.javalin.hotswap.ReloadPlugin.
HOTSWAP AGENT: 11:59:40.351 INFO (org.hotswap.agent.config.PluginRegistry) - Discovered plugins: [Reload Plugin]

so it correctly finds my plugin. Then, a little later I see

HOTSWAP AGENT: 11:59:40.428 INFO (io.javalin.hotswap.ReloadPlugin) - reload plugin initialised

so it is also initialising my plugin. However, when I change the TestClass and compile I see

HOTSWAP AGENT: 12:00:14.067 DEBUG (org.hotswap.agent.plugin.jvm.ClassInitPlugin) - Adding $$ha$clinit to class: io.javalin.hotswap.TestClass
HOTSWAP AGENT: 12:00:14.077 DEBUG (org.hotswap.agent.plugin.jvm.ClassInitPlugin) - Skipping old field INSTANCE
HOTSWAP AGENT: 12:00:14.107 DEBUG (org.hotswap.agent.plugin.jdk.JdkPlugin) - Flushing io.javalin.hotswap.TestClass from com.sun.beans.introspect.ClassInfo cache
HOTSWAP AGENT: 12:00:14.110 DEBUG (org.hotswap.agent.plugin.jdk.JdkPlugin) - Flushing io.javalin.hotswap.TestClass from introspector
HOTSWAP AGENT: 12:00:14.112 TRACE (org.hotswap.agent.plugin.jdk.JdkPlugin) - Removing class from declaredMethodCache.
HOTSWAP AGENT: 12:00:14.112 DEBUG (org.hotswap.agent.plugin.jdk.JdkPlugin) - Flushing io.javalin.hotswap.TestClass from ObjectStreamClass caches

so it is indeed redefining the TestClass but my @OnClassLoadEvent is not being called despite having a regexp of ".*".

I tried to follow the custom plugin example but it was using a very old version and referring to annotations which did not exist any more, and when I tried to run a copy to understand it better, it said it was for Java version 5!

If anyone could explain what I'm doing wrong, that would be much appreciated

Gradle?

Have any spring/(jetty or tomcat) projects that use gradle rather than maven for building?

How to use in Maven Project ?

I exported the two settings variable like this :

export MAVEN_OPTS='-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -Xms256m -Xmx1048m -XX:MaxPermSize=512m -XX:NewRatio=6 -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled' -XXaltjvm=dcevm -javaagent:e:\HotswapAgent.jar

and maven gave not a valid identifier error. How to use it in maven webapps ?

mvn tomcat7:run

Queries re: resource changes

Hi there.

Am working on a custom plugin for reloading Javalin on any class or resource change. I have the class reloading part working and the resource reloading works, but has some quirks or areas I don't understand

  • Is it necessary to use the watchResources property in hotswap-agent.properties if we want to watch for resource changes? If so, what is the purpose of the "path" parameter in the @OnResourceFileEvent annotation?
  • When I save a single file with a single word change, I seem to receive multiple file change events. Is this expected (I assume it is the IDE being clever to avoid losing data on a crash) and do I need to do anything specific to deal with it - right now I am using a scheduled reflection command and it appears to only be being called once, but I don't know exactly how that works!

Finally, thanks very much for what is a fantastically useful piece of code. With the reload plugin implemented, the application restarts in 10ms which makes for a much nicer development workflow

Maven install fails - project structure

Hi, this feels like a stupid question but I can't do anything with this project. Maven complains about the project structure. See the following output after I cloned the project:

(Maven 3.3.3 on Java 7)

C:\dev\HotswapAgentExamples>mvn install
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'parent.relativePath' of POM org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:unknown-version
points at org.hotswap.agent:hotswap-ag
ent-examples-aggregator instead of org.hotswap.agent:hotswap-agent-parent, please verify your project structure @ line 5
, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version]
: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at
wrong local POM @ line 5, column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.examples:plain-java:[unknown-version](C:devHotswapAgentExample
splain-javapom.xml) points at org.hotswap.agent:hotswap-agent-examples-aggregator instead of org.hotswap.agent:hotswap
-agent-parent, please verify your project structure @ line 7, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.examples:plain-java:[unknown-version]: Could not find artifact org.hot
swap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column
13
[WARNING] 'parent.relativePath' of POM org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:unknown-version
points at org.hotswap.agent:hotswap-ag
ent-examples-aggregator instead of org.hotswap.agent:hotswap-agent-parent, please verify your project structure @ org.ho
tswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\HotswapAgentExamples\hotswap-ag
ent-examples-servlet-parent\pom.xml, line 5, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version]
: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at
wrong local POM @ org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\Hotswap
AgentExamples\hotswap-agent-examples-servlet-parent\pom.xml, line 5, column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.plugin.examples:custom-plugin:[unknown-version](C:devHotswapAg
entExamplescustom-pluginpom.xml) points at org.hotswap.agent:hotswap-agent-examples-aggregator instead of org.hotswap.
agent:hotswap-agent-parent, please verify your project structure @ line 7, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.plugin.examples:custom-plugin:[unknown-version]: Could not find artifa
ct org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line
7, column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:unknown-version
points at org.hotswap.agent:hotswap-ag
ent-examples-aggregator instead of org.hotswap.agent:hotswap-agent-parent, please verify your project structure @ org.ho
tswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\HotswapAgentExamples\hotswap-ag
ent-examples-servlet-parent\pom.xml, line 5, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version]
: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at
wrong local POM @ org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\Hotswap
AgentExamples\hotswap-agent-examples-servlet-parent\pom.xml, line 5, column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.examples:seam-hibernate-jsf:[unknown-version](C:devHotswapAgen
tExamplesseam-hibernate-jsfpom.xml) points at org.hotswap.agent:hotswap-agent-examples-aggregator instead of org.hotsw
ap.agent:hotswap-agent-parent, please verify your project structure @ line 6, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.examples:seam-hibernate-jsf:[unknown-version]: Failure to find org.hot
swap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT in http://snapshots.jboss.org/maven2/ was cached in the local reposit
ory, resolution will not be reattempted until the update interval of snapshots.jboss.org has elapsed or updates are forc
ed and 'parent.relativePath' points at wrong local POM @ line 6, column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.examples:cdi-hibernate-jsf:[unknown-version](C:devHotswapAgent
Examplescdi-hibernate-jsfpom.xml) points at org.hotswap.agent:hotswap-agent-examples-aggregator instead of org.hotswap
.agent:hotswap-agent-parent, please verify your project structure @ line 6, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.examples:cdi-hibernate-jsf:[unknown-version]: Could not find artifact
org.hotswap.agent:hotswap-agent-parent:pom:0.3.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 6,
column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.examples:ejb-cdi-hibernate-jsf:[unknown-version](C:devHotswapA
gentExamplesejb-cdi-hibernate-jsfpom.xml) points at org.hotswap.agent:hotswap-agent-examples-aggregator instead of org
.hotswap.agent:hotswap-agent-parent, please verify your project structure @ line 6, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.examples:ejb-cdi-hibernate-jsf:[unknown-version]: Failure to find org.
hotswap.agent:hotswap-agent-parent:pom:0.3.0-SNAPSHOT in https://repository.jboss.org/nexus/content/groups/public/ was c
ached in the local repository, resolution will not be reattempted until the update interval of JBoss Repository has elap
sed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 6, column 13
@
[ERROR] The build could not read 8 projects -> [Help 1]
[ERROR]
[ERROR] The project org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version](C:devHot
swapAgentExampleshotswap-agent-examples-servlet-parentpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-vers
ion]: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points
at wrong local POM @ line 5, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:plain-java:[unknown-version](C:devHotswapAgentExamplesplain-javapom.
xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.examples:plain-java:[unknown-version]: Could not find artifact org
.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, col
umn 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:plain-servlet:[unknown-version](C:devHotswapAgentExamplesplain-servle
tpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-vers
ion]: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points
at wrong local POM @ org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\Hot
swapAgentExamples\hotswap-agent-examples-servlet-parent\pom.xml, line 5, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.plugin.examples:custom-plugin:[unknown-version](C:devHotswapAgentExamplescusto
m-pluginpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.plugin.examples:custom-plugin:[unknown-version]: Could not find ar
tifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ l
ine 7, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:spring-hibernate:[unknown-version](C:devHotswapAgentExamplesspring-hi
bernatepom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-vers
ion]: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points
at wrong local POM @ org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\Hot
swapAgentExamples\hotswap-agent-examples-servlet-parent\pom.xml, line 5, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:seam-hibernate-jsf:[unknown-version](C:devHotswapAgentExamplesseam-hi
bernate-jsfpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.examples:seam-hibernate-jsf:[unknown-version]: Failure to find org
.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT in http://snapshots.jboss.org/maven2/ was cached in the local rep
ository, resolution will not be reattempted until the update interval of snapshots.jboss.org has elapsed or updates are
forced and 'parent.relativePath' points at wrong local POM @ line 6, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:cdi-hibernate-jsf:[unknown-version](C:devHotswapAgentExamplescdi-hibe
rnate-jsfpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.examples:cdi-hibernate-jsf:[unknown-version]: Could not find artif
act org.hotswap.agent:hotswap-agent-parent:pom:0.3.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line
6, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:ejb-cdi-hibernate-jsf:[unknown-version](C:devHotswapAgentExamplesejb-
cdi-hibernate-jsfpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.examples:ejb-cdi-hibernate-jsf:[unknown-version]: Failure to find
org.hotswap.agent:hotswap-agent-parent:pom:0.3.0-SNAPSHOT in https://repository.jboss.org/nexus/content/groups/public/ w
as cached in the local repository, resolution will not be reattempted until the update interval of JBoss Repository has
elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 6, column 13 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

Unknown resource type of file file:

I get the above warning when I set my pluginPackages variable to the correct package where I created a plugin. I am using the latest DCEVM.

Disable hotswap agent logger

How to disable it? setting LOGGER=OFF has no effect
LOGGER=ERROR does not suit me, i got lots of errors which I have to scroll to find my stack trace

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.