001/* 002 * $RCSfile: Transient.java,v $ 003 * $Revision: 1.15.6.2 $ 004 * $Date: 2015/04/29 15:48:53 $ 005 * 006 * Copyright 2013 Cloud Software Group, Inc. ALL RIGHTS RESERVED. 007 * Cloud Software Group, Inc. Confidential Information 008 */ 009package com.tibco.xp.runtime; 010 011import com.kabira.platform.ObjectNotUniqueError; 012import com.kabira.platform.ResourceUnavailableException; 013import com.tibco.cep.runtime.model.event.EventContext; 014import com.tibco.cep.runtime.model.event.impl.SimpleEventImpl; 015 016/** 017 * Base class for transient events. 018 * <p> 019 * A transient event is one that has a TTL of 0. It is 020 * not stored in shared memory and is automatically 021 * destroyed at the end of the RTC 022 */ 023public abstract class Transient extends Event 024{ 025 /** 026 * Java constructor 027 */ 028 protected Transient() 029 { 030 } 031 032 /** 033 * Rule or Rule Function constructor 034 * @param id Unique identifier 035 */ 036 protected Transient(long id) 037 { 038 register(id); 039 } 040 041 @Override 042 public String toString() 043 { 044 StringBuilder value = new StringBuilder(super.toString()); 045 046 value.append("&context="); 047 value.append(Transient.getChannelContext(this)); 048 049 return value.toString(); 050 } 051 052 @Override 053 public final void delete() 054 { 055 // Delete is a noop for transient events 056 } 057 058 @Override 059 public final Boolean getRetryOnException() 060 { 061 return m_retryOnException; 062 } 063 064 @Override 065 public final Long getTimeToLive() 066 { 067 return m_timeToLive; 068 } 069 070 @Override 071 public final String getTimeToLiveUnits() 072 { 073 return m_timeToLiveUnits; 074 } 075 076 @Override 077 public final void assertEvent() throws ObjectNotUniqueError, ResourceUnavailableException 078 { 079 // TODO - Work-around for FLUENCY-5593. 080 super.assertEvent(); 081 } 082 083 @Override 084 protected final void setRetryOnException(Boolean retryOnException) 085 { 086 m_retryOnException = retryOnException; 087 } 088 089 @Override 090 public final PayLoad getPayLoad() 091 { 092 return m_payload; 093 } 094 095 /** 096 * Update user properties from shared memory 097 * @param eventImpl Event handle to update 098 */ 099 protected abstract void updateUserProperties(SimpleEventImpl eventImpl); 100 101 @Override 102 protected final void updatePayLoad(PayLoad payload) 103 { 104 m_payload = payload; 105 } 106 107 @Override 108 protected final void setTimeToLive(Long timeToLive) 109 { 110 assert timeToLive == 0 : timeToLive; 111 m_timeToLive = timeToLive; 112 } 113 114 @Override 115 protected final void setTimeToLiveUnits(String timeToLiveUnits) 116 { 117 m_timeToLiveUnits = timeToLiveUnits; 118 } 119 120 @Override 121 public final void setDestination(final String destination) 122 { 123 enforceDispatchState(); 124 125 if (destination == null) 126 { 127 throw new IllegalArgumentException("Destination cannot be null"); 128 } 129 130 m_destination = destination; 131 } 132 133 @Override 134 public final String getDestination() 135 { 136 return m_destination; 137 } 138 139 @Override 140 protected final Boolean getDispatched() 141 { 142 return m_dispatched; 143 } 144 145 @Override 146 protected final void setDispatched() 147 { 148 m_dispatched = true; 149 } 150 151 @Override 152 final String getTimerIdentifier() 153 { 154 return _INVALID_TIMER_IDENTIFIER; 155 } 156 157 @Override 158 final void setTimerIdentifier(final String identifier) 159 { 160 assert false : identifier; 161 } 162 163 @Override 164 protected final void updateProperties() 165 { 166 assert EntityProxy.getProxy(this) instanceof EventProxy : this; 167 assert getHandle(false) instanceof SimpleEventImpl : this; 168 169 EventProxy proxy = (EventProxy)EntityProxy.getProxy(this); 170 SimpleEventImpl handle = (SimpleEventImpl) getHandle(false); 171 172 proxy.updateMetaProperties(handle); 173 updateUserProperties(handle); 174 } 175 176 /** 177 * Get the channel context for an event 178 * @param event Event event 179 * @return Channel context for this event, may be null 180 * <p> 181 * N.B. This method is static to be consistent with the 182 * non-transient event method. 183 */ 184 static final EventContext getChannelContext(Transient event) 185 { 186 assert event != null; 187 return event.m_context; 188 } 189 190 /** 191 * Set the channel context for an event 192 * @param event Event 193 * @param context Channel context to set, may be null 194 * <p> 195 * N.B. This method is static to be consistent with the 196 * non-transient event method. 197 */ 198 static final void setChannelContext(Transient event, EventContext context) 199 { 200 assert event != null; 201 event.m_context = context; 202 } 203 204 private boolean m_dispatched = false; 205 private boolean m_retryOnException = _DEFAULT_RETRY_ON_EXCEPTION; 206 private long m_timeToLive = _DEFAULT_TIME_TO_LIVE; 207 private String m_timeToLiveUnits = _TIME_TO_LIVE_UNITS_DEFAULT; 208 private PayLoad m_payload = null; 209 private String m_destination = null; 210 private EventContext m_context = null; 211 private static final long serialVersionUID = 4L; 212}