com.gemstone.gemfire.internal.cache.execute.FunctionRemoteContext 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
The newest version!
/*
* 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.execute;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.DataSerializer;
import com.gemstone.gemfire.cache.execute.Function;
import com.gemstone.gemfire.cache.execute.FunctionService;
import com.gemstone.gemfire.internal.cache.TXStateInterface;
import com.gemstone.gemfire.internal.util.ArrayUtils;
/**
* FunctionContext for remote/target nodes
*
* @author Yogesh Mahajan
*
*/
public final class FunctionRemoteContext implements DataSerializable {
private Set filter;
private Object args;
private Set bucketSet;
private boolean isReExecute;
private boolean isFnSerializationReqd;
private String functionId;
private Function function;
private transient TXStateInterface txState;
public FunctionRemoteContext() {
}
public FunctionRemoteContext(final Function function, Object object,
Set filter, Set bucketSet, boolean isReExecute,
boolean isFnSerializationReqd, TXStateInterface tx) {
this.function = function;
this.args = object;
this.filter = filter;
this.bucketSet = bucketSet;
this.isReExecute = isReExecute;
this.isFnSerializationReqd = isFnSerializationReqd;
this.txState = tx;
}
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
Object object = DataSerializer.readObject(in);
if (object instanceof String) {
this.isFnSerializationReqd = false;
this.function = FunctionService.getFunction((String)object);
if (this.function == null) {
this.functionId = (String)object;
}
}
else {
this.function = (Function)object;
this.isFnSerializationReqd = true;
}
this.args = DataSerializer.readObject(in);
this.filter = DataSerializer.readHashSet(in);
this.bucketSet = (HashSet)DataSerializer.readHashSet(in);
this.isReExecute = DataSerializer.readBoolean(in);
}
public void toData(DataOutput out) throws IOException {
if (this.isFnSerializationReqd) {
DataSerializer.writeObject(this.function, out);
}
else {
DataSerializer.writeObject(function.getId(), out);
}
DataSerializer.writeObject(this.args, out);
DataSerializer.writeHashSet((HashSet)this.filter, out);
DataSerializer.writeHashSet((HashSet)this.bucketSet, out);
DataSerializer.writeBoolean(this.isReExecute, out);
}
public Set getFilter() {
return filter;
}
public Object getArgs() {
return args;
}
public Set getBucketSet() {
return bucketSet;
}
public boolean isReExecute() {
return isReExecute;
}
public Function getFunction() {
return function;
}
public String getFunctionId() {
return functionId;
}
public final TXStateInterface getTXState() {
return this.txState;
}
@Override
public String toString() {
final StringBuilder buff = new StringBuilder();
buff.append("{FunctionRemoteContext ");
buff.append("functionId=").append(this.functionId);
if (this.function != null) {
buff.append("; function=").append(this.function);
}
buff.append("; args=");
ArrayUtils.objectStringNonRecursive(this.args, buff);
buff.append("; isReExecute=").append(this.isReExecute);
buff.append("; filter=" + filter);
buff.append("; bucketSet=").append(this.bucketSet);
if (this.txState != null) {
buff.append("; txId=").append(this.txState.getTransactionId());
}
buff.append('}');
return buff.toString();
}
}