AtmospherePushConnection pushConnection = getConnectionForUI(ui); String id = resource.uuid();
/** * @param resource * @return the unique id for the given suspended connection * @deprecated use {@link AtmosphereResource#uuid()} */ @Deprecated public static String getUUID(AtmosphereResource resource) { return resource.uuid(); } }
/** * @param resource * @return the unique id for the given suspended connection * @deprecated use {@link AtmosphereResource#uuid()} */ @Deprecated public static String getUUID(AtmosphereResource resource) { return resource.uuid(); } }
@Ready public void onReady(final AtmosphereResource resource) { log.info("Browser " + resource.uuid() + " connected."); }
protected String uuid(AtmosphereResource r) { if(r==null)return null; String uuid = (String) r.getRequest().getAttribute(ApplicationConfig.SUSPENDED_ATMOSPHERE_RESOURCE_UUID); if(uuid==null){ uuid = r.uuid(); } return uuid; }
@SuppressWarnings("WeakerAccess") @Disconnect public void onDisconnect(final AtmosphereResourceEvent event) { if (event.isCancelled()) { // We didn't get notified, so we remove the user. logger.info("Browser {} unexpectedly disconnected for pathParam {}.", event.getResource().uuid(), id); } else if (event.isClosedByClient()) { logger.info("Browser {} closed the connection for pathParam {}.", event.getResource().uuid(), id); } else { logger.info("Browser {} closed for other reason for pathParam {}.", event.getResource().uuid(), id); } }
private void incrementUserSessionCount(AtmosphereResource resource) { String userId = getCurrentUserId(resource); boolean autoDelete = !(resource.transport() == AtmosphereResource.TRANSPORT.WEBSOCKET); userSessionCounterRepository.updateSession(userId, resource.uuid(), autoDelete); }
private boolean decrementUserSessionCount(AtmosphereResource resource) { String userId = getCurrentUserId(resource); if (userId == null) { LOGGER.debug("userId could not be found in Atmosphere session"); return false; } return userSessionCounterRepository.deleteSession(userId, resource.uuid()) < 1; }
@SuppressWarnings("WeakerAccess") @Ready(encoders = {WebSocketJSONConverter.class}) public WebSocketMessage onReady(final AtmosphereResource r) { logger.info("Browser {} connected to pathParam id {}.", r.uuid(), id); WebSocketMessage message = new WebSocketMessage(); message.setMessageType(MessageType.Heartbeat); message.setMessage("connected to " + id); return message; }
@Disconnect public final void onDisconnect(final AtmosphereResourceEvent event){ Collection<AtmosphereResource> atmosphereResources = event.getResource().getBroadcaster().getAtmosphereResources(); if (atmosphereResources.size() < 2 && subscription != null) { synchronized (subscription) { subscription.unsubscribe(); subscription = null; } LOG.debug("[websocket {}] [broadcaster:#{}] unsubscribed !", scopeAsAString, event.getResource().getBroadcaster().getID()); } if (event.isCancelled()) { LOG.info("[websocket {}] Client {} cancelled the connection", scopeAsAString, event.getResource().uuid()); } else if(event.isClosedByClient()) { LOG.info("[websocket {}] Client {} closed the connection", scopeAsAString, event.getResource().uuid()); } }
String uuid(AtmosphereResource r) { String s = (String) r.getRequest().getAttribute(SUSPENDED_ATMOSPHERE_RESOURCE_UUID); if (s != null) { return s; } s = r.getRequest().getHeader(HeaderConfig.X_ATMOSPHERE_TRACKING_ID); if (s != null && s != "0") { return s; } else { return r.uuid(); } }
@Override public void onDisconnect(AtmosphereResourceEvent event) { if (log.isDebugEnabled()) { String transport = event.getResource().getRequest().getHeader("X-Atmosphere-Transport"); HttpServletRequest req = event.getResource().getRequest(); log.debug(String.format("%s connection dropped from ip %s:%s", transport == null ? "websocket" : transport, req.getRemoteAddr(), req.getRemotePort())); } // It is possible that the application has already been destroyed, in which case // unregistration is no longer needed if (Application.get(applicationKey) != null) { findEventBus().unregisterConnection(event.getResource().uuid()); } }
@Override public Action suspended(AtmosphereRequest request, AtmosphereResponse response) throws IOException, ServletException { Action a = super.suspended(request, response); if (framework.getAtmosphereConfig().isSupportSession()) { AtmosphereResource r = request.resource(); HttpSession s = request.getSession(true); if (s != null) { sessions.put(r.uuid(), request.getSession(true)); } } return a; }
@Override public Action suspended(AtmosphereRequest request, AtmosphereResponse response) throws IOException, ServletException { Action a = super.suspended(request, response); if (framework.getAtmosphereConfig().isSupportSession()) { AtmosphereResource r = request.resource(); HttpSession s = request.getSession(true); if (s != null) { sessions.put(r.uuid(), request.getSession(true)); } } return a; }
@Ready public void onReady(final AtmosphereResource resource) throws IOException { log.info("[websocket] Client {} connected to build {}", resource.uuid(), resource.getBroadcaster().getID()); java.util.UUID buildId = BuildSerializer.uuidFromString(resource.getBroadcaster().getID()); if (build == null || build.getId() == null) { build = hub.getOrCreateBuild(buildId); } else { if (!build.getId().equals(buildId)) { log.debug("[websocket] this should never happen, no ? build.uuid {} !~= {} resource.getBroadcaster().getID", buildId, resource.getBroadcaster().getID()); } } }
@Override public void onResourceRequested() { RequestCycle requestCycle = RequestCycle.get(); ServletWebRequest request = (ServletWebRequest)requestCycle.getRequest(); // Grab a Meteor Meteor meteor = Meteor.build(request.getContainerRequest()); // Add us to the listener list. meteor.addListener(this); meteor.suspend(-1); String uuid = meteor.getAtmosphereResource().uuid(); component.getPage().setMetaData(ATMOSPHERE_UUID, uuid); findEventBus().registerPage(uuid, component.getPage()); }
@Override public void onRequest() { RequestCycle requestCycle = RequestCycle.get(); ServletWebRequest request = (ServletWebRequest)requestCycle.getRequest(); // Grab a Meteor Meteor meteor = Meteor.build(request.getContainerRequest()); // Add us to the listener list. meteor.addListener(this); meteor.suspend(-1); String uuid = meteor.getAtmosphereResource().uuid(); Page page = getComponent().getPage(); page.setMetaData(ATMOSPHERE_UUID, uuid); findEventBus().registerPage(uuid, page); }
@Override public void onRequest() { TesterBroadcaster broadcaster = (TesterBroadcaster) eventBus.getBroadcaster(); AtmosphereResource atmosphereResource = new AtmosphereResourceImpl(); AtmosphereRequest atmosphereRequest = AtmosphereRequest.wrap(wicketTester.getRequest()); AtmosphereResponse atmosphereResponse = AtmosphereResponse.wrap(wicketTester.getResponse()); TesterAsyncSupport asyncSupport = new TesterAsyncSupport(); atmosphereResource.initialize(broadcaster.getApplicationConfig(), broadcaster, atmosphereRequest, atmosphereResponse, asyncSupport, new AtmosphereHandlerAdapter()); atmosphereResource.setBroadcaster(broadcaster); broadcaster.addAtmosphereResource(atmosphereResource); String uuid = atmosphereResource.uuid(); Page page = getComponent().getPage(); page.setMetaData(ATMOSPHERE_UUID, uuid); eventBus.registerPage(uuid, page); } }