flinc/pling — pull request #2 by mrnugget (2014-06-27 07:12:42+00:00)
Title: Make pling thread safe by using a connection pool and thread local storage

This is an attempt to make the gem thread-safe by changing the way the gateways handle their connections.

Since every gateway is in practice a singleton to which every thread has access when calling `Pling.deliver` race-conditions and data corruptions might arise.

Especially the long-lasting connection in the APN gateway poses a problem. But the caching of connections in C2DM and GCM gateways via instance variables is not totally thread-safe either.

This change uses a connection pool for APN, so that each thread gets its own connection (which is kept alive) as soon as it wants it.

In the C2DM and GCM gateways this implementation uses thread local storage to cache the connection object instead of an instance variable.

What do you think?