JAVA Json RPC
This commit is contained in:
snoop 2017-04-10 19:26:11 +09:00
parent fca62deb01
commit 19b1026379
3 changed files with 47 additions and 40 deletions

View File

@ -6,6 +6,7 @@ import com.googlecode.jsonrpc4j.JsonRpcMethod;
import com.googlecode.jsonrpc4j.JsonRpcService;
import com.loafle.rpc.crawler.Crawler;
import com.loafle.rpc.model.Input;
import com.loafle.rpc.model.Output;
@ -14,22 +15,22 @@ import com.loafle.rpc.model.Output;
@JsonRpcService("/rpc")
public interface Remote {
@JsonRpcMethod("RPC.init")
Output init(String[] paths) throws JsonProcessingException;
@JsonRpcMethod("RPC.Init")
Output init(Input input) throws JsonProcessingException;
@JsonRpcMethod("RPC.add")
Output add(String type, String id) throws JsonProcessingException ;
@JsonRpcMethod("RPC.Add")
Output add(Input input) throws JsonProcessingException ;
// @JsonRpcMethod("Remote.remove")
int addDelegate(String name , Crawler crawler);
@JsonRpcMethod("RPC.get")
Output get(String type, String id) throws JsonProcessingException;
@JsonRpcMethod("RPC.Get")
Output get(Input input) throws JsonProcessingException;
@JsonRpcMethod("RPC.remove")
Output remove(String type, String id) throws JsonProcessingException;
@JsonRpcMethod("RPC.Remove")
Output remove(Input input) throws JsonProcessingException;
}

View File

@ -19,9 +19,9 @@ public class RemoteImpl implements Remote {
@Override
public Output init(String[] paths) throws JsonProcessingException {
public Output init(Input input) throws JsonProcessingException {
for (String v : paths) {
for (String v : input.getPaths()) {
System.out.println(v);
}
Output out = new Output();
@ -32,8 +32,14 @@ public class RemoteImpl implements Remote {
}
@Override
public Output add(String type, String id) throws JsonProcessingException {
return null;
public Output add(Input input) throws JsonProcessingException {
Crawler crawler = this.crawlerMap.get(input.getName());
if(crawler == null) {
System.out.println(input.getName() + "_crawler == null");
return null;
} else {
return crawler.add(input.getId());
}
}
@Override
@ -53,26 +59,26 @@ public class RemoteImpl implements Remote {
}
@Override
public Output get(String type, String id) throws JsonProcessingException {
public Output get(Input input) throws JsonProcessingException {
Crawler crawler = this.crawlerMap.get(type);
Crawler crawler = this.crawlerMap.get(input.getName());
if(crawler == null) {
System.out.println(type + "_crawler == null");
System.out.println(input.getName() + "_crawler == null");
return null;
} else {
return crawler.get(id);
return crawler.get(input.getId());
}
System.out.println("type : " + type);
System.out.println("id : " + id);
Output out = new Output();
out.setStartDate(new Date());
out.setEndDate(new Date());
out.setData("Not Delegate".getBytes());
return out;
}
@Override
public Output remove(String type, String id) throws JsonProcessingException {
return null;
public Output remove(Input input) throws JsonProcessingException {
Crawler crawler = this.crawlerMap.get(input.getName());
if(crawler == null) {
System.out.println(input.getName() + "_crawler == null");
return null;
} else {
return crawler.remove(input.getId());
}
}
}

View File

@ -4,31 +4,31 @@ package com.loafle.rpc.model;
* Created by root on 17. 4. 6.
*/
public class Input {
private String ip;
private String port;
private byte[] Data;
private String name;
private String id;
private String[] paths;
public String getIp() {
return ip;
public String getName() {
return name;
}
public void setIp(String ip) {
this.ip = ip;
public void setName(String name) {
this.name = name;
}
public String getPort() {
return port;
public String getId() {
return id;
}
public void setPort(String port) {
this.port = port;
public void setId(String id) {
this.id = id;
}
public byte[] getData() {
return Data;
public String[] getPaths() {
return paths;
}
public void setData(byte[] data) {
Data = data;
public void setPaths(String[] paths) {
this.paths = paths;
}
}