コード例 #1
0
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);
}
コード例 #2
0
ファイル: Codec11.cpp プロジェクト: slaskawi/cpp-client
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;
}
コード例 #3
0
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());
}
コード例 #4
0
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;
}
コード例 #5
0
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;
}
コード例 #6
0
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;
}
コード例 #7
0
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();
}
コード例 #8
0
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;
}
コード例 #9
0
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;
}
コード例 #10
0
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");
}
コード例 #11
0
void BaseCounterOperation::writeName(infinispan::hotrod::transport::Transport& transport, std::string counterName) {
    std::vector<char> counterNameAsVector(counterName.begin(), counterName.end());
    transport.writeArray(counterNameAsVector);
}