You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2017/07/10 18:00:35 UTC
[12/51] [abbrv] geode git commit: GEODE-3130: Refactoring AcceptorImpl
GEODE-3130: Refactoring AcceptorImpl
We extracted a switch statement in AcceptorImpl.handleNewClientConnection to a new method.
Signed-off-by: Alexander Murmann <am...@pivotal.io>
This closes #602
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/06961ec1
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/06961ec1
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/06961ec1
Branch: refs/heads/feature/GEODE-3109
Commit: 06961ec164d6b76fd6a33c3e814c7ce46786c4ea
Parents: ff6cbf3
Author: Brian Rowe <br...@pivotal.io>
Authored: Mon Jun 26 11:22:03 2017 -0700
Committer: Hitesh Khamesra <hk...@pivotal.io>
Committed: Tue Jun 27 14:42:57 2017 -0700
----------------------------------------------------------------------
.../cache/tier/sockets/AcceptorImpl.java | 61 +++++++++-----------
.../tier/sockets/AcceptorImplJUnitTest.java | 16 ++---
2 files changed, 31 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/06961ec1/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
index 50f7006..472af09 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
@@ -1449,42 +1449,16 @@ public class AcceptorImpl extends Acceptor implements Runnable {
socket.setTcpNoDelay(this.tcpNoDelay);
String communicationModeStr;
- switch (communicationMode) {
- default:
- throw new IOException("Acceptor received unknown communication mode: " + communicationMode);
-
- case PRIMARY_SERVER_TO_CLIENT:
- logger.debug(
- ":Bridge server: Initializing primary server-to-client communication socket: {}",
- socket);
- AcceptorImpl.this.clientNotifier.registerClient(socket, true, this.acceptorId,
- this.notifyBySubscription);
- return;
-
- case SECONDARY_SERVER_TO_CLIENT:
- logger.debug(
- ":Bridge server: Initializing secondary server-to-client communication socket: {}",
- socket);
- AcceptorImpl.this.clientNotifier.registerClient(socket, false, this.acceptorId,
- this.notifyBySubscription);
- return;
-
- case CLIENT_TO_SERVER:
- communicationModeStr = "client";
- break;
- case GATEWAY_TO_GATEWAY:
- communicationModeStr = "gateway";
- break;
- case MONITOR_TO_SERVER:
- communicationModeStr = "monitor";
- break;
- case CLIENT_TO_SERVER_FOR_QUEUE:
- communicationModeStr = "clientToServerForQueue";
- break;
- case PROTOBUF_CLIENT_SERVER_PROTOCOL:
- communicationModeStr = "Protobuf client";
- break;
+ if (communicationMode == PRIMARY_SERVER_TO_CLIENT
+ || communicationMode == SECONDARY_SERVER_TO_CLIENT) {
+ boolean primary = communicationMode == PRIMARY_SERVER_TO_CLIENT;
+ logger.debug(":Bridge server: Initializing {} server-to-client communication socket: {}",
+ primary ? "primary" : "secondary", socket);
+ AcceptorImpl.this.clientNotifier.registerClient(socket, primary, this.acceptorId,
+ this.notifyBySubscription);
+ return;
}
+ communicationModeStr = getCommunicationMode(communicationMode);
logger.debug("Bridge server: Initializing {} communication socket: {}", communicationModeStr,
socket);
@@ -1544,6 +1518,23 @@ public class AcceptorImpl extends Acceptor implements Runnable {
}
}
+ private String getCommunicationMode(byte communicationMode) throws IOException {
+ switch (communicationMode) {
+ default:
+ throw new IOException("Acceptor received unknown communication mode: " + communicationMode);
+ case CLIENT_TO_SERVER:
+ return "client";
+ case GATEWAY_TO_GATEWAY:
+ return "gateway";
+ case MONITOR_TO_SERVER:
+ return "monitor";
+ case CLIENT_TO_SERVER_FOR_QUEUE:
+ return "clientToServerForQueue";
+ case PROTOBUF_CLIENT_SERVER_PROTOCOL:
+ return "Protobuf client";
+ }
+ }
+
@Override
public boolean isRunning() {
return !this.shutdownStarted;
http://git-wip-us.apache.org/repos/asf/geode/blob/06961ec1/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImplJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImplJUnitTest.java
index 7aa11b7..1fe5980 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImplJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImplJUnitTest.java
@@ -14,21 +14,19 @@
*/
package org.apache.geode.internal.cache.tier.sockets;
-import org.apache.geode.cache.AttributesFactory;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import org.apache.geode.cache.CacheException;
import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.client.ServerRefusedConnectionException;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
-import org.apache.geode.internal.AvailablePort;
import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.internal.cache.EventID;
import org.apache.geode.internal.cache.InternalCache;
-import org.apache.geode.internal.cache.tier.Acceptor;
-import org.apache.geode.internal.cache.tier.MessageType;
import org.apache.geode.test.junit.categories.ClientServerTest;
import org.apache.geode.test.junit.categories.IntegrationTest;
import org.junit.After;
@@ -39,13 +37,9 @@ import org.junit.experimental.categories.Category;
import java.io.IOException;
import java.net.BindException;
-import java.net.Socket;
import java.util.Collections;
import java.util.Properties;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.junit.Assert.*;
-
@Category({IntegrationTest.class, ClientServerTest.class})
public class AcceptorImplJUnitTest {