Package org.jboss.ejb.client
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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TgetAttachment(AttachmentKey<T> key)Get an attachment from this object.Map<AttachmentKey<?>,?>getAttachments()Returns the attachments applicable for thisAttachable.<T> TputAttachment(AttachmentKey<T> key, T value)Set an attachment on this object.<T> TputAttachmentIfAbsent(AttachmentKey<T> key, T value)Set an attachment on this object if an existing attachment does not already exist.<T> TremoveAttachment(AttachmentKey<T> key)Remove and return an attachment value.<T> booleanremoveAttachment(AttachmentKey<T> key, T value)Remove an attachment if it has a certain value.<T> TreplaceAttachment(AttachmentKey<T> key, T value)Replace an attachment on this object if an existing attachment exists.<T> booleanreplaceAttachment(AttachmentKey<T> key, T oldValue, T newValue)Replace an attachment on this object if an existing attachment exists with a certain value.
-
-
-
Method Detail
-
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 thisAttachable. The returnedMapis an unmodifiableMap. If there are no attachments for thisAttachablethen this method returns an emptyMap- 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 keyvalue- the attachment's new value (may not benull)- Returns:
- the previous attachment value, or
nullif 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 keyvalue- the attachment's new value (may not benull)- Returns:
- the previous attachment value, or
nullif 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 keyvalue- the attachment's new value (may not benull)- Returns:
- the previous attachment value, or
nullif 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 keyoldValue- the attachment's expected value (may not benull)newValue- the attachment's new value (may not benull)- Returns:
trueif the old value matched and the value was replaced;falseotherwise
-
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
nullif 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 keyvalue- the attachment's expected value (may not benull)- Returns:
trueif the value was removed,falseif there was no attachment
-
-