aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications/src/main/java/com/juick/components/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-04-12 14:32:44 +0300
committerGravatar Vitaly Takmazov2018-04-12 14:32:44 +0300
commitc5649915e6259e921cfd087042525b69533d53b0 (patch)
tree54e2d7bdba8a21a640b3e2a0c427b72d33c445c2 /juick-notifications/src/main/java/com/juick/components/service
parent9e5a6b3f2f6907f18f22718bcb6f0ac7f79c95cd (diff)
notifications: pushserver is the only websocket component for now
Diffstat (limited to 'juick-notifications/src/main/java/com/juick/components/service')
-rw-r--r--juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java78
-rw-r--r--juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java40
-rw-r--r--juick-notifications/src/main/java/com/juick/components/service/TokenService.java10
3 files changed, 0 insertions, 128 deletions
diff --git a/juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java b/juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java
deleted file mode 100644
index 0f62e702..00000000
--- a/juick-notifications/src/main/java/com/juick/components/service/JuickServerComponent.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.juick.components.service;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.juick.components.Notifications;
-import com.juick.server.component.DisconnectedEvent;
-import com.juick.server.component.MessageEvent;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.ApplicationEventPublisher;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-import org.springframework.web.socket.CloseStatus;
-import org.springframework.web.socket.PingMessage;
-import org.springframework.web.socket.TextMessage;
-import org.springframework.web.socket.WebSocketSession;
-import org.springframework.web.socket.handler.TextWebSocketHandler;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import java.io.IOException;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-@Component
-public class JuickServerComponent extends TextWebSocketHandler {
- private static Logger logger = LoggerFactory.getLogger(JuickServerComponent.class);
- @Inject
- private ApplicationEventPublisher applicationEventPublisher;
- @Inject
- private Notifications notifications;
- @Inject
- private ObjectMapper jsonMapper;
-
- private WebSocketSession session;
- private final AtomicBoolean closeFlag = new AtomicBoolean(false);
-
- @PostConstruct
- public void init() {
- closeFlag.set(false);
- }
- @Override
- public void afterConnectionEstablished(WebSocketSession session) throws Exception {
- logger.info("WebSocket connected");
- this.session = session;
- }
-
- @Override
- public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
- logger.info("WebSocket disconnected with code {}: {}", status.getCode(), status.getReason());
- applicationEventPublisher.publishEvent(new DisconnectedEvent(this));
- }
-
- @Override
- protected void handleTextMessage(WebSocketSession session, TextMessage text) throws Exception {
- com.juick.Message jmsg = jsonMapper.readValue(text.asBytes(), com.juick.Message.class);
-
- if (logger.isInfoEnabled()) // prevent writeValueAsString execution if logger disabled
- logger.info("got jmsg: {}", jsonMapper.writeValueAsString(jmsg));
- if (!closeFlag.get()) {
- notifications.messageReceived(jmsg);
- }
- }
-
- @Scheduled(fixedRate = 30000, initialDelay = 30000)
- public void ping() throws IOException {
- if (session != null && session.isOpen()) {
- logger.debug("Sending WebSocket ping");
- session.sendMessage(new PingMessage());
- } else if (!closeFlag.get()) {
- applicationEventPublisher.publishEvent(new DisconnectedEvent(this));
- }
- }
- @PreDestroy
- public void close() {
- closeFlag.set(true);
- }
-
-}
diff --git a/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java b/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
deleted file mode 100644
index 6e6c8632..00000000
--- a/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package com.juick.components.service;
-
-import com.juick.ExternalToken;
-import com.juick.service.BaseRestService;
-import org.springframework.core.ParameterizedTypeReference;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.MediaType;
-import org.springframework.stereotype.Service;
-import org.springframework.web.client.RestTemplate;
-
-import javax.inject.Inject;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * Created by vitalyster on 15.12.2016.
- */
-@Service
-public class NotificationsTokenService extends BaseRestService implements TokenService {
-
- @Inject
- public NotificationsTokenService(RestTemplate rest) {
- super(rest);
- }
-
- @Override
- public void deleteTokens(String type, List<String> devices) {
- if (devices.size() > 0) {
- List<ExternalToken> list = devices.stream()
- .map(d -> new ExternalToken(null, type, d, null)).collect(Collectors.toList());
- HttpHeaders headers = new HttpHeaders();
- headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
- getRest().exchange("http://api.juick.com/notifications",
- HttpMethod.DELETE, new HttpEntity<>(list, headers), new ParameterizedTypeReference<Void>() {
- });
- }
- }
-}
diff --git a/juick-notifications/src/main/java/com/juick/components/service/TokenService.java b/juick-notifications/src/main/java/com/juick/components/service/TokenService.java
deleted file mode 100644
index 2a578386..00000000
--- a/juick-notifications/src/main/java/com/juick/components/service/TokenService.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.juick.components.service;
-
-import java.util.List;
-
-/**
- * Created by vitalyster on 15.12.2016.
- */
-public interface TokenService {
- void deleteTokens(String type, List<String> list);
-}