Open GoogleCodeExporter opened 8 years ago
The way the sockets are handled right now is a result of how APNS works.
Sending 5000 notifications shouldn't be a problem, and sockets opening/closing
should be handled automatically by the library. If you are experiencing
exceptions, please provide the code you are using, as well as a copy of the log
output for an attempt.
Original comment by sype...@gmail.com
on 8 May 2013 at 8:58
Original comment by sype...@gmail.com
on 8 May 2013 at 8:59
Thank you for prompt reply.
In fact we need to push arround couple of millions notifications
we start 400 threads(that sends 5000 messages) simaltaniously. (code given
below) . One reson or the other when start the threads , ends up in timeout
Exception.(sometimes)
it's throwing when tring to excute
if (socketTimeout > 0)this.socket.setSoTimeout(socketTimeout); in
PushNotificationManager.java ( protected void sendNotification() method)
It works , If I catch the exception and reinitialize connection.
However , my biggest worry is ;
Each thread will close the connection after sending 5000 messages .
If this exceptions thrown we cannot read the response from Apple.
public class PushBulkWorker implements Runnable {
private static final Logger logger = LoggerFactory.getLogger(PushBulkWorker.class);
List<String> tokens;
String message;
AppleNotificationServer server;
int no;
public PushBulkWorker(List<String> tokens, String message, AppleNotificationServer server,int no) {
super();
this.tokens = tokens;
this.message = message;
this.server = server;
this.no=no;
}
private void send() throws Exception {
PushNotificationPayload payload = PushNotificationPayload.alert(message);
PushedNotifications notifications;
PushNotificationManager pushManager;
notifications = new PushedNotifications();
pushManager = new PushNotificationManager();
pushManager.initializeConnection(server);
pushManager.setEnhancedNotificationFormatEnabled(false);
List deviceList = Devices.asDevices(tokens);
notifications.setMaxRetained(deviceList.size());
for(Iterator i$ = deviceList.iterator(); i$.hasNext();)
{
Device device = (Device)i$.next();
try
{
BasicDevice.validateTokenFormat(device.getToken());
PushedNotification notification = pushManager.sendNotification(device, payload, true);
notifications.add(notification);
}
catch(InvalidDeviceTokenFormatException e)
{
notifications.add(new PushedNotification(device, payload, e));
}
}
try
{
pushManager.stopConnection();
System.out.print(" fin : "+no);
//System.out.println("thred --------------- "+no+" finished");
//logger.info("thred --------------- "+no+" finished");
}catch(Exception e)
{
e.printStackTrace();
}finally
{
}
}
public void run() {
try {
send();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original comment by mohamfbh...@gmail.com
on 9 May 2013 at 8:49
Original issue reported on code.google.com by
mohamfbh...@gmail.com
on 8 May 2013 at 3:18