ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [50/50] ignite git commit: Unlock processor prototype.
Date Thu, 08 Sep 2016 14:46:32 GMT
Unlock processor prototype.


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

Branch: refs/heads/ignite-3199-1
Commit: 8359c220f6143d60e5791e80c0fce0ee2c991e90
Parents: 38bcc34
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Thu Sep 8 17:45:11 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Thu Sep 8 17:45:11 2016 +0300

----------------------------------------------------------------------
 ...tformDotnetSessionSetAndUnlockProcessor.java | 134 +++++++++++++++++++
 .../platform/websession/SessionStateData.java   |  17 ++-
 2 files changed, 148 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/8359c220/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/PlatformDotnetSessionSetAndUnlockProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/PlatformDotnetSessionSetAndUnlockProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/PlatformDotnetSessionSetAndUnlockProcessor.java
new file mode 100644
index 0000000..5f16bee
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/PlatformDotnetSessionSetAndUnlockProcessor.java
@@ -0,0 +1,134 @@
+/*
+ * 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.websession;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.cache.CacheEntryProcessor;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import javax.cache.processor.EntryProcessorException;
+import javax.cache.processor.MutableEntry;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Processor to unlock and optionally update the session.
+ */
+public class PlatformDotnetSessionSetAndUnlockProcessor implements
+    CacheEntryProcessor<String, SessionStateData, Void>, Binarylizable {
+    /** Lock node ID. */
+    private UUID lockNodeId;
+
+    /** Lock ID. */
+    private long lockId;
+
+    /** Update flag. */
+    private boolean update;
+
+    /** Data. */
+    private Map<String, byte[]> items;
+
+    /** Static data. */
+    private byte[] staticData;
+
+    /** Timeout. */
+    private int timeout;
+
+    /**
+     * Constructor.
+     *
+     * @param lockNodeId Lock node ID.
+     * @param lockId Lock ID.
+     */
+    public PlatformDotnetSessionSetAndUnlockProcessor(UUID lockNodeId, long lockId) {
+        this(lockNodeId, lockId, false, null, null, -1);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param lockNodeId Lock node ID.
+     * @param lockId Lock ID.
+     * @param items Items.
+     * @param staticData Static data.
+     * @param timeout Timeout.
+     */
+    public PlatformDotnetSessionSetAndUnlockProcessor(UUID lockNodeId, long lockId,
+        Map<String, byte[]> items, byte[] staticData, int timeout) {
+        this(lockNodeId, lockId, true, items, staticData, timeout);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param lockNodeId Lock node ID.
+     * @param lockId Lock ID.
+     * @param update Whether to perform update.
+     * @param items Items.
+     * @param staticData Static data.
+     * @param timeout Timeout.
+     */
+    public PlatformDotnetSessionSetAndUnlockProcessor(UUID lockNodeId, long lockId, boolean
update,
+        Map<String, byte[]> items, byte[] staticData, int timeout) {
+        this.lockNodeId = lockNodeId;
+        this.lockId = lockId;
+        this.update = update;
+        this.items = items;
+        this.staticData = staticData;
+        this.timeout = timeout;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Void process(MutableEntry<String, SessionStateData> entry, Object...
args)
+        throws EntryProcessorException {
+        assert entry.exists();
+
+        SessionStateData data = entry.getValue();
+
+        assert data != null;
+
+        // Unlock and update.
+        if (update)
+            data = data.updateAndUnlock(lockNodeId, lockId, items, staticData, timeout);
+        else
+            data = data.unlock(lockNodeId, lockId);
+
+        // Apply.
+        entry.setValue(data);
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+        // TODO
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+        // TODO
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(PlatformDotnetSessionSetAndUnlockProcessor.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/8359c220/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/SessionStateData.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/SessionStateData.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/SessionStateData.java
index 6eb3caa..ac81314 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/SessionStateData.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/websession/SessionStateData.java
@@ -123,26 +123,37 @@ public class SessionStateData implements Binarylizable {
     /**
      * Unlock session state data.
      *
+     * @param lockNodeId Lock node ID.
+     * @param lockId Lock ID.
      * @return Unlocked data.
      */
-    public SessionStateData unlock() {
+    public SessionStateData unlock(UUID lockNodeId, long lockId) {
         assert isLocked();
 
+        if (!this.lockNodeId.equals(lockNodeId))
+            throw new IllegalStateException("Can not unlock session data: lock node id check
failed.");
+
+        if (this.lockId != lockId)
+            throw new IllegalStateException("Can not unlock session data: lock id check failed.");
+
         return copyWithoutLockInfo();
     }
 
     /**
      * Update session state and release the lock.
      *
+     * @param lockNodeId Lock node ID.
+     * @param lockId Lock ID.
      * @param items Items.
      * @param staticObjects Static objects.
      * @param timeout Timeout.
      * @return Result.
      */
-    public SessionStateData updateAndUnlock(KeyValueDirtyTrackedCollection items, byte[]
staticObjects, int timeout) {
+    public SessionStateData updateAndUnlock(UUID lockNodeId, long lockId, KeyValueDirtyTrackedCollection
items,
+        byte[] staticObjects, int timeout) {
         assert items != null;
 
-        SessionStateData res = unlock();
+        SessionStateData res = unlock(lockNodeId, lockId);
 
         res.items.applyChanges(items);
         res.staticObjects = staticObjects;


Mime
View raw message