use of io.mantisrx.client.SinkConnectionsStatus in project mantis by Netflix.
the class ConnectToNamedJob method main.
public static void main(String[] args) {
// SinkParameters params = new SinkParameters.Builder().withParameter("filter", "windows8").build();
final AtomicLong eventCounter = new AtomicLong(0L);
System.setProperty("log4j.logger.io", "DEBUG");
try {
Args.parse(ConnectToNamedJob.class, args);
} catch (IllegalArgumentException e) {
Args.usage(SubmitEphemeralJob.class);
System.exit(1);
}
Properties properties = new Properties();
System.out.println("propfile=" + propFile);
try (InputStream inputStream = new FileInputStream(propFile)) {
properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
final CountDownLatch latch = new CountDownLatch(1);
MantisSSEJob job = null;
try {
job = new MantisSSEJob.Builder(properties).name(jobName).onConnectionReset(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
System.err.println("Reconnecting due to error: " + throwable.getMessage());
}
}).sinkConnectionsStatusObserver(new Observer<SinkConnectionsStatus>() {
@Override
public void onCompleted() {
System.out.println("ConnectionStatusObserver completed");
}
@Override
public void onError(Throwable e) {
System.err.println("ConnectionStatusObserver error: " + e.getMessage());
}
@Override
public void onNext(SinkConnectionsStatus status) {
System.out.println("ConnectionStatusObserver: receiving from " + status.getRecevingDataFrom() + ", connected to " + status.getNumConnected() + " of " + status.getTotal());
}
}).sinkDataRecvTimeoutSecs(11).buildJobConnector();
} catch (Exception e) {
e.printStackTrace();
}
// try{Thread.sleep(3000);}catch(InterruptedException ie){}
System.out.println("Subscribing now");
Subscription subscription = job.connectAndGet().doOnNext(new Action1<Observable<MantisServerSentEvent>>() {
@Override
public void call(Observable<MantisServerSentEvent> o) {
o.doOnNext(new Action1<MantisServerSentEvent>() {
@Override
public void call(MantisServerSentEvent data) {
logger.info("Got event: + " + data);
latch.countDown();
// if(eventCounter.incrementAndGet()>4)
// throw new RuntimeException("Test exception");
}
}).subscribe();
}
}).doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
logger.error(throwable.getMessage());
}
}).doOnCompleted(new Action0() {
@Override
public void call() {
System.out.println("Completed");
System.exit(0);
}
}).subscribe();
// .subscribe();
try {
boolean await = latch.await(30, TimeUnit.SECONDS);
if (await)
System.out.println("PASSED");
else
System.err.println("FAILED!");
Thread.sleep(5000000);
} catch (InterruptedException e) {
e.printStackTrace();
}
subscription.unsubscribe();
System.out.println("Unsubscribed");
try {
Thread.sleep(80000);
} catch (InterruptedException ie) {
}
System.exit(0);
}
use of io.mantisrx.client.SinkConnectionsStatus in project mantis by Netflix.
the class MantisSSEJobTest method submitAndConnectTest.
// @Test
public void submitAndConnectTest() {
CountDownLatch latch = new CountDownLatch(2);
CountDownLatch connectionStatusReceived = new CountDownLatch(1);
MantisSSEJob job = new MantisSSEJob.Builder(zkProps).name("mantis-examples-sine-function").sinkConnectionsStatusObserver(new Observer<SinkConnectionsStatus>() {
@Override
public void onCompleted() {
// TODO Auto-generated method stub
}
@Override
public void onError(Throwable e) {
// TODO Auto-generated method stub
}
@Override
public void onNext(SinkConnectionsStatus t) {
connectionStatusReceived.countDown();
}
}).onConnectionReset(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
System.err.println("Reconnecting due to error: " + throwable.getMessage());
}
}).onCloseKillJob().buildJobSubmitter();
job.submitAndGet().flatMap((t) -> {
return t.map((mmsse) -> {
return mmsse.getEventAsString();
});
}).take(2).doOnNext((d) -> {
latch.countDown();
}).toBlocking().subscribe((data) -> {
System.out.println("Got data -> " + data);
});
;
try {
latch.await(20, TimeUnit.SECONDS);
connectionStatusReceived.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
fail();
}
}
use of io.mantisrx.client.SinkConnectionsStatus in project mantis by Netflix.
the class MantisSSEJobTest method connectToJobTest.
// @Test
public void connectToJobTest() {
CountDownLatch latch = new CountDownLatch(5);
CountDownLatch connectionStatusReceived = new CountDownLatch(1);
MantisSSEJob job = new MantisSSEJob.Builder(zkProps).name("GroupByIP").sinkConnectionsStatusObserver(new Observer<SinkConnectionsStatus>() {
@Override
public void onCompleted() {
// TODO Auto-generated method stub
}
@Override
public void onError(Throwable e) {
// TODO Auto-generated method stub
}
@Override
public void onNext(SinkConnectionsStatus t) {
connectionStatusReceived.countDown();
}
}).onConnectionReset(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
System.err.println("Reconnecting due to error: " + throwable.getMessage());
}
}).buildJobConnector();
job.connectAndGet().flatMap((t) -> {
return t.map((mmsse) -> {
return mmsse.getEventAsString();
});
}).take(5).doOnNext((d) -> {
latch.countDown();
}).toBlocking().subscribe((data) -> {
System.out.println("Got data -> " + data);
});
;
try {
latch.await(10, TimeUnit.SECONDS);
connectionStatusReceived.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
fail();
}
}
Aggregations