All Downloads are FREE. Search and download functionalities are using the official Maven repository.

joynr.OnChangeWithKeepAliveSubscriptionQos Maven / Gradle / Ivy

package joynr;

/*
 * #%L
 * %%
 * Copyright (C) 2011 - 2016 BMW Car IT GmbH
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import io.joynr.pubsub.HeartbeatSubscriptionInformation;
import io.joynr.pubsub.SubscriptionQos;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * Class representing the quality of service settings for subscriptions
 * based on changes and time periods
 * 
* This class stores quality of service settings used for subscriptions to * attributes in generated proxy objects. Using it for subscriptions to * broadcasts is theoretically possible because of inheritance but makes no * sense (in this case the additional members will be ignored). *
* Notifications will be sent if the subscribed value has changed or a time * interval without notifications has expired. The subscription will * automatically expire after the expiry date is reached. If no publications * were received for alertAfter Interval, publicationMissed will be called. *
* minInterval can be used to prevent too many messages being sent. */ public class OnChangeWithKeepAliveSubscriptionQos extends OnChangeSubscriptionQos implements HeartbeatSubscriptionInformation { private static final long serialVersionUID = 1L; private static final Logger logger = LoggerFactory.getLogger(OnChangeWithKeepAliveSubscriptionQos.class); private static final long MIN_MAX_INTERVAL_MS = 50L; private static final long MAX_MAX_INTERVAL_MS = 2592000000L; // 30 days private static final long DEFAULT_MAX_INTERVAL_MS = 60000L; // 1 minute private static final long NO_ALERT_AFTER_INTERVAL = 0; private static final long DEFAULT_ALERT_AFTER_INTERVAL_MS = NO_ALERT_AFTER_INTERVAL; private static final long MAX_ALERT_AFTER_INTERVAL_MS = 2592000000L; // 30 days private long maxIntervalMs = DEFAULT_MAX_INTERVAL_MS; private long alertAfterIntervalMs = NO_ALERT_AFTER_INTERVAL; /** * Default Constructor */ public OnChangeWithKeepAliveSubscriptionQos() { } /** * @deprecated This constructor will be deleted by 2017-01-01. * Use the fluent interface instead. * * Constructor of OnChangeWithKeepAliveSubscriptionQos object with specified * minInterval, maxInterval, and expiry date. * * @param minIntervalMs * defines how often an update may be sent * @param maxIntervalMs * defines how long to wait before sending an update even if the * value did not change * @param expiryDateMs * how long is the subscription valid * * @see OnChangeSubscriptionQos#OnChangeSubscriptionQos(long, long, long) * OnChangeSubscriptionQos.OnChangeSubscriptionQos(long, long, long) * for more information about minInterval * @see #setMaxInterval(long) * @see SubscriptionQos#SubscriptionQos(long, long) * SubscriptionQos.SubscriptionQos(long, long) * for more information on expiryDate and publicationTtl * (publicationTtl will be set to its default value) * @see #setAlertAfterIntervalMs(long) * (alertAfterInterval will be set to its default value) */ @Deprecated public OnChangeWithKeepAliveSubscriptionQos(long minIntervalMs, long maxIntervalMs, long expiryDateMs) { this(minIntervalMs, maxIntervalMs, expiryDateMs, DEFAULT_ALERT_AFTER_INTERVAL_MS, SubscriptionQos.DEFAULT_PUBLICATION_TTL_MS); } /** * @deprecated This constructor will be deleted by 2017-01-01. * Use the fluent interface instead. * * Constructor of OnChangeWithKeepAliveSubscriptionQos object with specified * minInterval, maxInterval, expiry date, and alertAfterInterval. * * @param minIntervalMs * defines how often an update may be sent * @param maxIntervalMs * defines how long to wait before sending an update even if the * value did not change * @param expiryDateMs * how long is the subscription valid * @param alertAfterIntervalMs * defines how long to wait for an update before publicationMissed * is called if no publications were received. * * @see OnChangeSubscriptionQos#OnChangeSubscriptionQos(long, long, long) * OnChangeSubscriptionQos.OnChangeSubscriptionQos(long, long, long) * for more information about minInterval * @see #setMaxInterval(long) * @see SubscriptionQos#SubscriptionQos(long, long) * SubscriptionQos.SubscriptionQos(long, long) * for more information on expiryDate and publicationTtl * (publicationTtl will be set to its default value) * @see #setAlertAfterIntervalMs(long) */ @Deprecated public OnChangeWithKeepAliveSubscriptionQos(long minIntervalMs, long maxIntervalMs, long expiryDateMs, long alertAfterIntervalMs) { this(minIntervalMs, maxIntervalMs, expiryDateMs, alertAfterIntervalMs, SubscriptionQos.DEFAULT_PUBLICATION_TTL_MS); } /** * Constructor of OnChangeWithKeepAliveSubscriptionQos object with specified * minInterval, maxInterval, expiry date, alertAfterInterval, and * publicationTtl (full parameter set). * * @param minIntervalMs * defines how often an update may be sent * @param maxIntervalMs * defines how long to wait before sending an update even if the * value did not change * @param expiryDateMs * how long is the subscription valid * @param alertAfterIntervalMs * defines how long to wait for an update before publicationMissed * is called if no publications were received. * @param publicationTtlMs * time to live for publication messages * * @see OnChangeSubscriptionQos#OnChangeSubscriptionQos(long, long, long) * OnChangeSubscriptionQos.OnChangeSubscriptionQos(long, long, long) * for more information about minInterval * @see #setMaxInterval(long) * @see SubscriptionQos#SubscriptionQos(long, long) * SubscriptionQos.SubscriptionQos(long, long) * for more information on expiryDate and publicationTtl * @see #setAlertAfterIntervalMs(long) */ @Deprecated public OnChangeWithKeepAliveSubscriptionQos(long minIntervalMs, long maxIntervalMs, long expiryDateMs, long alertAfterIntervalMs, long publicationTtlMs) { super(minIntervalMs, expiryDateMs, publicationTtlMs); setMaxIntervalMs(maxIntervalMs); setAlertAfterIntervalMs(alertAfterIntervalMs); } /** * @deprecated Use getMaxIntervalMs instead * * Get the maximum interval in milliseconds. *
* The provider will send notifications every maximum interval in milliseconds, * even if the value didn't change. It will send notifications more often if * on-change notifications are enabled, the value changes more often, and the * minimum interval QoS does not prevent it. The maximum interval can thus * be seen as a sort of heart beat or keep alive interval, if no other * publication has been sent within that time. * * @return The maxInterval in milliseconds. The publisher will send a * notification at least every maxInterval milliseconds. */ @Deprecated public long getMaxInterval() { return getMaxIntervalMs(); } /** * Get the maximum interval in milliseconds. *
* The provider will send notifications every maximum interval in milliseconds, * even if the value didn't change. It will send notifications more often if * on-change notifications are enabled, the value changes more often, and the * minimum interval QoS does not prevent it. The maximum interval can thus * be seen as a sort of heart beat or keep alive interval, if no other * publication has been sent within that time. * * @return The maxInterval in milliseconds. The publisher will send a * notification at least every maxInterval milliseconds. */ public long getMaxIntervalMs() { return maxIntervalMs; } /** * Get the maximum interval in milliseconds. *
* The provider will send notifications every maximum interval in milliseconds, * even if the value didn't change. It will send notifications more often if * on-change notifications are enabled, the value changes more often, and the * minimum interval QoS does not prevent it. The maximum interval can thus * be seen as a sort of heart beat or keep alive interval, if no other * publication has been sent within that time. * * @return The maxInterval in milliseconds. The publisher will send a * notification at least every maxInterval milliseconds. */ @Override public long getPeriodMs() { return getMaxIntervalMs(); } /** * @deprecated Use setMaxIntervalMs instead * * Set the maximum interval in milliseconds. *
* The provider will send publications every maximum interval in milliseconds, * even if the value didn't change. It will send notifications more often if * on-change notifications are enabled, the value changes more often, and the * minimum interval QoS does not prevent it. The maximum interval can thus * be seen as a sort of heart beat or keep alive interval, if no other * publication has been sent within that time. * * @param maxIntervalMs * The publisher will send a notification at least every * maxIntervalMs.
*
* Minimum and Maximum Values *
    *
  • The absolute minimum setting is * {@value #MIN_MAX_INTERVAL_MS} milliseconds.
    * Any value less than this minimum will be treated at the absolute * minimum setting of{@value #MIN_MAX_INTERVAL_MS} milliseconds. *
  • The absolute maximum setting is * {@value #MAX_MAX_INTERVAL_MS} milliseconds.
    * Any value bigger than this maximum will be treated as the absolute * maximum setting of {@value #MAX_MAX_INTERVAL_MS} milliseconds. *
* @return this (fluent interface). */ @Deprecated public OnChangeWithKeepAliveSubscriptionQos setMaxInterval(long maxIntervalMs) { return setMaxIntervalMs(maxIntervalMs); } /** * Set the maximum interval in milliseconds. *
* The provider will send publications every maximum interval in milliseconds, * even if the value didn't change. It will send notifications more often if * on-change notifications are enabled, the value changes more often, and the * minimum interval QoS does not prevent it. The maximum interval can thus * be seen as a sort of heart beat or keep alive interval, if no other * publication has been sent within that time. * * @param maxIntervalMs * The publisher will send a notification at least every * maxIntervalMs.
*
* Minimum and Maximum Values *
    *
  • The absolute minimum setting is * {@value #MIN_MAX_INTERVAL_MS} milliseconds.
    * Any value less than this minimum will be treated at the absolute * minimum setting of{@value #MIN_MAX_INTERVAL_MS} milliseconds. *
  • The absolute maximum setting is * {@value #MAX_MAX_INTERVAL_MS} milliseconds.
    * Any value bigger than this maximum will be treated as the absolute * maximum setting of {@value #MAX_MAX_INTERVAL_MS} milliseconds. *
* @return this (fluent interface). */ public OnChangeWithKeepAliveSubscriptionQos setMaxIntervalMs(long maxIntervalMs) { if (maxIntervalMs < MIN_MAX_INTERVAL_MS) { this.maxIntervalMs = MIN_MAX_INTERVAL_MS; logger.warn("maxIntervalMs < MIN_MAX_INTERVAL_MS. Using MIN_MAX_INTERVAL_MS: {}", MIN_MAX_INTERVAL_MS); } else if (maxIntervalMs > MAX_MAX_INTERVAL_MS) { this.maxIntervalMs = MAX_MAX_INTERVAL_MS; logger.warn("maxIntervalMs > MAX_MAX_INTERVAL_MS. Using MAX_MAX_INTERVAL_MS: {}", MAX_MAX_INTERVAL_MS); } else { this.maxIntervalMs = maxIntervalMs; } if (this.maxIntervalMs < this.getMinIntervalMs()) { this.maxIntervalMs = this.getMinIntervalMs(); } if (alertAfterIntervalMs != 0 && alertAfterIntervalMs < this.maxIntervalMs) { alertAfterIntervalMs = this.maxIntervalMs; logger.warn("alertAfterIntervalMs < maxIntervalMs. Setting alertAfterIntervalMs = maxIntervalMs: {}", this.maxIntervalMs); } return this; } /** * @deprecated Use getAlertAfterIntervalMs instead * * Get the alertAfterInterval in milliseconds. *
* If no notification was received within the last alert interval, a missed * publication notification will be raised. * * @return The alertAfterInterval in milliseconds. If more than * alertAfterInterval milliseconds pass without receiving a message, * the subscriptionManager will issue a publicationMissed. If set * to 0 (NO_ALERT_AFTER_INTERVAL), never alert. */ @Override @Deprecated public long getAlertAfterInterval() { return alertAfterIntervalMs; } /** * Get the alertAfterInterval in milliseconds. *
* If no notification was received within the last alert interval, a missed * publication notification will be raised. * * @return The alertAfterInterval in milliseconds. If more than * alertAfterInterval milliseconds pass without receiving a message, * the subscriptionManager will issue a publicationMissed. If set * to 0 (NO_ALERT_AFTER_INTERVAL), never alert. */ @Override public long getAlertAfterIntervalMs() { return alertAfterIntervalMs; } /** * @deprecated Use setAlertAfterIntervalMs instead * * Set the alertAfterInterval in milliseconds. *
* If no notification was received within the last alert interval, a missed * publication notification will be raised. * * @param alertAfterIntervalMs * the max time that can expire without receiving a publication * before an alert will be generated. If more than alertIntervalMs * pass without receiving a message, subscriptionManager will issue * a publicationMissed. *
    *
  • Minimum setting: The value cannot be set below the * value of maxInterval
    * If a value is passed that is less than this minimum, maxInterval * will be used instead. *
  • The absolute maximum setting is 2.592.000.000 * milliseconds (30 days).
    * Any value bigger than this maximum will be treated as the * absolute maximum setting of 2.592.000.000 milliseconds. *
* @return this (fluent interface). */ @Deprecated public OnChangeWithKeepAliveSubscriptionQos setAlertAfterInterval(final long alertAfterIntervalMs) { return setAlertAfterIntervalMs(alertAfterIntervalMs); } /** * Set the alertAfterInterval in milliseconds. *
* If no notification was received within the last alert interval, a missed * publication notification will be raised. * * @param alertAfterIntervalMs * the max time that can expire without receiving a publication * before an alert will be generated. If more than alertIntervalMs * pass without receiving a message, subscriptionManager will issue * a publicationMissed. *
    *
  • Minimum setting: The value cannot be set below the * value of maxInterval
    * If a value is passed that is less than this minimum, maxInterval * will be used instead. *
  • The absolute maximum setting is 2.592.000.000 * milliseconds (30 days).
    * Any value bigger than this maximum will be treated as the * absolute maximum setting of 2.592.000.000 milliseconds. *
* @return this (fluent interface). */ public OnChangeWithKeepAliveSubscriptionQos setAlertAfterIntervalMs(final long alertAfterIntervalMs) { if (alertAfterIntervalMs > MAX_ALERT_AFTER_INTERVAL_MS) { this.alertAfterIntervalMs = MAX_ALERT_AFTER_INTERVAL_MS; logger.warn("alertAfterIntervalMs > maxInterval. Using MAX_ALERT_AFTER_INTERVAL_MS: {}", MAX_ALERT_AFTER_INTERVAL_MS); } else { this.alertAfterIntervalMs = alertAfterIntervalMs; } if (this.alertAfterIntervalMs != 0 && this.alertAfterIntervalMs < maxIntervalMs) { this.alertAfterIntervalMs = maxIntervalMs; logger.warn("attempt to set alertAfterIntervalMs to a value smaller than maxInterval; setting to maxInterval instead"); } return this; } @Override public OnChangeWithKeepAliveSubscriptionQos setExpiryDateMs(long expiryDateMs) { return (OnChangeWithKeepAliveSubscriptionQos) super.setExpiryDateMs(expiryDateMs); } @Override public OnChangeWithKeepAliveSubscriptionQos setMinIntervalMs(long minIntervalMs) { super.setMinIntervalMs(minIntervalMs); // adjust maxInterval to match new minInterval return setMaxIntervalMs(maxIntervalMs); } @Override public OnChangeWithKeepAliveSubscriptionQos setPublicationTtlMs(long publicationTtlMs) { return (OnChangeWithKeepAliveSubscriptionQos) super.setPublicationTtlMs(publicationTtlMs); } @Override public OnChangeWithKeepAliveSubscriptionQos setValidityMs(long validityMs) { return (OnChangeWithKeepAliveSubscriptionQos) super.setValidityMs(validityMs); } public void clearAlertAfterInterval() { this.alertAfterIntervalMs = NO_ALERT_AFTER_INTERVAL; } @Override @JsonIgnore @Deprecated /** * @deprecated this method will be removed by 2017-01-01. * Use getPeriodMs() or getMaxIntervalMs() instead. */ public long getHeartbeat() { return maxIntervalMs; } /** * Calculate code for hashing based on member contents * * @return The calculated hash code */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (int) (alertAfterIntervalMs ^ (alertAfterIntervalMs >>> 32)); result = prime * result + (int) (maxIntervalMs ^ (maxIntervalMs >>> 32)); return result; } /** * Check for equality * * @param obj Reference to the object to compare to * @return true, if objects are equal, false otherwise */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } OnChangeWithKeepAliveSubscriptionQos other = (OnChangeWithKeepAliveSubscriptionQos) obj; if (alertAfterIntervalMs != other.alertAfterIntervalMs) { return false; } if (maxIntervalMs != other.maxIntervalMs) { return false; } return true; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy