mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
fix session#getResultDistributor NullPointerException. #1579
This commit is contained in:
+9
-4
@@ -90,8 +90,10 @@ public class SessionManagerImpl implements SessionManager {
|
||||
ArrayList<Session> sessions = new ArrayList<Session>(this.sessions.values());
|
||||
for (Session session : sessions) {
|
||||
SharingResultDistributor resultDistributor = session.getResultDistributor();
|
||||
resultDistributor.appendResult(new MessageModel("arthas server is going to shutdown."));
|
||||
resultDistributor.close();
|
||||
if (resultDistributor != null) {
|
||||
resultDistributor.appendResult(new MessageModel("arthas server is going to shutdown."));
|
||||
resultDistributor.close();
|
||||
}
|
||||
logger.info("Removing session before shutdown: {}, last access time: {}", session.getSessionId(), session.getLastAccessTime());
|
||||
this.removeSession(session.getSessionId());
|
||||
}
|
||||
@@ -142,7 +144,10 @@ public class SessionManagerImpl implements SessionManager {
|
||||
}
|
||||
long timeOutInMinutes = sessionTimeoutMillis / 1000 / 60;
|
||||
String reason = "session is inactive for " + timeOutInMinutes + " min(s).";
|
||||
session.getResultDistributor().appendResult(new MessageModel(reason));
|
||||
SharingResultDistributor resultDistributor = session.getResultDistributor();
|
||||
if (resultDistributor != null) {
|
||||
resultDistributor.appendResult(new MessageModel(reason));
|
||||
}
|
||||
this.removeSession(session.getSessionId());
|
||||
logger.info("Removing inactive session: {}, last access time: {}", session.getSessionId(), session.getLastAccessTime());
|
||||
}
|
||||
@@ -153,7 +158,7 @@ public class SessionManagerImpl implements SessionManager {
|
||||
*/
|
||||
public void evictConsumers(Session session) {
|
||||
SharingResultDistributor distributor = session.getResultDistributor();
|
||||
if (distributor instanceof SharingResultDistributor) {
|
||||
if (distributor != null && distributor instanceof SharingResultDistributor) {
|
||||
SharingResultDistributor sharingResultDistributor = (SharingResultDistributor) distributor;
|
||||
List<ResultConsumer> consumers = sharingResultDistributor.getConsumers();
|
||||
//remove inactive consumer from session directly
|
||||
|
||||
+13
-3
@@ -321,7 +321,10 @@ public class HttpApiHandler {
|
||||
ResultConsumer resultConsumer = new ResultConsumerImpl();
|
||||
//disable input and interrupt
|
||||
resultConsumer.appendResult(new InputStatusModel(InputStatus.DISABLED));
|
||||
session.getResultDistributor().addConsumer(resultConsumer);
|
||||
SharingResultDistributor resultDistributor = session.getResultDistributor();
|
||||
if (resultDistributor != null) {
|
||||
resultDistributor.addConsumer(resultConsumer);
|
||||
}
|
||||
|
||||
ApiResponse response = new ApiResponse();
|
||||
response.setSessionId(session.getSessionId())
|
||||
@@ -486,7 +489,10 @@ public class HttpApiHandler {
|
||||
//add command before exec job
|
||||
CommandRequestModel commandRequestModel = new CommandRequestModel(commandLine, response.getState());
|
||||
commandRequestModel.setJobId(job.id());
|
||||
session.getResultDistributor().appendResult(commandRequestModel);
|
||||
SharingResultDistributor resultDistributor = session.getResultDistributor();
|
||||
if (resultDistributor != null) {
|
||||
resultDistributor.appendResult(commandRequestModel);
|
||||
}
|
||||
session.setForegroundJob(job);
|
||||
updateSessionInputStatus(session, InputStatus.ALLOW_INTERRUPT);
|
||||
|
||||
@@ -534,7 +540,11 @@ public class HttpApiHandler {
|
||||
if (StringUtils.isBlank(consumerId)) {
|
||||
throw new ApiException("'consumerId' is required");
|
||||
}
|
||||
ResultConsumer consumer = session.getResultDistributor().getConsumer(consumerId);
|
||||
ResultConsumer consumer = null;
|
||||
SharingResultDistributor resultDistributor = session.getResultDistributor();
|
||||
if (resultDistributor != null) {
|
||||
consumer = resultDistributor.getConsumer(consumerId);
|
||||
}
|
||||
if (consumer == null) {
|
||||
throw new ApiException("consumer not found: " + consumerId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user