public class TopicDefinition extends Object implements Serializable
A Topic definition comprises:
1) A mandatory type that defines the type of Topic Data (if any) associated
with the Topic.
2) A set of properties. Some are generic and some are dependent upon the
type. The generic properties are all optional but some type specific ones may
be mandatory.
3) A metadata definition which is mandatory for some types. The type of this
metadata is also dependent upon the type.
This class performs no validation of the settings. If a definition is used to create a topic and mandatory properties (or metadata) are not present or one or more values are invalid then topic creation would fail.
Each property has documented type (e.g. String, Integer, Long etc) and the
property value may be set to an object of that type or any other object that
can be parsed to that type via its toString method. For example to set an
integer property you could specify an Integer (or an int) but you could also
specify a String with a numeric Integer representation within it. However, if
a non numeric value was assigned to an Integer property then a failure may
occur when the property is used (for example, read using
getIntegerProperty(TopicProperty)
.
Constructor and Description |
---|
TopicDefinition(TopicDataType type)
Creates a Topic Definition of the specified type.
|
TopicDefinition(TopicDataType type,
Map<TopicProperty,Object> properties)
Creates a Topic Definition of a specified type with properties.
|
TopicDefinition(TopicDataType type,
Map<TopicProperty,Object> properties,
MNode metadata)
Creates a Topic Definition.
|
TopicDefinition(TopicDataType type,
MNode metadata)
Creates a Topic Definition of a specified type with Metadata.
|
Modifier and Type | Method and Description |
---|---|
Boolean |
getBooleanProperty(TopicProperty property)
Returns the value of a Boolean property.
|
Byte |
getByteProperty(TopicProperty property)
Returns the value of a Byte property
|
Integer |
getIntegerProperty(TopicProperty property)
Returns the value of an Integer property
|
String[] |
getListProperty(TopicProperty property)
Returns the value of a String property split by list delimiters.
|
Long |
getLongProperty(TopicProperty property)
Returns the value of a Long property
|
MNode |
getMetadata()
Returns metadata.
|
Map<TopicProperty,Object> |
getProperties()
Returns a copy of the map of the currently set definition properties.
|
Object |
getProperty(TopicProperty property)
Returns the value of a Topic property.
|
String |
getStringProperty(TopicProperty property)
Returns the value of a property as a String.
|
TopicDataType |
getType()
Returns the topic type.
|
void |
setListProperty(TopicProperty property,
List<String> list)
Sets a list type property.
|
void |
setListProperty(TopicProperty property,
String... list)
Sets a list type property.
|
void |
setMetadata(MNode metadata)
Sets metadata for the Topic.
|
void |
setProperties(Map<TopicProperty,Object> properties)
Set properties from a specified map of properties
|
void |
setProperty(TopicProperty property,
Object value)
Set a Topic property.
|
String |
toString() |
public TopicDefinition(TopicDataType type)
For some topic types this may be sufficient but for other types it may be necessary to set some properties or metadata after construction.
type
- the topic typepublic TopicDefinition(TopicDataType type, Map<TopicProperty,Object> properties)
Additional properties can be set after construction if required as can metadata for those types that need it.
type
- the topic typeproperties
- an initial set of properties.public TopicDefinition(TopicDataType type, MNode metadata)
Properties may still be set after construction if required.
type
- the topic typemetadata
- topic metadata. The actual type of metadata that is
required (if any) would be determined by the topic type. See
setMetadata(MNode)
for more details.public TopicDefinition(TopicDataType type, Map<TopicProperty,Object> properties, MNode metadata)
type
- the topic typeproperties
- an initial set of properties. Note that properties are
optional but some topic types do have mandatory properties.
Additional properties may be set after construction if required.
See TopicProperty
for full details of available
properties.metadata
- topic metadata. The actual type of metadata that is
required (if any) would be determined by the topic type. See
setMetadata(MNode)
for more details.public TopicDataType getType()
public void setProperty(TopicProperty property, Object value)
There are a number of optional properties that may be set for all topic types. Certain topic types have their own additional properties and some of these may be mandatory.
Note that no validation is done on property values and their settings by this method. If the definition is used to create a Topic and one or more property values are invalid or missing (if mandatory) then the topic creation would fail.
property
- the propertyvalue
- the property valuepublic void setListProperty(TopicProperty property, List<String> list)
This will set the value of the property as a String with each supplied
element separated by Message.LIST_DELIMITER_STRING
suitable for
retrieval using getListProperty(TopicProperty)
.
property
- the propertylist
- the list of valuespublic void setListProperty(TopicProperty property, String... list)
This will set the value of the property as a String with each supplied
element separated by Message.LIST_DELIMITER_STRING
suitable for
retrieval using getListProperty(TopicProperty)
.
property
- the propertylist
- the list of valuespublic Object getProperty(TopicProperty property)
property
- the propertypublic String getStringProperty(TopicProperty property)
This will invoke the Object.toString()
method on the property
value to obtain it as a String.
property
- the propertypublic Integer getIntegerProperty(TopicProperty property) throws APIException
property
- the propertyAPIException
- if the property had been set with a value that could
not be parsed to an Integerpublic Long getLongProperty(TopicProperty property) throws APIException
property
- the propertyAPIException
- if the property had been set with a value that could
not be parsed to a Longpublic Byte getByteProperty(TopicProperty property) throws APIException
property
- the property keyAPIException
- if the property had been set with a value that could
not be parsed to a Bytepublic Boolean getBooleanProperty(TopicProperty property)
Note that this will return true only if the property was set to a boolean value or to an object whose toString() method returns a value of "true" regardless of case.
property
- the propertypublic String[] getListProperty(TopicProperty property)
property
- the propertypublic Map<TopicProperty,Object> getProperties()
Changing the returned map will not change the definition.
public void setProperties(Map<TopicProperty,Object> properties)
properties
- map of propertiespublic void setMetadata(MNode metadata)
Only some types of Topic require metadata. Some other types (with data of
type TopicDataWithMetadata
can have optional metadata and for others it would
be ignored.
The type of metadata would depend upon the topic type as follows:
TopicDataType.SINGLE_VALUE
requires metadata of type
MField
.
TopicDataType.RECORD
requires metadata of type MMessage
.
TopicDataType.PAGED_RECORD
requires metadata of type
MRecord
.
And types with optional metadata can take any MNode
.
metadata
- a metadata nodepublic MNode getMetadata()
Copyright © 2016 Push Technology Ltd. All Rights Reserved.