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