001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018:
019: package org.apache.roller.pojos;
020:
021: import java.io.Serializable;
022: import java.sql.Timestamp;
023:
024: /**
025: * Ping queue entry. Each instance of this class represents an entry on the ping queue. The entry indicates when it was
026: * added to the queue, which configuration to apply for the ping, and the number of ping attempts that have been made
027: * for this entry so far.
028: *
029: * @author <a href="mailto:anil@busybuddha.org">Anil Gangolli</a>
030: * @ejb:bean name="PingQueueEntryData"
031: * @hibernate.class lazy="false" table="pingqueueentry"
032: * @hibernate.cache usage="read-write"
033: */
034: public class PingQueueEntryData extends PersistentObject implements
035: Serializable {
036: private String id = null;
037: private Timestamp entryTime = null;
038: private PingTargetData pingTarget = null;
039: private WebsiteData website = null;
040: private int attempts = 0;
041:
042: public static final long serialVersionUID = -1468021030819538243L;
043:
044: /**
045: * Default constructor. Leaves all fields at Java-specified default values.
046: */
047: public PingQueueEntryData() {
048: }
049:
050: /**
051: * Construct with all members
052: *
053: * @param id unique id of this entry
054: * @param entryTime timestamp of first entry onto queue
055: * @param pingTarget target site to ping
056: * @param website website originating the ping
057: * @param attempts number of prior ping attempts
058: */
059: public PingQueueEntryData(String id, Timestamp entryTime,
060: PingTargetData pingTarget, WebsiteData website, int attempts) {
061: this .id = id;
062: this .entryTime = entryTime;
063: this .pingTarget = pingTarget;
064: this .website = website;
065: this .attempts = attempts;
066: }
067:
068: /**
069: * @see PersistentObject#setData(PersistentObject)
070: */
071: public void setData(PersistentObject vo) {
072: PingQueueEntryData other = (PingQueueEntryData) vo;
073:
074: id = other.getId();
075: entryTime = other.getEntryTime();
076: pingTarget = other.getPingTarget();
077: website = other.getWebsite();
078: attempts = other.getAttempts();
079: }
080:
081: /**
082: * Get the unique id (primary key) of this object.
083: *
084: * @return the unique id of this object.
085: * @ejb:persistent-field
086: * @hibernate.id column="id" generator-class="uuid.hex" unsaved-value="null"
087: */
088: public String getId() {
089: return id;
090: }
091:
092: /**
093: * Set the unique id (primary key) of this object.
094: *
095: * @param id
096: * @ejb:persistent-field
097: */
098: public void setId(String id) {
099: this .id = id;
100: }
101:
102: /**
103: * Get the entry time. Get the time this entry was first added to the queue.
104: *
105: * @return the time the entry was first added to the queue.
106: * @ejb:persistent-field
107: * @hibernate.property column="entrytime" non-null="true"
108: */
109: public Timestamp getEntryTime() {
110: return entryTime;
111: }
112:
113: /**
114: * Set the entry time.
115: *
116: * @param entryTime the time the entry was first added to the queue.
117: * @ejb:persistent-field
118: */
119: public void setEntryTime(Timestamp entryTime) {
120: this .entryTime = entryTime;
121: }
122:
123: /**
124: * Get the ping target. Get the target to ping.
125: *
126: * @return the ping target to ping.
127: * @ejb:persistent-field
128: * @hibernate.many-to-one column="pingtargetid" cascade="none" not-null="true"
129: */
130: public PingTargetData getPingTarget() {
131: return pingTarget;
132: }
133:
134: /**
135: * Set the ping target.
136: *
137: * @param pingTarget target to ping.
138: * @ejb:persistent-field
139: */
140: public void setPingTarget(PingTargetData pingTarget) {
141: this .pingTarget = pingTarget;
142: }
143:
144: /**
145: * Get the website originating the ping.
146: *
147: * @return the website originating the ping.
148: * @ejb:persistent-field
149: * @hibernate.many-to-one column="websiteid" cascade="none" not-null="true"
150: */
151: public WebsiteData getWebsite() {
152: return website;
153: }
154:
155: /**
156: * Set the website originating the ping.
157: *
158: * @param website the website originating the ping.
159: * @ejb:persistent-field
160: */
161: public void setWebsite(WebsiteData website) {
162: this .website = website;
163: }
164:
165: /**
166: * Get the number of ping attempts that have been made for this queue entry.
167: *
168: * @return the number of ping attempts that have been made for this queue entry.
169: * @ejb:persistent-field
170: * @hibernate.property column="attempts" non-null="true"
171: */
172: public int getAttempts() {
173: return attempts;
174: }
175:
176: /**
177: * Set the number of failures that have occurred for this queue entry.
178: *
179: * @param attempts
180: * @ejb:persistent-field
181: */
182: public void setAttempts(int attempts) {
183: this .attempts = attempts;
184: }
185:
186: /**
187: * Increment the number of failures for this queue entry.
188: *
189: * @return the new value.
190: */
191: public int incrementAttempts() {
192: return ++attempts;
193: }
194:
195: /**
196: * @see Object#equals(Object o)
197: */
198: public boolean equals(Object o) {
199: if (this == o)
200: return true;
201: if (!(o instanceof PingQueueEntryData))
202: return false;
203:
204: final PingQueueEntryData pingQueueEntryData = (PingQueueEntryData) o;
205:
206: if (attempts != pingQueueEntryData.getAttempts())
207: return false;
208: if (entryTime != null ? !entryTime.equals(pingQueueEntryData
209: .getEntryTime())
210: : pingQueueEntryData.getEntryTime() != null) {
211: return false;
212: }
213: if (id != null ? !id.equals(pingQueueEntryData.getId())
214: : pingQueueEntryData.getId() != null)
215: return false;
216: if (pingTarget != null ? !pingTarget.equals(pingQueueEntryData
217: .getPingTarget())
218: : pingQueueEntryData.getPingTarget() != null) {
219: return false;
220: }
221: if (website != null ? !website.equals(pingQueueEntryData
222: .getWebsite())
223: : pingQueueEntryData.getWebsite() != null) {
224: return false;
225: }
226:
227: return true;
228: }
229:
230: /**
231: * @see Object#hashCode()
232: */
233: public int hashCode() {
234: return (id != null ? id.hashCode() : 0);
235: }
236:
237: /**
238: * Generate a string form of the object appropriate for logging or debugging.
239: *
240: * @return a string form of the object appropriate for logging or debugging.
241: * @see Object#toString()
242: */
243: public String toString() {
244: return "PingQueueEntryData{"
245: + "id='"
246: + id
247: + "'"
248: + ", entryTime="
249: + entryTime
250: + ", pingTarget="
251: + pingTarget
252: + ", website= "
253: + (website == null ? "null" : "{id='" + website.getId()
254: + "'} ") + ", attempts=" + attempts + "}";
255: }
256: }
|