com.apipulse.bastion.actors.messages.StepMessage.java Source code

Java tutorial

Introduction

Here is the source code for com.apipulse.bastion.actors.messages.StepMessage.java

Source

/*
 * Bastion Data Ingestor
 * Copyright (c) 2016 API Fortress Inc.
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

package com.apipulse.bastion.actors.messages;

import org.apache.commons.lang.SerializationUtils;

import java.io.Serializable;

/**
 * The message wrapper. It is meant to contain the data and the context.
 */
public class StepMessage implements Cloneable {
    /**
     * The actual data
     */
    private Object data;
    /**
     * the message context
     */
    private final ChainContext context;

    /**
     * Basic constructor. The context will be automatically generateed
     * @param data the data
     */
    public StepMessage(Object data) {
        this(data, new ChainContext());
    }

    /**
     * Constructor
     * @param data the data
     * @param context a context
     */
    public StepMessage(Object data, ChainContext context) {
        this.data = data;
        this.context = context;
    }

    /**
     * @return the message context
     */
    public ChainContext getContext() {
        return context;
    }

    /**
     * @return the data
     */
    public Object getData() {
        return data;
    }

    /**
     * @param data the data
     */
    public void setData(Object data) {
        this.data = data;
    }

    /**
     * Clones the message
     * @return the cloned message
     */
    public StepMessage clone() {
        Object nData = data;
        if (data instanceof Serializable)
            nData = SerializationUtils.clone((Serializable) data);
        return new StepMessage(nData, context.clone());
    }
}