SMILA (incubation) API documentation

org.eclipse.smila.blackboard.impl
Class BlackboardImpl

java.lang.Object
  extended by org.eclipse.smila.blackboard.impl.BlackboardImpl
All Implemented Interfaces:
Blackboard

public class BlackboardImpl
extends java.lang.Object
implements Blackboard

A non-persisting Blackboard implementation.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.eclipse.smila.blackboard.Blackboard
Blackboard.Get
 
Constructor Summary
BlackboardImpl(RecordFilterHelper filterHelper)
          create instance.
 
Method Summary
 void commit()
           commit ALL records on this blackboard to storages (if any) and release resources.
 void commitRecord(java.lang.String id)
          All changes are written to the storages before the record is removed.
 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.InputStream getAttachmentAsStream(java.lang.String id, java.lang.String name)
          Gets the attachment as stream.
 DataFactory getDataFactory()
          
 java.io.Serializable getGlobalNote(java.lang.String name)
          Gets the global note.
 AnyMap getMetadata(java.lang.String id)
          Shortcut for Blackboard.getRecord(String) + Record.getMetadata().
 Record getRecord(java.lang.String id)
          Get current version of record with given ID.
 Record getRecord(java.lang.String id, Blackboard.Get mode)
          get a reference to the record on the blackboard.
 Record getRecord(java.lang.String id, java.lang.String filterName)
          Shortcut for Blackboard.getRecord(String) + #filterRecord(Record, String)): Gets the blackboard record and applies the named filter.
 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 removeAttachment(java.lang.String id, java.lang.String name)
          Removes the attachment.
 void removeRecord(java.lang.String id)
          remove record completely from blackboard.
 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.
protected  void setBinaryStorage(BinaryStorageService binaryStorage)
          Set the binary service for blackboard.
 void setGlobalNote(java.lang.String name, java.io.Serializable object)
          Sets the global note.
 void setRecord(Record record)
          Sets a record on the blackboard.
 void setRecordNote(java.lang.String id, java.lang.String name, java.io.Serializable object)
          Sets the record note.
protected  void setRecordStorage(RecordStorage recordStorage)
          Set the record service for blackboard.
 void synchronizeRecord(Record record)
          Synchronize: copy all attributes and attachments from the incoming record to the blackboard record with the same ID.
 void unload()
          remove ALL records from blackboard and release all associated resources.
 void unloadRecord(java.lang.String id)
          The record is removed from the blackboard.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlackboardImpl

public BlackboardImpl(RecordFilterHelper filterHelper)
create instance.

Parameters:
filterHelper - record filter manager.
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,
                        Blackboard.Get mode)
                 throws BlackboardAccessException
get a reference to the record on the blackboard. See documentation of the values of Blackboard.Get for details on the mode parameter.

Specified by:
getRecord in interface Blackboard
Parameters:
id - the id
mode - configure behavior of method.
Returns:
the newly created or existing record.
Throws:
BlackboardAccessException

getRecord

public Record getRecord(java.lang.String id)
                 throws BlackboardAccessException
Get current version of record with given ID. Same as Blackboard.getRecord(String, Get) with Blackboard.Get.EXISTING. This method is usually the correct one to use in pipelets or workers to process a record.

Specified by:
getRecord in interface Blackboard
Parameters:
id - the id
Returns:
the record if it exists on blackboard or in record storage (if available), else null.
Throws:
BlackboardAccessException - error accessing attached storages

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 if the record exists on blackboard or in storage, else null.
Throws:
BlackboardAccessException - error accessing attached storages

getRecord

public Record getRecord(java.lang.String id,
                        java.lang.String filterName)
                 throws RecordFilterNotFoundException,
                        BlackboardAccessException
Shortcut for Blackboard.getRecord(String) + #filterRecord(Record, String)): Gets the blackboard record and applies the named filter.

Specified by:
getRecord in interface Blackboard
Parameters:
id - the id
filterName - the filter name
Returns:
the filtered record metadata if the record exists on blackboard or in storage, else null.
Throws:
RecordFilterNotFoundException - named record filter does not exist
BlackboardAccessException - error accessing storages for reading the record

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 - named record filter does not exist

setRecord

public void setRecord(Record record)
               throws BlackboardAccessException
Sets a record on the blackboard. If a record with the same ID already exists, it will be replaced. If the new record has attachment and a binary storage is attached to the blackboard, the attachments will be stored in binary storage and removed from memory.

Specified by:
setRecord in interface Blackboard
Parameters:
record - the record
Throws:
BlackboardAccessException - error accessing storages for reading the record or writing attachments

synchronizeRecord

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

Specified by:
synchronizeRecord in interface Blackboard
Parameters:
record - the record
Throws:
BlackboardAccessException - error accessing storages for reading the record or writing attachments

removeRecord

public void removeRecord(java.lang.String id)
remove record completely from blackboard. If storages are attached, the record data is removed from storages when Blackboard.commit() or Blackboard.commitRecord(String) is called.

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 the record exists and has the named attachment. Else false.
Throws:
BlackboardAccessException - error accessing storages for check

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, or null if record does not exist or does not have 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, or null if record does not exist or does not have the attachment
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 - error if record does not exist or on errors accessing storages for reading the record or deleting the attachment
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)
Checks for global note.

Specified by:
hasGlobalNote in interface Blackboard
Parameters:
name - the name
Returns:
true, if successful

getGlobalNote

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

Specified by:
getGlobalNote in interface Blackboard
Parameters:
name - the name
Returns:
the global note

setGlobalNote

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

Specified by:
setGlobalNote in interface Blackboard
Parameters:
name - the name
object - the object

hasRecordNote

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

Specified by:
hasRecordNote in interface Blackboard
Parameters:
id - the id
name - the name
Returns:
true, if successful

getRecordNote

public java.io.Serializable getRecordNote(java.lang.String id,
                                          java.lang.String name)
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)
Sets the record note.

Specified by:
setRecordNote in interface Blackboard
Parameters:
id - the id
name - the name
object - the object

commitRecord

public void commitRecord(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:
commitRecord in interface Blackboard
Parameters:
id - the id
Throws:
BlackboardAccessException - the blackboard access exception

unloadRecord

public void unloadRecord(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:
unloadRecord in interface Blackboard
Parameters:
id - the id

commit

public void commit()
            throws BlackboardAccessException

commit ALL records on this blackboard to storages (if any) and release resources.

The records will not be unloaded from the blackboard.

The operation 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.

unload

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

Specified by:
unload in interface Blackboard

setRecordStorage

protected void setRecordStorage(RecordStorage recordStorage)
Set the record service for blackboard. To be used by Declarative Services as the bind method.

Parameters:
recordStorage - RecordStorage - the record storage service interface

setBinaryStorage

protected void setBinaryStorage(BinaryStorageService binaryStorage)
Set the binary service for blackboard. To be used by Declarative Services as the bind method.

Parameters:
binaryStorage - BinaryStorageService - the binary storage service interface

SMILA (incubation) API documentation