All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults Maven / Gradle / Ivy

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.tools.gfsh.command;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.DataSerializer;

/**
 * CommandResults contains the results obtained from executing a CommandTask. It
 * may also contain error code and/or exception generated by the server.
 * 
 * @author dpark
 * 
 */
public class CommandResults implements DataSerializable {
	private static final long serialVersionUID = 1L;

	public static final byte CODE_NORMAL = 0;
	public static final byte CODE_ERROR = -1;

	private Object key;
	private Object dataObject;
	private byte code = CODE_NORMAL;
	private String codeMessage;
	// Will need to make it simpler for supporting catching native clients
	// exception
	private String exception;
	
	/**
	 * Creates a new CommandResults. CommandResults.setDataObject() to set the
	 * data object that contains the task results.
	 */
	public CommandResults() {
	}

	/**
	 * Creates a new CommandResults object with the data object contains
	 * results.
	 * 
	 * @param dataObject
	 *            The data object that contains the task results.
	 */
	public CommandResults(Object dataObject) {
		this.dataObject = dataObject;
	}

	/**
	 * Returns the results set by CommandTask.
	 */
	public Object getDataObject() {
		return dataObject;
	}

	/**
	 * Returns the code set by the CommandTask. It is typically used for sending
	 * error code. The default value is 0.
	 * 
	 * @return code 
	 *///FIXME: java docs @return
	public byte getCode() {
		return code;
	}

	public void setCode(byte code) {
		this.code = code;
	}

	/**
	 * Returns the message associated with the code. The default value is null.
	 */
	public String getCodeMessage() {
		return codeMessage;
	}

	public void setCodeMessage(String codeMessage) {
		this.codeMessage = codeMessage;
	}

	public void setKey(Object key) {
		this.key = key;
	}

	public Object getKey() {
		return key;
	}

	/**
	 * Returns the server exception if any.
	 */
	public Throwable getException() {
		return new Throwable(exception);
	}

	public void setException(Throwable exception) {
		this.exception = exception.getMessage();
	}

	public void setDataObject(Object dataObject) {
		this.dataObject = dataObject;
	}

	public void toData(DataOutput out) throws IOException {
		out.writeByte(code);
		DataSerializer.writeObject(codeMessage, out);
		DataSerializer.writeObject(dataObject, out);
		DataSerializer.writeObject(exception, out);
	}

	public void fromData(DataInput in) throws IOException,
			ClassNotFoundException {
		code = in.readByte();
		codeMessage = (String)DataSerializer.readObject(in);
		dataObject = DataSerializer.readObject(in);
		exception = (String)DataSerializer.readObject(in);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy