Attempt to make the bean thread-safe.
This commit is contained in:
parent
a874f75644
commit
bd8ce05082
1 changed files with 38 additions and 22 deletions
|
@ -149,6 +149,11 @@ public class LoginProcessBean {
|
||||||
public String formatMessage(Object[] args) {
|
public String formatMessage(Object[] args) {
|
||||||
return new MessageFormat(this.format).format(args);
|
return new MessageFormat(this.format).format(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Message[" + messageLevel + ", '" + format + "']";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -158,18 +163,21 @@ public class LoginProcessBean {
|
||||||
/** Where are we in the process? */
|
/** Where are we in the process? */
|
||||||
private State currentState = State.NOWHERE;
|
private State currentState = State.NOWHERE;
|
||||||
|
|
||||||
|
/** Where is the interaction taking place? */
|
||||||
|
private volatile String loginPageUrl;
|
||||||
|
|
||||||
|
/** Where do we go when finished? */
|
||||||
|
private volatile String afterLoginUrl;
|
||||||
|
|
||||||
|
/** message and messageArguments must be kept consistent. */
|
||||||
|
private final Object messageSynchronizer = new Object();
|
||||||
|
|
||||||
/** What message should we display on the screen? */
|
/** What message should we display on the screen? */
|
||||||
private Message message = Message.NO_MESSAGE;
|
private Message message = Message.NO_MESSAGE;
|
||||||
|
|
||||||
/** What arguments are needed to format the message? */
|
/** What arguments are needed to format the message? */
|
||||||
private Object[] messageArguments = NO_ARGUMENTS;
|
private Object[] messageArguments = NO_ARGUMENTS;
|
||||||
|
|
||||||
/** Where is the interaction taking place? */
|
|
||||||
private String loginPageUrl;
|
|
||||||
|
|
||||||
/** Where do we go when finished? */
|
|
||||||
private String afterLoginUrl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What username was submitted to the form? This isn't just for display --
|
* What username was submitted to the form? This isn't just for display --
|
||||||
* if they are changing passwords, we need to remember who it is.
|
* if they are changing passwords, we need to remember who it is.
|
||||||
|
@ -185,31 +193,39 @@ public class LoginProcessBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearMessage() {
|
public void clearMessage() {
|
||||||
this.message = Message.NO_MESSAGE;
|
synchronized (messageSynchronizer) {
|
||||||
this.messageArguments = NO_ARGUMENTS;
|
this.message = Message.NO_MESSAGE;
|
||||||
|
this.messageArguments = NO_ARGUMENTS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessage(Message message, Object... args) {
|
public void setMessage(Message message, Object... args) {
|
||||||
this.message = message;
|
synchronized (messageSynchronizer) {
|
||||||
this.messageArguments = args;
|
this.message = message;
|
||||||
|
this.messageArguments = args;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInfoMessageAndClear() {
|
public String getInfoMessageAndClear() {
|
||||||
String text = "";
|
synchronized (messageSynchronizer) {
|
||||||
if (message.getMessageLevel() == MLevel.INFO) {
|
String text = "";
|
||||||
text = message.formatMessage(messageArguments);
|
if (message.getMessageLevel() == MLevel.INFO) {
|
||||||
clearMessage();
|
text = message.formatMessage(messageArguments);
|
||||||
|
clearMessage();
|
||||||
|
}
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getErrorMessageAndClear() {
|
public String getErrorMessageAndClear() {
|
||||||
String text = "";
|
synchronized (messageSynchronizer) {
|
||||||
if (message.getMessageLevel() == MLevel.ERROR) {
|
String text = "";
|
||||||
text = message.formatMessage(messageArguments);
|
if (message.getMessageLevel() == MLevel.ERROR) {
|
||||||
clearMessage();
|
text = message.formatMessage(messageArguments);
|
||||||
|
clearMessage();
|
||||||
|
}
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
|
@ -238,8 +254,8 @@ public class LoginProcessBean {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "LoginProcessBean[state=" + currentState + ", message="
|
return "LoginProcessBean(" + hashCode() + ")[state=" + currentState
|
||||||
+ message + ", messageArguments="
|
+ ", message=" + message + ", messageArguments="
|
||||||
+ Arrays.deepToString(messageArguments) + ", username="
|
+ Arrays.deepToString(messageArguments) + ", username="
|
||||||
+ username + ", loginPageUrl=" + loginPageUrl
|
+ username + ", loginPageUrl=" + loginPageUrl
|
||||||
+ ", afterLoginUrl=" + afterLoginUrl + "]";
|
+ ", afterLoginUrl=" + afterLoginUrl + "]";
|
||||||
|
|
Loading…
Add table
Reference in a new issue