Skip to content
This repository has been archived by the owner on Sep 13, 2020. It is now read-only.

Commit

Permalink
Refactored internal CDI events fired by ActiveUser
Browse files Browse the repository at this point in the history
  • Loading branch information
emjunior258 committed Oct 27, 2019
1 parent 8e621f1 commit f9017d2
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 54 deletions.
14 changes: 8 additions & 6 deletions Web/src/main/java/org/emerjoin/hi/web/ActiveUser.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.emerjoin.hi.web;

import org.emerjoin.hi.web.events.sse.AbstractChannelEvent;
import org.emerjoin.hi.web.events.sse.ChannelJoinEvent;
import org.emerjoin.hi.web.events.sse.ChannelQuitEvent;
import org.emerjoin.hi.web.events.sse.UserSubscriptionEvent;
import org.emerjoin.hi.web.events.sse.JoinChannel;
import org.emerjoin.hi.web.events.sse.QuitChannel;
import org.emerjoin.hi.web.security.SecureTokenUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -32,7 +32,7 @@ public class ActiveUser implements Serializable {
private static final SecureTokenUtil csrfTokeUtil = new SecureTokenUtil();

@Inject
private transient Event<AbstractChannelEvent> channelEvent;
private transient Event<UserSubscriptionEvent> channelEvent;

@PostConstruct
public void init(){
Expand Down Expand Up @@ -90,14 +90,16 @@ public void subscribe(String webEventChannel) {
if (webEventChannel == null || webEventChannel.isEmpty())
throw new IllegalArgumentException("webEventChannel must not be null nor empty");
this.webEventSubscriptions.add(webEventChannel);
channelEvent.fire(new ChannelJoinEvent(uniqueId, webEventChannel));
channelEvent.fire(new JoinChannel(this,
webEventChannel));
}

public void unsubscribe(String webEventChannel){
if(webEventChannel==null||webEventChannel.isEmpty())
throw new IllegalArgumentException("webEventChannel must not be null nor empty");
if(this.webEventSubscriptions.remove(webEventChannel))
channelEvent.fire(new ChannelQuitEvent(uniqueId,webEventChannel));
channelEvent.fire(new QuitChannel(this,
webEventChannel));
}

public boolean isSubscribedTo(String webEventChannel){
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

14 changes: 14 additions & 0 deletions Web/src/main/java/org/emerjoin/hi/web/events/sse/JoinChannel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.emerjoin.hi.web.events.sse;

import org.emerjoin.hi.web.ActiveUser;

/**
* @author Mario Junior.
*/
public class JoinChannel extends UserSubscriptionEvent {

public JoinChannel(ActiveUser user, String channel) {
super(user, channel);
}

}
13 changes: 13 additions & 0 deletions Web/src/main/java/org/emerjoin/hi/web/events/sse/QuitChannel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.emerjoin.hi.web.events.sse;

import org.emerjoin.hi.web.ActiveUser;

/**
* @author Mario Junior.
*/
public class QuitChannel extends UserSubscriptionEvent {

public QuitChannel(ActiveUser user, String channel) {
super(user, channel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.emerjoin.hi.web.events.sse;

import org.emerjoin.hi.web.ActiveUser;
import org.emerjoin.hi.web.events.HiEvent;

/**
* @author Mario Junior.
*/
public abstract class UserSubscriptionEvent extends HiEvent {

private ActiveUser user;
private String channel;

public UserSubscriptionEvent(ActiveUser user, String channel){
this.user = user;
this.channel = channel;
}

public ActiveUser getUser() {
return user;
}

public String getChannel() {
return channel;
}
}

0 comments on commit f9017d2

Please sign in to comment.