Class Attachable

java.lang.Object
org.jboss.ejb.client.Attachable
Direct Known Subclasses:
AbstractInvocationContext, EJBClientContext, EJBReceiver

public abstract class Attachable extends Object
An object which may have attachments. Even if the object is serializable, its attachment map is not and will always deserialize empty.
Author:
David M. Lloyd
  • Method Details

    • getAttachment

      public <T> T getAttachment(AttachmentKey<T> key)
      Get an attachment from this object.
      Type Parameters:
      T - the attachment type
      Parameters:
      key - the attachment key
      Returns:
      the attachment value
    • getAttachments

      public Map<AttachmentKey<?>,?> getAttachments()
      Returns the attachments applicable for this Attachable. The returned Map is an unmodifiable Map. If there are no attachments for this Attachable then this method returns an empty Map
      Returns:
      a read-only copy of the attachments map
    • putAttachment

      public <T> T putAttachment(AttachmentKey<T> key, T value)
      Set an attachment on this object.
      Type Parameters:
      T - the attachment type
      Parameters:
      key - the attachment key
      value - the attachment's new value (may not be null)
      Returns:
      the previous attachment value, or null if there was none
    • putAttachmentIfAbsent

      public <T> T putAttachmentIfAbsent(AttachmentKey<T> key, T value)
      Set an attachment on this object if an existing attachment does not already exist.
      Type Parameters:
      T - the attachment type
      Parameters:
      key - the attachment key
      value - the attachment's new value (may not be null)
      Returns:
      the previous attachment value, or null if there was none
    • replaceAttachment

      public <T> T replaceAttachment(AttachmentKey<T> key, T value)
      Replace an attachment on this object if an existing attachment exists.
      Type Parameters:
      T - the attachment type
      Parameters:
      key - the attachment key
      value - the attachment's new value (may not be null)
      Returns:
      the previous attachment value, or null if there was none
    • replaceAttachment

      public <T> boolean replaceAttachment(AttachmentKey<T> key, T oldValue, T newValue)
      Replace an attachment on this object if an existing attachment exists with a certain value.
      Type Parameters:
      T - the attachment type
      Parameters:
      key - the attachment key
      oldValue - the attachment's expected value (may not be null)
      newValue - the attachment's new value (may not be null)
      Returns:
      true if the old value matched and the value was replaced; false otherwise
    • removeAttachment

      public <T> T removeAttachment(AttachmentKey<T> key)
      Remove and return an attachment value.
      Type Parameters:
      T - the attachment type
      Parameters:
      key - the attachment key
      Returns:
      the previous value of the attachment, or null if there was none
    • removeAttachment

      public <T> boolean removeAttachment(AttachmentKey<T> key, T value)
      Remove an attachment if it has a certain value.
      Type Parameters:
      T - the attachment type
      Parameters:
      key - the attachment key
      value - the attachment's expected value (may not be null)
      Returns:
      true if the value was removed, false if there was no attachment