|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.io.Reader; |
|
|
import java.io.Reader; |
|
|
|
|
|
import java.util.Collection; |
|
|
import java.util.logging.Level; |
|
|
import java.util.logging.Level; |
|
|
import java.util.logging.Logger; |
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Establishes bidirectional ("push") communication channels |
|
|
* Establishes bidirectional ("push") communication channels |
|
|
* |
|
|
|
|
|
|
|
|
* |
|
|
* @author Vaadin Ltd |
|
|
* @author Vaadin Ltd |
|
|
* @since 7.1 |
|
|
* @since 7.1 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Find the UI for the atmosphere resource, lock it and invoke the callback. |
|
|
* Find the UI for the atmosphere resource, lock it and invoke the callback. |
|
|
* |
|
|
|
|
|
|
|
|
* |
|
|
* @param resource |
|
|
* @param resource |
|
|
* the atmosphere resource for the current request |
|
|
* the atmosphere resource for the current request |
|
|
* @param callback |
|
|
* @param callback |
|
|
|
|
|
|
|
|
// Sets UI.currentInstance |
|
|
// Sets UI.currentInstance |
|
|
ui = service.findUI(vaadinRequest); |
|
|
ui = service.findUI(vaadinRequest); |
|
|
if (ui == null) { |
|
|
if (ui == null) { |
|
|
getLogger().log(Level.SEVERE, |
|
|
|
|
|
"Could not get UI. This should never happen"); |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* UI not found, could be because FF has asynchronously closed |
|
|
|
|
|
* the websocket connection and Atmosphere has already done |
|
|
|
|
|
* cleanup of the request attributes. |
|
|
|
|
|
* |
|
|
|
|
|
* In that case, we still have a chance of finding the right UI |
|
|
|
|
|
* by iterating through the UIs in the session looking for one |
|
|
|
|
|
* using the same AtmosphereResource. |
|
|
|
|
|
*/ |
|
|
|
|
|
ui = findUiUsingResource(resource, session.getUIs()); |
|
|
|
|
|
|
|
|
|
|
|
if (ui == null) { |
|
|
|
|
|
getLogger() |
|
|
|
|
|
.log(Level.SEVERE, |
|
|
|
|
|
"Could not get UI. This should never happen," |
|
|
|
|
|
+ " except when reloading in Firefox -" |
|
|
|
|
|
+ " see http://dev.vaadin.com/ticket/14251."); |
|
|
|
|
|
return; |
|
|
|
|
|
} else { |
|
|
|
|
|
getLogger() |
|
|
|
|
|
.log(Level.INFO, |
|
|
|
|
|
"No UI was found based on data in the request," |
|
|
|
|
|
+ " but a slower lookup based on the AtmosphereResource succeeded." |
|
|
|
|
|
+ " See http://dev.vaadin.com/ticket/14251 for more details."); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
PushMode pushMode = ui.getPushConfiguration().getPushMode(); |
|
|
PushMode pushMode = ui.getPushConfiguration().getPushMode(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static UI findUiUsingResource(AtmosphereResource resource, |
|
|
|
|
|
Collection<UI> uIs) { |
|
|
|
|
|
for (UI ui : uIs) { |
|
|
|
|
|
PushConnection pushConnection = ui.getPushConnection(); |
|
|
|
|
|
if (pushConnection instanceof AtmospherePushConnection) { |
|
|
|
|
|
if (((AtmospherePushConnection) pushConnection).getResource() == resource) { |
|
|
|
|
|
return ui; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Sends a refresh message to the given atmosphere resource. Uses an |
|
|
* Sends a refresh message to the given atmosphere resource. Uses an |
|
|
* AtmosphereResource instead of an AtmospherePushConnection even though it |
|
|
* AtmosphereResource instead of an AtmospherePushConnection even though it |
|
|
|
|
|
|
|
|
* two push connections which try to use the same UI. Using the |
|
|
* two push connections which try to use the same UI. Using the |
|
|
* AtmosphereResource directly guarantees the message goes to the correct |
|
|
* AtmosphereResource directly guarantees the message goes to the correct |
|
|
* recipient. |
|
|
* recipient. |
|
|
* |
|
|
|
|
|
|
|
|
* |
|
|
* @param resource |
|
|
* @param resource |
|
|
* The atmosphere resource to send refresh to |
|
|
* The atmosphere resource to send refresh to |
|
|
* |
|
|
|
|
|
|
|
|
* |
|
|
*/ |
|
|
*/ |
|
|
private static void sendRefreshAndDisconnect(AtmosphereResource resource) |
|
|
private static void sendRefreshAndDisconnect(AtmosphereResource resource) |
|
|
throws IOException { |
|
|
throws IOException { |