Search in sources :

Example 1 with MessageGroupRetrievalResponseEntry

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

the class AsyncRetrievalOperationImpl method retrieveSegments.

private void retrieveSegments(DHTKey relayKey, DHTKey[] segmentKeys, MetaData metaData) {
    List<MessageGroup> messageGroups;
    SegmentedRetrievalValue<K, V> segmentedRetrievalValue;
    if (segmentedRetrievalValues == null) {
        segmentedRetrievalValues = new ArrayList<>(segmentKeys.length);
    }
    segmentedRetrievalValue = new SegmentedRetrievalValue<>(segmentKeys, relayKey, this, nspoImpl.getValueDeserializer(), metaData);
    messageGroups = new ArrayList<>();
    for (DHTKey segmentKey : segmentKeys) {
        ProtoRetrievalMessageGroup protoRetrievalMG;
        boolean listenerInserted;
        List<WeakReference<ActiveKeyedOperationResultListener<MessageGroupRetrievalResponseEntry>>> listeners;
        protoRetrievalMG = createProtoRetrievalMG(new KeyedMessageEstimate(1), false);
        listenerInserted = activeRetrievalListeners.addListener(protoRetrievalMG.getUUID(), segmentKey, segmentedRetrievalValue);
        if (!listenerInserted) {
            throw new RuntimeException("Duplicate listener insertion");
        }
        protoRetrievalMG.addKey(segmentKey);
        protoRetrievalMG.addToMessageGroupList(messageGroups);
        // hold a reference to the uuid to prevent GC
        opUUIDs.add((OperationUUID) protoRetrievalMG.getUUID());
        segmentedRetrievalValues.add(segmentedRetrievalValue);
    }
    for (MessageGroup messageGroup : messageGroups) {
        retrievalSender.send(messageGroup);
    }
}
Also used : MessageGroup(com.ms.silverking.cloud.dht.net.MessageGroup) ProtoRetrievalMessageGroup(com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup) ProtoMessageGroup(com.ms.silverking.cloud.dht.net.ProtoMessageGroup) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) ProtoRetrievalMessageGroup(com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup) MessageGroupRetrievalResponseEntry(com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry) WeakReference(java.lang.ref.WeakReference)

Example 2 with MessageGroupRetrievalResponseEntry

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

the class AsyncRetrievalOperationImpl method createProtoRetrievalMG.

private ProtoRetrievalMessageGroup createProtoRetrievalMG(MessageEstimate estimate, boolean verifyIntegrity) {
    OperationUUID opUUID;
    ConcurrentMap<DHTKey, List<ActiveKeyedOperationResultListener<MessageGroupRetrievalResponseEntry>>> newMap;
    KeyedMessageEstimate keyedMessageEstimate;
    int relDeadline;
    keyedMessageEstimate = (KeyedMessageEstimate) estimate;
    opUUID = activeRetrievalListeners.newOpUUID();
    relDeadline = operation.getTimeoutController().getMaxRelativeTimeoutMillis(this);
    if (debugShortTimeout) {
        if (relDeadline < shortTimeoutLimit) {
            Log.warning("short relDeadline: " + relDeadline);
            // Log.warning(timeoutParameters.computeTimeout(keyedMessageEstimate.getNumKeys()));
            Log.warning(timeoutState.getCurRelTimeoutMillis());
        // throw new RuntimeException();
        }
    }
    return new ProtoRetrievalMessageGroup(opUUID, context.contextAsLong(), new InternalRetrievalOptions(retrievalOperation.retrievalOptions(), verifyIntegrity), originator, keyedMessageEstimate.getNumKeys(), relDeadline, retrievalOperation.retrievalOptions().getForwardingMode());
}
Also used : DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) ProtoRetrievalMessageGroup(com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MessageGroupRetrievalResponseEntry(com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry) InternalRetrievalOptions(com.ms.silverking.cloud.dht.common.InternalRetrievalOptions) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint)

Example 3 with MessageGroupRetrievalResponseEntry

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

the class SegmentedRetrievalValue method checkForCompletion.

@Override
protected void checkForCompletion() {
    MessageGroupRetrievalResponseEntry response;
    OpResult result;
    result = OpResult.SUCCEEDED;
    for (DHTKey key : keys) {
        if (getResult(key) != OpResult.SUCCEEDED) {
            result = getResult(key);
        // System.out.println("Incomplete: "+ key);
        }
    }
    if (result == OpResult.SUCCEEDED) {
        // System.out.println("SegmentedRetrievalValue complete");
        parent.reassembledResultReceived(relayKey, new SegmentedRetrievalResult<>(metaData, deserializer, getBuffers(), result));
    } else {
    // System.out.println("SegmentedRetrievalValue incomplete");
    // parent.resultReceived(relayKey, MessageGroupRetrievalResponseEntry);
    }
}
Also used : OpResult(com.ms.silverking.cloud.dht.common.OpResult) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) MessageGroupRetrievalResponseEntry(com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry)

Example 4 with MessageGroupRetrievalResponseEntry

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

the class NamespaceStore method handleSecondarySync.

public void handleSecondarySync(MessageGroup message) {
    List<StorageValueAndParameters> svpList;
    if (debug) {
        Log.warningAsyncf("incomingSyncRetrievalResponse");
    }
    svpList = new ArrayList<>();
    for (MessageGroupRetrievalResponseEntry entry : message.getRetrievalResponseValueKeyIterator()) {
        StorageValueAndParameters svp;
        svp = StorageValueAndParameters.createSVP(entry);
        if (svp != null) {
            svpList.add(svp);
        }
    }
    if (!svpList.isEmpty()) {
        put(svpList, emptyUserData, NullKeyedOpResultListener.instance);
    }
}
Also used : MessageGroupRetrievalResponseEntry(com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry)

Example 5 with MessageGroupRetrievalResponseEntry

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

the class ActiveRetrievalListeners method receivedRetrievalResponse.

void receivedRetrievalResponse(MessageGroup message) {
    if (enableMultipleOpsPerMessage) {
        // long    version;
        ConcurrentMap<DHTKey, List<WeakReference<ActiveKeyedOperationResultListener<MessageGroupRetrievalResponseEntry>>>> listenerMap;
        // version = message.getBuffers()[0].getLong(0);
        // System.out.println("receivedRetrievalResponse version "+ version);
        listenerMap = activeRetrievalListeners.get(message.getUUID());
        if (listenerMap != null) {
            // System.out.println("listenerMap "+ listenerMap);
            for (MessageGroupRetrievalResponseEntry entry : message.getRetrievalResponseValueKeyIterator()) {
                List<WeakReference<ActiveKeyedOperationResultListener<MessageGroupRetrievalResponseEntry>>> listenerList;
                // System.out.println("entry:\t"+ entry);
                listenerList = listenerMap.get(entry);
                if (listenerList != null) {
                    for (WeakReference<ActiveKeyedOperationResultListener<MessageGroupRetrievalResponseEntry>> listenerRef : listenerList) {
                        ActiveKeyedOperationResultListener<MessageGroupRetrievalResponseEntry> listener;
                        listener = listenerRef.get();
                        if (listener != null) {
                            listener.resultReceived(entry, entry);
                        } else {
                            Log.info("receivedRetrievalResponse. null listenerRef.get() for entry: ", entry);
                        }
                    }
                } else {
                    Log.warning("receivedRetrievalResponse. No listener for entry: ", entry);
                }
            }
        } else {
            // If we're receiving the error, then it's possible that we lost the
            // reference that was stored in the weak map.
            // FUTURE - was WARNING, think about level
            Log.info("receivedRetrievalResponse. No listenerMap for: ", message.getUUID());
        }
    } else {
        ActiveKeyedOperationResultListener<MessageGroupRetrievalResponseEntry> listener;
        listener = activeOpListeners.get(message.getUUID());
        if (listener == null) {
            Log.info("receivedRetrievalResponse. No listener for uuid: ", message.getUUID());
        } else {
            for (MessageGroupRetrievalResponseEntry entry : message.getRetrievalResponseValueKeyIterator()) {
                listener.resultReceived(entry, entry);
            }
        }
    }
}
Also used : WeakReference(java.lang.ref.WeakReference) DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) List(java.util.List) LinkedList(java.util.LinkedList) MessageGroupRetrievalResponseEntry(com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry)

Aggregations

MessageGroupRetrievalResponseEntry (com.ms.silverking.cloud.dht.net.MessageGroupRetrievalResponseEntry)10 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)4 List (java.util.List)3 OpResult (com.ms.silverking.cloud.dht.common.OpResult)2 StorageValueAndParameters (com.ms.silverking.cloud.dht.daemon.storage.StorageValueAndParameters)2 ProtoRetrievalMessageGroup (com.ms.silverking.cloud.dht.net.ProtoRetrievalMessageGroup)2 WeakReference (java.lang.ref.WeakReference)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ImmutableList (com.google.common.collect.ImmutableList)1 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)1 InternalRetrievalOptions (com.ms.silverking.cloud.dht.common.InternalRetrievalOptions)1 RetrievalCommunicator (com.ms.silverking.cloud.dht.daemon.storage.protocol.RetrievalCommunicator)1 RetrievalResult (com.ms.silverking.cloud.dht.daemon.storage.protocol.RetrievalResult)1 MessageGroup (com.ms.silverking.cloud.dht.net.MessageGroup)1 ProtoMessageGroup (com.ms.silverking.cloud.dht.net.ProtoMessageGroup)1 IPAndPort (com.ms.silverking.net.IPAndPort)1