-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ApplicationService with subscribeToFields to java-client-session #1738
Merged
devinrsmith
merged 2 commits into
deephaven:main
from
devinrsmith:java-client/application-service
Dec 27, 2021
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...client/session-examples/src/main/java/io/deephaven/client/examples/SubscribeToFields.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.deephaven.client.examples; | ||
|
||
import io.deephaven.client.impl.ApplicationService.Cancel; | ||
import io.deephaven.client.impl.ApplicationService.Listener; | ||
import io.deephaven.client.impl.Session; | ||
import io.deephaven.proto.backplane.grpc.FieldInfo; | ||
import io.deephaven.proto.backplane.grpc.FieldsChangeUpdate; | ||
import io.grpc.Status.Code; | ||
import io.grpc.StatusException; | ||
import io.grpc.StatusRuntimeException; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
|
||
@Command(name = "subscribe-fields", mixinStandardHelpOptions = true, | ||
description = "Subscribe to fields", version = "0.1.0") | ||
public final class SubscribeToFields extends SingleSessionExampleBase { | ||
@Override | ||
protected void execute(Session session) throws Exception { | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
final Cancel cancel = session.subscribeToFields(new Listener() { | ||
@Override | ||
public void onNext(FieldsChangeUpdate fields) { | ||
System.out.println("Created: " + fields.getCreatedCount()); | ||
System.out.println("Updated: " + fields.getUpdatedCount()); | ||
System.out.println("Removed: " + fields.getRemovedCount()); | ||
for (FieldInfo fieldInfo : fields.getCreatedList()) { | ||
System.out.println("Created: " + fieldInfo); | ||
} | ||
for (FieldInfo fieldInfo : fields.getUpdatedList()) { | ||
System.out.println("Updated: " + fieldInfo); | ||
} | ||
for (FieldInfo fieldInfo : fields.getRemovedList()) { | ||
System.out.println("Removed: " + fieldInfo); | ||
} | ||
} | ||
|
||
@Override | ||
public void onError(Throwable t) { | ||
if (!isCancelled(t)) { | ||
t.printStackTrace(System.err); | ||
} | ||
latch.countDown(); | ||
} | ||
|
||
@Override | ||
public void onCompleted() { | ||
latch.countDown(); | ||
} | ||
}); | ||
Runtime.getRuntime().addShutdownHook(new Thread(cancel::cancel)); | ||
latch.await(); | ||
} | ||
|
||
private static boolean isCancelled(Throwable t) { | ||
if (t instanceof StatusRuntimeException) { | ||
return ((StatusRuntimeException) t).getStatus().getCode() == Code.CANCELLED; | ||
} else if (t instanceof StatusException) { | ||
return ((StatusException) t).getStatus().getCode() == Code.CANCELLED; | ||
} | ||
return false; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int execute = new CommandLine(new SubscribeToFields()).execute(args); | ||
System.exit(execute); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
java-client/session/src/main/java/io/deephaven/client/impl/ApplicationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.deephaven.client.impl; | ||
|
||
import io.deephaven.proto.backplane.grpc.FieldsChangeUpdate; | ||
|
||
public interface ApplicationService { | ||
|
||
interface Listener { | ||
void onNext(FieldsChangeUpdate fields); | ||
|
||
void onError(Throwable t); | ||
|
||
void onCompleted(); | ||
} | ||
|
||
interface Cancel { | ||
void cancel(); | ||
} | ||
|
||
Cancel subscribeToFields(Listener listener); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems odd that this wasn't required before now, in that it might be a hole in the java-client-session api to not convey this, or this might be a more in-depth example than normally goes in this project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I need to change this to
runtimeOnly
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During your BOM refactoring, the session-examples broke - I haven't dug too deep, but this is the quick fix to get it back working.