public abstract class BaseWebSocketSettledHandler<T>
extends java.lang.Object
Different implementations can be used depending on payment flow mode.
The class maintains a map of registered event listeners and cleans up itself after related invoice have expired. Regular usage should unregister itself when disconnecting.| Modifier and Type | Field and Description |
|---|---|
protected java.util.concurrent.PriorityBlockingQueue<org.lightningj.paywall.spring.websocket.BaseWebSocketSettledHandler.ExpirableListener> |
expiringListeners
Priority queue of expiring date to paymentHash, in order to cleanup expiring listeners.
|
protected java.util.Map<java.lang.String,T> |
paymentListenerMap
Map of base64 paymentHash to paymentListener
|
| Constructor and Description |
|---|
BaseWebSocketSettledHandler() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
hasPaymentListener(java.lang.String preImageHash)
Method that returns true if related paymentListener is registered.
|
protected abstract void |
registerListener(T listener)
Abstract method to register in related event handler.
|
void |
registerPaymentListener(java.lang.String preImageHash,
long expireDate,
T paymentListener)
Method to register a payment listener to a related preImageHash and expireDate.
|
protected abstract void |
unregisterListener(T listener)
Abstract method to unregister in related event handler.
|
void |
unregisterPaymentListener(java.lang.String preImageHash)
Method that unregister the related payment listener and releases all related resources.
|
protected java.util.Map<java.lang.String,T> paymentListenerMap
protected java.util.concurrent.PriorityBlockingQueue<org.lightningj.paywall.spring.websocket.BaseWebSocketSettledHandler.ExpirableListener> expiringListeners
public void registerPaymentListener(java.lang.String preImageHash,
long expireDate,
T paymentListener)
throws InternalErrorException
preImageHash - the related preImageHash in Base64expireDate - the expireDate of the listener, should usually be the invoice expire date.paymentListener - the payment listener to register.InternalErrorException - if internal exception occurred registering the payment listener.public boolean hasPaymentListener(java.lang.String preImageHash)
preImageHash - the related preImageHash in Base64public void unregisterPaymentListener(java.lang.String preImageHash)
throws InternalErrorException
This method won't release data from expireQueue, it will clean itself up automatically over time.
preImageHash - the related PreImageHash in base64InternalErrorException - if internal problems occurred releasing the payment listener.protected abstract void registerListener(T listener) throws InternalErrorException
listener - the event listener to register, depending on type.InternalErrorException - thrown by underlying event handler.protected abstract void unregisterListener(T listener) throws InternalErrorException
listener - the event listener to unregister, depending on type.InternalErrorException - thrown by underlying event handler.