Better Ping/UDP-close-hint management
This commit is contained in:
parent
f4b4efe714
commit
0a2da83a2c
|
@ -31,10 +31,12 @@ import dorkbox.network.connection.listenerManagement.OnConnectedManager;
|
|||
import dorkbox.network.connection.listenerManagement.OnDisconnectedManager;
|
||||
import dorkbox.network.connection.listenerManagement.OnIdleManager;
|
||||
import dorkbox.network.connection.listenerManagement.OnMessageReceivedManager;
|
||||
import dorkbox.network.connection.ping.PingMessage;
|
||||
import dorkbox.util.Property;
|
||||
import dorkbox.util.collections.ConcurrentEntry;
|
||||
import dorkbox.util.generics.ClassHelper;
|
||||
import dorkbox.util.generics.TypeResolver;
|
||||
import io.netty.bootstrap.DatagramCloseMessage;
|
||||
import io.netty.util.concurrent.ImmediateEventExecutor;
|
||||
import io.netty.util.concurrent.Promise;
|
||||
|
||||
|
@ -312,8 +314,30 @@ class ConnectionManager<C extends Connection> implements Listeners, ISessionMana
|
|||
@Override
|
||||
public final
|
||||
void onMessage(final ConnectionImpl connection, final Object message) {
|
||||
// add the ping listener (internal use only!)
|
||||
Class<?> messageClass = message.getClass();
|
||||
if (messageClass == PingMessage.class) {
|
||||
PingMessage ping = (PingMessage) message;
|
||||
if (ping.isReply) {
|
||||
connection.updatePingResponse(ping);
|
||||
}
|
||||
else {
|
||||
// return the ping from whence it came
|
||||
ping.isReply = true;
|
||||
|
||||
connection.ping0(ping);
|
||||
}
|
||||
}
|
||||
|
||||
// add the UDP "close hint" to close remote connections (internal use only!)
|
||||
else if (messageClass == DatagramCloseMessage.class) {
|
||||
connection.forceClose();
|
||||
}
|
||||
|
||||
else {
|
||||
notifyOnMessage0(connection, message, false);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
private
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 dorkbox, llc.
|
||||
*
|
||||
* 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 dorkbox.network.connection;
|
||||
|
||||
import io.netty.bootstrap.DatagramCloseMessage;
|
||||
|
||||
/**
|
||||
* Uses a hint to close remote UDP connections
|
||||
*/
|
||||
public
|
||||
class DatagramCloseListener implements Listener.OnMessageReceived<Connection, DatagramCloseMessage> {
|
||||
@Override
|
||||
public
|
||||
void received(final Connection connection, final DatagramCloseMessage message) {
|
||||
if (connection instanceof ConnectionImpl) {
|
||||
((ConnectionImpl) connection).forceClose();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import dorkbox.network.Configuration;
|
||||
import dorkbox.network.connection.bridge.ConnectionBridgeBase;
|
||||
import dorkbox.network.connection.ping.PingSystemListener;
|
||||
import dorkbox.network.connection.registration.MetaChannel;
|
||||
import dorkbox.network.connection.wrapper.ChannelLocalWrapper;
|
||||
import dorkbox.network.connection.wrapper.ChannelNetworkWrapper;
|
||||
|
@ -259,15 +258,6 @@ class EndPoint extends Shutdownable {
|
|||
//noinspection unchecked
|
||||
connectionManager = new ConnectionManager(type.getSimpleName(), connection0(null, null).getClass());
|
||||
|
||||
// add the ping listener (internal use only!)
|
||||
connectionManager.add(new PingSystemListener());
|
||||
|
||||
// add the UDP "close hint" to close remote connections (internal use only!)
|
||||
if (config.udpPort > 0) {
|
||||
connectionManager.add(new DatagramCloseListener());
|
||||
}
|
||||
|
||||
|
||||
if (rmiEnabled) {
|
||||
rmiHandler = null;
|
||||
localRmiHandler = new RmiObjectLocalHandler(logger);
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 dorkbox, llc
|
||||
*
|
||||
* 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 dorkbox.network.connection.ping;
|
||||
|
||||
import dorkbox.network.connection.ConnectionImpl;
|
||||
import dorkbox.network.connection.Listener;
|
||||
|
||||
public
|
||||
class PingSystemListener implements Listener.OnMessageReceived<ConnectionImpl, PingMessage> {
|
||||
|
||||
public
|
||||
PingSystemListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(ConnectionImpl connection, PingMessage ping) {
|
||||
if (ping.isReply) {
|
||||
connection.updatePingResponse(ping);
|
||||
} else {
|
||||
// return the ping from whence it came
|
||||
ping.isReply = true;
|
||||
|
||||
connection.ping0(ping);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user