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

View File

@ -19,9 +19,9 @@ public class RemoteImpl implements Remote {
@Override @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); System.out.println(v);
} }
Output out = new Output(); Output out = new Output();
@ -32,8 +32,14 @@ public class RemoteImpl implements Remote {
} }
@Override @Override
public Output add(String type, String id) throws JsonProcessingException { public Output add(Input input) throws JsonProcessingException {
return null; 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 @Override
@ -53,26 +59,26 @@ public class RemoteImpl implements Remote {
} }
@Override @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) { if(crawler == null) {
System.out.println(type + "_crawler == null"); System.out.println(input.getName() + "_crawler == null");
return null;
} else { } 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 @Override
public Output remove(String type, String id) throws JsonProcessingException { public Output remove(Input input) throws JsonProcessingException {
return null; 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. * Created by root on 17. 4. 6.
*/ */
public class Input { public class Input {
private String ip; private String name;
private String port; private String id;
private byte[] Data; private String[] paths;
public String getIp() { public String getName() {
return ip; return name;
} }
public void setIp(String ip) { public void setName(String name) {
this.ip = ip; this.name = name;
} }
public String getPort() { public String getId() {
return port; return id;
} }
public void setPort(String port) { public void setId(String id) {
this.port = port; this.id = id;
} }
public byte[] getData() { public String[] getPaths() {
return Data; return paths;
} }
public void setData(byte[] data) { public void setPaths(String[] paths) {
Data = data; this.paths = paths;
} }
} }