return , error type
This commit is contained in:
snoop 2017-04-11 10:41:57 +09:00
parent 19b1026379
commit 0c7ce4655c
8 changed files with 72 additions and 60 deletions

View File

@ -1,4 +1,4 @@
package com.loafle.rpc;
package com.loafle.overflow.rpc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@ -1,4 +1,4 @@
package com.loafle.rpc;
package com.loafle.overflow.rpc;
import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImplExporter;
import org.springframework.context.annotation.Bean;

View File

@ -1,13 +1,13 @@
package com.loafle.rpc.api;
package com.loafle.overflow.rpc.api;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.googlecode.jsonrpc4j.JsonRpcMethod;
import com.googlecode.jsonrpc4j.JsonRpcService;
import com.loafle.rpc.crawler.Crawler;
import com.loafle.overflow.rpc.crawler.Crawler;
import com.loafle.rpc.model.Input;
import com.loafle.rpc.model.Output;
import com.loafle.overflow.rpc.model.Input;
import com.loafle.overflow.rpc.model.Output;
@ -16,21 +16,21 @@ import com.loafle.rpc.model.Output;
public interface Remote {
@JsonRpcMethod("RPC.Init")
Output init(Input input) throws JsonProcessingException;
Output init(Input input) throws Exception;
@JsonRpcMethod("RPC.Add")
Output add(Input input) throws JsonProcessingException ;
Output add(Input input) throws Exception ;
// @JsonRpcMethod("Remote.remove")
int addDelegate(String name , Crawler crawler);
@JsonRpcMethod("RPC.Get")
Output get(Input input) throws JsonProcessingException;
Output get(Input input) throws Exception;
@JsonRpcMethod("RPC.Remove")
Output remove(Input input) throws JsonProcessingException;
Output remove(Input input) throws Exception;
}

View File

@ -1,10 +1,10 @@
package com.loafle.rpc.api;
package com.loafle.overflow.rpc.api;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl;
import com.loafle.rpc.crawler.Crawler;
import com.loafle.rpc.model.Input;
import com.loafle.rpc.model.Output;
import com.loafle.overflow.rpc.crawler.Crawler;
import com.loafle.overflow.rpc.model.Input;
import com.loafle.overflow.rpc.model.Output;
import org.springframework.stereotype.Service;
import java.util.Date;
@ -19,7 +19,7 @@ public class RemoteImpl implements Remote {
@Override
public Output init(Input input) throws JsonProcessingException {
public Output init(Input input) throws Exception {
for (String v : input.getPaths()) {
System.out.println(v);
@ -32,13 +32,18 @@ public class RemoteImpl implements Remote {
}
@Override
public Output add(Input input) throws JsonProcessingException {
public Output add(Input input) throws Exception {
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());
Output out = new Output();
out.setStartDate(new Date());
out.setEndDate(new Date());
out.setData(crawler.add(input.getId()));
return out;
}
}
@ -59,26 +64,35 @@ public class RemoteImpl implements Remote {
}
@Override
public Output get(Input input) throws JsonProcessingException {
public Output get(Input input) throws Exception {
Crawler crawler = this.crawlerMap.get(input.getName());
if(crawler == null) {
System.out.println(input.getName() + "_crawler == null");
return null;
} else {
return crawler.get(input.getId());
Output out = new Output();
out.setStartDate(new Date());
out.setEndDate(new Date());
out.setData(crawler.get(input.getId()));
return out;
}
}
@Override
public Output remove(Input input) throws JsonProcessingException {
public Output remove(Input input) throws Exception {
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());
Output out = new Output();
out.setStartDate(new Date());
out.setEndDate(new Date());
out.setData(crawler.remove(input.getId()));
return out;
}
}
}

View File

@ -0,0 +1,32 @@
package com.loafle.overflow.rpc.crawler;
/**
* Created by root on 17. 4. 10.
*/
public abstract class Crawler {
public Object add(String id) throws Exception {
return null;
}
public abstract Object get(String id) throws Exception ;
public Object getConfig(String id) throws Exception {
return null;
}
public Object init(String config) throws Exception {
return null;
}
public Object remove(String id) throws Exception {
return null;
}
}

View File

@ -1,4 +1,4 @@
package com.loafle.rpc.model;
package com.loafle.overflow.rpc.model;
/**
* Created by root on 17. 4. 6.

View File

@ -1,4 +1,4 @@
package com.loafle.rpc.model;
package com.loafle.overflow.rpc.model;
import java.util.Date;
@ -8,7 +8,7 @@ import java.util.Date;
public class Output {
private Date startDate;
private Date endDate;
private byte[] data;
private Object data;
public Date getStartDate() {
return startDate;
@ -26,11 +26,11 @@ public class Output {
this.endDate = endDate;
}
public byte[] getData() {
public Object getData() {
return data;
}
public void setData(byte[] data) {
public void setData(Object data) {
this.data = data;
}
}

View File

@ -1,34 +0,0 @@
package com.loafle.rpc.crawler;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.loafle.rpc.model.Output;
/**
* Created by root on 17. 4. 10.
*/
public abstract class Crawler {
public Output add(String id) throws JsonProcessingException {
return null;
}
public abstract Output get(String id) throws JsonProcessingException ;
public Output getConfig(String id) throws JsonProcessingException {
return null;
}
public Output init(String config) throws JsonProcessingException {
return null;
}
public Output remove(String id) throws JsonProcessingException {
return null;
}
}