http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/UserAgentStaticProperties.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/UserAgentStaticProperties.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/UserAgentStaticProperties.java deleted file mode 100644 index 4c5d029..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/UserAgentStaticProperties.java +++ /dev/null @@ -1,124 +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.waveprotocol.wave.client.common.util; - -import com.google.gwt.core.client.GWT; - -/** - * Class to allow conditional compilation for different user agents. - * - * All methods should return values that are known at compile time. - * * - * TODO(user): Should this ever be thrown in for free with GWT, rather use - * their approach. A relevant thread is: - * http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse_thread/thread/6745dee7a85eb585/bd58d1a9f2344b34 - * - * FIXME: GWT superdev recompilation fails when this class is abstract - * - */ -public class UserAgentStaticProperties { - - static UserAgentStaticProperties get() { - return INSTANCE; - } - - private static final UserAgentStaticProperties INSTANCE = createInstance(); - - /** - * Creates an instance of UserAgent. - * - * NOTE(danilatos): This method is designed to be statically evaluable by - * the compiler, such that the compiler can determine that - * only one subclass of UserAgent is ever used within a - * given permutation. This is possible because - * GWT.isClient() is replaced with true by the compiler, - * even though it is executed normally in unit tests. - * Testing the return value of GWT.create() is not adequate - * because only boolean values can be statically evaluated - * by the compiler at this time. - * - * @return an instance of UserAgent. - */ - private static UserAgentStaticProperties createInstance() { - if (GWT.isClient()) { - return GWT.create(UserAgentStaticProperties.class); - } else { - return new FirefoxImpl(); - } - } - - final boolean isWebkit() { - return isSafari() || isMobileWebkit(); - } - - /** - * @return true iff the user agent uses mobile webkit - */ - final boolean isMobileWebkit() { - return isAndroid() || isIPhone(); - } - - // Default instance methods: most return false, since they are intended to be overriden. - boolean isSafari() { return false; } - boolean isFirefox() { return false; } - boolean isIE() { return false; } - boolean isAndroid() { return false; } - boolean isIPhone() { return false; } - - // NOTE(user): Created via deferred binding - public static class SafariImpl extends UserAgentStaticProperties { - @Override - protected boolean isSafari() { - return true; - } - } - - // NOTE(user): Created via deferred binding - public static class FirefoxImpl extends UserAgentStaticProperties { - @Override - protected boolean isFirefox() { - return true; - } - } - - // NOTE(user): Created via deferred binding - public static class IEImpl extends UserAgentStaticProperties { - @Override - protected boolean isIE() { - return true; - } - } - - // NOTE(user): Created via deferred binding - public static class AndroidImpl extends UserAgentStaticProperties { - @Override - protected boolean isAndroid() { - return true; - } - } - - // NOTE(user): Created via deferred binding - public static class IPhoneImpl extends UserAgentStaticProperties { - @Override - protected boolean isIPhone() { - return true; - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/View.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/View.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/View.java deleted file mode 100644 index 032b512..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/View.java +++ /dev/null @@ -1,44 +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.waveprotocol.wave.client.common.util; - -/** - * Base View interface. - * - * @param <L> listener interface for this view. - */ -public interface View<L> { - - interface Factory<V extends View<?>> extends org.waveprotocol.wave.client.common.util.Factory<V> {} - - /** - * Initializes this view. The view is considered to be used until - * {@link #reset()}. - * - * @param listener listener for events broadcast by this view - */ - void init(L listener); - - /** - * Releases this view from being used. It is up to each implementation type to - * define if this view is reusable after this method is called. - */ - void reset(); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/VolatileComparable.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/VolatileComparable.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/VolatileComparable.java deleted file mode 100644 index ebdfac4..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/VolatileComparable.java +++ /dev/null @@ -1,35 +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.waveprotocol.wave.client.common.util; - -/** - * Interface for volatile objects that may or may not be comparable to one another at any given - * moment. The volatility must be monotonic: one it is incomparable, it will never again be - * comparable. - * - * @author [email protected] (Daniel Danilatos) - */ -public interface VolatileComparable<T> extends Comparable<T> { - - /** - * @return true if it makes sense for this object to be compared to a similar object. - */ - boolean isComparable(); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/WaveRefConstants.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/WaveRefConstants.java b/wave/src/main/java/org/waveprotocol/wave/client/common/util/WaveRefConstants.java deleted file mode 100644 index c0129bd..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/WaveRefConstants.java +++ /dev/null @@ -1,43 +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.waveprotocol.wave.client.common.util; - - -public interface WaveRefConstants { - - public static final String WAVE_SCHEME = "wave"; - - /** The temporary format for wavelinks */ - public static final String WAVE_URI_PREFIX = WAVE_SCHEME + "://"; - - - @Deprecated - public static final String WAVE_SCHEME_OLD = "waveid"; - - /** - * The temporary format for wavelinks - * @deprecated Use WAVE_URI_PREFIX. - */ - @Deprecated - public static final String WAVE_URI_PREFIX_OLD = WAVE_SCHEME_OLD + "://"; - - /** The tag in a permalink */ - public static final String PERMALINK_WAVEREF_TAG = "waveref/"; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/util/quirks_strings ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/util/quirks_strings b/wave/src/main/java/org/waveprotocol/wave/client/common/util/quirks_strings deleted file mode 100755 index 04e34f6..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/util/quirks_strings +++ /dev/null @@ -1,63 +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.waveprotocol.wave.client.common.util; - -import org.waveprotocol.wave.model.util.CollectionUtils; -import org.waveprotocol.wave.model.util.StringMap; - -// THIS CLASS IS GENERATED BY generateConstants.sh, DO NOT EDIT DIRECTLY // - -/** QuirksConstants string names for debugging */ -public final class QuirksConstantsStrings { - public static final StringMap<Boolean> CONSTANTS = CollectionUtils.createStringMap(); - static { - - CONSTANTS.put("PROVIDES_MUTATION_EVENTS",QuirksConstants.PROVIDES_MUTATION_EVENTS); - CONSTANTS.put("USUALLY_LEFT_NORMALISES",QuirksConstants.USUALLY_LEFT_NORMALISES); - CONSTANTS.put("LIES_ABOUT_CARET_AT_LINK_END_BOUNDARY",QuirksConstants.LIES_ABOUT_CARET_AT_LINK_END_BOUNDARY); - CONSTANTS.put("DOES_NOT_LEFT_NORMALISE_AT_LINK_END_BOUNDARY",QuirksConstants.DOES_NOT_LEFT_NORMALISE_AT_LINK_END_BOUNDARY); - CONSTANTS.put("ALWAYS_GIVES_KEY_EVENT_BEFORE_CHANGING_DOM",QuirksConstants.ALWAYS_GIVES_KEY_EVENT_BEFORE_CHANGING_DOM); - CONSTANTS.put("CAN_TELL_WHEN_FIRST_KEY_EVENT_IS_IME",QuirksConstants.CAN_TELL_WHEN_FIRST_KEY_EVENT_IS_IME); - CONSTANTS.put("HAS_OLD_SCHOOL_CLIPBOARD_SHORTCUTS",QuirksConstants.HAS_OLD_SCHOOL_CLIPBOARD_SHORTCUTS); - CONSTANTS.put("OK_SELECTION_ACROSS_TEXT_NODE_DATA_CHANGES",QuirksConstants.OK_SELECTION_ACROSS_TEXT_NODE_DATA_CHANGES); - CONSTANTS.put("OK_SELECTION_ACROSS_NODE_REMOVALS",QuirksConstants.OK_SELECTION_ACROSS_NODE_REMOVALS); - CONSTANTS.put("OK_SELECTION_ACROSS_TEXT_NODE_SPLITS",QuirksConstants.OK_SELECTION_ACROSS_TEXT_NODE_SPLITS); - CONSTANTS.put("OK_SELECTION_ACROSS_MOVES",QuirksConstants.OK_SELECTION_ACROSS_MOVES); - CONSTANTS.put("PRESERVES_SEMANTIC_SELECTION_ACROSS_INTRINSIC_TEXT_NODE_CHANGES",QuirksConstants.PRESERVES_SEMANTIC_SELECTION_ACROSS_INTRINSIC_TEXT_NODE_CHANGES); - CONSTANTS.put("PRESERVES_SEMANTIC_SELECTION_ACROSS_MUTATIONS_OR_CLEARS_IT",QuirksConstants.PRESERVES_SEMANTIC_SELECTION_ACROSS_MUTATIONS_OR_CLEARS_IT); - CONSTANTS.put("RANGED_SELECTION_AFFECTED_BY_INTERNAL_CHANGED",QuirksConstants.RANGED_SELECTION_AFFECTED_BY_INTERNAL_CHANGED); - CONSTANTS.put("PRESERVES_IME_STATE_ACROSS_ADJACENT_CHANGES",QuirksConstants.PRESERVES_IME_STATE_ACROSS_ADJACENT_CHANGES); - CONSTANTS.put("DOES_NOT_SUPPORT_JSO_PROTO_FIELD",QuirksConstants.DOES_NOT_SUPPORT_JSO_PROTO_FIELD); - CONSTANTS.put("CANCEL_BUBBLING_CANCELS_IME_COMPOSITION_AND_CONTEXTMENU",QuirksConstants.CANCEL_BUBBLING_CANCELS_IME_COMPOSITION_AND_CONTEXTMENU); - CONSTANTS.put("SUPPORTS_EVENT_GET_RANGE_METHODS",QuirksConstants.SUPPORTS_EVENT_GET_RANGE_METHODS); - CONSTANTS.put("PREVENT_DEFAULT_STOPS_CONTEXTMENT",QuirksConstants.PREVENT_DEFAULT_STOPS_CONTEXTMENT); - CONSTANTS.put("CONTEXTMENU_SETS_SELECTION",QuirksConstants.CONTEXTMENU_SETS_SELECTION); - CONSTANTS.put("HAS_BASE_AND_EXTENT",QuirksConstants.HAS_BASE_AND_EXTENT); - CONSTANTS.put("COMMAND_COMBO_DOESNT_GIVE_KEYPRESS",QuirksConstants.COMMAND_COMBO_DOESNT_GIVE_KEYPRESS); - CONSTANTS.put("SUPPORTS_GET_ELEMENTS_BY_CLASSNAME",QuirksConstants.SUPPORTS_GET_ELEMENTS_BY_CLASSNAME); - CONSTANTS.put("SUPPORTS_COMPOSITION_EVENTS",QuirksConstants.SUPPORTS_COMPOSITION_EVENTS); - CONSTANTS.put("MODIFIES_DOM_AND_FIRES_TEXTINPUT_AFTER_COMPOSITION",QuirksConstants.MODIFIES_DOM_AND_FIRES_TEXTINPUT_AFTER_COMPOSITION); - CONSTANTS.put("SUPPORTS_CARET_IN_EMPTY_SPAN",QuirksConstants.SUPPORTS_CARET_IN_EMPTY_SPAN); - CONSTANTS.put("ADJUSTS_SCROLL_TOP_WHEN_FOCUSING",QuirksConstants.ADJUSTS_SCROLL_TOP_WHEN_FOCUSING); - CONSTANTS.put("PLAINTEXT_PASTE_DOES_NOT_EMIT_PASTE_EVENT",QuirksConstants.PLAINTEXT_PASTE_DOES_NOT_EMIT_PASTE_EVENT); - - } -} - http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/common/webdriver/DebugClassHelper.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/common/webdriver/DebugClassHelper.java b/wave/src/main/java/org/waveprotocol/wave/client/common/webdriver/DebugClassHelper.java deleted file mode 100644 index 2c4161b..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/common/webdriver/DebugClassHelper.java +++ /dev/null @@ -1,167 +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.waveprotocol.wave.client.common.webdriver; - -import com.google.common.base.Preconditions; -import com.google.gwt.dom.client.Element; -import com.google.gwt.user.client.ui.UIObject; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -/** - * Helper methods for adding debugclasses to the DOM Elements. - * - */ -public class DebugClassHelper { - - /** The name of the debug-class attribute. */ - private static final String DEBUG_CLASS_ATTRIBUTE = "dc"; - /** Whether debug class should be set (e.g. for testing purposes). */ - private static boolean debugClassEnabled = false; - - /** Disallow construction. */ - private DebugClassHelper() {} - - /** - * Adds a debug class to a UIObject. - * - * @param uiObject the object to modify - * @param debugClass to be added - */ - public static final void addDebugClass(UIObject uiObject, String debugClass) { - Preconditions.checkNotNull(uiObject, "uiObject cannot be null"); - addDebugClass(uiObject.getElement(), debugClass); - } - - /** - * Adds a debug class to an Element. - * - * @param elem the object to modify - * @param debugClass to be added - */ - public static final void addDebugClass(Element elem, String debugClass) { - Preconditions.checkNotNull(elem, "addDebugClass: Element must not be null"); - if (debugClassEnabled) { - Set<String> debugClasses = getDebugClasses(elem); - if (debugClasses.add(debugClass)) { - elem.setAttribute(DEBUG_CLASS_ATTRIBUTE, joinDebugClasses(debugClasses)); - } - } - } - - /** - * Replaces a debug class name from an Element with another one. - * - * @param elem the object to modify - * @param oldClassName previous class name to be removed - * @param newClassName new class name to be added - */ - public static final void replaceDebugClass( - Element elem, String oldClassName, String newClassName) { - Preconditions.checkNotNull(elem, "replaceDebugClass: Element must not be null"); - if (debugClassEnabled) { - Set<String> debugClasses = getDebugClasses(elem); - boolean removed = debugClasses.remove(oldClassName); - // if no change happened in the debugClasses, do nothing - if (debugClasses.add(newClassName) || removed) { - elem.setAttribute(DEBUG_CLASS_ATTRIBUTE, joinDebugClasses(debugClasses)); - } - } - } - - /** - * Removes a debug class from a UIObject. - * - * @param uiObject the object to modify - * @param debugClass to be removed - */ - public static final void removeDebugClass(UIObject uiObject, String debugClass) { - Preconditions.checkNotNull(uiObject, "uiObject cannot be null"); - removeDebugClass(uiObject.getElement(), debugClass); - } - - /** - * Remove a debug class from an Element. - * - * @param elem the object to modify - * @param debugClass to be removed - */ - public static final void removeDebugClass(Element elem, String debugClass) { - if (debugClassEnabled && null != elem) { - Set<String> debugClasses = getDebugClasses(elem); - if (debugClasses.remove(debugClass)) { - elem.setAttribute(DEBUG_CLASS_ATTRIBUTE, joinDebugClasses(debugClasses)); - } - } - } - - /** - * Removes all debug classes from a UIObject. - * @param uiObject The UIObject to remove debug classes from. - */ - public static void clearDebugClasses(UIObject uiObject) { - clearDebugClasses(uiObject.getElement()); - } - - /** - * Removes all debug classes from an Element. - * @param elem The element to remove debug classes from. - */ - public static void clearDebugClasses(Element elem) { - elem.removeAttribute(DEBUG_CLASS_ATTRIBUTE); - } - - /** - * Join a set of Strings into a space-separated String. - * @param debugClasses to be joined - * @return a String of debug classes - */ - private static final String joinDebugClasses(Set<String> debugClasses) { - StringBuilder result = new StringBuilder(); - for (String debugClass : debugClasses) { - result.append(debugClass); - result.append(" "); - } - return result.toString().trim(); - } - - /** - * Get a set of debug classes present in an element. - * @param elem from which debug classes will be read from - * @return the set of debug classes - */ - private static final Set<String> getDebugClasses(Element elem) { - Set<String> result = new HashSet<String>(); - String debugClasses = elem.getAttribute(DEBUG_CLASS_ATTRIBUTE); - result.addAll(Arrays.asList(debugClasses.split(" "))); - return result; - } - - /** - * Set whether to enable debug classes (for testing purposes). - * - * @param enableDebugClass the new value - */ - public static void setDebugClassEnabled(boolean enableDebugClass) { - debugClassEnabled = enableDebugClass; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/LiveChannelBinder.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/LiveChannelBinder.java b/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/LiveChannelBinder.java deleted file mode 100644 index 5b5908d..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/LiveChannelBinder.java +++ /dev/null @@ -1,202 +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.waveprotocol.wave.client.concurrencycontrol; - -import com.google.common.base.Preconditions; -import com.google.gwt.user.client.Command; - -import org.waveprotocol.wave.client.wave.WaveDocuments; -import org.waveprotocol.wave.concurrencycontrol.channel.Accessibility; -import org.waveprotocol.wave.concurrencycontrol.channel.OperationChannel; -import org.waveprotocol.wave.concurrencycontrol.channel.OperationChannelMultiplexer; -import org.waveprotocol.wave.concurrencycontrol.channel.OperationChannelMultiplexer.KnownWavelet; -import org.waveprotocol.wave.concurrencycontrol.common.CorruptionDetail; -import org.waveprotocol.wave.concurrencycontrol.wave.CcDocument; -import org.waveprotocol.wave.model.id.IdFilter; -import org.waveprotocol.wave.model.id.ModernIdSerialiser; -import org.waveprotocol.wave.model.id.WaveletId; -import org.waveprotocol.wave.model.util.CollectionUtils; -import org.waveprotocol.wave.model.util.StringMap; -import org.waveprotocol.wave.model.wave.ObservableWavelet; -import org.waveprotocol.wave.model.wave.WaveViewListener; -import org.waveprotocol.wave.model.wave.data.ObservableWaveletData; -import org.waveprotocol.wave.model.wave.opbased.OpBasedWavelet; -import org.waveprotocol.wave.model.wave.opbased.WaveViewImpl; - -import java.util.Collection; - -/** - * Binds operation channels from a {@link OperationChannelMultiplexer mux} with - * the output sinks of wavelets, and keeps binding matching channel/wavelet - * pairs while live. - * - * @author [email protected] (David Hearnden) - */ -public final class LiveChannelBinder - implements WaveViewListener, OperationChannelMultiplexer.Listener { - - private final StaticChannelBinder binder; - private final WaveletOperationalizer operationalizer; - private final WaveViewImpl<OpBasedWavelet> wave; - private final OperationChannelMultiplexer mux; - private final Command whenOpened; - - /** - * Operation channels waiting to be bound. This map is populated from {@link - * #onOperationChannelCreated(OperationChannel, ObservableWaveletData, - * Accessibility)}, and depleted by {@link #connect(String)}. - */ - private final StringMap<OperationChannel> channels = CollectionUtils.createStringMap(); - - // - // The binding flow is not completely trivial, because it has to work with - // two directions of control flow: - // - // Client-created wavelets: - // 1. wavelet shows up in the model - // 2. this binder tells mux to create op channel, - // 3. its operation channel shows up, then - // 4. wavelet and op channel are bound together. - // - // Server-created wavelets: - // 1. op channel shows up in the mux, - // 2. this binder builds wavelet and puts it in the model, - // 3. wavelet shows up in the model, then - // 4. wavelet and op channel are bound together. - // - // Also, the initial set of operation channels when opening a wave with known - // wavelet states is just like the server-created wavelet flow, except without - // step 2. - // - - private LiveChannelBinder(StaticChannelBinder binder, WaveletOperationalizer operationalizer, - WaveViewImpl<OpBasedWavelet> wave, OperationChannelMultiplexer mux, Command whenOpened) { - this.binder = binder; - this.operationalizer = operationalizer; - this.wave = wave; - this.mux = mux; - this.whenOpened = whenOpened; - } - - /** - * Opens a mux, binding its operation channels with operation-supporting - * wavelets. - */ - public static void openAndBind(WaveletOperationalizer operationalizer, - WaveViewImpl<OpBasedWavelet> wave, - WaveDocuments<? extends CcDocument> docRegistry, - OperationChannelMultiplexer mux, - IdFilter filter, - Command whenOpened) { - StaticChannelBinder staticBinder = new StaticChannelBinder(operationalizer, docRegistry); - LiveChannelBinder liveBinder = - new LiveChannelBinder(staticBinder, operationalizer, wave, mux, whenOpened); - - final Collection<KnownWavelet> remoteWavelets = CollectionUtils.createQueue(); - final Collection<ObservableWaveletData> localWavelets = CollectionUtils.createQueue(); - for (ObservableWaveletData wavelet : operationalizer.getWavelets()) { - // Version 0 wavelets must be wavelets that the client has created in this - // session. They are not to be included in the known-wavelet collection, - // because the server does not know about them. - if (wavelet.getVersion() > 0) { - remoteWavelets.add( - new KnownWavelet(wavelet, wavelet.getHashedVersion(), Accessibility.READ_WRITE)); - } else { - localWavelets.add(wavelet); - } - } - - // Start listening to wave events and channel events. - wave.addListener(liveBinder); - // This binder only starts getting events once open() has been called, since - // that is what sets this binder as a mux listener. Since wavelet-to-channel - // binding occurs through event callbacks, this listener setting must occur - // before trying to bind localWavelets. - mux.open(liveBinder, filter, remoteWavelets); - for (ObservableWaveletData local : localWavelets) { - mux.createOperationChannel(local.getWaveletId(), local.getCreator()); - } - } - - @Override - public void onFailed(CorruptionDetail detail) { - throw new RuntimeException(detail); - } - - @Override - public void onOpenFinished() { - if (whenOpened != null) { - whenOpened.execute(); - } - } - - // - // Wavelet and Channel lifecycle events: - // - - @Override - public void onWaveletAdded(ObservableWavelet wavelet) { - String id = ModernIdSerialiser.INSTANCE.serialiseWaveletId(wavelet.getId()); - if (channels.containsKey(id)) { - connect(id); - } else { - // This will trigger the onOperationChannelCreated callback below. - mux.createOperationChannel(wavelet.getId(), wavelet.getCreatorId()); - } - } - - @Override - public void onOperationChannelCreated( - OperationChannel channel, ObservableWaveletData snapshot, Accessibility accessibility) { - WaveletId wid = snapshot.getWaveletId(); - String id = ModernIdSerialiser.INSTANCE.serialiseWaveletId(wid); - - Preconditions.checkState(!channels.containsKey(id)); - channels.put(id, channel); - - if (wave.getWavelet(wid) != null) { - connect(id); - } else { - // This will trigger the onWaveletAdded callback above. - wave.addWavelet(operationalizer.operationalize(snapshot)); - } - } - - @Override - public void onWaveletRemoved(ObservableWavelet wavelet) { - // TODO - } - - @Override - public void onOperationChannelRemoved(OperationChannel channel, WaveletId waveletId) { - // TODO - } - - private void connect(String id) { - binder.bind(id, removeAndReturn(channels, id)); - } - - // Something that should have been on StringMap from the beginning. - private static <V> V removeAndReturn(StringMap<V> map, String key) { - V value = map.get(key); - map.remove(key); - return value; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/LiveTarget.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/LiveTarget.java b/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/LiveTarget.java deleted file mode 100644 index 1859622..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/LiveTarget.java +++ /dev/null @@ -1,85 +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.waveprotocol.wave.client.concurrencycontrol; - -import org.waveprotocol.wave.model.operation.Operation; -import org.waveprotocol.wave.model.operation.OperationException; -import org.waveprotocol.wave.model.operation.OperationRuntimeException; -import org.waveprotocol.wave.model.operation.SilentOperationSink; - -/** - * Connects a data object with operation sinks that make it live. - * - * @param <T> type to which operations apply - * @param <O> operation type - */ -public final class LiveTarget<T, O extends Operation<? super T>> { - /** Target data object. */ - private final T target; - - /** Sink that executes consumed operations. */ - private final SilentOperationSink<O> executor; - - /** Output sink for outgoing operations. */ - private final ProxyOperationSink<O> output; - - /** - * Creates a live-target triple. - */ - private LiveTarget(T target, SilentOperationSink<O> executor, ProxyOperationSink<O> output) { - this.target = target; - this.executor = executor; - this.output = output; - } - - /** - * Creates a live-target. - */ - public static <T, O extends Operation<? super T>> LiveTarget<T, O> create(final T data) { - ProxyOperationSink<O> output = ProxyOperationSink.create(); - SilentOperationSink<O> executor = new SilentOperationSink<O>() { - @Override - public void consume(O operation) { - try { - operation.apply(data); - } catch (OperationException e) { - // Fail this object permanently - throw new OperationRuntimeException("Error applying op", e); - } - } - }; - return new LiveTarget<T, O>(data, executor, output); - } - - /** @return the target object being controlled by operations. */ - public T getTarget() { - return target; - } - - /** @return the sink that executes operations on the target. */ - public SilentOperationSink<O> getExecutorSink() { - return executor; - } - - /** @return the sink to which operations from the target are sent. */ - public ProxyOperationSink<O> getOutputSink() { - return output; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/MuxConnector.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/MuxConnector.java b/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/MuxConnector.java deleted file mode 100644 index b6bee3d..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/MuxConnector.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.waveprotocol.wave.client.concurrencycontrol; - -import com.google.gwt.user.client.Command; - -import org.waveprotocol.wave.concurrencycontrol.channel.OperationChannelMultiplexer; - -/** - * Makes the operation channels in a {@link OperationChannelMultiplexer} go - * live. - * - */ -public interface MuxConnector { - /** - * Opens the underlying view channel, and connects the live operation channels - * with those in the mux. - * - * @param onOpened command executed once the channel is open. This feature is - * historical, and will be removed once the canonical client/server - * protocol is updated. Please do not rely on it. - */ - void connect(Command onOpened); - - /** - * Closes the underlying view channel. - */ - void close(); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/ProxyOperationSink.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/ProxyOperationSink.java b/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/ProxyOperationSink.java deleted file mode 100644 index 8fe0431..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/ProxyOperationSink.java +++ /dev/null @@ -1,84 +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.waveprotocol.wave.client.concurrencycontrol; - -import com.google.common.base.Preconditions; - -import org.waveprotocol.wave.model.operation.Operation; -import org.waveprotocol.wave.model.operation.SilentOperationSink; -import org.waveprotocol.wave.model.util.CollectionUtils; - -import java.util.Queue; - -/** - * A sink that proxies for another sink. This sink is usable immediately after - * construction. Operations that are consumed before the target sink is set are - * simply queued. Setting the target sink flushes any operations that have been - * queued. The target can be set only once, and after it is set, this sink - * routes all operations to it. - * - */ -public final class ProxyOperationSink<O extends Operation<?>> implements SilentOperationSink<O> { - - private Queue<O> queue; - private SilentOperationSink<O> target; - - private ProxyOperationSink() { - } - - /** - * Creates a proxy sink. - */ - public static <O extends Operation<?>> ProxyOperationSink<O> create() { - return new ProxyOperationSink<O>(); - } - - /** - * Sets this proxy's target. Any operations previously consumed by this proxy - * will be forwarded to the target synchronously within this method. Future - * operations consumed by this proxy will be sent directly to the target. This - * target can be set at most once. - * - * @param target target to consume future operations - */ - public void setTarget(SilentOperationSink<O> target) { - Preconditions.checkState(this.target == null); - this.target = target; - - if (queue != null) { - while (!queue.isEmpty()) { - target.consume(queue.poll()); - } - queue = null; - } - } - - @Override - public void consume(O op) { - if (target != null) { - target.consume(op); - } else { - if (queue == null) { - queue = CollectionUtils.createQueue(); - } - queue.add(op); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/StaticChannelBinder.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/StaticChannelBinder.java b/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/StaticChannelBinder.java deleted file mode 100644 index 67fb402..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/StaticChannelBinder.java +++ /dev/null @@ -1,112 +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.waveprotocol.wave.client.concurrencycontrol; - -import org.waveprotocol.wave.client.wave.WaveDocuments; -import org.waveprotocol.wave.concurrencycontrol.channel.OperationChannel; -import org.waveprotocol.wave.concurrencycontrol.common.ChannelException; -import org.waveprotocol.wave.concurrencycontrol.wave.CcDocument; -import org.waveprotocol.wave.concurrencycontrol.wave.FlushingOperationSink; -import org.waveprotocol.wave.concurrencycontrol.wave.OperationSucker; -import org.waveprotocol.wave.model.operation.SilentOperationSink; -import org.waveprotocol.wave.model.operation.wave.WaveletBlipOperation; -import org.waveprotocol.wave.model.operation.wave.WaveletOperation; -import org.waveprotocol.wave.model.util.Pair; - -/** - * Binds a wave's wavelets with supplied operation channels. - * - * @author [email protected] (David Hearnden) - */ -public final class StaticChannelBinder { - - private final WaveletOperationalizer operationalizer; - private final WaveDocuments<? extends CcDocument> docRegistry; - - /** - * Creates a binder for a wave. - * - * @param operationalizer operationalizer of the wave - * @param docRegistry document registry of the wave - */ - public StaticChannelBinder( - WaveletOperationalizer operationalizer, WaveDocuments<? extends CcDocument> docRegistry) { - this.operationalizer = operationalizer; - this.docRegistry = docRegistry; - } - - /** - * Connects a wavelet's operation sinks with an operation channel. - * - * @param id id of the wavelet to bind - * @param channel channel to bind - */ - public void bind(String id, OperationChannel channel) { - Pair<SilentOperationSink<WaveletOperation>, ProxyOperationSink<WaveletOperation>> sinks = - operationalizer.getSinks(id); - - // Bind the two ends together. - OperationSucker.start(channel, asFlushing(id, sinks.first)); - sinks.second.setTarget(asOpSink(channel)); - } - - /** - * Adapts a regular operation sink as a flushing sink. - */ - private FlushingOperationSink<WaveletOperation> asFlushing( - final String waveletId, final SilentOperationSink<WaveletOperation> target) { - return new FlushingOperationSink<WaveletOperation>() { - @Override - public void consume(WaveletOperation op) { - target.consume(op); - } - - @Override - public boolean flush(WaveletOperation op, Runnable c) { - if (op instanceof WaveletBlipOperation) { - CcDocument doc = - docRegistry.getBlipDocument(waveletId, ((WaveletBlipOperation) op).getBlipId()); - if (doc != null) { - return doc.flush(c); - } - } - return true; - } - }; - } - - /** - * Adapts an operation channel, making it look like an operation sink. The - * only reason a channel is not already a sink is because it has a more - * general acceptor that takes a varargs parameter. - */ - private static SilentOperationSink<WaveletOperation> asOpSink(final OperationChannel target) { - return new SilentOperationSink<WaveletOperation>() { - @Override - public void consume(WaveletOperation op) { - try { - target.send(op); - } catch (ChannelException e) { - throw new RuntimeException("Send failed, channel is broken", e); - } - } - }; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/WaveletOperationalizer.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/WaveletOperationalizer.java b/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/WaveletOperationalizer.java deleted file mode 100644 index a240b2b..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/concurrencycontrol/WaveletOperationalizer.java +++ /dev/null @@ -1,129 +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.waveprotocol.wave.client.concurrencycontrol; - -import com.google.common.base.Preconditions; - -import org.waveprotocol.wave.model.id.ModernIdSerialiser; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.operation.SilentOperationSink; -import org.waveprotocol.wave.model.operation.wave.BasicWaveletOperationContextFactory; -import org.waveprotocol.wave.model.operation.wave.WaveletOperation; -import org.waveprotocol.wave.model.operation.wave.WaveletOperationContext; -import org.waveprotocol.wave.model.operation.wave.WaveletOperationContext.Factory; -import org.waveprotocol.wave.model.util.CollectionUtils; -import org.waveprotocol.wave.model.util.Pair; -import org.waveprotocol.wave.model.util.ReadableStringMap.ProcV; -import org.waveprotocol.wave.model.util.StringMap; -import org.waveprotocol.wave.model.wave.ParticipantId; -import org.waveprotocol.wave.model.wave.ParticipationHelper; -import org.waveprotocol.wave.model.wave.data.ObservableWaveletData; -import org.waveprotocol.wave.model.wave.opbased.OpBasedWavelet; - -import java.util.Collection; - -/** - * Makes passive wavelet objects ({@link ObservableWaveletData}) operational, - * turning them into mutable wavelet objects {@link OpBasedWavelet} backed by - * operation sinks. - * - */ -public final class WaveletOperationalizer { - - private final WaveId waveId; - private final StringMap<LiveTarget<ObservableWaveletData, WaveletOperation>> wavelets = - CollectionUtils.createStringMap(); - private final WaveletOperationContext.Factory opContextFactory; - - private WaveletOperationalizer(WaveId waveId, Factory opContextFactory) { - this.waveId = waveId; - this.opContextFactory = opContextFactory; - } - - /** - * Creates an operationalizer. - */ - public static WaveletOperationalizer create(WaveId wave, ParticipantId user) { - WaveletOperationContext.Factory opContexts = new BasicWaveletOperationContextFactory(user); - return new WaveletOperationalizer(wave, opContexts); - } - - /** - * Turns a passive wavelet into a mutable wavelet, under the control of - * operations. - * <p> - * Note that this does not connect the wavelet with concurrency control, which - * means that local mutations will not be sent out anywhere, and remote - * mutations will not be routed to this wavelet. Additional work needs to be - * done for that (see {@link LiveChannelBinder} for that); this method merely - * associates the passive data wavelet with operation sinks that make it - * locally mutable. It is safe to mutate the returned wavelet before binding - * it with an operation channel; local mutations that occur before binding are - * queued until bound. - * - * @param data data object for the wavelet - * @return mutable operation-backed wavelet. - */ - public OpBasedWavelet operationalize(ObservableWaveletData data) { - LiveTarget<ObservableWaveletData, WaveletOperation> target = createSinks(data); - return new OpBasedWavelet(waveId, - data, - opContextFactory, - ParticipationHelper.DEFAULT, - target.getExecutorSink(), - target.getOutputSink()); - } - - /** @return all the operation-controlled targets in this wave. */ - public Collection<ObservableWaveletData> getWavelets() { - final Collection<ObservableWaveletData> targets = CollectionUtils.createQueue(); - this.wavelets.each(new ProcV<LiveTarget<ObservableWaveletData, WaveletOperation>>() { - @Override - public void apply(String id, LiveTarget<ObservableWaveletData, WaveletOperation> triple) { - targets.add(triple.getTarget()); - } - }); - return targets; - } - - /** @return the input and output sinks for a particular wavelet. */ - public Pair<SilentOperationSink<WaveletOperation>, ProxyOperationSink<WaveletOperation>> getSinks( - String waveletId) { - LiveTarget<ObservableWaveletData, WaveletOperation> target = wavelets.get(waveletId); - return Pair.of(target.getExecutorSink(), target.getOutputSink()); - } - - /** - * Creates a liveness triple for a data object, storing the triple in a map. - */ - private LiveTarget<ObservableWaveletData, WaveletOperation> createSinks( - ObservableWaveletData data) { - return putAndReturn(wavelets, - ModernIdSerialiser.INSTANCE.serialiseWaveletId(data.getWaveletId()), - LiveTarget.<ObservableWaveletData, WaveletOperation>create(data)); - } - - // Saves a bit of typing... - private static <V> V putAndReturn(StringMap<V> map, String key, V value) { - Preconditions.checkState(!map.containsKey(key)); - map.put(key, value); - return value; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/BufferedLogger.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/BufferedLogger.java b/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/BufferedLogger.java deleted file mode 100644 index 8f2a529..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/BufferedLogger.java +++ /dev/null @@ -1,104 +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.waveprotocol.wave.client.debug.logger; - -import com.google.gwt.user.client.Command; -import com.google.gwt.user.client.DeferredCommand; - -import org.waveprotocol.wave.common.logging.LogSink; -import org.waveprotocol.wave.common.logging.LogUtils; - -import java.util.ArrayList; -import java.util.List; - -/** - * Logger that buffers messages and only outputs to DOM on a deferred command. - * - * Logging to the DOM can be slow and can also interfere with other browser - * operations. Use this logger to buffer messages and only output to DOM on a - * deferred command. Note, when invocations to a buffered logger is interleaved - * with invocations to a normal logger, output to the buffered logger will - * always appear last. - * - */ -public class BufferedLogger extends DomLogger { - private static final class BufferedLogSink extends LogSink { - private static final class LogMessage { - private final Object message; - private final Level level; - LogMessage(Object message, Level level) { - this.message = message; - this.level = level; - } - - void logToSink(LogSink logSink) { - logSink.log(level, LogUtils.stringifyLogObject(message)); - } - } - - /** - * Buffer for log messages. - */ - private final List<LogMessage> buffer = new ArrayList<LogMessage>(); - private final LogSink outputSink; - - BufferedLogSink(LogSink outputSink) { - this.outputSink = outputSink; - } - - /** - * Flush contents of buffer to output. - */ - private final Command flush = new Command() { - public void execute() { - for (LogMessage m : buffer) { - m.logToSink(outputSink); - } - buffer.clear(); - } - }; - - @Override - public void log(Level level, String msg) { - lazyLog(level, msg); - } - - @Override - public void lazyLog(Level level, Object... messages) { - // NOTE(user): It is best to assume that DeferredCommand can execute - // immediately. - // NOTE(danilatos): We use DeferredCommand rather than - // org.waveprotocol.wave.Scheduler, so that we can log in - // the Scheduler implementations. - boolean doFlush = buffer.isEmpty(); - buffer.add(new LogMessage(messages, level)); - if (doFlush) { - DeferredCommand.addCommand(flush); - } - } - } - - /** - * @param module - */ - public BufferedLogger(String module) { - super(module, new BufferedLogSink(new GWTLogSink(module))); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/DomLogger.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/DomLogger.java b/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/DomLogger.java deleted file mode 100644 index 5cf0fa5..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/DomLogger.java +++ /dev/null @@ -1,774 +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.waveprotocol.wave.client.debug.logger; - -import com.google.gwt.core.client.Duration; -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.DivElement; -import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.StyleInjector; -import com.google.gwt.i18n.client.NumberFormat; -import com.google.gwt.resources.client.ClientBundle; -import com.google.gwt.resources.client.CssResource; -import com.google.gwt.user.client.Cookies; - -import org.waveprotocol.wave.client.common.util.DomHelper; -import org.waveprotocol.wave.common.logging.AbstractLogger; -import org.waveprotocol.wave.common.logging.AbstractLogger.NonNotifyingLogger; -import org.waveprotocol.wave.common.logging.InMemoryLogSink; -import org.waveprotocol.wave.common.logging.LogSink; -import org.waveprotocol.wave.common.logging.LogUtils; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -/** - * - * Debug logger - */ -public class DomLogger extends AbstractLogger implements NonNotifyingLogger { - public static final String WEBDRIVER_GET_FATAL_ERROR_HOOK_NAME = "webdriverGetFatalError"; - - public interface Resources extends ClientBundle { - /** CSS class names used by Logger. These are used in Logger.css */ - interface Css extends CssResource { - String panel(); - String entry(); - String module(); - String error(); - String fatal(); - String trace(); - String time(); - String msg(); - } - - @Source("Logger.css") - Css css(); - } - - /** This class is to be injected that decides on how to handle errors. */ - public interface ErrorHandler { - void handleClientErrors(Level level, Throwable t, Object... messages); - } - - /** - * @return content of the latest fatal error message if any. - */ - @SuppressWarnings("unused") // NOTE(user): Used by nativeSetupWebDriverTestPins() - static String webdriverGetFatalError() { - return DomLogger.latestFatalError; - } - - private static native void nativeSetupWebDriverTestPins(String hookName) /*-{ - $wnd[hookName] = function() { - return @org.waveprotocol.wave.client.debug.logger.DomLogger::webdriverGetFatalError()(); - } - }-*/; - - /** - * This is exclusively for Webdriver purpose. - * It stores the content of the latest fatal error message if any. - */ - private static String latestFatalError = ""; - - static { - // TODO(user): prevent exposing this hook if not in ll=debug mode. - // Surprisingly doing a LogLevel.showDebug() at this location always returns false. - if (GWT.isClient()) { - DomLogger.nativeSetupWebDriverTestPins(WEBDRIVER_GET_FATAL_ERROR_HOOK_NAME); - } - } - - /** The singleton instance of handler error messages. */ - private static ErrorHandler errorHandler = null; - - /** Whether we should log to console instead of the dom for efficiency purposes. */ - private static boolean enableConsoleLogging = false; - - /** The singleton instance of our resources. */ - private static Resources RESOURCES = null; - - /** - * Element the Logger will append log entries to. No logging - * will take place when outputElm = null; - */ - private static Element outputElm = null; - - /** - * All log modules - */ - private static Set<String> modules = new TreeSet<String>(); - - /** - * Modules to log to buffer. - */ - private static HashSet<String> enabledModulesBuffer = new HashSet<String>(); - - /** - * In memory log buffer. - */ - public static InMemoryLogSink logbuffer = new InMemoryLogSink(); - - /** - * Enabled log modules - */ - private static HashSet<String> enabledModules = new HashSet<String>(); - - private static ArrayList<LoggerListener> listeners = new ArrayList<LoggerListener>(); - - /** - * Only Logger's with level below this static will log - */ - private static int maxLevel = Level.TRACE.value(); - - /** - * Cookie name - */ - private static final String COOKIE_DEBUGLOG_MODULES = "wdm"; - - static { - if (GWT.isClient()) { - RESOURCES = GWT.create(Resources.class); - // Inject the CSS once. - StyleInjector.inject(RESOURCES.css().getText()); - // NOTE(user): GWT.create fails if called outside GWTTestCase or the actual client. - - // Get enabled log modules from cookie - String cookie = Cookies.getCookie(COOKIE_DEBUGLOG_MODULES); - if (cookie != null) { - String[] cookies = cookie.split("\\|"); - for (int i = 1; i < cookies.length; i++) { - enabledModules.add(cookies[i]); - } - } - } - } - - /** Sets the handler for error messages. This must be set before any errors can be handled. */ - public static void setErrorHandler(ErrorHandler handler) { - errorHandler = handler; - } - - /** Sets whether we should use console logging */ - public static void setEnableConsoleLogging(boolean enable) { - enableConsoleLogging = enable; - } - - - /** - * Sets a cookie value with an expiry date a year from now. - * @param key The name of the cookie to set. - * @param value The new value for the cookie. - */ - @SuppressWarnings("deprecation") // Calendar not supported by GWT - public static void setCookieValue(String key, String value) { - // Only set the cookie value if it is changing: - if (value.equals(Cookies.getCookie(key))) { - return; - } - - // Set the cookie to expire in one year - Date d = new Date(); - d.setYear(d.getYear() + 1); - Cookies.setCookie(key, value, d); - } - - /** - * The Logger's module name - */ - private final String module; - - /** - * Sets the listener that is interested in logger events. - */ - public static void addLoggerListener(LoggerListener listener) { - DomLogger.listeners.add(listener); - } - - /** - * Removes the listener that is interested in logger events. - */ - public static void removeLoggerListener(LoggerListener listener) { - DomLogger.listeners.remove(listener); - } - - private void triggerOnNewLogger(String loggerName) { - for (LoggerListener l : listeners) { - l.onNewLogger(loggerName); - } - } - - /** - * Enables all logging (although logging is still subject to module - * and max-level disabling) - * - * @param outputElm The Element to which Logger will - * appendChild log entries - */ - public static void enable(Element outputElm) { - DomLogger.outputElm = outputElm; - if (RESOURCES != null) { - outputElm.addClassName(RESOURCES.css().panel()); - } - if (shouldLogToConsole()) { - appendEntry("Your debug output has been logged to the console. " + - "In firefox it is logged to FireBug's console. " + - "In Safari it is logged to the error console.", Level.ERROR); - } - maybeClearOutputCache(); - } - - /** - * @return whether we should log to the brower's console - */ - private static boolean shouldLogToConsole() { - return enableConsoleLogging && consoleLoggingAvailable(); - } - - @Override - public boolean isModuleEnabled() { - return isModuleEnabled(module); - } - - /** - * Disables all logging (but remembers module and level disabling) - */ - public static void disable() { - DomLogger.outputElm = null; - } - - /** - * Set Loggers' maximum logging level - * - * @param maxLevel Only Loggers with value below this will log - */ - public static void setMaxLevel(Level maxLevel) { - DomLogger.maxLevel = maxLevel.value(); - } - - /** - * Constructs a logger with the default log sink. - * @param module - */ - public DomLogger(String module) { - this(module, new GWTLogSink(module)); - } - - /** - * Constructs a Logger - * - * @param module Module string. Log entries will be prefixed with this string; and - * logging can be enabled/disabled per-module. Loggers may share module string. - */ - public DomLogger(String module, LogSink logSink) { - super(logSink); - if (!modules.contains(module)) { - modules.add(module); - triggerOnNewLogger(module); - } - this.module = module; - if (GWT.isClient()) { - setupNativeLogging(module); - } - } - - /** - * A static log method for calling by JSNI methods, see {@link #setupNativeLogging(String)} - * @param module - * - * @param msg - */ - @SuppressWarnings("unused") - private static void nativeLog(String module, String msg) { - new DomLogger(module).trace().log(msg); - } - - /** - * A static logXml method for calling by JSNI methods, see {@link #setupNativeLogging(String)} - * - * @param module - * @param xml - */ - @SuppressWarnings("unused") - private static void nativeLogXml(String module, String xml) { - new DomLogger(module).trace().logXml(xml); - } - - /** - * A static log method for calling by JSNI methods, see {@link #setupNativeLogging(String)} - * - * @param module - * @param label - * @param javaObject - */ - @SuppressWarnings("unused") - private static void nativeLog(String module, String label, Object javaObject) { - new DomLogger(module).trace().log(label, javaObject); - } - - /** - * Setup a few native methods for logging. Lets JSNI method call <module>Log(msg), - * <module>LogXMl(xml), <module>LogJava(javaObject), and <module>LogObject(object). - * NB: this puts limitations on logging module names. E.g., 'drag-drop' is outlawed, - * as drag-dropLog would not be a legal function name. - * - * @param module - */ - private native void setupNativeLogging(String module) /*-{ - if (typeof window[module + "Log"] == "undefined") { - window[module + "Log"] = function(msg) { - @org.waveprotocol.wave.client.debug.logger.DomLogger::nativeLog(Ljava/lang/String;Ljava/lang/String;) - (module, msg); - } - window[module + "LogXml"] = function(xml) { - @org.waveprotocol.wave.client.debug.logger.DomLogger::nativeLogXml(Ljava/lang/String;Ljava/lang/String;) - (module, xml); - } - window[module + "LogJava"] = function(label, javaObject) { - @org.waveprotocol.wave.client.debug.logger.DomLogger::nativeLog(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;) - (module, label, javaObject); - } - window[module + "LogObject"] = function(object) { - var msg = ''; - for (a in object) { - msg += a + ': ' + object[a] + '<br/>'; - } - @org.waveprotocol.wave.client.debug.logger.DomLogger::nativeLog(Ljava/lang/String;Ljava/lang/String;) - (module, msg); - } - } - }-*/; - - /** - * Toggles whether this logger's module is enabled/disabled - */ - public void toggleModule() { - toggleModule(module); - } - - /** - * Toggles whether a module is enabled/disabled - * - * @param module - */ - public static void toggleModule(String module) { - enableModule(module, !isModuleEnabled(module)); - } - - /** - * Enables/disables this logger's module - * - * @param enable True if this logger's module should be enabled; - * false otherwise - */ - public void enableModule(boolean enable) { - enableModule(module, enable); - } - - /** - * Enables/disables buffer for this log's module - * - * @param enable True if module should be enabled; false otherwise - */ - public void enableModuleBuffer(boolean enable) { - enableModuleBuffer(module, enable); - } - - /** - * Enables/disables log module - * - * @param module - * @param enable True if module should be enabled; false otherwise - */ - public static void enableModule(String module, boolean enable) { - if (enable) { - enabledModules.add(module); - } else { - enabledModules.remove(module); - } - persistEnabledModules(); - } - - /** - * Enables/disables buffer for log module - * - * @param module - * @param enable True if module should be enabled; false otherwise - */ - public static void enableModuleBuffer(String module, boolean enable) { - if (enable) { - enabledModulesBuffer.add(module); - } else { - enabledModulesBuffer.remove(module); - } - } - - /** - * Enables all (known) modules - */ - public static void enableAllModules() { - enabledModules.addAll(modules); - } - - /** - * Disables all modules - */ - public static void disableAllModules() { - enabledModules.clear(); - } - - /** - * @param module - * @return True if module is enabled. - */ - public static boolean isModuleEnabled(String module) { - return enabledModules.contains(module); - } - - /** - * @return True if the module is enabled and global logging is enabled. - */ - public boolean isModuleLoggingEnabled() { - return isModuleEnabled(module); - } - - /** - * Persists enabled module names in cookie - */ - private static void persistEnabledModules() { - String cookie = "|"; - for (String s : enabledModules) { - cookie += s + "|"; - } - try { - setCookieValue(COOKIE_DEBUGLOG_MODULES, cookie); - } catch (Error ignoreOutsideGWT) { - // NOTE(user): this fails with an UnsatisfiedLinkError when - // running tests outside GWTTestCase, it's not required for the client to - // function so this makes it more robust, I should catch - // UnsatisfiedLinkError but that class is not available in GWT - } - } - - /** - * @return All modules - */ - public static Collection<String> getModules() { - return modules; - } - - /** - * Turns attribute of element into string suitable for human consumption - * - * @param e - * @param attr - * @return String rendering of attribute - */ - private static String attr(Element e, String attr) { - String a = e.getAttribute(attr); - return a == null ? "" : " " + attr + "='" + a + "'"; - } - - /** - * Shortens a string to 10 chars by adding '...' - * - * @param in - * @return Shortened version of in - */ - private static String shortString(String in) { - return in.length() <= 10 ? in : in.substring(0, 9) + "..."; - } - - /** - * Outputs debug-string representing a DOM element - * - * @param e - * @return XML rendering of element - */ - @SuppressWarnings("unused") - private static String toXml(Element e) { - String out = ""; - if (DomHelper.isTextNode(e)) { - out = "'" + shortString(e.getNodeValue()) + "'"; - } else { - String tagName = e.getTagName(); - out = "<" + tagName; - if (tagName.equals("INPUT")) { - out += attr(e, "type"); - out += attr(e, "value"); - } - out += attr(e, "class"); - if (tagName.equals("A")) { - out += ">" + e.getInnerText() + "</A>"; - } else { - out += "/>"; - } - } - return out; - } - - private static boolean shouldLogToBuffer(String module, Level level) { - // Buffer all error messages. - return enabledModulesBuffer.contains(module) || level.value() <= Level.ERROR.value(); - } - - private static boolean shouldLogToPanel(String module, Level level) { - // Always log fatal messages. - if (level.value() == Level.FATAL.value()) { - return true; - } - - return outputElm != null && enabledModules.contains(module) && - level.value() <= maxLevel; - } - - /** - * {@inheritDoc} - * - * @return If Logger should log based on module, level and - * whether logging system is enabled - */ - @Override - protected boolean shouldLog(Level level) { - // For production and unit-tests, don't log full stack traces: - // NOTE(user): LogLevel.showErrors() indirectly causes a GWT.create, so - // guard by GWT.isClient(). - boolean shouldShowErrorDetail = GWT.isClient() && LogLevel.showErrors(); - - // Only log in client/GWTTestCases when logging is not disabled. - return shouldShowErrorDetail - && (shouldLogToBuffer(module, level) || shouldLogToPanel(module, level)); - } - - /** - * Formats a log entry. - * @param module - * @param msg - * @param timestamp - */ - public static String formatLogEntry(String module, String msg, String timestamp) { - return "<span class='" + RESOURCES.css().module() + "'>" + module + "</span> " - + "<span class='" + RESOURCES.css().time() + "'>(" + timeStamp() + "):</span> " - + "<span class='" + RESOURCES.css().msg() + "'>" + msg + "</span>"; - } - - /** - * Appends an entry to the log panel. - * @param formatted - * @param level - */ - public static void appendEntry(String formatted, Level level) { - DivElement entry = Document.get().createDivElement(); - entry.setClassName(RESOURCES.css().entry()); - entry.setInnerHTML(formatted); - - // Add the style name associated with the log level. - switch (level) { - case ERROR: - entry.addClassName(RESOURCES.css().error()); - break; - case FATAL: - entry.addClassName(RESOURCES.css().fatal()); - break; - case TRACE: - entry.addClassName(RESOURCES.css().trace()); - break; - } - - // Make fatals detectable by WebDriver, so that tests can early out on - // failure: - if (level.equals(Level.FATAL)) { - latestFatalError = formatted; - } - writeOrCacheOutput(entry); - } - - /** List of output divs waiting to be written to the log panel. */ - private static List<DivElement> outputCache = new ArrayList<DivElement>(); - - /** Write output or cache it if the output element is not set. */ - private static void writeOrCacheOutput(DivElement element) { - outputCache.add(element); - maybeClearOutputCache(); - } - - /** Clear the output cache if the output element is set. */ - private static void maybeClearOutputCache() { - if (outputElm != null) { - for (DivElement e : outputCache) { - outputElm.appendChild(e); - } - outputCache.clear(); - outputElm.setScrollTop(1000000); - } - } - - @Override - protected void logPlainTextInner(Level level, String msg) { - // if we are not logging to console, we want to escape. - if (!shouldLogToConsole()) { - super.logPlainTextInner(level, msg); - } else { - doLog(level, msg); - } - } - - @Override - public void logWithoutNotifying(String message, Level level) { - assert this.sink instanceof GWTLogSink : - "we pass a GWTLogSink in the constructor so this cast should always be safe"; - ((GWTLogSink) this.sink).writeLog(message, level); - } - - private static void notifyLoggerListenersIfErrorOrFatal(Level level) { - if (level == Level.ERROR) { - for (LoggerListener l : listeners) { - l.onError(); - } - } else if (level == Level.FATAL) { - for (LoggerListener l : listeners) { - l.onFatal(); - } - } - } - - /** - * Log output sink to Debug panel. - */ - public static final class GWTLogSink extends LogSink { - private final String module; - - public GWTLogSink(String module) { - this.module = module; - } - - @Override - public void log(Level level, String message) { - lazyLog(level, message); - } - - @Override - public void lazyLog(Level level, Object... messages) { - String formatted = ""; - boolean shouldLogToBuffer = shouldLogToBuffer(module, level); - boolean shouldLogToPanel = shouldLogToPanel(module, level); - if (shouldLogToBuffer) { - logbuffer.lazyLog(level, messages); - } - if (shouldLogToPanel) { - formatted = formatLogEntry(module, LogUtils.stringifyLogObject(messages), timeStamp()); - if (shouldLogToConsole()) { - // bring up the panel to notify the user that there is something to show. - if (level == Level.FATAL) { - showOutput(); - } - String t = module + " (" + timeStamp() + "): " + formatted; - logToConsole(t); - } else { - logToPanel(formatted, level); - } - } - - notifyLoggerListenersIfErrorOrFatal(level); - } - - /** - * Write log without invoking listeners. - */ - private void writeLog(String msg, Level level) { - String formatted = ""; - boolean shouldLogToBuffer = shouldLogToBuffer(module, level); - boolean shouldLogToPanel = shouldLogToPanel(module, level); - if (shouldLogToBuffer || shouldLogToPanel) { - formatted = formatLogEntry(module, msg, timeStamp()); - } - if (shouldLogToBuffer) { - logbuffer.log(level, formatted); - } - if (shouldLogToPanel) { - if (shouldLogToConsole()) { - logToConsole(formatted); - } else { - logToPanel(formatted, level); - } - } - } - - private void logToPanel(String formatted, Level level) { - showOutput(); - appendEntry(formatted, level); - } - } - - static final NumberFormat TIMESTAMP_FORMAT = (GWT.isClient() ? - NumberFormat.getFormat("0000000000.000") : null); - - /** - * @return Timestamp for use in log - */ - private static String timeStamp() { - double ts = Duration.currentTimeMillis() / 1000.0; - // divide the startTime to second from millsecond and seconds is much easier to read - // for the user. - if (TIMESTAMP_FORMAT != null) { - return TIMESTAMP_FORMAT.format(ts); - } else { - return Double.toString(ts); - } - } - - /** - * Trigger onNeedOutput on all listeners. - */ - public static void showOutput() { - for (LoggerListener l : listeners) { - l.onNeedOutput(); - } - } - - @Override - protected void handleClientErrors(Level level, Throwable t, Object... messages) { - if (errorHandler != null) { - errorHandler.handleClientErrors(level, t, messages); - } - } - - public static native void logToConsole(String msg) /*-{ - var log = $wnd.console; - if (log) { - if (log.markTimeline) { - log.markTimeline(msg); - } - if (log.log) { - log.log(msg); - } - } - }-*/; - - public static native boolean consoleLoggingAvailable() /*-{ - return !!($wnd.console); - }-*/; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/LogLevel.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/LogLevel.java b/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/LogLevel.java deleted file mode 100644 index 4443ab9..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/LogLevel.java +++ /dev/null @@ -1,97 +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.waveprotocol.wave.client.debug.logger; - -import com.google.gwt.core.client.GWT; - -/** - * LogLevel defines an ordered list of logging levels.<br/> - * - * <pre>NONE < ERROR < DEBUG</pre> - * - * Deferred-binding property "loglevel" determines at which level the system - * is logging, allowing for unused code to be compiled out in production. - * - * e.g. anything logged at level DEBUG will only be logged when the - * "loglevel" deferred-binding property is set to "debug". - * If "loglevel" is "none", nothing should be logged. - * - */ -// TODO(user): Consider rather using the GWT logging API throughout: -// http://code.google.com/p/google-web-toolkit-incubator/wiki/Logging -public abstract class LogLevel { - private static final LogLevel INSTANCE = GWT.isClient() - ? GWT.<LogLevel>create(LogLevel.class) : new ErrorImpl(); - - // NOTE(user): LogLevel must *not* have a clinit method (i.e. any static - // initialisation code), otherwise each inlining of shouldX() - // will call the clinit. - - // NOTE(user): This class is not an enum, as GWT (as of 21 Jan 2009) does not - // do object identity tracking, even for enums. - // Hence the comparisons against the enum values do not get - // inlined (which is an essential goal of the "#ifdef" style - // methods below). - - /** - * Should an entry with level ERROR be logged? - */ - public static boolean showErrors() { - return INSTANCE.showErrorsInstance(); - } - - /** - * Should an entry with level DEBUG be logged? - */ - public static boolean showDebug() { - return INSTANCE.showDebugInstance(); - } - - // Intended for overriding per-implementation: - protected abstract boolean showErrorsInstance(); - protected abstract boolean showDebugInstance(); - - /** - * Deferred-binding replacement for LogLevel used for production. - */ - @SuppressWarnings("unused") // NOTE(user): Created via deferred binding - private static class NoneImpl extends LogLevel { - @Override protected boolean showErrorsInstance() { return false; } - @Override protected boolean showDebugInstance() { return false; } - } - - /** - * Deferred-binding replacement for LogLevel used for logging errors. - */ - @SuppressWarnings("unused") // NOTE(user): Created via deferred binding - private static class ErrorImpl extends LogLevel { - @Override protected boolean showErrorsInstance() { return true; } - @Override protected boolean showDebugInstance() { return false; } - } - - /** - * Deferred-binding replacement for LogLevel used for debugging errors. - */ - @SuppressWarnings("unused") // NOTE(user): Created via deferred binding - private static class DebugImpl extends LogLevel { - @Override protected boolean showErrorsInstance() { return true; } - @Override protected boolean showDebugInstance() { return true; } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/LoggerListener.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/LoggerListener.java b/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/LoggerListener.java deleted file mode 100644 index 600b422..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/debug/logger/LoggerListener.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.waveprotocol.wave.client.debug.logger; - -/** - * The logger listener that may want to do something when the logger changes. - * @author [email protected] (David) - */ -public interface LoggerListener { - /** - * Call this to notify a new logger of the given name was created. - */ - public void onNewLogger(String loggerName); - - /** - * A logger really wants to log something but the output is not yet given to it. - */ - public void onNeedOutput(); - - /** - * Notify listeners that an error log message has been triggered. - */ - public void onError(); - - /** - * Notify listeners that a fatal log message has been triggered. - */ - public void onFatal(); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/doodad/DoodadInstallers.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/doodad/DoodadInstallers.java b/wave/src/main/java/org/waveprotocol/wave/client/doodad/DoodadInstallers.java deleted file mode 100644 index db52ff0..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/doodad/DoodadInstallers.java +++ /dev/null @@ -1,60 +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.waveprotocol.wave.client.doodad; - -import org.waveprotocol.wave.client.editor.content.Registries; -import org.waveprotocol.wave.model.conversation.Conversation; -import org.waveprotocol.wave.model.conversation.ConversationBlip; -import org.waveprotocol.wave.model.wave.Wavelet; - -/** - * Defines the type namespace for doodad installers. - * - */ -public final class DoodadInstallers { - - // - // This class is merely used as a namespace; no instances are intended. - // - - private DoodadInstallers() { - } - - /** - * Installer for a context-free doodad handler. - */ - public interface GlobalInstaller { - void install(Registries r); - } - - /** - * Installer for a per-conversation doodad handler. - */ - public interface ConversationInstaller { - void install(Wavelet w, Conversation c, Registries r); - } - - /** - * Installer for a per-blip doodad handler. - */ - public interface BlipInstaller { - void install(Wavelet w, Conversation c, ConversationBlip b, Registries r); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/wave/client/doodad/attachment/AttachmentConstants.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/wave/client/doodad/attachment/AttachmentConstants.java b/wave/src/main/java/org/waveprotocol/wave/client/doodad/attachment/AttachmentConstants.java deleted file mode 100644 index 344162b..0000000 --- a/wave/src/main/java/org/waveprotocol/wave/client/doodad/attachment/AttachmentConstants.java +++ /dev/null @@ -1,74 +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.waveprotocol.wave.client.doodad.attachment; - -/** - * This class defines attachment-realated constants shared between the servers - * and client. - * - */ - -public class AttachmentConstants { - private AttachmentConstants() {} - - /** - * Defines the maximum thumbnail height / width in pixels used by the - * thumbnailers on the server side and thumbnail managers on the client - * side. - */ - public static final int MAX_THUMBNAIL_SIZE = 120; - - /** - * Defines the maximum large thumbnail width in pixels. - * - * This is used for the large thumbnails shown by the slideshow viewer and - * when downsampling images while uploading. - */ - public static final int MAX_LARGE_THUMBNAIL_WIDTH = 1024; - - /** - * Defines the maximum large thumbnail height in pixels. - * - * This is used for downsampling large images prior to uploading them. - */ - public static final int MAX_LARGE_THUMBNAIL_HEIGHT = 1024; - - /** - * All blobs larger than this limit are put in the BlobStore. Otherwise they - * are stored in Megastore. This is a compromise between a reasonable max - * for Megastore and a reasonable min for BlobStore. - */ - public static final int MEGASTORE_MAX_BLOB_BYTES = 64 * 1024; // 64 KB - - /** - * Thumbnails larger than this will be rejected. - */ - public static final int MAX_THUMBNAIL_BYTES = MEGASTORE_MAX_BLOB_BYTES; - - /** - * Blobs larger than this will be rejected. - */ - public static final int MAX_BLOB_SIZE_MEGABYTES = 20; - - /** - * Blobs larger than this will be rejected. - */ - public static final int MAX_BLOB_SIZE_BYTES = MAX_BLOB_SIZE_MEGABYTES * 1024 * 1024; -}
