From 094fabccf991fae1efd507a8a993fce1bc547b89 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Fri, 31 Aug 2012 19:27:09 +0300 Subject: [PATCH] Rename AbstractWebApplicationContext to ApplicationContext (#9402) --- server/src/com/vaadin/Application.java | 2 +- .../server/AbstractCommunicationManager.java | 3 +- ...onContext.java => ApplicationContext.java} | 127 +++++++++++++++--- .../server/DeploymentConfiguration.java | 2 - .../vaadin/server/GAEApplicationServlet.java | 1 - .../server/HttpServletRequestListener.java | 3 +- .../server/PortletApplicationContext2.java | 2 +- .../vaadin/server/PortletRequestListener.java | 3 +- .../src/com/vaadin/server/RequestTimer.java | 3 +- .../vaadin/server/WebApplicationContext.java | 4 +- .../vaadin/service/ApplicationContext.java | 125 ----------------- .../TransactionListenersConcurrency.java | 16 +-- .../RemoveTransactionListener.java | 4 +- .../components/AbstractTestApplication.java | 12 +- .../tests/components/AbstractTestCase.java | 11 +- .../tests/components/AbstractTestUI.java | 11 +- 16 files changed, 138 insertions(+), 191 deletions(-) rename server/src/com/vaadin/server/{AbstractWebApplicationContext.java => ApplicationContext.java} (57%) delete mode 100644 server/src/com/vaadin/service/ApplicationContext.java diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index cd34fb7540..2ea7f01eea 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -50,6 +50,7 @@ import com.vaadin.data.util.converter.DefaultConverterFactory; import com.vaadin.event.EventRouter; import com.vaadin.server.AbstractApplicationServlet; import com.vaadin.server.AbstractErrorMessage; +import com.vaadin.server.ApplicationContext; import com.vaadin.server.BootstrapFragmentResponse; import com.vaadin.server.BootstrapListener; import com.vaadin.server.BootstrapPageResponse; @@ -67,7 +68,6 @@ import com.vaadin.server.WebApplicationContext; import com.vaadin.server.WrappedRequest; import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.server.WrappedResponse; -import com.vaadin.service.ApplicationContext; import com.vaadin.shared.ui.ui.UIConstants; import com.vaadin.tools.ReflectTools; import com.vaadin.ui.AbstractComponent; diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java index 72406e629d..526d18fd34 100644 --- a/server/src/com/vaadin/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java @@ -1323,8 +1323,7 @@ public abstract class AbstractCommunicationManager implements Serializable { * response. */ private void writePerformanceData(final PrintWriter outWriter) { - AbstractWebApplicationContext ctx = (AbstractWebApplicationContext) application - .getContext(); + ApplicationContext ctx = application.getContext(); outWriter.write(String.format(", \"timings\":[%d, %d]", ctx.getTotalSessionTime(), ctx.getLastRequestTime())); } diff --git a/server/src/com/vaadin/server/AbstractWebApplicationContext.java b/server/src/com/vaadin/server/ApplicationContext.java similarity index 57% rename from server/src/com/vaadin/server/AbstractWebApplicationContext.java rename to server/src/com/vaadin/server/ApplicationContext.java index cf983f4c80..b698ea51c8 100644 --- a/server/src/com/vaadin/server/AbstractWebApplicationContext.java +++ b/server/src/com/vaadin/server/ApplicationContext.java @@ -15,6 +15,7 @@ */ package com.vaadin.server; +import java.io.File; import java.io.PrintWriter; import java.io.Serializable; import java.io.StringWriter; @@ -31,17 +32,65 @@ import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingListener; import com.vaadin.Application; -import com.vaadin.service.ApplicationContext; /** + * ApplicationContext provides information about the running + * context of the application. Each context is shared by all applications that + * are open for one user. In a web-environment this corresponds to a + * HttpSession. + *

* Base class for web application contexts (including portlet contexts) that * handles the common tasks. + * + * @author Vaadin Ltd. + * @since 3.1 */ -public abstract class AbstractWebApplicationContext implements - ApplicationContext, HttpSessionBindingListener, Serializable { +public abstract class ApplicationContext implements HttpSessionBindingListener, + Serializable { + + /** + * Interface for listening to transaction events. Implement this interface + * to listen to all transactions between the client and the application. + * + */ + public static interface TransactionListener extends Serializable { + + /** + * Invoked at the beginning of every transaction. + * + * The transaction is linked to the context, not the application so if + * you have multiple applications running in the same context you need + * to check that the request is associated with the application you are + * interested in. This can be done looking at the application parameter. + * + * @param application + * the Application object. + * @param transactionData + * the Data identifying the transaction. + */ + public void transactionStart(Application application, + Object transactionData); + + /** + * Invoked at the end of every transaction. + * + * The transaction is linked to the context, not the application so if + * you have multiple applications running in the same context you need + * to check that the request is associated with the application you are + * interested in. This can be done looking at the application parameter. + * + * @param applcation + * the Application object. + * @param transactionData + * the Data identifying the transaction. + */ + public void transactionEnd(Application application, + Object transactionData); + + } - protected Collection listeners = Collections - .synchronizedList(new LinkedList()); + protected Collection listeners = Collections + .synchronizedList(new LinkedList()); protected final HashSet applications = new HashSet(); @@ -53,15 +102,31 @@ public abstract class AbstractWebApplicationContext implements private long lastRequestTime = -1; - @Override - public void addTransactionListener(TransactionListener listener) { + /** + * Adds a transaction listener to this context. The transaction listener is + * called before and after each each request related to this session except + * when serving static resources. + * + * The transaction listener must not be null. + * + * @see com.vaadin.service.ApplicationContext#addTransactionListener(com.vaadin.service.ApplicationContext.TransactionListener) + */ + public void addTransactionListener( + ApplicationContext.TransactionListener listener) { if (listener != null) { listeners.add(listener); } } - @Override - public void removeTransactionListener(TransactionListener listener) { + /** + * Removes a transaction listener from this context. + * + * @param listener + * the listener to be removed. + * @see ApplicationContext.TransactionListener + */ + public void removeTransactionListener( + ApplicationContext.TransactionListener listener) { listeners.remove(listener); } @@ -74,11 +139,12 @@ public abstract class AbstractWebApplicationContext implements * the HTTP or portlet request that triggered the transaction. */ protected void startTransaction(Application application, Object request) { - ArrayList currentListeners; + ArrayList currentListeners; synchronized (listeners) { - currentListeners = new ArrayList(listeners); + currentListeners = new ArrayList( + listeners); } - for (TransactionListener listener : currentListeners) { + for (ApplicationContext.TransactionListener listener : currentListeners) { listener.transactionStart(application, request); } } @@ -94,12 +160,13 @@ public abstract class AbstractWebApplicationContext implements protected void endTransaction(Application application, Object request) { LinkedList exceptions = null; - ArrayList currentListeners; + ArrayList currentListeners; synchronized (listeners) { - currentListeners = new ArrayList(listeners); + currentListeners = new ArrayList( + listeners); } - for (TransactionListener listener : currentListeners) { + for (ApplicationContext.TransactionListener listener : currentListeners) { try { listener.transactionEnd(application, request); } catch (final RuntimeException t) { @@ -172,7 +239,13 @@ public abstract class AbstractWebApplicationContext implements return browser; } - @Override + /** + * Returns a collection of all the applications in this context. + * + * Each application context contains all active applications for one user. + * + * @return A collection containing all the applications in this context. + */ public Collection getApplications() { return Collections.unmodifiableCollection(applications); } @@ -209,7 +282,27 @@ public abstract class AbstractWebApplicationContext implements } private Logger getLogger() { - return Logger.getLogger(AbstractWebApplicationContext.class.getName()); + return Logger.getLogger(ApplicationContext.class.getName()); } + /** + * Returns application context base directory. + * + * Typically an application is deployed in a such way that is has an + * application directory. For web applications this directory is the root + * directory of the web applications. In some cases applications might not + * have an application directory (for example web applications running + * inside a war). + * + * @return The application base directory or null if the application has no + * base directory. + */ + public abstract File getBaseDirectory(); + + /** + * Returns the time between requests, in seconds, before this context is + * invalidated. A negative time indicates the context should never timeout. + */ + public abstract int getMaxInactiveInterval(); + } \ No newline at end of file diff --git a/server/src/com/vaadin/server/DeploymentConfiguration.java b/server/src/com/vaadin/server/DeploymentConfiguration.java index d1cbdfc499..d61d03f4d9 100644 --- a/server/src/com/vaadin/server/DeploymentConfiguration.java +++ b/server/src/com/vaadin/server/DeploymentConfiguration.java @@ -23,8 +23,6 @@ import java.util.Properties; import javax.portlet.PortletContext; import javax.servlet.ServletContext; -import com.vaadin.service.ApplicationContext; - /** * Provide deployment specific settings that are required outside terminal * specific code. diff --git a/server/src/com/vaadin/server/GAEApplicationServlet.java b/server/src/com/vaadin/server/GAEApplicationServlet.java index 16345edead..7e0b52c382 100644 --- a/server/src/com/vaadin/server/GAEApplicationServlet.java +++ b/server/src/com/vaadin/server/GAEApplicationServlet.java @@ -47,7 +47,6 @@ import com.google.appengine.api.memcache.Expiration; import com.google.appengine.api.memcache.MemcacheService; import com.google.appengine.api.memcache.MemcacheServiceFactory; import com.google.apphosting.api.DeadlineExceededException; -import com.vaadin.service.ApplicationContext; /** * ApplicationServlet to be used when deploying to Google App Engine, in diff --git a/server/src/com/vaadin/server/HttpServletRequestListener.java b/server/src/com/vaadin/server/HttpServletRequestListener.java index 1f9f633c17..e871dca05d 100644 --- a/server/src/com/vaadin/server/HttpServletRequestListener.java +++ b/server/src/com/vaadin/server/HttpServletRequestListener.java @@ -23,7 +23,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; -import com.vaadin.service.ApplicationContext.TransactionListener; /** * {@link Application} that implements this interface gets notified of request @@ -37,7 +36,7 @@ import com.vaadin.service.ApplicationContext.TransactionListener; * *

* Alternatives for implementing similar features are are Servlet {@link Filter} - * s and {@link TransactionListener}s in Vaadin. + * s and {@link ApplicationContext.TransactionListener}s in Vaadin. * * @since 6.2 * @see PortletRequestListener diff --git a/server/src/com/vaadin/server/PortletApplicationContext2.java b/server/src/com/vaadin/server/PortletApplicationContext2.java index aca80f9c17..366c5b160d 100644 --- a/server/src/com/vaadin/server/PortletApplicationContext2.java +++ b/server/src/com/vaadin/server/PortletApplicationContext2.java @@ -56,7 +56,7 @@ import com.vaadin.ui.UI; * @author peholmst */ @SuppressWarnings("serial") -public class PortletApplicationContext2 extends AbstractWebApplicationContext { +public class PortletApplicationContext2 extends ApplicationContext { protected Map> portletListeners = new HashMap>(); diff --git a/server/src/com/vaadin/server/PortletRequestListener.java b/server/src/com/vaadin/server/PortletRequestListener.java index 35f2a946c5..4562ddf7b9 100644 --- a/server/src/com/vaadin/server/PortletRequestListener.java +++ b/server/src/com/vaadin/server/PortletRequestListener.java @@ -22,7 +22,6 @@ import javax.portlet.PortletResponse; import javax.servlet.Filter; import com.vaadin.Application; -import com.vaadin.service.ApplicationContext.TransactionListener; /** * An {@link Application} that implements this interface gets notified of @@ -41,7 +40,7 @@ import com.vaadin.service.ApplicationContext.TransactionListener; * *

* Alternatives for implementing similar features are are Servlet {@link Filter} - * s and {@link TransactionListener}s in Vaadin. + * s and {@link ApplicationContext.TransactionListener}s in Vaadin. * * @since 6.2 * @see HttpServletRequestListener diff --git a/server/src/com/vaadin/server/RequestTimer.java b/server/src/com/vaadin/server/RequestTimer.java index 1dfe24f23b..470677e331 100644 --- a/server/src/com/vaadin/server/RequestTimer.java +++ b/server/src/com/vaadin/server/RequestTimer.java @@ -18,6 +18,7 @@ package com.vaadin.server; import java.io.Serializable; + /** * Times the handling of requests and stores the information as an attribute in * the request. The timing info is later passed on to the client in the UIDL and @@ -43,7 +44,7 @@ public class RequestTimer implements Serializable { * * @param context */ - public void stop(AbstractWebApplicationContext context) { + public void stop(ApplicationContext context) { // Measure and store the total handling time. This data can be // used in TestBench 3 tests. long time = (System.nanoTime() - requestStartTime) / 1000000; diff --git a/server/src/com/vaadin/server/WebApplicationContext.java b/server/src/com/vaadin/server/WebApplicationContext.java index 7059a04682..02e902f79e 100644 --- a/server/src/com/vaadin/server/WebApplicationContext.java +++ b/server/src/com/vaadin/server/WebApplicationContext.java @@ -37,7 +37,7 @@ import com.vaadin.Application; * @since 3.1 */ @SuppressWarnings("serial") -public class WebApplicationContext extends AbstractWebApplicationContext { +public class WebApplicationContext extends ApplicationContext { protected transient HttpSession session; private transient boolean reinitializingSession = false; @@ -119,7 +119,7 @@ public class WebApplicationContext extends AbstractWebApplicationContext { /** * Gets the application context base directory. * - * @see com.vaadin.service.ApplicationContext#getBaseDirectory() + * @see com.vaadin.server.ApplicationContext#getBaseDirectory() */ @Override public File getBaseDirectory() { diff --git a/server/src/com/vaadin/service/ApplicationContext.java b/server/src/com/vaadin/service/ApplicationContext.java deleted file mode 100644 index 591704764f..0000000000 --- a/server/src/com/vaadin/service/ApplicationContext.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed 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 com.vaadin.service; - -import java.io.File; -import java.io.Serializable; -import java.util.Collection; - -import com.vaadin.Application; - -/** - * ApplicationContext provides information about the running - * context of the application. Each context is shared by all applications that - * are open for one user. In a web-environment this corresponds to a - * HttpSession. - * - * @author Vaadin Ltd. - * @since 3.1 - */ -public interface ApplicationContext extends Serializable { - - /** - * Returns application context base directory. - * - * Typically an application is deployed in a such way that is has an - * application directory. For web applications this directory is the root - * directory of the web applications. In some cases applications might not - * have an application directory (for example web applications running - * inside a war). - * - * @return The application base directory or null if the application has no - * base directory. - */ - public File getBaseDirectory(); - - /** - * Returns a collection of all the applications in this context. - * - * Each application context contains all active applications for one user. - * - * @return A collection containing all the applications in this context. - */ - public Collection getApplications(); - - /** - * Adds a transaction listener to this context. The transaction listener is - * called before and after each each request related to this session except - * when serving static resources. - * - * The transaction listener must not be null. - * - * @see com.vaadin.service.ApplicationContext#addTransactionListener(com.vaadin.service.ApplicationContext.TransactionListener) - */ - public void addTransactionListener(TransactionListener listener); - - /** - * Removes a transaction listener from this context. - * - * @param listener - * the listener to be removed. - * @see TransactionListener - */ - public void removeTransactionListener(TransactionListener listener); - - /** - * Returns the time between requests, in seconds, before this context is - * invalidated. A negative time indicates the context should never timeout. - */ - public int getMaxInactiveInterval(); - - /** - * Interface for listening to transaction events. Implement this interface - * to listen to all transactions between the client and the application. - * - */ - public interface TransactionListener extends Serializable { - - /** - * Invoked at the beginning of every transaction. - * - * The transaction is linked to the context, not the application so if - * you have multiple applications running in the same context you need - * to check that the request is associated with the application you are - * interested in. This can be done looking at the application parameter. - * - * @param application - * the Application object. - * @param transactionData - * the Data identifying the transaction. - */ - public void transactionStart(Application application, - Object transactionData); - - /** - * Invoked at the end of every transaction. - * - * The transaction is linked to the context, not the application so if - * you have multiple applications running in the same context you need - * to check that the request is associated with the application you are - * interested in. This can be done looking at the application parameter. - * - * @param applcation - * the Application object. - * @param transactionData - * the Data identifying the transaction. - */ - public void transactionEnd(Application application, - Object transactionData); - - } -} diff --git a/server/tests/src/com/vaadin/tests/server/TransactionListenersConcurrency.java b/server/tests/src/com/vaadin/tests/server/TransactionListenersConcurrency.java index 0cacccd08a..302b534d8a 100644 --- a/server/tests/src/com/vaadin/tests/server/TransactionListenersConcurrency.java +++ b/server/tests/src/com/vaadin/tests/server/TransactionListenersConcurrency.java @@ -17,14 +17,13 @@ import javax.servlet.http.HttpSession; import junit.framework.TestCase; +import org.easymock.EasyMock; + import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; -import com.vaadin.server.AbstractWebApplicationContext; +import com.vaadin.server.ApplicationContext; import com.vaadin.server.DeploymentConfiguration; import com.vaadin.server.WebApplicationContext; -import com.vaadin.service.ApplicationContext.TransactionListener; - -import org.easymock.EasyMock; public class TransactionListenersConcurrency extends TestCase { @@ -90,9 +89,9 @@ public class TransactionListenersConcurrency extends TestCase { // Call the transaction listener using reflection as // startTransaction is protected. - Method m = AbstractWebApplicationContext.class - .getDeclaredMethod("startTransaction", - Application.class, Object.class); + Method m = ApplicationContext.class.getDeclaredMethod( + "startTransaction", Application.class, + Object.class); m.setAccessible(true); m.invoke(context, app, null); } catch (Exception e) { @@ -167,7 +166,8 @@ public class TransactionListenersConcurrency extends TestCase { * transactionStart and transactionEnd. * */ - public static class DelayTransactionListener implements TransactionListener { + public static class DelayTransactionListener implements + ApplicationContext.TransactionListener { private int delay; diff --git a/uitest/src/com/vaadin/tests/applicationcontext/RemoveTransactionListener.java b/uitest/src/com/vaadin/tests/applicationcontext/RemoveTransactionListener.java index f1730ed5f5..5927e9c19f 100644 --- a/uitest/src/com/vaadin/tests/applicationcontext/RemoveTransactionListener.java +++ b/uitest/src/com/vaadin/tests/applicationcontext/RemoveTransactionListener.java @@ -1,8 +1,8 @@ package com.vaadin.tests.applicationcontext; import com.vaadin.Application; -import com.vaadin.service.ApplicationContext; -import com.vaadin.service.ApplicationContext.TransactionListener; +import com.vaadin.server.ApplicationContext; +import com.vaadin.server.ApplicationContext.TransactionListener; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.Log; diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestApplication.java b/uitest/src/com/vaadin/tests/components/AbstractTestApplication.java index 406158e8e1..db17c67fdd 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractTestApplication.java +++ b/uitest/src/com/vaadin/tests/components/AbstractTestApplication.java @@ -1,9 +1,8 @@ package com.vaadin.tests.components; import com.vaadin.Application; -import com.vaadin.server.AbstractWebApplicationContext; +import com.vaadin.server.ApplicationContext; import com.vaadin.server.WebBrowser; -import com.vaadin.service.ApplicationContext; public abstract class AbstractTestApplication extends Application { protected abstract String getTestDescription(); @@ -12,12 +11,7 @@ public abstract class AbstractTestApplication extends Application { protected WebBrowser getBrowser() { ApplicationContext context = getContext(); - if (context instanceof AbstractWebApplicationContext) { - WebBrowser webBrowser = ((AbstractWebApplicationContext) context) - .getBrowser(); - return webBrowser; - } - - return null; + WebBrowser webBrowser = context.getBrowser(); + return webBrowser; } } diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestCase.java b/uitest/src/com/vaadin/tests/components/AbstractTestCase.java index 4e2ec1d935..f51c74d4a8 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractTestCase.java +++ b/uitest/src/com/vaadin/tests/components/AbstractTestCase.java @@ -1,9 +1,8 @@ package com.vaadin.tests.components; import com.vaadin.Application; -import com.vaadin.server.AbstractWebApplicationContext; +import com.vaadin.server.ApplicationContext; import com.vaadin.server.WebBrowser; -import com.vaadin.service.ApplicationContext; public abstract class AbstractTestCase extends Application.LegacyApplication { @@ -13,12 +12,8 @@ public abstract class AbstractTestCase extends Application.LegacyApplication { protected WebBrowser getBrowser() { ApplicationContext context = getContext(); - if (context instanceof AbstractWebApplicationContext) { - WebBrowser webBrowser = ((AbstractWebApplicationContext) context) - .getBrowser(); - return webBrowser; - } + WebBrowser webBrowser = context.getBrowser(); + return webBrowser; - return null; } } diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java index ff235c5d9f..21eda56891 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java @@ -1,10 +1,9 @@ package com.vaadin.tests.components; import com.vaadin.Application; -import com.vaadin.server.AbstractWebApplicationContext; +import com.vaadin.server.ApplicationContext; import com.vaadin.server.WebBrowser; import com.vaadin.server.WrappedRequest; -import com.vaadin.service.ApplicationContext; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.ui.Component; import com.vaadin.ui.Label; @@ -58,12 +57,8 @@ public abstract class AbstractTestUI extends UI { protected WebBrowser getBrowser() { ApplicationContext context = Application.getCurrent().getContext(); - if (context instanceof AbstractWebApplicationContext) { - AbstractWebApplicationContext webContext = (AbstractWebApplicationContext) context; - return webContext.getBrowser(); - } - - return null; + ApplicationContext webContext = context; + return webContext.getBrowser(); } } -- 2.39.5