I'm a little new to Google Cloud Messaging. We have been working with him for several months, but most recently we received messages about the connection. "When this happens, all communications cease.
Google says: https://developer.android.com/google/gcm/ccs.html#response
When you receive the CONNECTION_DRAINING message, you should immediately start sending messages to another CCS connection, opening, if necessary, a new connection. However, you must keep the original connection open and continue to receive messages that the connection can (and ACKing them) —CCS will handle initiating the connection to close when it is ready.
My question
- If I open a new connection manually, how does it know which connection to use if I do not close the existing connection?
- If 6 messages are sent at the same time, how to stop the method of opening 6 connections? Or am I embarrassed by this?
- Why is the connection leaking?
I am surprised that this is not yet implemented in their sample code. Seems like that's almost all you need. Is this already done for me in the code, and will I skip it?
I do not have the main method in my code, I myself serve as user servlets as triggers. My connection is initialized as follows
@PostConstruct public void init() throws Exception{ try { smackCcsClient.connect(Long.parseLong(env.getProperty("gcm.api")), env.getProperty("gcm.key")); }catch (IOException e ){ e.printStackTrace(); }catch(SmackException e){ e.printStackTrace(); }catch(XMPPException e){ e.printStackTrace(); } }
however after that i never touch the connection again. Am I handling this incorrectly, is it something that I should touch more often or something that I need to track?
_______________________ ADD AFTER QUESTION _________________________
I added a connection inside my sample code to try to reinitialize the connection. It looks like this:
if ("CONNECTION_DRAINING".equals(controlType)) { connectionDraining = true; //Open new connection because old connection will be closing or is already closed. try { connect(Long.parseLong(env.getProperty("gcm.api")), env.getProperty("gcm.key")); } catch (XMPPException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SmackException e) { e.printStackTrace(); } } else { logger.log(Level.INFO, "Unrecognized control type: %s. This could happen if new features are " + "added to the CCS protocol.", controlType); }
java spring-mvc google-cloud-messaging
B rad
source share