ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject ignite git commit: IGNITE-5896: Thin client: base server-side infrastructure.
Date Wed, 13 Sep 2017 11:28:49 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 948f31c0a -> 4af18327b


IGNITE-5896: Thin client: base server-side infrastructure.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4af18327
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4af18327
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4af18327

Branch: refs/heads/master
Commit: 4af18327ba41350a46e3a852a32f7a56091d3eec
Parents: 948f31c
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Wed Sep 13 14:28:38 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Wed Sep 13 14:28:38 2017 +0300

----------------------------------------------------------------------
 .../processors/odbc/SqlListenerNioListener.java | 13 ++-
 .../client/ClientConnectionContext.java         | 76 +++++++++++++++++
 .../platform/client/ClientMessageParser.java    | 90 ++++++++++++++++++++
 .../platform/client/ClientRequestHandler.java   | 58 +++++++++++++
 4 files changed, 235 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4af18327/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlListenerNioListener.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlListenerNioListener.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlListenerNioListener.java
index 98cd8ea..339c8c1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlListenerNioListener.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/SqlListenerNioListener.java
@@ -28,6 +28,9 @@ import org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream;
 import org.apache.ignite.internal.binary.streams.BinaryInputStream;
 import org.apache.ignite.internal.processors.odbc.jdbc.JdbcConnectionContext;
 import org.apache.ignite.internal.processors.odbc.odbc.OdbcConnectionContext;
+import org.apache.ignite.internal.processors.platform.client.ClientConnectionContext;
+import org.apache.ignite.internal.processors.platform.client.ClientMessageParser;
+import org.apache.ignite.internal.processors.platform.client.ClientRequestHandler;
 import org.apache.ignite.internal.util.GridSpinBusyLock;
 import org.apache.ignite.internal.util.nio.GridNioServerListenerAdapter;
 import org.apache.ignite.internal.util.nio.GridNioSession;
@@ -38,12 +41,15 @@ import org.jetbrains.annotations.Nullable;
  * SQL message listener.
  */
 public class SqlListenerNioListener extends GridNioServerListenerAdapter<byte[]> {
-    /** The value corresponds to ODBC driver of the parser field of the handshake request.
*/
+    /** ODBC driver handshake code. */
     public static final byte ODBC_CLIENT = 0;
 
-    /** The value corresponds to JDBC driver of the parser field of the handshake request.
*/
+    /** JDBC driver handshake code. */
     public static final byte JDBC_CLIENT = 1;
 
+    /** Thin client handshake code. */
+    public static final byte THIN_CLIENT = 2;
+
     /** Connection-related metadata key. */
     private static final int CONN_CTX_META_KEY = GridNioSessionMetaKey.nextUniqueKey();
 
@@ -227,6 +233,9 @@ public class SqlListenerNioListener extends GridNioServerListenerAdapter<byte[]>
             case JDBC_CLIENT:
                 return new JdbcConnectionContext(ctx, busyLock, maxCursors);
 
+            case THIN_CLIENT:
+                return new ClientConnectionContext(ctx);
+
             default:
                 throw new IgniteException("Unknown client type: " + clientType);
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/4af18327/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientConnectionContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientConnectionContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientConnectionContext.java
new file mode 100644
index 0000000..c6c2c3b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientConnectionContext.java
@@ -0,0 +1,76 @@
+/*
+ * 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.ignite.internal.processors.platform.client;
+
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryReaderExImpl;
+import org.apache.ignite.internal.processors.odbc.SqlListenerConnectionContext;
+import org.apache.ignite.internal.processors.odbc.SqlListenerMessageParser;
+import org.apache.ignite.internal.processors.odbc.SqlListenerProtocolVersion;
+import org.apache.ignite.internal.processors.odbc.SqlListenerRequestHandler;
+
+/**
+ * Thin Client connection context.
+ */
+public class ClientConnectionContext implements SqlListenerConnectionContext {
+    /** Version 1.0.0. */
+    private static final SqlListenerProtocolVersion VER_1_0_0 = SqlListenerProtocolVersion.create(1,
0, 0);
+
+    /** Message parser. */
+    private final ClientMessageParser parser;
+
+    /** Request handler. */
+    private final ClientRequestHandler handler;
+
+    /**
+     * Ctor.
+     *
+     * @param ctx Kernal context.
+     */
+    public ClientConnectionContext(GridKernalContext ctx) {
+        assert ctx != null;
+
+        parser = new ClientMessageParser(ctx);
+        handler = new ClientRequestHandler(ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isVersionSupported(SqlListenerProtocolVersion ver) {
+        return VER_1_0_0.equals(ver);
+    }
+
+    /** {@inheritDoc} */
+    @Override public SqlListenerProtocolVersion currentVersion() {
+        return VER_1_0_0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void initializeFromHandshake(SqlListenerProtocolVersion ver, BinaryReaderExImpl
reader) {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public SqlListenerRequestHandler handler() {
+        return handler;
+    }
+
+    /** {@inheritDoc} */
+    @Override public SqlListenerMessageParser parser() {
+        return parser;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/4af18327/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientMessageParser.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientMessageParser.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientMessageParser.java
new file mode 100644
index 0000000..3626de8
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientMessageParser.java
@@ -0,0 +1,90 @@
+/*
+ * 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.ignite.internal.processors.platform.client;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.streams.BinaryHeapInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream;
+import org.apache.ignite.internal.binary.streams.BinaryInputStream;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.processors.odbc.SqlListenerMessageParser;
+import org.apache.ignite.internal.processors.odbc.SqlListenerRequest;
+import org.apache.ignite.internal.processors.odbc.SqlListenerResponse;
+import org.apache.ignite.internal.processors.platform.client.cache.ClientCacheGetRequest;
+import org.apache.ignite.internal.processors.platform.client.cache.ClientCachePutRequest;
+
+/**
+ * Thin client message parser.
+ */
+public class ClientMessageParser implements SqlListenerMessageParser {
+    /** */
+    private static final short OP_CACHE_GET = 1;
+
+    /** */
+    private static final short OP_CACHE_PUT = 4;
+
+    /** Marshaller. */
+    private final GridBinaryMarshaller marsh;
+
+    /**
+     * Ctor.
+     *
+     * @param ctx Kernal context.
+     */
+    ClientMessageParser(GridKernalContext ctx) {
+        assert ctx != null;
+
+        CacheObjectBinaryProcessorImpl cacheObjProc = (CacheObjectBinaryProcessorImpl)ctx.cacheObjects();
+        marsh = cacheObjProc.marshaller();
+    }
+
+    /** {@inheritDoc} */
+    @Override public SqlListenerRequest decode(byte[] msg) {
+        assert msg != null;
+
+        BinaryInputStream inStream = new BinaryHeapInputStream(msg);
+        BinaryRawReaderEx reader = marsh.reader(inStream);
+
+        short opCode = reader.readShort();
+
+        switch (opCode) {
+            case OP_CACHE_GET:
+                return new ClientCacheGetRequest(reader);
+
+            case OP_CACHE_PUT:
+                return new ClientCachePutRequest(reader);
+        }
+
+        throw new IgniteException("Invalid operation: " + opCode);
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] encode(SqlListenerResponse resp) {
+        BinaryHeapOutputStream outStream = new BinaryHeapOutputStream(32);
+
+        BinaryRawWriter writer = marsh.writer(outStream);
+
+        ((ClientResponse)resp).encode(writer);
+
+        return outStream.array();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/4af18327/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientRequestHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientRequestHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientRequestHandler.java
new file mode 100644
index 0000000..30fb1a8
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientRequestHandler.java
@@ -0,0 +1,58 @@
+/*
+ * 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.ignite.internal.processors.platform.client;
+
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.processors.odbc.SqlListenerRequest;
+import org.apache.ignite.internal.processors.odbc.SqlListenerRequestHandler;
+import org.apache.ignite.internal.processors.odbc.SqlListenerResponse;
+
+/**
+ * Thin client request handler.
+ */
+public class ClientRequestHandler implements SqlListenerRequestHandler {
+    /** Kernal context. */
+    private final GridKernalContext ctx;
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Kernal context.
+     */
+    ClientRequestHandler(GridKernalContext ctx) {
+        assert ctx != null;
+
+        this.ctx = ctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public SqlListenerResponse handle(SqlListenerRequest req) {
+        return ((ClientRequest)req).process(ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public SqlListenerResponse handleException(Exception e) {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeHandshake(BinaryWriterExImpl writer) {
+        writer.writeBoolean(true);
+    }
+}
\ No newline at end of file


Mime
View raw message