Remove deprecated NetworkEvent.
This commit is contained in:
parent
64c217e613
commit
365881a428
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019, OpenConsensus Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package openconsensus.trace;
|
||||
|
||||
/**
|
||||
* Superclass for {@link MessageEvent} and {@link NetworkEvent} to resolve API backward
|
||||
* compatibility issue.
|
||||
*
|
||||
* <p>{@code SpanData.create} can't be overloaded with parameter types that differ only in the type
|
||||
* of the TimedEvent, because the signatures are the same after generic type erasure. {@code
|
||||
* BaseMessageEvent} allows the same method to accept both {@code TimedEvents<NetworkEvent>} and
|
||||
* {@code TimedEvents<MessageEvent>}.
|
||||
*
|
||||
* <p>This class should only be extended by {@code NetworkEvent} and {@code MessageEvent}.
|
||||
*
|
||||
* @deprecated This class is for internal use only.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class BaseMessageEvent {
|
||||
// package protected to avoid users to extend it.
|
||||
BaseMessageEvent() {}
|
||||
}
|
||||
|
|
@ -67,11 +67,6 @@ public final class BlankSpan extends Span {
|
|||
Utils.checkNotNull(annotation, "annotation");
|
||||
}
|
||||
|
||||
/** No-op implementation of the {@link Span#addNetworkEvent(NetworkEvent)} method. */
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addNetworkEvent(NetworkEvent networkEvent) {}
|
||||
|
||||
/** No-op implementation of the {@link Span#addMessageEvent(MessageEvent)} method. */
|
||||
@Override
|
||||
public void addMessageEvent(MessageEvent messageEvent) {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import openconsensus.internal.Utils;
|
|||
@Immutable
|
||||
@AutoValue
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class MessageEvent extends BaseMessageEvent {
|
||||
public abstract class MessageEvent {
|
||||
/**
|
||||
* Available types for a {@code MessageEvent}.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,200 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019, OpenConsensus Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package openconsensus.trace;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import openconsensus.common.Timestamp;
|
||||
import openconsensus.internal.Utils;
|
||||
|
||||
/**
|
||||
* A class that represents a network event. It requires a {@link Type type} and a message id that
|
||||
* serves to uniquely identify each network message. It can optionally can have information about
|
||||
* the kernel time and message size.
|
||||
*
|
||||
* @deprecated Use {@link MessageEvent}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Immutable
|
||||
@AutoValue
|
||||
@AutoValue.CopyAnnotations
|
||||
@Deprecated
|
||||
public abstract class NetworkEvent extends BaseMessageEvent {
|
||||
/**
|
||||
* Available types for a {@code NetworkEvent}.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public enum Type {
|
||||
/**
|
||||
* When the message was sent.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
SENT,
|
||||
/**
|
||||
* When the message was received.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
RECV,
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@link Builder} with default values.
|
||||
*
|
||||
* @param type designates whether this is a network send or receive message.
|
||||
* @param messageId serves to uniquely identify each network message.
|
||||
* @return a new {@code Builder} with default values.
|
||||
* @throws NullPointerException if {@code type} is {@code null}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static Builder builder(Type type, long messageId) {
|
||||
return new AutoValue_NetworkEvent.Builder()
|
||||
.setType(Utils.checkNotNull(type, "type"))
|
||||
.setMessageId(messageId)
|
||||
// We need to set a value for the message size because the autovalue requires all
|
||||
// primitives to be initialized.
|
||||
.setUncompressedMessageSize(0)
|
||||
.setCompressedMessageSize(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the kernel timestamp associated with the {@code NetworkEvent} or {@code null} if not
|
||||
* set.
|
||||
*
|
||||
* @return the kernel timestamp associated with the {@code NetworkEvent} or {@code null} if not
|
||||
* set.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Nullable
|
||||
public abstract Timestamp getKernelTimestamp();
|
||||
|
||||
/**
|
||||
* Returns the type of the {@code NetworkEvent}.
|
||||
*
|
||||
* @return the type of the {@code NetworkEvent}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract Type getType();
|
||||
|
||||
/**
|
||||
* Returns the message id argument that serves to uniquely identify each network message.
|
||||
*
|
||||
* @return the message id of the {@code NetworkEvent}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract long getMessageId();
|
||||
|
||||
/**
|
||||
* Returns the uncompressed size in bytes of the {@code NetworkEvent}.
|
||||
*
|
||||
* @return the uncompressed size in bytes of the {@code NetworkEvent}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract long getUncompressedMessageSize();
|
||||
|
||||
/**
|
||||
* Returns the compressed size in bytes of the {@code NetworkEvent}.
|
||||
*
|
||||
* @return the compressed size in bytes of the {@code NetworkEvent}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract long getCompressedMessageSize();
|
||||
|
||||
/**
|
||||
* Returns the uncompressed size in bytes of the {@code NetworkEvent}.
|
||||
*
|
||||
* @deprecated Use {@link #getUncompressedMessageSize}.
|
||||
* @return the uncompressed size in bytes of the {@code NetworkEvent}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Deprecated
|
||||
public long getMessageSize() {
|
||||
return getUncompressedMessageSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder class for {@link NetworkEvent}.
|
||||
*
|
||||
* @deprecated {@link NetworkEvent} is deprecated. Please use {@link MessageEvent} and its builder
|
||||
* {@link MessageEvent.Builder}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@AutoValue.Builder
|
||||
@Deprecated
|
||||
public abstract static class Builder {
|
||||
// Package protected methods because these values are mandatory and set only in the
|
||||
// NetworkEvent#builder() function.
|
||||
abstract Builder setType(Type type);
|
||||
|
||||
abstract Builder setMessageId(long messageId);
|
||||
|
||||
/**
|
||||
* Sets the kernel timestamp.
|
||||
*
|
||||
* @param kernelTimestamp The kernel timestamp of the event.
|
||||
* @return this.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract Builder setKernelTimestamp(@Nullable Timestamp kernelTimestamp);
|
||||
|
||||
/**
|
||||
* Sets the uncompressed message size.
|
||||
*
|
||||
* @deprecated Use {@link #setUncompressedMessageSize}.
|
||||
* @param messageSize represents the uncompressed size in bytes of this message.
|
||||
* @return this.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder setMessageSize(long messageSize) {
|
||||
return setUncompressedMessageSize(messageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the uncompressed message size.
|
||||
*
|
||||
* @param uncompressedMessageSize represents the uncompressed size in bytes of this message.
|
||||
* @return this.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract Builder setUncompressedMessageSize(long uncompressedMessageSize);
|
||||
|
||||
/**
|
||||
* Sets the compressed message size.
|
||||
*
|
||||
* @param compressedMessageSize represents the compressed size in bytes of this message.
|
||||
* @return this.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract Builder setCompressedMessageSize(long compressedMessageSize);
|
||||
|
||||
/**
|
||||
* Builds and returns a {@code NetworkEvent} with the desired values.
|
||||
*
|
||||
* @return a {@code NetworkEvent} with the desired values.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract NetworkEvent build();
|
||||
|
||||
Builder() {}
|
||||
}
|
||||
|
||||
NetworkEvent() {}
|
||||
}
|
||||
|
|
@ -22,7 +22,6 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
import openconsensus.internal.Utils;
|
||||
import openconsensus.trace.internal.BaseMessageEventUtils;
|
||||
|
||||
/**
|
||||
* An abstract class that represents a span. It has an associated {@link SpanContext} and a set of
|
||||
|
|
@ -159,21 +158,6 @@ public abstract class Span {
|
|||
*/
|
||||
public abstract void addAnnotation(Annotation annotation);
|
||||
|
||||
/**
|
||||
* Adds a NetworkEvent to the {@code Span}.
|
||||
*
|
||||
* <p>This function is only intended to be used by RPC systems (either client or server), not by
|
||||
* higher level applications.
|
||||
*
|
||||
* @param networkEvent the network event to add.
|
||||
* @deprecated Use {@link #addMessageEvent}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@Deprecated
|
||||
public void addNetworkEvent(NetworkEvent networkEvent) {
|
||||
addMessageEvent(BaseMessageEventUtils.asMessageEvent(networkEvent));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a MessageEvent to the {@code Span}.
|
||||
*
|
||||
|
|
@ -185,12 +169,7 @@ public abstract class Span {
|
|||
* @param messageEvent the message to add.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public void addMessageEvent(MessageEvent messageEvent) {
|
||||
// Default implementation by invoking addNetworkEvent() so that any existing derived classes,
|
||||
// including implementation and the mocked ones, do not need to override this method explicitly.
|
||||
Utils.checkNotNull(messageEvent, "messageEvent");
|
||||
addNetworkEvent(BaseMessageEventUtils.asNetworkEvent(messageEvent));
|
||||
}
|
||||
public abstract void addMessageEvent(MessageEvent messageEvent);
|
||||
|
||||
/**
|
||||
* Adds a {@link Link} to the {@code Span}.
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019, OpenConsensus Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package openconsensus.trace.internal;
|
||||
|
||||
import openconsensus.common.Internal;
|
||||
import openconsensus.internal.Utils;
|
||||
import openconsensus.trace.BaseMessageEvent;
|
||||
import openconsensus.trace.MessageEvent;
|
||||
import openconsensus.trace.NetworkEvent;
|
||||
|
||||
/** Helper class to convert/cast between for {@link MessageEvent} and {@link NetworkEvent}. */
|
||||
@Internal
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class BaseMessageEventUtils {
|
||||
/**
|
||||
* Cast or convert a {@link BaseMessageEvent} to {@link MessageEvent}.
|
||||
*
|
||||
* <p>Warning: if the input is a {@code NetworkEvent} and contains {@code kernelTimestamp}
|
||||
* information, this information will be dropped.
|
||||
*
|
||||
* @param event the {@code BaseMessageEvent} that is being cast or converted.
|
||||
* @return a {@code MessageEvent} representation of the input.
|
||||
*/
|
||||
public static MessageEvent asMessageEvent(BaseMessageEvent event) {
|
||||
Utils.checkNotNull(event, "event");
|
||||
if (event instanceof MessageEvent) {
|
||||
return (MessageEvent) event;
|
||||
}
|
||||
NetworkEvent networkEvent = (NetworkEvent) event;
|
||||
MessageEvent.Type type =
|
||||
(networkEvent.getType() == NetworkEvent.Type.RECV)
|
||||
? MessageEvent.Type.RECEIVED
|
||||
: MessageEvent.Type.SENT;
|
||||
return MessageEvent.builder(type, networkEvent.getMessageId())
|
||||
.setUncompressedMessageSize(networkEvent.getUncompressedMessageSize())
|
||||
.setCompressedMessageSize(networkEvent.getCompressedMessageSize())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast or convert a {@link BaseMessageEvent} to {@link NetworkEvent}.
|
||||
*
|
||||
* @param event the {@code BaseMessageEvent} that is being cast or converted.
|
||||
* @return a {@code NetworkEvent} representation of the input.
|
||||
*/
|
||||
public static NetworkEvent asNetworkEvent(BaseMessageEvent event) {
|
||||
Utils.checkNotNull(event, "event");
|
||||
if (event instanceof NetworkEvent) {
|
||||
return (NetworkEvent) event;
|
||||
}
|
||||
MessageEvent messageEvent = (MessageEvent) event;
|
||||
NetworkEvent.Type type =
|
||||
(messageEvent.getType() == MessageEvent.Type.RECEIVED)
|
||||
? NetworkEvent.Type.RECV
|
||||
: NetworkEvent.Type.SENT;
|
||||
return NetworkEvent.builder(type, messageEvent.getMessageId())
|
||||
.setUncompressedMessageSize(messageEvent.getUncompressedMessageSize())
|
||||
.setCompressedMessageSize(messageEvent.getCompressedMessageSize())
|
||||
.build();
|
||||
}
|
||||
|
||||
private BaseMessageEventUtils() {}
|
||||
}
|
||||
Loading…
Reference in New Issue