resource.getBroadcaster().getBroadcasterConfig().addFilter(injectEndpoint ? onPerMessageFilter : onMessageFilter);
request.setAttribute(RemoteEndpointImpl.class.getName(), remoteEndpoint);
if (onOpenMethod != null) {
resource.addEventListener(new AtmosphereResourceEventListenerAdapter() {
@Override
public void onSuspend(AtmosphereResourceEvent event) {
try {
if (!trackedUUID.add(resource.uuid())) return;
// TODO: Document this behavior
// Temporary remove the resource from being the target for event, to avoid long-poling loop.
event.broadcaster().removeAtmosphereResource(resource);
try {
invokeOpenOrClose(onOpenMethod, remoteEndpoint);
} finally {
event.broadcaster().addAtmosphereResource(resource);
}
} finally {
event.getResource().removeEventListener(this);
}
}
});
}
if (onResumeMethod != null) {
resource.addEventListener(new AtmosphereResourceEventListenerAdapter() {
@Override
public void onResume(AtmosphereResourceEvent event) {
if (event.isResumedOnTimeout()) {
try {
invokeOpenOrClose(onResumeMethod, remoteEndpoint);