You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/07/27 06:56:17 UTC
[6/6] ignite git commit: WIP on response structure.
WIP on response structure.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/07f10301
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/07f10301
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/07f10301
Branch: refs/heads/ignite-3553
Commit: 07f103018b96bf2d846e2d5549040e75faaf0258
Parents: 197a572
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Jul 27 07:57:44 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Jul 27 07:57:44 2016 +0300
----------------------------------------------------------------------
.../igfs/client/IgfsClientClosureManager.java | 35 +++++++
.../igfs/client/IgfsClientClosureResponse.java | 97 ++++++++++++++++++++
.../client/IgfsClientClosureResponseType.java | 53 +++++++++++
3 files changed, 185 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/07f10301/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureManager.java
index d37f741..bdd5ed7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureManager.java
@@ -24,7 +24,9 @@ import org.apache.ignite.internal.processors.igfs.IgfsContext;
import org.apache.ignite.internal.processors.igfs.IgfsManager;
import org.apache.ignite.internal.util.GridStripedSpinBusyLock;
import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.Marshaller;
+import org.jetbrains.annotations.Nullable;
import java.util.concurrent.ConcurrentLinkedDeque;
@@ -96,6 +98,39 @@ public class IgfsClientClosureManager extends IgfsManager {
return null;
}
+ /**
+ * Create closure response.
+ *
+ * @param msgId Message ID.
+ * @param res Response.
+ * @param marsh Marshaller.
+ * @return Response.
+ */
+ public IgfsClientClosureResponse createResponse(long msgId, @Nullable Object res, @Nullable Throwable resErr,
+ Marshaller marsh) {
+ try {
+
+ if (resErr != null)
+ return new IgfsClientClosureResponse(msgId, IgfsClientClosureResponseType.ERR, null,
+ marsh.marshal(resErr));
+ else {
+ if (res == null)
+ return new IgfsClientClosureResponse(msgId, IgfsClientClosureResponseType.NULL, null, null);
+ else if (res instanceof Boolean)
+ return new IgfsClientClosureResponse(msgId, IgfsClientClosureResponseType.BOOL, res, null);
+ else
+ return new IgfsClientClosureResponse(msgId, IgfsClientClosureResponseType.OBJ, null,
+ marsh.marshal(res));
+ }
+ }
+ catch (Exception e) {
+ U.error(log, "Failed to marshal IGFS closure result [msgId=" + msgId + ", res=" + res +
+ ", resErr=" + resErr + ']', e);
+
+ return new IgfsClientClosureResponse(msgId, IgfsClientClosureResponseType.MARSH_ERR, null, null);
+ }
+ }
+
/** {@inheritDoc} */
@Override public String toString() {
return S.toString(IgfsClientClosureManager.class, this);
http://git-wip-us.apache.org/repos/asf/ignite/blob/07f10301/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureResponse.java
index d768766..7d0d0d7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureResponse.java
@@ -17,16 +17,113 @@
package org.apache.ignite.internal.processors.igfs.client;
+import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.plugin.extensions.communication.Message;
+import org.apache.ignite.plugin.extensions.communication.MessageReader;
+import org.apache.ignite.plugin.extensions.communication.MessageWriter;
+import org.jetbrains.annotations.Nullable;
+
+import java.nio.ByteBuffer;
/**
* IGFS client closure execute response.
*/
public class IgfsClientClosureResponse implements Message {
+ /** Message ID. */
+ private long msgId;
+
+ /** Response type. */
+ private IgfsClientClosureResponseType typ;
+
+ /** Result. */
+ private Object res;
+
+ /** Result bytes. */
+ private byte[] resBytes;
+
/**
* Default constructor.
*/
public IgfsClientClosureResponse() {
// No-op.
}
+
+ /**
+ * Constructor.
+ *
+ * @param msgId Message ID.
+ * @param typ Type.
+ * @param res Result.
+ * @param resBytes Result bytes.
+ */
+ public IgfsClientClosureResponse(long msgId, IgfsClientClosureResponseType typ, @Nullable Object res,
+ @Nullable byte[] resBytes) {
+ this.msgId = msgId;
+ this.typ = typ;
+ this.res = res;
+ this.resBytes = resBytes;
+ }
+
+ /**
+ * @return Message ID.
+ */
+ public long messageId() {
+ return msgId;
+ }
+
+ /**
+ * @return Type.
+ */
+ public IgfsClientClosureResponseType type() {
+ return typ;
+ }
+
+ /**
+ * @return Result.
+ */
+ @Nullable public Object result() {
+ return res;
+ }
+
+ /**
+ * @return Result bytes.
+ */
+ @Nullable public byte[] resultBytes() {
+ return resBytes;
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte directType() {
+ return -28;
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte fieldsCount() {
+ return (byte)(typ == IgfsClientClosureResponseType.NULL || typ == IgfsClientClosureResponseType.MARSH_ERR ?
+ 2 : 3);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onAckReceived() {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+ // TODO
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+ // TODO
+
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(IgfsClientClosureResponse.class, this);
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/07f10301/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureResponseType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureResponseType.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureResponseType.java
new file mode 100644
index 0000000..8fd45c9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/client/IgfsClientClosureResponseType.java
@@ -0,0 +1,53 @@
+/*
+ * 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.igfs.client;
+
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * IGFS client closure response type.
+ */
+public enum IgfsClientClosureResponseType {
+ /** Object. */
+ OBJ,
+
+ /** Null result. */
+ NULL,
+
+ /** Boolean result. */
+ BOOL,
+
+ /** Error. */
+ ERR,
+
+ /** Marshalling error. */
+ MARSH_ERR;
+
+ /** Enum values. */
+ private static final IgfsClientClosureResponseType[] VALS = values();
+
+ /**
+ * Efficiently gets enumerated value from its ordinal.
+ *
+ * @param ord Ordinal value.
+ * @return Enumerated value.
+ */
+ @Nullable public static IgfsClientClosureResponseType fromOrdinal(int ord) {
+ return ord >= 0 && ord < VALS.length ? VALS[ord] : null;
+ }
+}