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 */
018
019package org.apache.oozie.client.event.message;
020
021import javax.jms.JMSException;
022import javax.jms.Message;
023
024import com.fasterxml.jackson.annotation.JsonIgnore;
025import org.apache.oozie.client.event.Event;
026import org.apache.oozie.client.event.Event.MessageType;
027import org.apache.oozie.client.event.jms.JMSHeaderConstants;
028import org.apache.oozie.AppType;
029
030/**
031 * Base class which holds attributes for event message
032 *
033 */
034public abstract class EventMessage {
035
036    private AppType appType;
037    private Event.MessageType messageType;
038
039    /**
040     * Default constructor for constructing event
041     */
042    public EventMessage() {
043        //Required for jackson
044    }
045
046    /**
047     * Constructs the event message using message type and app type
048     * @param messageType the message type
049     * @param appType the app type
050     */
051    protected EventMessage(MessageType messageType, AppType appType) {
052        this.messageType = messageType;
053        this.appType = appType;
054    }
055
056    /**
057     * Sets the appType for a event
058     * @param appType the app type
059     */
060    public void setAppType(AppType appType) {
061        this.appType = appType;
062    }
063
064    /**
065     * Returns the appType for a event
066     * @return the AppType
067     */
068    @JsonIgnore
069    public AppType getAppType() {
070        return appType;
071    }
072
073    /**
074     * Sets the message type for a event
075     * @param messageType the message type
076     */
077    public void setMessageType(MessageType messageType) {
078        this.messageType = messageType;
079    }
080
081    /**
082     * Returns the message type for a event
083     * @return the MessageType
084     */
085    @JsonIgnore
086    public MessageType getMessageType() {
087        return messageType;
088    }
089
090    /**
091     * Set the JMS selector properties for message object
092     * @param message the message
093     * @throws JMSException in case of a JMS error occurs
094     */
095    @JsonIgnore
096    public void setProperties(Message message) throws JMSException {
097        setAppType(AppType.valueOf(message.getStringProperty(JMSHeaderConstants.APP_TYPE)));
098        setMessageType(MessageType.valueOf(message.getStringProperty(JMSHeaderConstants.MESSAGE_TYPE)));
099    }
100
101}