mirror of
https://github.com/correl/mage.git
synced 2024-12-25 19:25:41 +00:00
Changed callbackException handling.
This commit is contained in:
parent
55b66315af
commit
ac81c5bbd4
1 changed files with 17 additions and 8 deletions
|
@ -66,9 +66,10 @@ public class Session {
|
||||||
private final Date timeConnected;
|
private final Date timeConnected;
|
||||||
private boolean isAdmin = false;
|
private boolean isAdmin = false;
|
||||||
private final AsynchInvokerCallbackHandler callbackHandler;
|
private final AsynchInvokerCallbackHandler callbackHandler;
|
||||||
private boolean error = false;
|
private boolean valid = true;
|
||||||
|
|
||||||
private final ReentrantLock lock;
|
private final ReentrantLock lock;
|
||||||
|
private final ReentrantLock callBackLock;
|
||||||
|
|
||||||
public Session(String sessionId, InvokerCallbackHandler callbackHandler) {
|
public Session(String sessionId, InvokerCallbackHandler callbackHandler) {
|
||||||
this.sessionId = sessionId;
|
this.sessionId = sessionId;
|
||||||
|
@ -76,6 +77,7 @@ public class Session {
|
||||||
this.isAdmin = false;
|
this.isAdmin = false;
|
||||||
this.timeConnected = new Date();
|
this.timeConnected = new Date();
|
||||||
this.lock = new ReentrantLock();
|
this.lock = new ReentrantLock();
|
||||||
|
this.callBackLock = new ReentrantLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String registerUser(String userName, String password, String email) throws MageException {
|
public String registerUser(String userName, String password, String email) throws MageException {
|
||||||
|
@ -371,20 +373,27 @@ public class Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fireCallback(final ClientCallback call) {
|
public void fireCallback(final ClientCallback call) {
|
||||||
if (error) {
|
boolean lockSet = false;
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
call.setMessageId(messageId++);
|
if (valid && callBackLock.tryLock(50, TimeUnit.MILLISECONDS)) {
|
||||||
callbackHandler.handleCallbackOneway(new Callback(call));
|
call.setMessageId(messageId++);
|
||||||
|
lockSet = true;
|
||||||
|
callbackHandler.handleCallbackOneway(new Callback(call));
|
||||||
|
}
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
logger.warn("SESSION LOCK - fireCallback - userId: " + userId + " messageId: " + call.getMessageId(), ex);
|
||||||
} catch (HandleCallbackException ex) {
|
} catch (HandleCallbackException ex) {
|
||||||
error = true; // to reduce repeated SESSION CALLBACK EXCEPTION
|
this.valid = false;
|
||||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||||
user.setUserState(User.UserState.Disconnected);
|
user.setUserState(User.UserState.Disconnected);
|
||||||
logger.warn("SESSION CALLBACK EXCEPTION - " + user.getName() + " userId " + userId + " - cause: " + getBasicCause(ex).toString());
|
logger.warn("SESSION CALLBACK EXCEPTION - " + user.getName() + " userId " + userId + " messageId: " + call.getMessageId() + " - cause: " + getBasicCause(ex).toString());
|
||||||
logger.trace("Stack trace:", ex);
|
logger.trace("Stack trace:", ex);
|
||||||
SessionManager.instance.disconnect(sessionId, LostConnection);
|
SessionManager.instance.disconnect(sessionId, LostConnection);
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
if (lockSet) {
|
||||||
|
callBackLock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue