com.ibm.cp4waiops.connectors.sdk.CloudEventStreamObserver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of connectors-sdk Show documentation
Show all versions of connectors-sdk Show documentation
A developer SDK for creating connectors for CP4WAIOps.
package com.ibm.cp4waiops.connectors.sdk;
import java.util.concurrent.atomic.AtomicBoolean;
import io.cloudevents.v1.proto.CloudEvent;
import io.grpc.stub.StreamObserver;
/**
* CloudEventStreamObserver wraps a StreamObserver and tracks if the stream has been closed
*/
public class CloudEventStreamObserver implements StreamObserver {
AtomicBoolean _active;
StreamObserver _decorated;
public CloudEventStreamObserver(StreamObserver decorated) {
this(decorated, new AtomicBoolean(true));
}
/**
* CloudEventStreamObserver constructor
*
* @param decorated
* the stream to wrap
* @param flag
* an atomic boolean initialized to true; will be set to false when the stream stops
*/
public CloudEventStreamObserver(StreamObserver decorated, AtomicBoolean flag) {
_active = flag;
_decorated = decorated;
}
/**
* isActive
*
* @return true if the stream is active, false if it has been closed
*/
public boolean isActive() {
return _active.get();
}
@Override
public void onNext(CloudEvent value) {
_decorated.onNext(value);
}
@Override
public void onError(Throwable t) {
_active.set(false);
_decorated.onError(t);
}
@Override
public void onCompleted() {
_active.set(false);
_decorated.onCompleted();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy