CounterConfiguration BaseCounterOperation::readConfiguration(infinispan::hotrod::transport::Transport& transport) {
    uint8_t flags;
    CounterType ct;
    Storage st;
    long concurrentLevel = 0;
    long lower = 0;
    long upper = 0;
    long initial = 0;
    flags = transport.readByte();
    switch (flags & 0x03) {
    case 0x00:
        ct = CounterType::UNBOUNDED_STRONG;
        break;
    case 0x01:
        ct = CounterType::WEAK;
        break;
    case 0x02:
        ct = CounterType::BOUNDED_STRONG;
        break;
    default:
        throw HotRodClientException(std::string("Unknown counter type: ") + std::to_string(flags));
    }
    st = (flags & 0x04) ? Storage::PERSISTENT : Storage::VOLATILE;

    if (ct == WEAK) {
        concurrentLevel = transport.readVInt();
    }
    if (ct == BOUNDED_STRONG) {
        lower = transport.readLong();
        upper = transport.readLong();
    }
    initial = transport.readLong();
    return CounterConfiguration(initial, lower, upper, concurrentLevel, ct, st);
}
Exemple #2
0
std::map<InetSocketAddress, std::set<int32_t> > Codec11::computeNewHashes(
        infinispan::hotrod::transport::Transport& transport, uint32_t /*newTopologyId*/, int16_t /*numKeyOwners*/,
        uint8_t hashFunctionVersion, uint32_t /*hashSpace*/, uint32_t clusterSize) const {

    uint32_t numVirtualNodes = transport.readVInt();
    std::map<InetSocketAddress, std::set<int32_t> > servers2Hash;

    ConsistentHash* ch;
    if (hashFunctionVersion != 0) {
        ch = transport.getTransportFactory().getConsistentHashFactory().newConsistentHash(hashFunctionVersion);
    } else {
        ch = 0;
        WARN("Could not obtain a consistent hash for version %d", hashFunctionVersion);
    }

    for (uint32_t i = 0; i < clusterSize; i++) {
        std::string host = transport.readString();
        int16_t port = transport.readUnsignedShort();
        // TODO: Performance improvement, since hash positions are fixed, we could
        //maybe only calculate for those nodes that the client is not aware of?
        int32_t baseHashCode = transport.read4ByteInt();
        int32_t normalizedHashCode = getNormalizedHash(baseHashCode, ch);

        cacheHashCode(servers2Hash, host, port, normalizedHashCode);
        if (numVirtualNodes > 1) {
            calcVirtualHashCodes(baseHashCode, numVirtualNodes, servers2Hash,
                    host, port, ch);
        }
    }

    return servers2Hash;
}
void BaseCounterOperation::writeConfiguration(infinispan::hotrod::transport::Transport& transport,
        const CounterConfiguration& c) {
    uint8_t flags = 0;
    switch (c.getType()) {
    case CounterType::WEAK:
        flags |= 0x01;
        break;
    case CounterType::BOUNDED_STRONG:
        flags |= 0x02;
        break;
    case CounterType::UNBOUNDED_STRONG:
        break;
    }

    switch (c.getStorage()) {
    case Storage::PERSISTENT:
        flags |= 0x04;
        break;
    case Storage::VOLATILE:
        break;
    }
    transport.writeByte(flags);

    if (c.getType() == CounterType::WEAK) {
        transport.writeVInt(c.getConcurrencyLevel());
    }

    if (c.getType() == CounterType::BOUNDED_STRONG)
            {
        transport.writeLong(c.getLowerBound());
        transport.writeLong(c.getUpperBound());
    }
    transport.writeLong(c.getInitialValue());
}
bool RemoveCounterListenerOperation::executeOperation(infinispan::hotrod::transport::Transport& transport) {
    TRACE("Executing RemoveCounterListenerOperation(flags=%u)", flags);
    std::unique_ptr<HeaderParams> params(
            RetryOnFailureOperation<bool>::writeHeader(transport, COUNTER_REMOVE_LISTENER_REQUEST));
    writeName(transport, counterName);
    transport.writeArray(listenerId);
    transport.flush();
    uint8_t status = readHeaderAndValidate(transport, *params);
    return status == NO_ERROR_STATUS;
}
long GetCounterValueOperation::executeOperation(infinispan::hotrod::transport::Transport& transport) {
    TRACE("Executing IsCounterDefinedOperation(flags=%u)", flags);
    std::unique_ptr<HeaderParams> params(RetryOnFailureOperation<long>::writeHeader(transport, COUNTER_GET_REQUEST));
    writeName(transport, counterName);
    transport.flush();
    uint8_t status = readHeaderAndValidate(transport, *params);
    if (!isSuccess(status)) {
        throw HotRodClientException(
                std::string("Error in GetCountervalue operation, counter name: ") + counterName + " status: "
                        + std::to_string(status));
    }
    auto ret = (long)transport.readLong();
    TRACE("Finished IsCounterDefinedOperation");
    return ret;
}
std::set<std::string> GetCounterNamesOperation::executeOperation(infinispan::hotrod::transport::Transport& transport) {
    TRACE("Executing GetCounterNamesOperation(flags=%u)", flags);
    std::unique_ptr<HeaderParams> params(
            RetryOnFailureOperation<std::set<std::string>>::writeHeader(transport, COUNTER_GET_NAMES_REQUEST));
    uint8_t status = readHeaderAndValidate(transport, *params);
    std::set<std::string> ret;
    if (!isSuccess(status)) {
        auto num = transport.readVInt();
        for (uint32_t i = 0; i < num; i++) {
            auto name = transport.readString();
            ret.insert(name);
        }
    }
    TRACE("Finished GetCounterNamesOperation");
    return ret;
}
hrbytes ClearOperation::executeOperation(infinispan::hotrod::transport::Transport& transport)
{
    hr_scoped_ptr<HeaderParams> params(&(RetryOnFailureOperation<hrbytes>::writeHeader(transport, CLEAR_REQUEST)));
    transport.flush();
    RetryOnFailureOperation<hrbytes>::readHeaderAndValidate(transport, *params);
    return hrbytes();
}
long CompareAndSwapCounterValueOperation::executeOperation(infinispan::hotrod::transport::Transport& transport) {
    TRACE("Executing CompareAndSwapOperation(flags=%u)", flags);
    std::unique_ptr<HeaderParams> params(RetryOnFailureOperation<long>::writeHeader(transport, COUNTER_CAS_REQUEST));
    writeName(transport, counterName);
    transport.writeLong(expect);
    transport.writeLong(update);
    transport.flush();
    uint8_t status = readHeaderAndValidate(transport, *params);
    assertBoundaries(status);
    if (status != NO_ERROR_STATUS) {
        throw HotRodClientException(
                std::string("Error in CompareAndSwap operation, counter name: ") + counterName + " status: "
                        + std::to_string(status));
    }
    auto ret = (long)transport.readLong();
    TRACE("Finished CompareAndSwapDefinedOperation");
    return ret;
}
bool IsCounterDefinedOperation::executeOperation(infinispan::hotrod::transport::Transport& transport) {
    TRACE("Executing IsCounterDefinedOperation(flags=%u)", flags);
    std::unique_ptr<HeaderParams> params(RetryOnFailureOperation<bool>::writeHeader(transport, COUNTER_CREATE_REQUEST));
    writeName(transport, counterName);
    transport.flush();
    uint8_t status = readHeaderAndValidate(transport, *params);
    TRACE("Finished IsCounterDefinedOperation");
    return status==0x00;
}
void RemoveCounterOperation::executeOperation(infinispan::hotrod::transport::Transport& transport) {
    TRACE("Executing RemoveOperation(flags=%u)", flags);
    std::unique_ptr<HeaderParams> params(RetryOnFailureOperation<void>::writeHeader(transport, COUNTER_REMOVE_REQUEST));
    writeName(transport, counterName);
    transport.flush();
    uint8_t status = readHeaderAndValidate(transport, *params);
    if (!isSuccess(status) && status != KEY_DOES_NOT_EXIST_STATUS) {
        throw HotRodClientException(
                std::string("Error in CounterRemove operation, counter name: ") + counterName + " status: "
                        + std::to_string(status));
    }
    TRACE("Finished RemoveOperation");
}
void BaseCounterOperation::writeName(infinispan::hotrod::transport::Transport& transport, std::string counterName) {
    std::vector<char> counterNameAsVector(counterName.begin(), counterName.end());
    transport.writeArray(counterNameAsVector);
}