You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ud...@apache.org on 2017/10/16 17:29:46 UTC

[geode] branch feature/GEODE-3774 updated: GEODE-3774: Amended ProtobufProtocolService.java to create statistics only once. Moved the initialization of statistics for the ClientProtocolService to be inside TCPServer

This is an automated email from the ASF dual-hosted git repository.

udo pushed a commit to branch feature/GEODE-3774
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-3774 by this push:
     new de8d07f  GEODE-3774: Amended ProtobufProtocolService.java to create statistics only once. Moved the initialization of statistics for the ClientProtocolService to be inside TCPServer
de8d07f is described below

commit de8d07f6e5416cd10201a70b564026e242639d76
Author: kohlmu-pivotal <uk...@pivotal.io>
AuthorDate: Mon Oct 16 10:29:37 2017 -0700

    GEODE-3774: Amended ProtobufProtocolService.java to create statistics only once.
    Moved the initialization of statistics for the ClientProtocolService to be inside TCPServer
---
 .../distributed/internal/InternalLocator.java      |  6 ----
 .../distributed/internal/tcpserver/TcpServer.java  |  2 ++
 .../internal/protocol/ProtobufProtocolService.java |  8 +++--
 .../protocol/ProtobufProtocolServiceJUnitTest.java | 37 ++++++++++++++++++++++
 4 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
index 557610f..9b0ad22 100644
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/InternalLocator.java
@@ -1335,12 +1335,6 @@ public class InternalLocator extends Locator implements ConnectListener {
     try {
       this.stats.hookupStats(sys,
           SocketCreator.getLocalHost().getCanonicalHostName() + '-' + this.server.getBindAddress());
-
-      ClientProtocolService clientProtocolService =
-          this.server.getClientProtocolServiceLoader().lookupService();
-      if (clientProtocolService != null) {
-        clientProtocolService.initializeStatistics("LocatorStats", sys);
-      }
     } catch (UnknownHostException e) {
       logger.warn(e);
     }
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java
index 40f1f0f..34a34d6 100755
--- a/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java
@@ -387,6 +387,8 @@ public class TcpServer {
             try {
               ClientProtocolService clientProtocolService =
                   clientProtocolServiceLoader.lookupService();
+              clientProtocolService.initializeStatistics("LocatorStats",
+                  internalLocator.getDistributedSystem());
               try (ClientProtocolProcessor pipeline =
                   clientProtocolService.createProcessorForLocator(internalLocator)) {
                 pipeline.processMessage(input, socket.getOutputStream());
diff --git a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/ProtobufProtocolService.java b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/ProtobufProtocolService.java
index 44b20c4..a0e9ebc 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/ProtobufProtocolService.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/internal/protocol/ProtobufProtocolService.java
@@ -32,15 +32,17 @@ public class ProtobufProtocolService implements ClientProtocolService {
 
   @Override
   public synchronized void initializeStatistics(String statisticsName, StatisticsFactory factory) {
-    statistics = new ProtobufClientStatisticsImpl(factory, statisticsName,
-        ProtobufClientStatistics.PROTOBUF_STATS_NAME);
+    if (statistics == null) {
+      statistics = new ProtobufClientStatisticsImpl(factory, statisticsName,
+          ProtobufClientStatistics.PROTOBUF_STATS_NAME);
+    }
   }
 
   /**
    * For internal use. This is necessary because the statistics may get initialized in another
    * thread.
    */
-  private ProtobufClientStatistics getStatistics() {
+  ProtobufClientStatistics getStatistics() {
     if (statistics == null) {
       return new NoOpStatistics();
     }
diff --git a/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/ProtobufProtocolServiceJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/ProtobufProtocolServiceJUnitTest.java
new file mode 100644
index 0000000..d952f0f
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/internal/protocol/ProtobufProtocolServiceJUnitTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You 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.apache.geode.internal.protocol;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.internal.protocol.protobuf.statistics.ProtobufClientStatistics;
+import org.apache.geode.internal.statistics.DummyStatisticsFactory;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class ProtobufProtocolServiceJUnitTest {
+  @Test
+  public void initializeStatistics() {
+    ProtobufProtocolService service = new ProtobufProtocolService();
+    service.initializeStatistics("first", new DummyStatisticsFactory());
+    ProtobufClientStatistics firstStatistics = service.getStatistics();
+    service.initializeStatistics("second", new DummyStatisticsFactory());
+    ProtobufClientStatistics secondStatistics = service.getStatistics();
+    assertEquals(firstStatistics, secondStatistics);
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].