Skip to content

Commit

Permalink
Symatic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
singhashmeet committed Nov 16, 2021
1 parent 0d392f3 commit 9c1f448
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/pusher/client/channel/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface Channel {
* {@link com.pusher.client.Pusher#subscribe(String, ChannelEventListener, String...)}
* again to receive a fresh {@linkplain Channel} instance.
*/
void bind_global(SubscriptionEventListener listener);
void bindGlobal(SubscriptionEventListener listener);

/**
* <p>
Expand Down Expand Up @@ -129,7 +129,7 @@ public interface Channel {
* {@link com.pusher.client.Pusher#subscribe(String, ChannelEventListener, String...)}
* again to receive a fresh {@linkplain Channel} instance.
*/
void unbind_global(SubscriptionEventListener listener);
void unbindGlobal(SubscriptionEventListener listener);

/**
*
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/com/pusher/client/channel/impl/ChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ChannelImpl implements InternalChannel {
private static final String INTERNAL_EVENT_PREFIX = "pusher_internal:";
protected static final String SUBSCRIPTION_SUCCESS_EVENT = "pusher_internal:subscription_succeeded";
protected final String name;
private Set<SubscriptionEventListener> globalListners = new HashSet<SubscriptionEventListener>();
private Set<SubscriptionEventListener> globalListeners = new HashSet<SubscriptionEventListener>();
private final Map<String, Set<SubscriptionEventListener>> eventNameToListenerMap = new HashMap<String, Set<SubscriptionEventListener>>();
protected volatile ChannelState state = ChannelState.INITIAL;
private ChannelEventListener eventListener;
Expand Down Expand Up @@ -68,14 +68,11 @@ public void bind(final String eventName, final SubscriptionEventListener listene
}

@Override
public void bind_global(SubscriptionEventListener listener) {
public void bindGlobal(SubscriptionEventListener listener) {
validateArguments("", listener);

synchronized(lock) {
if (globalListners == null) {
globalListners = new HashSet<SubscriptionEventListener>();
}
globalListners.add(listener);
globalListeners.add(listener);
}
}

Expand All @@ -96,12 +93,12 @@ public void unbind(final String eventName, final SubscriptionEventListener liste
}

@Override
public void unbind_global(SubscriptionEventListener listener) {
public void unbindGlobal(SubscriptionEventListener listener) {
validateArguments("", listener);

synchronized(lock) {
if (globalListners != null) {
globalListners.remove(listener);
if (globalListeners != null) {
globalListeners.remove(listener);
}
}
}
Expand Down Expand Up @@ -244,8 +241,8 @@ protected Set<SubscriptionEventListener> getInterestedListeners(String event) {
if (sharedListeners != null ) {
listners.addAll(sharedListeners);
}
if (!globalListners.isEmpty()) {
listners.addAll(globalListners);
if (!globalListeners.isEmpty()) {
listners.addAll(globalListeners);
}

if (listners.isEmpty()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testDataIsExtractedFromMessageAndPassedToSingleListener() {
}
@Test
public void testDataIsExtractedFromMessageAndPassedToSingleListenerGlobalEvent() {
channel.bind_global(mockListener);
channel.bindGlobal(mockListener);
channel.onMessage(EVENT_NAME, "{\"event\":\"event1\",\"data\":\"{\\\"fish\\\":\\\"chips\\\"}\"}");

verify(mockListener, times(1)).onEvent(argCaptor.capture());
Expand Down Expand Up @@ -166,8 +166,8 @@ public void testEventIsNotPassedOnIfListenerHasUnboundFromEvent() {
@Test
public void testEventIsNotPassedOnIfListenerHasUnboundFromGlobalEvent() {

channel.bind_global(mockListener);
channel.unbind_global(mockListener);
channel.bindGlobal(mockListener);
channel.unbindGlobal(mockListener);
channel.onMessage(EVENT_NAME, "{\"event\":\"event1\",\"data\":\"{\\\"fish\\\":\\\"chips\\\"}\"}");

verify(mockListener, never()).onEvent(any(PusherEvent.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void testDataIsExtractedFromMessageAndPassedToSingleListenerGlobalEvent()

PrivateEncryptedChannelEventListener mockListener = mock(PrivateEncryptedChannelEventListener.class);

channel.bind_global(mockListener);
channel.bindGlobal(mockListener);

channel.onMessage("my-event", "{\"event\":\"event1\",\"data\":\"{" +
"\\\"nonce\\\": \\\"4sVYwy4j/8dCcjyxtPCWyk19GaaViaW9\\\"," +
Expand Down

0 comments on commit 9c1f448

Please sign in to comment.