handle err

This commit is contained in:
insanity 2017-05-18 13:41:53 +09:00
parent 4283748b71
commit 21082796ac
2 changed files with 13 additions and 9 deletions

View File

@ -52,7 +52,7 @@
<dependency> <dependency>
<groupId>com.loafle.overflow</groupId> <groupId>com.loafle.overflow</groupId>
<artifactId>crawler_sql</artifactId> <artifactId>crawler_sql</artifactId>
<version>1.0.1-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,6 +1,7 @@
package com.loafle.overflow; package com.loafle.overflow;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import com.loafle.overflow.crawler.Crawler;
import com.loafle.overflow.crawler.jmx.JmxCrawler; import com.loafle.overflow.crawler.jmx.JmxCrawler;
import com.loafle.overflow.crawler.mongo.MongoCrawler; import com.loafle.overflow.crawler.mongo.MongoCrawler;
import com.loafle.overflow.crawler.redis.RedisCralwer; import com.loafle.overflow.crawler.redis.RedisCralwer;
@ -10,10 +11,11 @@ import com.loafle.overflow.crawler.wmi.WMICrawler;
import com.loafle.overflow.rpc.*; import com.loafle.overflow.rpc.*;
import io.grpc.ServerBuilder; import io.grpc.ServerBuilder;
import io.grpc.stub.StreamObserver; import io.grpc.stub.StreamObserver;
import com.loafle.overflow.crawler.Crawler;
import java.io.*; import java.io.ByteArrayOutputStream;
import java.lang.Boolean; import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -102,6 +104,7 @@ public class Server {
responseObserver.onCompleted(); responseObserver.onCompleted();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
responseObserver.onError(e);
} }
} }
@ -116,18 +119,16 @@ public class Server {
if(crawler != null) { if(crawler != null) {
try { try {
Object obj = crawler.get(req.getId()); Object obj = crawler.get(req.getId());
Output reply = Output.newBuilder() Output reply = Output.newBuilder()
.setData(ByteString.copyFrom((byte[])obj)) .setData(ByteString.copyFrom((byte[])obj))
.setStartDate(333) .setStartDate(0)
.setEndDate(333) .setEndDate(0)
.build(); .build();
responseObserver.onNext(reply); responseObserver.onNext(reply);
responseObserver.onCompleted(); responseObserver.onCompleted();
}catch(Exception e) { }catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
responseObserver.onError(e);
} }
} }
} }
@ -162,6 +163,7 @@ public class Server {
responseObserver.onCompleted(); responseObserver.onCompleted();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
responseObserver.onError(e);
} }
} }
@ -180,6 +182,7 @@ public class Server {
responseObserver.onCompleted(); responseObserver.onCompleted();
}catch(Exception e) { }catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
responseObserver.onError(e);
} }
} }
} }
@ -199,6 +202,7 @@ public class Server {
responseObserver.onCompleted(); responseObserver.onCompleted();
}catch(Exception e) { }catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
responseObserver.onError(e);
} }
} }
} }