Now possible to subscribe to a channel before connecting. The ChannelManager is now a connection listener, and it will queue any subscribe messages until the connected callback is received.
Added extra unit test
Fixed issue where I wasn't updating the state to SUBSCRIBE_SENT when subscribing to channels that had been queued until the connected callback is received. Also fixed clear() method so that it clears out the queued subscriptions. Had to make InternalChannel implement Comparable because I'm now storing them in a ConcurrentSkipListMap inside ChannelManager (to avoid ConcurrentModificationExceptions when subscribing and removing within a loop) and the ConcurrentSkipListMap is a sorted map, so the keys must be comparable.
Merge branch 'master' into subscription-before-connection
(minor) just reformatting the ChannelManager class.
(minor) Also reformatting Pusher.java
Refactor: the ChannelManager used to be responsible for getting the auth token when you initially subscribe. It only did it once, which means that if the subscription gets queued the token will be stale by the time the connection comes up. Changed it so that the fetching of the auth token and building of the subscribe message is now done by the PrivateChannelImpl and PresenceChannelImpl classes themselves, and only when they actually need to subscribe. They will also call the authorizer every time they need to subscribe, which should make resubscription after a connection loss work properly. Also added EndToEndTest.java which mocks out very little (just the websocket) so is useful for making API calls to Pusher and seeing which messages come out the other end.
Refactor: we don't need the queuedSubscriptions set in ChannelManager at all. We just need to resubscribe to all of the channels in channelNameToChannelMap whenever we get the connected callback. This ensures that all subscriptions are resubscribed (with a fresh auth token) after each connection bounce. Added an end to end test for this scenario.
Split ChannelEventListener into two interfaces, SubscriptionEventListener now receives events, and ChannelEventListener receives the subscriptionSuccess callback. You can only have one ChannelEventListener, and the way to set it is to call Pusher.subscribe() with a ChannelEventListener instance. This removes the logic where when we got the subscription success callback we looped through all of the subscription listeners and informed all of them that the subscription was successful - now we only inform the ChannelEventListener and not the SubscriptionEventListeners. ChannelEventListener also extends SubscriptionEventListener so it can be used for receiving subscription events as well as the subscription successful callback, if you want it to.
Add Header support to the HttpAuthorizer
merge
merge of subscription-before-connected branch
Merge branch 'ryan/authHeaders' of git://github.com/Sendhub/pusher-java-client into Sendhub-ryan/authHeaders
merge pull request #7
format
refactoring HttpAuthorizer to have a setHeader method
Removing constructor which took hash for header name/values
auto resubscribe
The previous implementation only auto resubscribed if the connection was unexpectedly closed. The new functionality copies that of the JavaScript library; it will resubscribe even if the disconnect and reconnect were invoked via API method calls
updating to use Java-WebSocket master as submodule
moving subscription call to after connect
defining repo location & adding licence