http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletProvider.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletProvider.java b/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletProvider.java deleted file mode 100644 index d8dc0ac..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletProvider.java +++ /dev/null @@ -1,133 +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.box.server.waveserver; - -import com.google.common.collect.ImmutableSet; - -import org.waveprotocol.box.common.ExceptionalIterator; -import org.waveprotocol.box.common.Receiver; -import org.waveprotocol.box.server.frontend.CommittedWaveletSnapshot; -import org.waveprotocol.wave.federation.Proto.ProtocolWaveletDelta; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.id.WaveletId; -import org.waveprotocol.wave.model.id.WaveletName; -import org.waveprotocol.wave.model.operation.wave.TransformedWaveletDelta; -import org.waveprotocol.wave.model.version.HashedVersion; -import org.waveprotocol.wave.model.wave.ParticipantId; - -/** - * Provides wavelet snapshots and history, and accepts delta submissions to - * wavelets. - */ -public interface WaveletProvider { - /** - * Receives the result of a delta submission request. - */ - interface SubmitRequestListener { - /** - * Notifies the listener that the delta was successfully applied. - * - * @param operationsApplied number of operations applied - * @param hashedVersionAfterApplication wavelet hashed version after the delta - * @param applicationTimestamp timestamp of delta application - */ - void onSuccess(int operationsApplied, HashedVersion hashedVersionAfterApplication, - long applicationTimestamp); - - /** - * Notifies the listener that the delta failed to apply. - */ - void onFailure(String errorMessage); - } - - /** - * Initializes the provider from storage. No other method is valid until - * initialization is complete. - */ - void initialize() throws WaveServerException; - - /** - * Request that a given delta is submitted to the wavelet. - * - * @param waveletName name of wavelet. - * @param delta to be submitted to the server. - * @param listener callback which will return the result of the submission. - */ - void submitRequest(WaveletName waveletName, ProtocolWaveletDelta delta, - SubmitRequestListener listener); - - /** - * Retrieve the wavelet history of deltas applied to the wavelet. - * - * @param waveletName name of wavelet. - * @param versionStart start version (inclusive), minimum 0. - * @param versionEnd end version (exclusive). - * @param receiver of deltas. - * @throws AccessControlException if {@code versionStart} or - * {@code versionEnd} are not in the wavelet history. - * @throws WaveServerException if storage access fails or if the wavelet is in - * a bad state - */ - void getHistory(WaveletName waveletName, HashedVersion versionStart, HashedVersion versionEnd, - Receiver<TransformedWaveletDelta> receiver) throws WaveServerException; - - /** - * Check if the specified participantId has access to the named wavelet. - * - * @param waveletName name of wavelet. - * @param participantId id of participant attempting to gain access to - * wavelet, or null if the user isn't logged in. - * @return true if the wavelet exists and the participant is a participant on - * the wavelet. - * @throws WaveServerException if storage access fails or if the wavelet is in - * a bad state - */ - boolean checkAccessPermission(WaveletName waveletName, ParticipantId participantId) - throws WaveServerException; - - /** - * Returns an iterator over all waves in the server. - * - * The iterator may or may not include waves created after the iterator is returned. - * - * @return an iterator over the ids of all waves - * @throws WaveServerException if storage access fails - */ - ExceptionalIterator<WaveId, WaveServerException> getWaveIds() throws WaveServerException; - - /** - * Looks up all wavelets in a wave. - * - * @param waveId wave to look up - * @return ids of all non-empty wavelets - * @throws WaveServerException if storage access fails - */ - ImmutableSet<WaveletId> getWaveletIds(WaveId waveId) throws WaveServerException; - - /** - * Request the current state of the wavelet. - * - * @param waveletName the name of the wavelet - * @return the wavelet, or null if the wavelet doesn't exist - * @throws WaveServerException if storage access fails or if the wavelet is in - * a bad state - */ - CommittedWaveletSnapshot getSnapshot(WaveletName waveletName) throws WaveServerException; -}
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletState.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletState.java b/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletState.java deleted file mode 100644 index 85e29ef..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletState.java +++ /dev/null @@ -1,146 +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.box.server.waveserver; - -import com.google.common.util.concurrent.ListenableFuture; -import com.google.protobuf.InvalidProtocolBufferException; -import java.io.IOException; - -import org.waveprotocol.box.common.Receiver; - -import org.waveprotocol.wave.federation.Proto.ProtocolAppliedWaveletDelta; -import org.waveprotocol.wave.model.id.WaveletName; -import org.waveprotocol.wave.model.operation.OperationException; -import org.waveprotocol.wave.model.operation.wave.TransformedWaveletDelta; -import org.waveprotocol.wave.model.version.HashedVersion; -import org.waveprotocol.wave.model.wave.data.ReadableWaveletData; - -/** - * The state of a wavelet, including its delta history. Combines persisted and - * not-yet-persisted delta history. - * - * Implementations of this interface are not thread safe. The callers must - * serialize all calls to an instance of this interface. - * - * @author [email protected] (Soren Lassen) - */ -interface WaveletState { - - /** - * @return The wavelet name. - */ - WaveletName getWaveletName(); - - /** - * @return a snapshot copy of the wavelet state. The snapshot is a reference - * the internal state. - */ - ReadableWaveletData getSnapshot(); - - /** - * @return the current hashed version. - */ - HashedVersion getCurrentVersion(); - - /** - * @return The last persisted hashed version. - */ - HashedVersion getLastPersistedVersion(); - - /** - * @return the hashed version at the given version, if the version is at a - * delta boundary, otherwise null. - */ - HashedVersion getHashedVersion(long version); - - /** - * @return the transformed delta applied at the given version, if it exists, - * otherwise null. - */ - TransformedWaveletDelta getTransformedDelta(HashedVersion beginVersion); - - /** - * @return the transformed delta with the given resulting version, if it - * exists, otherwise null. - */ - TransformedWaveletDelta getTransformedDeltaByEndVersion(HashedVersion endVersion); - - /** - * Gets the transformed deltas from the one applied at the given start version - * until the one resulting in the given end version or receiver will interrupt. - */ - void getTransformedDeltaHistory(HashedVersion startVersion, HashedVersion endVersion, - Receiver<TransformedWaveletDelta> receiver); - - /** - * @return the applied delta applied at the given version, if it exists, - * otherwise null. - */ - ByteStringMessage<ProtocolAppliedWaveletDelta> getAppliedDelta(HashedVersion beginVersion); - - /** - * @return the applied delta with the given resulting version, if it exists, - * otherwise null. - */ - ByteStringMessage<ProtocolAppliedWaveletDelta> getAppliedDeltaByEndVersion( - HashedVersion endVersion); - - /** - * Gets the applied deltas from the one applied at the given start version - * until the one resulting in the given end version or receiver will interrupt. - */ - void getAppliedDeltaHistory( - HashedVersion startVersion, HashedVersion endVersion, - Receiver<ByteStringMessage<ProtocolAppliedWaveletDelta>> receiver); - - /** - * Appends the delta to the in-memory delta history. - * - * <p> - * The caller must make a subsequent call to {@link #persist(HashedVersion)} - * to persist the appended delta. - */ - void appendDelta(WaveletDeltaRecord deltaRecord) - throws InvalidProtocolBufferException, OperationException; - - /** - * Initiates persistence of all in-memory deltas up to the one which - * results in the given version. This call is non-blocking. - * - * <p> - * If the deltas up to the given version are already persisted, this call does - * nothing and returns a future which is already done. - * - * @param version Must be the resulting version of some delta in the delta - * history. - * @return a future which is done when the version is persisted, or the attempt - * to persist fails (in which case the future raises an exception). - */ - ListenableFuture<Void> persist(HashedVersion version); - - /** Flushes persisted delta from memory. */ - void flush(HashedVersion version); - - /** - * Closes the object. No other methods on the object should be invoked after - * this class. - */ - void close() throws IOException; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletStateException.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletStateException.java b/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletStateException.java deleted file mode 100644 index 0460bf8..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletStateException.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.box.server.waveserver; - -/** - * Signals a failure to load a wavelet or an attempt to access a - * wavelet that has failed to load or is corrupted. - */ -public class WaveletStateException extends WaveServerException { - - public WaveletStateException(String message) { - super(message); - } - - public WaveletStateException(String message, Throwable cause) { - super(message, cause); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletStore.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletStore.java b/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletStore.java deleted file mode 100644 index ba5245b..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/waveserver/WaveletStore.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.box.server.waveserver; - -import com.google.common.collect.ImmutableSet; - -import org.waveprotocol.box.common.ExceptionalIterator; -import org.waveprotocol.box.server.persistence.FileNotFoundPersistenceException; -import org.waveprotocol.box.server.persistence.PersistenceException; -import org.waveprotocol.wave.model.id.WaveId; -import org.waveprotocol.wave.model.id.WaveletId; -import org.waveprotocol.wave.model.id.WaveletName; - -/** - * Stores wavelets. - * - * <p> - * Callers must serialize all calls to {@link #open(WaveletName)} and - * {@link #delete(WaveletName)} on the same wavelet. - * - * @param <T> wavelet handle data type - * - * @author [email protected] (Soren Lassen) - */ -public interface WaveletStore<T extends WaveletDeltaRecordReader> { - - /** - * Opens a wavelet, which can be used to store wavelet state. If the wavelet - * doesn't exist, it is implicitly created when the first op is appended to - * it. - * - * @throws PersistenceException if anything goes wrong with the underlying - * storage. - */ - T open(WaveletName waveletName) throws PersistenceException; - - /** - * Deletes a non-empty wavelet. - * - * @throws PersistenceException if anything goes wrong with the underlying - * storage. - * @throws FileNotFoundPersistenceException if the the wavelet does not exist - * in the delta store. - */ - void delete(WaveletName waveletName) throws PersistenceException, - FileNotFoundPersistenceException; - - /** - * Looks up all non-empty wavelets in the store. - * - * @throws PersistenceException if anything goes wrong with the underlying - * storage. - */ - ImmutableSet<WaveletId> lookup(WaveId waveId) throws PersistenceException; - - /** - * Return an {@link ExceptionalIterator} that throws a {@link PersistenceException} if something - * goes wrong while iterating over the store's wave IDs. This will only return the ids of waves - * that have at least one non-empty wavelet. - * - * The results returned from the iterator may or may not reflect concurrent modifications. - * the iterator itself is NOT thread safe and should only be used by one thread. - * - * @throws PersistenceException if anything goes wrong with the underlying - * storage while creating the iterator. - */ - ExceptionalIterator<WaveId, PersistenceException> getWaveIdIterator() throws PersistenceException; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/server/waveserver/testing/Certificates.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/server/waveserver/testing/Certificates.java b/wave/src/main/java/org/waveprotocol/box/server/waveserver/testing/Certificates.java deleted file mode 100644 index cf04e46..0000000 --- a/wave/src/main/java/org/waveprotocol/box/server/waveserver/testing/Certificates.java +++ /dev/null @@ -1,210 +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.box.server.waveserver.testing; - -import com.google.common.collect.ImmutableList; - -import org.apache.commons.codec.binary.Base64; -import org.waveprotocol.wave.crypto.SignerInfo; -import org.waveprotocol.wave.federation.Proto.ProtocolSignerInfo.HashAlgorithm; - -import java.io.ByteArrayInputStream; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; - -/** - * Helper methods for tests involving certificates. - * - * @author [email protected] (Lennard de Rijk) - */ -public class Certificates { - - /* - * Startcom domain certificate. - */ - public static final String STARTCOM_CERT = - "-----BEGIN CERTIFICATE-----\n" + - "MIIHADCCBmmgAwIBAgIBFDANBgkqhkiG9w0BAQUFADCBsDELMAkGA1UEBhMCSUwx\n" + - "DzANBgNVBAgTBklzcmFl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ZWQgTGlhYmlsaXR5LCByZWFkIHRoZSBzZWN0aW9uICpM\n" + - "ZWdhbCBMaW1pdGF0aW9ucyogb2YgdGhlIFN0YXJ0Q29tIENlcnRpZmljYXRpb24g\n" + - "QXV0aG9yaXR5IFBvbGljeSBhdmFpbGFibGUgYXQgaHR0cDovL2NlcnQuc3RhcnRj\n" + - "b20ub3JnL3BvbGljeS5wZGYwDQYJKoZIhvcNAQEFBQADgYEAtOq85Q1lf8PjsJCg\n" + - "uQ6TL3TJ1rSadfOwEyHJqIjR5LYpxdcJ5WxSEM3DxdrFnTaPBC6RQ7v836i9DdW3\n" + - "FS5/y1Et5gKksLNPQqaYEVFuvB4AGTp2HkdUGo8Oz9Dd4zTcvTSTeo/9mVxqdxKa\n" + - "lhMZMHD/ivqg8faZSQNYMg6xq7I=\n" + - "-----END CERTIFICATE-----\n"; - - /* - * These belong to the initech-corp.com domain. - */ - public static final String REAL_DOMAIN = "initech-corp.com"; - - public static final String REAL_CERTIFICATE = - "-----BEGIN CERTIFICATE-----\n" + - "MIIHWzCCBkOgAwIBAgICCn0wDQYJKoZIhvcNAQEFBQAwgdgxCzAJBgNVBAYTAlVT\n" + - "MREwDwYDVQQIDAhDb2xvcmFkbzEjMCEGA1UECgwaSmFiYmVyIFNvZnR3YXJlIEZv\n" + - "dW5kYXRpb24xIzAhBgNVBAsMGlNlY3VyZSBDZXJ0aWZpY2F0ZSBTaWduaW5nMUYw\n" + - "RAYDVQQDDD1TdGFydENvbSBDbGFzcyAxIEludGVybWVkaWF0ZSBDQSAtIEphYmJl\n" + - "ciBTb2Z0d2FyZSBGb3VuZGF0aW9uMSQwIgYJKoZIhvcNAQkBFhVjZXJ0bWFzdGVy\n" + - "QGphYmJlci5vcmcwHhcNMDkwODI4MTM0MDUyWhcNMTAwODI4MTM0MDUyWjCBoDEL\n" + - "MAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUtU3RhdGUxGTAXBgNVBAoTEGluaXRl\n" + - "Y2gtY29ycC5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JNNNDHkzegy53/kzsq/IzhS6ovsSEQdR2ue7a1sYmvZ\n" + - "Hj8K5F7+S93u/P9iHsoGjU2j4IgAq6iCxEqDEsVBr1IMMZaLbbNZiSboq1ZYSLhV\n" + - "jU2YSURXFt+84p/k5juk\n" + - "-----END CERTIFICATE-----\n"; - - public static final byte[] REAL_SIGNATURE = Base64.decodeBase64(( - "aYfzuohSPaqbwn/Ro0bgklyoTwKAmsYl7efRlC684yGOXdbAm+bPm9KHVVYIeLjSHTR" + - "M4ZB5rTkHIzh1B+/QHM8eO61AOp9WIP6kF7Vqnjm4KhcDbuUYPdV8qLPkjEjoDl1vCd" + - "p4NMnfLyHS7MMsN4MGTaLNtFeLNK6AyAZrM8c=").getBytes()); - - /* - * These belong to the example.com domain. - */ - public static final String EXAMPLE_DOMAIN = "example.com"; - - public static final String EXAMPLE_CERTIFICATE = - "-----BEGIN CERTIFICATE-----\n" + - "MIIC9TCCAl6gAwIBAgIJALQVfb0zIz6bMA0GCSqGSIb3DQEBBQUAMFsxCzAJBgNV\n" + - "BAYTAlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX\n" + - "aWRnaXRzIFB0eSBMdGQxFDASBgNVBAMTC2V4YW1wbGUuY29tMB4XDTA5MDcxODA2\n" + - "MjIyNloXDTEwMDcxODA2MjIyNlowWzELMAkGA1UEBhMCVVMxEzARBgNVBAgTClNv\n" + - "bWUtU3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEUMBIG\n" + - "A1UEAxMLZXhhbXBsZS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKue\n" + - "RG+YuGX6FifkJpYR+Gh/qF+PpGLSYVR7CzhGNh5a8RayKwPM8YNqsfKAT8VqLdAk\n" + - "19x//cf03CgcUwLQsuUo3zxK4E110L96lVX6oF12FiIpSCVN+E93qin2W7VXw2Jt\n" + - "fvQ4BllwdNMj/yNPl+bHuhtOjFAPpWEhCkSJP6NlAgMBAAGjgcAwgb0wHQYDVR0O\n" + - "BBYEFD2DmpOW+OiFr6U3Nu7NuDGuBSJgMIGNBgNVHSMEgYUwgYKAFD2DmpOW+OiF\n" + - "r6U3Nu7NuDGuBSJgoV+kXTBbMQswCQYDVQQGEwJVUzETMBEGA1UECBMKU29tZS1T\n" + - "dGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRQwEgYDVQQD\n" + - "EwtleGFtcGxlLmNvbYIJALQVfb0zIz6bMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcN\n" + - "AQEFBQADgYEAS7H+mB7lmEihX5lOWp9ZtyI7ua7MYVK05bbuBZJLAhO1mApu5Okg\n" + - "DqcybVV8ijPLJkII75dn+q7olpwMmgyjjsozEKY1N0It9nRsb9fW2tKGp2qlCMA4\n" + - "zP29U9091ZRH/xL1RPVzhkRHqfNJ/x+iTC4laSLBtwlsjjkd8Us6xrg=\n" + - "-----END CERTIFICATE-----\n"; - - public static final String EXAMPLE_PRIVATE_KEY = - "-----BEGIN PRIVATE KEY-----\n" + - "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAKueRG+YuGX6Fifk\n" + - "JpYR+Gh/qF+PpGLSYVR7CzhGNh5a8RayKwPM8YNqsfKAT8VqLdAk19x//cf03Cgc\n" + - "UwLQsuUo3zxK4E110L96lVX6oF12FiIpSCVN+E93qin2W7VXw2JtfvQ4BllwdNMj\n" + - "/yNPl+bHuhtOjFAPpWEhCkSJP6NlAgMBAAECgYAaRocP1wAUjO+rd+D4hRPVXAY5\n" + - "a1Kt1qwUNSqImSdcCmxzHyA62rv3dPR9vmt4PEN7ZMiv9+CxJqo2ce+7tJxO/Xq1\n" + - "lPTh8IVX+NUPI8LWtek9VZlXZ16nY5qXZ0i32vrwOz+GaZMfchAK05eTaiUJTN4P\n" + - "T2Wskp6jnlDGZYeNmQJBANXMPa70jf2M6zHq0dKBg+4I3XZ1x59G0fUnho1Ck+Q5\n" + - "ixo5GpFbbx2YgQmbFNUHhMNAJvLTduV5S3+CopqB3FMCQQDNfpUYQrmrAOvAZiQ0\n" + - "uX/BtorjvSoTkj4g2JegaGWUVAc8As9d3VrBf8l2ovJRuzVSGqHpzke7T8wGwaGr\n" + - "cEpnAkBFz+N0dbbHzHQgYKUTL+d8mrh2Lg95Gw8EFlwBVHQmWgPqFCtwu4KVD29T\n" + - "S6iJx2K6vv/42sRAOlNE18tw2GaxAkBAKakGBTeR5Fy4G2xspgr1AjlFuLfdmokZ\n" + - "mmdlp5MoCECmBT6YUVhYGL1f9KryyCBy/WvW5BjTrKvI5EbFj+87AkAobTHhq+D7\n" + - "TOQBpaA5v45z6HNsFdCovQkQokJbirQ0KDIopo5IT7Qtz7+Gi3S0uYl3xooAsCRc\n" + - "Zj50nIvr3txX\n" + - "-----END PRIVATE KEY-----\n"; - - private Certificates(){ - } - - /** - * Returns {@link SignerInfo} for the (realcert, startcom) certificate chain. - * @throws Exception if the certificates fail to be resolved properly - */ - public static SignerInfo getRealSignerInfo() throws Exception { - CertificateFactory factory = CertificateFactory.getInstance("X.509"); - X509Certificate realCert = (X509Certificate) factory.generateCertificate( - new ByteArrayInputStream(REAL_CERTIFICATE.getBytes())); - X509Certificate startCom = (X509Certificate) factory.generateCertificate( - new ByteArrayInputStream(STARTCOM_CERT.getBytes())); - - return new SignerInfo(HashAlgorithm.SHA256, - ImmutableList.of(realCert, startCom), REAL_DOMAIN); - } - - /** - * Returns {@link SignerInfo} for the (example.com) certificate chain. - * @throws Exception if the certificates fail to be resolved properly - */ - public static SignerInfo getExampleSignerInfo() throws Exception { - CertificateFactory factory = CertificateFactory.getInstance("X.509"); - X509Certificate exampleCert = (X509Certificate) factory.generateCertificate( - new ByteArrayInputStream(EXAMPLE_CERTIFICATE.getBytes())); - return new SignerInfo(HashAlgorithm.SHA256, - ImmutableList.of(exampleCert), EXAMPLE_DOMAIN); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/AsyncCallContext.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/AsyncCallContext.java b/wave/src/main/java/org/waveprotocol/box/stat/AsyncCallContext.java deleted file mode 100644 index cc0e00a..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/AsyncCallContext.java +++ /dev/null @@ -1,66 +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.box.stat; - -import java.util.Map; - -/** - * Saves and restores scope and timer of asynchronous call. - * - * @author [email protected] (A. Kaplanov) - */ -@SuppressWarnings({"rawtypes"}) -public class AsyncCallContext { - final Map<Class, RequestScope.Value> values; - final Timer timer; - - private AsyncCallContext(Map<Class, RequestScope.Value> values, Timer timer) { - this.values = values; - this.timer = timer; - } - - /** - * Clones scope values and creates new timer. - * - * @param name the name of new task. - * @return context with new scope and timer. - */ - public static AsyncCallContext start(String name) { - Map<Class, RequestScope.Value> values = null; - Timer timer = null; - if (Timing.isEnabled()) { - values = Timing.cloneScopeValues(); - ExecutionTree tree = (ExecutionTree)values.get(ExecutionTree.class); - if (tree != null) { - timer = tree.start(name); - } - } - return new AsyncCallContext(values, timer); - } - - /** - * Enters to cloned scope and stop timer. - */ - public void stop() { - if (timer != null && timer.isActive()) { - Timing.enterScope(values); - Timing.stop(timer); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/ExecutionNode.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/ExecutionNode.java b/wave/src/main/java/org/waveprotocol/box/stat/ExecutionNode.java deleted file mode 100644 index 15fd32e..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/ExecutionNode.java +++ /dev/null @@ -1,99 +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.box.stat; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -import java.util.List; -import java.util.Map; - -/** - * Represents a single timer node. - * - * @author [email protected] (A. Kaplanov) - */ -class ExecutionNode { - - private final ExecutionNode parent; - private final String name; - private final String module; - private final boolean isRequest; - private final List<ExecutionNode> children; - private final Map<String, ExecutionNode> childMap; - private final Measurement measurement; - - ExecutionNode(ExecutionNode parent, String name, String module, boolean isRequest, int threshold) { - this.parent = parent; - this.name = name; - this.module = module; - this.isRequest = isRequest; - this.children = Lists.newArrayList(); - this.childMap = Maps.newHashMap(); - this.measurement = new Measurement(); - measurement.setThreshold(threshold); - } - - /** - * Creates - * @param name - * @param module - * @param isRequest - * @param threshold - * @return - */ - synchronized ExecutionNode newChild(String name, String module, boolean isRequest, int threshold) { - ExecutionNode node = childMap.get(name); - if (node == null) { - node = new ExecutionNode(this, name, module, isRequest, threshold); - children.add(node); - childMap.put(name, node); - } - return node; - } - - synchronized void sample(int delta) { - measurement.sample(delta); - } - - String getName() { - return name; - } - - String getModule() { - return module; - } - - boolean isRequest() { - return isRequest; - } - - Measurement getMeasurement() { - return measurement; - } - - ExecutionNode getParent() { - return parent; - } - - synchronized Iterable<ExecutionNode> getChildren() { - return ImmutableList.copyOf(children); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/ExecutionTree.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/ExecutionTree.java b/wave/src/main/java/org/waveprotocol/box/stat/ExecutionTree.java deleted file mode 100644 index 634ca34..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/ExecutionTree.java +++ /dev/null @@ -1,162 +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.box.stat; - -import com.google.gwt.core.shared.GWT; - -/** - * Class that helps build a hierarchical tree of timers. - * - * @author [email protected] (A. Kaplanov) - */ -public class ExecutionTree implements RequestScope.Value { - private static final int DEFAULT_THRESHOLD = 500; - - private final ExecutionNode root; - private ExecutionNode currentNode; - - public ExecutionTree() { - root = new ExecutionNode(null, null, "", false, 0); - currentNode = root; - } - - private ExecutionTree(ExecutionNode root, ExecutionNode currentNode) { - this.root = root; - this.currentNode = currentNode; - } - - /** - * Push a new timer node. - */ - Timer start(String name) { - return start(name, false, DEFAULT_THRESHOLD); - } - - /** - * Push a new timer node. - */ - Timer start(String name, int threshold) { - return start(name, false, threshold); - } - - /** - * Push a new timer node. - */ - Timer startRequest(String name) { - return start(name, true, DEFAULT_THRESHOLD); - } - - /** - * Push a new timer node. - */ - Timer startRequest(String name, int threshold) { - return start(name, true, threshold); - } - - /** - * Push a new timer node. - */ - Timer start(String name, boolean isRequest, int threshold) { - ExecutionNode node = currentNode.newChild(name, getModuleName(), isRequest, threshold); - currentNode = node; - Timer timer = new Timer(node); - timer.start(); - return timer; - } - - /** - * Pop the timer node. - */ - void pop(ExecutionNode node) { - while (currentNode != node && currentNode.getParent() != null) { - currentNode = currentNode.getParent(); - } - if (node == currentNode && currentNode.getParent() != null) { - currentNode = currentNode.getParent(); - } - } - - /** - * Record statistics. - */ - void record(String name, int interval) { - record(name, false, interval, DEFAULT_THRESHOLD); - } - - /** - * Record statistics. - */ - void record(String name, int interval, int threshold) { - record(name, false, interval, threshold); - } - - /** - * Record statistics. - */ - void recordRequest(String name, int interval) { - record(name, true, interval, DEFAULT_THRESHOLD); - } - - /** - * Record statistics. - */ - void recordRequest(String name, int interval, int threshold) { - record(name, true, interval, threshold); - } - - @Override - public RequestScope.Value clone() { - return new ExecutionTree(root, currentNode); - } - - /** - * Record statistics. - */ - void record(String name, boolean isRequest, int interval, int threshold) { - ExecutionNode node = currentNode.newChild(name, getModuleName(), isRequest, threshold); - record(node, interval); - } - - /** - * Record statistics. - */ - void record(ExecutionNode node, int interval) { - node.sample(interval); - - Timing.getStatsRecorder().record(node.getName(), node.getModule(), interval, node.getMeasurement().getThreshold()); - if (node.isRequest()) { - Timing.getStatsRecorder().recordRequest(node); - } - } - - ExecutionNode getRoot() { - return root; - } - - ExecutionNode getCurrent() { - return currentNode; - } - - private String getModuleName() { - if (GWT.isClient()) { - return com.google.gwt.core.client.GWT.getModuleName(); - } - return ""; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/Measurement.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/Measurement.java b/wave/src/main/java/org/waveprotocol/box/stat/Measurement.java deleted file mode 100644 index 7e7ba9b..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/Measurement.java +++ /dev/null @@ -1,113 +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.box.stat; - -/** - * Represents sampling of measurements. - * - * @author David Byttow - * @author [email protected] (A. Kaplanov) - */ -class Measurement { - private int average; - private int high; - private int low; - private int total; - private int numSamples; - private int threshold; - - Measurement() { - this.low = Integer.MAX_VALUE; - this.high = 0; - } - - /** - * Samples with a new delta. - * - * @param delta the duration of the current sample. - */ - synchronized void sample(int delta) { - ++numSamples; - low = Math.min(delta, low); - high = Math.max(delta, high); - total += delta; - average = total / numSamples; - } - - int getAverage() { - return average; - } - - int getHigh() { - return high; - } - - int getLow() { - return low; - } - - int getTotal() { - return total; - } - - int getNumSamples() { - return numSamples; - } - - /** - * @return threshold time considered "too slow" - */ - int getThreshold() { - return threshold; - } - - void setThreshold(int threshold) { - this.threshold = threshold; - } - - @Override - public String toString() { - if (numSamples == 0) { - return "<td></td> <td></td> <td></td> <td></td> <td></td>"; - } else if (numSamples == 1) { - return new StringBuilder().append("<td></td> <td></td> <td></td> <td></td> <td>"). - append(formatMillis(total)).append("</td>").toString(); - } else { - return new StringBuilder().append("<td>").append(numSamples).append("</td>"). - append(" <td>").append(formatMillis(average)).append("</td>"). - append(" <td>").append(formatMillis(low)).append("</td>"). - append(" <td>").append(formatMillis(high)).append("</td>"). - append(" <td>").append(formatMillis(total)).append("</td>").toString(); - } - } - - private static String formatMillis(long millis) { - long sec = millis / 1000; - long ms = millis % 1000; - StringBuilder sb = new StringBuilder(); - sb.append(sec).append("."); - if (ms < 10) { - sb.append("00"); - } else if (ms < 100) { - sb.append('0'); - } - sb.append(ms).append("s"); - return sb.toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/RequestScope.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/RequestScope.java b/wave/src/main/java/org/waveprotocol/box/stat/RequestScope.java deleted file mode 100644 index 5c7d68a..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/RequestScope.java +++ /dev/null @@ -1,69 +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.box.stat; - -import java.util.Map; - -/** - * Request scope with execution tree and current execution node. - * - * @author [email protected] (A. Kaplanov) - */ -@SuppressWarnings("rawtypes") -public interface RequestScope { - - public interface Value { - public Value clone(); - } - - /** - * Initializes scope. - */ - public void enter(); - - /** - * Initializes scope with specified values. - */ - public void enter(Map<Class, Value> values); - - /** - * Clears scope. - */ - public void exit(); - - /** - * Checks is scope initialized. - */ - public boolean isEntered(); - - /** - * Sets value. - */ - public <T extends Value> void set(Class<T> clazz, T value); - - /** - * Gets value. - */ - public <T extends Value> T get(Class<T> clazz); - - /** - * Clone values. - */ - public Map<Class, Value> cloneValues(); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/SessionContext.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/SessionContext.java b/wave/src/main/java/org/waveprotocol/box/stat/SessionContext.java deleted file mode 100644 index 9a97ffc..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/SessionContext.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.box.stat; - -import org.waveprotocol.wave.model.wave.ParticipantId; - -/** - * Represents the current session. - * - * @author David Byttow - * @author [email protected] (A. Kaplanov) - */ -public interface SessionContext extends RequestScope.Value { - /** - * @return true if the user is authenticated. - */ - boolean isAuthenticated(); - - /** - * @return a unique session key. - */ - String getSessionKey(); - - /** - * @return the current participant id. - */ - ParticipantId getParticipantId(); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/Stat.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/Stat.java b/wave/src/main/java/org/waveprotocol/box/stat/Stat.java deleted file mode 100644 index 6a9ff48..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/Stat.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.box.stat; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Represents an annotation to mark a field as a tracked statistic. - * - * @author David Byttow - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface Stat { - /** - * @return the visible name of this statistic. - */ - String name(); - - /** - * @return a human readable description of what is being tracked. - */ - String help(); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/StatRecorder.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/StatRecorder.java b/wave/src/main/java/org/waveprotocol/box/stat/StatRecorder.java deleted file mode 100644 index 9e2f9b8..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/StatRecorder.java +++ /dev/null @@ -1,80 +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.box.stat; - -import com.google.gwt.core.shared.GWT; - -import java.util.HashMap; -import java.util.Map; - -/** - * Collects global and request-based statistic. - * - * @author [email protected] (A. Kaplanov) - */ -class StatRecorder { - - private final StatStore globalStore = new StatStore(); - private final Map<String, StatStore> sessionsStore = new HashMap<>(); - - StatRecorder() { - } - - /** - * Gets global statistic. - */ - StatStore getGlobalStore() { - return globalStore; - } - - synchronized StatStore getSessionStore() { - if (getSessionContext() != null) { - StatStore store = sessionsStore.get(getSessionContext().getSessionKey()); - if (store == null) { - sessionsStore.put(getSessionContext().getSessionKey(), store = new StatStore()); - } - return store; - } - return null; - } - - /** - * Records a single incident of measure and duration in millis with threshold. - */ - void record(String name, String module, int duration, int threshold) { - if (!GWT.isClient() && getSessionContext() != null && getSessionContext().isAuthenticated()) { - getSessionStore().recordMeasurement(name, module, duration, threshold); - } - globalStore.recordMeasurement(name, module, duration, threshold); - } - - /** - * Records an http request call tree. - */ - void recordRequest(ExecutionNode node) { - if (!GWT.isClient() && getSessionContext() != null && getSessionContext().isAuthenticated()) { - getSessionStore().storeRequest(node); - } - globalStore.storeRequest(node); - } - - private SessionContext getSessionContext() { - return Timing.getScopeValue(SessionContext.class); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/StatRenderer.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/StatRenderer.java b/wave/src/main/java/org/waveprotocol/box/stat/StatRenderer.java deleted file mode 100644 index 0ff531b..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/StatRenderer.java +++ /dev/null @@ -1,198 +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.box.stat; - -import com.google.gwt.core.shared.GWT; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import org.waveprotocol.box.stat.Statistic.Entry; - -import org.waveprotocol.wave.model.util.Pair; - -/** - * Renderer for statistic. - * - * @author David Byttow - * @author [email protected] (A. Kaplanov) - */ -class StatRenderer { - - /** - * Represents a profiled request. - */ - static class ProfiledRequest { - String uri; - ExecutionNode node; - - public ProfiledRequest(String uri, ExecutionNode node) { - this.uri = uri; - this.node = node; - } - } - - private boolean showModule; - - StatRenderer() { - this.showModule = GWT.isClient(); - } - - String renderHtml(List<Pair<String, Measurement>> measurements, List<ExecutionNode> nodes) { - StringBuilder builder = new StringBuilder(); - return builder.append("<div style=\"font-size: 0.9em; padding:4px\">") - .append(renderTitle("Global", 3)) - .append(renderGlobalStats(measurements)) - .append("<br/>") - .append(renderTitle("Requests", 3)) - .append(renderRequestStats(nodes)) - .append("</div>") - .toString(); - } - - String renderHtml(Collection<Entry> stats) { - StringBuilder builder = new StringBuilder(); - for (Statistic.Entry entry : stats) { - builder.append("<b>") - .append(entry.getName()) - .append(":</b> ") - .append(entry.getValue()) - .append("<br/>"); - } - return builder.toString(); - } - - String renderTitle(String title, int level) { - StringBuilder builder = new StringBuilder(); - return builder.append("<h") - .append(level) - .append(" style='margin-top: 5px; margin-bottom: 0px'>") - .append(title) - .append("</h") - .append(level) - .append(">") - .toString(); - } - - String renderRequestStats(List<ExecutionNode> nodes) { - StringBuilder builder = new StringBuilder(); - - beginStatTable(builder, showModule); - for (int i = nodes.size() - 1; i >= 0; --i) { - ExecutionNode node = nodes.get(i); - builder.append(renderNode(node, 0)); - } - endStatTable(builder); - - return builder.toString(); - } - - String renderNode(ExecutionNode node, int spaces) { - StringBuilder builder = new StringBuilder(); - Measurement measurement = node.getMeasurement(); - if (showModule) { - builder.append("<tr style=\"") - .append(getMeasurementStyle(measurement)) - .append("\"><td><pre style=\"display:inline\">") - .append(getSpaces(spaces)) - .append("</pre>") - .append(node.getName() + "</td>") - .append(" <td>") - .append(node.getModule() + "</td>") - .append(" ") - .append(node.getMeasurement()) - .append("</tr>"); - } else { - builder.append("<tr style=\"") - .append(getMeasurementStyle(measurement)) - .append("\"><td><pre style=\"display:inline\">") - .append(getSpaces(spaces)) - .append("</pre>") - .append(node.getName() + "</td>") - .append(" ") - .append(node.getMeasurement()) - .append("</tr>"); - } - for (ExecutionNode child : node.getChildren()) { - builder.append(renderNode(child, spaces + 2)); - } - return builder.toString(); - } - - private String renderGlobalStats(List<Pair<String, Measurement>> measurements) { - StringBuilder builder = new StringBuilder(); - - Collections.sort(measurements, new Comparator<Pair<String, Measurement>>() { - - @Override - public int compare(Pair<String, Measurement> p1, Pair<String, Measurement> p2) { - return -Integer.compare(p1.second.getTotal(), p2.second.getTotal()); - } - }); - - beginStatTable(builder, false); - for (Pair<String, Measurement> entry : measurements) { - builder.append("<tr style=\"") - .append(getMeasurementStyle(entry.second)) - .append("\">") - .append("<td>" + entry.first + "</td>") - .append(" ") - .append(entry.second) - .append("</tr>"); - } - endStatTable(builder); - - return builder.toString(); - } - - private static void beginStatTable(StringBuilder builder, boolean showModule) { - builder.append("<table>"); - builder.append("<tr style=\"font-style: oblique\">"); - builder.append("<td>Name</td>"); - if (showModule) { - builder.append("<td>Module</td>"); - } - builder.append("<td>Count</td><td>Average</td><td>Low</td><td>Hight</td><td>Total</td>"); - builder.append("</tr>"); - } - - private static void endStatTable(StringBuilder builder) { - builder.append("</table>"); - } - - private static String getSpaces(int spaces) { - char[] array = new char[spaces]; - Arrays.fill(array, ' '); - return new String(array); - } - - private static String getMeasurementStyle(Measurement m) { - if (m.getThreshold() == 0) { - return ""; - } - if (m.getAverage() >= m.getThreshold()) { - return "color: red;"; - } else if (m.getHigh() > m.getThreshold() * 0.5) { - return "color: orange;"; - } - return ""; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/StatService.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/StatService.java b/wave/src/main/java/org/waveprotocol/box/stat/StatService.java deleted file mode 100644 index 916df46..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/StatService.java +++ /dev/null @@ -1,28 +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.box.stat; - -/** - * Statistic servlet. - * - * @author [email protected] (A. Kaplanov) - */ -public class StatService { - public static final String STAT_URL = "/speedz"; -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/StatStore.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/StatStore.java b/wave/src/main/java/org/waveprotocol/box/stat/StatStore.java deleted file mode 100644 index c37473a..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/StatStore.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.box.stat; - -import java.util.HashMap; -import java.util.LinkedList; - -import java.util.List; -import java.util.Map; -import java.util.Queue; - -import org.waveprotocol.wave.model.util.Pair; -import com.google.common.collect.ImmutableList; - -/** - * Store for profiling statistic. - * - * @author [email protected] (A. Kaplanov) - */ -class StatStore { - - private static int MAX_REQUESTS = 100; - - private volatile int queueSize = 0; - private final Queue<ExecutionNode> profiledRequests = new LinkedList<>(); - private final Map<String, Measurement> measurements = new HashMap<>(); - - StatStore() { - } - - synchronized void recordMeasurement(String name, String module, int duration, int threshold) { - Measurement m = measurements.get(name); - if (m == null) { - measurements.put(name, m = new Measurement()); - } - m.sample(duration); - m.setThreshold(threshold); - } - - synchronized void storeRequest(ExecutionNode node) { - if (profiledRequests.offer(node)) { - queueSize++; - } - - // Remove items from the queue while there are items to remove. - if (queueSize > MAX_REQUESTS) { - profiledRequests.poll(); - queueSize--; - } - } - - synchronized List<Pair<String, Measurement>> getMeasurements() { - LinkedList<Pair<String, Measurement>> list = new LinkedList<>(); - for (Map.Entry<String, Measurement> entry : measurements.entrySet()) { - list.add(Pair.of(entry.getKey(), entry.getValue())); - } - return list; - } - - synchronized List<ExecutionNode> getProfiledRequests() { - return ImmutableList.copyOf(profiledRequests); - } - - synchronized void clear() { - queueSize = 0; - profiledRequests.clear(); - measurements.clear(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/Statistic.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/Statistic.java b/wave/src/main/java/org/waveprotocol/box/stat/Statistic.java deleted file mode 100644 index a4d3be3..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/Statistic.java +++ /dev/null @@ -1,122 +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.box.stat; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; - -import java.lang.reflect.Field; -import java.util.Collection; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Handles tracking of statistic on a per-object or per-class basis. - * - * @author David Byttow - */ -public class Statistic { - // TODO: Track stats over-time as well, for relative usage. - private static final Logger LOG = Logger.getLogger(Statistic.class.getName()); - - /** - * Represents a single tracked stat. - */ - public static abstract class Entry { - final String name; - final String help; - - Entry(String name, String help) { - this.name = name; - this.help = help; - } - - /** - * @return name of this stat. - */ - public String getName() { - return name; - } - - /** - * @return human readable description of the stat. - */ - public String getHelp() { - return help; - } - - @Override - public String toString() { - return getValue(); - } - - /** - * @return the current value of the stat. - */ - public abstract String getValue(); - } - - private static class FieldEntry extends Entry { - final Field field; - final Object ref; - - FieldEntry(Stat stat, Field field, Object ref) { - super(stat.name(), stat.help()); - this.field = field; - this.ref = ref; - } - - @Override - public String getValue() { - field.setAccessible(true); - try { - return field.get(ref).toString(); - } catch (IllegalArgumentException e) { - LOG.log(Level.WARNING, "Failed to get field.", e); - } catch (IllegalAccessException e) { - LOG.log(Level.WARNING, "Failed to access field.", e); - } - return ""; - } - } - - private static final List<Entry> trackedStats = Lists.newLinkedList(); - - /** - * Tracks all static fields of a class marked with a {@link Stat} annotation. - * - * @param clazz the class type to track. - */ - public static void trackClass(Class<?> clazz) { - for (Field field : clazz.getDeclaredFields()) { - Stat stat = field.getAnnotation(Stat.class); - if (stat != null) { - trackedStats.add(new FieldEntry(stat, field, null)); - } - } - } - - /** - * @return the collection of tracked stats. - */ - public static Collection<Entry> getStats() { - return ImmutableList.copyOf(trackedStats); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/Timed.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/Timed.java b/wave/src/main/java/org/waveprotocol/box/stat/Timed.java deleted file mode 100644 index d63d2da..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/Timed.java +++ /dev/null @@ -1,41 +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.box.stat; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Apply this annotation to a method to measure its runtime. - * You are not allowed to use '//' (double slashes) in the - * name of a measure. - * - * @author [email protected] (Dhanji R. Prasanna) - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface Timed { - String value() default ""; - - boolean isRequest() default false; - - int threshold() default 500; // we'll just say 500ms is a good default. -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/Timer.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/Timer.java b/wave/src/main/java/org/waveprotocol/box/stat/Timer.java deleted file mode 100644 index f50ec4e..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/Timer.java +++ /dev/null @@ -1,61 +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.box.stat; - -import org.waveprotocol.wave.model.util.Preconditions; - -/** - * A timer for call. - * Stores node in execution tree ant start time. - * - * @author [email protected] (A. Kaplanov) - */ -public class Timer { - private final ExecutionNode node; - private long startTime; - private long stopTime = 0; - - public Timer(ExecutionNode node) { - this.node = node; - } - - public void start() { - start(System.currentTimeMillis()); - } - - public void start(long startTime) { - this.startTime = startTime; - } - - public boolean isActive() { - return stopTime == 0; - } - - public void stop(ExecutionTree tree) { - stop(tree, System.currentTimeMillis()); - } - - public void stop(ExecutionTree tree, long stopTime) { - Preconditions.checkArgument(isActive(), "Timer is not active"); - this.stopTime = stopTime; - int interval = (int)(stopTime - startTime); - tree.pop(node); - tree.record(node, interval); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/Timing.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/Timing.java b/wave/src/main/java/org/waveprotocol/box/stat/Timing.java deleted file mode 100644 index 3ef587b..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/Timing.java +++ /dev/null @@ -1,277 +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.box.stat; - -import com.google.gwt.core.shared.GWT; -import java.util.Map; - -/** - * Request-scoped timing. - * - * @author [email protected] (A. Kaplanov) - */ -@SuppressWarnings({"rawtypes"}) -public class Timing { - static private final StatRecorder statsRecorder = new StatRecorder(); - static private final StatRenderer renderer = new StatRenderer(); - static private RequestScope scope; - - static private boolean enabled = false; - - /** - * Gets recorder of statistic. - */ - public static StatRecorder getStatsRecorder() { - return statsRecorder; - } - - /** - * Enables/disables statistic. - */ - static public void setEnabled(boolean enabled) { - Timing.enabled = enabled; - } - - /** - * Gets enable state. - */ - static public boolean isEnabled() { - return enabled; - } - - /** - * Initializes scope. - */ - static public void enterScope() { - if (enabled && scope != null) { - scope.enter(); - } - } - - /** - * Initializes scope with specified data. - */ - static public void enterScope(Map<Class, RequestScope.Value> scopeValues) { - if (enabled && scope != null && scopeValues != null) { - scope.enter(scopeValues); - } - } - - /** - * Clears scope. - */ - static public void exitScope() { - if (scope != null) { - scope.exit(); - } - } - - /** - * Sets scope. - */ - static public void setScope(RequestScope scope) { - Timing.scope = scope; - } - - /** - * Gets scope value. - */ - static public <T extends RequestScope.Value> T getScopeValue(Class<T> clazz) { - if (scope != null) { - enterIfOutOfScope(); - return scope.get(clazz); - } - return null; - } - - /** - * Sets scope value. - */ - static public <T extends RequestScope.Value> void setScopeValue(Class<T> clazz, T value) { - if (scope != null) { - enterIfOutOfScope(); - scope.set(clazz, value); - } - } - - /** - * Clones scope values. - */ - static public Map<Class, RequestScope.Value> cloneScopeValues() { - if (scope != null) { - enterIfOutOfScope(); - return scope.cloneValues(); - } - return null; - } - - /** - * Creates and starts the timer with specified name. - */ - static public Timer start(String name) { - if (enabled) { - return getExecutionTree().start(name); - } - return null; - } - - /** - * Creates and starts the timer with specified name and threshold. - */ - static public Timer start(String name, int threshold) { - if (enabled) { - return getExecutionTree().start(name, threshold); - } - return null; - } - - /** - * Creates and starts the timer for request with specified name. - */ - static public Timer startRequest(String name) { - if (enabled) { - return getExecutionTree().startRequest(name); - } - return null; - } - - /** - * Creates and starts the timer for request with specified name and threshold. - */ - static public Timer startRequest(String name, int threshold) { - if (enabled) { - return getExecutionTree().startRequest(name, threshold); - } - return null; - } - - /** - * Stops the timer. - */ - static public void stop(Timer timer) { - if (timer != null && timer.isActive()) { - timer.stop(getExecutionTree()); - } - } - - /** - * Stops the timer on specified time. - */ - static public void stop(Timer timer, long stopTime) { - if (timer != null) { - timer.stop(getExecutionTree(), stopTime); - } - } - - /** - * Records statistics for specified name and interval. - */ - static public void record(String name, int interval) { - if (enabled) { - getExecutionTree().record(name, interval); - } - } - - /** - * Records statistics for specified name, interval and threshold. - */ - static public void record(String name, int interval, int threshold) { - if (enabled) { - getExecutionTree().record(name, interval, threshold); - } - } - - /** - * Records statistics for specified request name and threshold. - */ - static public void recordRequest(String name, int interval) { - if (enabled) { - getExecutionTree().recordRequest(name, interval); - } - } - - /** - * Records statistics for specified request name, interval and threshold. - */ - static public void recordRequest(String name, int interval, int threshold) { - if (enabled) { - getExecutionTree().recordRequest(name, interval, threshold); - } - } - - /** - * Clears the statistics. - */ - static public void clearStatistics() { - if (GWT.isClient()) { - statsRecorder.getGlobalStore().clear(); - } else { - statsRecorder.getSessionStore().clear(); - } - } - - /** - * Renders statistics for all program. - */ - static public String renderGlobalStatistics() { - return renderer.renderHtml( - statsRecorder.getGlobalStore().getMeasurements(), - statsRecorder.getGlobalStore().getProfiledRequests()); - } - - /** - * Renders statistics for current session. Server only. - */ - static public String renderSessionStatistics() { - return renderer.renderHtml( - statsRecorder.getSessionStore().getMeasurements(), - statsRecorder.getSessionStore().getProfiledRequests()); - } - - /** - * Renders tracked statistic. - */ - static public String renderStats() { - return renderer.renderHtml(Statistic.getStats()); - } - - /** - * Renders title. - */ - static public String renderTitle(String title, int level) { - return renderer.renderTitle(title, level); - } - - /** - * Gets execution tree. - */ - static private ExecutionTree getExecutionTree() { - if (scope != null) { - enterIfOutOfScope(); - return scope.get(ExecutionTree.class); - } - return null; - } - - static private void enterIfOutOfScope() { - if (!scope.isEntered()) { - scope.enter(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/stat/TimingReceiver.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/stat/TimingReceiver.java b/wave/src/main/java/org/waveprotocol/box/stat/TimingReceiver.java deleted file mode 100644 index b790763..0000000 --- a/wave/src/main/java/org/waveprotocol/box/stat/TimingReceiver.java +++ /dev/null @@ -1,51 +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.box.stat; - -import org.waveprotocol.box.common.Receiver; - -/** - * Receiver proxy for profiling. - * - * @author [email protected] (Andrew Kaplanov) - */ -@SuppressWarnings({"rawtypes"}) -public class TimingReceiver<T> implements Receiver<T> { - private Receiver<T> receiver; - private String name; - - public TimingReceiver() { - } - - public Receiver init(Receiver <T> receiver, String name) { - this.receiver = receiver; - this.name = name; - return this; - } - - @Override - public boolean put(T obj) { - Timer timer = Timing.start(name); - try { - return receiver.put(obj); - } finally { - Timing.stop(timer); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/client/ClientIdGenerator.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/client/ClientIdGenerator.java b/wave/src/main/java/org/waveprotocol/box/webclient/client/ClientIdGenerator.java deleted file mode 100644 index ddd8ef3..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/client/ClientIdGenerator.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.waveprotocol.box.webclient.client; - -import org.waveprotocol.wave.model.id.IdGeneratorImpl; -import org.waveprotocol.wave.model.wave.ParticipantId; - -/** - * @author [email protected] (David Hearnden) - */ -public final class ClientIdGenerator { - - // Utility class - private ClientIdGenerator() { - } - - public static IdGeneratorImpl create() { - return create( - new ParticipantId(Session.get().getAddress()).getDomain(), Session.get().getIdSeed()); - } - - private static IdGeneratorImpl create(String domain, final String seed) { - return new IdGeneratorImpl(domain, new IdGeneratorImpl.Seed() { - @Override - public String get() { - return seed; - } - }); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/org/waveprotocol/box/webclient/client/DebugMessagePanel.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/org/waveprotocol/box/webclient/client/DebugMessagePanel.java b/wave/src/main/java/org/waveprotocol/box/webclient/client/DebugMessagePanel.java deleted file mode 100644 index 4d23a83..0000000 --- a/wave/src/main/java/org/waveprotocol/box/webclient/client/DebugMessagePanel.java +++ /dev/null @@ -1,100 +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.box.webclient.client; - -import com.google.gwt.core.client.GWT; -import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.SpanElement; -import com.google.gwt.resources.client.CssResource; -import com.google.gwt.uibinder.client.UiBinder; -import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.HTMLPanel; -import com.google.gwt.user.client.ui.Widget; - -import org.waveprotocol.wave.client.events.ClientEvents; -import org.waveprotocol.wave.client.events.DebugMessageEvent; -import org.waveprotocol.wave.client.events.DebugMessageEventHandler; - -import java.util.Date; - -public class DebugMessagePanel extends Composite { - interface Binder extends UiBinder<Widget, DebugMessagePanel> { - } - - interface Style extends CssResource { - String entry(); - - String info(); - - String severe(); - } - - private static final Binder BINDER = GWT.create(Binder.class); - - @UiField - HTMLPanel panel; - - @UiField - Style style; - - public DebugMessagePanel() { - initWidget(BINDER.createAndBindUi(this)); - } - - public void enable() { - ClientEvents.get().addDebugMessageHandler(new DebugMessageEventHandler() { - @Override - public void onDebugMessage(DebugMessageEvent event) { - StringBuilder message = new StringBuilder(); - message.append(new Date()); - message.append("[").append(event.getSeverity().toString()).append("] "); - message.append(event.getMessage()).append("\n"); - Throwable error = event.getError(); - while (error != null) { - message.append(error.getMessage()).append("\n"); - for (StackTraceElement elt : error.getStackTrace()) { - message.append(" ").append(elt.getClassName()).append(".").append( - elt.getMethodName()).append(" (").append(elt.getFileName()).append( - ":").append(elt.getLineNumber()).append(")\n"); - } - error = error.getCause(); - if (error != null) { - message.append("Caused by: "); - } - } - - SpanElement elt = Document.get().createSpanElement(); - elt.setInnerText(message.toString()); - switch (event.severity) { - case SEVERE: - elt.setClassName(style.entry() + " " + style.severe()); - break; - case INFO: - elt.setClassName(style.entry() + " " + style.info()); - break; - } - - panel.getElement().appendChild(elt); - elt.scrollIntoView(); - } - }); - } -}
