SMILA (incubation) API documentation

org.eclipse.smila.blackboard.impl
Class TransientBlackboardImpl

java.lang.Object
  extended by org.eclipse.smila.blackboard.impl.TransientBlackboardImpl
All Implemented Interfaces:
Blackboard
Direct Known Subclasses:
PersistingBlackboardImpl

public class TransientBlackboardImpl
extends java.lang.Object
implements Blackboard

A non-persisting Blackboard implementation.


Constructor Summary
TransientBlackboardImpl(RecordFilterHelper filterHelper, java.io.File attachmentsTempDir)
          create instance.
 
Method Summary
protected  void checkCachedFileAttachment(java.lang.String id, java.lang.String name)
          Checks if there is cached File attachment for given Id and prevents overwriting it.
 void commit()
          commit ALL records on this blackboard to storages (if any) and release resources.
 void commit(java.lang.String id)
          All changes are written to the storages before the record is removed.
protected  boolean containsRecord(java.lang.String id)
          check if record exists on blackboard.
protected  void copyAttributes(AnyMap source, AnyMap destination)
          Copy attributes.
 Record copyRecord(java.lang.String id, java.lang.String newId)
          Creates a copy of the record with a new Id and returns the new record.
 Record create(java.lang.String id)
          Creates a new record with a given ID in memory, but only if it doesn't exist there yet, if it does, then nothing happens and the existing record is returned.
 Record filterRecord(Record record, java.lang.String filterName)
          Filter record metadata.
 byte[] getAttachment(java.lang.String id, java.lang.String name)
          Gets the attachment.
 java.io.File getAttachmentAsFile(java.lang.String id, java.lang.String name)
          Gets attachment as file.
 java.io.InputStream getAttachmentAsStream(java.lang.String id, java.lang.String name)
          Gets the attachment as stream.
protected  java.lang.String getAttachmentId(java.lang.String id, java.lang.String name)
          Calculates the attachment id that will be used as a key in binary storage.
protected  Record getCachedRecord(java.lang.String id)
          Returns cached record by id or null if record is not loaded into blackboard.
 DataFactory getDataFactory()
          
 java.io.Serializable getGlobalNote(java.lang.String name)
          Gets the global note.
protected  java.util.Collection<java.lang.String> getIds()
          create a collection of all IDs of records on the blackboard.
 AnyMap getMetadata(java.lang.String id)
          Shortcut for Blackboard.getRecord(String) + Record.getMetadata().
 Record getRecord(java.lang.String id)
          Gets the record for the given Id.
 Record getRecord(java.lang.String id, java.lang.String filterName)
          Gets the filtered record.
 java.io.Serializable getRecordNote(java.lang.String id, java.lang.String name)
          Gets the record note.
 boolean hasAttachment(java.lang.String id, java.lang.String name)
          Checks for attachment.
 boolean hasGlobalNote(java.lang.String name)
          Checks for global note.
 boolean hasRecordNote(java.lang.String id, java.lang.String name)
          Checks for record note.
 void invalidate()
          remove ALL records from blackboard and release all associated resources.
 void invalidate(java.lang.String id)
          The record is removed from the blackboard.
 Record load(java.lang.String id)
          same as create(String).
 void removeAttachment(java.lang.String id, java.lang.String name)
          Removes the attachment.
 void removeRecord(java.lang.String id)
          remove record completely from blackboard and persistence.
 void setAttachment(java.lang.String id, java.lang.String name, byte[] attachment)
          Sets the attachment.
 void setAttachmentFromFile(java.lang.String id, java.lang.String name, java.io.File attachmentFile)
          Sets attachment from file.
 void setAttachmentFromStream(java.lang.String id, java.lang.String name, java.io.InputStream attachmentStream)
          Sets the attachment from stream.
 void setGlobalNote(java.lang.String name, java.io.Serializable object)
          Sets the global note.
 void setRecord(Record record)
          Stores a record on the blackboard.
 void setRecordNote(java.lang.String id, java.lang.String name, java.io.Serializable object)
          Sets the record note.
 void synchronizeRecord(Record record)
          Synchronize: copy all existing attributes from the incoming record to the blackboard record with the same ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransientBlackboardImpl

public TransientBlackboardImpl(RecordFilterHelper filterHelper,
                               java.io.File attachmentsTempDir)
create instance.

Parameters:
filterHelper - record filter manager.
attachmentsTempDir - directory to use for temporary attachment files.
Method Detail

getDataFactory

public DataFactory getDataFactory()

Specified by:
getDataFactory in interface Blackboard
Returns:
the data factory used by this blackboard to create records.

getRecord

public Record getRecord(java.lang.String id)
                 throws BlackboardAccessException
Gets the record for the given Id. This will first check against the memory and if not present there it will call Blackboard.load(String). Depending on the blackboard implementation, attachments may or may not be included in the returned record.

Specified by:
getRecord in interface Blackboard
Parameters:
id - the id
Returns:
the record
Throws:
BlackboardAccessException - the blackboard access exception

getMetadata

public AnyMap getMetadata(java.lang.String id)
                   throws BlackboardAccessException
Shortcut for Blackboard.getRecord(String) + Record.getMetadata(). If Blackboard.getRecord(String) would yield null, this method yields null, too.

Specified by:
getMetadata in interface Blackboard
Parameters:
id - the id
Returns:
the record metadata
Throws:
BlackboardAccessException - the blackboard access exception

getRecord

public Record getRecord(java.lang.String id,
                        java.lang.String filterName)
                 throws RecordFilterNotFoundException,
                        BlackboardAccessException
Gets the filtered record. No attachments will be included.

Specified by:
getRecord in interface Blackboard
Parameters:
id - the id
filterName - the filter name
Returns:
the record
Throws:
RecordFilterNotFoundException - the record filter not found exception
BlackboardAccessException - the blackboard access exception

filterRecord

public Record filterRecord(Record record,
                           java.lang.String filterName)
                    throws RecordFilterNotFoundException
Filter record metadata. Attachments will not be included in the filtered record.

Specified by:
filterRecord in interface Blackboard
Parameters:
record - the record
filterName - the filter name
Returns:
the record
Throws:
RecordFilterNotFoundException - the record filter not found exception

setRecord

public void setRecord(Record record)
               throws BlackboardAccessException
Stores a record on the blackboard. If a record with the same Id already exists, it will be replaced.

Specified by:
setRecord in interface Blackboard
Parameters:
record - the record
Throws:
BlackboardAccessException - the blackboard access exception

copyRecord

public Record copyRecord(java.lang.String id,
                         java.lang.String newId)
                  throws BlackboardAccessException
Creates a copy of the record with a new Id and returns the new record. Attachments are not copied.

Specified by:
copyRecord in interface Blackboard
Parameters:
id - the id
newId - the id of the copy
Returns:
the copied record.
Throws:
BlackboardAccessException - the blackboard access exception

synchronizeRecord

public void synchronizeRecord(Record record)
                       throws BlackboardAccessException
Synchronize: copy all existing attributes from the incoming record to the blackboard record with the same ID.

Specified by:
synchronizeRecord in interface Blackboard
Parameters:
record - the record
Throws:
BlackboardAccessException - the blackboard access exception

commit

public void commit()
            throws BlackboardAccessException
commit ALL records on this blackboard to storages (if any) and release resources. It is guaranteed that the blackboard is empty after the operation, but it throws an exception if at least one record could not be committed (e.g. written to storages) successfully. However, the implementation should try to commit as many records as possible and not stop on the first failed commit and invalidate the remaining records.

Specified by:
commit in interface Blackboard
Throws:
BlackboardAccessException - at least one record could not be committed.

invalidate

public void invalidate()
remove ALL records from blackboard and release all associated resources. Nothing is written to connected storage services.

Specified by:
invalidate in interface Blackboard

create

public Record create(java.lang.String id)
Creates a new record with a given ID in memory, but only if it doesn't exist there yet, if it does, then nothing happens and the existing record is returned. This method is agnostic to the persistence layer, i.e. it will not check if a record with the same ID has been persisted before. Hence, if there is a record that is persisted but not in memory and this method is called a new record is created (in memory) and a possible flowing commit will overwrite the persisted record.

Specified by:
create in interface Blackboard
Parameters:
id - the id
Returns:
the newly created or existing record.

load

public Record load(java.lang.String id)
            throws BlackboardAccessException
same as create(String). Loads record data for the given ID from persistence (or prepare it to be loaded). Used by a client to indicate that it wants to process this record. The behavior is very implementation specific so check the the impl's doc.

Specified by:
load in interface Blackboard
Parameters:
id - the id
Returns:
a newly created or existing record, or in some cases null if record isn't found (implementation specific)
Throws:
BlackboardAccessException - the blackboard access exception

commit

public void commit(java.lang.String id)
            throws BlackboardAccessException
All changes are written to the storages before the record is removed. The record is unlocked in the database.

Specified by:
commit in interface Blackboard
Parameters:
id - the id
Throws:
BlackboardAccessException - the blackboard access exception

invalidate

public void invalidate(java.lang.String id)
The record is removed from the blackboard. The record is unlocked in the database. If the record was created new (not overwritten) on this blackboard it should be removed from the storage completely.

Specified by:
invalidate in interface Blackboard
Parameters:
id - the id

removeRecord

public void removeRecord(java.lang.String id)
remove record completely from blackboard and persistence.

Specified by:
removeRecord in interface Blackboard
Parameters:
id - record id

hasAttachment

public boolean hasAttachment(java.lang.String id,
                             java.lang.String name)
                      throws BlackboardAccessException
Checks for attachment.

Specified by:
hasAttachment in interface Blackboard
Parameters:
id - the id
name - the name
Returns:
true, if successful
Throws:
BlackboardAccessException - the blackboard access exception

getAttachment

public byte[] getAttachment(java.lang.String id,
                            java.lang.String name)
                     throws BlackboardAccessException
Gets the attachment.

Specified by:
getAttachment in interface Blackboard
Parameters:
id - the id
name - the name
Returns:
the attachment
Throws:
BlackboardAccessException

getAttachmentAsStream

public java.io.InputStream getAttachmentAsStream(java.lang.String id,
                                                 java.lang.String name)
                                          throws BlackboardAccessException
Gets the attachment as stream.

Specified by:
getAttachmentAsStream in interface Blackboard
Parameters:
id - the id
name - the name
Returns:
the attachment as stream
Throws:
BlackboardAccessException

getAttachmentAsFile

public java.io.File getAttachmentAsFile(java.lang.String id,
                                        java.lang.String name)
                                 throws BlackboardAccessException
Gets attachment as file. Creates file containing copy of the attachment into blackboard bundle's working directory.

Specified by:
getAttachmentAsFile in interface Blackboard
Parameters:
id - the id
name - the name
Returns:
File
Throws:
BlackboardAccessException

setAttachment

public void setAttachment(java.lang.String id,
                          java.lang.String name,
                          byte[] attachment)
                   throws BlackboardAccessException
Sets the attachment.

Specified by:
setAttachment in interface Blackboard
Parameters:
id - the id
name - the name
attachment - the attachment
Throws:
BlackboardAccessException

setAttachmentFromStream

public void setAttachmentFromStream(java.lang.String id,
                                    java.lang.String name,
                                    java.io.InputStream attachmentStream)
                             throws BlackboardAccessException
Sets the attachment from stream.

Specified by:
setAttachmentFromStream in interface Blackboard
Parameters:
id - the id
name - the name
attachmentStream - the attachment stream
Throws:
BlackboardAccessException

setAttachmentFromFile

public void setAttachmentFromFile(java.lang.String id,
                                  java.lang.String name,
                                  java.io.File attachmentFile)
                           throws BlackboardAccessException
Sets attachment from file.

Specified by:
setAttachmentFromFile in interface Blackboard
Parameters:
id - the id
name - the name
attachmentFile - attachment file
Throws:
BlackboardAccessException

removeAttachment

public void removeAttachment(java.lang.String id,
                             java.lang.String name)
                      throws BlackboardAccessException
Removes the attachment.

Specified by:
removeAttachment in interface Blackboard
Parameters:
id - the id
name - the name
Throws:
BlackboardAccessException - the blackboard access exception
See Also:
org.eclipse.smila.blackboard.Blackboard#removeAttachment(org.eclipse.smila.datamodel.id.Id, java.lang.String)

hasGlobalNote

public boolean hasGlobalNote(java.lang.String name)
                      throws BlackboardAccessException
Checks for global note.

Specified by:
hasGlobalNote in interface Blackboard
Parameters:
name - the name
Returns:
true, if successful
Throws:
BlackboardAccessException - the blackboard access exception

getGlobalNote

public java.io.Serializable getGlobalNote(java.lang.String name)
                                   throws BlackboardAccessException
Gets the global note.

Specified by:
getGlobalNote in interface Blackboard
Parameters:
name - the name
Returns:
the global note
Throws:
BlackboardAccessException - the blackboard access exception

setGlobalNote

public void setGlobalNote(java.lang.String name,
                          java.io.Serializable object)
                   throws BlackboardAccessException
Sets the global note.

Specified by:
setGlobalNote in interface Blackboard
Parameters:
name - the name
object - the object
Throws:
BlackboardAccessException - the blackboard access exception

hasRecordNote

public boolean hasRecordNote(java.lang.String id,
                             java.lang.String name)
                      throws BlackboardAccessException
Checks for record note.

Specified by:
hasRecordNote in interface Blackboard
Parameters:
id - the id
name - the name
Returns:
true, if successful
Throws:
BlackboardAccessException - the blackboard access exception

getRecordNote

public java.io.Serializable getRecordNote(java.lang.String id,
                                          java.lang.String name)
                                   throws BlackboardAccessException
Gets the record note.

Specified by:
getRecordNote in interface Blackboard
Parameters:
id - the id
name - the name
Returns:
the record note
Throws:
BlackboardAccessException

setRecordNote

public void setRecordNote(java.lang.String id,
                          java.lang.String name,
                          java.io.Serializable object)
                   throws BlackboardAccessException
Sets the record note.

Specified by:
setRecordNote in interface Blackboard
Parameters:
id - the id
name - the name
object - the object
Throws:
BlackboardAccessException - the blackboard access exception

getAttachmentId

protected java.lang.String getAttachmentId(java.lang.String id,
                                           java.lang.String name)
Calculates the attachment id that will be used as a key in binary storage.

Parameters:
id - the id
name - the name
Returns:
the attachment id

checkCachedFileAttachment

protected void checkCachedFileAttachment(java.lang.String id,
                                         java.lang.String name)
                                  throws BlackboardAccessException
Checks if there is cached File attachment for given Id and prevents overwriting it.

Parameters:
id - Id
name - attachment name
Throws:
BlackboardAccessException - file exists.

getCachedRecord

protected Record getCachedRecord(java.lang.String id)
Returns cached record by id or null if record is not loaded into blackboard.

Parameters:
id - Record id
Returns:
Record

containsRecord

protected boolean containsRecord(java.lang.String id)
check if record exists on blackboard.

Parameters:
id - record ID
Returns:
true if a record with this ID is currently loaded.

getIds

protected java.util.Collection<java.lang.String> getIds()
create a collection of all IDs of records on the blackboard.

Returns:
collection containing IDs of all currently loaded records.

copyAttributes

protected void copyAttributes(AnyMap source,
                              AnyMap destination)
Copy attributes.

Parameters:
source - the source
destination - the destination

SMILA (incubation) API documentation