WO2024212612A1 - Remote invocation dynamic extension method based on dynamic java bytecode - Google Patents
Remote invocation dynamic extension method based on dynamic java bytecode Download PDFInfo
- Publication number
- WO2024212612A1 WO2024212612A1 PCT/CN2023/143141 CN2023143141W WO2024212612A1 WO 2024212612 A1 WO2024212612 A1 WO 2024212612A1 CN 2023143141 W CN2023143141 W CN 2023143141W WO 2024212612 A1 WO2024212612 A1 WO 2024212612A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- remote call
- server
- bytecode
- task
- client
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/547—Remote procedure calls [RPC]; Web services
- G06F9/548—Object oriented; Remote method invocation [RMI]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/02—Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/133—Protocols for remote procedure calls [RPC]
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L69/00—Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
- H04L69/16—Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
- H04L69/161—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
- H04L69/162—Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms
Definitions
- the present invention relates to the field of information technology, and in particular to a remote call dynamic expansion method based on Java dynamic bytecode.
- an agent is usually installed on the specified cloud host in the vpc, and then the server sends task instructions to implement remote calls to the specified agent, such as initiating HTTP calls to vpc internal components or reading and writing configuration files and other complex functions.
- the traditional solution is a C/S architecture implemented in Java language, and the server calls the remote call interface on the agent through the application layer protocol.
- remote call tasks defined by shell scripts can be executed without compilation, but for complex calls such as http requests and string processing or scenarios containing Java language features, the implementation will be very complicated.
- remote calls with complex logic or containing Java language features it is necessary to write supporting implementation codes on both the calling and called ends, and then execute remote calls through application layer protocols.
- problems such as large development and operation workload and poor scalability.
- the present invention provides a remote call dynamic extension method based on Java dynamic bytecode, which can use Java language characteristics to define remote tasks, and can also be flexibly extended to improve development efficiency and reduce operation and maintenance costs.
- the present invention proposes a remote call dynamic extension method based on Java dynamic bytecode, comprising:
- a communication channel is established between the client and the server.
- the server initiates a remote call to the specified client
- the client creates a custom ClassLoader, dynamically loads the task bytecode remotely from the server based on the task ID and version number, and generates a Java class;
- the client executes the method of the remote task object and returns the call result.
- the client caches the bytecode of the remote call implementation class locally based on the remote call ID and version number to speed up the program running efficiency.
- the client creates a custom ClassLoader to load the bytecode of the remote call implementation class from the server according to the task ID and version number parameters, and then instantiates the remote call object through the Java reflection mechanism and forces it to be transformed into the agreed remote call interface.
- the communication channel is for the client to communicate with the server through a TCP long connection.
- server initiates a remote call to the specified client as follows:
- the server initiates a remote call to the specified client using the remote call task ID, version number, and business data as parameters.
- the server calls the specified task on the client through a remote call protocol at the application layer based on a TCP long connection, provides a general interface for the server to call the specified task on the client, and uses the Gson tool name as a serialization/deserialization tool to process parameters and return values.
- the server uses Javassist to dynamically compile it into a bytecode file, uses the task name and version number as the class name, and stores the compiled bytecode in the server file system.
- the server saves the version history of the remote call source code to the database to perform source code level version control.
- the present invention also proposes a remote call dynamic expansion system based on Java dynamic bytecode, comprising:
- the server management console provides an interface based on the Web management system for maintaining remote call tasks of Java source code type, and has the functions of adding, deleting, modifying and checking;
- a server interface providing a web interface, through which remote tasks are defined and managed;
- Javassist compiler based on Javassist, dynamically compiles remote tasks of Java source code type defined through the server interface into bytecode, and the bytecode will be stored on the server;
- Remote call protocol which implements the application layer remote call protocol based on TCP long connection, and is used by the server to call the general interface of the specified task on the client;
- the remote call protocol uses Gson as a serialization/deserialization tool to process parameters and return values;
- Remote call interface which provides the agreed remote call interface, including the remote call method, parameters, return value and exception.
- the remote call task can only be implemented by writing the implementation method based on the remote call interface;
- the custom ClassLoader is created by the client, dynamically loads the remote task bytecode from the server according to the ID and version number of the remote call task, and generates a Java class.
- the embodiment of the present invention provides a remote call dynamic extension method and system based on Java dynamic bytecode, which has the following beneficial effects compared with the prior art:
- the present invention defines remote call tasks through Java source code, and can use Java language characteristics to write complex call logic; uses Java dynamic compilation technology, so it can take effect without compilation and deployment, and can achieve the effect of dynamic expansion; performs source code level version control on remote call implementation, and can be flexibly switched at runtime, avoiding online risks brought by dynamic expansion; the server compiles once and the client runs on multiple terminals, eliminating repeated client compilation operations and avoiding the possibility of compilation errors at runtime.
- FIG. 1 is a flow chart of a remote call dynamic extension method based on Java dynamic bytecode according to an embodiment of the present invention
- FIG. 2 is a functional block diagram of a remote call dynamic expansion device based on Java dynamic bytecode according to an embodiment of the present invention.
- the terms “installed”, “connected”, and “connected” should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components.
- installed should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components.
- a remote call dynamic extension method based on Java dynamic bytecode includes:
- a communication channel is established between the client and the server.
- the server provides an interface, which is used to maintain remote call tasks of Java source code type;
- the server initiates a remote call to the specified client
- the client creates a custom ClassLoader, dynamically loads the task bytecode remotely from the server based on the task ID and version number, and generates a Java class;
- the client executes the method of the remote task object and returns the call result.
- the method of defining tasks using Java language features allows developers to use the features of the Java programming language to define complex remote call tasks, including various libraries, frameworks, and functions provided by the Java programming language, making it easier to implement complex remote call logic; through Javassist technology, Java source code type remote tasks can be dynamically compiled into bytecode on the server side without manual compilation and deployment, bringing dynamic expansion effects.
- the result is that the deployment and update of new tasks are more flexible; the method of this embodiment provides a version control mechanism at the source code level, allowing different versions of task implementations to be switched at runtime. This helps to avoid online risks that may be caused by dynamic expansion, while allowing the system to switch between different versions of tasks; using Java source code to define tasks simplifies the development of complex calling logic.
- the client creates a custom ClassLoader and dynamically loads the task bytecode, without sending the source code of the task to the client, which helps maintain the independence of the client and reduces potential security risks; by establishing a C/S architecture communication channel and using a standard remote call protocol, the method provides a general remote call framework that can be used in a variety of remote call scenarios.
- it also includes:
- the client caches the bytecode of the remote call implementation class locally based on the remote call ID and version number to speed up the program running efficiency.
- the client maintains a local cache manager to store the bytecode of the remote call task.
- This manager can use memory cache or disk cache, depending on the number and size of tasks.
- the client builds a unique cache key based on the remote call ID and version number to retrieve the corresponding bytecode in the cache.
- the cache key can be concatenated with the remote call ID and version number to ensure uniqueness.
- the client can use cache elimination strategies such as LRU (Least Recently Used) to ensure that the cache space is occupied by frequently used tasks, reduce the cache priority of infrequently used tasks, and improve the cache hit rate.
- LRU Least Recently Used
- the client Before initiating a remote call, the client first checks whether there is bytecode corresponding to the remote call ID and version number in the local cache.
- the bytecode in the local cache is directly used to instantiate the remote call object, avoiding the time and network overhead of loading the bytecode again from the server.
- the server initiates a new remote call or updates the version of the task
- the client needs to update the local cache accordingly.
- the cache can be updated by regularly checking the task version information on the server, or by notifying the client when the server task changes.
- the client creates a custom ClassLoader to load the bytecode of the remote call implementation class from the server according to the task ID and version number parameters, and then uses Java The reflection mechanism instantiates the remote call object and forces it to be transformed into the agreed remote call interface.
- the client requests the server to obtain the bytecode for a specific task.
- HTTP or other network protocols can be used for communication to request the server to provide the bytecode for the task.
- the server should respond to the client's request and return the bytecode data.
- Custom ClassLoader loads bytecode: After the client's custom ClassLoader obtains the bytecode data through the network, it uses custom logic to load the bytecode. You can use the defineClass method to load the bytecode and convert it into a Class object.
- Instantiate remote call object The client uses the Java reflection mechanism to instantiate the remote call object based on the obtained Class object. This can be done through the Class.newInstance() method or by calling the constructor through reflection.
- Interface forced transformation The client can force the instantiated object to be transformed into the agreed remote call interface, and the client can call the methods defined in the task interface.
- the communication channel is that the client communicates with the server through a TCP long connection.
- the server initiates a remote call to a specified client as follows:
- the server initiates a remote call to the specified client using the remote call task ID, version number, and business data as parameters.
- the client and server can establish a two-way communication channel, so that both parties can communicate at any time, enhancing the real-time and interactive nature of the system.
- the server can initiate a remote call request to the specified client at any time, so that the remote call can be triggered and executed in real time, which is particularly important in scenarios that require immediate response, such as monitoring and alarming.
- the server can dynamically call the client according to the specific task and version number, achieving more Add flexible remote call logic.
- TCP long connection allows asynchronous communication, and the client and server can process multiple requests in parallel, thereby improving the concurrency and performance of the system.
- the client and server connections can be easily expanded to meet the growing communication needs. Long connection is more reliable in an unstable network environment because the maintenance of the connection can tolerate certain network fluctuations without the need to frequently re-establish the connection. If the connection is disconnected, the client and server can implement an automatic reconnection mechanism to ensure the reliability of the connection.
- the server calls a specified task on the client by implementing a remote call protocol at the application layer based on a TCP long connection, provides a general interface for the server to call the specified task on the client, and uses the Gson tool name as a serialization/deserialization tool to process parameters and return values.
- Serialize parameters and return values On both the client and server side, use Gson or a similar library to serialize method call parameters and deserialize return values. This ensures that the data is encoded and decoded in a standard format when transmitted over the network.
- Establish a TCP persistent connection Use Java Socket programming to establish a persistent TCP persistent connection between the server and the client to achieve two-way communication.
- the server provides a common interface:
- the server should provide a common interface for receiving remote call requests. This interface can accept the method name, parameters and other call information of the request, and then execute the logic of the remote call according to the protocol definition.
- the client calls the server method:
- the client sends a remote call request to the server through the established TCP connection, and serializes the method name and parameters and sends them to the server.
- the server processes the remote call request: After receiving the client's request, the server executes the corresponding method according to the method name and parameters in the request. Then the return value of the method is serialized and sent back to the client.
- Client receives and processes the result: The client receives the response from the server and responds to it. Serialize, get the return value of the method, and finally return it to the caller.
- Exception handling If an exception occurs during the execution of a remote method, the exception information needs to be captured and serialized and passed to the client. The client handles the exception based on the received exception information.
- the server when saving a remote call source code task, uses Javassist to dynamically compile it into a bytecode file, uses the task name and version number as the class name, and stores the compiled bytecode in the server file system.
- the server saves the version history of the remote call source code to a database to perform source code level version control.
- dynamic scalability Using Javassist to dynamically compile source code allows new remote call tasks to be added to the system without recompiling the entire application, which improves the scalability of the system and allows new features to be introduced dynamically.
- the server can prevent duplicate task names so that tasks of different versions can coexist. This allows multiple different versions of tasks to be supported in the system, ensuring compatibility and smooth upgrades. Since there is no need to redeploy or compile the entire application, dynamically compiled tasks can take effect immediately at runtime. This allows developers to adjust remote call tasks more quickly without interrupting the running system.
- the version history of the remote call source code is saved to the database, and source code-level version control is performed, so that the system can track the evolution of remote call tasks. This helps to understand the modification records of each task version, facilitates troubleshooting and rollback to previous versions. By saving the history of remote call task versions to the database, administrators can better manage and maintain different versions of tasks. This is very important for the stability and maintainability of the system.
- Source code-level version control allows flexible switching of task versions at runtime, thereby avoiding online risks that may be introduced by dynamic expansion and ensuring the stability of the system.
- this embodiment develops a basic framework of C/S architecture based on Netty framework.
- the client communicates with the server through TCP long connection, and the server holds the client's session information.
- a set of application layer remote call protocols is implemented based on TCP long connection, providing a general interface for the server to call the specified task on the client, and using Gson tool name as the serialization/deserialization tool to process parameters and return values;
- the management console of the server adopts
- the WEB management system developed by springboot+mybatis-plus+vue provides an interface for maintaining remote call tasks of Java source code type, with the functions of adding, deleting, modifying and checking;
- the system provides an agreed remote call interface, including remote call methods, parameters, return values and exceptions, and remote call tasks can only be implemented based on this interface; when saving remote call source code tasks, the server will use Javassist to dynamically compile them into bytecode files, use the task name and version number as the class name to avoid duplication, and store the compiled byte
- an embodiment of the present invention further provides a remote call dynamic expansion system based on Java dynamic bytecode, comprising:
- the server management console provides an interface based on the Web management system for maintaining remote call tasks of Java source code type, and has the functions of adding, deleting, modifying and checking;
- the server interface provides a web interface for defining and managing remote tasks
- Javassist compiler based on Javassist, dynamically compiles remote tasks of Java source code type defined through the server interface into bytecode, which will be saved on the server;
- Remote call protocol which implements the application layer remote call protocol based on TCP long connection, is a general interface for the server to call the specified task on the client; the remote call protocol uses Gson as a serialization/deserialization tool to process parameters and return values;
- Remote call interface which provides the agreed remote call interface, including the remote call method, parameters, return value and exception.
- the remote call task can only be implemented by writing the implementation method based on the remote call interface.
- the custom ClassLoader is created by the client, dynamically loads the remote task bytecode from the server according to the ID and version number of the remote call task, and generates a Java class.
- the server responsible for task management has the following functions: task definition, task testing, task compilation, version control, task publishing and remote calling;
- the client responsible for task execution has the following functions: task update, task loading, task caching and task execution.
- the system allows remote call tasks to be dynamically added, modified, and deleted at runtime without recompiling or deploying the entire application. This provides great flexibility and dynamic scalability, allowing the system to change as needs change.
- developers and administrators can easily manage and configure remote call tasks, including defining, editing, deleting, and querying tasks. This simplifies the task management process and reduces the complexity of development and maintenance.
- Custom ClassLoader can load remote task bytecode from the server based on the task ID and version number. The client instantiates the remote call object through the Java reflection mechanism, which provides higher performance because the local execution of bytecode is faster than other methods.
- Gson as a serialization/deserialization tool to handle parameters and return values makes data transmission more efficient and allows different versions of tasks to communicate using the same protocol.
- the methods, parameters, return values, and exceptions of remote call tasks are agreed upon, thereby ensuring the consistency and interoperability of tasks.
- Version control allows the system to maintain a history of different task versions, which helps troubleshooting, rollback, and maintenance.
- the management console on the server provides a user-friendly interface based on the web management system, making it easier to create and manage tasks. Administrators can easily view, modify, and monitor tasks.
- Source code-level version control allows flexible switching of task versions at runtime, thereby avoiding online risks that may be introduced by dynamic expansion and ensuring system stability.
- the system provided in the above embodiment is only illustrated by the division of the above functional modules.
- the above functions can be assigned to different functional modules as needed, that is, the modules or steps in the embodiments of the present invention can be decomposed or combined.
- the modules in the above embodiment can be combined into one module, or further divided into multiple sub-modules to complete all or part of the functions described above.
- the names of the modules and steps involved in the embodiments of the present invention are only for distinguishing each module or step and are not to be regarded as improper limitations of the present invention.
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Computer Security & Cryptography (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
Description
本发明涉及信息技术的领域,具体而言,涉及一种基于Java动态字节码的远程调用动态扩展方法。The present invention relates to the field of information technology, and in particular to a remote call dynamic expansion method based on Java dynamic bytecode.
私有云IaaS场景下,为了实现对vpc内部组件的远程管理,通常会在vpc内指定云主机上安装一个代理程序(agent),再通过服务端下发任务指令来实现对指定agent的远程调用,例如对vpc内部组件发起http调用或是配置文件读写等复杂的功能。传统方案是基于Java语言实现的C/S架构,服务端通过应用层协议调用agent上的远程调用接口来实现。In the private cloud IaaS scenario, in order to achieve remote management of vpc internal components, an agent is usually installed on the specified cloud host in the vpc, and then the server sends task instructions to implement remote calls to the specified agent, such as initiating HTTP calls to vpc internal components or reading and writing configuration files and other complex functions. The traditional solution is a C/S architecture implemented in Java language, and the server calls the remote call interface on the agent through the application layer protocol.
当前,系统中对远程调用的实现主要分为shell脚本语言和Java语言两种:通过shell脚本定义的远程调用任务不需要编译就可以执行,但是对http请求、字符串处理等复杂调用或者包含Java语言特性的场景,实现就会非常复杂。对逻辑复杂或包含Java语言特性的远程调用,需要同时在调用端和被调用端编写配套的实现代码,再通过应用层协议执行远程调用。存在开发运维工作量大,可扩展性差的问题。Currently, the implementation of remote calls in the system is mainly divided into two types: shell script language and Java language: remote call tasks defined by shell scripts can be executed without compilation, but for complex calls such as http requests and string processing or scenarios containing Java language features, the implementation will be very complicated. For remote calls with complex logic or containing Java language features, it is necessary to write supporting implementation codes on both the calling and called ends, and then execute remote calls through application layer protocols. There are problems such as large development and operation workload and poor scalability.
发明内容Summary of the invention
有鉴于此,本发明提供了一种基于Java动态字节码的远程调用动态扩展方法,能够使用Java语言特性来定义远程任务,同时也可以灵活扩展,提高开发效率,减少运维成本。In view of this, the present invention provides a remote call dynamic extension method based on Java dynamic bytecode, which can use Java language characteristics to define remote tasks, and can also be flexibly extended to improve development efficiency and reduce operation and maintenance costs.
一方面,本发明提出的一种基于Java动态字节码的远程调用动态扩展方法,包括:On the one hand, the present invention proposes a remote call dynamic extension method based on Java dynamic bytecode, comprising:
基于建立C/S架构,客户端与服务端之间建立通信渠道,服务端 提供界面,所述界面用于维护Java源码类型的远程调用任务;Based on the establishment of C/S architecture, a communication channel is established between the client and the server. Providing an interface for maintaining a remote call task of a Java source code type;
通过所述界面定义Java源码类型的远程任务,通过Javassist将Java源码动态预先编译为任务字节码,并保存在服务端;Define a remote task of Java source code type through the interface, dynamically precompile the Java source code into task bytecode through Javassist, and save it on the server;
服务端发起对指定客户端的远程调用;The server initiates a remote call to the specified client;
客户端创建自定义ClassLoader,根据任务ID、版本号动态从服务端远程加载任务字节码,并生成Java类;The client creates a custom ClassLoader, dynamically loads the task bytecode remotely from the server based on the task ID and version number, and generates a Java class;
客户端执行远程任务对象的方法并返回调用结果。The client executes the method of the remote task object and returns the call result.
进一步地,还包括:Furthermore, it also includes:
客户端根据远程调用ID和版本号缓存远程调用实现类的字节码到本地,用于加快程序运行效率。The client caches the bytecode of the remote call implementation class locally based on the remote call ID and version number to speed up the program running efficiency.
进一步地,客户端创建自定义ClassLoader根据任务ID和版本号参数从服务端加载远程调用实现类的字节码,再通过Java反射机制实例化远程调用对象,并强制转型为约定的远程调用接口。Furthermore, the client creates a custom ClassLoader to load the bytecode of the remote call implementation class from the server according to the task ID and version number parameters, and then instantiates the remote call object through the Java reflection mechanism and forces it to be transformed into the agreed remote call interface.
进一步地,所述通信渠道为客户端通过TCP长连接与服务端通信。Furthermore, the communication channel is for the client to communicate with the server through a TCP long connection.
进一步地,服务端发起对指定客户端的远程调用具体为:Furthermore, the server initiates a remote call to the specified client as follows:
服务端以远程调用任务的ID、版本号和业务数据为参数发起对指定客户端的远程调用。The server initiates a remote call to the specified client using the remote call task ID, version number, and business data as parameters.
进一步地,服务端调用客户端上指定任务通过基于TCP长连接实现应用层的远程调用协议,提供服务端调用客户端上指定任务的通用接口,使用Gson工具名作为序列化/反序列化工具处理参数和返回值。Furthermore, the server calls the specified task on the client through a remote call protocol at the application layer based on a TCP long connection, provides a general interface for the server to call the specified task on the client, and uses the Gson tool name as a serialization/deserialization tool to process parameters and return values.
进一步地,保存远程调用源码任务时,服务端使用Javassist将其动态编译成字节码文件,使用任务名和版本号作为类名,编译出的字节码存放到服务端文件系统。Furthermore, when saving a remote call source code task, the server uses Javassist to dynamically compile it into a bytecode file, uses the task name and version number as the class name, and stores the compiled bytecode in the server file system.
进一步地,服务端保存远程调用源码的版本历史到数据库,做源码级别的版本控制。Furthermore, the server saves the version history of the remote call source code to the database to perform source code level version control.
另一方面,本发明还提出了一种基于Java动态字节码的远程调用动态扩展系统,包括:On the other hand, the present invention also proposes a remote call dynamic expansion system based on Java dynamic bytecode, comprising:
服务端管理台,基于Web管理系统提供界面用于维护Java源码类型的远程调用任务,并且具有增删改查的功能; The server management console provides an interface based on the Web management system for maintaining remote call tasks of Java source code type, and has the functions of adding, deleting, modifying and checking;
服务端界面,提供Web界面,通过所述Web界面定义和管理远程任务;A server interface, providing a web interface, through which remote tasks are defined and managed;
Javassist编译器,基于Javassist将通过服务端界面定义的Java源码类型的远程任务动态编译为字节码,所述字节码将被保存在服务端;Javassist compiler, based on Javassist, dynamically compiles remote tasks of Java source code type defined through the server interface into bytecode, and the bytecode will be stored on the server;
远程调用协议,基于TCP长连接实现应用层的远程调用协议,用于服务端调用客户端上指定任务的通用接口;所述远程调用协议使用Gson作为序列化/反序列化工具来处理参数和返回值;Remote call protocol, which implements the application layer remote call protocol based on TCP long connection, and is used by the server to call the general interface of the specified task on the client; the remote call protocol uses Gson as a serialization/deserialization tool to process parameters and return values;
远程调用接口,提供约定的远程调用接口,包括远程调用的方法、参数、返回值和异常,远程调用任务只能基于所述远程调用接口编写实现方法;Remote call interface, which provides the agreed remote call interface, including the remote call method, parameters, return value and exception. The remote call task can only be implemented by writing the implementation method based on the remote call interface;
自定义ClassLoader,被客户端创建,根据远程调用任务的ID和版本号从服务端动态加载远程任务字节码,并生成Java类。The custom ClassLoader is created by the client, dynamically loads the remote task bytecode from the server according to the ID and version number of the remote call task, and generates a Java class.
本发明实施例一种基于Java动态字节码的远程调用动态扩展方法及系统,与现有技术相比,其有益效果在于:The embodiment of the present invention provides a remote call dynamic extension method and system based on Java dynamic bytecode, which has the following beneficial effects compared with the prior art:
本发明通过Java源码来定义远程调用任务,可使用Java语言特性来编写复杂的调用逻辑;使用Java动态编译技术,所以不需要编译和部署即可生效,能起到动态扩展的效果;对远程调用实现做源码级别的版本控制,可在运行时灵活切换,规避了动态扩展带来的线上风险;服务端一次编译,客户端多端运行,省去了客户端编译的重复操作,也避免了运行时编译出错的可能性。The present invention defines remote call tasks through Java source code, and can use Java language characteristics to write complex call logic; uses Java dynamic compilation technology, so it can take effect without compilation and deployment, and can achieve the effect of dynamic expansion; performs source code level version control on remote call implementation, and can be flexibly switched at runtime, avoiding online risks brought by dynamic expansion; the server compiles once and the client runs on multiple terminals, eliminating repeated client compilation operations and avoiding the possibility of compilation errors at runtime.
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据提供的附图获得其他的附图。In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
图1是本发明实施例基于Java动态字节码的远程调用动态扩展方法的流程图; 1 is a flow chart of a remote call dynamic extension method based on Java dynamic bytecode according to an embodiment of the present invention;
图2是本发明实施例基于Java动态字节码的远程调用动态扩展装置的功能框图。FIG. 2 is a functional block diagram of a remote call dynamic expansion device based on Java dynamic bytecode according to an embodiment of the present invention.
下面将对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention are described clearly and completely below. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
在本申请的描述中,需要说明的是,除非另有明确的规定和限定,术语“安装”、“相连”、“连接”应做广义理解,例如,可以是固定连接,也可以是可拆卸连接,或一体地连接;可以是机械连接,也可以是电连接;可以是直接相连,也可以通过中间媒介间接相连,可以是两个元件内部的连通。对于本领域的普通技术人员而言,可以具体情况理解上述术语在本申请中的具体含义。In the description of this application, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.
参阅图1-2所示,本发明优选实施例的一种基于Java动态字节码的远程调用动态扩展方法,包括:Referring to FIG. 1-2 , a remote call dynamic extension method based on Java dynamic bytecode according to a preferred embodiment of the present invention includes:
基于建立C/S架构,客户端与服务端之间建立通信渠道,服务端提供界面,界面用于维护Java源码类型的远程调用任务;Based on the establishment of C/S architecture, a communication channel is established between the client and the server. The server provides an interface, which is used to maintain remote call tasks of Java source code type;
通过界面定义Java源码类型的远程任务,通过Javassist将Java源码动态预先编译为任务字节码,并保存在服务端;Define remote tasks of Java source code type through the interface, dynamically pre-compile Java source code into task bytecode through Javassist, and save it on the server;
服务端发起对指定客户端的远程调用;The server initiates a remote call to the specified client;
客户端创建自定义ClassLoader,根据任务ID、版本号动态从服务端远程加载任务字节码,并生成Java类;The client creates a custom ClassLoader, dynamically loads the task bytecode remotely from the server based on the task ID and version number, and generates a Java class;
客户端执行远程任务对象的方法并返回调用结果。The client executes the method of the remote task object and returns the call result.
需要说明的是,使用Java语言特性定义任务,该方法允许开发人员使用Java编程语言的特性来定义复杂的远程调用任务,包括Java编程语言所提供的各种库、框架和功能,从而更容易实现复杂的远程调用逻辑;通过Javassist技术,Java源码类型的远程任务可以在服务端动态编译为字节码,无需手动编译和部署,带来了动态扩展的效 果,使新任务的部署和更新更加灵活;本实施例的方法提供了源码级别的版本控制机制,允许在运行时切换不同版本的任务实现。这有助于规避动态扩展可能带来的线上风险,同时允许系统在不同版本的任务之间切换;使用Java源码来定义任务简化了复杂调用逻辑的开发。此外,不需要手动编译和部署任务,减少了运维工作,提高了开发和维护的效率;客户端创建自定义ClassLoader并动态加载任务字节码,无需将任务的源代码发送到客户端,有助于保持客户端的独立性,并降低了潜在的安全风险;通过建立C/S架构通信渠道和使用标准的远程调用协议,该方法提供了通用的远程调用框架,可用于多种远程调用场景。It should be noted that the method of defining tasks using Java language features allows developers to use the features of the Java programming language to define complex remote call tasks, including various libraries, frameworks, and functions provided by the Java programming language, making it easier to implement complex remote call logic; through Javassist technology, Java source code type remote tasks can be dynamically compiled into bytecode on the server side without manual compilation and deployment, bringing dynamic expansion effects. The result is that the deployment and update of new tasks are more flexible; the method of this embodiment provides a version control mechanism at the source code level, allowing different versions of task implementations to be switched at runtime. This helps to avoid online risks that may be caused by dynamic expansion, while allowing the system to switch between different versions of tasks; using Java source code to define tasks simplifies the development of complex calling logic. In addition, there is no need to manually compile and deploy tasks, which reduces operation and maintenance work and improves development and maintenance efficiency; the client creates a custom ClassLoader and dynamically loads the task bytecode, without sending the source code of the task to the client, which helps maintain the independence of the client and reduces potential security risks; by establishing a C/S architecture communication channel and using a standard remote call protocol, the method provides a general remote call framework that can be used in a variety of remote call scenarios.
在其中一些实施例中,还包括:In some embodiments, it also includes:
客户端根据远程调用ID和版本号缓存远程调用实现类的字节码到本地,用于加快程序运行效率。The client caches the bytecode of the remote call implementation class locally based on the remote call ID and version number to speed up the program running efficiency.
可以理解的是,客户端维护一个本地缓存管理器,用于存储远程调用任务的字节码。这个管理器可以采用内存缓存或者磁盘缓存的方式,具体选择取决于任务数量和大小。客户端根据远程调用的ID和版本号构建唯一的缓存键,以便在缓存中检索相应的字节码。通常,缓存键可以使用远程调用的ID和版本号拼接而成,确保唯一性。客户端可以采用LRU(Least Recently Used)等缓存淘汰策略,确保缓存空间被高频使用的任务占用,降低不常使用任务的缓存优先级,提高缓存的命中率。在发起远程调用之前,客户端首先检查本地缓存中是否存在与远程调用ID和版本号相对应的字节码。如果存在,则直接使用本地缓存中的字节码实例化远程调用对象,避免了从服务端再次加载字节码的时间和网络开销。当服务端发起新的远程调用或者更新了任务的版本时,客户端需要相应地更新本地缓存。可以通过定期检查服务端的任务版本信息,或者在服务端任务发生变化时由服务端通知客户端进行缓存的更新。It is understood that the client maintains a local cache manager to store the bytecode of the remote call task. This manager can use memory cache or disk cache, depending on the number and size of tasks. The client builds a unique cache key based on the remote call ID and version number to retrieve the corresponding bytecode in the cache. Usually, the cache key can be concatenated with the remote call ID and version number to ensure uniqueness. The client can use cache elimination strategies such as LRU (Least Recently Used) to ensure that the cache space is occupied by frequently used tasks, reduce the cache priority of infrequently used tasks, and improve the cache hit rate. Before initiating a remote call, the client first checks whether there is bytecode corresponding to the remote call ID and version number in the local cache. If it exists, the bytecode in the local cache is directly used to instantiate the remote call object, avoiding the time and network overhead of loading the bytecode again from the server. When the server initiates a new remote call or updates the version of the task, the client needs to update the local cache accordingly. The cache can be updated by regularly checking the task version information on the server, or by notifying the client when the server task changes.
在其中一些实施例中,客户端创建自定义ClassLoader根据任务ID和版本号参数从服务端加载远程调用实现类的字节码,再通过Java 反射机制实例化远程调用对象,并强制转型为约定的远程调用接口。In some embodiments, the client creates a custom ClassLoader to load the bytecode of the remote call implementation class from the server according to the task ID and version number parameters, and then uses Java The reflection mechanism instantiates the remote call object and forces it to be transformed into the agreed remote call interface.
可以理解的是,上述内容的实现方式可以是:客户端自定义ClassLoader的创建:客户端需要创建一个自定义的ClassLoader,用于加载服务端提供的远程调用任务的字节码。ClassLoader可以继承自java.lang.ClassLoader类,重写findClass方法,以便在加载字节码时使用自定义的逻辑。It is understandable that the above content can be implemented in the following ways: Creation of a custom ClassLoader on the client: The client needs to create a custom ClassLoader to load the bytecode of the remote call task provided by the server. ClassLoader can inherit from the java.lang.ClassLoader class and override the findClass method to use custom logic when loading bytecode.
字节码的获取:客户端向服务端请求获取特定任务的字节码。通常,可以使用HTTP或其他网络协议进行通信,请求服务端提供任务的字节码。服务端应该响应客户端的请求,并返回字节码数据。Obtaining bytecode: The client requests the server to obtain the bytecode for a specific task. Usually, HTTP or other network protocols can be used for communication to request the server to provide the bytecode for the task. The server should respond to the client's request and return the bytecode data.
自定义ClassLoader加载字节码:客户端的自定义ClassLoader通过网络获取到字节码数据后,使用自定义的逻辑加载这些字节码。可以使用defineClass方法加载字节码,将其转化为Class对象。Custom ClassLoader loads bytecode: After the client's custom ClassLoader obtains the bytecode data through the network, it uses custom logic to load the bytecode. You can use the defineClass method to load the bytecode and convert it into a Class object.
实例化远程调用对象:客户端根据获得的Class对象,使用Java反射机制实例化远程调用对象。这可以通过Class.newInstance()方法或者反射调用构造函数来完成。Instantiate remote call object: The client uses the Java reflection mechanism to instantiate the remote call object based on the obtained Class object. This can be done through the Class.newInstance() method or by calling the constructor through reflection.
接口强制转型:客户端可以将实例化后的对象强制转型为约定的远程调用接口,客户端可以调用任务接口中定义的方法。Interface forced transformation: The client can force the instantiated object to be transformed into the agreed remote call interface, and the client can call the methods defined in the task interface.
在其中一些实施例中,通信渠道为客户端通过TCP长连接与服务端通信。In some of the embodiments, the communication channel is that the client communicates with the server through a TCP long connection.
在其中一些实施例中,服务端发起对指定客户端的远程调用具体为:In some embodiments, the server initiates a remote call to a specified client as follows:
服务端以远程调用任务的ID、版本号和业务数据为参数发起对指定客户端的远程调用。The server initiates a remote call to the specified client using the remote call task ID, version number, and business data as parameters.
需要说明的是,通过TCP长连接,客户端和服务端能够建立双向通信渠道,使得双方可以在任何时候进行通信,增强了系统的实时性和互动性。服务端可以随时向指定客户端发起远程调用请求,使得远程调用可以实时触发和执行,在需要即时响应的场景中尤为重要,如监控、告警等。通过将远程调用任务的ID、版本号和业务数据作为参数传递,服务端能够根据具体任务和版本号动态调用客户端,实现更 加灵活的远程调用逻辑。TCP长连接允许异步通信,客户端和服务端可以并行处理多个请求,从而提高了系统的并发性和性能。由于通信渠道建立在TCP协议上,可以很容易地扩展客户端和服务端的连接,以满足不断增长的通信需求。长连接在网络不稳定的环境下更为可靠,因为连接的维护可以容忍一定的网络波动,而不需要频繁重新建立连接。如果连接断开,客户端和服务端可以实现自动重连机制,确保连接的可靠性。It should be noted that through TCP persistent connection, the client and server can establish a two-way communication channel, so that both parties can communicate at any time, enhancing the real-time and interactive nature of the system. The server can initiate a remote call request to the specified client at any time, so that the remote call can be triggered and executed in real time, which is particularly important in scenarios that require immediate response, such as monitoring and alarming. By passing the remote call task ID, version number, and business data as parameters, the server can dynamically call the client according to the specific task and version number, achieving more Add flexible remote call logic. TCP long connection allows asynchronous communication, and the client and server can process multiple requests in parallel, thereby improving the concurrency and performance of the system. Since the communication channel is built on the TCP protocol, the client and server connections can be easily expanded to meet the growing communication needs. Long connection is more reliable in an unstable network environment because the maintenance of the connection can tolerate certain network fluctuations without the need to frequently re-establish the connection. If the connection is disconnected, the client and server can implement an automatic reconnection mechanism to ensure the reliability of the connection.
在其中一些实施例中,服务端调用客户端上指定任务通过基于TCP长连接实现应用层的远程调用协议,提供服务端调用客户端上指定任务的通用接口,使用Gson工具名作为序列化/反序列化工具处理参数和返回值。In some of the embodiments, the server calls a specified task on the client by implementing a remote call protocol at the application layer based on a TCP long connection, provides a general interface for the server to call the specified task on the client, and uses the Gson tool name as a serialization/deserialization tool to process parameters and return values.
可以理解的是,上述内容可通过以下方式实现:定义远程调用协议接口:在服务端和客户端之间共享一个协议接口,该接口定义了可以远程调用的方法、参数、返回值和异常。这个接口应该包含所有远程调用所需的信息。It is understandable that the above can be achieved in the following ways: Define a remote call protocol interface: Share a protocol interface between the server and the client, which defines the methods, parameters, return values and exceptions that can be called remotely. This interface should contain all the information required for remote calls.
序列化参数和返回值:在客户端和服务端,使用Gson或类似的库来序列化方法调用的参数和反序列化返回值。这确保了数据在网络上传输时以标准格式进行编码和解码。Serialize parameters and return values: On both the client and server side, use Gson or a similar library to serialize method call parameters and deserialize return values. This ensures that the data is encoded and decoded in a standard format when transmitted over the network.
建立TCP长连接:使用Java的Socket编程,服务端和客户端之间建立持久的TCP长连接,以实现双向通信。Establish a TCP persistent connection: Use Java Socket programming to establish a persistent TCP persistent connection between the server and the client to achieve two-way communication.
服务端提供通用接口:服务端应提供一个通用接口,用于接收远程调用请求。这个接口可以接受请求的方法名、参数和其他调用信息,然后按照协议定义执行远程调用的逻辑。The server provides a common interface: The server should provide a common interface for receiving remote call requests. This interface can accept the method name, parameters and other call information of the request, and then execute the logic of the remote call according to the protocol definition.
客户端调用服务端方法:客户端通过建立的TCP连接向服务端发送远程调用请求,将方法名和参数进行序列化后发送给服务端。The client calls the server method: The client sends a remote call request to the server through the established TCP connection, and serializes the method name and parameters and sends them to the server.
服务端处理远程调用请求:服务端接收客户端的请求后,根据请求中的方法名和参数执行对应的方法。然后将方法的返回值进行序列化后发送回客户端。The server processes the remote call request: After receiving the client's request, the server executes the corresponding method according to the method name and parameters in the request. Then the return value of the method is serialized and sent back to the client.
客户端接收和处理结果:客户端接收服务端的响应,对其进行反 序列化,得到方法的返回值,最后将其返回给调用方。Client receives and processes the result: The client receives the response from the server and responds to it. Serialize, get the return value of the method, and finally return it to the caller.
异常处理:如果远程方法执行过程中发生异常,需要将异常信息捕获并序列化后传递给客户端,客户端根据接收到的异常信息来处理异常情况。Exception handling: If an exception occurs during the execution of a remote method, the exception information needs to be captured and serialized and passed to the client. The client handles the exception based on the received exception information.
在其中一些实施例中,保存远程调用源码任务时,服务端使用Javassist将其动态编译成字节码文件,使用任务名和版本号作为类名,编译出的字节码存放到服务端文件系统。In some of the embodiments, when saving a remote call source code task, the server uses Javassist to dynamically compile it into a bytecode file, uses the task name and version number as the class name, and stores the compiled bytecode in the server file system.
在其中一些实施例中,服务端保存远程调用源码的版本历史到数据库,做源码级别的版本控制。In some of the embodiments, the server saves the version history of the remote call source code to a database to perform source code level version control.
需要说明的是,动态扩展性:使用Javassist动态编译源码使得新的远程调用任务可以在不需要重新编译整个应用的情况下添加到系统中,提高了系统的可扩展性,允许动态引入新功能。通过将任务名和版本号作为类名,服务端能够防止重复的任务名称,使得不同版本的任务可以共存。这允许在系统中支持多个不同版本的任务,从而确保兼容性和平滑升级。由于不需要重新部署或编译整个应用,动态编译的任务可以在运行时立即生效。这使得开发人员可以更迅速地调整远程调用任务而不中断正在运行的系统。将远程调用源码的版本历史保存到数据库,并进行源码级别的版本控制,使得系统能够跟踪远程调用任务的演化。这有助于了解每个任务版本的修改记录,便于排查问题和回滚到以前的版本。通过将远程调用任务版本的历史记录保存到数据库,管理员可以更好地管理和维护不同版本的任务。这对于系统的稳定性和可维护性非常重要。源码级别的版本控制允许在运行时灵活切换任务的版本,从而规避了动态扩展可能引入的线上风险,确保系统的稳定性。It should be noted that dynamic scalability: Using Javassist to dynamically compile source code allows new remote call tasks to be added to the system without recompiling the entire application, which improves the scalability of the system and allows new features to be introduced dynamically. By using the task name and version number as the class name, the server can prevent duplicate task names so that tasks of different versions can coexist. This allows multiple different versions of tasks to be supported in the system, ensuring compatibility and smooth upgrades. Since there is no need to redeploy or compile the entire application, dynamically compiled tasks can take effect immediately at runtime. This allows developers to adjust remote call tasks more quickly without interrupting the running system. The version history of the remote call source code is saved to the database, and source code-level version control is performed, so that the system can track the evolution of remote call tasks. This helps to understand the modification records of each task version, facilitates troubleshooting and rollback to previous versions. By saving the history of remote call task versions to the database, administrators can better manage and maintain different versions of tasks. This is very important for the stability and maintainability of the system. Source code-level version control allows flexible switching of task versions at runtime, thereby avoiding online risks that may be introduced by dynamic expansion and ensuring the stability of the system.
优选地,本实施例基于Netty框架开发一套C/S架构的基础框架,客户端通过TCP长连接和服务端通信,服务端持有客户端的会话信息;基于TCP长连接实现一套应用层的远程调用协议,提供服务端调用客户端上指定任务的通用接口,使用Gson工具名作为序列化/反序列化工具处理参数和返回值;服务端的管理台为采用 springboot+mybatis-plus+vue开发的WEB管理系统,提供界面用于维护Java源码类型的远程调用任务,具有增删改查的功能;系统提供约定的远程调用接口,包括远程调用的方法、参数、返回值和异常,远程调用任务只能基于该接口编写实现方法;保存远程调用源码任务时,服务端会使用Javassist将其动态编译成字节码文件,使用任务名和版本号作为类名来避免重复,编译出的字节码存放到服务端文件系统;服务端保存远程调用源码的版本历史到数据库,对其做源码级别的版本控制;服务端使用远程任务的ID、版本号和业务数据作为参数,发起对指定客户端的远程调用(基于2中的协议);客户端创建自定义ClassLoader根据任务ID和版本号参数从服务端加载远程调用实现类的字节码,再通过Java反射机制实例化远程调用对象,并强制转型为约定的远程调用接口;客户端执行远程调用对象的接口方法,再通过远程调用协议返回调用结果到服务端;客户端根据远程调用ID和版本号缓存远程调用实现类的字节码到本地,以加快程序运行效率。Preferably, this embodiment develops a basic framework of C/S architecture based on Netty framework. The client communicates with the server through TCP long connection, and the server holds the client's session information. A set of application layer remote call protocols is implemented based on TCP long connection, providing a general interface for the server to call the specified task on the client, and using Gson tool name as the serialization/deserialization tool to process parameters and return values; the management console of the server adopts The WEB management system developed by springboot+mybatis-plus+vue provides an interface for maintaining remote call tasks of Java source code type, with the functions of adding, deleting, modifying and checking; the system provides an agreed remote call interface, including remote call methods, parameters, return values and exceptions, and remote call tasks can only be implemented based on this interface; when saving remote call source code tasks, the server will use Javassist to dynamically compile them into bytecode files, use the task name and version number as the class name to avoid duplication, and store the compiled bytecode in the server file system; the server saves the version history of the remote call source code to the database, It performs version control at the source code level; the server uses the remote task ID, version number and business data as parameters to initiate a remote call to the specified client (based on the protocol in 2); the client creates a custom ClassLoader to load the bytecode of the remote call implementation class from the server according to the task ID and version number parameters, and then instantiates the remote call object through the Java reflection mechanism and forces it to transform into the agreed remote call interface; the client executes the interface method of the remote call object, and then returns the call result to the server through the remote call protocol; the client caches the bytecode of the remote call implementation class locally according to the remote call ID and version number to speed up the program running efficiency.
另一方面,本发明实施例还提供了一种基于Java动态字节码的远程调用动态扩展系统,包括:On the other hand, an embodiment of the present invention further provides a remote call dynamic expansion system based on Java dynamic bytecode, comprising:
服务端管理台,基于Web管理系统提供界面用于维护Java源码类型的远程调用任务,并且具有增删改查的功能;The server management console provides an interface based on the Web management system for maintaining remote call tasks of Java source code type, and has the functions of adding, deleting, modifying and checking;
服务端界面,提供Web界面,通过Web界面定义和管理远程任务;The server interface provides a web interface for defining and managing remote tasks;
Javassist编译器,基于Javassist将通过服务端界面定义的Java源码类型的远程任务动态编译为字节码,字节码将被保存在服务端;Javassist compiler, based on Javassist, dynamically compiles remote tasks of Java source code type defined through the server interface into bytecode, which will be saved on the server;
远程调用协议,基于TCP长连接实现应用层的远程调用协议,用于服务端调用客户端上指定任务的通用接口;远程调用协议使用Gson作为序列化/反序列化工具来处理参数和返回值;Remote call protocol, which implements the application layer remote call protocol based on TCP long connection, is a general interface for the server to call the specified task on the client; the remote call protocol uses Gson as a serialization/deserialization tool to process parameters and return values;
远程调用接口,提供约定的远程调用接口,包括远程调用的方法、参数、返回值和异常,远程调用任务只能基于远程调用接口编写实现方法;Remote call interface, which provides the agreed remote call interface, including the remote call method, parameters, return value and exception. The remote call task can only be implemented by writing the implementation method based on the remote call interface.
自定义ClassLoader,被客户端创建,根据远程调用任务的ID和版本号从服务端动态加载远程任务字节码,并生成Java类。 The custom ClassLoader is created by the client, dynamically loads the remote task bytecode from the server according to the ID and version number of the remote call task, and generates a Java class.
具体而言,如图2所示,承担任务管理的服务端其具备:任务定义、任务测试、任务编译、版本控制、任务发布与远程调用功能;承担任务执行的客户端具备:任务更新、任务加载、任务缓存与任务执行功能。Specifically, as shown in Figure 2, the server responsible for task management has the following functions: task definition, task testing, task compilation, version control, task publishing and remote calling; the client responsible for task execution has the following functions: task update, task loading, task caching and task execution.
需要说明的是,该系统允许在运行时动态添加、修改和删除远程调用任务,而无需重新编译或部署整个应用程序。这提供了极大的灵活性和动态扩展性,允许系统随着需求的变化而变化。通过提供Web界面,开发人员和管理员可以轻松地管理和配置远程调用任务,包括定义、编辑、删除和查询任务。这简化了任务管理过程,减少了开发和维护的复杂性。自定义ClassLoader可根据任务的ID和版本号从服务端加载远程任务字节码。客户端通过Java反射机制实例化远程调用对象,这提供了更高的性能,因为字节码的本地执行比其他方式更快。使用Gson作为序列化/反序列化工具来处理参数和返回值,使得数据传输更高效,而且允许不同版本的任务使用相同的协议进行通信。通过提供远程调用接口,约定了远程调用任务的方法、参数、返回值和异常,从而确保任务的一致性和可互操作性。版本控制允许系统维护不同任务版本的历史记录,这有助于问题排查、回滚和维护。服务端的管理台基于Web管理系统提供了用户友好的界面,使任务的创建和管理变得更加容易。管理员可以轻松地查看、修改和监控任务。源码级别的版本控制允许在运行时灵活切换任务的版本,从而规避了动态扩展可能引入的线上风险,确保系统的稳定性。It should be noted that the system allows remote call tasks to be dynamically added, modified, and deleted at runtime without recompiling or deploying the entire application. This provides great flexibility and dynamic scalability, allowing the system to change as needs change. By providing a web interface, developers and administrators can easily manage and configure remote call tasks, including defining, editing, deleting, and querying tasks. This simplifies the task management process and reduces the complexity of development and maintenance. Custom ClassLoader can load remote task bytecode from the server based on the task ID and version number. The client instantiates the remote call object through the Java reflection mechanism, which provides higher performance because the local execution of bytecode is faster than other methods. Using Gson as a serialization/deserialization tool to handle parameters and return values makes data transmission more efficient and allows different versions of tasks to communicate using the same protocol. By providing a remote call interface, the methods, parameters, return values, and exceptions of remote call tasks are agreed upon, thereby ensuring the consistency and interoperability of tasks. Version control allows the system to maintain a history of different task versions, which helps troubleshooting, rollback, and maintenance. The management console on the server provides a user-friendly interface based on the web management system, making it easier to create and manage tasks. Administrators can easily view, modify, and monitor tasks. Source code-level version control allows flexible switching of task versions at runtime, thereby avoiding online risks that may be introduced by dynamic expansion and ensuring system stability.
以上所述仅为本发明的一个实施例子,但不能以此限制本发明的范围,凡依据本发明所做的结构上的变化,只要不失本发明的要义所在,都应视为落入本发明保护范围之内受到制约。The above is only an example of implementation of the present invention, but it cannot be used to limit the scope of the present invention. Any structural changes made according to the present invention should be regarded as falling within the protection scope of the present invention and subject to restrictions as long as they do not lose the essence of the present invention.
需要说明的是,上述实施例提供的系统,仅以上述各功能模块的划分进行举例说明,在实际应用中,可以根据需要而将上述功能分配由不同的功能模块来完成,即将本发明实施例中的模块或者步骤再分解或者组合,例如,上述实施例的模块可以合并为一个模块,也可以进一步拆分成多个子模块,以完成以上描述的全部或者部分功能。对 于本发明实施例中涉及的模块、步骤的名称,仅仅是为了区分各个模块或者步骤,不视为对本发明的不当限定。It should be noted that the system provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the modules or steps in the embodiments of the present invention can be decomposed or combined. For example, the modules in the above embodiment can be combined into one module, or further divided into multiple sub-modules to complete all or part of the functions described above. The names of the modules and steps involved in the embodiments of the present invention are only for distinguishing each module or step and are not to be regarded as improper limitations of the present invention.
术语“包括”或者任何其它类似用语旨在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备/装置不仅包括那些要素,而且还包括没有明确列出的其它要素,或者还包括这些过程、方法、物品或者设备/装置所固有的要素。The term "comprise" or any other similar term is intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus/device that includes a list of elements includes not only those elements but also other elements not expressly listed, or also includes elements inherent to such process, method, article, or apparatus/device.
至此,已经结合附图所示的优选实施方式描述了本发明的技术方案,但是,本领域技术人员容易理解的是,本发明的保护范围显然不局限于这些具体实施方式。在不偏离本发明的原理的前提下,本领域技术人员可以对相关技术特征作出等同的更改或替换,这些更改或替换之后的技术方案都将落入本发明的保护范围之内。So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.
以上所述,仅为本发明的较佳实施例而已,并非用于限定本发明的保护范围。 The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention.
Claims (10)
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311710213.9A CN117851087B (en) | 2023-12-13 | 2023-12-13 | Java dynamic byte code-based remote call dynamic extension method |
| CN202311710213.9 | 2023-12-13 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2024212612A1 true WO2024212612A1 (en) | 2024-10-17 |
Family
ID=90531163
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2023/143141 Pending WO2024212612A1 (en) | 2023-12-13 | 2023-12-29 | Remote invocation dynamic extension method based on dynamic java bytecode |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN117851087B (en) |
| WO (1) | WO2024212612A1 (en) |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6385661B1 (en) * | 1998-10-19 | 2002-05-07 | Recursion Software, Inc. | System and method for dynamic generation of remote proxies |
| CN111338770A (en) * | 2020-02-12 | 2020-06-26 | 咪咕文化科技有限公司 | A task scheduling method, server and computer-readable storage medium |
| CN111736916A (en) * | 2020-06-08 | 2020-10-02 | 北京达佳互联信息技术有限公司 | Java language-based dynamic extension method, device, electronic device and storage medium |
| CN112035276A (en) * | 2020-08-06 | 2020-12-04 | 上海视云网络科技有限公司 | A Java-based Cross-Platform Extensible RPC Framework Design Method |
| CN116501348A (en) * | 2023-04-11 | 2023-07-28 | 北京三维天地科技股份有限公司 | Method for thermally updating java code based on java virtual machine |
Family Cites Families (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6629128B1 (en) * | 1999-11-30 | 2003-09-30 | Recursion Software, Inc. | System and method for distributed processing in a computer network |
| CN112445466A (en) * | 2019-09-02 | 2021-03-05 | 无锡江南计算技术研究所 | Method for dynamically encapsulating local methods as services |
| CN115718588B (en) * | 2022-11-21 | 2025-11-21 | 中科云谷科技有限公司 | Method, device, storage medium and processor for publishing network service |
| CN117056103A (en) * | 2023-09-14 | 2023-11-14 | 浪潮通用软件有限公司 | Remote calling method, system, equipment and medium |
-
2023
- 2023-12-13 CN CN202311710213.9A patent/CN117851087B/en active Active
- 2023-12-29 WO PCT/CN2023/143141 patent/WO2024212612A1/en active Pending
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6385661B1 (en) * | 1998-10-19 | 2002-05-07 | Recursion Software, Inc. | System and method for dynamic generation of remote proxies |
| CN111338770A (en) * | 2020-02-12 | 2020-06-26 | 咪咕文化科技有限公司 | A task scheduling method, server and computer-readable storage medium |
| CN111736916A (en) * | 2020-06-08 | 2020-10-02 | 北京达佳互联信息技术有限公司 | Java language-based dynamic extension method, device, electronic device and storage medium |
| CN112035276A (en) * | 2020-08-06 | 2020-12-04 | 上海视云网络科技有限公司 | A Java-based Cross-Platform Extensible RPC Framework Design Method |
| CN116501348A (en) * | 2023-04-11 | 2023-07-28 | 北京三维天地科技股份有限公司 | Method for thermally updating java code based on java virtual machine |
Also Published As
| Publication number | Publication date |
|---|---|
| CN117851087A (en) | 2024-04-09 |
| CN117851087B (en) | 2025-10-31 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US8443347B2 (en) | Translating declarative models | |
| US5764982A (en) | Peer-to-peer communication interface | |
| US8862756B2 (en) | Apparatus, system, and method for facilitating data flow between a first application programming interface and a second application programming interface | |
| US6549955B2 (en) | System and method for dynamic generation of remote proxies | |
| US7885978B2 (en) | Systems and methods to facilitate utilization of database modeling | |
| CN102187313B (en) | Caching runtime generated code | |
| US6871223B2 (en) | System and method for agent reporting in to server | |
| US8261248B2 (en) | System and method of executing a dynamic program in a structured environment | |
| CN113688186B (en) | Intelligent contract execution method, engine and block link point | |
| EP0972258A1 (en) | Java-to-database connectivity server | |
| JP2003058517A (en) | System for enabling transaction-based service utilizing non-transactional resource | |
| US20080271004A1 (en) | Computer-implemented method, system, and program product for optimizing a distributed application | |
| JPH10512079A (en) | Object-oriented method maintenance mechanism that does not require stopping the computer system or its programs | |
| CN102664952B (en) | Method for managing and monitoring embedded equipment cluster | |
| CN117632372A (en) | Helm-based continuous deployment management method | |
| CN117851513A (en) | A lock-free distributed data high-concurrency processing framework system based on Redis | |
| JP2000194631A (en) | Communication agent between the information processing system manager and at least one resource | |
| WO2024212612A1 (en) | Remote invocation dynamic extension method based on dynamic java bytecode | |
| US8260850B2 (en) | Thin-client and distributed development using data programming | |
| CN1381004A (en) | Method and apparatus for dynamic commmand extensibility in intelligent agent | |
| CN106844156A (en) | WCF communication informations hold-up interception method in intelligent building comprehensive management platform system | |
| JP2001084133A (en) | Skeleton and stub with rmi communication log function, method for generating them and rmi communication method using them | |
| Skopp | Low bandwidth operation in a multi-user software development environment | |
| CN119576880A (en) | Data processing method, device, equipment and medium based on Flink engine | |
| Golomshtok | . NET Framework and Windows Management Instrumentation |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 23932882 Country of ref document: EP Kind code of ref document: A1 |