private boolean isChannelInactive(final UserAgent<SockJsSessionContext> userAgent) { final Channel ch = userAgent.context().getContext().channel(); return !ch.isActive() && !ch.isRegistered(); } }
@Override public void run() { final Set<Ack> unacked = simplePushServer.getUnacknowledged(uaid); logger.info("Resending " + unacked); session.send(toJson(new NotificationMessageImpl(unacked))); } },
@Override public void run() { logger.info("Running reaper at interval of " + simplePushServer.config().userAgentReaperTimeout()); for (Iterator<UserAgent<SockJsSessionContext>> it = userAgents.all().iterator(); it.hasNext();) { final UserAgent<SockJsSessionContext> userAgent = it.next(); final long now = System.currentTimeMillis(); if (isChannelInactive(userAgent) && userAgent.timestamp() + simplePushServer.config().userAgentReaperTimeout() < now) { logger.info("Removing inactive UserAgent [" + userAgent.uaid() + "]"); /* TODO: update this when persistence is in place so that the logic to remove is in one place and not spread out among the UserAgents class and the SimplePushServer. */ // remove from user agents map it.remove(); // remove from database simplePushServer.removeAllChannels(userAgent.uaid()); // close the user agent connectContext userAgent.context().close(); } } }
@Override public void run() { logger.info("Running reaper at interval of " + simplePushServer.config().userAgentReaperTimeout()); for (Iterator<UserAgent<SockJsSessionContext>> it = userAgents.all().iterator(); it.hasNext();) { final UserAgent<SockJsSessionContext> userAgent = it.next(); final long now = System.currentTimeMillis(); if (isChannelInactive(userAgent) && userAgent.timestamp() + simplePushServer.config().userAgentReaperTimeout() < now) { logger.info("Removing inactive UserAgent [" + userAgent.uaid() + "]"); /* TODO: update this when persistence is in place so that the logic to remove is in one place and not spread out among the UserAgents class and the SimplePushServer. */ // remove from user agents map it.remove(); // remove from database simplePushServer.removeAllChannels(userAgent.uaid()); // close the user agent connectContext userAgent.context().close(); } } }
@Override public void run() { final Set<Ack> unacked = simplePushServer.getUnacknowledged(uaid); logger.info("Resending " + unacked); session.send(toJson(new NotificationMessageImpl(unacked))); } },
private boolean isChannelInactive(final UserAgent<SockJsSessionContext> userAgent) { final Channel ch = userAgent.context().getContext().channel(); return !ch.isActive() && !ch.isRegistered(); } }
@Override public Void call() throws Exception { try { final Notification notification = simplePushServer.handleNotification(endpoint, payload.toString(UTF_8)); final String uaid = notification.uaid(); final SockJsSessionContext session = userAgents.get(uaid).context(); if (logger.isDebugEnabled()) { logger.debug("Sending notification for UAID [ " + notification.uaid() + "] " + toJson(new NotificationMessageImpl(notification.ack()))); } session.send(toJson(new NotificationMessageImpl(notification.ack()))); userAgents.updateAccessedTime(uaid); } catch (final ChannelNotFoundException e) { logger.debug("Could not find channel for [" + endpoint + "]"); } catch (final VersionException e) { logger.debug(e.getMessage()); } finally { payload.release(); } return null; } }
private void processUnacked(final String uaid, final SockJsSessionContext session, final long delay) { final Set<Ack> unacked = simplePushServer.getUnacknowledged(uaid); if (unacked.isEmpty()) { if (ackJobFuture != null && !ackJobFuture.isCancelled()) { ackJobFuture.cancel(false); logger.info("Cancelled Re-Acknowledger job"); } } else if (ackJobFuture == null) { ackJobFuture = session.getContext().executor().scheduleAtFixedRate(new Runnable() { @Override public void run() { final Set<Ack> unacked = simplePushServer.getUnacknowledged(uaid); logger.info("Resending " + unacked); session.send(toJson(new NotificationMessageImpl(unacked))); } }, delay, simplePushServer.config().acknowledmentInterval(), TimeUnit.MILLISECONDS); } }
@Override public Void call() throws Exception { try { final Notification notification = simplePushServer.handleNotification(endpoint, payload.toString(UTF_8)); final String uaid = notification.uaid(); final SockJsSessionContext session = userAgents.get(uaid).context(); if (logger.isDebugEnabled()) { logger.debug("Sending notification for UAID [ " + notification.uaid() + "] " + toJson(new NotificationMessageImpl(notification.ack()))); } session.send(toJson(new NotificationMessageImpl(notification.ack()))); userAgents.updateAccessedTime(uaid); } catch (final ChannelNotFoundException e) { logger.debug("Could not find channel for [" + endpoint + "]"); } catch (final VersionException e) { logger.debug(e.getMessage()); } finally { payload.release(); } return null; } }
private void processUnacked(final String uaid, final SockJsSessionContext session, final long delay) { final Set<Ack> unacked = simplePushServer.getUnacknowledged(uaid); if (unacked.isEmpty()) { if (ackJobFuture != null && !ackJobFuture.isCancelled()) { ackJobFuture.cancel(false); logger.info("Cancelled Re-Acknowledger job"); } } else if (ackJobFuture == null) { ackJobFuture = session.getContext().executor().scheduleAtFixedRate(new Runnable() { @Override public void run() { final Set<Ack> unacked = simplePushServer.getUnacknowledged(uaid); logger.info("Resending " + unacked); session.send(toJson(new NotificationMessageImpl(unacked))); } }, delay, simplePushServer.config().acknowledmentInterval(), TimeUnit.MILLISECONDS); } }
if (!checkHandshakeCompleted(uaid)) { final HelloResponse response = simplePushServer.handleHandshake(fromJson(message, HelloMessageImpl.class)); session.send(toJson(response)); uaid = response.getUAID(); userAgents.add(uaid, session); if (checkHandshakeCompleted(uaid)) { final RegisterResponse response = simplePushServer.handleRegister(fromJson(message, RegisterMessageImpl.class), uaid); session.send(toJson(response)); logger.info("UserAgent [" + uaid + "] Registered[" + response.getChannelId() + "]"); final UnregisterMessage unregister = fromJson(message, UnregisterMessageImpl.class); final UnregisterResponse response = simplePushServer.handleUnregister(unregister, uaid); session.send(toJson(response)); logger.info("UserAgent [" + uaid + "] Unregistered[" + response.getChannelId() + "]"); session.send(PingMessageImpl.JSON); break;
if (!checkHandshakeCompleted(uaid)) { final HelloResponse response = simplePushServer.handleHandshake(fromJson(message, HelloMessageImpl.class)); session.send(toJson(response)); uaid = response.getUAID(); userAgents.add(uaid, session); if (checkHandshakeCompleted(uaid)) { final RegisterResponse response = simplePushServer.handleRegister(fromJson(message, RegisterMessageImpl.class), uaid); session.send(toJson(response)); logger.info("UserAgent [" + uaid + "] Registered[" + response.getChannelId() + "]"); final UnregisterMessage unregister = fromJson(message, UnregisterMessageImpl.class); final UnregisterResponse response = simplePushServer.handleUnregister(unregister, uaid); session.send(toJson(response)); logger.info("UserAgent [" + uaid + "] Unregistered[" + response.getChannelId() + "]"); session.send(PingMessageImpl.JSON); break;