Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
jsf/pastecode/src/main/java/org/jboss/weld/examples/pastecode/session/PostTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.jboss.weld.examples.pastecode.session; | ||
|
||
import java.util.Date; | ||
import java.util.LinkedList; | ||
|
||
import javax.ejb.Stateful; | ||
import javax.enterprise.context.SessionScoped; | ||
import javax.inject.Inject; | ||
|
||
@SessionScoped | ||
@Stateful // Add passivation capabilities.... | ||
public class PostTracker | ||
{ | ||
|
||
private LinkedList<Date> posts; | ||
|
||
@Inject DatabasePopulater databasePopulater; | ||
|
||
public PostTracker() | ||
{ | ||
this.posts = new LinkedList<Date>(); | ||
} | ||
|
||
public void addPost() | ||
{ | ||
this.posts.offerFirst(new Date()); | ||
} | ||
|
||
public boolean isNewPostAllowed() | ||
{ | ||
// if we are populating the database, skip | ||
if (!databasePopulater.isPopulated()) | ||
{ | ||
return true; | ||
} | ||
long diff = new Date().getTime() - posts.get(2).getTime(); | ||
return diff > 20 * 1000; | ||
} | ||
|
||
} |