io.datakernel.crdt.CrdtMessaging Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datakernel-crdt Show documentation
Show all versions of datakernel-crdt Show documentation
Conflict-free replicated data type implementation for DataKernel Framework.
/*
* Copyright (C) 2015-2018 SoftIndex LLC.
*
* 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 io.datakernel.crdt;
import io.datakernel.codec.CodecSubtype;
import io.datakernel.codec.StructuredCodec;
import static io.datakernel.codec.StructuredCodecs.*;
public final class CrdtMessaging {
public static final StructuredCodec MESSAGE_CODEC = CodecSubtype.create()
.with(Download.class, object(Download::new,
"token", Download::getToken, LONG64_CODEC))
.with(CrdtMessages.class, ofEnum(CrdtMessages.class));
public static final StructuredCodec RESPONSE_CODEC = CodecSubtype.create()
.with(CrdtResponses.class, ofEnum(CrdtResponses.class))
.with(DownloadStarted.class, object(DownloadStarted::new))
.with(ServerError.class, object(ServerError::new,
"msg", ServerError::getMsg, STRING_CODEC));
public interface CrdtMessage {}
public interface CrdtResponse {}
public enum CrdtMessages implements CrdtMessage {
UPLOAD,
REMOVE,
PING
}
public final static class Download implements CrdtMessage {
private final long token;
public Download(long token) {
this.token = token;
}
public long getToken() {
return token;
}
@Override
public String toString() {
return "Download{token=" + token + '}';
}
}
public enum CrdtResponses implements CrdtResponse {
UPLOAD_FINISHED,
REMOVE_FINISHED,
PONG
}
public final static class DownloadStarted implements CrdtResponse {
@Override
public String toString() {
return "DownloadStarted";
}
}
public final static class ServerError implements CrdtResponse {
private final String msg;
public ServerError(String msg) {
this.msg = msg;
}
public String getMsg() {
return msg;
}
@Override
public String toString() {
return "ServerError{msg=" + msg + '}';
}
}
}