mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: define powerjob remote
This commit is contained in:
parent
dc98f5f37a
commit
d3b8c4e353
1
pom.xml
1
pom.xml
@ -44,6 +44,7 @@
|
||||
<module>powerjob-worker-spring-boot-starter</module>
|
||||
<module>powerjob-worker-samples</module>
|
||||
<module>powerjob-official-processors</module>
|
||||
<module>powerjob-remote</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
24
powerjob-remote/pom.xml
Normal file
24
powerjob-remote/pom.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>powerjob</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>3.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>powerjob-remote-framework</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>powerjob-remote</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
30
powerjob-remote/powerjob-remote-framework/pom.xml
Normal file
30
powerjob-remote/powerjob-remote-framework/pom.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>powerjob-remote</artifactId>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<version>3.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>powerjob-remote-framework</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<powerjob-common.version>4.2.0</powerjob-common.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>tech.powerjob</groupId>
|
||||
<artifactId>powerjob-common</artifactId>
|
||||
<version>${powerjob-common.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,21 @@
|
||||
package tech.powerjob.remote.framework.actor;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 行为处理器
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
public @interface Actor {
|
||||
|
||||
/**
|
||||
* root path
|
||||
* @return root path
|
||||
*/
|
||||
String path();
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package tech.powerjob.remote.framework.actor;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Handler
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
public @interface Handler {
|
||||
|
||||
/**
|
||||
* handler path
|
||||
* @return handler path
|
||||
*/
|
||||
String path();
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package tech.powerjob.remote.framework.actor;
|
||||
|
||||
import tech.powerjob.remote.framework.base.HandlerLocation;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* HandlerInfo
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
public class HandlerInfo implements Serializable {
|
||||
|
||||
private HandlerLocation location;
|
||||
/**
|
||||
* handler 对应的方法
|
||||
*/
|
||||
private Method method;
|
||||
/**
|
||||
* actor 对象
|
||||
*/
|
||||
private Object actor;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package tech.powerjob.remote.framework.base;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
public class Address implements Serializable {
|
||||
private String host;
|
||||
private int port;
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package tech.powerjob.remote.framework.base;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* handler location
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
public class HandlerLocation implements Serializable {
|
||||
/**
|
||||
* 根路径
|
||||
*/
|
||||
private String rootPath;
|
||||
/**
|
||||
* 方法路径
|
||||
*/
|
||||
private String methodPath;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package tech.powerjob.remote.framework.base;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* RemotingException
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
public class RemotingException extends IOException {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package tech.powerjob.remote.framework.base;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* URL
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
public class URL implements Serializable {
|
||||
/**
|
||||
* remote address
|
||||
*/
|
||||
private Address address;
|
||||
|
||||
/**
|
||||
* location
|
||||
*/
|
||||
private HandlerLocation location;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package tech.powerjob.remote.framework.cs;
|
||||
|
||||
import tech.powerjob.remote.framework.actor.HandlerInfo;
|
||||
import tech.powerjob.remote.framework.transporter.Transporter;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* client & server initializer
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
public interface CSInitializer extends Closeable {
|
||||
|
||||
/**
|
||||
* initialize the framework
|
||||
* @param config config
|
||||
*/
|
||||
void init(CSInitializerConfig config);
|
||||
|
||||
/**
|
||||
* build a Transporter by based network framework
|
||||
* @return Transporter
|
||||
*/
|
||||
Transporter buildTransporter();
|
||||
|
||||
/**
|
||||
* bind Actor, publish handler's service
|
||||
* @param handlerInfos handler infos
|
||||
*/
|
||||
void bindHandlers(List<HandlerInfo> handlerInfos);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package tech.powerjob.remote.framework.cs;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import tech.powerjob.remote.framework.base.Address;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* CSInitializerConfig
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
public class CSInitializerConfig implements Serializable {
|
||||
|
||||
private Address bindAddress;
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* PowerJob 网络框架层
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
package tech.powerjob.remote.framework;
|
@ -0,0 +1,16 @@
|
||||
package tech.powerjob.remote.framework.transporter;
|
||||
|
||||
/**
|
||||
* 通讯协议
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
public interface Protocol {
|
||||
|
||||
/**
|
||||
* 通讯协议名称
|
||||
* @return 协议名称
|
||||
*/
|
||||
String name();
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package tech.powerjob.remote.framework.transporter;
|
||||
|
||||
import tech.powerjob.common.PowerSerializable;
|
||||
import tech.powerjob.remote.framework.base.RemotingException;
|
||||
import tech.powerjob.remote.framework.base.URL;
|
||||
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
/**
|
||||
* 通讯器,封装与远程服务端交互逻辑
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/12/31
|
||||
*/
|
||||
public interface Transporter {
|
||||
|
||||
/**
|
||||
* Protocol
|
||||
* @return return protocol
|
||||
*/
|
||||
Protocol getProtocol();
|
||||
|
||||
/**
|
||||
*send message
|
||||
* @param url url
|
||||
* @param request request
|
||||
*/
|
||||
void tell(URL url, PowerSerializable request);
|
||||
|
||||
/**
|
||||
* ask by request
|
||||
* @param url url
|
||||
* @param request request
|
||||
* @param executorService thread pool, null is acceptable
|
||||
* @return CompletionStage
|
||||
* @throws RemotingException remote exception
|
||||
*/
|
||||
CompletionStage<Object> ask(URL url, PowerSerializable request, ExecutorService executorService) throws RemotingException;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user