From fd27ce8fa25a07062e6643f7edb59bacb96d1f68 Mon Sep 17 00:00:00 2001 From: Fabian Lange Date: Sat, 12 Jul 2014 21:44:09 +0200 Subject: [PATCH] Optimizes initial sizes of frequently used Collections. (#14223) There are a few places in frequently used core classes which could initialize collection classes with the correct (or slightly oversized) length. Maps are initialized with 2x the size due to its load factor. Change-Id: I3aee5a60602937a8550ca5a200ec2a529ff36fe9 --- server/src/com/vaadin/server/JsonCodec.java | 23 +- .../src/com/vaadin/server/VaadinService.java | 239 +++++++++--------- .../communication/LegacyUidlWriter.java | 13 +- .../communication/ServerRpcHandler.java | 34 +-- .../src/com/vaadin/ui/ConnectorTracker.java | 91 +++---- 5 files changed, 205 insertions(+), 195 deletions(-) diff --git a/server/src/com/vaadin/server/JsonCodec.java b/server/src/com/vaadin/server/JsonCodec.java index 93074abcdb..34b05f73bf 100644 --- a/server/src/com/vaadin/server/JsonCodec.java +++ b/server/src/com/vaadin/server/JsonCodec.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 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 @@ -56,7 +56,7 @@ import com.vaadin.ui.ConnectorTracker; /** * Decoder for converting RPC parameters and other values from JSON in transfer * between the client and the server and vice versa. - * + * * @since 7.0 */ public class JsonCodec implements Serializable { @@ -119,9 +119,9 @@ public class JsonCodec implements Serializable { public static Collection find(Class type) throws IntrospectionException { - Collection properties = new ArrayList(); - Field[] fields = type.getFields(); + Collection properties = new ArrayList( + fields.length); for (Field field : fields) { if (!Modifier.isStatic(field.getModifiers())) { properties.add(new FieldProperty(field)); @@ -341,7 +341,7 @@ public class JsonCodec implements Serializable { * using the declared type. Otherwise only internal types are allowed in * collections. *

- * + * * @param targetType * The type that should be returned by this method * @param valueAndType @@ -471,13 +471,13 @@ public class JsonCodec implements Serializable { private static Map decodeObjectMap(Type keyType, Type valueType, JSONArray jsonMap, ConnectorTracker connectorTracker) throws JSONException { - Map map = new HashMap(); JSONArray keys = jsonMap.getJSONArray(0); JSONArray values = jsonMap.getJSONArray(1); assert (keys.length() == values.length()); + Map map = new HashMap(keys.length() * 2); for (int i = 0; i < keys.length(); i++) { Object key = decodeInternalOrCustomType(keyType, keys.get(i), connectorTracker); @@ -580,8 +580,9 @@ public class JsonCodec implements Serializable { private static List decodeList(Type targetType, boolean restrictToInternalTypes, JSONArray jsonArray, ConnectorTracker connectorTracker) throws JSONException { - List list = new ArrayList(); - for (int i = 0; i < jsonArray.length(); ++i) { + int arrayLength = jsonArray.length(); + List list = new ArrayList(arrayLength); + for (int i = 0; i < arrayLength; ++i) { // each entry always has two elements: type and value Object encodedValue = jsonArray.get(i); Object decodedChild = decodeParametrizedType(targetType, @@ -754,7 +755,7 @@ public class JsonCodec implements Serializable { /** * Compares the value with the reference. If they match, returns true. - * + * * @param fieldValue * @param referenceValue * @return diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java index e8cdcd7055..442e2fa83c 100644 --- a/server/src/com/vaadin/server/VaadinService.java +++ b/server/src/com/vaadin/server/VaadinService.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 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 @@ -34,6 +34,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; @@ -69,9 +70,9 @@ import com.vaadin.util.ReflectTools; /** * Provide deployment specific settings that are required outside terminal * specific code. - * + * * @author Vaadin Ltd. - * + * * @since 7.0 */ public abstract class VaadinService implements Serializable { @@ -144,7 +145,7 @@ public abstract class VaadinService implements Serializable { /** * Creates a new vaadin service based on a deployment configuration - * + * * @param deploymentConfiguration * the deployment configuration for the service */ @@ -172,7 +173,7 @@ public abstract class VaadinService implements Serializable { /** * Initializes this service. The service should be initialized before it is * used. - * + * * @since 7.1 * @throws ServiceException * if a problem occurs when creating the service @@ -191,7 +192,7 @@ public abstract class VaadinService implements Serializable { * called first. This enables overriding this method and using add on the * returned list to add a custom request handler which overrides any * predefined handler. - * + * * @return The list of request handlers used by this service. * @throws ServiceException * if a problem occurs when creating the request handlers @@ -214,13 +215,13 @@ public abstract class VaadinService implements Serializable { * Return the URL from where static files, e.g. the widgetset and the theme, * are served. In a standard configuration the VAADIN folder inside the * returned folder is what is used for widgetsets and themes. - * + * * The returned folder is usually the same as the context path and * independent of e.g. the servlet mapping. - * + * * @param request * the request for which the location should be determined - * + * * @return The location of static resources (should contain the VAADIN * directory). Never ends with a slash (/). */ @@ -229,7 +230,7 @@ public abstract class VaadinService implements Serializable { /** * Gets the widgetset that is configured for this deployment, e.g. from a * parameter in web.xml. - * + * * @param request * the request for which a widgetset is required * @return the name of the widgetset @@ -239,7 +240,7 @@ public abstract class VaadinService implements Serializable { /** * Gets the theme that is configured for this deployment, e.g. from a portal * parameter or just some sensible default value. - * + * * @param request * the request for which a theme is required * @return the name of the theme @@ -251,7 +252,7 @@ public abstract class VaadinService implements Serializable { * whether it will be included into some other context. A standalone UI may * do things that might interfere with other parts of a page, e.g. changing * the page title and requesting focus upon loading. - * + * * @param request * the request for which the UI is loaded * @return a boolean indicating whether the UI should be standalone @@ -262,9 +263,9 @@ public abstract class VaadinService implements Serializable { * Gets the class loader to use for loading classes loaded by name, e.g. * custom UI classes. This is by default the class loader that was used to * load the Servlet or Portlet class to which this service belongs. - * + * * @return the class loader to use, or null - * + * * @see #setClassLoader(ClassLoader) */ public ClassLoader getClassLoader() { @@ -277,10 +278,10 @@ public abstract class VaadinService implements Serializable { * any existing class loader hierarchy, e.g. by ensuring that a class loader * set for this service delegates to the previously set class loader if the * class is not found. - * + * * @param classLoader * the new class loader to set, not null. - * + * * @see #getClassLoader() */ public void setClassLoader(ClassLoader classLoader) { @@ -296,11 +297,11 @@ public abstract class VaadinService implements Serializable { * not known. The MIME type is determined by the configuration of the * container, and may be specified in a deployment descriptor. Common MIME * types are "text/html" and "image/gif". - * + * * @param resourceName * a String specifying the name of a file * @return a String specifying the file's MIME type - * + * * @see ServletContext#getMimeType(String) * @see PortletContext#getMimeType(String) */ @@ -308,7 +309,7 @@ public abstract class VaadinService implements Serializable { /** * Gets the deployment configuration. - * + * * @return the deployment configuration */ public DeploymentConfiguration getDeploymentConfiguration() { @@ -318,9 +319,9 @@ public abstract class VaadinService implements Serializable { /** * Sets the system messages provider to use for getting system messages to * display to users of this service. - * + * * @see #getSystemMessagesProvider() - * + * * @param systemMessagesProvider * the system messages provider; null is not * allowed. @@ -340,11 +341,11 @@ public abstract class VaadinService implements Serializable { * By default, the {@link DefaultSystemMessagesProvider} which always * provides the built-in default {@link SystemMessages} is used. *

- * + * * @see #setSystemMessagesProvider(SystemMessagesProvider) * @see SystemMessagesProvider * @see SystemMessages - * + * * @return the system messages provider; not null */ public SystemMessagesProvider getSystemMessagesProvider() { @@ -356,7 +357,7 @@ public abstract class VaadinService implements Serializable { * also be implemented to use information from current instances of various * objects, which means that this method might return different values for * the same locale under different circumstances. - * + * * @param locale * the desired locale for the system messages * @param request @@ -373,13 +374,13 @@ public abstract class VaadinService implements Serializable { /** * Returns the 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. */ @@ -393,10 +394,10 @@ public abstract class VaadinService implements Serializable { * the listener is not necessarily notified immediately when the session is * created but only when the first request for that session is handled by * this service. - * + * * @see #removeSessionInitListener(SessionInitListener) * @see SessionInitListener - * + * * @param listener * the Vaadin service session initialization listener */ @@ -408,9 +409,9 @@ public abstract class VaadinService implements Serializable { /** * Removes a Vaadin service session initialization listener from this * service. - * + * * @see #addSessionInitListener(SessionInitListener) - * + * * @param listener * the Vaadin service session initialization listener to remove. */ @@ -425,9 +426,9 @@ public abstract class VaadinService implements Serializable { *

* The session being destroyed is locked and its UIs have been removed when * the listeners are called. - * + * * @see #addSessionInitListener(SessionInitListener) - * + * * @param listener * the vaadin service session destroy listener */ @@ -439,7 +440,7 @@ public abstract class VaadinService implements Serializable { /** * Handles destruction of the given session. Internally ensures proper * locking is done. - * + * * @param vaadinSession * The session to destroy */ @@ -485,9 +486,9 @@ public abstract class VaadinService implements Serializable { /** * Removes a Vaadin service session destroy listener from this service. - * + * * @see #addSessionDestroyListener(SessionDestroyListener) - * + * * @param listener * the vaadin service session destroy listener */ @@ -502,12 +503,12 @@ public abstract class VaadinService implements Serializable { * Handles locking of the session internally to avoid creation of duplicate * sessions by two threads simultaneously. *

- * + * * @param request * the request to get a vaadin service session for. - * + * * @see VaadinSession - * + * * @return the vaadin service session for the request, or null * if no session is found and this is a request for which a new * session shouldn't be created. @@ -529,7 +530,7 @@ public abstract class VaadinService implements Serializable { * Associates the given lock with this service and the given wrapped * session. This method should not be called more than once when the lock is * initialized for the session. - * + * * @see #getSessionLock(WrappedSession) * @param wrappedSession * The wrapped session the lock is associated with @@ -550,7 +551,7 @@ public abstract class VaadinService implements Serializable { /** * Returns the name used to store the lock in the HTTP session. - * + * * @return The attribute name for the lock */ private String getLockAttributeName() { @@ -564,7 +565,7 @@ public abstract class VaadinService implements Serializable { * This method uses the wrapped session instead of VaadinSession to be able * to lock even before the VaadinSession has been initialized. *

- * + * * @param wrappedSession * The wrapped session * @return A lock instance used for locking access to the wrapped session @@ -588,10 +589,10 @@ public abstract class VaadinService implements Serializable { /** * Locks the given session for this service instance. Typically you want to * call {@link VaadinSession#lock()} instead of this method. - * + * * @param wrappedSession * The session to lock - * + * * @throws IllegalStateException * if the session is invalidated before it can be locked */ @@ -631,7 +632,7 @@ public abstract class VaadinService implements Serializable { * Releases the lock for the given session for this service instance. * Typically you want to call {@link VaadinSession#unlock()} instead of this * method. - * + * * @param wrappedSession * The session to unlock */ @@ -666,7 +667,7 @@ public abstract class VaadinService implements Serializable { * Finds or creates a Vaadin session. Assumes necessary synchronization has * been done by the caller to ensure this is not called simultaneously by * several threads. - * + * * @param request * @param requestCanCreateSession * @return @@ -733,8 +734,8 @@ public abstract class VaadinService implements Serializable { /** * Creates and registers a new VaadinSession for this service. Assumes * proper locking has been taken care of by the caller. - * - * + * + * * @param request * The request which triggered session creation. * @return A new VaadinSession instance @@ -771,11 +772,11 @@ public abstract class VaadinService implements Serializable { * service. *

* This is only used to support legacy cases. - * + * * @param request * @return * @throws MalformedURLException - * + * * @deprecated As of 7.0. Only used to support {@link LegacyApplication}. */ @Deprecated @@ -786,12 +787,12 @@ public abstract class VaadinService implements Serializable { /** * Creates a new Vaadin session for this service and request - * + * * @param request * The request for which to create a VaadinSession * @return A new VaadinSession * @throws ServiceException - * + * */ protected VaadinSession createVaadinSession(VaadinRequest request) throws ServiceException { @@ -839,7 +840,7 @@ public abstract class VaadinService implements Serializable { /** * Retrieves the wrapped session for the request. - * + * * @param request * The request for which to retrieve a session * @param requestCanCreateSession @@ -862,7 +863,7 @@ public abstract class VaadinService implements Serializable { /** * Checks whether it's valid to create a new service session as a result of * the given request. - * + * * @param request * the request * @return true if it's valid to create a new service session @@ -877,10 +878,10 @@ public abstract class VaadinService implements Serializable { * {@link InheritableThreadLocal}). In other cases, (e.g. from background * threads started in some other way), the current service is not * automatically defined. - * + * * @return the current Vaadin service instance if available, otherwise * null - * + * * @see #setCurrentInstances(VaadinRequest, VaadinResponse) */ public static VaadinService getCurrent() { @@ -898,14 +899,14 @@ public abstract class VaadinService implements Serializable { * instances outside the normal request handling, e.g. when initiating * custom background threads. *

- * + * * @param request * the Vaadin request to set as the current request, or * null if no request should be set. * @param response * the Vaadin response to set as the current response, or * null if no response should be set. - * + * * @see #getCurrent() * @see #getCurrentRequest() * @see #getCurrentResponse() @@ -919,7 +920,7 @@ public abstract class VaadinService implements Serializable { /** * Sets the given Vaadin service as the current service. - * + * * @param service */ public static void setCurrent(VaadinService service) { @@ -931,10 +932,10 @@ public abstract class VaadinService implements Serializable { * automatically defined when the request is started. The current request * can not be used in e.g. background threads because of the way server * implementations reuse request instances. - * + * * @return the current Vaadin request instance if available, otherwise * null - * + * * @see #setCurrentInstances(VaadinRequest, VaadinResponse) */ public static VaadinRequest getCurrentRequest() { @@ -946,10 +947,10 @@ public abstract class VaadinService implements Serializable { * automatically defined when the request is started. The current response * can not be used in e.g. background threads because of the way server * implementations reuse response instances. - * + * * @return the current Vaadin response instance if available, otherwise * null - * + * * @see #setCurrentInstances(VaadinRequest, VaadinResponse) */ public static VaadinResponse getCurrentResponse() { @@ -961,7 +962,7 @@ public abstract class VaadinService implements Serializable { * different services of the same type but the same for corresponding * instances running in different JVMs in a cluster. This is typically based * on e.g. the configured servlet's or portlet's name. - * + * * @return the unique name of this service instance. */ public abstract String getServiceName(); @@ -972,11 +973,11 @@ public abstract class VaadinService implements Serializable { * related to any particular UI or have the UI information encoded in a * non-standard way. The returned UI is also set as the current UI ( * {@link UI#setCurrent(UI)}). - * + * * @param request * the request for which a UI is desired * @return the UI belonging to the request or null if no UI is found - * + * */ public UI findUI(VaadinRequest request) { // getForSession asserts that the lock is held @@ -1002,12 +1003,12 @@ public abstract class VaadinService implements Serializable { * typically checks the @{@link PreserveOnRefresh} annotation but UI * providers and ultimately VaadinService implementations may choose to * override the defaults. - * + * * @param provider * the UI provider responsible for the UI * @param event * the UI create event with details about the UI - * + * * @return true if the UI should be preserved on refresh; * false if a new UI instance should be initialized on * refreshed. @@ -1024,7 +1025,7 @@ public abstract class VaadinService implements Serializable { * Please note that this method makes certain assumptions about how data is * stored in the underlying session and may thus not be compatible with some * environments. - * + * * @param request * The Vaadin request for which the session should be * reinitialized @@ -1034,8 +1035,10 @@ public abstract class VaadinService implements Serializable { // Stores all attributes (security key, reference to this context // instance) so they can be added to the new session - HashMap attrs = new HashMap(); - for (String name : oldSession.getAttributeNames()) { + Set attributeNames = oldSession.getAttributeNames(); + HashMap attrs = new HashMap( + attributeNames.size() * 2); + for (String name : attributeNames) { Object value = oldSession.getAttribute(name); if (value instanceof VaadinSession) { // set flag to avoid cleanup @@ -1076,9 +1079,9 @@ public abstract class VaadinService implements Serializable { /** * TODO PUSH Document - * + * * TODO Pass UI or VaadinSession? - * + * * @param uI * @param themeName * @param resource @@ -1090,14 +1093,14 @@ public abstract class VaadinService implements Serializable { /** * Creates and returns a unique ID for the DIV where the UI is to be * rendered. - * + * * @param session * The service session to which the bootstrapped UI will belong. * @param request * The request for which a div id is needed * @param uiClass * The class of the UI that will be bootstrapped - * + * * @return the id to use in the DOM */ public abstract String getMainDivId(VaadinSession session, @@ -1115,9 +1118,9 @@ public abstract class VaadinService implements Serializable { * To avoid causing out of sync errors, you should typically redirect to * some other page using {@link Page#setLocation(String)} to make the * browser unload the invalidated UI. - * + * * @see SystemMessages#getSessionExpiredCaption() - * + * * @param session * the session to close */ @@ -1129,7 +1132,7 @@ public abstract class VaadinService implements Serializable { * Called at the end of a request, after sending the response. Closes * inactive UIs in the given session, removes closed UIs from the session, * and closes the session if it is itself inactive. - * + * * @param session */ void cleanupSession(VaadinSession session) { @@ -1164,7 +1167,7 @@ public abstract class VaadinService implements Serializable { /** * Removes those UIs from the given session for which {@link UI#isClosing() * isClosing} yields true. - * + * * @param session */ private void removeClosedUIs(final VaadinSession session) { @@ -1186,7 +1189,7 @@ public abstract class VaadinService implements Serializable { /** * Closes those UIs in the given session for which {@link #isUIActive} * yields false. - * + * * @since 7.0.0 */ private void closeInactiveUIs(VaadinSession session) { @@ -1212,11 +1215,11 @@ public abstract class VaadinService implements Serializable { * session. This is a lower bound; it might take longer to close an inactive * UI. Returns a negative number if heartbeat is disabled and timeout never * occurs. - * + * * @see DeploymentConfiguration#getHeartbeatInterval() - * + * * @since 7.0.0 - * + * * @return The heartbeat timeout in seconds or a negative number if timeout * never occurs. */ @@ -1235,12 +1238,12 @@ public abstract class VaadinService implements Serializable { * requests suffice to keep the session alive, but it will still eventually * expire in the regular manner if there are no requests at all (see * {@link WrappedSession#getMaxInactiveInterval()}). - * + * * @see DeploymentConfiguration#isCloseIdleSessions() * @see #getHeartbeatTimeout() - * + * * @since 7.0.0 - * + * * @return The UIDL request timeout in seconds, or a negative number if * timeout never occurs. */ @@ -1257,12 +1260,12 @@ public abstract class VaadinService implements Serializable { * A UI is active if and only if its {@link UI#isClosing() isClosing} * returns false and {@link #getHeartbeatTimeout() getHeartbeatTimeout} is * negative or has not yet expired. - * + * * @since 7.0.0 - * + * * @param ui * The UI whose status to check - * + * * @return true if the UI is active, false if it could be removed. */ private boolean isUIActive(UI ui) { @@ -1282,10 +1285,10 @@ public abstract class VaadinService implements Serializable { * A session is active if and only if its {@link #isClosing} returns false * and {@link #getUidlRequestTimeout(VaadinSession) getUidlRequestTimeout} * is negative or has not yet expired. - * + * * @param session * The session whose status to check - * + * * @return true if the session is active, false if it could be closed. */ private boolean isSessionActive(VaadinSession session) { @@ -1305,7 +1308,7 @@ public abstract class VaadinService implements Serializable { /** * Called before the framework starts handling a request - * + * * @param request * The request * @param response @@ -1323,7 +1326,7 @@ public abstract class VaadinService implements Serializable { /** * Called after the framework has handled a request and the response has * been written. - * + * * @param request * The request object * @param response @@ -1360,11 +1363,11 @@ public abstract class VaadinService implements Serializable { * Returns the request handlers that are registered with this service. The * iteration order of the returned collection is the same as the order in * which the request handlers will be invoked when a request is handled. - * + * * @return a collection of request handlers in the order they are invoked - * + * * @see #createRequestHandlers() - * + * * @since 7.1 */ public Iterable getRequestHandlers() { @@ -1381,7 +1384,7 @@ public abstract class VaadinService implements Serializable { * request handler handles session expiration a default expiration message * will be written. *

- * + * * @param request * The incoming request * @param response @@ -1473,7 +1476,7 @@ public abstract class VaadinService implements Serializable { /** * Writes the given string as a response using the given content type. - * + * * @param response * The response reference * @param contentType @@ -1498,7 +1501,7 @@ public abstract class VaadinService implements Serializable { /** * Called when the session has expired and the request handling is therefore * aborted. - * + * * @param request * The request * @param response @@ -1553,7 +1556,7 @@ public abstract class VaadinService implements Serializable { /** * Creates a JSON message which, when sent to client as-is, will cause a * critical error to be shown with the given details. - * + * * @param caption * The caption of the error or null to omit * @param message @@ -1616,10 +1619,10 @@ public abstract class VaadinService implements Serializable { /** * Enables push if push support is available and push has not yet been * enabled. - * + * * If push support is not available, a warning explaining the situation will * be logged at least the first time this method is invoked. - * + * * @return true if push can be used; false if push * is not available. */ @@ -1638,7 +1641,7 @@ public abstract class VaadinService implements Serializable { * internally used by {@link VaadinSession#accessSynchronously(Runnable)} * and {@link UI#accessSynchronously(Runnable)} to help avoid causing * deadlocks. - * + * * @since 7.1 * @param session * the session that is being locked @@ -1657,7 +1660,7 @@ public abstract class VaadinService implements Serializable { * provided one for which the current thread holds a lock. This method might * not detect all cases where some other session is locked, but it should * cover the most typical situations. - * + * * @since 7.2 * @param session * the session that is expected to be locked @@ -1681,11 +1684,11 @@ public abstract class VaadinService implements Serializable { * to allow a certain type of testing. For these cases, the check can be * disabled by setting the init parameter * disable-xsrf-protection to true. - * + * * @see DeploymentConfiguration#isXsrfProtectionEnabled() - * + * * @since 7.1 - * + * * @param session * the vaadin session for which the check should be done * @param requestToken @@ -1712,15 +1715,15 @@ public abstract class VaadinService implements Serializable { * Implementation for {@link VaadinSession#access(Runnable)}. This method is * implemented here instead of in {@link VaadinSession} to enable overriding * the implementation without using a custom subclass of VaadinSession. - * + * * @since 7.1 * @see VaadinSession#access(Runnable) - * + * * @param session * the vaadin session to access * @param runnable * the runnable to run with the session locked - * + * * @return a future that can be used to check for task completion and to * cancel the task */ @@ -1739,7 +1742,7 @@ public abstract class VaadinService implements Serializable { * thread, the queue will be purged when the session is unlocked. If the * lock is not held by any thread, it is acquired and the queue is purged * right away. - * + * * @since 7.1.2 * @param session * the session for which the access queue should be purged @@ -1775,7 +1778,7 @@ public abstract class VaadinService implements Serializable { *

* This method is automatically run by the framework at appropriate * situations and is not intended to be used by application developers. - * + * * @param session * the vaadin session to purge the queue for * @since 7.1 @@ -1817,11 +1820,11 @@ public abstract class VaadinService implements Serializable { /** * Adds a service destroy listener that gets notified when this service is * destroyed. - * + * * @since 7.2 * @param listener * the service destroy listener to add - * + * * @see #destroy() * @see #removeServiceDestroyListener(ServiceDestroyListener) * @see ServiceDestroyListener @@ -1834,7 +1837,7 @@ public abstract class VaadinService implements Serializable { /** * Removes a service destroy listener that was previously added with * {@link #addServiceDestroyListener(ServiceDestroyListener)}. - * + * * @since 7.2 * @param listener * the service destroy listener to remove @@ -1848,11 +1851,11 @@ public abstract class VaadinService implements Serializable { * Called when the servlet, portlet or similar for this service is being * destroyed. After this method has been called, no more requests will be * handled by this service. - * + * * @see #addServiceDestroyListener(ServiceDestroyListener) * @see Servlet#destroy() * @see Portlet#destroy() - * + * * @since 7.2 */ public void destroy() { diff --git a/server/src/com/vaadin/server/communication/LegacyUidlWriter.java b/server/src/com/vaadin/server/communication/LegacyUidlWriter.java index 43ea1aca67..3f70a25c5b 100644 --- a/server/src/com/vaadin/server/communication/LegacyUidlWriter.java +++ b/server/src/com/vaadin/server/communication/LegacyUidlWriter.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 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 @@ -35,7 +35,7 @@ import com.vaadin.ui.UI; /** * Serializes legacy UIDL changes to JSON. - * + * * @author Vaadin Ltd * @since 7.1 */ @@ -44,7 +44,7 @@ public class LegacyUidlWriter implements Serializable { /** * Writes a JSON array containing the changes of all dirty * {@link LegacyComponent}s in the given UI. - * + * * @param ui * The {@link UI} whose legacy changes to write * @param writer @@ -60,7 +60,8 @@ public class LegacyUidlWriter implements Serializable { Collection dirtyVisibleConnectors = ui .getConnectorTracker().getDirtyVisibleConnectors(); - List legacyComponents = new ArrayList(); + List legacyComponents = new ArrayList( + dirtyVisibleConnectors.size()); for (ClientConnector connector : dirtyVisibleConnectors) { // All Components that want to use paintContent must implement // LegacyComponent diff --git a/server/src/com/vaadin/server/communication/ServerRpcHandler.java b/server/src/com/vaadin/server/communication/ServerRpcHandler.java index 36bfc8bcc6..6f1d44d087 100644 --- a/server/src/com/vaadin/server/communication/ServerRpcHandler.java +++ b/server/src/com/vaadin/server/communication/ServerRpcHandler.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 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 @@ -55,7 +55,7 @@ import com.vaadin.ui.UI; /** * Handles a client-to-server message containing serialized {@link ServerRpc * server RPC} invocations. - * + * * @author Vaadin Ltd * @since 7.1 */ @@ -64,7 +64,7 @@ public class ServerRpcHandler implements Serializable { /** * A data transfer object representing an RPC request sent by the client * side. - * + * * @since 7.2 * @author Vaadin Ltd */ @@ -91,7 +91,7 @@ public class ServerRpcHandler implements Serializable { /** * Gets the CSRF security token (double submit cookie) for this request. - * + * * @return the CSRF security token for this current change request */ public String getCsrfToken() { @@ -100,7 +100,7 @@ public class ServerRpcHandler implements Serializable { /** * Gets the data to recreate the RPC as requested by the client side. - * + * * @return the data describing which RPC should be made, and all their * data */ @@ -110,7 +110,7 @@ public class ServerRpcHandler implements Serializable { /** * Gets the sync id last seen by the client. - * + * * @return the last sync id given by the server, according to the * client's request */ @@ -124,9 +124,9 @@ public class ServerRpcHandler implements Serializable { *

* Note: This is a shared reference - any modifications made * will be shared. - * + * * @return the raw JSON object that was received from the client - * + * */ public JSONObject getRawJson() { return json; @@ -138,7 +138,7 @@ public class ServerRpcHandler implements Serializable { /** * Reads JSON containing zero or more serialized RPC calls (including legacy * variable changes) and executes the calls. - * + * * @param ui * The {@link UI} receiving the calls. Cannot be null. * @param reader @@ -188,7 +188,7 @@ public class ServerRpcHandler implements Serializable { * changeVariables() is only called once for them. This preserves the Vaadin * 6 semantics for components and add-ons that do not use Vaadin 7 RPC * directly. - * + * * @param uI * the UI receiving the invocations data * @param lastSyncIdSeenByClient @@ -318,7 +318,7 @@ public class ServerRpcHandler implements Serializable { /** * Parse JSON from the client into a list of MethodInvocation instances. - * + * * @param connectorTracker * The ConnectorTracker used to lookup connectors * @param invocationsJson @@ -333,11 +333,13 @@ public class ServerRpcHandler implements Serializable { private List parseInvocations( ConnectorTracker connectorTracker, JSONArray invocationsJson, int lastSyncIdSeenByClient) throws JSONException { - ArrayList invocations = new ArrayList(); + int invocationCount = invocationsJson.length(); + ArrayList invocations = new ArrayList( + invocationCount); MethodInvocation previousInvocation = null; // parse JSON to MethodInvocations - for (int i = 0; i < invocationsJson.length(); ++i) { + for (int i = 0; i < invocationCount; ++i) { JSONArray invocationJson = invocationsJson.getJSONArray(i); @@ -500,7 +502,7 @@ public class ServerRpcHandler implements Serializable { /** * Generates an error message when the client is trying to to something * ('what') with a connector which is disabled or invisible. - * + * * @since 7.1.8 * @param connector * the connector which is disabled (or invisible) diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index b5a0227d99..9b8729f779 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 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 @@ -55,10 +55,10 @@ import com.vaadin.server.StreamVariable; * operation new information needs to be sent to its * {@link com.vaadin.client.ServerConnector}. *

- * + * * @author Vaadin Ltd * @since 7.0.0 - * + * */ public class ConnectorTracker implements Serializable { @@ -87,7 +87,7 @@ public class ConnectorTracker implements Serializable { /** * Map to track on which syncId each connector was removed. - * + * * @see #getCurrentSyncId() * @see #cleanConcurrentlyRemovedConnectorIds(long) */ @@ -95,9 +95,9 @@ public class ConnectorTracker implements Serializable { /** * Gets a logger for this class - * + * * @return A logger instance for logging within this class - * + * */ public static Logger getLogger() { return Logger.getLogger(ConnectorTracker.class.getName()); @@ -107,7 +107,7 @@ public class ConnectorTracker implements Serializable { * Creates a new ConnectorTracker for the given uI. A tracker is always * attached to a uI and the uI cannot be changed during the lifetime of a * {@link ConnectorTracker}. - * + * * @param uI * The uI to attach to. Cannot be null. */ @@ -121,7 +121,7 @@ public class ConnectorTracker implements Serializable { * The lookup method {@link #getConnector(String)} only returns registered * connectors. *

- * + * * @param connector * The connector to register. */ @@ -157,12 +157,12 @@ public class ConnectorTracker implements Serializable { /** * Unregister the given connector. - * + * *

* The lookup method {@link #getConnector(String)} only returns registered * connectors. *

- * + * * @param connector * The connector to unregister */ @@ -213,7 +213,7 @@ public class ConnectorTracker implements Serializable { * Checks whether the given connector has already been initialized in the * browser. The given connector should be registered with this connector * tracker. - * + * * @param connector * the client connector to check * @return true if the initial state has previously been sent @@ -228,9 +228,9 @@ public class ConnectorTracker implements Serializable { /** * Marks the given connector as initialized, meaning that the client-side * state has been initialized for the connector. - * + * * @see #isClientSideInitialized(ClientConnector) - * + * * @param connector * the connector that should be marked as initialized */ @@ -242,7 +242,7 @@ public class ConnectorTracker implements Serializable { * Marks all currently registered connectors as uninitialized. This should * be done when the client-side has been reset but the server-side state is * retained. - * + * * @see #isClientSideInitialized(ClientConnector) */ public void markAllClientSidesUninitialized() { @@ -252,7 +252,7 @@ public class ConnectorTracker implements Serializable { /** * Gets a connector by its id. - * + * * @param connectorId * The connector id to look for * @return The connector with the given id or null if no connector has the @@ -400,10 +400,10 @@ public class ConnectorTracker implements Serializable { /** * Mark the connector as dirty. This should not be done while the response * is being written. - * + * * @see #getDirtyConnectors() * @see #isWritingResponse() - * + * * @param connector * The connector that should be marked clean. */ @@ -425,7 +425,7 @@ public class ConnectorTracker implements Serializable { /** * Mark the connector as clean. - * + * * @param connector * The connector that should be marked clean. */ @@ -443,7 +443,7 @@ public class ConnectorTracker implements Serializable { /** * Returns {@link #getConnectorString(ClientConnector)} for the connector * and its parent (if it has a parent). - * + * * @param connector * The connector * @return A string describing the connector and its parent @@ -460,7 +460,7 @@ public class ConnectorTracker implements Serializable { /** * Returns a string with the connector name and id. Useful mostly for * debugging and logging. - * + * * @param connector * The connector * @return A string that describes the connector @@ -500,7 +500,7 @@ public class ConnectorTracker implements Serializable { /** * Marks all visible connectors dirty, starting from the given connector and * going downwards in the hierarchy. - * + * * @param c * The component to start iterating downwards from */ @@ -521,7 +521,7 @@ public class ConnectorTracker implements Serializable { * The state and pending RPC calls for dirty connectors are sent to the * client in the following request. *

- * + * * @return A collection of all dirty connectors for this uI. This list may * contain invisible connectors. */ @@ -531,7 +531,7 @@ public class ConnectorTracker implements Serializable { /** * Checks if there a dirty connectors. - * + * * @return true if there are dirty connectors, false otherwise */ public boolean hasDirtyConnectors() { @@ -541,17 +541,19 @@ public class ConnectorTracker implements Serializable { /** * Returns a collection of those {@link #getDirtyConnectors() dirty * connectors} that are actually visible to the client. - * + * * @return A list of dirty and visible connectors. */ public ArrayList getDirtyVisibleConnectors() { - ArrayList dirtyConnectors = new ArrayList(); - for (ClientConnector c : getDirtyConnectors()) { + Collection dirtyConnectors = getDirtyConnectors(); + ArrayList dirtyVisibleConnectors = new ArrayList( + dirtyConnectors.size()); + for (ClientConnector c : dirtyConnectors) { if (LegacyCommunicationManager.isConnectorVisibleToClient(c)) { - dirtyConnectors.add(c); + dirtyVisibleConnectors.add(c); } } - return dirtyConnectors; + return dirtyVisibleConnectors; } public JSONObject getDiffState(ClientConnector connector) { @@ -571,10 +573,10 @@ public class ConnectorTracker implements Serializable { /** * Checks whether the response is currently being written. Connectors can * not be marked as dirty when a response is being written. - * + * * @see #setWritingResponse(boolean) * @see #markDirty(ClientConnector) - * + * * @return true if the response is currently being written, * false if outside the response writing phase. */ @@ -590,14 +592,14 @@ public class ConnectorTracker implements Serializable { * {@link #getCurrentSyncId()}), if {@link #isWritingResponse()} returns * false and writingResponse is set to * true. - * + * * @param writingResponse * the new response status. - * + * * @see #markDirty(ClientConnector) * @see #isWritingResponse() * @see #getCurrentSyncId() - * + * * @throws IllegalArgumentException * if the new response status is the same as the previous value. * This is done to help detecting problems caused by missed @@ -625,7 +627,7 @@ public class ConnectorTracker implements Serializable { // Convert JSONObjects in diff state to String representation as // JSONObject is not serializable HashMap stringDiffStates = new HashMap( - diffStates.size()); + diffStates.size() * 2); for (ClientConnector key : diffStates.keySet()) { stringDiffStates.put(key, diffStates.get(key).toString()); } @@ -643,7 +645,8 @@ public class ConnectorTracker implements Serializable { @SuppressWarnings("unchecked") HashMap stringDiffStates = (HashMap) in .readObject(); - diffStates = new HashMap(); + diffStates = new HashMap( + stringDiffStates.size() * 2); for (ClientConnector key : stringDiffStates.keySet()) { try { diffStates.put(key, new JSONObject(stringDiffStates.get(key))); @@ -657,7 +660,7 @@ public class ConnectorTracker implements Serializable { /** * Checks if the indicated connector has a StreamVariable of the given name * and returns the variable if one is found. - * + * * @param connectorId * @param variableName * @return variable if a matching one exists, otherwise null @@ -678,7 +681,7 @@ public class ConnectorTracker implements Serializable { /** * Adds a StreamVariable of the given name to the indicated connector. - * + * * @param connectorId * @param variableName * @param variable @@ -734,7 +737,7 @@ public class ConnectorTracker implements Serializable { /** * Removes any StreamVariable of the given name from the indicated * connector. - * + * * @param connectorId * @param variableName */ @@ -752,7 +755,7 @@ public class ConnectorTracker implements Serializable { /** * Returns the security key associated with the given StreamVariable. - * + * * @param variable * @return matching security key if one exists, null otherwise */ @@ -767,7 +770,7 @@ public class ConnectorTracker implements Serializable { * Check whether a connector was present on the client when the it was * creating this request, but was removed server-side before the request * arrived. - * + * * @since 7.2 * @param connectorId * The connector id to check for whether it was removed @@ -827,7 +830,7 @@ public class ConnectorTracker implements Serializable { *

* The sync id value -1 is ignored to facilitate testing with * pre-recorded requests. - * + * * @see #setWritingResponse(boolean) * @see #connectorWasPresentAsRequestWasSent(String, long) * @since 7.2 @@ -853,7 +856,7 @@ public class ConnectorTracker implements Serializable { *

* The sync id value -1 is ignored to facilitate testing with * pre-recorded requests. - * + * * @see #connectorWasPresentAsRequestWasSent(String, long) * @since 7.2 * @param lastSyncIdSeenByClient -- 2.39.5