From efdb99f8cecc4afb592afad79c761081d5d5cf22 Mon Sep 17 00:00:00 2001
From: lee <4766465@qq.com>
Date: Wed, 18 Dec 2024 13:27:00 +0800
Subject: [PATCH] init

---
 xxl-job/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java |  122 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 122 insertions(+), 0 deletions(-)

diff --git a/xxl-job/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java b/xxl-job/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java
new file mode 100644
index 0000000..7e35012
--- /dev/null
+++ b/xxl-job/xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java
@@ -0,0 +1,122 @@
+package com.xxl.job.core.context;
+
+/**
+ * xxl-job context
+ *
+ * @author xuxueli 2020-05-21
+ * [Dear hj]
+ */
+public class XxlJobContext {
+
+    public static final int HANDLE_CODE_SUCCESS = 200;
+    public static final int HANDLE_CODE_FAIL = 500;
+    public static final int HANDLE_CODE_TIMEOUT = 502;
+
+    // ---------------------- base info ----------------------
+
+    /**
+     * job id
+     */
+    private final long jobId;
+
+    /**
+     * job param
+     */
+    private final String jobParam;
+
+    // ---------------------- for log ----------------------
+
+    /**
+     * job log filename
+     */
+    private final String jobLogFileName;
+
+    // ---------------------- for shard ----------------------
+
+    /**
+     * shard index
+     */
+    private final int shardIndex;
+
+    /**
+     * shard total
+     */
+    private final int shardTotal;
+
+    // ---------------------- for handle ----------------------
+
+    /**
+     * handleCode:The result status of job execution
+     *
+     *      200 : success
+     *      500 : fail
+     *      502 : timeout
+     *
+     */
+    private int handleCode;
+
+    /**
+     * handleMsg:The simple log msg of job execution
+     */
+    private String handleMsg;
+
+
+    public XxlJobContext(long jobId, String jobParam, String jobLogFileName, int shardIndex, int shardTotal) {
+        this.jobId = jobId;
+        this.jobParam = jobParam;
+        this.jobLogFileName = jobLogFileName;
+        this.shardIndex = shardIndex;
+        this.shardTotal = shardTotal;
+
+        this.handleCode = HANDLE_CODE_SUCCESS;  // default success
+    }
+
+    public long getJobId() {
+        return jobId;
+    }
+
+    public String getJobParam() {
+        return jobParam;
+    }
+
+    public String getJobLogFileName() {
+        return jobLogFileName;
+    }
+
+    public int getShardIndex() {
+        return shardIndex;
+    }
+
+    public int getShardTotal() {
+        return shardTotal;
+    }
+
+    public void setHandleCode(int handleCode) {
+        this.handleCode = handleCode;
+    }
+
+    public int getHandleCode() {
+        return handleCode;
+    }
+
+    public void setHandleMsg(String handleMsg) {
+        this.handleMsg = handleMsg;
+    }
+
+    public String getHandleMsg() {
+        return handleMsg;
+    }
+
+    // ---------------------- tool ----------------------
+
+    private static InheritableThreadLocal<XxlJobContext> contextHolder = new InheritableThreadLocal<XxlJobContext>(); // support for child thread of job handler)
+
+    public static void setXxlJobContext(XxlJobContext xxlJobContext){
+        contextHolder.set(xxlJobContext);
+    }
+
+    public static XxlJobContext getXxlJobContext(){
+        return contextHolder.get();
+    }
+
+}
\ No newline at end of file

--
Gitblit v1.9.3