vaadin / collaboration-engine

The simplest way to build real-time collaboration into web apps
https://vaadin.com/collaboration
Other
3 stars 1 forks source link

Add expiration timeout API to CollaborationBinder #24

Closed pekam closed 3 years ago

pekam commented 3 years ago

To solve #23, the following API was added to CollaborationMap:

void setExpirationTimeout(Duration expirationTimeout);
Optional<Duration> getExpirationTimeout();

It enables setting a timeout after the last connection to the topic when the map should be cleared. E.g. to clear the edited values in a collaborative form after no one has been editing it for 15 minutes, you can do this:

CollaborationEngine.getInstance().openTopicConnection(this, "topic-id",
        user, topicConnection -> {
            topicConnection
                    .getNamedMap(CollaborationBinder.class.getName())
                    .setExpirationTimeout(Duration.ofMinutes(15));
            return null;
        });

This works, but is not very convenient. We should add the same API directly to CollaborationBinder, so that you could do simply this:

collaborationBinder.setExpirationTimeout(Duration.ofMinutes(15)

Since the same methods are then in two classes, we should create an interface to ensure those are in sync:

interface HasExpirationTimeout {
    void setExpirationTimeout(Duration expirationTimeout);
    Optional<Duration> getExpirationTimeout();
}

and make CollaborationMap and CollaborationBinder implement this interface.

Remember to override the JavaDocs to make sense for each implementer.