Skip to content

Commit 5326c06

Browse files
feat: Support event with long polling (box/box-codegen#807) (#1409)
1 parent 2f2a375 commit 5326c06

File tree

12 files changed

+934
-2
lines changed

12 files changed

+934
-2
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "aa448e3", "specHash": "ec8720b", "version": "0.1.0" }
1+
{ "engineHash": "fa469c0", "specHash": "ec8720b", "version": "0.1.0" }

docs/EventStream.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Event Stream
2+
3+
The Event Stream class utilizes long-polling to receive real-time events from Box. The SDK provides an easy way to set up and manage the event stream which returns an iterable object and yields events as they are received.
4+
5+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
6+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
7+
8+
- [Event Stream](#event-stream)
9+
- [Listening to the Event Stream](#listening-to-the-event-stream)
10+
- [Deduplication](#deduplication)
11+
12+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
13+
14+
## Listening to the Event Stream
15+
16+
When the `EventStream` is started, it will begin long-polling asynchronously. Events received from the API are then yielded to the caller.
17+
18+
```java
19+
EventStream stream = client.getEvents().getEventStream();
20+
for (Event event : stream) {
21+
System.out.printf(
22+
"Received event: ID=%s, Type=%s, CreatedAt=%s%n\n",event.getEventId(),event.getEventType(),event.getCreatedAt());
23+
}
24+
25+
```
26+
27+
## Deduplication
28+
29+
The `EventStream` class automatically deduplicates events based on their `eventId`. This means that if the same event is received multiple times, it will only be emitted once to the listeners.

docs/events.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
- [Get events long poll endpoint](#get-events-long-poll-endpoint)
55
- [List user and enterprise events](#list-user-and-enterprise-events)
6+
- [Get event stream](#get-event-stream)
67

78
## Get events long poll endpoint
89

@@ -107,3 +108,30 @@ chunk, as well as the next `stream_position` that can be
107108
queried.
108109

109110

111+
## Get event stream
112+
113+
Get an event stream for the Box API
114+
115+
This operation is performed by calling function `getEventStream`.
116+
117+
118+
119+
```
120+
client.getEvents().getEventStream()
121+
```
122+
123+
### Arguments
124+
125+
- queryParams `GetEventStreamQueryParams`
126+
- Query parameters of getEvents method
127+
- headers `GetEventStreamHeaders`
128+
- Headers of getEvents method
129+
130+
131+
### Returns
132+
133+
This function returns a value of type `EventStream`.
134+
135+
136+
137+

migration-guides/from-box-java-sdk-gen-v0-to-box-java-sdk-v10.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Migration guide from beta release (v0.8.0) of the `box-java-sdk-gen` to the v10 version of the `box-java-sdk`
1+
# Migration guide from beta release (v0.X.Y) of the `box-java-sdk-gen` to the v10 version of the `box-java-sdk`
22

33
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
44
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -92,6 +92,7 @@ List of changed `OneOf` classes and types associated with them:
9292
| FileMiniOrFolderMini | Resource |
9393
| FileOrFolderOrWebLink | LegalHoldPolicyAssignedItem/CollaborationItem |
9494
| FileOrFolderScope | ResourceScope |
95+
| FileOrFolderScopeScopeField | ResourceScopeScopeField |
9596
| FileReferenceOrFolderReferenceOrWeblinkReferenceV2025R0 | HubItemReferenceV2025R0 |
9697
| GroupMiniOrUserCollaborations | CollaborationAccessGrantee |
9798
| IntegrationMappingPartnerItemSlackUnion | IntegrationMappingPartnerItemSlack |
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.box.sdkgen.box.eventstream;
2+
3+
import com.box.sdkgen.managers.events.EventsManager;
4+
import com.box.sdkgen.managers.events.GetEventStreamHeaders;
5+
import com.box.sdkgen.managers.events.GetEventStreamQueryParams;
6+
import com.box.sdkgen.schemas.event.Event;
7+
import java.util.Iterator;
8+
9+
public class EventStream implements Iterable<Event> {
10+
11+
EventStreamIterator iterator;
12+
13+
private EventStream(Builder builder) {
14+
this.iterator =
15+
new EventStreamIterator(builder.eventsManager, builder.queryParams, builder.headersInput);
16+
}
17+
18+
@Override
19+
public Iterator<Event> iterator() {
20+
return this.iterator;
21+
}
22+
23+
public void stop() {
24+
this.iterator.stop();
25+
}
26+
27+
public static class Builder {
28+
final EventsManager eventsManager;
29+
final GetEventStreamQueryParams queryParams;
30+
GetEventStreamHeaders headersInput;
31+
32+
public Builder(EventsManager eventsManager, GetEventStreamQueryParams queryParams) {
33+
this.eventsManager = eventsManager;
34+
this.queryParams = queryParams;
35+
this.headersInput = new GetEventStreamHeaders();
36+
}
37+
38+
public Builder headersInput(GetEventStreamHeaders headersInput) {
39+
this.headersInput = headersInput != null ? headersInput : new GetEventStreamHeaders();
40+
return this;
41+
}
42+
43+
public EventStream build() {
44+
return new EventStream(this);
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)