PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/notnoop/apns/ApnsDelegate.java

http://github.com/notnoop/java-apns
Java | 92 lines | 9 code | 7 blank | 76 comment | 0 complexity | 0214bdea75a1618bd2969bc0ec51c88a MD5 | raw file
 1/*
 2 *  Copyright 2009, Mahmood Ali.
 3 *  All rights reserved.
 4 *
 5 *  Redistribution and use in source and binary forms, with or without
 6 *  modification, are permitted provided that the following conditions are
 7 *  met:
 8 *
 9 *    * Redistributions of source code must retain the above copyright
10 *      notice, this list of conditions and the following disclaimer.
11 *    * Redistributions in binary form must reproduce the above
12 *      copyright notice, this list of conditions and the following disclaimer
13 *      in the documentation and/or other materials provided with the
14 *      distribution.
15 *    * Neither the name of Mahmood Ali. nor the names of its
16 *      contributors may be used to endorse or promote products derived from
17 *      this software without specific prior written permission.
18 *
19 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31package com.notnoop.apns;
32
33/**
34 * A delegate that gets notified of the status of notification delivery to the
35 * Apple Server.
36 *
37 * The delegate doesn't get notified when the notification actually arrives at
38 * the phone.
39 */
40public interface ApnsDelegate {
41
42    /**
43     * Called when message was successfully sent to the Apple servers
44     *
45     * @param message the notification that was sent
46     * @param resent whether the notification was resent after an error
47     */
48    public void messageSent(ApnsNotification message, boolean resent);
49
50    /**
51     * Called when the delivery of the message failed for any reason
52     *
53     * If message is null, then your notification has been rejected by Apple but
54     * it has been removed from the cache so it is not possible to identify
55     * which notification caused the error. In this case subsequent
56     * notifications may be lost. If this happens you should consider increasing
57     * your cacheLength value to prevent data loss.
58     *
59     * @param message the notification that was attempted to be sent
60     * @param e the cause and description of the failure
61     */
62    public void messageSendFailed(ApnsNotification message, Throwable e);
63
64    /**
65     * The connection was closed and/or an error packet was received while
66     * monitoring was turned on.
67     *
68     * @param e the delivery error
69     * @param messageIdentifier  id of the message that failed
70     */
71    public void connectionClosed(DeliveryError e, int messageIdentifier);
72
73    /**
74     * The resend cache needed a bigger size (while resending messages)
75     *
76     * @param newCacheLength new size of the resend cache.
77     */
78    public void cacheLengthExceeded(int newCacheLength);
79
80    /**
81     * A number of notifications has been queued for resending due to a error-response
82     * packet being received.
83     *
84     * @param resendCount the number of messages being queued for resend
85     */
86    public void notificationsResent(int resendCount);
87    
88    /**
89     * A no operation delegate that does nothing!
90     */
91    public final static ApnsDelegate EMPTY = new ApnsDelegateAdapter();
92}