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

net.anotheria.anoprise.eventservice.Event Maven / Gradle / Ivy

Go to download

Collection of utils for different enterprise class projects. Among other stuff contains Caches, Mocking, DualCrud, MetaFactory and SessionDistributorService. Visit https://opensource.anotheria.net for details.

There is a newer version: 4.0.0
Show newest version
package net.anotheria.anoprise.eventservice;

import java.io.Serializable;

import net.anotheria.util.Date;

/**
 * An event. Something which can somehow occur and is worth being sent over an event channel.
 * @author lrosenberg
 * Created on 22.09.2004
 */
public class Event implements Serializable, Cloneable{
	
	/**
	 * Serial versionuid.
	 */
	private static final long serialVersionUID = -956595007030617361L;
	/**
	 * Default originator.
	 */
	public static final String NO_ORIGINATOR = "Unknown";
	
	/**
	 * Creation timestamp of this event.
	 */
	private long timestamp;
	/**
	 * Originator of the event, i.e. the creator or sender.
	 */
	private String originator;
	/**
	 * Custom event data.
	 */
	private Serializable data;
	
	/**
	 * If true this event will not be passed to any 'real' consumers, but only used to check the communication path.
	 */
	private boolean nonExistent;
	
	public Event(){
		this(EventServiceConstants.NO_EVENT_ORIGINATOR, null);
	}
	
	public Event(Serializable data){
		this(EventServiceConstants.NO_EVENT_ORIGINATOR, data);
	}
	
	public Event(String anOriginator, Serializable aData){
		timestamp = System.currentTimeMillis();
		originator = anOriginator;
		data      = aData;
		nonExistent = false;
	}
	
	/**
	 * @return
	 */
	public Serializable getData() {
		return data;
	}

	/**
	 * @return
	 */
	public String getOriginator() {
		return originator;
	}

	/**
	 * @return
	 */
	public long getTimestamp() {
		return timestamp;
	}

	/**
	 * @param serializable
	 */
	public void setData(Serializable serializable) {
		data = serializable;
	}

	/**
	 * @param string
	 */
	public void setOriginator(String string) {
		originator = string;
	}
	
	@Override
	public String toString(){
		return "Event from "+originator+" at "+new Date(timestamp)+" with data: "+data;
	}

	public boolean isNonExistent() {
		return nonExistent;
	}

	public void setNonExistent(boolean nonExistent) {
		this.nonExistent = nonExistent;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy