[
https://issues.apache.org/jira/browse/GEODE-4054?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16282840#comment-16282840
]
ASF GitHub Bot commented on GEODE-4054:
---------------------------------------
WireBaron commented on a change in pull request #1141: GEODE-4054: Create
module for Protobuf message-based client
URL: https://github.com/apache/geode/pull/1141#discussion_r155681256
##########
File path:
geode-protobuf-client/src/main/java/org/apache/geode/internal/cache/client/protobuf/Cache.java
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.cache.client.protobuf;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.geode.annotations.Experimental;
+import org.apache.geode.internal.protocol.protobuf.v1.BasicTypes;
+import org.apache.geode.internal.protocol.protobuf.v1.ClientProtocol;
+import org.apache.geode.internal.protocol.protobuf.v1.ConnectionAPI;
+import org.apache.geode.internal.protocol.protobuf.v1.RegionAPI;
+
+@Experimental
+public class Cache {
+ final Socket socket;
+
+ Cache(String host, int port) throws Exception {
+ socket = new Socket(host, port);
+
+ final OutputStream outputStream = socket.getOutputStream();
+ outputStream.write(0x6E); // Magic byte
+ outputStream.write(0x01); // Major version
+
+ final InputStream inputStream = socket.getInputStream();
+ ClientProtocol.Message.newBuilder()
+ .setRequest(ClientProtocol.Request.newBuilder()
+ .setHandshakeRequest(ConnectionAPI.HandshakeRequest.newBuilder()
+
.setMajorVersion(ConnectionAPI.MajorVersions.CURRENT_MAJOR_VERSION_VALUE)
+
.setMinorVersion(ConnectionAPI.MinorVersions.CURRENT_MINOR_VERSION_VALUE)))
+ .build().writeDelimitedTo(outputStream);
+
+ if
(!ClientProtocol.Message.parseDelimitedFrom(inputStream).getResponse().getHandshakeResponse()
+ .getHandshakePassed()) {
+ throw new Exception("Failed handshake.");
+ }
+ }
+
+ public Set<String> getRegionNames() throws Exception {
+ Set<String> regionNames = new HashSet<>();
+
+ final OutputStream outputStream = socket.getOutputStream();
+ ClientProtocol.Message.newBuilder()
+ .setRequest(ClientProtocol.Request.newBuilder()
+
.setGetRegionNamesRequest(RegionAPI.GetRegionNamesRequest.newBuilder()))
+ .build().writeDelimitedTo(outputStream);
+
+ final InputStream inputStream = socket.getInputStream();
+ final RegionAPI.GetRegionNamesResponse getRegionNamesResponse =
ClientProtocol.Message
+
.parseDelimitedFrom(inputStream).getResponse().getGetRegionNamesResponse();
+ for (int i = 0; i < getRegionNamesResponse.getRegionsCount(); ++i) {
Review comment:
Might be more straightforward to write this as:
for (String regionName : getRegionNamesResponse.getRegionsList())
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Create module for Protobuf message-based client
> -----------------------------------------------
>
> Key: GEODE-4054
> URL: https://issues.apache.org/jira/browse/GEODE-4054
> Project: Geode
> Issue Type: Improvement
> Components: client/server
> Reporter: Michael Dodge
> Fix For: 1.4.0
>
>
> Create a module, geode-protobuf-client, that contains a simple Java client
> that exercises the Protobuf messages and the new protocol. This client should
> allow the interaction with a locator and cache server based on command-line
> arguments, a file of commands, or an interactive shell.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)