All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tarantool.protocol.TarantoolPacket Maven / Gradle / Ivy

package org.tarantool.protocol;

import org.tarantool.Key;

import java.util.Map;

public class TarantoolPacket {
    private final Map headers;
    private final Map body;

    public TarantoolPacket(Map headers, Map body) {
        this.headers = headers;
        this.body = body;
    }

    public TarantoolPacket(Map headers) {
        this.headers = headers;
        body = null;
    }

    public Long getCode() {
        Object potenticalCode = headers.get(Key.CODE.getId());

        if (!(potenticalCode instanceof Long)) {
            //noinspection ConstantConditions
            throw new IllegalStateException(
                "A value contained in the header by key '" + Key.CODE.name() +
                    "' is not instance of Long class: " +
                    potenticalCode != null ? potenticalCode.getClass().toString() : "null"
            );
        }

        return (Long) potenticalCode;
    }

    public Long getSync() {
        return (Long) getHeaders().get(Key.SYNC.getId());
    }

    public Map getHeaders() {
        return headers;
    }

    public Map getBody() {
        return body;
    }

    public boolean hasBody() {
        return body != null && body.size() > 0;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy