001/**
002 *
003 * Copyright 2015 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smack.tcp;
018
019/**
020 * This callback is used to get the current value of the period in which Smack does bundle and defer
021 * outgoing stanzas.
022 * <p>
023 * Smack will bundle and defer stanzas if the connection is authenticated
024 * and if a bundle and defer callback is set, either via
025 * {@link XMPPTCPConnection#setDefaultBundleAndDeferCallback(BundleAndDeferCallback)} or
026 * {@link XMPPTCPConnection#setBundleandDeferCallback(BundleAndDeferCallback)}, and
027 * {@link #getBundleAndDeferMillis(BundleAndDefer)} returns a positive value. In a mobile environment, bundling
028 * and deferring outgoing stanzas may reduce battery consumption. It heavily depends on the
029 * environment, but recommend values for the bundle and defer period range from 20-60 seconds. But
030 * keep in mind that longer periods decrease the realtime aspect of Smack.
031 * </p>
032 * <p>
033 * Smack will invoke the callback when it needs to know the length of the bundle and defer period.
034 * If {@link #getBundleAndDeferMillis(BundleAndDefer)} returns 0 or a negative value, then the
035 * stanzas will send immediately. You can also prematurely abort the bundling of stanzas by calling
036 * {@link BundleAndDefer#stopCurrentBundleAndDefer()}.
037 * </p>
038 */
039public interface BundleAndDeferCallback {
040
041    /**
042     * Return the bundle and defer period used by Smack in milliseconds.
043     *
044     * @param bundleAndDefer used to premature abort bundle and defer.
045     * @return the bundle and defer period in milliseconds.
046     */
047    int getBundleAndDeferMillis(BundleAndDefer bundleAndDefer);
048
049}