import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
+import java.io.DataInput;
+import java.io.DataOutput;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
/**
* Globally-unique identifier of a local history.
*
- * @param <T> Frontend type
- *
* @author Robert Varga
*/
-public final class LocalHistoryIdentifier<T extends FrontendType> implements Identifier {
- private static final class Proxy<T extends FrontendType> implements Externalizable {
+public final class LocalHistoryIdentifier implements Identifier, WritableObject {
+ private static final class Proxy implements Externalizable {
private static final long serialVersionUID = 1L;
- private ClientIdentifier<T> clientId;
+ private ClientIdentifier clientId;
private long historyId;
public Proxy() {
// For Externalizable
}
- Proxy(final ClientIdentifier<T> frontendId, final long historyId) {
+ Proxy(final ClientIdentifier frontendId, final long historyId) {
this.clientId = Preconditions.checkNotNull(frontendId);
this.historyId = historyId;
}
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
- out.writeObject(clientId);
- out.writeLong(historyId);
+ clientId.writeTo(out);
+ WritableObjects.writeLong(out, historyId);
}
- @SuppressWarnings("unchecked")
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
- clientId = (ClientIdentifier<T>) in.readObject();
- historyId = in.readLong();
+ clientId = ClientIdentifier.readFrom(in);
+ historyId = WritableObjects.readLong(in);
}
private Object readResolve() {
- return new LocalHistoryIdentifier<>(clientId, historyId);
+ return new LocalHistoryIdentifier(clientId, historyId);
}
}
private static final long serialVersionUID = 1L;
- private final ClientIdentifier<T> clientId;
+ private final ClientIdentifier clientId;
private final long historyId;
- public LocalHistoryIdentifier(final ClientIdentifier<T> frontendId, final long historyId) {
+ public LocalHistoryIdentifier(final ClientIdentifier frontendId, final long historyId) {
this.clientId = Preconditions.checkNotNull(frontendId);
this.historyId = historyId;
}
- public ClientIdentifier<T> getClienId() {
+ public static LocalHistoryIdentifier readFrom(final DataInput in) throws IOException {
+ final ClientIdentifier clientId = ClientIdentifier.readFrom(in);
+ return new LocalHistoryIdentifier(clientId, WritableObjects.readLong(in));
+ }
+
+ @Override
+ public void writeTo(final DataOutput out) throws IOException {
+ clientId.writeTo(out);
+ WritableObjects.writeLong(out, historyId);
+ }
+
+ public ClientIdentifier getClientId() {
return clientId;
}
return false;
}
- final LocalHistoryIdentifier<?> other = (LocalHistoryIdentifier<?>) o;
+ final LocalHistoryIdentifier other = (LocalHistoryIdentifier) o;
return historyId == other.historyId && clientId.equals(other.clientId);
}
}
private Object writeReplace() {
- return new Proxy<>(clientId, historyId);
+ return new Proxy(clientId, historyId);
}
}