notifySetupFailureAndDisconnect(
loggingIn ?
new LoginFailureException(
LOGIN_REFUSED_REASON,
LoginFailureException.FailureReason.SERVER_UNAVAILABLE) :
new RelocateFailureException(
RELOCATE_REFUSED_REASON,
RelocateFailureException.FailureReason.SERVER_UNAVAILABLE));
return;
}
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "identity:{0} assigned to node:{1}",
identity, assignedNodeId);
}
if (assignedNodeId == sessionService.getLocalNodeId()) {
/*
* Handle this login (or relocation) request locally. First,
* validate that the user is allowed to log in (or relocate).
*/
if (!sessionService.validateUserLogin(
identity, ClientSessionHandler.this, loggingIn))
{
// This client session is not allowed to proceed.
if (logger.isLoggable(Level.FINE)) {
logger.log(
Level.FINE,
"{0} rejected to node:{1} identity:{2}",
(loggingIn ? "User login" : "Session relocation"),
sessionService.getLocalNodeId(), identity);
}
notifySetupFailureAndDisconnect(
loggingIn ?
new LoginFailureException(
LOGIN_REFUSED_REASON,
LoginFailureException.FailureReason.DUPLICATE_LOGIN) :
new RelocateFailureException(
RELOCATE_REFUSED_REASON,
RelocateFailureException.
FailureReason.DUPLICATE_LOGIN));
return;
}
taskQueue = sessionService.createTaskQueue();
/*
* If logging in, store the client session in the data store.
*/
if (loggingIn) {
CreateClientSessionTask createTask =
new CreateClientSessionTask();
try {
sessionService.runTransactionalTask(createTask, identity);
} catch (Exception e) {
logger.logThrow(
Level.WARNING, e,
"Storing ClientSession for identity:{0} throws",
identity);
notifySetupFailureAndDisconnect(
new LoginFailureException(LOGIN_REFUSED_REASON, e));
return;
}
sessionRefId = createTask.getId();
}
/*
* Inform the session service that this handler is available. If
* logging in, schedule a task to perform client login (which calls
* the AppListener.loggedIn method), otherwise set the "relocating"
* flag in the client session's state to false to indicate that
* relocation is complete.
*/
sessionService.addHandler(
sessionRefId, ClientSessionHandler.this,
loggingIn ? null : identity);
if (loggingIn) {
scheduleTask(new LoginTask());
} else {
try {
sessionService.runTransactionalTask(
new AbstractKernelRunnable("SetSessionRelocated") {
public void run() {
ClientSessionImpl sessionImpl =
ClientSessionImpl.getSession(
dataService, sessionRefId);
sessionImpl.relocationComplete();
} }, identity);
setupSuccess();
} catch (Exception e) {
logger.logThrow(
Level.WARNING, e,
"Relocating ClientSession for identity:{0} " +
"to local node:{1} throws",
identity, sessionService.getLocalNodeId());
notifySetupFailureAndDisconnect(
new RelocateFailureException(
RELOCATE_REFUSED_REASON, e));
return;
}
}