package com.datastax.oss.driver.internal.core.channel;
import com.datastax.oss.driver.api.core.metadata.Node;
import java.util.Objects;
import net.jcip.annotations.Immutable;
@Immutable
public class ChannelEvent {
public enum Type {
OPENED,
CLOSED,
RECONNECTION_STARTED,
RECONNECTION_STOPPED,
CONTROL_CONNECTION_FAILED
}
public static ChannelEvent channelOpened(Node node) {
return new ChannelEvent(Type.OPENED, node);
}
public static ChannelEvent channelClosed(Node node) {
return new ChannelEvent(Type.CLOSED, node);
}
public static ChannelEvent reconnectionStarted(Node node) {
return new ChannelEvent(Type.RECONNECTION_STARTED, node);
}
public static ChannelEvent reconnectionStopped(Node node) {
return new ChannelEvent(Type.RECONNECTION_STOPPED, node);
}
public static ChannelEvent controlConnectionFailed(Node node) {
return new ChannelEvent(Type.CONTROL_CONNECTION_FAILED, node);
}
public final Type type;
public final Node node;
public ChannelEvent(Type type, Node node) {
this.type = type;
this.node = node;
}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
} else if (other instanceof ChannelEvent) {
ChannelEvent that = (ChannelEvent) other;
return this.type == that.type && Objects.equals(this.node, that.node);
} else {
return false;
}
}
@Override
public int hashCode() {
return Objects.hash(type, node);
}
@Override
public String toString() {
return "ChannelEvent(" + type + ", " + node + ")";
}
}