T
- the identifier type which is used as the key for the notification instances representing the message
stored in notification map in the form of SendNotification
public abstract class SendCallback<T> extends Object
computeKey(XMessageContext)
method should be implemented to provide the key
that represents the message.Modifier and Type | Field and Description |
---|---|
Map<T,SendNotification> |
notificationMap
The notification map which holds the SendNotifications over the key computed using
computeKey(XMessageContext) using the message properties |
Constructor and Description |
---|
SendCallback() |
Modifier and Type | Method and Description |
---|---|
void |
close()
This method makes sure that no messages/resources is leaking while stopping the SendCallback by checking the
notificationMap for any stale messages/notifications.
|
protected void |
complete(T identifier)
This is expected to be called by all concrete implementations of SendCallback to make sure the callback completes
successfully.
|
protected abstract T |
computeKey(XMessageContext message)
This abstract method should be implemented by all concrete implementations such that it provides the same key
that is passed in for the
complete(Object) and notifyError(Object, Exception) methods using
the properties of the message |
protected void |
notifyError(T identifier,
Exception e)
This method is expected to be called by concrete implementations of the SendCallback to mark a message as an
error or a send failure.
|
SendNotification |
register(XMessageContext messageContext,
long timeout)
Registers the given message for send completion.
|
(package private) SendNotification |
unregister(XMessageContext message)
This method is supposed to be only used by the
SendNotification.close() method and hence package local
access modifier is used for this method. |
public Map<T,SendNotification> notificationMap
computeKey(XMessageContext)
using the message propertiespublic SendNotification register(XMessageContext messageContext, long timeout)
SendNotification
instance acquired by calling this
method should be closed within a finally block or use try declared resources to make sure there is no
message leak, as follows
try (SendNotification sendNotification = sendCallback.register(message)) { // ..sending logic sendNotification.waitForCompletion(); }
Or in prior to Java 7
SendNotification sendNotification = sendCallback.register(message); try { // ..sending logic sendNotification.waitForCompletion(); } finally { try { sendNotification.close(); } catch (IOException ignore) {} }
messageContext
- the messageContext to be registeredtimeout
- the timeout of the SendNotification for waiting after calling SendNotification.waitForCompletion()
SendNotification
created for this message on which the caller can wait for completionprotected void complete(T identifier)
computeKey(XMessageContext)
identifier
- the identifier of the message/notification that is waiting for completionprotected void notifyError(T identifier, Exception e)
identifier
- the identifier of the message/notification that is waiting for completione
- the exception that is causing the send failureSendNotification unregister(XMessageContext message)
SendNotification.close()
method and hence package local
access modifier is used for this method. It unregister the registered message from the SendCallbackmessage
- the message to be unregisterednull
otherwiseprotected abstract T computeKey(XMessageContext message)
complete(Object)
and notifyError(Object, Exception)
methods using
the properties of the messagemessage
- the message to be used for computing the key for the SendNotificationpublic void close()
TransportSender.stop()
Copyright © 2016–2019 AdroitLogic. All rights reserved.