com.gemstone.gemfire.internal.cache.PutAllPartialResultException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.internal.cache;
import com.gemstone.gemfire.CancelException;
import com.gemstone.gemfire.GemFireException;
import com.gemstone.gemfire.internal.cache.tier.sockets.VersionedObjectList;
import java.io.Serializable;
import java.util.*;
/**
* This exception is thrown as some keys in map failed in putAll operation.
*
* @author xzhou
*
*
* @since 6.5
*/
public class PutAllPartialResultException extends GemFireException {
private PutAllPartialResult result;
//////////////////// Constructors ////////////////////
/**
* Creates a new PutAllPartialResultException
*/
public PutAllPartialResultException(PutAllPartialResult result) {
super("Partial keys are processed in putAll", result != null ? result
.getFailure() : null);
this.result = result;
}
public PutAllPartialResultException() {
super("Partial keys are processed in putAll");
result = new PutAllPartialResult(-1);
}
/**
* consolidate exceptions
*/
public void consolidate(PutAllPartialResultException pre) {
this.result.consolidate(pre.getResult());
}
public void consolidate(PutAllPartialResult otherResult) {
this.result.consolidate(otherResult);
}
public PutAllPartialResult getResult() {
return this.result;
}
/**
* Returns the key set in exception
*/
public VersionedObjectList getSucceededKeysAndVersions() {
return this.result.getSucceededKeysAndVersions();
}
public Exception getFailure() {
return this.result.getFailure();
}
/**
* Returns there's failedKeys
*/
public boolean hasFailure() {
return this.result.hasFailure();
}
public Object getFirstFailedKey() {
return this.result.getFirstFailedKey();
}
@Override
public String getMessage() {
return this.result.toString();
}
public static class PutAllPartialResult implements Serializable {
private VersionedObjectList succeededKeys;
private Object firstFailedKey;
private Exception firstCauseOfFailure;
private int totalMapSize;
//////////////////// Constructors ////////////////////
/**
* Creates a new PutAllPartialResult
*/
public PutAllPartialResult(int totalMapSize) {
this.succeededKeys = new VersionedObjectList();
this.totalMapSize = totalMapSize;
}
public void setTotalMapSize(int totalMapSize) {
this.totalMapSize = totalMapSize;
}
public void consolidate(PutAllPartialResult other) {
synchronized(this.succeededKeys) {
this.succeededKeys.addAll(other.getSucceededKeysAndVersions());
}
saveFailedKey(other.firstFailedKey, other.firstCauseOfFailure);
}
public Exception getFailure() {
return this.firstCauseOfFailure;
}
/**
* record all succeeded keys in a version list response
*/
public void addKeysAndVersions(VersionedObjectList keysAndVersions) {
synchronized(this.succeededKeys){
this.succeededKeys.addAll(keysAndVersions);
}
}
/**
* record all succeeded keys when there are no version results
*/
public void addKeys(Collection