diffusion
Version:
Diffusion JavaScript client
258 lines (245 loc) • 10.5 kB
JavaScript
var TopicType = require('./topic-type');
var TopicSpecification = require('./topic-specification');
var FetchRequest = require('./fetch-request').FetchRequest;
/**
* Provide access to {@link diffusion.topics.TopicType TopicType},
* {@link diffusion.topics.TopicSpecification TopicSpecification}, and
* {@link diffusion.topics.UnsubscribeReason UnsubscribeReason}
* @namespace diffusion.topics
*/
module.exports.TopicType = TopicType;
module.exports.TopicSpecification = TopicSpecification;
module.exports.FetchRequest = FetchRequest;
function UnsubscribeReason(id, reason) {
this.id = id;
this.reason = reason;
}
/**
* Enum containing reasons that an unsubscription occurred.
*
* @example
* // Use UnsubscribeReason to validate unsubscription notifications
* session.subscribe(">foo").on('unsubscribe', function(reason, topic) {
* switch (reason) {
* case diffusion.topics.UnsubscribeReason.REMOVED :
* // Do something if the topic was removed
* default :
* // Do something else if the client was explicitly unsubscribed
* }
* });
*
* @readonly
* @enum
* @memberOf diffusion.topics
* @alias UnsubscribeReason
*/
module.exports.UnsubscribeReason = {
/**
* The server has re-subscribed this session to the topic. Existing
* streams are unsubscribed because the topic type and other attributes
* may have changed.
*
* <p>
* This can happen if a set of servers are configured to use session
* replication, and the session connected to one server reconnects
* ("fails over") to a different server.
*
* <p>
* A stream that receives an unsubscription notification with this
* reason will also receive a subscription notification with the new
* {@link TopicSpecification} or {@link TopicDetails}.
*
* @since 5.9
*/
SUBSCRIPTION_REFRESH : new UnsubscribeReason(undefined, "The server has re-subscribed this session"),
/**
* A fallback stream has been unsubscribed or subscribed due to the
* addition or removal of a stream that selects the topic.
*
* @since 5.9
*/
STREAM_CHANGE : new UnsubscribeReason(undefined, "A more specific stream has been registered to the same path"),
/**
* The unsubscription was requested by this client.
*/
REQUESTED : new UnsubscribeReason(0, "The unsubscription was requested by this client"),
/**
* The server or another client unsubscribed this client.
*/
CONTROL : new UnsubscribeReason(1, "The server or another client unsubscribed this client"),
/**
* The topic was removed
*/
REMOVED : new UnsubscribeReason(2, "The topic was removed"),
/**
* The unsubscription occurred because the session is no longer authorized to access the topic.
* @since 5.9
*/
AUTHORIZATION : new UnsubscribeReason(3, "Not authorized to subscribe to this topic")
};
function UpdateFailReason(id, reason) {
this.id = id;
this.reason = reason;
}
/**
* The reason that a topic could not be updated.
*
* @example
* session.topics.update("foo", "bar").then(function() { ... }, function(err) {
* switch (err) {
* case diffusion.topics.UpdateFailReason.MISSING_TOPIC:
* ...
* case diffusion.topics.UpdateFailReason.EXCLUSIVE_UPDATER_CONFLICT:
* ...
* }
* });
*
* @readonly
* @enum
* @memberof diffusion.topics
* @alias UpdateFailReason
*/
module.exports.UpdateFailReason = {
/**
* The update was of a type that is not compatible with the topic it was submitted for, or
* the topic does not support updating.
*/
INCOMPATIBLE_UPDATE: new UpdateFailReason(1, "Update type is incompatible with topic type"),
/**
* The update failed, possibly because the content sent with the update was invalid/incompatible with topic type or
* data format.
*/
UPDATE_FAILED: new UpdateFailReason(2, "Update failed - possible content incompatibility"),
/**
* The updater used is not active.
*/
INVALID_UPDATER: new UpdateFailReason(3, "Updater is invalid for updating"),
/**
* The topic being updated does not exist.
*/
MISSING_TOPIC: new UpdateFailReason(4, "Topic does not exist"),
/**
* Invalid key or index used for addressing topic content.
*/
INVALID_ADDRESS: new UpdateFailReason(5, "Key or index value is invalid for topic data"),
/**
* Violation of content duplication restrictions.
*/
DUPLICATES: new UpdateFailReason(6, "Duplicates violation"),
/**
* Attempt to perform a non-exclusive update to a topic branch that already has an update source registered to it.
*/
EXCLUSIVE_UPDATER_CONFLICT:
new UpdateFailReason(7, "An exclusive update source is already registered for the topic branch"),
/**
* An attempt has been made to apply a delta to a topic that has not yet has a value specified for it.
*/
DELTA_WITHOUT_VALUE:
new UpdateFailReason(8, "An attempt has been made to apply a delta to a topic that does not yet have a value"),
/**
* An update to a replicated topic failed because the cluster was
* repartitioning due to a server starting, stopping, or failing. The
* session can retry the operation.
*/
CLUSTER_REPARTITION: new UpdateFailReason(
9, "When trying to update the topic the cluster was migrating the partition that owns the topic"),
/**
* An update could not be performed because the topic is managed by a
* component (e.g fan-out) that prohibits updates from the caller.
*/
INCOMPATIBLE_STATE: new UpdateFailReason(
10, "An update could not be performed because the topic is managed by" +
"a component (e.g fan-out) that prohibits updates from the caller")
};
function TopicAddFailReason(id, reason) {
this.id = id;
this.reason = reason;
}
/**
* The reason that a topic could not be added.
*
* @example
* session.topics.add("foo").then(function() { ... }, function(err) {
* switch (err) {
* case diffusion.topics.TopicAddFailReason.EXISTS:
* ...
* case diffusion.topics.TopicAddFailReason.INVALID_PATH:
* ...
* }
* });
*
* @readonly
* @enum
* @memberOf diffusion.topics
* @alias TopicAddFailReason
*/
module.exports.TopicAddFailReason = {
/** The topic already exists with the same details. */
EXISTS: new TopicAddFailReason(1, "The topic already exists with the same details"),
/** The topic already exists, with different details. */
EXISTS_MISMATCH: new TopicAddFailReason(2, "The topic already exists, with different details"),
/** The topic path is invalid. */
INVALID_PATH: new TopicAddFailReason(3, "The topic path is invalid"),
/** The topic details are invalid. */
INVALID_DETAILS: new TopicAddFailReason(4, "The topic details are invalid"),
/** A user supplied class could not be found or instantiated.
* <b>Deprecation notice</b>
* <P>
* This value is associated only with removed methods that create topics.
* It will be removed in a future release.
*
* @deprecated Since 6.2
*/
USER_CODE_ERROR: new TopicAddFailReason(5, "A user supplied class could not be found or instantiated"),
/** A referenced topic could not be found. */
TOPIC_NOT_FOUND: new TopicAddFailReason(6, "A referenced topic could not be found"),
/** Invalid permissions to add a topic at the specified path. */
PERMISSIONS_FAILURE: new TopicAddFailReason(7, "Invalid permissions to add a topic at the specified path"),
/** The topic could not be initialised, supplied value may be of the wrong format.
* <b>Deprecation notice</b>
* <P>
* This value is associated only with removed methods that
* allow the specification of an initial value when creating a
* topic. It will be removed in a future release.
*
* @deprecated Since 6.1
*/
INITIALISE_ERROR:
new TopicAddFailReason(8, "The topic could not be initialised, supplied value may be of the wrong format"),
/** An unexpected error occured while creating the topic. */
UNEXPECTED_ERROR: new TopicAddFailReason(9, "An unexpected error occured while creating the topic"),
/** When trying to create the topic the cluster was migrating the partition
* that owns the topic. The correct owner could not be identified and the
* request failed. This is a transient failure for the duration of the
* partition migration. */
CLUSTER_REPARTITION: new TopicAddFailReason(
10, "When trying to create the topic the cluster was migrating the partition that owns the topic"),
/** Adding the topic failed because of a license limit. */
EXCEEDED_LICENSE_LIMIT: new TopicAddFailReason(
11, "Adding the topic failed because of a license limit"),
/** Adding the topic failed because a topic owned by a publisher is already bound to the parent path. */
INCOMPATIBLE_PARENT: new TopicAddFailReason(
12, "Adding the topic failed because a topic owned by a publisher is already bound to the parent path"),
/** Adding a slave topic failed because a topic owned by a publisher is
* already bound to the specified master path. */
INCOMPATIBLE_MASTER: new TopicAddFailReason(
13, "Adding a slave topic failed because a topic owned by a publisher" +
"is already bound to the specified master path."),
/**
* Adding the topic failed because a topic is already bound to the specified
* path but the caller does not have the rights to manage it.
* <P>
* This can be because the topic is being managed by a component with
* exclusive control over the topic, such as fan-out or a publisher and thus
* the caller will not be able to update or remove the topic.
* <P>
* If the caller has suitable permissions then it could still subscribe to
* the topic, but the topic's specification may be different from that
* requested.
*/
EXISTS_INCOMPATIBLE: new TopicAddFailReason(
14, "Adding the topic failed because a topic is already bound to the specified" +
"path but the caller does not have the rights to manage it"),
/** The supplied topic path is invalid. */
INVALID_NAME: new TopicAddFailReason(15, "The supplied topic path is invalid."),
};