Package org.cyclos.impl.utils
Class AbstractPushNotificationHandlerImpl
- java.lang.Object
-
- org.cyclos.impl.utils.AbstractPushNotificationHandlerImpl
-
- All Implemented Interfaces:
PushNotificationHandler
- Direct Known Subclasses:
NoClusterPushNotificationHandlerImpl
public abstract class AbstractPushNotificationHandlerImpl extends Object implements PushNotificationHandler
Base implementation forPushNotificationHandlers
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.logging.log4j.LoggerLOG
-
Constructor Summary
Constructors Constructor Description AbstractPushNotificationHandlerImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidaddMissedEvent(PushNotificationListenerSubscription subscription, PushNotificationEvent<?> event)Enqueues a missed event for the given subscriptionprotected abstract voidclearMissedEvents(PushNotificationListenerSubscription subscription)Removes any queued missing events for the given subscriptionprotected abstract StringdoSubscribe(String clientId, PushNotificationSubscriptionMatcher matcher, Consumer<PushNotificationEvent<?>> listener)Must be implemented in order to physically subscribe an event listenerprotected abstract LonggetCloseAfter(PushNotificationListenerSubscription subscription)Returns the time in millis after which the given subscription will be closedprotected abstract ExecutorServicegetExecutorService()longgetExpirationOffset()Returns the expiration offset after which a subscription marked as timed out will really expire and be closedprotected abstract Collection<PushNotificationEvent<?>>getMissedEvents(PushNotificationListenerSubscription subscription)Returns the events that were missed on the given subscriptionprotected abstract PushNotificationListenerSubscriptiongetSubscription(String subId)Must be implemented in order to return details of a subscription for the given id.protected abstract StringgetSubscriptionIdForClientId(String clientId)Must be implemented to return the subscription id associated with the given client idprotected abstract booleanhasMatchingSubscriptions(PushNotificationEventContext<?> context)Must be implemented to return the matching subscriptions for a contextprotected booleanisActuallyExpired(PushNotificationListenerSubscription subscription)Returns whether the given subscription is actually expired, which means, already marked as timed out, and also with thegetExpirationOffset()elapsedbooleanisTimedOut(PushNotificationListenerSubscription subscription)protected abstract StringnewEventId()Must be implemented to generate an event idprotected abstract voidpost(PushNotificationEvent<?> event)Must be implemented to physically post the eventprotected voidprocessEvent(PushNotificationListenerSubscription subscription, PushNotificationEvent<?> event, Consumer<PushNotificationEvent<?>> listener)<T> booleanpublish(PushNotificationEventContext<T> context, Supplier<T> dataSupplier)Publishes aPushNotificationEventto a specific user session, calling the supplier and returning if the event is really publishedprotected List<PushNotificationEvent<?>>renew(PushNotificationListenerSubscription subscription)Renew this subscription, returning the missed events for this client idprotected abstract voidsessionInvalidated(String sessionToken)Must be implemented in order to remove all traces of the given session tokenprotected abstract voidsetCloseAfter(PushNotificationListenerSubscription subscription, Long closeAfter)Sets the given subscription to close after a given time in millis, or null if it shouldn't close automaticallyvoidsetExpirationOffset(long expirationOffset)For testing, allow changing the expiration offset after a timeoutprotected voidsetTimedOut(PushNotificationListenerSubscription subscription)Marks a subscription as timeout.Stringsubscribe(String originalClientId, String lastEventId, PushNotificationEventFilter filter, Consumer<PushNotificationEvent<?>> listener)Subscribes a newPushNotificationListenerfor listening events of the given types, for the user expressed in the currentSessionData.voidtimeout(String id)Marks a subscription as timed-out.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.cyclos.impl.utils.PushNotificationHandler
close
-
-
-
-
Method Detail
-
getExpirationOffset
public long getExpirationOffset()
Returns the expiration offset after which a subscription marked as timed out will really expire and be closed
-
isTimedOut
public boolean isTimedOut(PushNotificationListenerSubscription subscription)
-
publish
public final <T> boolean publish(PushNotificationEventContext<T> context, Supplier<T> dataSupplier)
Description copied from interface:PushNotificationHandlerPublishes aPushNotificationEventto a specific user session, calling the supplier and returning if the event is really published- Specified by:
publishin interfacePushNotificationHandler
-
setExpirationOffset
public void setExpirationOffset(long expirationOffset)
For testing, allow changing the expiration offset after a timeout
-
subscribe
public final String subscribe(String originalClientId, String lastEventId, PushNotificationEventFilter filter, Consumer<PushNotificationEvent<?>> listener)
Description copied from interface:PushNotificationHandlerSubscribes a newPushNotificationListenerfor listening events of the given types, for the user expressed in the currentSessionData.- Specified by:
subscribein interfacePushNotificationHandler
-
timeout
public final void timeout(String id)
Description copied from interface:PushNotificationHandlerMarks a subscription as timed-out.- Specified by:
timeoutin interfacePushNotificationHandler- See Also:
ServiceFacade.timeoutSubscription(String)
-
addMissedEvent
protected abstract void addMissedEvent(PushNotificationListenerSubscription subscription, PushNotificationEvent<?> event)
Enqueues a missed event for the given subscription
-
clearMissedEvents
protected abstract void clearMissedEvents(PushNotificationListenerSubscription subscription)
Removes any queued missing events for the given subscription
-
doSubscribe
protected abstract String doSubscribe(String clientId, PushNotificationSubscriptionMatcher matcher, Consumer<PushNotificationEvent<?>> listener)
Must be implemented in order to physically subscribe an event listener
-
getCloseAfter
protected abstract Long getCloseAfter(PushNotificationListenerSubscription subscription)
Returns the time in millis after which the given subscription will be closed
-
getExecutorService
protected abstract ExecutorService getExecutorService()
-
getMissedEvents
protected abstract Collection<PushNotificationEvent<?>> getMissedEvents(PushNotificationListenerSubscription subscription)
Returns the events that were missed on the given subscription
-
getSubscription
protected abstract PushNotificationListenerSubscription getSubscription(String subId)
Must be implemented in order to return details of a subscription for the given id. Returning null means the subscription is not valid
-
getSubscriptionIdForClientId
protected abstract String getSubscriptionIdForClientId(String clientId)
Must be implemented to return the subscription id associated with the given client id
-
hasMatchingSubscriptions
protected abstract boolean hasMatchingSubscriptions(PushNotificationEventContext<?> context)
Must be implemented to return the matching subscriptions for a context
-
isActuallyExpired
protected boolean isActuallyExpired(PushNotificationListenerSubscription subscription)
Returns whether the given subscription is actually expired, which means, already marked as timed out, and also with thegetExpirationOffset()elapsed
-
newEventId
protected abstract String newEventId()
Must be implemented to generate an event id
-
post
protected abstract void post(PushNotificationEvent<?> event)
Must be implemented to physically post the event
-
processEvent
protected void processEvent(PushNotificationListenerSubscription subscription, PushNotificationEvent<?> event, Consumer<PushNotificationEvent<?>> listener)
-
renew
protected List<PushNotificationEvent<?>> renew(PushNotificationListenerSubscription subscription)
Renew this subscription, returning the missed events for this client id
-
sessionInvalidated
protected abstract void sessionInvalidated(String sessionToken)
Must be implemented in order to remove all traces of the given session token
-
setCloseAfter
protected abstract void setCloseAfter(PushNotificationListenerSubscription subscription, Long closeAfter)
Sets the given subscription to close after a given time in millis, or null if it shouldn't close automatically
-
setTimedOut
protected void setTimedOut(PushNotificationListenerSubscription subscription)
Marks a subscription as timeout. It should then queue missed events, because it is expected that the client reconnects after some time.
-
-