public abstract class Publisher extends com.pushtechnology.diffusion.publisher.BasePublisher implements TopicProvider, ClientAckListener
To implement a Publisher you must extend this class and override the appropriate methods. The methods that need to be overridden depend upon the nature of the publisher implementation.
Note that all Publishers within a Diffusion Server share the same
TopicTree
.
Constructor and Description |
---|
Publisher() |
Modifier and Type | Method and Description |
---|---|
PublisherServerConnection |
addServerConnection(String name,
ServerDetails serverDetails)
Deprecated.
since 5.9 - See
PublisherServerConnection |
PublisherServerConnection |
addServerConnection(String name,
String host,
int port)
Deprecated.
since 5.9 - See
PublisherServerConnection |
Topic |
addTopic(String topicName)
Add a Topic to the root of the Topic tree.
|
Topic |
addTopic(String topicName,
TopicData data)
Add a Topic to the root of the Topic tree.
|
Topic |
addTopic(String topicName,
TopicDefinition definition)
Add a Topic to the root of the Topic tree.
|
Topic |
addTopic(String topicName,
TopicTreeNode parent)
Adds a Topic to a specified parent Topic.
|
Topic |
addTopic(String topicName,
TopicTreeNode parent,
TopicData data)
Adds a Topic to a specified parent Topic.
|
Topic |
addTopic(String topicName,
TopicTreeNode parent,
TopicDefinition definition)
Adds a Topic to a specified parent Topic.
|
void |
addTopicListener(TopicListener topicListener,
MessageSourceType sourceType,
String... topics)
Adds a
TopicListener . |
void |
addTopicListener(TopicListener topicListener,
MessageSourceType sourceType,
TopicSet topics)
Adds a
TopicListener . |
void |
addTopicLoader(TopicLoader topicLoader,
String topicPattern)
addTopicLoader
|
void |
addTopics(TopicSet topics)
Add a set of Topics.
|
void |
addTopics(TopicSet topics,
TopicTreeNode parent)
Add a set of Topics to a specified parent node.
|
ClientGroup |
createClientGroup(String groupName)
Create a client group.
|
TopicMessage |
createDeltaMessage(String topicName)
Creates an empty delta message.
|
TopicMessage |
createDeltaMessage(String topicName,
int capacity)
Creates an empty delta message.
|
TopicMessage |
createLoadMessage(String topicName)
Creates an empty Topic Load message.
|
TopicMessage |
createLoadMessage(String topicName,
int capacity)
Creates an empty Topic Load message.
|
protected TopicMessage |
fetchForClient(Client client,
Topic topic,
List<String> headers)
Deprecated.
since 5.6. Currently a classic client can issue a fetch
request to a stateless topic. This method enables a publisher
to return a reply. At future releases this capability will be
removed.
|
long |
getAckTimeout()
Returns the default ACK timeout value for the provider.
|
boolean |
getBooleanProperty(String key)
This is a convenience method to get an boolean property value for this
publisher from the Publishers.xml file.
|
int |
getBytesProperty(String key)
This is a convenience method to get a bytes property value for this
publisher from the Publishers.xml file.
|
ClientGroup |
getClientGroup(String groupName)
Get a client group.
|
List<String> |
getClientGroupMembership(TopicClient client)
clientInWhichGroups
|
List<TopicClient> |
getClients(Topic topic)
Returns the list of clients currently subscribed to a given topic.
|
PublisherConfig |
getConfig()
Returns the publisher's configuration object.
|
TopicSet |
getInitialTopicSet()
Returns the initial topic set that the publisher was loaded with.
|
int |
getIntegerProperty(String key)
This is a convenience method to get an integer property value for this
publisher from the Publishers.xml file.
|
LogWriter |
getLogger()
Returns the logger which may be used to write log messages for the
publisher.
|
long |
getMillisProperty(String key)
This is a convenience method to get a time property value for this
publisher from the Publishers.xml file.
|
int |
getNumberOfTopics()
getNumberOfTopics
|
String |
getProperty(String key)
This is a convenience method to get a configured property value for this
publisher.
|
String |
getPublisherName()
Returns the publisher's name.
|
PublisherServerConnection |
getServerConnection(String name)
Deprecated.
since 5.9 - See
PublisherServerConnection |
List<PublisherServerConnection> |
getServerConnections()
Deprecated.
since 5.9 - See
PublisherServerConnection |
PublisherStatistics |
getStatistics()
Return the statistics for this publisher.
|
Topic |
getTopic(String topicName)
getTopic
|
Topic |
getTopic(TopicMessage message)
Returns the Topic belonging to the provider that matches a given Message.
|
TopicLoader |
getTopicLoader(String topicName)
Get topic loader for named topic.
|
List<Topic> |
getTopics()
getTopics
|
TopicTree |
getTopicTree()
Get the Topic Tree.
|
boolean |
hasProperty(String key)
Indicates whether a property with the given name has been configured for
this publisher
|
boolean |
hasServerConnection(String name)
Deprecated.
since 5.9 - See
PublisherServerConnection |
protected void |
initialLoad()
This is called when the publisher is started to perform initial publisher
load actions as required.
|
boolean |
isStarted()
Indicates whether the publisher is in a 'started' state.
|
boolean |
isStatisticsEnabled()
Indicates whether Statistics reporting for this Publisher is enabled or
not.
|
protected boolean |
isStoppable()
Can we stop this publisher?
|
boolean |
isTopicAliasing()
Is this publisher topic aliasing?
|
protected void |
messageFromClient(TopicMessage message,
Client client)
This is called when a message has been received from a client.
|
protected void |
messageFromServer(ServerConnection serverConnection,
TopicMessage message)
Notification of a message from another Server.
|
void |
messageNotAcknowledged(TopicMessage message,
List<TopicClient> clients)
This is a notification of non acknowledgement of a message that required
acknowledgement by one or more Clients.
|
String |
processHTMLTag(String tagID,
HTTPRequest details)
This method is call when a "DiffusionTag" comment is found in a web page
which identifies the Publisher.
|
protected void |
publisherRemoved()
Called when the publisher is finally removed from the system.
|
protected void |
publisherStarted()
This is called to notify that the Publisher has been started.
|
protected void |
publisherStopped()
Called when when publisher is stopped.
|
protected void |
publisherStopping()
Called when when publisher stop request has been received but its topics
have not yet been removed.
|
void |
publishExclusiveMessage(TopicMessage message,
TopicClient client)
A variant of
TopicProvider.publishMessage(TopicMessage) that publishes a
message to all but one client. |
void |
publishExclusiveMessage(TopicMessage message,
TopicClient client,
MessagePriority priority)
A variant of
TopicProvider.publishMessage(TopicMessage) that publishes a
message to all but one client and allows the message priority to be
specified. |
void |
publishMessage(TopicMessage message)
Publish a message to all clients that are subscribed to the topic of the
message.
|
void |
publishMessage(TopicMessage message,
MessagePriority priority)
A variant of
TopicProvider.publishMessage(TopicMessage) that allows the
message priority to be specified. |
boolean |
removeClientGroup(String groupName)
Remove a named client group.
|
boolean |
removeServerConnection(String name)
Deprecated.
since 5.9 - See
PublisherServerConnection |
boolean |
removeTopic(String topicName)
Remove topic
|
boolean |
removeTopicListener(TopicListener topicListener)
Removes a
TopicListener . |
boolean |
removeTopicLoader(TopicLoader topicLoader)
removeTopicLoader
|
TopicSet |
removeTopics(TopicSet topics)
Remove topics
|
protected void |
serverConnected(ServerConnection serverConnection)
Notification of Connection to a remote server.
|
protected void |
serverDisconnected(ServerConnection serverConnection)
Notification of disconnection.
|
protected void |
serverRejectedCredentials(ServerConnection serverConnection,
Credentials credentials)
This is called when Credentials have been sent to the Server (using
ServerConnection.sendCredentials(Credentials) ) but the Server has
rejected the credentials. |
protected void |
serverTopicStatusChanged(ServerConnection serverConnection,
String topicName,
TopicStatus status)
Notification that the status of a Topic that was subscribed to has
changed.
|
void |
setAckTimeout(long ackTimeout)
Sets the (default) ACK timeout value for messages that require
Acknowledgment.
|
void |
setLogger(LogWriter logWriter)
Set logger
|
void |
startPublisher()
Starts the publisher.
|
void |
startStatistics()
Starts the collection of this Publisher's statistics.
|
void |
stopPublisher()
Stops the publisher.
|
void |
stopStatistics()
Stops the collection of this Publisher's statistics.
|
void |
subscribeClients(Topic topic)
Subscribe all connected clients to a specified topic.
|
void |
subscribeClients(Topic topic,
boolean force)
Deprecated.
|
protected void |
subscription(Client client,
Topic topic,
boolean loaded)
This method is called when a client subscribes to a topic.
|
protected void |
systemStarted()
This is called when the System as a whole has started.
|
protected void |
unsubscription(Client client,
Topic topic)
This is called when a client unsubscribes from one of the publisher's
topics.
|
public final String getPublisherName()
getPublisherName
in class com.pushtechnology.diffusion.publisher.BasePublisher
public final TopicSet getInitialTopicSet()
getInitialTopicSet
in class com.pushtechnology.diffusion.publisher.BasePublisher
public final TopicTree getTopicTree()
com.pushtechnology.diffusion.publisher.BasePublisher
getTopicTree
in interface TopicProvider
getTopicTree
in class com.pushtechnology.diffusion.publisher.BasePublisher
public final Topic addTopic(String topicName) throws TopicInvalidException
TopicProvider
addTopic
in interface TopicProvider
topicName
- the name of the Topic. If the name is a hierarchical
name and the intermediate level Topics do not exist then they will
also be created. Topic names may contain any UTF-8 compatible
characters except ',' and any character used as a metacharacter in
a regular expression Pattern
.TopicInvalidException
- if unable to create a Topic of the given
name, possibly because one already exists or a parent Topic is
owned by a different Topic Provider.public final Topic addTopic(String topicName, TopicTreeNode parent) throws TopicInvalidException
TopicProvider
addTopic
in interface TopicProvider
topicName
- the name of the Topic within its parent. The actual
Topic name will become the hierarchic name of the parent plus this
name (e.g. parent/name). If the name is a hierarchical name and
the intermediate level Topics do not exist then they will also be
created. Topic names may contain any UTF-8 compatible characters
except ',' and any character used as a metacharacter in a regular
expression Pattern
.parent
- the parent node within the Topic tree. If this is specified
as null then it is same as calling TopicProvider.addTopic(String)
.TopicInvalidException
- if unable to create a Topic of the given
name within the specified parent node, possibly because the name
is invalid or a Topic with the same name already exists or a
parent Topic is owned by a different Topic Provider.public final Topic addTopic(String topicName, TopicDefinition definition) throws TopicInvalidException, APIException
TopicProvider
This version specifies a definition object and may be used when it is required to set some or all attributes of the Topic when it is constructed. For example, the definition can fully specify the Topic Data required.
addTopic
in interface TopicProvider
topicName
- the name of the Topic. If the name is a hierarchical
name and the intermediate level Topics do not exist then they will
also be created. Topic names may contain any UTF-8 compatible
characters except ',' and any character used as a metacharacter in
a regular expression Pattern
.definition
- the definition of the TopicTopicInvalidException
- if the specified topic name is invalidAPIException
- if unable to create a Topic possibly because one
already exists or some aspect of the definition is invalid.public final Topic addTopic(String topicName, TopicTreeNode parent, TopicDefinition definition) throws TopicInvalidException, APIException
TopicProvider
This version specifies a definition object and may be used when it is required to some or all attributes of the Topic when it is constructed. For example, the Topic Data required can be specified by the definition.
addTopic
in interface TopicProvider
topicName
- the name of the Topic within its parent. The actual
Topic name will become the hierarchic name of the parent plus this
name (e.g. parent/name). If the name is a hierarchical name and
the intermediate level Topics do not exist then they will also be
created. Topic names may contain any UTF-8 compatible characters
except ',' and any character used as a metacharacter in a regular
expression Pattern
.parent
- the parent node within the Topic tree. If this is specified
as null then it is same as calling TopicProvider.addTopic(String)
.definition
- the Topic definitionTopicInvalidException
- if the specified topic name is invalidAPIException
- if unable to create a Topic possibly because one
already exists or some aspect of the definition is invalid.public final Topic addTopic(String topicName, TopicData data) throws TopicInvalidException, APIException
TopicProvider
addTopic
in interface TopicProvider
topicName
- the name of the Topic. If the name is a hierarchical
name and the intermediate level Topics do not exist then they will
also be created. Topic names may contain any UTF-8 compatible
characters except ',' and any character used as a metacharacter in
a regular expression Pattern
.data
- the Topic Data.TopicInvalidException
- if topic name is invalid.APIException
- if unable to add the data to the Topicpublic final Topic addTopic(String topicName, TopicTreeNode parent, TopicData data) throws TopicInvalidException, APIException
TopicProvider
addTopic
in interface TopicProvider
topicName
- the name of the Topic within its parent. The actual
Topic name will become the hierarchic name of the parent plus this
name (e.g. parent/name). If the name is a hierarchical name and
the intermediate level Topics do not exist then they will also be
created. Topic names may contain any UTF-8 compatible characters
except ',' and any character used as a metacharacter in a regular
expression Pattern
.parent
- the parent node within the Topic tree. If this is specified
as null then it is same as calling TopicProvider.addTopic(String)
.data
- the Topic Data.TopicInvalidException
- if topic name is invalid.APIException
- if unable to add the Topic.public final void addTopics(TopicSet topics, TopicTreeNode parent) throws TopicInvalidException
TopicProvider
This is the same as repeatedly calling
TopicProvider.addTopic(String, TopicTreeNode)
for each Topic name within the
set except all Topic names are validated before any are added. Duplicates
are ignored.
addTopics
in interface TopicProvider
topics
- a set of Topic names to add.parent
- the parent node.TopicInvalidException
- if unable to add Topics.public final void addTopics(TopicSet topics) throws TopicInvalidException
TopicProvider
This is the same as repeatedly calling TopicProvider.addTopic(String)
for each
Topic name within the set except all Topic names are validated before any
are added. Duplicates are ignored.
addTopics
in interface TopicProvider
topics
- a set of Topic names to add.TopicInvalidException
- if unable to add Topics.public final boolean removeTopic(String topicName)
com.pushtechnology.diffusion.publisher.BasePublisher
removeTopic
in interface TopicProvider
removeTopic
in class com.pushtechnology.diffusion.publisher.BasePublisher
topicName
- the full hierarchic Topic name.public final TopicSet removeTopics(TopicSet topics)
com.pushtechnology.diffusion.publisher.BasePublisher
removeTopics
in interface TopicProvider
removeTopics
in class com.pushtechnology.diffusion.publisher.BasePublisher
topics
- a set of Topics.public final List<Topic> getTopics()
com.pushtechnology.diffusion.publisher.BasePublisher
getTopics
in interface TopicProvider
getTopics
in class com.pushtechnology.diffusion.publisher.BasePublisher
public final Topic getTopic(String topicName)
com.pushtechnology.diffusion.publisher.BasePublisher
getTopic
in interface TopicProvider
getTopic
in class com.pushtechnology.diffusion.publisher.BasePublisher
topicName
- the Topic namepublic final Topic getTopic(TopicMessage message)
TopicProvider
getTopic
in interface TopicProvider
message
- the message.public final int getNumberOfTopics()
com.pushtechnology.diffusion.publisher.BasePublisher
getNumberOfTopics
in interface TopicProvider
getNumberOfTopics
in class com.pushtechnology.diffusion.publisher.BasePublisher
public final void addTopicLoader(TopicLoader topicLoader, String topicPattern) throws TopicInvalidException
com.pushtechnology.diffusion.publisher.BasePublisher
addTopicLoader
in interface TopicProvider
addTopicLoader
in class com.pushtechnology.diffusion.publisher.BasePublisher
topicLoader
- the Topic Loader to add.topicPattern
- the Topic name or selector pattern that indicates
which Topics the Topic Loader applies to.TopicInvalidException
- if the supplied topicPattern is not a valid
Topic name or selector pattern.public final boolean removeTopicLoader(TopicLoader topicLoader)
com.pushtechnology.diffusion.publisher.BasePublisher
removeTopicLoader
in interface TopicProvider
removeTopicLoader
in class com.pushtechnology.diffusion.publisher.BasePublisher
topicLoader
- the Topic Loader to remove.public final TopicLoader getTopicLoader(String topicName)
com.pushtechnology.diffusion.publisher.BasePublisher
getTopicLoader
in interface TopicProvider
getTopicLoader
in class com.pushtechnology.diffusion.publisher.BasePublisher
topicName
- the Topic name.public final boolean isTopicAliasing()
com.pushtechnology.diffusion.publisher.BasePublisher
isTopicAliasing
in interface TopicProvider
isTopicAliasing
in class com.pushtechnology.diffusion.publisher.BasePublisher
public final void subscribeClients(Topic topic)
TopicProvider
subscribeClients
in interface TopicProvider
subscribeClients
in class com.pushtechnology.diffusion.publisher.BasePublisher
topic
- the topic.@Deprecated public final void subscribeClients(Topic topic, boolean force)
TopicProvider
Passing true
for the force
parameter has the same effect
as TopicProvider.subscribeClients(Topic)
.
In previous releases,
automatic subscription
of clients to new topics was optional. Calling
this method with a false
value for the force
parameter
would cause client subscriptions to be re-evaluated against the topic.
Since 5.5, automatic subscription cannot be disabled, and calling this
method with force=false has no effect.
subscribeClients
in interface TopicProvider
subscribeClients
in class com.pushtechnology.diffusion.publisher.BasePublisher
topic
- the topic.force
- see above.public final void publishMessage(TopicMessage message) throws APIException
TopicProvider
Once a message is published it is locked and may no longer be changed.
publishMessage
in interface TopicProvider
message
- the message to publish.APIException
- if unable to publish the message.public final void publishExclusiveMessage(TopicMessage message, TopicClient client) throws APIException
TopicProvider
TopicProvider.publishMessage(TopicMessage)
that publishes a
message to all but one client.publishExclusiveMessage
in interface TopicProvider
message
- the message to publish.client
- the client not to send the message to.APIException
- if unable to publish the message.public final void publishMessage(TopicMessage message, MessagePriority priority) throws APIException
TopicProvider
TopicProvider.publishMessage(TopicMessage)
that allows the
message priority to be specified.publishMessage
in interface TopicProvider
message
- the message to publish.priority
- the priorityAPIException
- if unable to publish the message.public final void publishExclusiveMessage(TopicMessage message, TopicClient client, MessagePriority priority) throws APIException
TopicProvider
TopicProvider.publishMessage(TopicMessage)
that publishes a
message to all but one client and allows the message priority to be
specified.publishExclusiveMessage
in interface TopicProvider
message
- the message to publish.client
- the client not to send the message to.priority
- the priorityAPIException
- if unable to publish the message.public final PublisherStatistics getStatistics()
The returned PublisherStatistics
will become stale if statistics
recording is disabled (for example, if stopStatistics()
is
called). If publisher statistics recording is disabled when this method
is called, the PublisherStatistics
will return -1
for
each statistic value.
getStatistics
in class com.pushtechnology.diffusion.publisher.BasePublisher
protected void initialLoad() throws APIException
By default this does nothing and should be overridden to perform processing as required.
initialLoad
in class com.pushtechnology.diffusion.publisher.BasePublisher
APIException
- can be thrown to indicate some failure in the
initial server load.protected void systemStarted()
By default this does nothing and should be overridden to perform processing as required. Any exception thrown here will be ignored.
systemStarted
in class com.pushtechnology.diffusion.publisher.BasePublisher
protected void subscription(Client client, Topic topic, boolean loaded) throws APIException
For stateful topics (topics that have topic data), a topic load message
based on the topic data will have been sent to the client before this
method is called. The loaded
parameter will be true.
For stateless topics (topics that do not have topic data), this method is
called after any TopicLoader
found for the topic is invoked. The
loaded
parameter will be true if a matching TopicLoader was found
and a topic load message was sent.
In all cases, the topic is locked automatically while this method is called, and no topic updates will be sent to the client until this method returns. The publisher can use this method to send further initialisation messages to the client for the subscription. This provides a way to implement custom protocols for stateful topic streams, but requires additional client-side application code to interpret the messages. Generally, topic data is a simpler and more efficient way to implement stateful streams and should be preferred.
In Diffusion 5.6, the way subscriptions are evaluated was changed to
reduce locking and improve scalability. API calls to
Client#subscribe(...)
,
Topic.subscribeClients()
, or Topic.subscribe(TopicClient)
can result in new subscriptions. Applications should no longer assume the
subscriptions will be completed before the API call returns. The new
subscriptions might not be included in the results of immediate calls to
TopicClient.isSubscribed(Topic)
or Topic.getClients()
. Updates
immediately sent to the topic might not be broadcast to the client;
although when the subscription is completed, the initial load message
received by the client will reflect the updated topic state. The new
behavior is similar to the way that auto-subscriptions are evaluated
asynchronously when adding topics.
subscription
in class com.pushtechnology.diffusion.publisher.BasePublisher
client
- the client subscribing to the topic.topic
- the topic.loaded
- true if a topic load message has already been sent,
otherwise falseAPIException
- thrown to indicate that subscription fails and the
client should be unsubscribed from the topic@Deprecated protected TopicMessage fetchForClient(Client client, Topic topic, List<String> headers) throws APIException
This may be called as a result of a Client requesting a Topic 'fetch',
for example in the Client API calling
ExternalClientConnection.fetch(String, String...)
. Before this is called the
AuthorisationHandler.canFetch(Client, Topic)
will have been
called to ensure that the Client is permitted to fetch the Topic state.
A Client may not need to be subscribed to a Topic in order to fetch its
state. This will only be called if there was no other mechanism available
for fetching the Topic state. For example, if the Topic has
TopicData
then the state will be obtained from the Topic Data.
fetchForClient
in class com.pushtechnology.diffusion.publisher.BasePublisher
client
- the Client that has requested the Topic state.topic
- the Topic to fetch the state of.headers
- these are the headers that were sent with the request for
correlation purposes. These will be added to the reply message
(after any existing headers) anyway but are passed here for
information only.APIException
- if a failure occurs whilst fetching the stateprotected void unsubscription(Client client, Topic topic)
By default this does nothing but may be overridden if required.
unsubscription
in class com.pushtechnology.diffusion.publisher.BasePublisher
client
- the client that has unsubscribed.topic
- the topic that the client has unsubscribed from.protected void messageFromClient(TopicMessage message, Client client)
This should be overridden to provide the processing required when a message is received from a client.
Calls to this method will always present Messages in the order they were sent from the Client. Note that delegating processing of the Message to another thread could compromise that order.
messageFromClient
in class com.pushtechnology.diffusion.publisher.BasePublisher
message
- the message received.client
- the client.public void messageNotAcknowledged(TopicMessage message, List<TopicClient> clients)
ClientAckListener
messageNotAcknowledged
in interface ClientAckListener
message
- the message that was not acknowledged.clients
- a list of the Clients that did not acknowledge the
message.@Deprecated public final PublisherServerConnection addServerConnection(String name, String host, int port) throws APIException
PublisherServerConnection
A server connection is a connection to another Diffusion server.
addServerConnection
in class com.pushtechnology.diffusion.publisher.BasePublisher
name
- the name of the server connection, which must be unique for
this publisher. If not supplied then the server name is made up of
the host address and the port.host
- the server host address. If not supplied then 'localhost' is
assumed.port
- the port on which the server listens for publisher client
connections.APIException
- if unable to add the server connection. This may be
because there is already a server connection with the same name.@Deprecated public final PublisherServerConnection addServerConnection(String name, ServerDetails serverDetails) throws APIException
PublisherServerConnection
A server connection is a connection to another Diffusion server.
addServerConnection
in class com.pushtechnology.diffusion.publisher.BasePublisher
name
- the name of the server connection, which must be unique for
this publisher. If not supplied then the server name is made up of
the host address and the port.serverDetails
- the details of the server to connect to. This may be
standard TCP or TCP over SSL. Certain properties of the connection
(such as initial topics or whether Credentials
are
required) may be specified in the server details.APIException
- if unable to add the server connection. This may be
because there is already a server connection with the same name.@Deprecated public final boolean hasServerConnection(String name)
PublisherServerConnection
PublisherServerConnection
with the given name?
hasServerConnection
in class com.pushtechnology.diffusion.publisher.BasePublisher
name
- the server connection name.@Deprecated public final PublisherServerConnection getServerConnection(String name)
PublisherServerConnection
getServerConnection
in class com.pushtechnology.diffusion.publisher.BasePublisher
name
- the server connection name.@Deprecated public final boolean removeServerConnection(String name)
PublisherServerConnection
PublisherServerConnection
.
removeServerConnection
in class com.pushtechnology.diffusion.publisher.BasePublisher
name
- the server connection name.@Deprecated public final List<PublisherServerConnection> getServerConnections()
PublisherServerConnection
getServerConnections
in class com.pushtechnology.diffusion.publisher.BasePublisher
protected void messageFromServer(ServerConnection serverConnection, TopicMessage message)
messageFromServer
in class com.pushtechnology.diffusion.publisher.BasePublisher
serverConnection
- the Server connection.message
- the message which can be a topic load message or a delta
message.protected void serverTopicStatusChanged(ServerConnection serverConnection, String topicName, TopicStatus status)
serverTopicStatusChanged
in class com.pushtechnology.diffusion.publisher.BasePublisher
serverConnection
- the Server connection.topicName
- the name of the topic that has had a status change.status
- the new Topic status.protected void serverConnected(ServerConnection serverConnection)
This is called when a Server connection is made.
serverConnected
in class com.pushtechnology.diffusion.publisher.BasePublisher
serverConnection
- the Server connection.protected void serverRejectedCredentials(ServerConnection serverConnection, Credentials credentials)
ServerConnection.sendCredentials(Credentials)
) but the Server has
rejected the credentials.
serverRejectedCredentials
in class com.pushtechnology.diffusion.publisher.BasePublisher
serverConnection
- the Server connection.credentials
- the credentials that were rejected. notification.protected void serverDisconnected(ServerConnection serverConnection)
The reason for the disconnection can be established by checking the state
of the connection using ServerConnection.getState()
serverDisconnected
in class com.pushtechnology.diffusion.publisher.BasePublisher
serverConnection
- the server connection.public final void addTopicListener(TopicListener topicListener, MessageSourceType sourceType, String... topics) throws APIException
TopicListener
.
This allows inbound messages to be routed to one or more recipient objects according to the message Topic. Messages are routed to listeners in the order that they were declared and before routing to the standard method. Each listener will receive a different copy of the Message.
A topic listener can be declared for each Topic or can apply to more than
one Topic by using Topic selector patterns, see TopicSet
for full
details of how to use Topic selector patterns. Also, any number of
listeners may be specified for any one topic or selector pattern.
Topic listeners may be added for Topics at any time, even before the Topic itself is added.
Any listener may choose to consume the Message in which case it will not be passed on to any other listener, or to the standard method.
addTopicListener
in class com.pushtechnology.diffusion.publisher.BasePublisher
topicListener
- the topic listener.sourceType
- the type of source from which the listener will handle
messages.topics
- a list of full topic names and/or Topic selector patterns.APIException
- if unable to add the topic listenerpublic final void addTopicListener(TopicListener topicListener, MessageSourceType sourceType, TopicSet topics) throws APIException
TopicListener
.
addTopicListener
in class com.pushtechnology.diffusion.publisher.BasePublisher
topicListener
- the topic listener.sourceType
- the type of source from which the listener will handle
messages.topics
- a set of full topic names and/or Topic selector patterns.APIException
- if unable to add the topic listeneraddTopicListener(TopicListener, MessageSourceType, String...)
public final boolean removeTopicListener(TopicListener topicListener)
TopicListener
.
All uses of the given listener are removed.
removeTopicListener
in class com.pushtechnology.diffusion.publisher.BasePublisher
topicListener
- the topic listenerpublic final boolean hasProperty(String key)
key
- the property name or keypublic final String getProperty(String key)
This would be the equivalent of obtaining the publisher configuration
using getConfig()
and then calling
PublisherConfig.getPropertyValue(String)
key
- the property keypublic final int getIntegerProperty(String key) throws PropertyException
key
- the property key (without the publisher prefix).PropertyException
- if the property was not found or the property
was found but could not be parsed as an integer.public final boolean getBooleanProperty(String key) throws PropertyException
key
- the property key (without the publisher prefix).PropertyException
- if the property was not found or the property
was found but could not be parsed as an boolean.public final long getMillisProperty(String key) throws PropertyException
key
- the property key (without the publisher prefix).PropertyException
- if the property was not found or the property
was found but could not be parsed as a time.public final int getBytesProperty(String key) throws PropertyException
key
- the property key (without the publisher prefix).PropertyException
- if the property was not found or the property
was found but could not be parsed as a bytes value.public final LogWriter getLogger()
getLogger
in class com.pushtechnology.diffusion.publisher.BasePublisher
public final void setLogger(LogWriter logWriter)
setLogger
in class com.pushtechnology.diffusion.publisher.BasePublisher
logWriter
- the loggerpublic final void startPublisher() throws APIException
startPublisher
in class com.pushtechnology.diffusion.publisher.BasePublisher
APIException
- if failed to start.public String processHTMLTag(String tagID, HTTPRequest details)
For example:
<!--@DiffusionTag publisher="Trade" tagid="table" -->
It is the responsibility of this method to return a valid String of HTML which will be inserted at the end of the tag comment.
tagID
- the tag identifier.details
- the HTTP Request detailsprotected void publisherStarted() throws APIException
This is called when the publisher is first started and also when the publisher is restarted after being stopped. When a publisher is restarted it will have only the initial topics that it was started with and any others must be added by the publisher.
publisherStarted
in class com.pushtechnology.diffusion.publisher.BasePublisher
APIException
- can be thrown to indicate a failure in the
processing of the publisher started notification.public final boolean isStarted()
isStarted
in class com.pushtechnology.diffusion.publisher.BasePublisher
protected boolean isStoppable()
It is possible to allow a publisher to be stopped and restarted again but in order for this to work the publisher must be able to handle it. One effect of a 'stop' is to remove all topics and so for a publisher to be stopped it must consider how it could be restarted and may want to re-establish its root topic (for example).
If a publisher can handle being stopped then it must override this method to return true, otherwise stop will be disabled.
isStoppable
in class com.pushtechnology.diffusion.publisher.BasePublisher
public final void stopPublisher() throws APIException
stopPublisher
in class com.pushtechnology.diffusion.publisher.BasePublisher
APIException
- if the publisher can not be stopped (i.e stopping is
prohibited - only removal of the publisher is valid).protected void publisherStopping() throws APIException
publisherStopping
in class com.pushtechnology.diffusion.publisher.BasePublisher
APIException
- can be thrown to indicate a failure in the
processing of the publisher stopping notification.protected void publisherStopped() throws APIException
Note that when a publisher is stopped it should suspend processing until
it is restarted (notified via publisherStarted()
).
publisherStopped
in class com.pushtechnology.diffusion.publisher.BasePublisher
APIException
- can be thrown to indicate a failure in the
processing of the publisher stopped notification.protected void publisherRemoved() throws APIException
This may be used to perform any final release of resources.
publisherRemoved
in class com.pushtechnology.diffusion.publisher.BasePublisher
APIException
- can be thrown to indicate a failure in the
processing.public final void startStatistics()
If Statistics reporting is enabled, this will start the collection of statistics specific to this Publisher if they are not already running.
startStatistics
in class com.pushtechnology.diffusion.publisher.BasePublisher
public final void stopStatistics()
If statistics collection for this Publisher has been enabled, this will discard the statistics and stop further values from being recorded.
stopStatistics
in class com.pushtechnology.diffusion.publisher.BasePublisher
public final boolean isStatisticsEnabled()
By default this will be false, unless '
isStatisticsEnabled
in class com.pushtechnology.diffusion.publisher.BasePublisher
public final List<TopicClient> getClients(Topic topic)
getClients
in class com.pushtechnology.diffusion.publisher.BasePublisher
topic
- the topic.public final ClientGroup createClientGroup(String groupName) throws APIException
com.pushtechnology.diffusion.publisher.BasePublisher
createClientGroup
in interface TopicProvider
createClientGroup
in class com.pushtechnology.diffusion.publisher.BasePublisher
groupName
- the group nameAPIException
- if group already exists.public final ClientGroup getClientGroup(String groupName)
com.pushtechnology.diffusion.publisher.BasePublisher
getClientGroup
in interface TopicProvider
getClientGroup
in class com.pushtechnology.diffusion.publisher.BasePublisher
groupName
- the group name.public final List<String> getClientGroupMembership(TopicClient client)
com.pushtechnology.diffusion.publisher.BasePublisher
getClientGroupMembership
in interface TopicProvider
getClientGroupMembership
in class com.pushtechnology.diffusion.publisher.BasePublisher
client
- the client to enquire upon.public final boolean removeClientGroup(String groupName)
com.pushtechnology.diffusion.publisher.BasePublisher
removeClientGroup
in interface TopicProvider
removeClientGroup
in class com.pushtechnology.diffusion.publisher.BasePublisher
groupName
- the group name.public final TopicMessage createLoadMessage(String topicName) throws MessageException
TopicProvider
This is a convenience method equivalent to calling
Topic.createLoadMessage()
on an existing Topic. This can also be
used to create a message for a Topic that does not exist as it is
permitted to send fetch replies for non existent Topics.
createLoadMessage
in interface TopicProvider
topicName
- the topic name.MessageException
- if unable to create a message.public final TopicMessage createLoadMessage(String topicName, int capacity) throws MessageException
TopicProvider
This is a convenience method equivalent to calling
Topic.createLoadMessage(int)
on a existing Topic. This can also
be used to create a message for a Topic that does not exist as it is
permitted to send fetch replies for non existent Topics.
createLoadMessage
in interface TopicProvider
topicName
- the topic name.capacity
- the initial capacity of the message which should be
sufficient to hold the data and any user headers. If more is
written to the message than this then it will automatically be
extended, however there is an overhead to such extensions so for
maximum efficiency a suitable capacity should be chosen.MessageException
- if unable to create a message.public final TopicMessage createDeltaMessage(String topicName) throws MessageException
TopicProvider
This is a convenience method equivalent to calling
Topic.createDeltaMessage()
on the Topic.
createDeltaMessage
in interface TopicProvider
topicName
- the topic name.MessageException
- if unable to create a new message.public final TopicMessage createDeltaMessage(String topicName, int capacity) throws MessageException
TopicProvider
This is a convenience method equivalent to calling
Topic.createDeltaMessage(int)
on the Topic.
createDeltaMessage
in interface TopicProvider
topicName
- the topic name.capacity
- the initial capacity of the message which should be
sufficient to hold the data and any user headers. If more is
written to the message than this then it will automatically be
extended, however there is an overhead to such extensions so for
maximum efficiency a suitable capacity should be chosen.MessageException
- if unable to create a new message.public final long getAckTimeout()
TopicProvider
getAckTimeout
in interface TopicProvider
public final void setAckTimeout(long ackTimeout)
TopicProvider
The ACK timeout is the number of milliseconds allowed between sending a
message with acknowledgment required (see
TopicMessage.setAckRequired()
) and acknowledgment being received
by the provider. If acknowledgment is not received within this time then
the provider will be notified via the ClientAckListener
interface.
This value is used if the timeout value is not explicitly set for the
message using TopicMessage.setAckTimeout(long)
.
If no value is explicitly specified for a provider then a default value is assumed.
setAckTimeout
in interface TopicProvider
ackTimeout
- the default ACK timeout value in milliseconds.public final PublisherConfig getConfig()
getConfig
in class com.pushtechnology.diffusion.publisher.BasePublisher
Copyright © 2016 Push Technology Ltd. All Rights Reserved.