WICKET-6305 Remove Atmosphere module
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/0dd70694 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/0dd70694 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/0dd70694 Branch: refs/heads/master Commit: 0dd7069492cbf560b19d4d9391cd66de32c87b6b Parents: d9bfc96 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Fri Jan 13 19:01:20 2017 +0100 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Fri Jan 13 19:01:20 2017 +0100 ---------------------------------------------------------------------- wicket-experimental/pom.xml | 1 - wicket-experimental/wicket-atmosphere/pom.xml | 121 ---- .../atmosphere/AjaxRequestInitializer.java | 30 - .../wicket/atmosphere/AtmosphereBehavior.java | 278 -------- .../wicket/atmosphere/AtmosphereEvent.java | 54 -- .../AtmosphereEventSubscriptionCollector.java | 119 ---- .../atmosphere/AtmosphereInternalEvent.java | 88 --- .../atmosphere/AtmosphereRequestHandler.java | 141 ---- .../atmosphere/AtmosphereRequestMapper.java | 76 --- .../wicket/atmosphere/AtmosphereWebRequest.java | 239 ------- .../atmosphere/AtmosphereWebResponse.java | 179 ----- .../org/apache/wicket/atmosphere/EventBus.java | 567 ---------------- .../apache/wicket/atmosphere/EventFilter.java | 46 -- .../wicket/atmosphere/EventSubscription.java | 175 ----- .../atmosphere/EventSubscriptionInvoker.java | 47 -- .../apache/wicket/atmosphere/Initializer.java | 42 -- ...JQueryWicketAtmosphereResourceReference.java | 59 -- .../wicket/atmosphere/NoFilterPredicate.java | 33 - .../org/apache/wicket/atmosphere/PageKey.java | 87 --- .../ResourceRegistrationListener.java | 51 -- .../org/apache/wicket/atmosphere/Subscribe.java | 67 -- ...cribeAnnotationEventSubscriptionInvoker.java | 61 -- .../atmosphere/config/AtmosphereLogLevel.java | 40 -- .../atmosphere/config/AtmosphereMethod.java | 27 - .../atmosphere/config/AtmosphereParameters.java | 667 ------------------- .../atmosphere/config/AtmosphereTransport.java | 41 -- .../atmosphere/jquery.wicketatmosphere.js | 45 -- .../atmosphere/tester/AtmosphereTester.java | 197 ------ .../atmosphere/tester/TesterAsyncSupport.java | 68 -- .../tester/TesterAtmosphereBehavior.java | 65 -- .../atmosphere/tester/TesterBroadcaster.java | 41 -- .../tester/TesterBroadcasterFactory.java | 48 -- .../services/org.apache.wicket.IInitializer | 1 - .../wicket/atmosphere/AtmosphereTesterTest.java | 110 --- .../apache/wicket/atmosphere/ChatMessage.java | 42 -- .../org/apache/wicket/atmosphere/HomePage.html | 24 - .../org/apache/wicket/atmosphere/HomePage.java | 84 --- .../wicket/atmosphere/ReceiverFilter.java | 40 -- .../util/license/ApacheLicenceHeaderTest.java | 35 - 39 files changed, 4136 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-experimental/pom.xml b/wicket-experimental/pom.xml index 99b02eb..1c9c529 100644 --- a/wicket-experimental/pom.xml +++ b/wicket-experimental/pom.xml @@ -29,7 +29,6 @@ <name>Wicket-Experimental</name> <description>Wicket-Experimental contains experimental Wicket modules that may or may not be supported in the future.</description> <modules> - <module>wicket-atmosphere</module> <module>wicket-http2</module> <module>wicket-metrics</module> </modules> http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/pom.xml b/wicket-experimental/wicket-atmosphere/pom.xml deleted file mode 100644 index d9e973d..0000000 --- a/wicket-experimental/wicket-atmosphere/pom.xml +++ /dev/null @@ -1,121 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.wicket.experimental.wicket8</groupId> - <artifactId>wicket-experimental</artifactId> - <version>8.0.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - <artifactId>wicket-atmosphere</artifactId> - <version>0.25-SNAPSHOT</version> - <packaging>jar</packaging> - <name>Wicket-Atmosphere</name> - <description>Wicket-Atmosphere provides integration of the Atmosphere Framework in Wicket.</description> - <repositories> - <repository> - <id>Sonatype OSS snapshots</id> - <url>https://oss.sonatype.org/content/repositories/snapshots/</url> - <releases> - <enabled>false</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </repository> - </repositories> - <properties> - <atmosphere.version>2.2.8</atmosphere.version> - <jquery.atmosphere.version>2.2.13</jquery.atmosphere.version> - </properties> - <dependencyManagement> - <dependencies> - <dependency> - <groupId>org.atmosphere</groupId> - <artifactId>atmosphere-runtime</artifactId> - <version>${atmosphere.version}</version> - <exclusions> - <exclusion> - <groupId>org.atmosphere</groupId> - <artifactId>atmosphere-compat-jetty</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.webjars</groupId> - <artifactId>jquery-atmosphere</artifactId> - <version>${jquery.atmosphere.version}</version> - <exclusions> - <exclusion> - <groupId>org.webjars</groupId> - <artifactId>jquery</artifactId> - </exclusion> - </exclusions> - </dependency> - </dependencies> - </dependencyManagement> - <dependencies> - <dependency> - <groupId>com.google.code.findbugs</groupId> - <artifactId>jsr305</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> - <dependency> - <groupId>de.agilecoders.wicket.webjars</groupId> - <artifactId>wicket-webjars</artifactId> - </dependency> - <dependency> - <groupId>org.apache.wicket</groupId> - <artifactId>wicket-core</artifactId> - </dependency> - <dependency> - <groupId>org.atmosphere</groupId> - <artifactId>atmosphere-runtime</artifactId> - </dependency> - <dependency> - <groupId>org.webjars</groupId> - <artifactId>jquery-atmosphere</artifactId> - </dependency> - </dependencies> - <build> - <resources> - <resource> - <directory>src/main/resources</directory> - <filtering>false</filtering> - </resource> - <resource> - <directory>src/main/java</directory> - <filtering>false</filtering> - <includes> - <include>**/jquery.wicketatmosphere.js</include> - </includes> - </resource> - </resources> - <plugins> - <plugin> - <groupId>net.alchim31.maven</groupId> - <artifactId>yuicompressor-maven-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AjaxRequestInitializer.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AjaxRequestInitializer.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AjaxRequestInitializer.java deleted file mode 100644 index 882e931..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AjaxRequestInitializer.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import org.apache.wicket.ajax.AjaxRequestTarget; - -/** - * Initializes {@link AjaxRequestTarget} for current event notification. - */ -public interface AjaxRequestInitializer -{ - /** - * performs initialization of {@link AjaxRequestTarget} - */ - void initialize(); -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java deleted file mode 100644 index e2b7707..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereBehavior.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import org.apache.wicket.Application; -import org.apache.wicket.Component; -import org.apache.wicket.MetaDataKey; -import org.apache.wicket.Page; -import org.apache.wicket.WicketRuntimeException; -import org.apache.wicket.behavior.AbstractAjaxBehavior; -import org.apache.wicket.markup.head.IHeaderResponse; -import org.apache.wicket.markup.head.JavaScriptHeaderItem; -import org.apache.wicket.markup.head.OnDomReadyHeaderItem; -import org.apache.wicket.protocol.http.servlet.ServletWebRequest; -import org.apache.wicket.request.Url; -import org.apache.wicket.request.cycle.RequestCycle; -import org.apache.wicket.request.http.WebRequest; -import org.apache.wicket.resource.CoreLibrariesContributor; -import org.apache.wicket.util.string.Strings; -import org.atmosphere.cpr.AtmosphereRequest; -import org.atmosphere.cpr.AtmosphereResource; -import org.atmosphere.cpr.AtmosphereResourceEvent; -import org.atmosphere.cpr.AtmosphereResourceEventListener; -import org.atmosphere.cpr.HeaderConfig; -import org.atmosphere.cpr.Meteor; -import org.json.JSONException; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * {@code AtmosphereBehavior} manages the suspended connection from the client. It adds the required - * javascript libraries to the markup which setup a suspended connection. This connection can be - * websocket, streaming http or long-polling, depending on what the client and server support. This - * behavior is added automatically to pages with components with event subscriptions. - * - * @author papegaaij - */ -public class AtmosphereBehavior extends AbstractAjaxBehavior - implements - AtmosphereResourceEventListener -{ - private static final Logger log = LoggerFactory.getLogger(AtmosphereBehavior.class); - - /** - * The key under which a unique id is stored in the page. This id is unique for all clients. - */ - public static final MetaDataKey<String> ATMOSPHERE_UUID = new MetaDataKey<String>() - { - private static final long serialVersionUID = 1L; - }; - - private static final long serialVersionUID = 1L; - - private String applicationKey; - - - /** - * Construct. - */ - public AtmosphereBehavior() - { - applicationKey = Application.get().getApplicationKey(); - } - - private EventBus findEventBus() - { - return EventBus.get(Application.get(applicationKey)); - } - - @Override - public final boolean getStatelessHint(Component component) - { - return false; - } - - @Override - public void onPreSuspend(AtmosphereResourceEvent event) - { - } - - @Override - public void onClose(AtmosphereResourceEvent event) - { - } - - - @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 onBroadcast(AtmosphereResourceEvent event) - { - if (log.isDebugEnabled()) - { - log.debug("onBroadcast: {}", event.getMessage()); - } - - // If we are using long-polling, resume the connection as soon as we get - // an event. - String transport = event.getResource() - .getRequest() - .getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT); - - if (HeaderConfig.LONG_POLLING_TRANSPORT.equalsIgnoreCase(transport)) - { - Meteor meteor = Meteor.lookup(event.getResource().getRequest()); - meteor.resume(); - } - EventBus eventBus = findEventBus(); - if (eventBus.isWantAtmosphereNotifications()) - { - eventBus.post(new AtmosphereInternalEvent(AtmosphereInternalEvent.Type.Broadcast, event)); - } - } - - @Override - public void onSuspend(AtmosphereResourceEvent event) - { - if (log.isDebugEnabled()) - { - AtmosphereRequest atmosphereRequest = event.getResource().getRequest(); - String transport = atmosphereRequest.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT); - log.debug(String.format("Suspending the %s response from ip %s:%s", transport == null - ? "websocket" : transport, atmosphereRequest.getRemoteAddr(), atmosphereRequest.getRemotePort())); - } - } - - @Override - public void onResume(AtmosphereResourceEvent event) - { - if (log.isDebugEnabled()) - { - AtmosphereRequest atmosphereRequest = event.getResource().getRequest(); - String transport = atmosphereRequest.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT); - log.debug(String.format("Resuming the %s response from ip %s:%s", transport == null - ? "websocket" : transport, atmosphereRequest.getRemoteAddr(), atmosphereRequest.getRemotePort())); - } - EventBus eventBus = findEventBus(); - if (eventBus.isWantAtmosphereNotifications()) - { - eventBus.post(new AtmosphereInternalEvent(AtmosphereInternalEvent.Type.Resume, event)); - } - } - - @Override - public void onDisconnect(AtmosphereResourceEvent event) - { - if (log.isDebugEnabled()) - { - AtmosphereRequest atmosphereRequest = event.getResource().getRequest(); - String transport = atmosphereRequest.getHeader(HeaderConfig.X_ATMOSPHERE_TRANSPORT); - log.debug(String.format("%s connection dropped from ip %s:%s", transport == null - ? "websocket" : transport, atmosphereRequest.getRemoteAddr(), atmosphereRequest.getRemotePort())); - } - // It is possible that the application has already been destroyed, in which case - // unregistration is no longer needed - EventBus eventBus = findEventBus(); - if (Application.get(applicationKey) != null) - { - eventBus.unregisterConnection(event.getResource().uuid()); - } - - if (eventBus.isWantAtmosphereNotifications()) - { - eventBus.post(new AtmosphereInternalEvent(AtmosphereInternalEvent.Type.Disconnect, event)); - } - } - - @Override - public void onThrowable(AtmosphereResourceEvent event) - { - Throwable throwable = event.throwable(); - log.error(throwable.getMessage(), throwable); - - EventBus eventBus = findEventBus(); - if (eventBus.isWantAtmosphereNotifications()) - { - eventBus.post(new AtmosphereInternalEvent(AtmosphereInternalEvent.Type.Throwable, event)); - } - } - - @Override - public void onHeartbeat(AtmosphereResourceEvent event) - { - } - - @Override - public void renderHead(Component component, IHeaderResponse response) - { - super.renderHead(component, response); - try - { - CoreLibrariesContributor.contributeAjax(component.getApplication(), response); - - response.render(JavaScriptHeaderItem.forReference(JQueryWicketAtmosphereResourceReference.get())); - JSONObject options = findEventBus().getParameters().toJSON(); - options.put("url", getCallbackUrl()); - response.render(OnDomReadyHeaderItem.forScript("jQuery('#" + component.getMarkupId() + - "').wicketAtmosphere(" + options.toString() + ")")); - } - catch (JSONException e) - { - throw new WicketRuntimeException(e); - } - } - - /** - * Make it look like a normal Ajax call so the page id/renderCount are not incremented when Atmosphere makes - * the "upgrade" request - * - * @return the url to this behavior's listener interface - */ - @Override - public CharSequence getCallbackUrl() - { - RequestCycle requestCycle = getComponent().getRequestCycle(); - Url baseUrl = requestCycle.getUrlRenderer().getBaseUrl(); - CharSequence ajaxBaseUrl = Strings.escapeMarkup(baseUrl.toString()); - - return new StringBuilder(256) - .append(super.getCallbackUrl()) - .append('&').append(WebRequest.PARAM_AJAX).append("=true&") - .append(WebRequest.PARAM_AJAX_BASE_URL).append('=').append(ajaxBaseUrl); - } - - /** - * Find the Atmosphere UUID for the suspended connection for the given page (if any). - * - * @param page - * @return The UUID of the Atmosphere Resource, or null if no resource is suspended for the - * page. - */ - public static String getUUID(Page page) - { - return page.getMetaData(ATMOSPHERE_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(); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereEvent.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereEvent.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereEvent.java deleted file mode 100644 index 7b06d0c..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereEvent.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import org.atmosphere.cpr.AtmosphereResource; - -/** - * The event fired by {@link EventBus}, containing the payload and the {@code AtmosphereResource} it - * is targeted at. - * - * @author papegaaij - */ -public class AtmosphereEvent -{ - private final Object payload; - - private final AtmosphereResource resource; - - AtmosphereEvent(Object payload, AtmosphereResource resource) - { - this.payload = payload; - this.resource = resource; - } - - /** - * @return The payload of the event, as posted on the {@link EventBus}. - */ - public Object getPayload() - { - return payload; - } - - /** - * @return The resource this event is targeted at. - */ - public AtmosphereResource getResource() - { - return resource; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereEventSubscriptionCollector.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereEventSubscriptionCollector.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereEventSubscriptionCollector.java deleted file mode 100644 index 61ebd4a..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereEventSubscriptionCollector.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import java.lang.reflect.Method; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; - -import org.apache.wicket.Component; -import org.apache.wicket.Page; -import org.apache.wicket.WicketRuntimeException; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.application.IComponentOnBeforeRenderListener; -import org.apache.wicket.behavior.Behavior; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.collect.ImmutableList; - -/** - * Collects {@linkplain Subscribe event subscriptions} on components. Subscriptions are refreshed on - * every render of component. If a page contains a component with a subscription, an - * {@link AtmosphereBehavior} is added to the page. There is no need to register this listener, it - * is added automatically by {@link EventBus}. - * - * @author papegaaij - */ -public class AtmosphereEventSubscriptionCollector implements IComponentOnBeforeRenderListener -{ - private Cache<Class<?>, Iterable<Method>> subscribedMethodsCache; - private EventBus eventBus; - - /** - * Construct. - * - * @param eventBus - */ - public AtmosphereEventSubscriptionCollector(EventBus eventBus) - { - this.eventBus = eventBus; - subscribedMethodsCache = CacheBuilder.newBuilder().build(); - } - - @Override - public void onBeforeRender(Component component) - { - for (Method curMethod : findSubscribedMethods(component.getClass())) - { - subscribeComponent(component, null, curMethod); - } - for (Behavior curBehavior : component.getBehaviors()) - { - for (Method curMethod : findSubscribedMethods(curBehavior.getClass())) - { - subscribeComponent(component, curBehavior, curMethod); - } - } - } - - private Iterable<Method> findSubscribedMethods(final Class<?> clazz) - { - try - { - return subscribedMethodsCache.get(clazz, new Callable<Iterable<Method>>() - { - @Override - public Iterable<Method> call() throws Exception - { - ImmutableList.Builder<Method> ret = ImmutableList.builder(); - for (Method curMethod : clazz.getMethods()) - { - if (curMethod.isAnnotationPresent(Subscribe.class)) - { - verifyMethodParameters(curMethod); - ret.add(curMethod); - } - } - return ret.build(); - } - }); - } - catch (ExecutionException e) - { - throw new WicketRuntimeException(e); - } - } - - private void verifyMethodParameters(Method method) - { - Class<?>[] params = method.getParameterTypes(); - if (params.length != 2 || !params[0].equals(AjaxRequestTarget.class)) - throw new WicketRuntimeException("@Subscribe can only be used on " + - "methods with 2 params, of which the first is AjaxRequestTarget. " + method + - " does not conform to this signature."); - } - - private void subscribeComponent(Component component, Behavior behavior, Method method) - { - EventSubscription subscription = new EventSubscription(component, behavior, method); - Page page = component.getPage(); - eventBus.register(page, subscription); - if (page.getBehaviors(AtmosphereBehavior.class).isEmpty()) - page.add(new AtmosphereBehavior()); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereInternalEvent.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereInternalEvent.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereInternalEvent.java deleted file mode 100644 index 46b8da6..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereInternalEvent.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import org.atmosphere.cpr.AtmosphereResourceEvent; - -/** - * An event that is broadcasted by the EventBus whenever Atmosphere notifies - * {@linkplain org.apache.wicket.atmosphere.AtmosphereBehavior} about {@link org.atmosphere.cpr.AtmosphereResourceEventListener} - * events. - * - * To be notified add a method like the one below to your components: - * <pre><code>{@literal - * @Subscribe - * public void anyName(AjaxRequestTarget target, AtmosphereInternalEvent event) { - * switch (event.getType()) { - * case Resume: ...; break; - * case Disconnect: ...; break; - * .... - * } - * } - * }</code></pre> - * - * @see org.apache.wicket.atmosphere.EventBus#wantAtmosphereNotifications - * @see org.atmosphere.cpr.AtmosphereResourceEventListener - */ -public class AtmosphereInternalEvent -{ - /** - * The types enumerating the notification methods in {@link org.atmosphere.cpr.AtmosphereResourceEventListener} - * - * Suspend type is not supported because it is not possible to push messages with suspended connection - */ - public static enum Type - { - PreSuspend, /*Suspend,*/ Resume, Disconnect, Broadcast, Throwable, Close - } - - /** - * The internal Atmosphere event - */ - private final AtmosphereResourceEvent event; - - /** - * The type of the notification - */ - private final Type type; - - - public AtmosphereInternalEvent(Type type, AtmosphereResourceEvent event) - { - this.type = type; - this.event = event; - } - - public AtmosphereResourceEvent getEvent() - { - return event; - } - - public Type getType() - { - return type; - } - - @Override - public String toString() - { - return "AtmosphereInternalEvent{" + - "event=" + event + - ", type=" + type + - '}'; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java deleted file mode 100644 index cbb8ef5..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestHandler.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import java.util.Iterator; - -import org.apache.wicket.Component; -import org.apache.wicket.Page; -import org.apache.wicket.Session; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.behavior.Behavior; -import org.apache.wicket.protocol.http.WebApplication; -import org.apache.wicket.request.IRequestCycle; -import org.apache.wicket.request.IRequestHandler; -import org.apache.wicket.request.cycle.RequestCycle; -import org.apache.wicket.util.lang.Args; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Handles pseudo requests triggered by an event. An {@link AjaxRequestTarget} is scheduled and the - * subscribed methods are invoked. - * - * @author papegaaij - */ -public class AtmosphereRequestHandler implements IRequestHandler -{ - private static final Logger LOGGER = LoggerFactory.getLogger(AtmosphereRequestHandler.class); - - private final PageKey pageKey; - - private final AtmosphereEvent event; - - private final Iterator<EventSubscription> subscriptions; - - private final EventSubscriptionInvoker eventSubscriptionInvoker; - - private boolean ajaxRequestScheduled = false; - - /** - * Construct. - * - * @param pageKey - * @param subscriptions - * @param event - * @param eventSubscriptionInvoker - */ - public AtmosphereRequestHandler(PageKey pageKey, Iterator<EventSubscription> subscriptions, - AtmosphereEvent event, EventSubscriptionInvoker eventSubscriptionInvoker) - { - this.pageKey = pageKey; - this.subscriptions = subscriptions; - this.event = event; - this.eventSubscriptionInvoker = Args.notNull(eventSubscriptionInvoker, "eventSubscriptionInvoker"); - } - - @Override - public void respond(IRequestCycle requestCycle) - { - WebApplication application = WebApplication.get(); - Integer pageId = pageKey.getPageId(); - Page page = (Page) Session.get().getPageManager().getPage(pageId); - if (page != null) - { - page.dirty(); - AjaxRequestTarget target = application.newAjaxRequestTarget(page); - executeHandlers(target, page); - } - else - { - LOGGER.warn("Could not find a page with id '{}' for session with id '{}' in the page stores. It will be unregistered", - pageId, pageKey.getSessionId()); - EventBus.get(application).unregister(pageKey); - - } - } - - private void executeHandlers(AjaxRequestTarget target, Page page) - { - while (subscriptions.hasNext()) - { - EventSubscription curSubscription = subscriptions.next(); - if (curSubscription.getContextAwareFilter().apply(event)) - { - String componentPath = curSubscription.getComponentPath(); - Component component = page.get(componentPath); - if (component != null) - { - Integer behaviorIndex = curSubscription.getBehaviorIndex(); - if (behaviorIndex == null) - { - invokeMethod(target, curSubscription, component); - } - else - { - Behavior behavior = component.getBehaviorById(behaviorIndex); - invokeMethod(target, curSubscription, behavior); - } - } - else - { - LOGGER.debug("Cannot find component with path '{}' in page '{}'. Maybe it has been removed.", - componentPath, page); - EventBus.get().unregister(page, curSubscription); - } - } - } - } - - private void invokeMethod(final AjaxRequestTarget target, EventSubscription subscription, - Object base) - { - AjaxRequestInitializer initializer = new AjaxRequestInitializer() - { - @Override - public void initialize() - { - if (!ajaxRequestScheduled) - { - RequestCycle.get().scheduleRequestHandlerAfterCurrent(target); - ajaxRequestScheduled = true; - } - } - }; - eventSubscriptionInvoker.invoke(target, subscription, base, event, initializer); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestMapper.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestMapper.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestMapper.java deleted file mode 100644 index 0f427e2..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereRequestMapper.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import org.apache.wicket.request.IRequestHandler; -import org.apache.wicket.request.IRequestMapper; -import org.apache.wicket.request.Request; -import org.apache.wicket.request.Url; -import org.apache.wicket.util.lang.Args; - -/** - * Internal {@link IRequestMapper} to map {@link AtmosphereWebRequest} to - * {@link AtmosphereRequestHandler}. This mapper is registered automatically by {@link EventBus}. - * - * @author papegaaij - */ -public class AtmosphereRequestMapper implements IRequestMapper -{ - private final EventSubscriptionInvoker eventSubscriptionInvoker; - - /** - * Construct with {@link SubscribeAnnotationEventSubscriptionInvoker} - */ - public AtmosphereRequestMapper() - { - eventSubscriptionInvoker = new SubscribeAnnotationEventSubscriptionInvoker(); - } - - /** - * Construct. - * - * @param eventSubscriptionInvoker - */ - public AtmosphereRequestMapper(EventSubscriptionInvoker eventSubscriptionInvoker) - { - this.eventSubscriptionInvoker = Args.notNull(eventSubscriptionInvoker, "eventSubscriptionInvoker"); - } - - @Override - public IRequestHandler mapRequest(Request request) - { - if (request instanceof AtmosphereWebRequest) - { - AtmosphereWebRequest pushRequest = (AtmosphereWebRequest)request; - return new AtmosphereRequestHandler(pushRequest.getPageKey(), - pushRequest.getSubscriptions(), pushRequest.getEvent(), eventSubscriptionInvoker); - } - return null; - } - - @Override - public int getCompatibilityScore(Request request) - { - return request instanceof AtmosphereWebRequest ? Integer.MAX_VALUE : 0; - } - - @Override - public Url mapHandler(IRequestHandler requestHandler) - { - return null; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebRequest.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebRequest.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebRequest.java deleted file mode 100644 index 5922270..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebRequest.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import java.nio.charset.Charset; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.fileupload.FileItemFactory; -import org.apache.commons.fileupload.FileUploadException; -import org.apache.wicket.protocol.http.RequestUtils; -import org.apache.wicket.protocol.http.servlet.MultipartServletWebRequest; -import org.apache.wicket.protocol.http.servlet.ServletWebRequest; -import org.apache.wicket.request.IRequestParameters; -import org.apache.wicket.request.Url; -import org.apache.wicket.util.lang.Bytes; -import org.apache.wicket.util.time.Time; - -/** - * Internal request to signal the processing of an event. This request will be mapped by - * {@link AtmosphereRequestMapper} to an {@link AtmosphereRequestHandler}. The response will be - * written to the client of a suspended connection. - * - * @author papegaaij - */ -class AtmosphereWebRequest extends ServletWebRequest -{ - private final ServletWebRequest wrappedRequest; - - private final PageKey pageKey; - - private final Iterator<EventSubscription> subscriptions; - - private final AtmosphereEvent event; - - AtmosphereWebRequest(ServletWebRequest wrappedRequest, PageKey pageKey, - Iterator<EventSubscription> subscriptions, AtmosphereEvent event) - { - super(wrappedRequest.getContainerRequest(), wrappedRequest.getFilterPrefix()); - this.wrappedRequest = wrappedRequest; - this.pageKey = pageKey; - this.subscriptions = subscriptions; - this.event = event; - } - - public PageKey getPageKey() - { - return pageKey; - } - - public Iterator<EventSubscription> getSubscriptions() - { - return subscriptions; - } - - public AtmosphereEvent getEvent() - { - return event; - } - - @Override - public List<Cookie> getCookies() - { - return wrappedRequest.getCookies(); - } - - @Override - public List<String> getHeaders(String name) - { - return wrappedRequest.getHeaders(name); - } - - @Override - public String getHeader(String name) - { - return wrappedRequest.getHeader(name); - } - - @Override - public Time getDateHeader(String name) - { - return wrappedRequest.getDateHeader(name); - } - - @Override - public Url getUrl() - { - return wrappedRequest.getUrl(); - } - - @Override - public Url getClientUrl() - { - return wrappedRequest.getClientUrl(); - } - - @Override - public Locale getLocale() - { - return wrappedRequest.getLocale(); - } - - @Override - public Charset getCharset() - { - // called from the super constructor, when wrappedRequest is still null - if (wrappedRequest == null) - return RequestUtils.getCharset(super.getContainerRequest()); - return wrappedRequest.getCharset(); - } - - @Override - public Cookie getCookie(String cookieName) - { - return wrappedRequest.getCookie(cookieName); - } - - @Override - public int hashCode() - { - return wrappedRequest.hashCode(); - } - - @Override - public Url getOriginalUrl() - { - return wrappedRequest.getOriginalUrl(); - } - - @Override - public IRequestParameters getQueryParameters() - { - return wrappedRequest.getQueryParameters(); - } - - @Override - public IRequestParameters getRequestParameters() - { - return wrappedRequest.getRequestParameters(); - } - - @Override - public boolean equals(Object obj) - { - return wrappedRequest.equals(obj); - } - - @Override - public String getFilterPrefix() - { - return wrappedRequest.getFilterPrefix(); - } - - @Override - public String toString() - { - return wrappedRequest.toString(); - } - - @Override - public IRequestParameters getPostParameters() - { - return wrappedRequest.getPostParameters(); - } - - @Override - public ServletWebRequest cloneWithUrl(Url url) - { - return wrappedRequest.cloneWithUrl(url); - } - - @Override - public MultipartServletWebRequest newMultipartWebRequest(Bytes maxSize, String upload) - throws FileUploadException - { - return wrappedRequest.newMultipartWebRequest(maxSize, upload); - } - - @Override - public MultipartServletWebRequest newMultipartWebRequest(Bytes maxSize, String upload, - FileItemFactory factory) throws FileUploadException - { - return wrappedRequest.newMultipartWebRequest(maxSize, upload, factory); - } - - @Override - public String getPrefixToContextPath() - { - return wrappedRequest.getPrefixToContextPath(); - } - - @Override - public HttpServletRequest getContainerRequest() - { - return wrappedRequest.getContainerRequest(); - } - - @Override - public String getContextPath() - { - return wrappedRequest.getContextPath(); - } - - @Override - public String getFilterPath() - { - return wrappedRequest.getFilterPath(); - } - - @Override - public boolean shouldPreserveClientUrl() - { - return wrappedRequest.shouldPreserveClientUrl(); - } - - @Override - public boolean isAjax() - { - return true; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebResponse.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebResponse.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebResponse.java deleted file mode 100644 index 5653deb..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/AtmosphereWebResponse.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import javax.servlet.http.Cookie; - -import org.apache.wicket.request.http.WebResponse; -import org.apache.wicket.util.string.AppendingStringBuffer; -import org.apache.wicket.util.time.Time; -import org.atmosphere.cpr.AtmosphereResponse; - -/** - * Internal response class to wrap {@code AtmosphereResponse} to a {@link WebResponse}. - * - * @author papegaaij - */ -class AtmosphereWebResponse extends WebResponse -{ - private final AtmosphereResponse response; - private final AppendingStringBuffer out; - private boolean redirect; - - /** - * Construct. - * - * @param response - */ - AtmosphereWebResponse(AtmosphereResponse response) - { - this.response = response; - out = new AppendingStringBuffer(128); - } - - @Override - public void addCookie(Cookie cookie) - { - response.addCookie(cookie); - } - - @Override - public void clearCookie(Cookie cookie) - { - throw new UnsupportedOperationException(); - } - - @Override - public void setHeader(String name, String value) - { - response.setHeader(name, value); - } - - @Override - public void addHeader(String name, String value) - { - response.addHeader(name, value); - } - - @Override - public void setDateHeader(String name, Time date) - { - response.setDateHeader(name, date.getMilliseconds()); - } - - @Override - public void setContentLength(long length) - { - response.addHeader("Content-Length", Long.toString(length)); - } - - @Override - public void setContentType(String mimeType) - { - response.setContentType(mimeType); - } - - @Override - public void setStatus(int sc) - { - response.setStatus(sc); - } - - @Override - public void sendError(int sc, String msg) - { - throw new UnsupportedOperationException(); - } - - @Override - public String encodeRedirectURL(CharSequence url) - { - // TODO temp fix for https://github.com/Atmosphere/atmosphere/issues/949 - return url.toString(); - } - - @Override - public void sendRedirect(String url) - { - out.clear(); - out.append("<ajax-response><redirect><![CDATA[" + url + "]]></redirect></ajax-response>"); - redirect = true; - } - - @Override - public void write(byte[] array) - { - throw new UnsupportedOperationException(); - } - - @Override - public void write(byte[] array, int offset, int length) - { - throw new UnsupportedOperationException(); - } - - @Override - public String encodeURL(CharSequence url) - { - // TODO temp fix for https://github.com/Atmosphere/atmosphere/issues/949 - return url.toString(); - } - - @Override - public Object getContainerResponse() - { - return response; - } - - @Override - public boolean isRedirect() - { - return false; - } - - @Override - public void reset() - { - out.clear(); - } - - @Override - public void flush() - { - } - - @Override - public void write(CharSequence sequence) - { - if (!redirect) - out.append(sequence); - } - - /** - * @return The internal buffer directly as a {@link CharSequence} - */ - public CharSequence getBuffer() - { - return out; - } - - @Override - public String toString() - { - return out.toString(); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java deleted file mode 100644 index 6ddb2e4..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventBus.java +++ /dev/null @@ -1,567 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.CopyOnWriteArrayList; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletRequestWrapper; - -import org.apache.wicket.Application; -import org.apache.wicket.Component; -import org.apache.wicket.MetaDataKey; -import org.apache.wicket.Page; -import org.apache.wicket.Session; -import org.apache.wicket.ThreadContext; -import org.apache.wicket.WicketRuntimeException; -import org.apache.wicket.application.IComponentOnBeforeRenderListener; -import org.apache.wicket.atmosphere.config.AtmosphereParameters; -import org.apache.wicket.protocol.http.WebApplication; -import org.apache.wicket.protocol.http.WicketFilter; -import org.apache.wicket.protocol.http.servlet.ServletWebRequest; -import org.apache.wicket.request.Response; -import org.apache.wicket.session.ISessionStore.UnboundListener; -import org.atmosphere.cpr.AtmosphereConfig; -import org.atmosphere.cpr.AtmosphereFramework; -import org.atmosphere.cpr.AtmosphereResource; -import org.atmosphere.cpr.AtmosphereResourceFactory; -import org.atmosphere.cpr.Broadcaster; -import org.atmosphere.cpr.BroadcasterFactory; -import org.atmosphere.util.Version; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; - -/** - * Broadcasts events to methods on components annotated with {@link Subscribe}. - * {@linkplain EventBus#post(Object) Posted} events are broadcasted to all components on active - * pages if they have a method annotated with {@link Subscribe}. To create and register an - * {@code EventBus}, put the following code in your application's init method: - * - * <pre> - * this.eventBus = new EventBus(this); - * </pre> - * - * The {@code EventBus} will register itself in the application once instantiated. It might be - * practical to keep a reference in the application, but you can always get it using {@link #get()}. - * - * @author papegaaij - */ -public class EventBus implements UnboundListener -{ - private static final Logger log = LoggerFactory.getLogger(EventBus.class); - - private static final MetaDataKey<EventBus> EVENT_BUS_KEY = new MetaDataKey<EventBus>() - { - private static final long serialVersionUID = 1L; - }; - - /** - * @return the {@code EventBus} registered for the current Wicket application. - */ - public static EventBus get() - { - return get(Application.get()); - } - - /** - * @param application - * @return the {@code EventBus} registered for the given Wicket application. - */ - public static EventBus get(Application application) - { - EventBus eventBus = application.getMetaData(EVENT_BUS_KEY); - if (eventBus == null) - { - throw new WicketRuntimeException( - "There is no EventBus registered for the given application: " + - application.getName()); - } - return eventBus; - } - - /** - * @param application - * @return {@code true} if there is an installed EventBus to the given application - */ - public static boolean isInstalled(Application application) - { - return application.getMetaData(EVENT_BUS_KEY) != null; - } - - private final WebApplication application; - - private final Multimap<PageKey, EventSubscription> subscriptions = HashMultimap.create(); - - private final Map<String, PageKey> trackedPages = Maps.newHashMap(); - - private final List<ResourceRegistrationListener> registrationListeners = new CopyOnWriteArrayList<>(); - - private final AtmosphereParameters parameters = new AtmosphereParameters(); - - private Broadcaster broadcaster; - - /** - * A flag indicating whether to be notified about Atmosphere internal events - * - * <strong>Caution:</strong>: enabling this may cause a lot of <em>onBroadcast</em> notifications - * - * @see org.apache.wicket.atmosphere.AtmosphereInternalEvent - * @see org.atmosphere.cpr.AtmosphereResourceEventListener - */ - private boolean wantAtmosphereNotifications = false; - - /** - * Creates and registers an {@code EventBus} for the given application. The first broadcaster - * returned by the {@code BroadcasterFactory} is used. - * - * @param application - */ - public EventBus(WebApplication application) - { - this(application, null); - } - - private static Broadcaster lookupDefaultBroadcaster() - { - BroadcasterFactory factory = BroadcasterFactory.getDefault(); - if (factory == null) - { - throw new WicketRuntimeException( - "There is no Atmosphere BroadcasterFactory configured. Did you include the " - + "atmosphere.xml configuration file and configured AtmosphereServlet?"); - } - Collection<Broadcaster> allBroadcasters = factory.lookupAll(); - if (allBroadcasters.isEmpty()) - { - throw new WicketRuntimeException( - "The Atmosphere BroadcasterFactory has no Broadcasters, " - + "something is wrong with your Atmosphere configuration."); - } - return allBroadcasters.iterator().next(); - } - - /** - * Creates and registers an {@code EventBus} for the given application and broadcaster - * - * @param application - * @param broadcaster - */ - public EventBus(WebApplication application, Broadcaster broadcaster) - { - this.application = application; - this.broadcaster = broadcaster; - application.setMetaData(EVENT_BUS_KEY, this); - application.mount(new AtmosphereRequestMapper(createEventSubscriptionInvoker())); - application.getComponentPostOnBeforeRenderListeners().add( - createEventSubscriptionCollector()); - application.getSessionStore().registerUnboundListener(this); - checkEnabledAnalytics(getBroadcaster().getBroadcasterConfig().getAtmosphereConfig()); - } - - private void checkEnabledAnalytics(AtmosphereConfig config) - { - int major = Version.getMajorVersion(); - int minor = Version.getMinorVersion(); - boolean analyticsAlwaysEnabled = major == 2 && minor < 3; - boolean analyticsOption = - config.getInitParameter(AtmosphereFramework.class.getName() + ".analytics", true); - if (analyticsAlwaysEnabled || analyticsOption) - { - log.warn("Atmosphere's Google Analytics callback is enabled. Atmosphere will contact " - + "Google Analytics on startup of your application. To disable this, upgrade " - + "to Atmosphere 2.3 and disable ApplicationConfig.ANALYTICS in your web.xml"); - } - } - - /** - * - * @return event subscription invoker - */ - protected EventSubscriptionInvoker createEventSubscriptionInvoker() - { - return new SubscribeAnnotationEventSubscriptionInvoker(); - } - - /** - * - * @return event subscription collector - */ - protected IComponentOnBeforeRenderListener createEventSubscriptionCollector() - { - return new AtmosphereEventSubscriptionCollector(this); - } - - /** - * @return The {@link Broadcaster} used by the {@code EventBus} to broadcast messages to. - */ - public Broadcaster getBroadcaster() - { - return broadcaster != null ? broadcaster : lookupDefaultBroadcaster(); - } - - public EventBus setBroadcaster(Broadcaster broadcaster) - { - this.broadcaster = broadcaster; - return this; - } - - /** - * Returns the {@linkplain AtmosphereParameters parameters} that will be passed to the - * Atmosphere JQuery plugin. You can change these parameters, for example to disable WebSockets. - * - * @return The parameters. - */ - public AtmosphereParameters getParameters() - { - return parameters; - } - - /** - * Registers a page for the given tracking-id in the {@code EventBus}. - * - * @param trackingId - * @param page - */ - public synchronized void registerPage(String trackingId, Page page) - { - PageKey oldPage = trackedPages.remove(trackingId); - PageKey pageKey = new PageKey(page.getPageId(), Session.get().getId()); - if (oldPage != null && !oldPage.equals(pageKey)) - { - subscriptions.removeAll(oldPage); - fireUnregistration(trackingId); - } - trackedPages.put(trackingId, pageKey); - fireRegistration(trackingId, page); - - if (log.isDebugEnabled()) - { - log.debug("registered page {} for session {}", pageKey.getPageId(), - pageKey.getSessionId()); - } - } - - /** - * Registers an {@link EventSubscription} for the given page. - * - * @param page - * @param subscription - */ - public synchronized void register(Page page, EventSubscription subscription) - { - if (log.isDebugEnabled()) - { - log.debug( - "registering {} for page {} for session {}: {}{}", - new Object[] { - subscription.getBehaviorIndex() == null ? "component" : "behavior", - page.getPageId(), - Session.get().getId(), - subscription.getComponentPath(), - subscription.getBehaviorIndex() == null ? "" : ":" + - subscription.getBehaviorIndex() }); - } - PageKey pageKey = new PageKey(page.getPageId(), Session.get().getId()); - if (!subscriptions.containsEntry(pageKey, subscription)) - { - subscriptions.put(pageKey, subscription); - } - } - - /** - * Unregisters an {@link EventSubscription} for the given page. - * - * @param page - * @param subscription - */ - public synchronized void unregister(Page page, EventSubscription subscription) - { - if (log.isDebugEnabled()) - { - log.debug( - "unregistering {} for page {} for session {}: {}{}", - new Object[] { - subscription.getBehaviorIndex() == null ? "component" : "behavior", - page.getPageId(), - Session.get().getId(), - subscription.getComponentPath(), - subscription.getBehaviorIndex() == null ? "" : ":" + - subscription.getBehaviorIndex() }); - } - PageKey pageKey = new PageKey(page.getPageId(), Session.get().getId()); - subscriptions.remove(pageKey, subscription); - } - - /** - * Unregisters all {@link EventSubscription}s for the given pageKey. - * - * @param pageKey - * The key with the page id and session id - */ - public synchronized void unregister(PageKey pageKey) - { - if (log.isDebugEnabled()) - { - log.debug("unregistering all subscriptions for page {} for session {}", - pageKey.getPageId(), pageKey.getSessionId()); - } - subscriptions.removeAll(pageKey); - } - - /** - * Unregisters all {@link EventSubscription}s for the given component, including the - * subscriptions for its behaviors. - * - * @param component - */ - public synchronized void unregister(Component component) - { - String componentPath = component.getPageRelativePath(); - PageKey pageKey = new PageKey(component.getPage().getPageId(), Session.get().getId()); - Collection<EventSubscription> subscriptionsForPage = subscriptions.get(pageKey); - Iterator<EventSubscription> it = subscriptionsForPage.iterator(); - while (it.hasNext()) - { - if (it.next().getComponentPath().equals(componentPath)) - it.remove(); - } - } - - /** - * Unregisters all subscriptions for the given tracking id. - * - * @param trackingId - */ - public synchronized void unregisterConnection(String trackingId) - { - PageKey pageKey = trackedPages.remove(trackingId); - if (pageKey != null) - { - fireUnregistration(trackingId); - if (log.isDebugEnabled()) - { - log.debug("unregistering page {} for session {}", pageKey.getPageId(), - pageKey.getSessionId()); - } - } - } - - /** - * Post an event to a single resource. This will invoke the event handlers on all components on - * the page with the suspended connection. The resulting AJAX update (if any) is pushed to the - * client. You can find the UUID via {@link AtmosphereBehavior#getUUID(Page)}. If no resource - * exists with the given UUID, no post is performed. - * - * @param event - * @param resourceUuid - */ - public void post(Object event, String resourceUuid) - { - AtmosphereResource resource = AtmosphereResourceFactory.getDefault().find(resourceUuid); - if (resource != null) - { - post(event, resource); - } - } - - /** - * Post an event to a single resource. This will invoke the event handlers on all components on - * the page with the suspended connection. The resulting AJAX update (if any) is pushed to the - * client. - * - * @param event - * @param resource - */ - public void post(Object event, AtmosphereResource resource) - { - ThreadContext oldContext = ThreadContext.get(false); - try - { - postToSingleResource(event, resource); - } - finally - { - ThreadContext.restore(oldContext); - } - } - - /** - * Post an event to all pages that have a suspended connection. This will invoke the event - * handlers on components, annotated with {@link Subscribe}. The resulting AJAX updates are - * pushed to the clients. - * - * @param event - */ - public void post(Object event) - { - ThreadContext oldContext = ThreadContext.get(false); - try - { - for (AtmosphereResource resource : ImmutableList.copyOf(getBroadcaster().getAtmosphereResources())) - { - postToSingleResource(event, resource); - } - } - finally - { - ThreadContext.restore(oldContext); - } - } - - private void postToSingleResource(Object payload, AtmosphereResource resource) - { - AtmosphereEvent event = new AtmosphereEvent(payload, resource); - ThreadContext.detach(); - ThreadContext.setApplication(application); - PageKey key; - Iterable<EventSubscription> subscriptionsForPage; - synchronized (this) - { - key = trackedPages.get(resource.uuid()); - Collection<EventSubscription> eventSubscriptions = subscriptions.get(key); - subscriptionsForPage = Iterables.filter(ImmutableList.copyOf(eventSubscriptions), - new EventFilter(event)); - } - if (key == null) - getBroadcaster().removeAtmosphereResource(resource); - else - { - Iterator<EventSubscription> iterator = subscriptionsForPage.iterator(); - if (iterator.hasNext()) - post(resource, key, iterator, event); - } - } - - private void post(AtmosphereResource resource, PageKey pageKey, - Iterator<EventSubscription> subscriptionsForPage, AtmosphereEvent event) - { - String filterPath = WebApplication.get() - .getWicketFilter() - .getFilterConfig() - .getInitParameter(WicketFilter.FILTER_MAPPING_PARAM); - filterPath = filterPath.substring(1, filterPath.length() - 1); - HttpServletRequest httpRequest = new HttpServletRequestWrapper(resource.getRequest()) - { - @Override - public String getContextPath() - { - String ret = super.getContextPath(); - return ret == null ? "" : ret; - } - }; - AtmosphereWebRequest request = new AtmosphereWebRequest( - (ServletWebRequest)application.newWebRequest(httpRequest, filterPath), pageKey, - subscriptionsForPage, event); - Response response = new AtmosphereWebResponse(resource.getResponse()); - if (application.createRequestCycle(request, response).processRequestAndDetach()) - getBroadcaster().broadcast(response.toString(), resource); - } - - @Override - public synchronized void sessionUnbound(String sessionId) - { - log.debug("Session unbound {}", sessionId); - Iterator<Entry<String, PageKey>> pageIt = trackedPages.entrySet().iterator(); - while (pageIt.hasNext()) - { - Entry<String, PageKey> curEntry = pageIt.next(); - if (curEntry.getValue().isForSession(sessionId)) - { - pageIt.remove(); - fireUnregistration(curEntry.getKey()); - } - } - Iterator<PageKey> subscriptionIt = subscriptions.keySet().iterator(); - while (subscriptionIt.hasNext()) - if (subscriptionIt.next().isForSession(sessionId)) - subscriptionIt.remove(); - } - - /** - * Add a new {@link ResourceRegistrationListener} to the {@code EventBus}. This listener will be - * notified on all Atmosphere resource registrations and unregistrations. - * - * @param listener - */ - public void addRegistrationListener(ResourceRegistrationListener listener) - { - registrationListeners.add(listener); - } - - /** - * Removes a previously added {@link ResourceRegistrationListener}. - * - * @param listener - */ - public void removeRegistrationListener(ResourceRegistrationListener listener) - { - registrationListeners.remove(listener); - } - - private void fireRegistration(String uuid, Page page) - { - for (ResourceRegistrationListener curListener : registrationListeners) - { - curListener.resourceRegistered(uuid, page); - } - } - - private void fireUnregistration(String uuid) - { - for (ResourceRegistrationListener curListener : registrationListeners) - { - curListener.resourceUnregistered(uuid); - } - } - - /** - * @see org.apache.wicket.atmosphere.AtmosphereInternalEvent - * @see org.atmosphere.cpr.AtmosphereResourceEventListener - * @return whether to be notified about Atmosphere internal events or not - */ - public boolean isWantAtmosphereNotifications() - { - return wantAtmosphereNotifications; - } - - /** - * A flag indicating whether to be notified about Atmosphere internal events - * - * <strong>Caution:</strong>: enabling this may cause a lot of <em>onBroadcast</em> notifications - * - * @param wantAtmosphereNotifications - * {@code true} to be notified, {@code false} - otherwise - * @see org.apache.wicket.atmosphere.AtmosphereInternalEvent - * @see org.atmosphere.cpr.AtmosphereResourceEventListener - */ - public EventBus setWantAtmosphereNotifications(boolean wantAtmosphereNotifications) - { - this.wantAtmosphereNotifications = wantAtmosphereNotifications; - return this; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventFilter.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventFilter.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventFilter.java deleted file mode 100644 index 7bbb62e..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventFilter.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import com.google.common.base.Predicate; - -/** - * Used by {@link EventBus} to filters subscriptions for a given event. Both event type and - * {@linkplain Subscribe#filter() subscription filter} are taken into account. - * - * @author papegaaij - */ -public class EventFilter implements Predicate<EventSubscription> -{ - private AtmosphereEvent event; - - /** - * Construct. - * - * @param event - */ - public EventFilter(AtmosphereEvent event) - { - this.event = event; - } - - @Override - public boolean apply(EventSubscription input) - { - return input.getFilter().apply(event); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventSubscription.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventSubscription.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventSubscription.java deleted file mode 100644 index f7080bd..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventSubscription.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import java.lang.reflect.Method; - -import org.apache.wicket.Component; -import org.apache.wicket.WicketRuntimeException; -import org.apache.wicket.behavior.Behavior; - -import com.google.common.base.Objects; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; - -/** - * The subscription of a method on a component to certain events. This is used by {@link EventBus} - * to track the subscriptions. - * - * @author papegaaij - */ -public class EventSubscription -{ - private final String componentPath; - - private final Integer behaviorIndex; - - private final String methodName; - - private final Predicate<AtmosphereEvent> filter; - - private final Predicate<AtmosphereEvent> contextAwareFilter; - - /** - * Construct. - * - * @param component - * @param behavior - * @param method - */ - public EventSubscription(Component component, Behavior behavior, Method method) - { - componentPath = component.getPageRelativePath(); - behaviorIndex = behavior == null ? null : component.getBehaviorId(behavior); - Class<?> eventType = method.getParameterTypes()[1]; - Subscribe subscribe = method.getAnnotation(Subscribe.class); - filter = Predicates.and(payloadOfType(eventType), createFilter(subscribe.filter())); - contextAwareFilter = createFilter(subscribe.contextAwareFilter()); - methodName = method.getName(); - } - - /** - * Construct. - * - * @param component - * @param behavior - * @param method - * @param filter - * @param contextAwareFilter - */ - public EventSubscription(Component component, Behavior behavior, Method method, - Predicate<AtmosphereEvent> filter, Predicate<AtmosphereEvent> contextAwareFilter) - { - componentPath = component.getPageRelativePath(); - behaviorIndex = behavior == null ? null : component.getBehaviorId(behavior); - this.filter = filter == null ? new NoFilterPredicate() : filter; - this.contextAwareFilter = contextAwareFilter == null ? new NoFilterPredicate() - : contextAwareFilter; - methodName = method.getName(); - } - - private static Predicate<AtmosphereEvent> payloadOfType(final Class<?> type) - { - return new Predicate<AtmosphereEvent>() - { - @Override - public boolean apply(AtmosphereEvent input) - { - return type.isInstance(input.getPayload()); - } - }; - } - - private static Predicate<AtmosphereEvent> createFilter( - Class<? extends Predicate<AtmosphereEvent>> filterClass) - { - try - { - return filterClass.newInstance(); - } - catch (InstantiationException e) - { - throw new WicketRuntimeException(e); - } - catch (IllegalAccessException e) - { - throw new WicketRuntimeException(e); - } - } - - /** - * @return The path of the subscribed component - */ - public String getComponentPath() - { - return componentPath; - } - - /** - * @return The index of the subscribed behavior, or null if the subscription is for the - * component itself - */ - public Integer getBehaviorIndex() - { - return behaviorIndex; - } - - /** - * @return The filter on incoming events, a combination of the type and the - * {@link Subscribe#filter()} parameter. - */ - public Predicate<AtmosphereEvent> getFilter() - { - return filter; - } - - /** - * @return The context ware filter on incoming events, constructed from the - * {@link Subscribe#contextAwareFilter()} parameter. - */ - public Predicate<AtmosphereEvent> getContextAwareFilter() - { - return contextAwareFilter; - } - - /** - * @return The method that is subscribed - */ - public String getMethodName() - { - return methodName; - } - - @Override - public int hashCode() - { - return Objects.hashCode(componentPath, behaviorIndex, methodName); - } - - @Override - public boolean equals(Object obj) - { - if (obj instanceof EventSubscription) - { - EventSubscription other = (EventSubscription)obj; - return Objects.equal(componentPath, other.getComponentPath()) && - Objects.equal(behaviorIndex, other.getBehaviorIndex()) && - Objects.equal(methodName, other.getMethodName()); - } - return false; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventSubscriptionInvoker.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventSubscriptionInvoker.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventSubscriptionInvoker.java deleted file mode 100644 index ed70b62..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/EventSubscriptionInvoker.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import org.apache.wicket.Component; -import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.behavior.Behavior; - -/** - * Delivers events to a subscribed {@link Component} or {@link Behavior}. Implementations convey - * {@link AtmosphereEvent#getPayload()} into an invocation of the subscription method - * {@link EventSubscription#getMethodName()}. - */ -public interface EventSubscriptionInvoker -{ - /** - * - * @param target - * {@link AjaxRequestTarget} to which {@link EventSubscription} result should be sent - * @param subscription - * {@link EventSubscription} - * @param base - * {@link EventSubscription} object on which {@link EventSubscription} should be - * invoked - * @param event - * {@link AtmosphereEvent} which matches the {@link EventSubscription}'s predicates - * @param ajaxRequestInitializer - * call {@code ajaxRequestInitializer.initialize()} before you are going to invoke - * {@link EventSubscription} - */ - void invoke(AjaxRequestTarget target, EventSubscription subscription, Object base, - AtmosphereEvent event, AjaxRequestInitializer ajaxRequestInitializer); -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/Initializer.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/Initializer.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/Initializer.java deleted file mode 100644 index 9ca643d..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/Initializer.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import de.agilecoders.wicket.webjars.WicketWebjars; -import org.apache.wicket.Application; -import org.apache.wicket.IInitializer; - -/** - * Initializes Wicket Atmosphere application. - * Installs Webjars support. - */ -public class Initializer implements IInitializer -{ - @Override - public void init(Application application) - { - if (WicketWebjars.isInstalled(application) == false) - { - WicketWebjars.install((org.apache.wicket.protocol.http.WebApplication) application); - } - } - - @Override - public void destroy(Application application) - { - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/JQueryWicketAtmosphereResourceReference.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/JQueryWicketAtmosphereResourceReference.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/JQueryWicketAtmosphereResourceReference.java deleted file mode 100644 index d1c35d2..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/JQueryWicketAtmosphereResourceReference.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import java.util.List; - -import org.apache.wicket.markup.head.HeaderItem; -import org.apache.wicket.markup.head.JavaScriptHeaderItem; -import org.apache.wicket.resource.JQueryPluginResourceReference; - -import de.agilecoders.wicket.webjars.request.resource.WebjarsJavaScriptResourceReference; - -/** - * Resource reference for the jquery.atmosphere.js module and the wicket glue. - * - * @author papegaaij - */ -public class JQueryWicketAtmosphereResourceReference extends JQueryPluginResourceReference -{ - private static final long serialVersionUID = 1L; - - private static final JQueryWicketAtmosphereResourceReference INSTANCE = new JQueryWicketAtmosphereResourceReference(); - - /** - * @return the singleton instance of this resource reference. - */ - public static JQueryWicketAtmosphereResourceReference get() - { - return INSTANCE; - } - - private JQueryWicketAtmosphereResourceReference() - { - super(JQueryWicketAtmosphereResourceReference.class, "jquery.wicketatmosphere.js"); - } - - @Override - public List<HeaderItem> getDependencies() - { - List<HeaderItem> dependencies = super.getDependencies(); - WebjarsJavaScriptResourceReference jqueryAtmosphereReference = new WebjarsJavaScriptResourceReference("jquery-atmosphere/current/jquery.atmosphere.js"); - dependencies.add(JavaScriptHeaderItem.forReference(jqueryAtmosphereReference)); - return dependencies; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/NoFilterPredicate.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/NoFilterPredicate.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/NoFilterPredicate.java deleted file mode 100644 index cce9420..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/NoFilterPredicate.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import com.google.common.base.Predicate; - -/** - * A filter that always returns true. - * - * @author papegaaij - */ -public class NoFilterPredicate implements Predicate<AtmosphereEvent> -{ - @Override - public boolean apply(AtmosphereEvent input) - { - return true; - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/0dd70694/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/PageKey.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/PageKey.java b/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/PageKey.java deleted file mode 100644 index c875f8e..0000000 --- a/wicket-experimental/wicket-atmosphere/src/main/java/org/apache/wicket/atmosphere/PageKey.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.wicket.atmosphere; - -import com.google.common.base.Objects; -import org.apache.wicket.util.lang.Args; - -/** - * Identifies a page by its id and the session it belongs to. - * - * @author papegaaij - */ -public class PageKey -{ - private final Integer pageId; - - private final String sessionId; - - /** - * Construct. - * - * @param pageId - * @param sessionId - */ - public PageKey(Integer pageId, String sessionId) - { - this.pageId = Args.notNull(pageId, "pageId"); - this.sessionId = sessionId; - } - - /** - * @return The id of the page - */ - public Integer getPageId() - { - return pageId; - } - - /** - * @return The id of the session - */ - public String getSessionId() - { - return sessionId; - } - - /** - * @param sessionId - * @return true if this {@code PageKey} is for the same session - */ - public boolean isForSession(String sessionId) - { - String sid = getSessionId(); - return sid != null && sid.equals(sessionId); - } - - @Override - public int hashCode() - { - return Objects.hashCode(pageId, sessionId); - } - - @Override - public boolean equals(Object obj) - { - if (obj instanceof PageKey) - { - PageKey other = (PageKey)obj; - return Objects.equal(pageId, other.pageId) && Objects.equal(sessionId, other.sessionId); - } - return false; - } -}
