Skip to content

Commit

Permalink
Merge pull request #212 from dshurt/socketio-fix-2.3.x
Browse files Browse the repository at this point in the history
#211 - Socket IO Module - Hanging on Shutdown
  • Loading branch information
jfarcand committed Oct 26, 2015
2 parents 668c9be + a46bbb5 commit fdd33c9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.atmosphere.cpr.AtmosphereHandler;
import org.atmosphere.cpr.AtmosphereResourceImpl;
import org.atmosphere.socketio.cpr.SocketIOAtmosphereHandler;
import org.atmosphere.socketio.transport.DisconnectReason;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,58 @@
/*
* Copyright 2014 Sebastien Dionne
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.atmosphere.socketio;

/**
* @author Sebastien Dionne : sebastien.dionne@gmail.com
*/
public interface SocketIOSessionManager extends SocketIOSessionFactory {

/**
* @param timeout
*/
void setTimeout(long timeout);

/**
* @return
*/
long getTimeout();

/**
* @param interval
*/
void setHeartbeatInterval(long interval);

/**
* @return
*/
long getHeartbeatInterval();

/**
* @param suspendTime
*/
void setRequestSuspendTime(long suspendTime);

/**
* @return
*/
long getRequestSuspendTime();
}
/*
* Copyright 2014 Sebastien Dionne
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.atmosphere.socketio;

/**
* @author Sebastien Dionne : sebastien.dionne@gmail.com
*/
public interface SocketIOSessionManager extends SocketIOSessionFactory {

/**
* @param timeout
*/
void setTimeout(long timeout);

/**
* @return
*/
long getTimeout();

/**
* @param interval
*/
void setHeartbeatInterval(long interval);

/**
* @return
*/
long getHeartbeatInterval();

/**
* @param suspendTime
*/
void setRequestSuspendTime(long suspendTime);

/**
* @return
*/
long getRequestSuspendTime();

/**
* This will destroy the session manager and release resources.
*/
void destory();

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
package org.atmosphere.socketio.cpr;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.atmosphere.config.service.AtmosphereInterceptorService;
import org.atmosphere.cpr.Action;
import org.atmosphere.cpr.AsyncIOWriter;
Expand All @@ -32,19 +36,13 @@
import org.atmosphere.socketio.transport.JSONPPollingTransport;
import org.atmosphere.socketio.transport.SocketIOPacketImpl;
import org.atmosphere.socketio.transport.SocketIOSessionManagerImpl;
import static org.atmosphere.socketio.transport.SocketIOSessionManagerImpl.mapper;
import org.atmosphere.socketio.transport.Transport;
import org.atmosphere.socketio.transport.WebSocketTransport;
import org.atmosphere.socketio.transport.XHRPollingTransport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static org.atmosphere.socketio.transport.SocketIOSessionManagerImpl.mapper;

/**
* SocketIO implementation.
*
Expand Down Expand Up @@ -250,6 +248,7 @@ public void postInspect(AtmosphereResource r) {

@Override
public void destroy() {
sessionManager.destory();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.concurrent.atomic.AtomicLong;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.concurrent.TimeUnit;
import org.atmosphere.cpr.AtmosphereHandler;
import org.atmosphere.cpr.AtmosphereRequest;
import org.atmosphere.cpr.AtmosphereResourceEventImpl;
Expand Down Expand Up @@ -151,6 +152,16 @@ public long getRequestSuspendTime() {
return requestSuspendTime;
}

@Override
public void destory() {
executor.shutdownNow();
try {
executor.awaitTermination(1, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
logger.debug("Interrupted while waiting for executor to terminate. (Continuing)", ex);
}
}

private class SessionImpl implements SocketIOSession {
private final String sessionId;

Expand Down

0 comments on commit fdd33c9

Please sign in to comment.