diff --git a/src/main/java/com/loafle/rpc/api/Remote.java b/src/main/java/com/loafle/rpc/api/Remote.java index 8d779fb..331988e 100644 --- a/src/main/java/com/loafle/rpc/api/Remote.java +++ b/src/main/java/com/loafle/rpc/api/Remote.java @@ -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; } \ No newline at end of file diff --git a/src/main/java/com/loafle/rpc/api/RemoteImpl.java b/src/main/java/com/loafle/rpc/api/RemoteImpl.java index 8dccaf1..50e618f 100644 --- a/src/main/java/com/loafle/rpc/api/RemoteImpl.java +++ b/src/main/java/com/loafle/rpc/api/RemoteImpl.java @@ -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()); + } } } \ No newline at end of file diff --git a/src/main/java/com/loafle/rpc/model/Input.java b/src/main/java/com/loafle/rpc/model/Input.java index ecf7439..59ffe0f 100644 --- a/src/main/java/com/loafle/rpc/model/Input.java +++ b/src/main/java/com/loafle/rpc/model/Input.java @@ -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; } }