- add maven dependency(引入maven依赖)
now version is : 1.0.4
<dependency>
<groupId>cn.lishiyuan</groupId>
<artifactId>jaria2</artifactId>
<version>{jaria2.version}</version>
</dependency>- aria2c start (启动程序)
public static void main(String[]args){
String path = "aria2c";
String[] params = {"--enable-rpc","--rpc-allow-origin-all","--rpc-secret=2089b05ecca3d829"};
Aria2Manager aria2Manager = Aria2Manager.build(path,params);
aria2Manager.start();
System.out.println(aria2Manager.status());
}- send action (客户端发送请求)
public static void main(String[]args){
Aria2Client client = = new DefaultAria2Client("2089b05ecca3d829");
client.addEventProcessor(event->{
System.out.println(event.toJsonString());
});
client.connect();
AddUriAction.AddUriActionResponse response = client.action(new AddUriAction(UUID.randomUUID().toString(),"https://desk-fd.zol-img.com.cn/t_s720x360c5/g7/M00/0A/0D/ChMkK2MoBA6IcIAaAAnmKLET1UwAAHq2wB4jO4ACeZA213.jpg"));
System.out.println(response.toJsonString());
}All in all, jaria2 has two parts: Aria2Manager and Aria2Client.
总的来说,jaria2主要有两个部分组成:Aria2Manager和Aria2Client。
Aria2Manager Aria2Manager is used to start aria2c program, instead of starting the server through command line and so on.
Aria2Manager用来aria2c程序,代替命令行启动服务端等等操作。
Aria2Client Aria2Client is used to interact with the server, which is currently netty + websocket. There are two main features.
Aria2Client是与服务端交互的客户端,目前是netty + websocket。主要有下面两个feature
- Action
action corresponds to method, and I describe it as an action instruction issued by a client to a server.
action对应method,我这里描述为一个客户端向服务端发出的动作指令。
- Event
event corresponds to notification, in which each life cycle node of the download will have a corresponding event trigger.
event对应notification,在下载的各个生命周期节点都会有对应的event触发。
Configuration is concentrated in the Aria2Config class, which also includes two parts: Manager and Client.
配置集中在Aria2Config类里面,它同样包括Manager和Client两部分。 Aria2Config
- Aria2Client
Default implementation is DefaultAria2Client, if you need to customize, implement the Aria2Client interface.
默认实现是DefaultAria2Client,如果需要自定义,实现Aria2Client接口即可。
- EventProcessor
EventProcessor is used to process event, you can add multiple EventProcessor to the client.
EventProcessor用来处理event,可以向client添加多个EventProcessor。
- Action Action is used to send action to server, I have add all Action to the client.
Action用来向服务端发送action,我已经把所有的Action都添加到了client里面。
all action and notification coverage.
所有的action和notification的覆盖情况。
Below are all the events that are already supported, that is, notifications, and the check marks are already tested.
下面是所有的已经支持的事件回调,也就是通知,打钩是已经通过测试的。
- onDownloadStart
- onDownloadError
- onDownloadComplete
- onBtDownloadComplete
- onDownloadStop
- onDownloadPause
below are all the methods that are already supported, that is, actions, and the check marks are already tested.
下面是所有的已经支持的方法,也就是动作,打钩是已经通过测试的。
- listMethods
- listNotifications
- pause
- unpause
- pauseAll
- unpauseAll
- getVersion
- getSessionsInfo
- tellStatus
- tellWaiting
- tellStopped
- tellActive
- addUri
- addTorrent
- addMetalink
- getUris
- getFiles
- getPeers
- getServers
- ForcePause
- ForcePauseAll
- ForceRemove
- ForceShutdown
- Remove
- Shutdown
- SaveSession
- ChangePosition
- ChangeUri
- PurgeDownloadResult
- RemoveDownloadResult
- ChangeGlobalOption
- ChangeOption
- Multicall
- GetOption
- GetGlobalOption
- GetGlobalStat
李干嘛大帅哥