Skip to content
Snippets Groups Projects
Commit 49d4ffdb authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Get rid of visitor pattern for event handling

@EventListener is used for handler methods instead of implementing
a visitor interface.
parent 7c48d14f
Branches
No related merge requests found
Showing
with 14 additions and 300 deletions
......@@ -19,6 +19,7 @@ package de.thm.arsnova.cache;
import de.thm.arsnova.event.*;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
/**
......@@ -26,105 +27,29 @@ import org.springframework.stereotype.Component;
* caches, e.g, for a specific session.
*/
@Component
public class CacheBusterImpl implements CacheBuster, ArsnovaEventVisitor {
public class CacheBusterImpl implements CacheBuster {
@CacheEvict(value = "statistics", allEntries = true)
@Override
public void visit(NewCommentEvent event) { }
@EventListener
public void handleNewComment(NewCommentEvent event) { }
@CacheEvict(value = "statistics", allEntries = true)
@Override
public void visit(DeleteCommentEvent event) { }
@Override
public void visit(NewQuestionEvent event) { }
@Override
public void visit(UnlockQuestionEvent event) { }
@Override
public void visit(UnlockQuestionsEvent newQuestionsEvent) { }
@Override
public void visit(LockQuestionEvent lockQuestionEvent) { }
@Override
public void visit(LockQuestionsEvent lockQuestionsEvent) { }
@EventListener
public void handleDeleteComment(DeleteCommentEvent event) { }
@CacheEvict(value = "answerlists", key = "#event.content.id")
@Override
public void visit(NewAnswerEvent event) { }
@Override
public void visit(DeleteAnswerEvent event) { }
@Override
public void visit(DeleteQuestionEvent event) { }
@Override
public void visit(DeleteAllQuestionsEvent event) { }
@Override
public void visit(DeleteAllQuestionsAnswersEvent event) { }
@Override
public void visit(DeleteAllPreparationAnswersEvent event) { }
@Override
public void visit(DeleteAllLectureAnswersEvent event) { }
@Override
public void visit(NewFeedbackEvent event) { }
@Override
public void visit(DeleteFeedbackForRoomsEvent event) { }
@Override
public void visit(StatusRoomEvent event) { }
@EventListener
public void handleNewAnswer(NewAnswerEvent event) { }
@CacheEvict(value = "statistics", allEntries = true)
@Override
public void visit(ChangeScoreEvent changeLearningProgress) { }
@Override
public void visit(PiRoundDelayedStartEvent piRoundDelayedStartEvent) { }
@Override
public void visit(PiRoundEndEvent piRoundEndEvent) { }
@Override
public void visit(PiRoundCancelEvent piRoundCancelEvent) { }
@Override
public void visit(PiRoundResetEvent piRoundResetEvent) { }
@EventListener
public void handleChangeScore(ChangeScoreEvent changeLearningProgress) { }
@CacheEvict(value = "statistics", allEntries = true)
@Override
public void visit(NewRoomEvent newSessionEvent) { }
@EventListener
public void handleewRoom(NewRoomEvent newSessionEvent) { }
@CacheEvict(value = "statistics", allEntries = true)
@Override
public void visit(DeleteRoomEvent deleteSessionEvent) { }
@Override
public void visit(LockVoteEvent lockVoteEvent) { }
@Override
public void visit(LockVotesEvent lockVotesEvent) { }
@Override
public void visit(UnlockVoteEvent unlockVoteEvent) { }
@Override
public void visit(UnlockVotesEvent unlockVotesEvent) { }
@Override
public void visit(FeatureChangeEvent featureChangeEvent) { }
@Override
public void visit(LockFeedbackEvent lockFeedbackEvent) { }
@Override
public void visit(FlipFlashcardsEvent flipFlashcardsEvent) { }
@EventListener
public void handleDeleteRoom(DeleteRoomEvent deleteSessionEvent) { }
}
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2018 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.cache;
import de.thm.arsnova.event.ArsnovaEvent;
import de.thm.arsnova.event.ArsnovaEventVisitor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
/**
* Listener registration for the cache buster.
*
* Note that this class is necessary in order for the annotations to work.
*/
@Component
public class CacheBusterListener implements ApplicationListener<ArsnovaEvent> {
@Autowired
private CacheBuster cacheBuster;
@Override
public void onApplicationEvent(ArsnovaEvent event) {
event.accept((ArsnovaEventVisitor) cacheBuster);
}
}
......@@ -34,7 +34,6 @@ import de.thm.arsnova.web.PathApiVersionContentNegotiationStrategy;
import de.thm.arsnova.web.ResponseInterceptorHandler;
import de.thm.arsnova.websocket.ArsnovaSocketioServer;
import de.thm.arsnova.websocket.ArsnovaSocketioServerImpl;
import de.thm.arsnova.websocket.ArsnovaSocketioServerListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
......@@ -275,11 +274,6 @@ public class AppConfig implements WebMvcConfigurer {
return socketioServer;
}
@Bean
public ArsnovaSocketioServerListener arsnovaSocketListener() {
return new ArsnovaSocketioServerListener();
}
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager();
......
......@@ -30,6 +30,4 @@ public abstract class ArsnovaEvent extends ApplicationEvent {
super(source);
}
public abstract void accept(ArsnovaEventVisitor visitor);
}
/*
* This file is part of ARSnova Backend.
* Copyright (C) 2012-2018 The ARSnova Team and Contributors
*
* ARSnova Backend is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ARSnova Backend is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thm.arsnova.event;
/**
* Listeners wanting to receive ARSnova's internal events should implement this interface.
*/
public interface ArsnovaEventVisitor {
void visit(NewCommentEvent newCommentEvent);
void visit(DeleteCommentEvent deleteCommentEvent);
void visit(NewQuestionEvent newQuestionEvent);
void visit(UnlockQuestionEvent unlockQuestionEvent);
void visit(UnlockQuestionsEvent newQuestionsEvent);
void visit(LockQuestionEvent lockQuestionEvent);
void visit(LockQuestionsEvent lockQuestionsEvent);
void visit(NewAnswerEvent newAnswerEvent);
void visit(DeleteAnswerEvent deleteAnswerEvent);
void visit(DeleteQuestionEvent deleteQuestionEvent);
void visit(DeleteAllQuestionsEvent deleteAllQuestionsEvent);
void visit(DeleteAllQuestionsAnswersEvent deleteAllAnswersEvent);
void visit(DeleteAllPreparationAnswersEvent deleteAllPreparationAnswersEvent);
void visit(DeleteAllLectureAnswersEvent deleteAllLectureAnswersEvent);
void visit(NewFeedbackEvent newFeedbackEvent);
void visit(DeleteFeedbackForRoomsEvent deleteFeedbackEvent);
void visit(StatusRoomEvent statusSessionEvent);
void visit(ChangeScoreEvent changeLearningProgress);
void visit(PiRoundDelayedStartEvent piRoundDelayedStartEvent);
void visit(PiRoundEndEvent piRoundEndEvent);
void visit(PiRoundCancelEvent piRoundCancelEvent);
void visit(PiRoundResetEvent piRoundResetEvent);
void visit(NewRoomEvent newSessionEvent);
void visit(DeleteRoomEvent deleteSessionEvent);
void visit(LockVoteEvent lockVoteEvent);
void visit(LockVotesEvent lockVotesEvent);
void visit(UnlockVoteEvent unlockVoteEvent);
void visit(UnlockVotesEvent unlockVotesEvent);
void visit(FeatureChangeEvent featureChangeEvent);
void visit(LockFeedbackEvent lockFeedbackEvent);
void visit(FlipFlashcardsEvent flipFlashcardsEvent);
}
......@@ -30,9 +30,4 @@ public class ChangeScoreEvent extends RoomEvent {
super(source, room);
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -30,9 +30,4 @@ public class DeleteAllLectureAnswersEvent extends RoomEvent {
super(source, room);
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -29,9 +29,4 @@ public class DeleteAllPreparationAnswersEvent extends RoomEvent {
public DeleteAllPreparationAnswersEvent(Object source, Room room) {
super(source, room);
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -29,9 +29,4 @@ public class DeleteAllQuestionsAnswersEvent extends RoomEvent {
public DeleteAllQuestionsAnswersEvent(Object source, Room room) {
super(source, room);
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -31,9 +31,4 @@ public class DeleteAllQuestionsEvent extends RoomEvent {
super(source, room);
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -34,11 +34,6 @@ public class DeleteAnswerEvent extends RoomEvent {
this.content = content;
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
public Content getQuestion() {
return content;
}
......
......@@ -34,11 +34,6 @@ public class DeleteCommentEvent extends RoomEvent {
this.comment = comment;
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
public Comment getQuestion() {
return comment;
}
......
......@@ -46,9 +46,4 @@ public class DeleteFeedbackForRoomsEvent extends ArsnovaEvent {
return userId;
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -38,9 +38,4 @@ public class DeleteQuestionEvent extends RoomEvent {
return this.content;
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -31,9 +31,4 @@ public class DeleteRoomEvent extends RoomEvent {
super(source, room);
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -30,9 +30,4 @@ public class FeatureChangeEvent extends RoomEvent {
super(source, room);
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -29,9 +29,4 @@ public class FlipFlashcardsEvent extends RoomEvent {
public FlipFlashcardsEvent(Object source, Room room) {
super(source, room);
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -29,9 +29,4 @@ public class LockFeedbackEvent extends RoomEvent {
public LockFeedbackEvent(Object source, Room room) {
super(source, room);
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -38,9 +38,4 @@ public class LockQuestionEvent extends RoomEvent {
return this.content;
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
......@@ -40,9 +40,4 @@ public class LockQuestionsEvent extends RoomEvent {
return this.contents;
}
@Override
public void accept(ArsnovaEventVisitor visitor) {
visitor.visit(this);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment