View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.model;
12  
13  import java.util.ArrayList;
14  import java.util.Date;
15  import java.util.List;
16  import java.util.Locale;
17  
18  /**
19   * POJO representing HTTP session.
20   */
21  public class ApplicationSession {
22  
23    /** The Constant LAST_ACCESSED_BY_IP. */
24    public static final String LAST_ACCESSED_BY_IP = "__psiprobe_la_ip";
25  
26    /** The Constant LAST_ACCESSED_LOCALE. */
27    public static final String LAST_ACCESSED_LOCALE = "__psiprobe_la_local";
28  
29    /** The id. */
30    private String id;
31  
32    /** The application name. */
33    private String applicationName;
34  
35    /** The creation time. */
36    private Date creationTime;
37  
38    /** The last access time. */
39    private Date lastAccessTime;
40  
41    /** The max idle time. */
42    private int maxIdleTime;
43  
44    /** The valid. */
45    private boolean valid;
46  
47    /** The serializable. */
48    private boolean serializable;
49  
50    /** The object count. */
51    private long objectCount;
52  
53    /** The info. */
54    private String info;
55  
56    /** The manager type. */
57    private String managerType;
58  
59    /** The attributes. */
60    private List<Attribute> attributes = new ArrayList<>();
61  
62    /** The size. */
63    private long size;
64  
65    /** The allowed to view values. */
66    private boolean allowedToViewValues;
67  
68    /** The last accessed ip. */
69    private String lastAccessedIp;
70  
71    /** The last accessed ip locale. */
72    private Locale lastAccessedIpLocale;
73  
74    /**
75     * Gets the id.
76     *
77     * @return the id
78     */
79    public String getId() {
80      return id;
81    }
82  
83    /**
84     * Sets the id.
85     *
86     * @param id the new id
87     */
88    public void setId(String id) {
89      this.id = id;
90    }
91  
92    /**
93     * Gets the application name.
94     *
95     * @return the application name
96     */
97    public String getApplicationName() {
98      return applicationName;
99    }
100 
101   /**
102    * Sets the application name.
103    *
104    * @param applicationName the new application name
105    */
106   public void setApplicationName(String applicationName) {
107     this.applicationName = applicationName;
108   }
109 
110   /**
111    * Gets the creation time.
112    *
113    * @return the creation time
114    */
115   public Date getCreationTime() {
116     return creationTime == null ? null : new Date(creationTime.getTime());
117   }
118 
119   /**
120    * Sets the creation time.
121    *
122    * @param creationTime the new creation time
123    */
124   public void setCreationTime(Date creationTime) {
125     this.creationTime = creationTime == null ? null : new Date(creationTime.getTime());
126   }
127 
128   /**
129    * Gets the last access time.
130    *
131    * @return the last access time
132    */
133   public Date getLastAccessTime() {
134     return lastAccessTime == null ? null : new Date(lastAccessTime.getTime());
135   }
136 
137   /**
138    * Sets the last access time.
139    *
140    * @param lastAccessTime the new last access time
141    */
142   public void setLastAccessTime(Date lastAccessTime) {
143     this.lastAccessTime = lastAccessTime == null ? null : new Date(lastAccessTime.getTime());
144   }
145 
146   /**
147    * Gets the max idle time.
148    *
149    * @return the max idle time
150    */
151   public int getMaxIdleTime() {
152     return maxIdleTime;
153   }
154 
155   /**
156    * Sets the max idle time.
157    *
158    * @param maxIdleTime the new max idle time
159    */
160   public void setMaxIdleTime(int maxIdleTime) {
161     this.maxIdleTime = maxIdleTime;
162   }
163 
164   /**
165    * Checks if is valid.
166    *
167    * @return true, if is valid
168    */
169   public boolean isValid() {
170     return valid;
171   }
172 
173   /**
174    * Sets the valid.
175    *
176    * @param valid the new valid
177    */
178   public void setValid(boolean valid) {
179     this.valid = valid;
180   }
181 
182   /**
183    * Gets the object count.
184    *
185    * @return the object count
186    */
187   public long getObjectCount() {
188     return objectCount;
189   }
190 
191   /**
192    * Sets the object count.
193    *
194    * @param objectCount the new object count
195    */
196   public void setObjectCount(long objectCount) {
197     this.objectCount = objectCount;
198   }
199 
200   /**
201    * Gets the attributes.
202    *
203    * @return the attributes
204    */
205   public List<Attribute> getAttributes() {
206     return attributes;
207   }
208 
209   /**
210    * Sets the attributes.
211    *
212    * @param attributes the new attributes
213    */
214   public void setAttributes(List<Attribute> attributes) {
215     this.attributes = attributes;
216   }
217 
218   /**
219    * Adds the attribute.
220    *
221    * @param sa the sa
222    */
223   public void addAttribute(Attribute sa) {
224     attributes.add(sa);
225   }
226 
227   /**
228    * Gets the info.
229    *
230    * @return the info
231    */
232   public String getInfo() {
233     return info;
234   }
235 
236   /**
237    * Sets the info.
238    *
239    * @param info the new info
240    */
241   public void setInfo(String info) {
242     this.info = info;
243   }
244 
245   /**
246    * Gets the manager type.
247    *
248    * @return the manager type
249    */
250   public String getManagerType() {
251     return managerType;
252   }
253 
254   /**
255    * Sets the manager type.
256    *
257    * @param managerType the new manager type
258    */
259   public void setManagerType(String managerType) {
260     this.managerType = managerType;
261   }
262 
263   /**
264    * Gets the age.
265    *
266    * @return the age
267    */
268   public long getAge() {
269     if (creationTime == null) {
270       return 0;
271     }
272     return System.currentTimeMillis() - creationTime.getTime();
273   }
274 
275   /**
276    * Gets the idle time.
277    *
278    * @return the idle time
279    */
280   public long getIdleTime() {
281     if (lastAccessTime == null) {
282       return getAge();
283     }
284     return System.currentTimeMillis() - lastAccessTime.getTime();
285   }
286 
287   /**
288    * Gets the expiry time.
289    *
290    * @return the expiry time
291    */
292   public Date getExpiryTime() {
293     if (getMaxIdleTime() <= 0) {
294       return null;
295     }
296     return new Date(System.currentTimeMillis() + getMaxIdleTime() - getIdleTime());
297   }
298 
299   /**
300    * Checks if is serializable.
301    *
302    * @return true, if is serializable
303    */
304   public boolean isSerializable() {
305     return serializable;
306   }
307 
308   /**
309    * Sets the serializable.
310    *
311    * @param serializable the new serializable
312    */
313   public void setSerializable(boolean serializable) {
314     this.serializable = serializable;
315   }
316 
317   /**
318    * Gets the size.
319    *
320    * @return the size
321    */
322   public long getSize() {
323     return size;
324   }
325 
326   /**
327    * Sets the size.
328    *
329    * @param size the new size
330    */
331   public void setSize(long size) {
332     this.size = size;
333   }
334 
335   /**
336    * Checks if is allowed to view values.
337    *
338    * @return true, if is allowed to view values
339    */
340   public boolean isAllowedToViewValues() {
341     return allowedToViewValues;
342   }
343 
344   /**
345    * Sets the allowed to view values.
346    *
347    * @param allowedToViewValues the new allowed to view values
348    */
349   public void setAllowedToViewValues(boolean allowedToViewValues) {
350     this.allowedToViewValues = allowedToViewValues;
351   }
352 
353   /**
354    * Gets the last accessed ip.
355    *
356    * @return the last accessed ip
357    */
358   public String getLastAccessedIp() {
359     return lastAccessedIp;
360   }
361 
362   /**
363    * Sets the last accessed ip.
364    *
365    * @param lastAccessedIp the new last accessed ip
366    */
367   public void setLastAccessedIp(String lastAccessedIp) {
368     this.lastAccessedIp = lastAccessedIp;
369   }
370 
371   /**
372    * Gets the last accessed ip locale.
373    *
374    * @return the last accessed ip locale
375    */
376   public Locale getLastAccessedIpLocale() {
377     return lastAccessedIpLocale;
378   }
379 
380   /**
381    * Sets the last accessed ip locale.
382    *
383    * @param lastAccessedIpLocale the new last accessed ip locale
384    */
385   public void setLastAccessedIpLocale(Locale lastAccessedIpLocale) {
386     this.lastAccessedIpLocale = lastAccessedIpLocale;
387   }
388 
389 }