public interface MessageFactory
A message factory is used to create DataSource messages that can be published to other DataSources.
You do not have to implement this interface yourself. An implementation is provided, and can be
retrieved from any Publisher
by calling the
Publisher.getMessageFactory()
method.
Modifier and Type | Method and Description |
---|---|
ContainerMessage |
createContainerMessage(java.lang.String subject)
Creates a message that defines a container.
|
GenericMessage |
createGenericMessage(java.lang.String subject)
Creates an empty Generic message to which structured data can be added.
|
MappingMessage |
createMappingMessage(java.lang.String subject,
java.lang.String mapping)
Creates a MappingMessage for mapping subjects
|
NewsMessage |
createNewsMessage(java.lang.String subject,
java.lang.String headline,
java.lang.String storyReference,
java.lang.String newsDateTime)
Creates a News message for the given subject.
|
PageMessage |
createPageMessage(java.lang.String subject,
int maxColumns,
int maxRows)
Creates a Page message for the given subject.
|
PermissionMessage |
createPermissionMessage(java.lang.String subject,
java.lang.String key)
Creates a Permission message for the given subject.
|
RecordType1Message |
createRecordType1Message(java.lang.String subject)
Creates a Record message to which Type 1 structured data can be added.
|
RecordType2Message |
createRecordType2Message(java.lang.String subject,
java.lang.String type2IndexField,
java.lang.String type2IndexValue)
Creates a Record message to which Type 2 structured data can be added.
|
RecordType3Message |
createRecordType3Message(java.lang.String subject)
Creates a Record message to which Type 3 structured data can be added.
|
StoryMessage |
createStoryMessage(java.lang.String subject,
java.lang.String text)
Creates a Story message for the given subject.
|
SubjectErrorEvent |
createSubjectErrorEvent(java.lang.String subject,
SubjectError error) |
SubjectErrorEvent |
createSubjectErrorEvent(java.lang.String subject,
SubjectError error,
SubjectError.Flags... flags)
Creates a subject error event.
|
SubjectStatusEvent |
createSubjectStatusEvent(java.lang.String subject,
SubjectStatus status,
java.lang.String message)
Creates a subject status event.
|
WrapperMessage |
createWrapperMessage(java.lang.String subject)
Creates a Wrapper message for the given subject.
|
RecordType1Message createRecordType1Message(java.lang.String subject)
Creates a Record message to which Type 1 structured data can be added.
The returned message contains no data. To populate the message with data, use the appropriate
methods of RecordType1Message
.
subject
- The subject of the Record.RecordType2Message createRecordType2Message(java.lang.String subject, java.lang.String type2IndexField, java.lang.String type2IndexValue)
Creates a Record message to which Type 2 structured data can be added.
The returned message contains no data. To populate the message with data, use the appropriate
methods of RecordType2Message
.
subject
- The subject of the Record.type2IndexField
- Field name of the type2 index.type2IndexValue
- The value of the type2 index.RecordType3Message createRecordType3Message(java.lang.String subject)
Creates a Record message to which Type 3 structured data can be added.
The returned message contains no data. To populate the message with data, use the appropriate
methods of RecordType3Message
.
subject
- The subject of the Record.GenericMessage createGenericMessage(java.lang.String subject)
Creates an empty Generic message to which structured data can be added.
Generic messages can be used without specifying field mappings in a separate adapter configuration file.
This may be useful when receiving updates from a provider which supplies a variable or unknown
number of fields.
The returned message contains no data. To populate the message with data, use the appropriate
methods of GenericMessage
.
subject
- The subject of the Record.MappingMessage createMappingMessage(java.lang.String subject, java.lang.String mapping)
Creates a MappingMessage for mapping subjects
The returned message contains the mapped subject.
subject
- The subject of the message.mapping
- The mapped subject of the messageContainerMessage createContainerMessage(java.lang.String subject)
Creates a message that defines a container. The name of the container is the given subject.
subject
- The subject defining the name of the container.NewsMessage createNewsMessage(java.lang.String subject, java.lang.String headline, java.lang.String storyReference, java.lang.String newsDateTime)
Creates a News message for the given subject.
The method parameters allow you to set the basic content of the message: its subject,
headline, story reference, and date+time. To add keywords or terms describing the news
headline, call the NewsMessage.getTags()
method
on the newly created message (see NewsMessage
).
To set permissions for the NewsMessage
, call
NewsMessage.setPermission(String)
.
subject
- The subject identifying the news message.headline
- The news headline.storyReference
- The reference to the news story associated with the headline.newsDateTime
- The date and time of the news headline.PageMessage createPageMessage(java.lang.String subject, int maxColumns, int maxRows)
Creates a Page message for the given subject.
The returned message contains no data. To populate the message with data, use the appropriate
methods of PageMessage
.
subject
- The subject of the page message.maxColumns
- The maximum horizontal size of the page in columns of text characters.maxRows
- The maximum vertical size of the page in rows of text.PermissionMessage createPermissionMessage(java.lang.String subject, java.lang.String key)
Creates a Permission message for the given subject.
The returned message contains no data. To populate the message with data, use the appropriate
methods of PermissionMessage
.
subject
- The subject of the Permission message.key
- The permission key.StoryMessage createStoryMessage(java.lang.String subject, java.lang.String text)
subject
- The subject of the story.text
- The story text.WrapperMessage createWrapperMessage(java.lang.String subject)
subject
- The subject of the story.SubjectErrorEvent createSubjectErrorEvent(java.lang.String subject, SubjectError error, SubjectError.Flags... flags)
subject
- The subject to which the error relates.error
- The error.flags
- Additional flags to be set on the nodata
The following example shows how to create an SubjectErrorEvent for a specified subject, and send it to all peers that have requested that subject:
import com.caplin.datasource.SubjectError;
import com.caplin.datasource.SubjectErrorEvent;
import com.caplin.datasource.publisher.Publisher;
public class SendSubjectErrorEvent
{
public void sendSubjectErrorEvent(Publisher publisher, String subject)
{
// Create a SubjectErrorEvent
SubjectErrorEvent ev = publisher.getMessageFactory().createSubjectErrorEvent(subject, SubjectError.NotFound);
// Distribute the error to all peers that have requested this subject.
publisher.publishSubjectErrorEvent(ev);
}
}
SubjectErrorEvent createSubjectErrorEvent(java.lang.String subject, SubjectError error)
SubjectStatusEvent createSubjectStatusEvent(java.lang.String subject, SubjectStatus status, java.lang.String message)
subject
- The subject to which the status relates.status
- The status.message
- A free form textual message indicating the reason for the status message being
raised.
The following example shows how to create an ISubjectStatusEvent for a specified subject, and send it to all peers that have requested that subject:
import com.caplin.datasource.SubjectStatus;
import com.caplin.datasource.SubjectStatusEvent;
import com.caplin.datasource.publisher.Publisher;
public class SendSubjectStatusEvent
{
public void sendSubjectStatusToSubscribedPeers(Publisher publisher, String subject)
{
// Create a Stale subject status event.
SubjectStatusEvent ev = publisher.getMessageFactory().createSubjectStatusEvent(subject, SubjectStatus.Stale, "Object is stale");
// And publish to all subscribed peers.
publisher.publishSubjectStatusEvent(ev);
}
}
Please send bug reports and comments to Caplin support