|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.relayrides.pushy.apns.ApnsConnection<T>
public class ApnsConnection<T extends ApnsPushNotification>
A connection to an APNs gateway. An ApnsConnection
is responsible for sending push notifications to the
APNs gateway, and reports lifecycle events via its ApnsConnectionListener
.
Generally, connections should be managed by a parent PushManager
and not manipulated directly (although
connections are fully functional on their own). Connections are created in a disconnected state, and must be
explicitly connected before they can be used to send push notifications.
PushManager
Constructor Summary | |
---|---|
ApnsConnection(ApnsEnvironment environment,
SSLContext sslContext,
NioEventLoopGroup eventLoopGroup,
ApnsConnectionListener<T> listener)
Constructs a new APNs connection. |
Method Summary | |
---|---|
void |
connect()
Asynchronously connects to the APNs gateway in this connection's environment. |
void |
sendNotification(T notification)
Asynchronously sends a push notification to the connected APNs gateway. |
void |
shutdownGracefully()
Gracefully and asynchronously shuts down this connection. |
void |
shutdownImmediately()
Immediately closes this connection (assuming it was ever open). |
String |
toString()
|
void |
waitForPendingWritesToFinish()
Waits for all pending write operations to finish. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ApnsConnection(ApnsEnvironment environment, SSLContext sslContext, NioEventLoopGroup eventLoopGroup, ApnsConnectionListener<T> listener)
environment
- the environment in which this connection will operatesslContext
- an SSL context with the keys/certificates and trust managers this connection should use when
communicating with the APNs gatewayeventLoopGroup
- the event loop group this connection should use for asynchronous network operationslistener
- the listener to which this connection will report lifecycle events; must not be null
Method Detail |
---|
public void connect()
ApnsConnectionListener.handleConnectionSuccess(ApnsConnection)
,
ApnsConnectionListener.handleConnectionFailure(ApnsConnection, Throwable)
public void sendNotification(T notification)
notification
- the notification to sendApnsConnectionListener.handleWriteFailure(ApnsConnection, ApnsPushNotification, Throwable)
,
ApnsConnectionListener.handleRejectedNotification(ApnsConnection, ApnsPushNotification, RejectedNotificationReason)
public void waitForPendingWritesToFinish() throws InterruptedException
Waits for all pending write operations to finish. When this method exits normally (i.e. when it does
not throw an InterruptedException
), All pending writes will have either finished successfully or failed
and passed to this connection's listener via the
ApnsConnectionListener.handleWriteFailure(ApnsConnection, ApnsPushNotification, Throwable)
method.
It is not guaranteed that all write operations will have finished by the time a connection has
closed. Applications that need to know when all writes have finished should call this method after a connection
closes, but must not do so in an IO thread (i.e. the thread that called the
ApnsConnectionListener.handleConnectionClosure(ApnsConnection)
method.
InterruptedException
- if interrupted while waiting for pending read/write operations to finishpublic void shutdownGracefully()
Gracefully and asynchronously shuts down this connection. Graceful disconnection is triggered by sending a known-bad notification to the APNs gateway; when the gateway rejects the notification, it is guaranteed that preceding notifications were processed successfully and that all following notifications were not processed at all. The gateway will close the connection after rejecting the notification, and this connection's listener will be notified when the connection is closed.
Note that if/when the known-bad notification is rejected by the APNs gateway, this connection's listener will not be notified of the rejection.
Calling this method before establishing a connection with the APNs gateway or while a graceful shutdown attempt is already in progress has no effect.
ApnsConnectionListener.handleRejectedNotification(ApnsConnection, ApnsPushNotification, RejectedNotificationReason)
,
ApnsConnectionListener.handleConnectionClosure(ApnsConnection)
public void shutdownImmediately()
Immediately closes this connection (assuming it was ever open). No guarantees are made with regard to the
state of sent notifications, and callers should generally prefer shutdownGracefully()
to
this method. If the connection was previously open, the connection's listener will be notified of the
connection's closure. If a connection attempt was in progress, the listener will be notified of a connection
failure. If the connection was never open, this method has no effect.
Calling this method while not connected has no effect.
ApnsConnectionListener.handleConnectionClosure(ApnsConnection)
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |