001/* Copyright 2011-2012 the original author or authors:
002 *
003 *    Marc Palmer (marc@grailsrocks.com)
004 *    Stéphane Maldini (smaldini@vmware.com)
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.grails.plugin.platform.events;
019
020import org.grails.plugin.platform.events.dispatcher.GormTopicSupport;
021
022import java.io.Serializable;
023import java.util.Map;
024
025/**
026 * @author Stephane Maldini <smaldini@vmware.com>
027 * @version 1.0
028 * @file
029 * @date 30/12/11
030 * @section DESCRIPTION
031 * <p/>
032 * [Does stuff]
033 */
034public class EventMessage<D> implements Serializable {
035    final private String namespace;
036    final private String event;
037    final private D data;
038    final private Boolean gormSession;
039    final private Map<String, String> headers;
040
041    public EventMessage(String event, D data) {
042        this(event, data, null);
043    }
044
045    public EventMessage(String event, D data, String namespace) {
046        this(event, data, namespace, namespace == null || !namespace.equals(GormTopicSupport.GORM_SOURCE));
047    }
048
049    public EventMessage(String event, D data, String namespace, boolean gormSession) {
050        this(event, data, namespace, gormSession, null);
051    }
052
053    public EventMessage(String event, D data, String namespace, boolean gormSession, Map<String,String> headers) {
054        this.event = event;
055        this.data = data;
056        this.namespace = namespace;
057        this.gormSession = gormSession;
058        this.headers = headers;
059    }
060
061    public D getData() {
062        return data;
063    }
064
065
066    public String getNamespace() {
067        return namespace;
068    }
069
070
071    public String getEvent() {
072        return event;
073    }
074
075
076    public boolean isGormSession() {
077        return gormSession;
078    }
079
080    public Map<String, String> getHeaders() {
081        return headers;
082    }
083}