Search in sources :

Example 1 with ProtoValueMessageGroup

use of com.ms.silverking.cloud.dht.net.ProtoValueMessageGroup in project SilverKing by Morgan-Stanley.

the class ActiveProxyRetrieval method sendResults.

/**
 * Send responses for all locally completed operations
 * @param retrievalOperation
 */
protected void sendResults(List<RetrievalResult> results) {
    if (debug) {
        System.out.printf("ActiveProxyRetrieval.sendresults() %d\n", results.size());
    }
    /*
        debugString.append("***\n");
        for (RetrievalResult result : results) {
            debugString.append(result.getValue() +"\n");
        }
        debugString.append("+++\n");
        */
    try {
        if (results.size() > 0) {
            ProtoValueMessageGroup pmg;
            byte[] _originator;
            List<List<RetrievalResult>> resultGroups;
            _originator = ConvergenceController2.isChecksumVersionConstraint(retrievalOptions.getVersionConstraint()) ? originator : messageModule.getMessageGroupBase().getMyID();
            resultGroups = createResultGroups(results);
            for (List<RetrievalResult> resultGroup : resultGroups) {
                MessageGroup messageGroup;
                int groupLength;
                groupLength = RetrievalResult.totalResultLength(resultGroup);
                pmg = new ProtoValueMessageGroup(uuid, namespace, results.size(), groupLength, _originator, messageModule.getAbsMillisTimeSource().relMillisRemaining(absDeadlineMillis));
                for (RetrievalResult result : resultGroup) {
                    DHTKey key;
                    ByteBuffer value;
                    if (debug) {
                        System.out.println(result);
                    }
                    key = result.getKey();
                    if (retrievalOptions.getWaitMode() != WaitMode.WAIT_FOR || result.getValue() == null) {
                        value = result.getValue();
                    } else {
                        value = result.getValue().duplicate();
                    }
                    if (value == null) {
                        pmg.addErrorCode(key, result.getResult());
                    } else {
                        pmg.addValue(key, value, result.getResultLength(), true);
                    }
                }
                messageGroup = pmg.toMessageGroup();
                connection.sendAsynchronous(messageGroup, messageGroup.getDeadlineAbsMillis(messageModule.getAbsMillisTimeSource()));
            }
        }
    /*
        } catch (RuntimeException re) {
            // for debugging only
            re.printStackTrace();
            System.out.println("results.size() "+ results.size());
            for (RetrievalResult result : results) {
                System.out.println(result);
            }
            //rComm.displayDebug();
            System.exit(-1);
            */
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}
Also used : ProtoKeyedMessageGroup(com.ms.silverking.cloud.dht.net.ProtoKeyedMessageGroup) MessageGroup(com.ms.silverking.cloud.dht.net.MessageGroup) ProtoValueMessageGroup(com.ms.silverking.cloud.dht.net.ProtoValueMessageGroup) ProtoRetrievalMessageGroup(com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup) ProtoMessageGroup(com.ms.silverking.cloud.dht.net.ProtoMessageGroup) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RetrievalResult(com.ms.silverking.cloud.dht.daemon.storage.protocol.RetrievalResult) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) ProtoValueMessageGroup(com.ms.silverking.cloud.dht.net.ProtoValueMessageGroup)

Example 2 with ProtoValueMessageGroup

use of com.ms.silverking.cloud.dht.net.ProtoValueMessageGroup in project SilverKing by Morgan-Stanley.

the class ActiveProxyRetrieval method createValueMessageForSecondaryReplicas.

// ///////////////////////
private ProtoValueMessageGroup createValueMessageForSecondaryReplicas(RetrievalResult result) {
    ProtoValueMessageGroup pmg;
    ByteBuffer buf;
    ValueCreator creator;
    int valueBytes;
    ByteBuffer value;
    int valueLength;
    buf = result.getValue();
    creator = MetaDataUtil.getCreator(buf, 0);
    valueBytes = MetaDataUtil.getStoredLength(buf, 0);
    valueLength = MetaDataUtil.getCompressedLength(buf, 0);
    value = (ByteBuffer) buf.duplicate().flip();
    if (debug) {
        System.out.printf("buf   %s\n", buf);
        System.out.printf("value %s\n", value);
        System.out.printf("valueBytes %d valueLength %d\n", valueBytes, valueLength);
    }
    pmg = new ProtoValueMessageGroup(new UUIDBase(), message.getContext(), 1, valueBytes, creator.getBytes(), DHTConstants.defaultSecondaryReplicaUpdateTimeoutMillis);
    pmg.addValue(result.getKey(), value, valueLength, true);
    return pmg;
}
Also used : UUIDBase(com.ms.silverking.id.UUIDBase) ByteBuffer(java.nio.ByteBuffer) ValueCreator(com.ms.silverking.cloud.dht.ValueCreator) ProtoValueMessageGroup(com.ms.silverking.cloud.dht.net.ProtoValueMessageGroup)

Aggregations

ProtoValueMessageGroup (com.ms.silverking.cloud.dht.net.ProtoValueMessageGroup)2 ByteBuffer (java.nio.ByteBuffer)2 ImmutableList (com.google.common.collect.ImmutableList)1 ValueCreator (com.ms.silverking.cloud.dht.ValueCreator)1 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)1 RetrievalResult (com.ms.silverking.cloud.dht.daemon.storage.protocol.RetrievalResult)1 MessageGroup (com.ms.silverking.cloud.dht.net.MessageGroup)1 ProtoKeyedMessageGroup (com.ms.silverking.cloud.dht.net.ProtoKeyedMessageGroup)1 ProtoMessageGroup (com.ms.silverking.cloud.dht.net.ProtoMessageGroup)1 ProtoRetrievalMessageGroup (com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup)1 UUIDBase (com.ms.silverking.id.UUIDBase)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1