001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  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.apache.oozie.client.event.message;
019
020import java.util.Map;
021
022import javax.jms.JMSException;
023import javax.jms.Message;
024
025import org.apache.oozie.client.event.Event;
026import org.apache.oozie.client.event.Event.MessageType;
027import org.apache.oozie.client.event.JobEvent.EventStatus;
028import org.apache.oozie.client.event.jms.JMSHeaderConstants;
029import org.apache.oozie.AppType;
030import org.codehaus.jackson.annotate.JsonIgnore;
031
032/**
033 * Base class which holds attributes for event message
034 *
035 */
036public abstract class EventMessage {
037
038    private AppType appType;
039    private Event.MessageType messageType;
040
041    /**
042     * Default constructor for constructing event
043     */
044    public EventMessage() {
045        //Required for jackson
046    }
047
048    /**
049     * Constructs the event message using message type and app type
050     * @param messageType the message type
051     * @param appType the app type
052     */
053    protected EventMessage(MessageType messageType, AppType appType) {
054        this.messageType = messageType;
055        this.appType = appType;
056    }
057
058    /**
059     * Sets the appType for a event
060     * @param appType
061     */
062    public void setAppType(AppType appType) {
063        this.appType = appType;
064    }
065
066    /**
067     * Returns the appType for a event
068     * @return the AppType
069     */
070    @JsonIgnore
071    public AppType getAppType() {
072        return appType;
073    }
074
075    /**
076     * Sets the message type for a event
077     * @param messageType
078     */
079    public void setMessageType(MessageType messageType) {
080        this.messageType = messageType;
081    }
082
083    /**
084     * Returns the message type for a event
085     * @return the MessageType
086     */
087    @JsonIgnore
088    public MessageType getMessageType() {
089        return messageType;
090    }
091
092    /**
093     * Set the JMS selector properties for message object
094     * @param message
095     * @throws JMSException
096     */
097    @JsonIgnore
098    public void setProperties(Message message) throws JMSException {
099        setAppType(AppType.valueOf(message.getStringProperty(JMSHeaderConstants.APP_TYPE)));
100        setMessageType(MessageType.valueOf(message.getStringProperty(JMSHeaderConstants.MESSAGE_TYPE)));
101    }
102
103}