You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2015/11/05 14:15:53 UTC
[01/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Repository: ignite
Updated Branches:
refs/heads/ignite-1282 76b65b21a -> b783d2b71
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicSelfTest.java
deleted file mode 100644
index 106e59b..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCachePortableObjectsAtomicSelfTest extends GridCachePortableObjectsAbstractSelfTest {
- /** {@inheritDoc} */
- @Override protected CacheMode cacheMode() {
- return PARTITIONED;
- }
-
- /** {@inheritDoc} */
- @Override protected CacheAtomicityMode atomicityMode() {
- return ATOMIC;
- }
-
- /** {@inheritDoc} */
- @Override protected NearCacheConfiguration nearConfiguration() {
- return new NearCacheConfiguration();
- }
-
- /** {@inheritDoc} */
- @Override protected int gridCount() {
- return 3;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
deleted file mode 100644
index 5bc4672..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.cache.portable.distributed.dht;
-
-/**
- *
- */
-public class GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest
- extends GridCachePortableObjectsPartitionedNearDisabledSelfTest{
- /** {@inheritDoc} */
- @Override protected boolean offheapTiered() {
- return true;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledSelfTest.java
deleted file mode 100644
index df55de7..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCachePortableObjectsPartitionedNearDisabledSelfTest extends GridCachePortableObjectsAbstractSelfTest {
- /** {@inheritDoc} */
- @Override protected CacheMode cacheMode() {
- return PARTITIONED;
- }
-
- /** {@inheritDoc} */
- @Override protected CacheAtomicityMode atomicityMode() {
- return TRANSACTIONAL;
- }
-
- /** {@inheritDoc} */
- @Override protected NearCacheConfiguration nearConfiguration() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override protected int gridCount() {
- return 3;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedOffheapTieredSelfTest.java
deleted file mode 100644
index a6bc0b4..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedOffheapTieredSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.cache.portable.distributed.dht;
-
-/**
- *
- */
-public class GridCachePortableObjectsPartitionedOffheapTieredSelfTest
- extends GridCachePortableObjectsPartitionedSelfTest {
- /** {@inheritDoc} */
- @Override protected boolean offheapTiered() {
- return true;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedSelfTest.java
deleted file mode 100644
index 8c248be..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCachePortableObjectsPartitionedSelfTest extends GridCachePortableObjectsAbstractSelfTest {
- /** {@inheritDoc} */
- @Override protected CacheMode cacheMode() {
- return PARTITIONED;
- }
-
- /** {@inheritDoc} */
- @Override protected CacheAtomicityMode atomicityMode() {
- return TRANSACTIONAL;
- }
-
- /** {@inheritDoc} */
- @Override protected NearCacheConfiguration nearConfiguration() {
- return new NearCacheConfiguration();
- }
-
- /** {@inheritDoc} */
- @Override protected int gridCount() {
- return 3;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java
new file mode 100644
index 0000000..0c2734e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.cache.portable.distributed.replicated;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsReplicatedSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return REPLICATED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return TRANSACTIONAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 3;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCachePortableObjectsReplicatedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCachePortableObjectsReplicatedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCachePortableObjectsReplicatedSelfTest.java
deleted file mode 100644
index 953fbfa..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCachePortableObjectsReplicatedSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.cache.portable.distributed.replicated;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.REPLICATED;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCachePortableObjectsReplicatedSelfTest extends GridCachePortableObjectsAbstractSelfTest {
- /** {@inheritDoc} */
- @Override protected CacheMode cacheMode() {
- return REPLICATED;
- }
-
- /** {@inheritDoc} */
- @Override protected CacheAtomicityMode atomicityMode() {
- return TRANSACTIONAL;
- }
-
- /** {@inheritDoc} */
- @Override protected NearCacheConfiguration nearConfiguration() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override protected int gridCount() {
- return 3;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java
new file mode 100644
index 0000000..19321fb
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.cache.portable.local;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsAtomicLocalSelfTest extends GridCacheBinaryObjectsLocalSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return ATOMIC;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.java
new file mode 100644
index 0000000..4801fa5
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.cache.portable.local;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsLocalOffheapTieredSelfTest extends GridCacheBinaryObjectsLocalSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean offheapTiered() {
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalSelfTest.java
new file mode 100644
index 0000000..21053d7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.cache.portable.local;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.LOCAL;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsLocalSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return LOCAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return TRANSACTIONAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 1;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsAtomicLocalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsAtomicLocalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsAtomicLocalSelfTest.java
deleted file mode 100644
index 3f3a350..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsAtomicLocalSelfTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.cache.portable.local;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-
-/**
- *
- */
-public class GridCachePortableObjectsAtomicLocalSelfTest extends GridCachePortableObjectsLocalSelfTest {
- /** {@inheritDoc} */
- @Override protected CacheAtomicityMode atomicityMode() {
- return ATOMIC;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalOffheapTieredSelfTest.java
deleted file mode 100644
index 53713ce..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalOffheapTieredSelfTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.cache.portable.local;
-
-/**
- *
- */
-public class GridCachePortableObjectsLocalOffheapTieredSelfTest extends GridCachePortableObjectsLocalSelfTest {
- /** {@inheritDoc} */
- @Override protected boolean offheapTiered() {
- return true;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalSelfTest.java
deleted file mode 100644
index 1a87865..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.cache.portable.local;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.LOCAL;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCachePortableObjectsLocalSelfTest extends GridCachePortableObjectsAbstractSelfTest {
- /** {@inheritDoc} */
- @Override protected CacheMode cacheMode() {
- return LOCAL;
- }
-
- /** {@inheritDoc} */
- @Override protected CacheAtomicityMode atomicityMode() {
- return TRANSACTIONAL;
- }
-
- /** {@inheritDoc} */
- @Override protected NearCacheConfiguration nearConfiguration() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override protected int gridCount() {
- return 1;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java
index b6b3d70..65dd690 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessorSelfTest.java
@@ -149,6 +149,13 @@ public class DataStreamProcessorSelfTest extends GridCommonAbstractTest {
}
/**
+ * @return {@code True} if custom stream receiver should use keepBinary flag.
+ */
+ protected boolean customKeepBinary() {
+ return false;
+ }
+
+ /**
* @throws Exception If failed.
*/
public void testPartitioned() throws Exception {
@@ -914,6 +921,7 @@ public class DataStreamProcessorSelfTest extends GridCommonAbstractTest {
try (IgniteDataStreamer<String, TestObject> ldr = ignite.dataStreamer(null)) {
ldr.allowOverwrite(true);
+ ldr.keepBinary(customKeepBinary());
ldr.receiver(getStreamReceiver());
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridHashMapLoadTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridHashMapLoadTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridHashMapLoadTest.java
index a6dfc9c..a41f6c8 100644
--- a/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridHashMapLoadTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/loadtests/hashmap/GridHashMapLoadTest.java
@@ -85,7 +85,8 @@ public class GridHashMapLoadTest extends GridCommonAbstractTest {
@Override public boolean tmLock(IgniteInternalTx tx,
long timeout,
@Nullable GridCacheVersion serOrder,
- GridCacheVersion serReadVer) {
+ GridCacheVersion serReadVer,
+ boolean keepBinary) {
return false;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/platform/PlatformComputePortableArgTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformComputePortableArgTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformComputePortableArgTask.java
index 0e8b825..1e3c499 100644
--- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformComputePortableArgTask.java
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformComputePortableArgTask.java
@@ -25,8 +25,8 @@ import org.apache.ignite.compute.ComputeJobAdapter;
import org.apache.ignite.compute.ComputeJobResult;
import org.apache.ignite.compute.ComputeTaskAdapter;
import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.jetbrains.annotations.Nullable;
@@ -87,9 +87,9 @@ public class PlatformComputePortableArgTask extends ComputeTaskAdapter<Object, I
/** {@inheritDoc} */
@Nullable @Override public Object execute() {
- PortableObject arg0 = ((PortableObject)arg);
+ BinaryObject arg0 = ((BinaryObject)arg);
- PortableMetadata meta = ignite.portables().metadata(arg0.typeId());
+ BinaryType meta = ignite.binary().metadata(arg0.typeId());
if (meta == null)
throw new IgniteException("Metadata doesn't exist.");
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/platform/PlatformEventsWriteEventTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformEventsWriteEventTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformEventsWriteEventTask.java
index d9dee9d..84c3584 100644
--- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformEventsWriteEventTask.java
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformEventsWriteEventTask.java
@@ -32,7 +32,7 @@ import org.apache.ignite.events.DiscoveryEvent;
import org.apache.ignite.events.JobEvent;
import org.apache.ignite.events.SwapSpaceEvent;
import org.apache.ignite.events.TaskEvent;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;
@@ -41,8 +41,6 @@ import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.events.*;
-import org.apache.ignite.plugin.security.SecurityPermission;
-import org.apache.ignite.plugin.security.SecuritySubjectType;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.jetbrains.annotations.Nullable;
@@ -97,7 +95,7 @@ public class PlatformEventsWriteEventTask extends ComputeTaskAdapter<Long, Objec
try (PlatformMemory mem = ctx.memory().get(ptr)) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
int evtType = EventType.EVT_SWAP_SPACE_CLEARED;
String msg = "msg";
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/spi/swapspace/file/GridFileSwapSpaceSpiSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/file/GridFileSwapSpaceSpiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/file/GridFileSwapSpaceSpiSelfTest.java
index c7d6899..64652b1 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/swapspace/file/GridFileSwapSpaceSpiSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/swapspace/file/GridFileSwapSpaceSpiSelfTest.java
@@ -28,6 +28,8 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
import org.apache.ignite.internal.util.typedef.CIX1;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiInClosure;
@@ -111,7 +113,7 @@ public class GridFileSwapSpaceSpiSelfTest extends GridSwapSpaceSpiAbstractSelfTe
* @return Swap key.
*/
private SwapKey key(int i) {
- return new SwapKey(i, i % 11, U.intToBytes(i));
+ return new SwapKey(new KeyCacheObjectImpl(i, U.intToBytes(i)), i % 11, U.intToBytes(i));
}
/**
@@ -354,8 +356,11 @@ public class GridFileSwapSpaceSpiSelfTest extends GridSwapSpaceSpiAbstractSelfTe
assertEquals(cnt, spi.count(space));
- for (Map.Entry<SwapKey, byte[]> entry : map.entrySet())
- hash1 += (Integer)entry.getKey().key() * Arrays.hashCode(entry.getValue());
+ for (Map.Entry<SwapKey, byte[]> entry : map.entrySet()) {
+ KeyCacheObject key = (KeyCacheObject)entry.getKey().key();
+
+ hash1 += (Integer)key.value(null, false) * Arrays.hashCode(entry.getValue());
+ }
assertEquals(hash0, hash1);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
index 23f702c..4b17c2e 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
@@ -35,7 +35,7 @@ import org.apache.ignite.IgniteEvents;
import org.apache.ignite.IgniteFileSystem;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteMessaging;
-import org.apache.ignite.IgnitePortables;
+import org.apache.ignite.IgniteBinary;
import org.apache.ignite.IgniteQueue;
import org.apache.ignite.IgniteScheduler;
import org.apache.ignite.IgniteServices;
@@ -276,7 +276,7 @@ public class IgniteMock implements Ignite {
}
/** {@inheritDoc} */
- @Override public IgnitePortables portables() {
+ @Override public IgniteBinary binary() {
return null;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
index 6a71f97..d2e17d8 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
@@ -129,7 +129,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
}
/** {@inheritDoc} */
- @Override public void loadCache(@Nullable IgniteBiPredicate<K, V> p, @Nullable Object... args)
+ @Override public void loadCache(@Nullable IgniteBiPredicate<K, V> p, @Nullable Object... args)
throws CacheException {
throw new UnsupportedOperationException("Method should be supported.");
}
@@ -424,7 +424,7 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
}
/** {@inheritDoc} */
- @Override public <K1, V1> IgniteCache<K1, V1> withKeepPortable() {
+ @Override public <K1, V1> IgniteCache<K1, V1> withKeepBinary() {
throw new UnsupportedOperationException("Method should be supported.");
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
index 536f283..7d28150 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
@@ -41,7 +41,7 @@ import org.apache.ignite.IgniteFileSystem;
import org.apache.ignite.IgniteIllegalStateException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteMessaging;
-import org.apache.ignite.IgnitePortables;
+import org.apache.ignite.IgniteBinary;
import org.apache.ignite.IgniteQueue;
import org.apache.ignite.IgniteScheduler;
import org.apache.ignite.IgniteServices;
@@ -551,7 +551,7 @@ public class IgniteProcessProxy implements IgniteEx {
}
/** {@inheritDoc} */
- @Override public IgnitePortables portables() {
+ @Override public IgniteBinary binary() {
throw new UnsupportedOperationException("Operation isn't supported yet.");
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
index 6d8e12d..c6b1fbc 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
@@ -19,10 +19,10 @@ package org.apache.ignite.testsuites;
import junit.framework.TestSuite;
import org.apache.ignite.internal.portable.GridPortableAffinityKeySelfTest;
-import org.apache.ignite.internal.portable.GridPortableBuilderAdditionalSelfTest;
-import org.apache.ignite.internal.portable.GridPortableBuilderSelfTest;
-import org.apache.ignite.internal.portable.GridPortableBuilderStringAsCharsAdditionalSelfTest;
-import org.apache.ignite.internal.portable.GridPortableBuilderStringAsCharsSelfTest;
+import org.apache.ignite.internal.portable.GridBinaryObjectBuilderAdditionalSelfTest;
+import org.apache.ignite.internal.portable.GridBinaryObjectBuilderSelfTest;
+import org.apache.ignite.internal.portable.GridBinaryObjectBuilderStringAsCharsAdditionalSelfTest;
+import org.apache.ignite.internal.portable.GridBinaryObjectBuilderStringAsCharsSelfTest;
import org.apache.ignite.internal.portable.GridPortableMarshallerCtxDisabledSelfTest;
import org.apache.ignite.internal.portable.GridPortableMarshallerSelfTest;
import org.apache.ignite.internal.portable.GridPortableMetaDataDisabledSelfTest;
@@ -30,24 +30,24 @@ import org.apache.ignite.internal.portable.GridPortableMetaDataSelfTest;
import org.apache.ignite.internal.portable.GridPortableWildcardsSelfTest;
import org.apache.ignite.internal.portable.PortableCompactOffsetsHeapSelfTest;
import org.apache.ignite.internal.portable.PortableCompactOffsetsOffheapSelfTest;
-import org.apache.ignite.internal.portable.PortableFieldsHeapSelfTest;
-import org.apache.ignite.internal.portable.PortableFieldsOffheapSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheClientNodePortableMetadataMultinodeTest;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheClientNodePortableMetadataTest;
+import org.apache.ignite.internal.portable.BinaryFieldsHeapSelfTest;
+import org.apache.ignite.internal.portable.BinaryFieldsOffheapSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheClientNodeBinaryObjectMetadataMultinodeTest;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheClientNodeBinaryObjectMetadataTest;
import org.apache.ignite.internal.processors.cache.portable.GridCachePortableStoreObjectsSelfTest;
import org.apache.ignite.internal.processors.cache.portable.GridCachePortableStorePortablesSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsAtomicNearDisabledSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsAtomicOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsAtomicSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsPartitionedNearDisabledSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsPartitionedOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsPartitionedSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.replicated.GridCachePortableObjectsReplicatedSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.local.GridCachePortableObjectsAtomicLocalSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.local.GridCachePortableObjectsLocalOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.local.GridCachePortableObjectsLocalSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsAtomicOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsPartitionedNearDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsPartitionedSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.replicated.GridCacheBinaryObjectsReplicatedSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.local.GridCacheBinaryObjectsAtomicLocalSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.local.GridCacheBinaryObjectsLocalOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.local.GridCacheBinaryObjectsLocalSelfTest;
/**
* Test for portable objects stored in cache.
@@ -62,12 +62,12 @@ public class IgnitePortableObjectsTestSuite extends TestSuite {
suite.addTestSuite(GridPortableMarshallerSelfTest.class);
suite.addTestSuite(GridPortableMarshallerCtxDisabledSelfTest.class);
- suite.addTestSuite(GridPortableBuilderSelfTest.class);
- suite.addTestSuite(GridPortableBuilderStringAsCharsSelfTest.class);
- suite.addTestSuite(GridPortableBuilderAdditionalSelfTest.class);
- suite.addTestSuite(GridPortableBuilderStringAsCharsAdditionalSelfTest.class);
- suite.addTestSuite(PortableFieldsHeapSelfTest.class);
- suite.addTestSuite(PortableFieldsOffheapSelfTest.class);
+ suite.addTestSuite(GridBinaryObjectBuilderSelfTest.class);
+ suite.addTestSuite(GridBinaryObjectBuilderStringAsCharsSelfTest.class);
+ suite.addTestSuite(GridBinaryObjectBuilderAdditionalSelfTest.class);
+ suite.addTestSuite(GridBinaryObjectBuilderStringAsCharsAdditionalSelfTest.class);
+ suite.addTestSuite(BinaryFieldsHeapSelfTest.class);
+ suite.addTestSuite(BinaryFieldsOffheapSelfTest.class);
suite.addTestSuite(PortableCompactOffsetsHeapSelfTest.class);
suite.addTestSuite(PortableCompactOffsetsOffheapSelfTest.class);
suite.addTestSuite(GridPortableMetaDataSelfTest.class);
@@ -75,25 +75,25 @@ public class IgnitePortableObjectsTestSuite extends TestSuite {
suite.addTestSuite(GridPortableAffinityKeySelfTest.class);
suite.addTestSuite(GridPortableWildcardsSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsLocalSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsAtomicLocalSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsReplicatedSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsPartitionedSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsPartitionedNearDisabledSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsAtomicSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsAtomicNearDisabledSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsLocalSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsAtomicLocalSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsReplicatedSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsPartitionedSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsAtomicSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsAtomicNearDisabledSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsLocalOffheapTieredSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsAtomicOffheapTieredSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsPartitionedOffheapTieredSelfTest.class);
- suite.addTestSuite(GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsLocalOffheapTieredSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.class);
+ suite.addTestSuite(GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.class);
suite.addTestSuite(GridCachePortableStoreObjectsSelfTest.class);
suite.addTestSuite(GridCachePortableStorePortablesSelfTest.class);
- suite.addTestSuite(GridCacheClientNodePortableMetadataTest.class);
- suite.addTestSuite(GridCacheClientNodePortableMetadataMultinodeTest.class);
+ suite.addTestSuite(GridCacheClientNodeBinaryObjectMetadataTest.class);
+ suite.addTestSuite(GridCacheClientNodeBinaryObjectMetadataMultinodeTest.class);
return suite;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 4c07132..d5efebf 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -1079,7 +1079,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
throw new IgniteCheckedException("Found duplicated properties with the same name [keyType=" +
type.keyClass().getName() + ", valueType=" + type.valueClass().getName() + "]");
- String ptrn = "Name ''{0}'' is reserved and cannot be used as a field name [class=" + type + "]";
+ String ptrn = "Name ''{0}'' is reserved and cannot be used as a field name [type=" + type.name() + "]";
for (String name : names) {
if (name.equals(KEY_FIELD_NAME) || name.equals(VAL_FIELD_NAME))
@@ -1585,23 +1585,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
}
}
- /** {@inheritDoc} */
- @Override public boolean isSqlType(Class<?> cls) {
- switch (DBTypeEnum.fromClass(cls)) {
- case OTHER:
- case ARRAY:
- return false;
-
- default:
- return true;
- }
- }
-
- /** {@inheritDoc} */
- @Override public boolean isGeometryClass(Class<?> cls) {
- return DataType.isGeometryClass(cls);
- }
-
/**
* Enum that helps to map java types to database types.
*/
@@ -1686,8 +1669,6 @@ public class IgniteH2Indexing implements GridQueryIndexing {
map.put(Timestamp.class, TIMESTAMP);
map.put(java.util.Date.class, TIMESTAMP);
map.put(java.sql.Date.class, DATE);
- map.put(char.class, CHAR);
- map.put(Character.class, CHAR);
map.put(String.class, VARCHAR);
map.put(UUID.class, UUID);
map.put(byte[].class, BINARY);
@@ -2272,7 +2253,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
if (v == null)
return null;
- return v.value(cctx.cacheObjectContext(), false);
+ return v;
}
/** {@inheritDoc} */
@@ -2318,4 +2299,4 @@ public class IgniteH2Indexing implements GridQueryIndexing {
return preferSwapVal;
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
index d790d34..fd0e6ed 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2ValueCacheObject.java
@@ -104,7 +104,7 @@ public class GridH2ValueCacheObject extends Value {
/** {@inheritDoc} */
@Override public byte[] getBytesNoCopy() {
- if (obj.type() == CacheObject.TYPE_REGULAR) {
+ if (obj.cacheObjectType() == CacheObject.TYPE_REGULAR) {
// Result must be the same as `marshaller.marshall(obj.value(coctx, false));`
try {
return obj.valueBytes(objectContext());
@@ -114,13 +114,13 @@ public class GridH2ValueCacheObject extends Value {
}
}
- // For portables and byte array cache object types.
- return Utils.serialize(obj.value(objectContext(), false), null);
+ // For user-provided and array types.
+ return Utils.serialize(obj, null);
}
/** {@inheritDoc} */
@Override public Object getObject() {
- return obj.value(objectContext(), false);
+ return obj.isPlatformType() ? obj.value(objectContext(), false) : obj;
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
index 85cf822..957e5f6 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridLuceneIndex.java
@@ -164,8 +164,8 @@ public class GridLuceneIndex implements Closeable {
public void store(CacheObject k, CacheObject v, byte[] ver, long expires) throws IgniteCheckedException {
CacheObjectContext coctx = objectContext();
- Object key = k.value(coctx, false);
- Object val = v.value(coctx, false);
+ Object key = k.isPlatformType() ? k.value(coctx, false) : k;
+ Object val = v.isPlatformType() ? v.value(coctx, false) : v;
Document doc = new Document();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
index 17f929a..9ccb893 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractFieldsQuerySelfTest.java
@@ -143,7 +143,8 @@ public abstract class IgniteCacheAbstractFieldsQuerySelfTest extends GridCommonA
}
}
- cache.setIndexedTypes(indexedTypes.toArray(new Class[indexedTypes.size()]));
+ if (!indexedTypes.isEmpty())
+ cache.setIndexedTypes(indexedTypes.toArray(new Class[indexedTypes.size()]));
if (cacheMode() == PARTITIONED)
cache.setBackups(1);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapTieredMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapTieredMultithreadedSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapTieredMultithreadedSelfTest.java
index ecd7229..ab6af45 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapTieredMultithreadedSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapTieredMultithreadedSelfTest.java
@@ -17,10 +17,7 @@
package org.apache.ignite.internal.processors.cache;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
+import java.io.Serializable;
import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.ThreadLocalRandom;
@@ -155,7 +152,7 @@ public class IgniteCacheOffheapTieredMultithreadedSelfTest extends GridCommonAbs
/**
* Person record used for query test.
*/
- public static class Person implements Externalizable {
+ public static class Person implements Serializable {
/** Person ID. */
@QuerySqlField(index = true)
private int id;
@@ -283,24 +280,6 @@ public class IgniteCacheOffheapTieredMultithreadedSelfTest extends GridCommonAbs
}
/** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(id);
- out.writeInt(orgId);
- out.writeUTF(firstName);
- out.writeUTF(lastName);
- out.writeDouble(salary);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- id = in.readInt();
- orgId = in.readInt();
- firstName = in.readUTF();
- lastName = in.readUTF();
- salary = in.readDouble();
- }
-
- /** {@inheritDoc} */
@Override public boolean equals(Object o) {
return this == o || (o instanceof Person) && id == ((Person)o).id;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java
index 07fa2bc..01c2db2 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheP2pUnmarshallingQueryErrorTest.java
@@ -23,6 +23,8 @@ import javax.cache.CacheException;
import org.apache.ignite.cache.query.ScanQuery;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteKernal;
import org.apache.ignite.lang.IgniteBiPredicate;
/**
@@ -51,10 +53,10 @@ public class IgniteCacheP2pUnmarshallingQueryErrorTest extends IgniteCacheP2pUnm
try {
jcache(0).query(new SqlQuery<TestKey, String>(String.class, "field like '" + key + "'")).getAll();
- fail("p2p marshalling failed, but error response was not sent");
+ assertTrue("p2p marshalling failed, but error response was not sent", portableMarshaller());
}
catch (CacheException e) {
- // No-op
+ assertFalse("Unexpected exception: " + e, portableMarshaller());
}
}
@@ -77,10 +79,19 @@ public class IgniteCacheP2pUnmarshallingQueryErrorTest extends IgniteCacheP2pUnm
}
})).getAll();
- fail("Request unmarshalling failed, but error response was not sent.");
+ assertTrue("Request unmarshalling failed, but error response was not sent.", portableMarshaller());
}
catch (Exception e) {
- // No-op.
+ assertFalse("Unexpected exception: " + e, portableMarshaller());
}
}
+
+ /**
+ * @return {@code True} if portable marshaller is configured.
+ */
+ private boolean portableMarshaller() {
+ IgniteEx kernal = (IgniteKernal)ignite(0);
+
+ return "PortableMarshaller".equals(kernal.context().config().getMarshaller().getClass().getSimpleName());
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePartitionedQueryMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePartitionedQueryMultiThreadedSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePartitionedQueryMultiThreadedSelfTest.java
index 7324e62..42f4c6e 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePartitionedQueryMultiThreadedSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePartitionedQueryMultiThreadedSelfTest.java
@@ -18,9 +18,6 @@
package org.apache.ignite.internal.processors.cache;
import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.util.Collection;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -43,7 +40,6 @@ import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.typedef.CAX;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
@@ -220,7 +216,7 @@ public class IgniteCachePartitionedQueryMultiThreadedSelfTest extends GridCommon
}
/** Test class. */
- private static class PersonObj implements Externalizable {
+ private static class PersonObj {
/** */
@GridToStringExclude
private UUID id = UUID.randomUUID();
@@ -279,22 +275,6 @@ public class IgniteCachePartitionedQueryMultiThreadedSelfTest extends GridCommon
}
/** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- U.writeUuid(out, id);
- U.writeString(out, name);
- out.writeInt(salary);
- U.writeString(out, degree);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- id = U.readUuid(in);
- name = U.readString(in);
- salary = in.readInt();
- degree = U.readString(in);
- }
-
- /** {@inheritDoc} */
@Override public int hashCode() {
return id.hashCode() + 31 * name.hashCode() + 31 * 31 * salary;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
index acfe3b6..194fb82 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/GridIndexingSpiAbstractSelfTest.java
@@ -565,11 +565,16 @@ public abstract class GridIndexingSpiAbstractSelfTest extends GridCommonAbstract
}
/** {@inheritDoc} */
- @Override public byte type() {
+ @Override public byte cacheObjectType() {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
+ @Override public boolean isPlatformType() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
@Override public CacheObject prepareForCache(CacheObjectContext ctx) {
throw new UnsupportedOperationException();
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
index ca85a2a..26a142b 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheAbstractTest.cs
@@ -342,7 +342,7 @@ namespace Apache.Ignite.Core.Tests.Cache
[TearDown]
public virtual void AfterTest() {
for (int i = 0; i < GridCount(); i++)
- Cache(i).RemoveAll();
+ Cache(i).WithKeepPortable<object, object>().RemoveAll();
for (int i = 0; i < GridCount(); i++)
{
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Compute/compute-grid1.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Compute/compute-grid1.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Compute/compute-grid1.xml
index 183676b..0ad0070 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Compute/compute-grid1.xml
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/Compute/compute-grid1.xml
@@ -72,13 +72,13 @@
<bean class="org.apache.ignite.marshaller.portable.PortableMarshaller">
<property name="typeConfigurations">
<list>
- <bean class="org.apache.ignite.portable.PortableTypeConfiguration">
+ <bean class="org.apache.ignite.binary.BinaryTypeConfiguration">
<property name="className" value="org.apache.ignite.platform.PlatformComputePortable"/>
</bean>
- <bean class="org.apache.ignite.portable.PortableTypeConfiguration">
+ <bean class="org.apache.ignite.binary.BinaryTypeConfiguration">
<property name="className" value="org.apache.ignite.platform.PlatformComputeJavaPortable"/>
</bean>
- <bean class="org.apache.ignite.portable.PortableTypeConfiguration">
+ <bean class="org.apache.ignite.binary.BinaryTypeConfiguration">
<property name="className" value="org.apache.ignite.platform.PlatformComputeEnum"/>
</bean>
</list>
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
index ad7de45..c7667d2 100644
--- a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
+++ b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
@@ -355,10 +355,10 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
}
/** {@inheritDoc} */
- @Override public IgnitePortables portables() {
+ @Override public IgniteBinary binary() {
assert g != null;
- return g.portables();
+ return g.binary();
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Organization.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Organization.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Organization.java
index efb71d6..f457e7e 100644
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Organization.java
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Organization.java
@@ -21,16 +21,16 @@ import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+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.query.annotations.QuerySqlField;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
/**
* Organization record used for query test.
*/
-public class Organization implements Externalizable, PortableMarshalAware {
+public class Organization implements Externalizable, Binarylizable {
/** Organization ID. */
@QuerySqlField(index = true)
private int id;
@@ -98,13 +98,13 @@ public class Organization implements Externalizable, PortableMarshalAware {
}
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeInt("id", id);
writer.writeString("name", name);
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
id = reader.readInt("id");
name = reader.readString("name");
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Person.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Person.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Person.java
index e826d65..e59ba19 100644
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Person.java
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Person.java
@@ -21,16 +21,16 @@ import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+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.query.annotations.QuerySqlField;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
/**
* Person record used for query test.
*/
-public class Person implements Externalizable, PortableMarshalAware {
+public class Person implements Externalizable, Binarylizable {
/** Person ID. */
@QuerySqlField(index = true)
private int id;
@@ -176,7 +176,7 @@ public class Person implements Externalizable, PortableMarshalAware {
}
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeInt("id", id);
writer.writeInt("orgId", orgId);
writer.writeString("firstName", firstName);
@@ -185,7 +185,7 @@ public class Person implements Externalizable, PortableMarshalAware {
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
id = reader.readInt("id");
orgId = reader.readInt("orgId");
firstName = reader.readString("firstName");
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleKey.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleKey.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleKey.java
index 5fa9dea..e089696 100644
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleKey.java
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleKey.java
@@ -21,15 +21,15 @@ import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
/**
* Key class for benchmark.
*/
-public class SampleKey implements Externalizable, PortableMarshalAware {
+public class SampleKey implements Externalizable, Binarylizable {
/** */
private int id;
@@ -70,12 +70,12 @@ public class SampleKey implements Externalizable, PortableMarshalAware {
}
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeInt("id", id);
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
id = reader.readInt("id");
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java
----------------------------------------------------------------------
diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java
index f15d671..b28862c 100644
--- a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java
+++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/SampleValue.java
@@ -21,15 +21,15 @@ import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
/**
* Entity class for benchmark.
*/
-public class SampleValue implements Externalizable, PortableMarshalAware {
+public class SampleValue implements Externalizable, Binarylizable {
/** */
private int id;
@@ -70,12 +70,12 @@ public class SampleValue implements Externalizable, PortableMarshalAware {
}
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeInt("id", id);
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
id = reader.readInt("id");
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 06dfd70..07c1847 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -320,8 +320,8 @@
<packages>org.apache.ignite.marshaller*</packages>
</group>
<group>
- <title>Portable Objects API</title>
- <packages>org.apache.ignite.portable*</packages>
+ <title>Ignite Binary Objects API</title>
+ <packages>org.apache.ignite.binary*</packages>
</group>
<group>
<title>Visor Plugins</title>
@@ -749,7 +749,8 @@
<exclude>**/configure.ac</exclude>
<exclude>**/*.pc.in</exclude>
<exclude>**/*.sln</exclude>
- <exclude>**/*.slnrel</exclude>
+ <exclude>**/*.snk</exclude>
+ <exclude>**/*.slnrel</exclude>
<exclude>**/*.sln.DotSettings</exclude>
<exclude>**/*.FxCop</exclude>
<exclude>**/*.csproj</exclude>
[09/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
index 7a08ef5..4c0921a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
@@ -24,8 +24,8 @@ import org.apache.ignite.IgniteLogger;
import org.apache.ignite.cache.CachePeekMode;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.PlatformExtendedException;
import org.apache.ignite.internal.processors.platform.PlatformNativeException;
@@ -96,7 +96,7 @@ public class PlatformUtils {
* @param writer Writer.
* @param col Collection to write.
*/
- public static <T> void writeNullableCollection(PortableRawWriterEx writer, @Nullable Collection<T> col) {
+ public static <T> void writeNullableCollection(BinaryRawWriterEx writer, @Nullable Collection<T> col) {
writeNullableCollection(writer, col, null, null);
}
@@ -107,7 +107,7 @@ public class PlatformUtils {
* @param col Collection to write.
* @param writeClo Writer closure.
*/
- public static <T> void writeNullableCollection(PortableRawWriterEx writer, @Nullable Collection<T> col,
+ public static <T> void writeNullableCollection(BinaryRawWriterEx writer, @Nullable Collection<T> col,
@Nullable PlatformWriterClosure<T> writeClo) {
writeNullableCollection(writer, col, writeClo, null);
}
@@ -120,7 +120,7 @@ public class PlatformUtils {
* @param writeClo Optional writer closure.
* @param filter Optional filter.
*/
- public static <T> void writeNullableCollection(PortableRawWriterEx writer, @Nullable Collection<T> col,
+ public static <T> void writeNullableCollection(BinaryRawWriterEx writer, @Nullable Collection<T> col,
@Nullable PlatformWriterClosure<T> writeClo, @Nullable IgnitePredicate<T> filter) {
if (col != null) {
writer.writeBoolean(true);
@@ -137,7 +137,7 @@ public class PlatformUtils {
* @param writer Writer.
* @param col Collection to write.
*/
- public static <T> void writeCollection(PortableRawWriterEx writer, Collection<T> col) {
+ public static <T> void writeCollection(BinaryRawWriterEx writer, Collection<T> col) {
writeCollection(writer, col, null, null);
}
@@ -148,7 +148,7 @@ public class PlatformUtils {
* @param col Collection to write.
* @param writeClo Writer closure.
*/
- public static <T> void writeCollection(PortableRawWriterEx writer, Collection<T> col,
+ public static <T> void writeCollection(BinaryRawWriterEx writer, Collection<T> col,
@Nullable PlatformWriterClosure<T> writeClo) {
writeCollection(writer, col, writeClo, null);
}
@@ -161,7 +161,7 @@ public class PlatformUtils {
* @param writeClo Optional writer closure.
* @param filter Optional filter.
*/
- public static <T> void writeCollection(PortableRawWriterEx writer, Collection<T> col,
+ public static <T> void writeCollection(BinaryRawWriterEx writer, Collection<T> col,
@Nullable PlatformWriterClosure<T> writeClo, @Nullable IgnitePredicate<T> filter) {
assert col != null;
@@ -202,7 +202,7 @@ public class PlatformUtils {
* @param writer Writer.
* @param map Map to write.
*/
- public static <K, V> void writeNullableMap(PortableRawWriterEx writer, @Nullable Map<K, V> map) {
+ public static <K, V> void writeNullableMap(BinaryRawWriterEx writer, @Nullable Map<K, V> map) {
if (map != null) {
writer.writeBoolean(true);
@@ -218,7 +218,7 @@ public class PlatformUtils {
* @param writer Writer.
* @param map Map to write.
*/
- public static <K, V> void writeMap(PortableRawWriterEx writer, Map<K, V> map) {
+ public static <K, V> void writeMap(BinaryRawWriterEx writer, Map<K, V> map) {
assert map != null;
writeMap(writer, map, null);
@@ -231,7 +231,7 @@ public class PlatformUtils {
* @param map Map to write.
* @param writeClo Writer closure.
*/
- public static <K, V> void writeMap(PortableRawWriterEx writer, Map<K, V> map,
+ public static <K, V> void writeMap(BinaryRawWriterEx writer, Map<K, V> map,
@Nullable PlatformWriterBiClosure<K, V> writeClo) {
assert map != null;
@@ -255,7 +255,7 @@ public class PlatformUtils {
* @param reader Reader.
* @return List.
*/
- public static <T> List<T> readCollection(PortableRawReaderEx reader) {
+ public static <T> List<T> readCollection(BinaryRawReaderEx reader) {
return readCollection(reader, null);
}
@@ -266,7 +266,7 @@ public class PlatformUtils {
* @param readClo Optional reader closure.
* @return List.
*/
- public static <T> List<T> readCollection(PortableRawReaderEx reader, @Nullable PlatformReaderClosure<T> readClo) {
+ public static <T> List<T> readCollection(BinaryRawReaderEx reader, @Nullable PlatformReaderClosure<T> readClo) {
int cnt = reader.readInt();
List<T> res = new ArrayList<>(cnt);
@@ -289,7 +289,7 @@ public class PlatformUtils {
* @param reader Reader.
* @return List.
*/
- public static <T> List<T> readNullableCollection(PortableRawReaderEx reader) {
+ public static <T> List<T> readNullableCollection(BinaryRawReaderEx reader) {
return readNullableCollection(reader, null);
}
@@ -299,7 +299,7 @@ public class PlatformUtils {
* @param reader Reader.
* @return List.
*/
- public static <T> List<T> readNullableCollection(PortableRawReaderEx reader,
+ public static <T> List<T> readNullableCollection(BinaryRawReaderEx reader,
@Nullable PlatformReaderClosure<T> readClo) {
if (!reader.readBoolean())
return null;
@@ -311,7 +311,7 @@ public class PlatformUtils {
* @param reader Reader.
* @return Set.
*/
- public static <T> Set<T> readSet(PortableRawReaderEx reader) {
+ public static <T> Set<T> readSet(BinaryRawReaderEx reader) {
int cnt = reader.readInt();
Set<T> res = U.newHashSet(cnt);
@@ -326,7 +326,7 @@ public class PlatformUtils {
* @param reader Reader.
* @return Set.
*/
- public static <T> Set<T> readNullableSet(PortableRawReaderEx reader) {
+ public static <T> Set<T> readNullableSet(BinaryRawReaderEx reader) {
if (!reader.readBoolean())
return null;
@@ -339,7 +339,7 @@ public class PlatformUtils {
* @param reader Reader.
* @return Map.
*/
- public static <K, V> Map<K, V> readMap(PortableRawReaderEx reader) {
+ public static <K, V> Map<K, V> readMap(BinaryRawReaderEx reader) {
return readMap(reader, null);
}
@@ -350,7 +350,7 @@ public class PlatformUtils {
* @param readClo Reader closure.
* @return Map.
*/
- public static <K, V> Map<K, V> readMap(PortableRawReaderEx reader,
+ public static <K, V> Map<K, V> readMap(BinaryRawReaderEx reader,
@Nullable PlatformReaderBiClosure<K, V> readClo) {
int cnt = reader.readInt();
@@ -377,7 +377,7 @@ public class PlatformUtils {
* @param reader Reader.
* @return Map.
*/
- public static <K, V> Map<K, V> readNullableMap(PortableRawReaderEx reader) {
+ public static <K, V> Map<K, V> readNullableMap(BinaryRawReaderEx reader) {
if (!reader.readBoolean())
return null;
@@ -390,7 +390,7 @@ public class PlatformUtils {
* @param writer Writer.
* @param val Values.
*/
- public static void writeIgniteUuid(PortableRawWriterEx writer, IgniteUuid val) {
+ public static void writeIgniteUuid(BinaryRawWriterEx writer, IgniteUuid val) {
if (val == null)
writer.writeUuid(null);
else {
@@ -483,7 +483,7 @@ public class PlatformUtils {
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
int cntPos = writer.reserveInt();
@@ -552,7 +552,7 @@ public class PlatformUtils {
* @param writer Writer.
* @param evt Event.
*/
- private static void writeCacheEntryEvent(PortableRawWriterEx writer, CacheEntryEvent evt) {
+ private static void writeCacheEntryEvent(BinaryRawWriterEx writer, CacheEntryEvent evt) {
writer.writeObjectDetached(evt.getKey());
writer.writeObjectDetached(evt.getOldValue());
writer.writeObjectDetached(evt.getValue());
@@ -564,7 +564,7 @@ public class PlatformUtils {
* @param err Error.
* @param writer Writer.
*/
- public static void writeErrorData(Throwable err, PortableRawWriterEx writer) {
+ public static void writeErrorData(Throwable err, BinaryRawWriterEx writer) {
writeErrorData(err, writer, null);
}
@@ -574,7 +574,7 @@ public class PlatformUtils {
* @param writer Writer.
* @param log Optional logger.
*/
- public static void writeErrorData(Throwable err, PortableRawWriterEx writer, @Nullable IgniteLogger log) {
+ public static void writeErrorData(Throwable err, BinaryRawWriterEx writer, @Nullable IgniteLogger log) {
// Write additional data if needed.
if (err instanceof PlatformExtendedException) {
PlatformExtendedException err0 = (PlatformExtendedException)err;
@@ -659,7 +659,7 @@ public class PlatformUtils {
// Write error data.
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
try {
PlatformUtils.writeErrorData(err, writer, ctx.kernalContext().log(PlatformContext.class));
@@ -696,7 +696,7 @@ public class PlatformUtils {
* @param resObj Result.
* @param err Error.
*/
- public static void writeInvocationResult(PortableRawWriterEx writer, Object resObj, Exception err)
+ public static void writeInvocationResult(BinaryRawWriterEx writer, Object resObj, Exception err)
{
if (err == null) {
writer.writeBoolean(true);
@@ -732,7 +732,7 @@ public class PlatformUtils {
* @return Result.
* @throws IgniteCheckedException When invocation result is an error.
*/
- public static Object readInvocationResult(PlatformContext ctx, PortableRawReaderEx reader)
+ public static Object readInvocationResult(PlatformContext ctx, BinaryRawReaderEx reader)
throws IgniteCheckedException {
// 1. Read success flag.
boolean success = reader.readBoolean();
@@ -769,7 +769,7 @@ public class PlatformUtils {
* @param writer Writer.
* @param cfg Configuration.
*/
- public static void writeDotNetConfiguration(PortableRawWriterEx writer, PlatformDotNetConfiguration cfg) {
+ public static void writeDotNetConfiguration(BinaryRawWriterEx writer, PlatformDotNetConfiguration cfg) {
// 1. Write assemblies.
writeNullableCollection(writer, cfg.getAssemblies());
@@ -780,7 +780,7 @@ public class PlatformUtils {
writeNullableCollection(writer, portableCfg.getTypesConfiguration(),
new PlatformWriterClosure<PlatformDotNetPortableTypeConfiguration>() {
- @Override public void write(PortableRawWriterEx writer, PlatformDotNetPortableTypeConfiguration typ) {
+ @Override public void write(BinaryRawWriterEx writer, PlatformDotNetPortableTypeConfiguration typ) {
writer.writeString(typ.getTypeName());
writer.writeString(typ.getNameMapper());
writer.writeString(typ.getIdMapper());
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterBiClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterBiClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterBiClosure.java
index 6b04ad3..b0e6a65 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterBiClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterBiClosure.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.processors.platform.utils;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
/**
* Interop writer bi-closure.
@@ -30,5 +30,5 @@ public interface PlatformWriterBiClosure<T1, T2> {
* @param val1 Value 1.
* @param val2 Value 2.
*/
- public void write(PortableRawWriterEx writer, T1 val1, T2 val2);
+ public void write(BinaryRawWriterEx writer, T1 val1, T2 val2);
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterClosure.java
index a67d70a..c55c209 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterClosure.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.processors.platform.utils;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
/**
* Interop writer closure.
@@ -29,5 +29,5 @@ public interface PlatformWriterClosure<T> {
* @param writer Writer.
* @param val Value.
*/
- public void write(PortableRawWriterEx writer, T val);
+ public void write(BinaryRawWriterEx writer, T val);
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
index cf8d4a2..7697a12 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryIndexing.java
@@ -155,22 +155,6 @@ public interface GridQueryIndexing {
public void unregisterCache(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException;
/**
- * Checks if the given class can be mapped to a simple SQL type.
- *
- * @param cls Class.
- * @return {@code true} If can.
- */
- public boolean isSqlType(Class<?> cls);
-
- /**
- * Checks if the given class is GEOMETRY.
- *
- * @param cls Class.
- * @return {@code true} If this is geometry.
- */
- public boolean isGeometryClass(Class<?> cls);
-
- /**
* Registers type if it was not known before or updates it otherwise.
*
* @param spaceName Space name.
@@ -257,4 +241,4 @@ public interface GridQueryIndexing {
* @param reconnectFut Reconnect future.
*/
public void onDisconnected(IgniteFuture<?> reconnectFut);
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 84db145..d1f9869 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -21,6 +21,9 @@ import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.sql.Time;
+import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -31,7 +34,9 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.TreeSet;
+import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import javax.cache.Cache;
@@ -40,14 +45,15 @@ import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.cache.CacheTypeMetadata;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.QueryIndexType;
import org.apache.ignite.cache.query.QueryCursor;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.query.SqlQuery;
-import org.apache.ignite.cache.query.annotations.QueryGroupIndex;
-import org.apache.ignite.cache.query.annotations.QuerySqlField;
-import org.apache.ignite.cache.query.annotations.QueryTextField;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.events.CacheQueryExecutedEvent;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.processors.GridProcessorAdapter;
@@ -89,6 +95,31 @@ import static org.apache.ignite.internal.processors.query.GridQueryIndexType.SOR
* Indexing processor.
*/
public class GridQueryProcessor extends GridProcessorAdapter {
+ /** */
+ public static final String _VAL = "_val";
+
+ /** */
+ private static final Class<?> GEOMETRY_CLASS = U.classForName("com.vividsolutions.jts.geom.Geometry", null);
+
+ /** */
+ private static Set<Class<?>> SQL_TYPES = new HashSet<>(F.<Class<?>>asList(
+ Integer.class,
+ Boolean.class,
+ Byte.class,
+ Short.class,
+ Long.class,
+ BigDecimal.class,
+ Double.class,
+ Float.class,
+ Time.class,
+ Timestamp.class,
+ java.util.Date.class,
+ java.sql.Date.class,
+ String.class,
+ UUID.class,
+ byte[].class
+ ));
+
/** For tests. */
public static Class<? extends GridQueryIndexing> idxCls;
@@ -140,7 +171,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
* @return {@code true} If query index must be enabled for this cache.
*/
public static boolean isEnabled(CacheConfiguration<?,?> ccfg) {
- return !F.isEmpty(ccfg.getIndexedTypes()) || !F.isEmpty(ccfg.getTypeMetadata());
+ return !F.isEmpty(ccfg.getIndexedTypes()) ||
+ !F.isEmpty(ccfg.getTypeMetadata()) ||
+ !F.isEmpty(ccfg.getQueryEntities());
}
/**
@@ -158,58 +191,128 @@ public class GridQueryProcessor extends GridProcessorAdapter {
idx.registerCache(ccfg);
try {
- if (!F.isEmpty(ccfg.getTypeMetadata())) {
- for (CacheTypeMetadata meta : ccfg.getTypeMetadata()) {
- if (F.isEmpty(meta.getValueType()))
- throw new IgniteCheckedException("Value type is not set: " + meta);
+ if (!F.isEmpty(ccfg.getQueryEntities())) {
+ for (QueryEntity qryEntity : ccfg.getQueryEntities()) {
+ if (F.isEmpty(qryEntity.getValueType()))
+ throw new IgniteCheckedException("Value type is not set: " + qryEntity);
TypeDescriptor desc = new TypeDescriptor();
- Class<?> valCls = U.classForName(meta.getValueType(), null);
+ // Key and value classes still can be available if they are primitive or JDK part.
+ // We need that to set correct types for _key and _val columns.
+ Class<?> keyCls = U.classForName(qryEntity.getKeyType(), Object.class);
+ Class<?> valCls = U.classForName(qryEntity.getValueType(), null);
+
+ String simpleValType = valCls == null ? qryEntity.getValueType() : typeName(valCls);
- desc.name(valCls != null ? typeName(valCls) : meta.getValueType());
+ desc.name(simpleValType);
- desc.valueClass(valCls != null ? valCls : Object.class);
- desc.keyClass(
- meta.getKeyType() == null ?
- Object.class :
- U.classForName(meta.getKeyType(), Object.class));
+ if (ctx.cacheObjects().isPortableEnabled(ccfg)) {
+ // Safe to check null.
+ if (SQL_TYPES.contains(valCls))
+ desc.valueClass(valCls);
+ else
+ desc.valueClass(Object.class);
+
+ if (SQL_TYPES.contains(keyCls))
+ desc.keyClass(keyCls);
+ else
+ desc.keyClass(Object.class);
+ }
+ else {
+ desc.valueClass(valCls);
+ desc.keyClass(keyCls);
+ }
TypeId typeId;
+ TypeId altTypeId = null;
if (valCls == null || ctx.cacheObjects().isPortableEnabled(ccfg)) {
- processPortableMeta(meta, desc);
+ processPortableMeta(qryEntity, desc);
- typeId = new TypeId(ccfg.getName(), ctx.cacheObjects().typeId(meta.getValueType()));
+ typeId = new TypeId(ccfg.getName(), ctx.cacheObjects().typeId(qryEntity.getValueType()));
+
+ if (valCls != null)
+ altTypeId = new TypeId(ccfg.getName(), valCls);
}
else {
- processClassMeta(meta, desc);
+ processClassMeta(qryEntity, desc);
typeId = new TypeId(ccfg.getName(), valCls);
+ altTypeId = new TypeId(ccfg.getName(), ctx.cacheObjects().typeId(qryEntity.getValueType()));
}
addTypeByName(ccfg, desc);
types.put(typeId, desc);
+ if (altTypeId != null)
+ types.put(altTypeId, desc);
+
desc.registered(idx.registerType(ccfg.getName(), desc));
+
}
}
- Class<?>[] clss = ccfg.getIndexedTypes();
+ if (!F.isEmpty(ccfg.getTypeMetadata())) {
+ for (CacheTypeMetadata meta : ccfg.getTypeMetadata()) {
+ if (F.isEmpty(meta.getValueType()))
+ throw new IgniteCheckedException("Value type is not set: " + meta);
+
+ TypeDescriptor desc = new TypeDescriptor();
+
+ // Key and value classes still can be available if they are primitive or JDK part.
+ // We need that to set correct types for _key and _val columns.
+ Class<?> keyCls = U.classForName(meta.getKeyType(), Object.class);
+ Class<?> valCls = U.classForName(meta.getValueType(), null);
+
+ desc.name(meta.getSimpleValueType());
- if (!F.isEmpty(clss)) {
- for (int i = 0; i < clss.length; i += 2) {
- Class<?> keyCls = clss[i];
- Class<?> valCls = clss[i + 1];
+ if (ctx.cacheObjects().isPortableEnabled(ccfg)) {
+ // Safe to check null.
+ if (SQL_TYPES.contains(valCls))
+ desc.valueClass(valCls);
+ else
+ desc.valueClass(Object.class);
- TypeDescriptor desc = processKeyAndValueClasses(keyCls, valCls);
+ if (SQL_TYPES.contains(keyCls))
+ desc.keyClass(keyCls);
+ else
+ desc.keyClass(Object.class);
+ }
+ else {
+ desc.valueClass(valCls);
+ desc.keyClass(keyCls);
+ }
+
+ TypeId typeId;
+ TypeId altTypeId = null;
+
+ if (valCls == null || ctx.cacheObjects().isPortableEnabled(ccfg)) {
+ processPortableMeta(meta, desc);
+
+ typeId = new TypeId(ccfg.getName(), ctx.cacheObjects().typeId(meta.getValueType()));
+
+ if (valCls != null)
+ altTypeId = new TypeId(ccfg.getName(), valCls);
+ }
+ else {
+ processClassMeta(meta, desc);
+
+ typeId = new TypeId(ccfg.getName(), valCls);
+ altTypeId = new TypeId(ccfg.getName(), ctx.cacheObjects().typeId(meta.getValueType()));
+ }
addTypeByName(ccfg, desc);
- types.put(new TypeId(ccfg.getName(), valCls), desc);
+ types.put(typeId, desc);
+
+ if (altTypeId != null)
+ types.put(altTypeId, desc);
desc.registered(idx.registerType(ccfg.getName(), desc));
}
}
+
+ // Indexed types must be translated to CacheTypeMetadata in CacheConfiguration.
}
catch (IgniteCheckedException | RuntimeException e) {
idx.unregisterCache(ccfg);
@@ -229,33 +332,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
"in cache '" + ccfg.getName() + "'.");
}
- /**
- * @param keyCls Key class.
- * @param valCls Value class.
- * @return Type descriptor.
- * @throws IgniteCheckedException If failed.
- */
- private TypeDescriptor processKeyAndValueClasses(
- Class<?> keyCls,
- Class<?> valCls
- )
- throws IgniteCheckedException {
- TypeDescriptor d = new TypeDescriptor();
-
- d.keyClass(keyCls);
- d.valueClass(valCls);
-
- processAnnotationsInClass(true, d.keyCls, d, null);
-
- String valTypeName = typeName(valCls);
-
- d.name(valTypeName);
-
- processAnnotationsInClass(false, d.valCls, d, null);
-
- return d;
- }
-
/** {@inheritDoc} */
@Override public void onKernalStop(boolean cancel) {
super.onKernalStop(cancel);
@@ -845,6 +921,28 @@ public class GridQueryProcessor extends GridProcessorAdapter {
}
/**
+ * Checks if the given class can be mapped to a simple SQL type.
+ *
+ * @param cls Class.
+ * @return {@code true} If can.
+ */
+ public static boolean isSqlType(Class<?> cls) {
+ cls = U.box(cls);
+
+ return SQL_TYPES.contains(cls) || isGeometryClass(cls);
+ }
+
+ /**
+ * Checks if the given class is GEOMETRY.
+ *
+ * @param cls Class.
+ * @return {@code true} If this is geometry.
+ */
+ public static boolean isGeometryClass(Class<?> cls) {
+ return GEOMETRY_CLASS != null && GEOMETRY_CLASS.isAssignableFrom(cls);
+ }
+
+ /**
* Gets type name by class.
*
* @param cls Class.
@@ -1050,182 +1148,168 @@ public class GridQueryProcessor extends GridProcessorAdapter {
}
/**
- * Process annotations for class.
+ * Processes declarative metadata for class.
*
- * @param key If given class relates to key.
- * @param cls Class.
- * @param type Type descriptor.
- * @param parent Parent in case of embeddable.
- * @throws IgniteCheckedException In case of error.
+ * @param meta Type metadata.
+ * @param d Type descriptor.
+ * @throws IgniteCheckedException If failed.
*/
- private void processAnnotationsInClass(boolean key, Class<?> cls, TypeDescriptor type,
- @Nullable ClassProperty parent) throws IgniteCheckedException {
- if (U.isJdk(cls) || idx.isGeometryClass(cls)) {
- if (parent == null && !key && idx.isSqlType(cls) ) { // We have to index primitive _val.
- String idxName = "_val_idx";
-
- type.addIndex(idxName, idx.isGeometryClass(cls) ? GEO_SPATIAL : SORTED);
+ private void processClassMeta(CacheTypeMetadata meta, TypeDescriptor d)
+ throws IgniteCheckedException {
+ Map<String,String> aliases = meta.getAliases();
- type.addFieldToIndex(idxName, "_VAL", 0, false);
- }
+ if (aliases == null)
+ aliases = Collections.emptyMap();
- return;
- }
+ Class<?> keyCls = d.keyClass();
+ Class<?> valCls = d.valueClass();
- if (parent != null && parent.knowsClass(cls))
- throw new IgniteCheckedException("Recursive reference found in type: " + cls.getName());
+ assert keyCls != null;
+ assert valCls != null;
- if (parent == null) { // Check class annotation at top level only.
- QueryTextField txtAnnCls = cls.getAnnotation(QueryTextField.class);
+ for (Map.Entry<String, Class<?>> entry : meta.getAscendingFields().entrySet())
+ addToIndex(d, keyCls, valCls, entry.getKey(), entry.getValue(), 0, IndexType.ASC, null, aliases);
- if (txtAnnCls != null)
- type.valueTextIndex(true);
+ for (Map.Entry<String, Class<?>> entry : meta.getDescendingFields().entrySet())
+ addToIndex(d, keyCls, valCls, entry.getKey(), entry.getValue(), 0, IndexType.DESC, null, aliases);
- QueryGroupIndex grpIdx = cls.getAnnotation(QueryGroupIndex.class);
+ for (String txtField : meta.getTextFields())
+ addToIndex(d, keyCls, valCls, txtField, String.class, 0, IndexType.TEXT, null, aliases);
- if (grpIdx != null)
- type.addIndex(grpIdx.name(), SORTED);
+ Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> grps = meta.getGroups();
- QueryGroupIndex.List grpIdxList = cls.getAnnotation(QueryGroupIndex.List.class);
+ if (grps != null) {
+ for (Map.Entry<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> entry : grps.entrySet()) {
+ String idxName = entry.getKey();
- if (grpIdxList != null && !F.isEmpty(grpIdxList.value())) {
- for (QueryGroupIndex idx : grpIdxList.value())
- type.addIndex(idx.name(), SORTED);
- }
- }
+ LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>> idxFields = entry.getValue();
- for (Class<?> c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
- for (Field field : c.getDeclaredFields()) {
- QuerySqlField sqlAnn = field.getAnnotation(QuerySqlField.class);
- QueryTextField txtAnn = field.getAnnotation(QueryTextField.class);
+ int order = 0;
- if (sqlAnn != null || txtAnn != null) {
- ClassProperty prop = new ClassProperty(field, key);
+ for (Map.Entry<String, IgniteBiTuple<Class<?>, Boolean>> idxField : idxFields.entrySet()) {
+ Boolean descending = idxField.getValue().get2();
- prop.parent(parent);
+ if (descending == null)
+ descending = false;
- processAnnotation(key, sqlAnn, txtAnn, field.getType(), prop, type);
+ addToIndex(d, keyCls, valCls, idxField.getKey(), idxField.getValue().get1(), order,
+ descending ? IndexType.DESC : IndexType.ASC, idxName, aliases);
- type.addProperty(prop, true);
+ order++;
}
}
+ }
- for (Method mtd : c.getDeclaredMethods()) {
- QuerySqlField sqlAnn = mtd.getAnnotation(QuerySqlField.class);
- QueryTextField txtAnn = mtd.getAnnotation(QueryTextField.class);
-
- if (sqlAnn != null || txtAnn != null) {
- if (mtd.getParameterTypes().length != 0)
- throw new IgniteCheckedException("Getter with QuerySqlField " +
- "annotation cannot have parameters: " + mtd);
-
- ClassProperty prop = new ClassProperty(mtd, key);
-
- prop.parent(parent);
-
- processAnnotation(key, sqlAnn, txtAnn, mtd.getReturnType(), prop, type);
+ for (Map.Entry<String, Class<?>> entry : meta.getQueryFields().entrySet()) {
+ ClassProperty prop = buildClassProperty(
+ keyCls,
+ valCls,
+ entry.getKey(),
+ entry.getValue(),
+ aliases);
- type.addProperty(prop, true);
- }
- }
+ d.addProperty(prop, false);
}
}
/**
- * Processes annotation at field or method.
- *
- * @param key If given class relates to key.
- * @param sqlAnn SQL annotation, can be {@code null}.
- * @param txtAnn H2 text annotation, can be {@code null}.
- * @param cls Class of field or return type for method.
- * @param prop Current property.
- * @param desc Class description.
- * @throws IgniteCheckedException In case of error.
+ * @param d Type descriptor.
+ * @param keyCls Key class.
+ * @param valCls Value class.
+ * @param pathStr Path string.
+ * @param resType Result type.
+ * @param idxOrder Order number in index or {@code -1} if no need to index.
+ * @param idxType Index type.
+ * @param idxName Index name.
+ * @param aliases Aliases.
+ * @throws IgniteCheckedException If failed.
*/
- private void processAnnotation(boolean key, QuerySqlField sqlAnn, QueryTextField txtAnn,
- Class<?> cls, ClassProperty prop, TypeDescriptor desc) throws IgniteCheckedException {
- if (sqlAnn != null) {
- processAnnotationsInClass(key, cls, desc, prop);
-
- if (!sqlAnn.name().isEmpty())
- prop.name(sqlAnn.name());
+ private void addToIndex(
+ TypeDescriptor d,
+ Class<?> keyCls,
+ Class<?> valCls,
+ String pathStr,
+ Class<?> resType,
+ int idxOrder,
+ IndexType idxType,
+ String idxName,
+ Map<String,String> aliases
+ ) throws IgniteCheckedException {
+ String propName;
+ Class<?> propCls;
+
+ if (_VAL.equals(pathStr)) {
+ propName = _VAL;
+ propCls = valCls;
+ }
+ else {
+ ClassProperty prop = buildClassProperty(
+ keyCls,
+ valCls,
+ pathStr,
+ resType,
+ aliases);
- if (sqlAnn.index()) {
- String idxName = prop.name() + "_idx";
+ d.addProperty(prop, false);
- desc.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+ propName = prop.name();
+ propCls = prop.type();
+ }
- desc.addFieldToIndex(idxName, prop.name(), 0, sqlAnn.descending());
- }
+ if (idxType != null) {
+ if (idxName == null)
+ idxName = propName + "_idx";
- if (!F.isEmpty(sqlAnn.groups())) {
- for (String group : sqlAnn.groups())
- desc.addFieldToIndex(group, prop.name(), 0, false);
- }
+ if (idxOrder == 0) // Add index only on the first field.
+ d.addIndex(idxName, isGeometryClass(propCls) ? GEO_SPATIAL : SORTED);
- if (!F.isEmpty(sqlAnn.orderedGroups())) {
- for (QuerySqlField.Group idx : sqlAnn.orderedGroups())
- desc.addFieldToIndex(idx.name(), prop.name(), idx.order(), idx.descending());
- }
+ if (idxType == IndexType.TEXT)
+ d.addFieldToTextIndex(propName);
+ else
+ d.addFieldToIndex(idxName, propName, idxOrder, idxType == IndexType.DESC);
}
-
- if (txtAnn != null)
- desc.addFieldToTextIndex(prop.name());
}
/**
- * Processes declarative metadata for class.
+ * Processes declarative metadata for portable object.
*
- * @param meta Type metadata.
+ * @param meta Declared metadata.
* @param d Type descriptor.
* @throws IgniteCheckedException If failed.
*/
- private void processClassMeta(CacheTypeMetadata meta, TypeDescriptor d)
+ private void processPortableMeta(CacheTypeMetadata meta, TypeDescriptor d)
throws IgniteCheckedException {
- Class<?> keyCls = d.keyClass();
- Class<?> valCls = d.valueClass();
+ Map<String,String> aliases = meta.getAliases();
- assert keyCls != null;
- assert valCls != null;
+ if (aliases == null)
+ aliases = Collections.emptyMap();
for (Map.Entry<String, Class<?>> entry : meta.getAscendingFields().entrySet()) {
- ClassProperty prop = buildClassProperty(
- keyCls,
- valCls,
- entry.getKey(),
- entry.getValue());
+ PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue(), aliases);
d.addProperty(prop, false);
String idxName = prop.name() + "_idx";
- d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+ d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
d.addFieldToIndex(idxName, prop.name(), 0, false);
}
for (Map.Entry<String, Class<?>> entry : meta.getDescendingFields().entrySet()) {
- ClassProperty prop = buildClassProperty(
- keyCls,
- valCls,
- entry.getKey(),
- entry.getValue());
+ PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue(), aliases);
d.addProperty(prop, false);
String idxName = prop.name() + "_idx";
- d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+ d.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
d.addFieldToIndex(idxName, prop.name(), 0, true);
}
for (String txtIdx : meta.getTextFields()) {
- ClassProperty prop = buildClassProperty(
- keyCls,
- valCls,
- txtIdx,
- String.class);
+ PortableProperty prop = buildPortableProperty(txtIdx, String.class, aliases);
d.addProperty(prop, false);
@@ -1243,11 +1327,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
int order = 0;
for (Map.Entry<String, IgniteBiTuple<Class<?>, Boolean>> idxField : idxFields.entrySet()) {
- ClassProperty prop = buildClassProperty(
- keyCls,
- valCls,
- idxField.getKey(),
- idxField.getValue().get1());
+ PortableProperty prop = buildPortableProperty(idxField.getKey(), idxField.getValue().get1(), aliases);
d.addProperty(prop, false);
@@ -1261,86 +1341,113 @@ public class GridQueryProcessor extends GridProcessorAdapter {
}
for (Map.Entry<String, Class<?>> entry : meta.getQueryFields().entrySet()) {
- ClassProperty prop = buildClassProperty(
- keyCls,
- valCls,
- entry.getKey(),
- entry.getValue());
+ PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue(), aliases);
- d.addProperty(prop, false);
+ if (!d.props.containsKey(prop.name()))
+ d.addProperty(prop, false);
}
}
/**
* Processes declarative metadata for portable object.
*
- * @param meta Declared metadata.
+ * @param qryEntity Declared metadata.
* @param d Type descriptor.
* @throws IgniteCheckedException If failed.
*/
- private void processPortableMeta(CacheTypeMetadata meta, TypeDescriptor d)
- throws IgniteCheckedException {
- for (Map.Entry<String, Class<?>> entry : meta.getAscendingFields().entrySet()) {
- PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue());
-
- d.addProperty(prop, false);
+ private void processPortableMeta(QueryEntity qryEntity, TypeDescriptor d) throws IgniteCheckedException {
+ Map<String,String> aliases = qryEntity.getAliases();
- String idxName = prop.name() + "_idx";
+ if (aliases == null)
+ aliases = Collections.emptyMap();
- d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+ for (Map.Entry<String, String> entry : qryEntity.getFields().entrySet()) {
+ PortableProperty prop = buildPortableProperty(entry.getKey(), U.classForName(entry.getValue(), Object.class), aliases);
- d.addFieldToIndex(idxName, prop.name(), 0, false);
+ d.addProperty(prop, false);
}
- for (Map.Entry<String, Class<?>> entry : meta.getDescendingFields().entrySet()) {
- PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue());
-
- d.addProperty(prop, false);
+ processIndexes(qryEntity, d);
+ }
- String idxName = prop.name() + "_idx";
+ /**
+ * Processes declarative metadata for portable object.
+ *
+ * @param qryEntity Declared metadata.
+ * @param d Type descriptor.
+ * @throws IgniteCheckedException If failed.
+ */
+ private void processClassMeta(QueryEntity qryEntity, TypeDescriptor d) throws IgniteCheckedException {
+ Map<String,String> aliases = qryEntity.getAliases();
- d.addIndex(idxName, idx.isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+ if (aliases == null)
+ aliases = Collections.emptyMap();
- d.addFieldToIndex(idxName, prop.name(), 0, true);
- }
+ for (Map.Entry<String, String> entry : qryEntity.getFields().entrySet()) {
+ ClassProperty prop = buildClassProperty(
+ d.keyClass(),
+ d.valueClass(),
+ entry.getKey(),
+ U.classForName(entry.getValue(), Object.class),
+ aliases);
- for (String txtIdx : meta.getTextFields()) {
- PortableProperty prop = buildPortableProperty(txtIdx, String.class);
d.addProperty(prop, false);
-
- d.addFieldToTextIndex(prop.name());
}
- Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> grps = meta.getGroups();
+ processIndexes(qryEntity, d);
+ }
- if (grps != null) {
- for (Map.Entry<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> entry : grps.entrySet()) {
- String idxName = entry.getKey();
+ /**
+ * Processes indexes based on query entity.
+ *
+ * @param qryEntity Query entity to process.
+ * @param d Type descriptor to populate.
+ * @throws IgniteCheckedException If failed to build index information.
+ */
+ private void processIndexes(QueryEntity qryEntity, TypeDescriptor d) throws IgniteCheckedException {
+ if (!F.isEmpty(qryEntity.getIndexes())) {
+ Map<String, String> aliases = qryEntity.getAliases();
- LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>> idxFields = entry.getValue();
+ if (aliases == null)
+ aliases = Collections.emptyMap();
- int order = 0;
+ for (QueryIndex idx : qryEntity.getIndexes()) {
+ String idxName = idx.getName();
- for (Map.Entry<String, IgniteBiTuple<Class<?>, Boolean>> idxField : idxFields.entrySet()) {
- PortableProperty prop = buildPortableProperty(idxField.getKey(), idxField.getValue().get1());
+ if (idxName == null)
+ idxName = QueryEntity.defaultIndexName(idx);
- d.addProperty(prop, false);
+ if (idx.getIndexType() == QueryIndexType.SORTED || idx.getIndexType() == QueryIndexType.GEOSPATIAL) {
+ d.addIndex(idxName, idx.getIndexType() == QueryIndexType.SORTED ? SORTED : GEO_SPATIAL);
- Boolean descending = idxField.getValue().get2();
+ int i = 0;
- d.addFieldToIndex(idxName, prop.name(), order, descending != null && descending);
+ for (Map.Entry<String, Boolean> entry : idx.getFields().entrySet()) {
+ String field = entry.getKey();
+ boolean asc = entry.getValue();
- order++;
+ String alias = aliases.get(field);
+
+ if (alias != null)
+ field = alias;
+
+ d.addFieldToIndex(idxName, field, i++, !asc);
+ }
}
- }
- }
+ else {
+ assert idx.getIndexType() == QueryIndexType.FULLTEXT;
- for (Map.Entry<String, Class<?>> entry : meta.getQueryFields().entrySet()) {
- PortableProperty prop = buildPortableProperty(entry.getKey(), entry.getValue());
+ for (String field : idx.getFields().keySet()) {
+ String alias = aliases.get(field);
- if (!d.props.containsKey(prop.name()))
- d.addProperty(prop, false);
+ if (alias != null)
+ field = alias;
+
+ d.addFieldToTextIndex(field);
+ }
+ }
+ }
}
}
@@ -1350,15 +1457,26 @@ public class GridQueryProcessor extends GridProcessorAdapter {
* @param pathStr String representing path to the property. May contains dots '.' to identify
* nested fields.
* @param resType Result type.
+ * @param aliases Aliases.
* @return Portable property.
*/
- private PortableProperty buildPortableProperty(String pathStr, Class<?> resType) {
+ private PortableProperty buildPortableProperty(String pathStr, Class<?> resType, Map<String,String> aliases) {
String[] path = pathStr.split("\\.");
PortableProperty res = null;
- for (String prop : path)
- res = new PortableProperty(prop, res, resType);
+ StringBuilder fullName = new StringBuilder();
+
+ for (String prop : path) {
+ if (fullName.length() != 0)
+ fullName.append('.');
+
+ fullName.append(prop);
+
+ String alias = aliases.get(fullName.toString());
+
+ res = new PortableProperty(prop, res, resType, alias);
+ }
return res;
}
@@ -1368,19 +1486,21 @@ public class GridQueryProcessor extends GridProcessorAdapter {
* @param valCls Value class.
* @param pathStr Path string.
* @param resType Result type.
+ * @param aliases Aliases.
* @return Class property.
* @throws IgniteCheckedException If failed.
*/
- private static ClassProperty buildClassProperty(Class<?> keyCls, Class<?> valCls, String pathStr, Class<?> resType)
- throws IgniteCheckedException {
+ private static ClassProperty buildClassProperty(Class<?> keyCls, Class<?> valCls, String pathStr, Class<?> resType,
+ Map<String,String> aliases) throws IgniteCheckedException {
ClassProperty res = buildClassProperty(
true,
keyCls,
pathStr,
- resType);
+ resType,
+ aliases);
if (res == null) // We check key before value consistently with PortableProperty.
- res = buildClassProperty(false, valCls, pathStr, resType);
+ res = buildClassProperty(false, valCls, pathStr, resType, aliases);
if (res == null)
throw new IgniteCheckedException("Failed to initialize property '" + pathStr + "' for " +
@@ -1395,16 +1515,25 @@ public class GridQueryProcessor extends GridProcessorAdapter {
* @param cls Source type class.
* @param pathStr String representing path to the property. May contains dots '.' to identify nested fields.
* @param resType Expected result type.
+ * @param aliases Aliases.
* @return Property instance corresponding to the given path.
- * @throws IgniteCheckedException If property cannot be created.
*/
- static ClassProperty buildClassProperty(boolean key, Class<?> cls, String pathStr, Class<?> resType)
- throws IgniteCheckedException {
+ static ClassProperty buildClassProperty(boolean key, Class<?> cls, String pathStr, Class<?> resType,
+ Map<String,String> aliases) {
String[] path = pathStr.split("\\.");
ClassProperty res = null;
+ StringBuilder fullName = new StringBuilder();
+
for (String prop : path) {
+ if (fullName.length() != 0)
+ fullName.append('.');
+
+ fullName.append(prop);
+
+ String alias = aliases.get(fullName.toString());
+
ClassProperty tmp;
try {
@@ -1414,11 +1543,11 @@ public class GridQueryProcessor extends GridProcessorAdapter {
bld.setCharAt(3, Character.toUpperCase(bld.charAt(3)));
- tmp = new ClassProperty(cls.getMethod(bld.toString()), key);
+ tmp = new ClassProperty(cls.getMethod(bld.toString()), key, alias);
}
catch (NoSuchMethodException ignore) {
try {
- tmp = new ClassProperty(cls.getDeclaredField(prop), key);
+ tmp = new ClassProperty(cls.getDeclaredField(prop), key, alias);
}
catch (NoSuchFieldException ignored) {
return null;
@@ -1585,11 +1714,12 @@ public class GridQueryProcessor extends GridProcessorAdapter {
*
* @param member Element.
*/
- ClassProperty(Member member, boolean key) {
+ ClassProperty(Member member, boolean key, String name) {
this.member = member;
this.key = key;
- name = member instanceof Method && member.getName().startsWith("get") && member.getName().length() > 3 ?
+ this.name = !F.isEmpty(name) ? name :
+ member instanceof Method && member.getName().startsWith("get") && member.getName().length() > 3 ?
member.getName().substring(3) : member.getName();
((AccessibleObject) member).setAccessible(true);
@@ -1624,13 +1754,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
}
}
- /**
- * @param name Property name.
- */
- public void name(String name) {
- this.name = name;
- }
-
/** {@inheritDoc} */
@Override public String name() {
return name;
@@ -1669,6 +1792,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
/** Property name. */
private String propName;
+ /** */
+ private String alias;
+
/** Parent property. */
private PortableProperty parent;
@@ -1685,8 +1811,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
* @param parent Parent property.
* @param type Result type.
*/
- private PortableProperty(String propName, PortableProperty parent, Class<?> type) {
+ private PortableProperty(String propName, PortableProperty parent, Class<?> type, String alias) {
this.propName = propName;
+ this.alias = F.isEmpty(alias) ? propName : alias;
this.parent = parent;
this.type = type;
}
@@ -1711,9 +1838,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
if (isKeyProp0 == 0) {
// Key is allowed to be a non-portable object here.
// We check key before value consistently with ClassProperty.
- if (ctx.cacheObjects().isPortableObject(key) && ctx.cacheObjects().hasField(key, propName))
+ if (key instanceof BinaryObject && ((BinaryObject)key).hasField(propName))
isKeyProp = isKeyProp0 = 1;
- else if (ctx.cacheObjects().hasField(val, propName))
+ else if (val instanceof BinaryObject && ((BinaryObject)val).hasField(propName))
isKeyProp = isKeyProp0 = -1;
else {
U.warn(log, "Neither key nor value have property " +
@@ -1731,7 +1858,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
/** {@inheritDoc} */
@Override public String name() {
- return propName;
+ return alias;
}
/** {@inheritDoc} */
@@ -2126,4 +2253,11 @@ public class GridQueryProcessor extends GridProcessorAdapter {
return S.toString(TypeName.class, this);
}
}
+
+ /**
+ * The way to index.
+ */
+ private enum IndexType {
+ ASC, DESC, TEXT
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskRequest.java
index 6b53143..3ac16f2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientTaskRequest.java
@@ -35,7 +35,7 @@ public class GridClientTaskRequest extends GridClientAbstractMessage {
/** Task parameter. */
private Object arg;
- /** Keep portables flag. */
+ /** Keep binary flag. */
private boolean keepPortables;
/**
@@ -67,14 +67,14 @@ public class GridClientTaskRequest extends GridClientAbstractMessage {
}
/**
- * @return Keep portables flag.
+ * @return Keep binary flag.
*/
public boolean keepPortables() {
return keepPortables;
}
/**
- * @param keepPortables Keep portables flag.
+ * @param keepPortables Keep binary flag.
*/
public void keepPortables(boolean keepPortables) {
this.keepPortables = keepPortables;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index 3c1913a..259d8c9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -1336,9 +1336,9 @@ public abstract class IgniteUtils {
*/
@Nullable public static Class<?> classForName(String cls, @Nullable Class<?> dflt) {
try {
- return Class.forName(cls);
+ return cls == null ? dflt : Class.forName(cls);
}
- catch (ClassNotFoundException e) {
+ catch (ClassNotFoundException ignore) {
return dflt;
}
}
@@ -8098,9 +8098,10 @@ public abstract class IgniteUtils {
if (cls == null)
return null;
- Class<?> boxed = boxedClsMap.get(cls);
+ if (!cls.isPrimitive())
+ return cls;
- return boxed != null ? boxed : cls;
+ return boxedClsMap.get(cls);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
index f9cf509..d3e7437 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
@@ -28,11 +28,10 @@ import org.apache.ignite.internal.portable.GridPortableMarshaller;
import org.apache.ignite.internal.portable.PortableContext;
import org.apache.ignite.marshaller.AbstractMarshaller;
import org.apache.ignite.marshaller.MarshallerContext;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableIdMapper;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableSerializer;
-import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryTypeIdMapper;
+import org.apache.ignite.binary.BinarySerializer;
import org.jetbrains.annotations.Nullable;
/**
@@ -75,17 +74,18 @@ import org.jetbrains.annotations.Nullable;
* For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a>
*/
public class PortableMarshaller extends AbstractMarshaller {
+ // TODO ignite-1282 Move to IgniteConfiguration.
/** Class names. */
private Collection<String> clsNames;
/** ID mapper. */
- private PortableIdMapper idMapper;
+ private BinaryTypeIdMapper idMapper;
/** Serializer. */
- private PortableSerializer serializer;
+ private BinarySerializer serializer;
/** Types. */
- private Collection<PortableTypeConfiguration> typeCfgs;
+ private Collection<BinaryTypeConfiguration> typeCfgs;
/** Whether to convert string to bytes using UTF-8 encoding. */
private boolean convertString = true;
@@ -125,7 +125,7 @@ public class PortableMarshaller extends AbstractMarshaller {
*
* @return ID mapper.
*/
- public PortableIdMapper getIdMapper() {
+ public BinaryTypeIdMapper getIdMapper() {
return idMapper;
}
@@ -134,7 +134,7 @@ public class PortableMarshaller extends AbstractMarshaller {
*
* @param idMapper ID mapper.
*/
- public void setIdMapper(PortableIdMapper idMapper) {
+ public void setIdMapper(BinaryTypeIdMapper idMapper) {
this.idMapper = idMapper;
}
@@ -143,7 +143,7 @@ public class PortableMarshaller extends AbstractMarshaller {
*
* @return Serializer.
*/
- public PortableSerializer getSerializer() {
+ public BinarySerializer getSerializer() {
return serializer;
}
@@ -152,7 +152,7 @@ public class PortableMarshaller extends AbstractMarshaller {
*
* @param serializer Serializer.
*/
- public void setSerializer(PortableSerializer serializer) {
+ public void setSerializer(BinarySerializer serializer) {
this.serializer = serializer;
}
@@ -161,7 +161,7 @@ public class PortableMarshaller extends AbstractMarshaller {
*
* @return Types configuration.
*/
- public Collection<PortableTypeConfiguration> getTypeConfigurations() {
+ public Collection<BinaryTypeConfiguration> getTypeConfigurations() {
return typeCfgs;
}
@@ -170,7 +170,7 @@ public class PortableMarshaller extends AbstractMarshaller {
*
* @param typeCfgs Type configurations.
*/
- public void setTypeConfigurations(Collection<PortableTypeConfiguration> typeCfgs) {
+ public void setTypeConfigurations(Collection<BinaryTypeConfiguration> typeCfgs) {
this.typeCfgs = typeCfgs;
}
@@ -198,7 +198,7 @@ public class PortableMarshaller extends AbstractMarshaller {
/**
* If {@code true}, meta data will be collected or all types. If you need to override this behaviour for
- * some specific type, use {@link PortableTypeConfiguration#setMetaDataEnabled(Boolean)} method.
+ * some specific type, use {@link org.apache.ignite.binary.BinaryTypeConfiguration#setMetaDataEnabled(Boolean)} method.
* <p>
* Default value if {@code true}.
*
@@ -216,11 +216,11 @@ public class PortableMarshaller extends AbstractMarshaller {
}
/**
- * If {@code true}, {@link PortableObject} will cache deserialized instance after
- * {@link PortableObject#deserialize()} is called. All consequent calls of this
- * method on the same instance of {@link PortableObject} will return that cached
+ * If {@code true}, {@link org.apache.ignite.binary.BinaryObject} will cache deserialized instance after
+ * {@link org.apache.ignite.binary.BinaryObject#deserialize()} is called. All consequent calls of this
+ * method on the same instance of {@link org.apache.ignite.binary.BinaryObject} will return that cached
* value without actually deserializing portable object. If you need to override this
- * behaviour for some specific type, use {@link PortableTypeConfiguration#setKeepDeserialized(Boolean)}
+ * behaviour for some specific type, use {@link org.apache.ignite.binary.BinaryTypeConfiguration#setKeepDeserialized(Boolean)}
* method.
* <p>
* Default value if {@code true}.
@@ -271,7 +271,7 @@ public class PortableMarshaller extends AbstractMarshaller {
out.write(arr);
}
catch (IOException e) {
- throw new PortableException("Failed to marshal the object: " + obj, e);
+ throw new BinaryObjectException("Failed to marshal the object: " + obj, e);
}
}
@@ -298,7 +298,7 @@ public class PortableMarshaller extends AbstractMarshaller {
return impl.deserialize(buf.toByteArray(), clsLdr);
}
catch (IOException e) {
- throw new PortableException("Failed to unmarshal the object from InputStream", e);
+ throw new BinaryObjectException("Failed to unmarshal the object from InputStream", e);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableBuilder.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableBuilder.java
deleted file mode 100644
index 377fcdc..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableBuilder.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.IgnitePortables;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Portable object builder. Provides ability to build portable objects dynamically without having class definitions.
- * <p>
- * Here is an example of how a portable object can be built dynamically:
- * <pre name=code class=java>
- * PortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject");
- *
- * builder.setField("fieldA", "A");
- * builder.setField("fieldB", "B");
- *
- * PortableObject portableObj = builder.build();
- * </pre>
- *
- * <p>
- * Also builder can be initialized by existing portable object. This allows changing some fields without affecting
- * other fields.
- * <pre name=code class=java>
- * PortableBuilder builder = Ignition.ignite().portables().builder(person);
- *
- * builder.setField("name", "John");
- *
- * person = builder.build();
- * </pre>
- * </p>
- *
- * If you need to modify nested portable object you can get builder for nested object using
- * {@link #getField(String)}, changes made on nested builder will affect parent object,
- * for example:
- *
- * <pre name=code class=java>
- * PortableBuilder personBuilder = grid.portables().createBuilder(personPortableObj);
- * PortableBuilder addressBuilder = personBuilder.setField("address");
- *
- * addressBuilder.setField("city", "New York");
- *
- * personPortableObj = personBuilder.build();
- *
- * // Should be "New York".
- * String city = personPortableObj.getField("address").getField("city");
- * </pre>
- *
- * @see IgnitePortables#builder(int)
- * @see IgnitePortables#builder(String)
- * @see IgnitePortables#builder(PortableObject)
- */
-public interface PortableBuilder {
- /**
- * Returns value assigned to the specified field.
- * If the value is a portable object instance of {@code GridPortableBuilder} will be returned,
- * which can be modified.
- * <p>
- * Collections and maps returned from this method are modifiable.
- *
- * @param name Field name.
- * @return Filed value.
- */
- public <T> T getField(String name);
-
- /**
- * Sets field value.
- *
- * @param name Field name.
- * @param val Field value (cannot be {@code null}).
- * @see PortableObject#metaData()
- */
- public PortableBuilder setField(String name, Object val);
-
- /**
- * Sets field value with value type specification.
- * <p>
- * Field type is needed for proper metadata update.
- *
- * @param name Field name.
- * @param val Field value.
- * @param type Field type.
- * @see PortableObject#metaData()
- */
- public <T> PortableBuilder setField(String name, @Nullable T val, Class<? super T> type);
-
- /**
- * Sets field value.
- * <p>
- * This method should be used if field is portable object.
- *
- * @param name Field name.
- * @param builder Builder for object field.
- */
- public PortableBuilder setField(String name, @Nullable PortableBuilder builder);
-
- /**
- * Removes field from this builder.
- *
- * @param fieldName Field name.
- * @return {@code this} instance for chaining.
- */
- public PortableBuilder removeField(String fieldName);
-
- /**
- * Sets hash code for resulting portable object returned by {@link #build()} method.
- * <p>
- * If not set {@code 0} is used.
- *
- * @param hashCode Hash code.
- * @return {@code this} instance for chaining.
- */
- public PortableBuilder hashCode(int hashCode);
-
- /**
- * Builds portable object.
- *
- * @return Portable object.
- * @throws PortableException In case of error.
- */
- public PortableObject build() throws PortableException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableException.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableException.java
deleted file mode 100644
index 0f8d78b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableException.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.IgniteException;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Exception indicating portable object serialization error.
- */
-public class PortableException extends IgniteException {
- /** */
- private static final long serialVersionUID = 0L;
-
- /**
- * Creates portable exception with error message.
- *
- * @param msg Error message.
- */
- public PortableException(String msg) {
- super(msg);
- }
-
- /**
- * Creates portable exception with {@link Throwable} as a cause.
- *
- * @param cause Cause.
- */
- public PortableException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Creates portable exception with error message and {@link Throwable} as a cause.
- *
- * @param msg Error message.
- * @param cause Cause.
- */
- public PortableException(String msg, @Nullable Throwable cause) {
- super(msg, cause);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableField.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableField.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableField.java
deleted file mode 100644
index 81a7424..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableField.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.portable;
-
-/**
- * Portable object field. Can be used to speed object field lookup.
- */
-public interface PortableField {
- /**
- * Get field's name.
- *
- * @return Name.
- */
- public String name();
-
- /**
- * Check whether field exists in the object.
- *
- * @param obj Object.
- * @return {@code True} if exists.
- */
- public boolean exists(PortableObject obj);
-
- /**
- * Get field's value from the given object.
- *
- * @param obj Object.
- * @return Value.
- */
- public <T> T value(PortableObject obj);
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableIdMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableIdMapper.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableIdMapper.java
deleted file mode 100644
index 368e415..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableIdMapper.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-
-/**
- * Type and field ID mapper for portable objects. Ignite never writes full
- * strings for field or type names. Instead, for performance reasons, Ignite
- * writes integer hash codes for type and field names. It has been tested that
- * hash code conflicts for the type names or the field names
- * within the same type are virtually non-existent and, to gain performance, it is safe
- * to work with hash codes. For the cases when hash codes for different types or fields
- * actually do collide {@code PortableIdMapper} allows to override the automatically
- * generated hash code IDs for the type and field names.
- * <p>
- * Portable ID mapper can be configured for all portable objects via {@link PortableMarshaller#getIdMapper()} method,
- * or for a specific portable type via {@link PortableTypeConfiguration#getIdMapper()} method.
- */
-public interface PortableIdMapper {
- /**
- * Gets type ID for provided class name.
- * <p>
- * If {@code 0} is returned, hash code of class simple name will be used.
- *
- * @param clsName Class name.
- * @return Type ID.
- */
- public int typeId(String clsName);
-
- /**
- * Gets ID for provided field.
- * <p>
- * If {@code 0} is returned, hash code of field name will be used.
- *
- * @param typeId Type ID.
- * @param fieldName Field name.
- * @return Field ID.
- */
- public int fieldId(int typeId, String fieldName);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableInvalidClassException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableInvalidClassException.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableInvalidClassException.java
deleted file mode 100644
index 0098ec3..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableInvalidClassException.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.portable;
-
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Exception indicating that class needed for deserialization of portable object does not exist.
- * <p>
- * Thrown from {@link PortableObject#deserialize()} method.
- */
-public class PortableInvalidClassException extends PortableException {
- /** */
- private static final long serialVersionUID = 0L;
-
- /**
- * Creates invalid class exception with error message.
- *
- * @param msg Error message.
- */
- public PortableInvalidClassException(String msg) {
- super(msg);
- }
-
- /**
- * Creates invalid class exception with {@link Throwable} as a cause.
- *
- * @param cause Cause.
- */
- public PortableInvalidClassException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Creates invalid class exception with error message and {@link Throwable} as a cause.
- *
- * @param msg Error message.
- * @param cause Cause.
- */
- public PortableInvalidClassException(String msg, @Nullable Throwable cause) {
- super(msg, cause);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableMarshalAware.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableMarshalAware.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableMarshalAware.java
deleted file mode 100644
index 4270885..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableMarshalAware.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.portable;
-
-/**
- * Interface that allows to implement custom serialization
- * logic for portable objects. Portable objects are not required
- * to implement this interface, in which case Ignite will automatically
- * serialize portable objects using reflection.
- * <p>
- * This interface, in a way, is analogous to {@link java.io.Externalizable}
- * interface, which allows users to override default serialization logic,
- * usually for performance reasons. The only difference here is that portable
- * serialization is already very fast and implementing custom serialization
- * logic for portables does not provide significant performance gains.
- */
-public interface PortableMarshalAware {
- /**
- * Writes fields to provided writer.
- *
- * @param writer Portable object writer.
- * @throws PortableException In case of error.
- */
- public void writePortable(PortableWriter writer) throws PortableException;
-
- /**
- * Reads fields from provided reader.
- *
- * @param reader Portable object reader.
- * @throws PortableException In case of error.
- */
- public void readPortable(PortableReader reader) throws PortableException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableMetadata.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableMetadata.java
deleted file mode 100644
index 4ea808b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableMetadata.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.portable;
-
-import java.util.Collection;
-import org.apache.ignite.IgnitePortables;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Portable type meta data. Metadata for portable types can be accessed from any of the
- * {@link IgnitePortables#metadata(String)} methods.
- * Having metadata also allows for proper formatting of {@code PortableObject#toString()} method,
- * even when portable objects are kept in binary format only, which may be necessary for audit reasons.
- */
-public interface PortableMetadata {
- /**
- * Gets portable type name.
- *
- * @return Portable type name.
- */
- public String typeName();
-
- /**
- * Gets collection of all field names for this portable type.
- *
- * @return Collection of all field names for this portable type.
- */
- public Collection<String> fields();
-
- /**
- * Gets name of the field type for a given field.
- *
- * @param fieldName Field name.
- * @return Field type name.
- */
- @Nullable public String fieldTypeName(String fieldName);
-
- /**
- * Portable objects can optionally specify custom key-affinity mapping in the
- * configuration. This method returns the name of the field which should be
- * used for the key-affinity mapping.
- *
- * @return Affinity key field name.
- */
- @Nullable public String affinityKeyFieldName();
-}
\ No newline at end of file
[05/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
index 917ba03..ea96842 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
@@ -17,34 +17,6 @@
package org.apache.ignite.internal.portable;
-import junit.framework.Assert;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.builder.PortableBuilderImpl;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableIdMapper;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableRawReader;
-import org.apache.ignite.portable.PortableRawWriter;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableSerializer;
-import org.apache.ignite.portable.PortableTypeConfiguration;
-import org.apache.ignite.portable.PortableWriter;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.jsr166.ConcurrentHashMap8;
-import sun.misc.Unsafe;
-
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -67,6 +39,34 @@ import java.util.TreeSet;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
+import junit.framework.Assert;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawReader;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinarySerializer;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.binary.BinaryTypeIdMapper;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.portable.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jsr166.ConcurrentHashMap8;
+import sun.misc.Unsafe;
import static org.apache.ignite.internal.portable.PortableThreadLocalMemoryAllocator.THREAD_LOCAL_ALLOC;
import static org.junit.Assert.assertArrayEquals;
@@ -84,11 +84,11 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
/** */
protected static final PortableMetaDataHandler META_HND = new PortableMetaDataHandler() {
- @Override public void addMeta(int typeId, PortableMetadata meta) {
+ @Override public void addMeta(int typeId, BinaryType meta) {
// No-op.
}
- @Override public PortableMetadata metadata(int typeId) {
+ @Override public BinaryType metadata(int typeId) {
return null;
}
};
@@ -394,16 +394,16 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
/**
* @throws Exception If failed.
*/
- public void testPortableObject() throws Exception {
+ public void testBinaryObject() throws Exception {
PortableMarshaller marsh = new PortableMarshaller();
- marsh.setTypeConfigurations(Arrays.asList(new PortableTypeConfiguration(SimpleObject.class.getName())));
+ marsh.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
- PortableObject po0 = marshalUnmarshal(po, marsh);
+ BinaryObject po0 = marshalUnmarshal(po, marsh);
assertTrue(po.hasField("b"));
assertTrue(po.hasField("s"));
@@ -435,7 +435,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
* @throws Exception If failed.
*/
public void testDateAndTimestampInSingleObject() throws Exception {
- PortableTypeConfiguration cfg1 = new PortableTypeConfiguration(DateClass1.class.getName());
+ BinaryTypeConfiguration cfg1 = new BinaryTypeConfiguration(DateClass1.class.getName());
PortableMarshaller marsh = new PortableMarshaller();
@@ -448,7 +448,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
obj1.date = date;
obj1.ts = ts;
- PortableObject po1 = marshal(obj1, marsh);
+ BinaryObject po1 = marshal(obj1, marsh);
assertEquals(date, po1.field("date"));
assertEquals(Date.class, po1.field("date").getClass());
@@ -467,12 +467,12 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
assertEquals(obj.hashCode(), po.hashCode());
@@ -509,7 +509,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
assertArrayEquals(ordinals(obj.enumArr), ordinals((Enum<?>[])po.field("enumArr")));
assertNull(po.field("unknown"));
- PortableObject innerPo = po.field("inner");
+ BinaryObject innerPo = po.field("inner");
assertEquals(obj.inner, innerPo.deserialize());
@@ -554,13 +554,13 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName()),
- new PortableTypeConfiguration(TestPortableObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName()),
+ new BinaryTypeConfiguration(TestBinary.class.getName())
));
- TestPortableObject obj = portableObject();
+ TestBinary obj = BinaryObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
assertEquals(obj.hashCode(), po.hashCode());
@@ -596,7 +596,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
assertArrayEquals(ordinals(obj.enumArr), ordinals((Enum<?>[])po.field("_enumArr")));
assertNull(po.field("unknown"));
- PortableObject simplePo = po.field("_simple");
+ BinaryObject simplePo = po.field("_simple");
assertEquals(obj.simple, simplePo.deserialize());
@@ -634,7 +634,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
assertNull(simplePo.field("portable"));
assertNull(simplePo.field("unknown"));
- PortableObject portablePo = po.field("_portable");
+ BinaryObject portablePo = po.field("_portable");
assertEquals(obj.portable, portablePo.deserialize());
@@ -676,7 +676,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
* @param obj Simple object.
* @param po Portable object.
*/
- private void checkSimpleObjectData(SimpleObject obj, PortableObject po) {
+ private void checkSimpleObjectData(SimpleObject obj, BinaryObject po) {
assertEquals(obj.b, (byte)po.field("b"));
assertEquals(obj.s, (short)po.field("s"));
assertEquals(obj.i, (int)po.field("i"));
@@ -718,25 +718,25 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(NoPublicConstructor.class.getName()),
- new PortableTypeConfiguration(NoPublicDefaultConstructor.class.getName()),
- new PortableTypeConfiguration(ProtectedConstructor.class.getName()))
+ new BinaryTypeConfiguration(NoPublicConstructor.class.getName()),
+ new BinaryTypeConfiguration(NoPublicDefaultConstructor.class.getName()),
+ new BinaryTypeConfiguration(ProtectedConstructor.class.getName()))
);
initPortableContext(marsh);
NoPublicConstructor npc = new NoPublicConstructor();
- PortableObject npc2 = marshal(npc, marsh);
+ BinaryObject npc2 = marshal(npc, marsh);
assertEquals("test", npc2.<NoPublicConstructor>deserialize().val);
NoPublicDefaultConstructor npdc = new NoPublicDefaultConstructor(239);
- PortableObject npdc2 = marshal(npdc, marsh);
+ BinaryObject npdc2 = marshal(npdc, marsh);
assertEquals(239, npdc2.<NoPublicDefaultConstructor>deserialize().val);
ProtectedConstructor pc = new ProtectedConstructor();
- PortableObject pc2 = marshal(pc, marsh);
+ BinaryObject pc2 = marshal(pc, marsh);
assertEquals(ProtectedConstructor.class, pc2.<ProtectedConstructor>deserialize().getClass());
}
@@ -747,8 +747,8 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
public void testCustomSerializer() throws Exception {
PortableMarshaller marsh = new PortableMarshaller();
- PortableTypeConfiguration type =
- new PortableTypeConfiguration(CustomSerializedObject1.class.getName());
+ BinaryTypeConfiguration type =
+ new BinaryTypeConfiguration(CustomSerializedObject1.class.getName());
type.setSerializer(new CustomSerializer1());
@@ -756,7 +756,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
CustomSerializedObject1 obj1 = new CustomSerializedObject1(10);
- PortableObject po1 = marshal(obj1, marsh);
+ BinaryObject po1 = marshal(obj1, marsh);
assertEquals(20, po1.<CustomSerializedObject1>deserialize().val);
}
@@ -769,10 +769,10 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
marsh.setSerializer(new CustomSerializer1());
- PortableTypeConfiguration type1 =
- new PortableTypeConfiguration(CustomSerializedObject1.class.getName());
- PortableTypeConfiguration type2 =
- new PortableTypeConfiguration(CustomSerializedObject2.class.getName());
+ BinaryTypeConfiguration type1 =
+ new BinaryTypeConfiguration(CustomSerializedObject1.class.getName());
+ BinaryTypeConfiguration type2 =
+ new BinaryTypeConfiguration(CustomSerializedObject2.class.getName());
type2.setSerializer(new CustomSerializer2());
@@ -780,13 +780,13 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
CustomSerializedObject1 obj1 = new CustomSerializedObject1(10);
- PortableObject po1 = marshal(obj1, marsh);
+ BinaryObject po1 = marshal(obj1, marsh);
assertEquals(20, po1.<CustomSerializedObject1>deserialize().val);
CustomSerializedObject2 obj2 = new CustomSerializedObject2(10);
- PortableObject po2 = marshal(obj2, marsh);
+ BinaryObject po2 = marshal(obj2, marsh);
assertEquals(30, po2.<CustomSerializedObject2>deserialize().val);
}
@@ -797,10 +797,10 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
public void testCustomIdMapper() throws Exception {
PortableMarshaller marsh = new PortableMarshaller();
- PortableTypeConfiguration type =
- new PortableTypeConfiguration(CustomMappedObject1.class.getName());
+ BinaryTypeConfiguration type =
+ new BinaryTypeConfiguration(CustomMappedObject1.class.getName());
- type.setIdMapper(new PortableIdMapper() {
+ type.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 11111;
}
@@ -823,7 +823,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
CustomMappedObject1 obj1 = new CustomMappedObject1(10, "str");
- PortableObjectEx po1 = marshal(obj1, marsh);
+ BinaryObjectEx po1 = marshal(obj1, marsh);
assertEquals(11111, po1.typeId());
assertEquals(10, po1.field(22222));
@@ -839,7 +839,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
public void testCustomIdMapperWithGlobal() throws Exception {
PortableMarshaller marsh = new PortableMarshaller();
- marsh.setIdMapper(new PortableIdMapper() {
+ marsh.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 11111;
}
@@ -856,12 +856,12 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
});
- PortableTypeConfiguration type1 =
- new PortableTypeConfiguration(CustomMappedObject1.class.getName());
- PortableTypeConfiguration type2 =
- new PortableTypeConfiguration(CustomMappedObject2.class.getName());
+ BinaryTypeConfiguration type1 =
+ new BinaryTypeConfiguration(CustomMappedObject1.class.getName());
+ BinaryTypeConfiguration type2 =
+ new BinaryTypeConfiguration(CustomMappedObject2.class.getName());
- type2.setIdMapper(new PortableIdMapper() {
+ type2.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 44444;
}
@@ -882,7 +882,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
CustomMappedObject1 obj1 = new CustomMappedObject1(10, "str1");
- PortableObjectEx po1 = marshal(obj1, marsh);
+ BinaryObjectEx po1 = marshal(obj1, marsh);
assertEquals(11111, po1.typeId());
assertEquals(10, po1.field(22222));
@@ -893,7 +893,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
CustomMappedObject2 obj2 = new CustomMappedObject2(20, "str2");
- PortableObjectEx po2 = marshal(obj2, marsh);
+ BinaryObjectEx po2 = marshal(obj2, marsh);
assertEquals(44444, po2.typeId());
assertEquals(20, po2.field(55555));
@@ -910,10 +910,10 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(DynamicObject.class.getName())
+ new BinaryTypeConfiguration(DynamicObject.class.getName())
));
- PortableObject po1 = marshal(new DynamicObject(0, 10, 20, 30), marsh);
+ BinaryObject po1 = marshal(new DynamicObject(0, 10, 20, 30), marsh);
assertEquals(new Integer(10), po1.field("val1"));
assertEquals(null, po1.field("val2"));
@@ -925,7 +925,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
assertEquals(0, do1.val2);
assertEquals(0, do1.val3);
- PortableObject po2 = marshal(new DynamicObject(1, 10, 20, 30), marsh);
+ BinaryObject po2 = marshal(new DynamicObject(1, 10, 20, 30), marsh);
assertEquals(new Integer(10), po2.field("val1"));
assertEquals(new Integer(20), po2.field("val2"));
@@ -937,7 +937,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
assertEquals(20, do2.val2);
assertEquals(0, do2.val3);
- PortableObject po3 = marshal(new DynamicObject(2, 10, 20, 30), marsh);
+ BinaryObject po3 = marshal(new DynamicObject(2, 10, 20, 30), marsh);
assertEquals(new Integer(10), po3.field("val1"));
assertEquals(new Integer(20), po3.field("val2"));
@@ -957,14 +957,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(CycleLinkObject.class.getName())
+ new BinaryTypeConfiguration(CycleLinkObject.class.getName())
));
CycleLinkObject obj = new CycleLinkObject();
obj.self = obj;
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
CycleLinkObject obj0 = po.deserialize();
@@ -978,8 +978,8 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(DetachedTestObject.class.getName()),
- new PortableTypeConfiguration(DetachedInnerTestObject.class.getName())
+ new BinaryTypeConfiguration(DetachedTestObject.class.getName()),
+ new BinaryTypeConfiguration(DetachedInnerTestObject.class.getName())
));
UUID id = UUID.randomUUID();
@@ -992,7 +992,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
assert obj.inner1 == obj.inner4;
- PortableObjectImpl innerPo = (PortableObjectImpl)obj.inner2;
+ BinaryObjectImpl innerPo = (BinaryObjectImpl)obj.inner2;
assert innerPo.detached();
@@ -1000,7 +1000,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
assertEquals(id, inner.id);
- PortableObjectImpl detachedPo = (PortableObjectImpl)innerPo.detach();
+ BinaryObjectImpl detachedPo = (BinaryObjectImpl)innerPo.detach();
assert detachedPo.detached();
@@ -1008,7 +1008,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
assertEquals(id, inner.id);
- innerPo = (PortableObjectImpl)obj.inner3;
+ innerPo = (BinaryObjectImpl)obj.inner3;
assert innerPo.detached();
@@ -1017,7 +1017,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
assertEquals(id, inner.id);
assertNotNull(inner.inner);
- detachedPo = (PortableObjectImpl)innerPo.detach();
+ detachedPo = (BinaryObjectImpl)innerPo.detach();
assert detachedPo.detached();
@@ -1034,9 +1034,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(CollectionFieldsObject.class.getName()),
- new PortableTypeConfiguration(Key.class.getName()),
- new PortableTypeConfiguration(Value.class.getName())
+ new BinaryTypeConfiguration(CollectionFieldsObject.class.getName()),
+ new BinaryTypeConfiguration(Key.class.getName()),
+ new BinaryTypeConfiguration(Value.class.getName())
));
Object[] arr = new Object[] {new Value(1), new Value(2), new Value(3)};
@@ -1045,7 +1045,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
CollectionFieldsObject obj = new CollectionFieldsObject(arr, col, map);
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
Object[] arr0 = po.field("arr");
@@ -1054,18 +1054,18 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
int i = 1;
for (Object valPo : arr0)
- assertEquals(i++, ((PortableObject)valPo).<Value>deserialize().val);
+ assertEquals(i++, ((BinaryObject)valPo).<Value>deserialize().val);
- Collection<PortableObject> col0 = po.field("col");
+ Collection<BinaryObject> col0 = po.field("col");
i = 4;
- for (PortableObject valPo : col0)
+ for (BinaryObject valPo : col0)
assertEquals(i++, valPo.<Value>deserialize().val);
- Map<PortableObject, PortableObject> map0 = po.field("map");
+ Map<BinaryObject, BinaryObject> map0 = po.field("map");
- for (Map.Entry<PortableObject, PortableObject> e : map0.entrySet())
+ for (Map.Entry<BinaryObject, BinaryObject> e : map0.entrySet())
assertEquals(e.getKey().<Key>deserialize().key, e.getValue().<Value>deserialize().val);
}
@@ -1075,10 +1075,10 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
public void testDefaultMapping() throws Exception {
PortableMarshaller marsh1 = new PortableMarshaller();
- PortableTypeConfiguration customMappingType =
- new PortableTypeConfiguration(TestPortableObject.class.getName());
+ BinaryTypeConfiguration customMappingType =
+ new BinaryTypeConfiguration(TestBinary.class.getName());
- customMappingType.setIdMapper(new PortableIdMapper() {
+ customMappingType.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
String typeName;
@@ -1102,19 +1102,19 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
});
marsh1.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName()),
+ new BinaryTypeConfiguration(SimpleObject.class.getName()),
customMappingType
));
- TestPortableObject obj = portableObject();
+ TestBinary obj = BinaryObject();
- PortableObjectImpl po = marshal(obj, marsh1);
+ BinaryObjectImpl po = marshal(obj, marsh1);
PortableMarshaller marsh2 = new PortableMarshaller();
marsh2.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName()),
- new PortableTypeConfiguration(TestPortableObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName()),
+ new BinaryTypeConfiguration(TestBinary.class.getName())
));
PortableContext ctx = initPortableContext(marsh2);
@@ -1130,9 +1130,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
public void testTypeNames() throws Exception {
PortableMarshaller marsh = new PortableMarshaller();
- PortableTypeConfiguration customType1 = new PortableTypeConfiguration(Value.class.getName());
+ BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration(Value.class.getName());
- customType1.setIdMapper(new PortableIdMapper() {
+ customType1.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 300;
}
@@ -1142,9 +1142,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
});
- PortableTypeConfiguration customType2 = new PortableTypeConfiguration("org.gridgain.NonExistentClass1");
+ BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("org.gridgain.NonExistentClass1");
- customType2.setIdMapper(new PortableIdMapper() {
+ customType2.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 400;
}
@@ -1154,9 +1154,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
});
- PortableTypeConfiguration customType3 = new PortableTypeConfiguration("NonExistentClass2");
+ BinaryTypeConfiguration customType3 = new BinaryTypeConfiguration("NonExistentClass2");
- customType3.setIdMapper(new PortableIdMapper() {
+ customType3.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 500;
}
@@ -1166,9 +1166,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
});
- PortableTypeConfiguration customType4 = new PortableTypeConfiguration("NonExistentClass5");
+ BinaryTypeConfiguration customType4 = new BinaryTypeConfiguration("NonExistentClass5");
- customType4.setIdMapper(new PortableIdMapper() {
+ customType4.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 0;
}
@@ -1179,9 +1179,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
});
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(Key.class.getName()),
- new PortableTypeConfiguration("org.gridgain.NonExistentClass3"),
- new PortableTypeConfiguration("NonExistentClass4"),
+ new BinaryTypeConfiguration(Key.class.getName()),
+ new BinaryTypeConfiguration("org.gridgain.NonExistentClass3"),
+ new BinaryTypeConfiguration("NonExistentClass4"),
customType1,
customType2,
customType3,
@@ -1206,9 +1206,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
public void testFieldIdMapping() throws Exception {
PortableMarshaller marsh = new PortableMarshaller();
- PortableTypeConfiguration customType1 = new PortableTypeConfiguration(Value.class.getName());
+ BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration(Value.class.getName());
- customType1.setIdMapper(new PortableIdMapper() {
+ customType1.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 300;
}
@@ -1227,9 +1227,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
});
- PortableTypeConfiguration customType2 = new PortableTypeConfiguration("NonExistentClass1");
+ BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("NonExistentClass1");
- customType2.setIdMapper(new PortableIdMapper() {
+ customType2.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 400;
}
@@ -1248,8 +1248,8 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
});
- marsh.setTypeConfigurations(Arrays.asList(new PortableTypeConfiguration(Key.class.getName()),
- new PortableTypeConfiguration("NonExistentClass2"),
+ marsh.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(Key.class.getName()),
+ new BinaryTypeConfiguration("NonExistentClass2"),
customType1,
customType2));
@@ -1272,9 +1272,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
public void testDuplicateTypeId() throws Exception {
final PortableMarshaller marsh = new PortableMarshaller();
- PortableTypeConfiguration customType1 = new PortableTypeConfiguration("org.gridgain.Class1");
+ BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration("org.gridgain.Class1");
- customType1.setIdMapper(new PortableIdMapper() {
+ customType1.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 100;
}
@@ -1284,9 +1284,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
});
- PortableTypeConfiguration customType2 = new PortableTypeConfiguration("org.gridgain.Class2");
+ BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("org.gridgain.Class2");
- customType2.setIdMapper(new PortableIdMapper() {
+ customType2.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 100;
}
@@ -1318,14 +1318,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- final PortableObject po = marshal(obj, marsh);
+ final BinaryObject po = marshal(obj, marsh);
- PortableObject copy = copy(po, null);
+ BinaryObject copy = copy(po, null);
assertEquals(obj, copy.deserialize());
@@ -1441,14 +1441,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
- PortableObject copy = copy(po, F.<String, Object>asMap("str", "str3"));
+ BinaryObject copy = copy(po, F.<String, Object>asMap("str", "str3"));
assertEquals("str3", copy.<String>field("str"));
@@ -1464,16 +1464,16 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
UUID uuid = UUID.randomUUID();
- PortableObject copy = copy(po, F.<String, Object>asMap("uuid", uuid));
+ BinaryObject copy = copy(po, F.<String, Object>asMap("uuid", uuid));
assertEquals(uuid, copy.<UUID>field("uuid"));
@@ -1489,14 +1489,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
- PortableObject copy = copy(po, F.<String, Object>asMap("bArr", new byte[]{1, 2, 3}));
+ BinaryObject copy = copy(po, F.<String, Object>asMap("bArr", new byte[]{1, 2, 3}));
assertArrayEquals(new byte[] {1, 2, 3}, copy.<byte[]>field("bArr"));
@@ -1510,8 +1510,8 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
* @param fields Fields.
* @return Copy.
*/
- private PortableObject copy(PortableObject po, Map<String, Object> fields) {
- PortableBuilder builder = PortableBuilderImpl.wrap(po);
+ private BinaryObject copy(BinaryObject po, Map<String, Object> fields) {
+ BinaryObjectBuilder builder = BinaryObjectBuilderImpl.wrap(po);
if (fields != null) {
for (Map.Entry<String, Object> e : fields.entrySet())
@@ -1528,14 +1528,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
- PortableObject copy = copy(po, F.<String, Object>asMap("sArr", new short[]{1, 2, 3}));
+ BinaryObject copy = copy(po, F.<String, Object>asMap("sArr", new short[]{1, 2, 3}));
assertArrayEquals(new short[] {1, 2, 3}, copy.<short[]>field("sArr"));
@@ -1551,14 +1551,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
- PortableObject copy = copy(po, F.<String, Object>asMap("iArr", new int[]{1, 2, 3}));
+ BinaryObject copy = copy(po, F.<String, Object>asMap("iArr", new int[]{1, 2, 3}));
assertArrayEquals(new int[] {1, 2, 3}, copy.<int[]>field("iArr"));
@@ -1574,14 +1574,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
- PortableObject copy = copy(po, F.<String, Object>asMap("lArr", new long[]{1, 2, 3}));
+ BinaryObject copy = copy(po, F.<String, Object>asMap("lArr", new long[]{1, 2, 3}));
assertArrayEquals(new long[] {1, 2, 3}, copy.<long[]>field("lArr"));
@@ -1597,14 +1597,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
- PortableObject copy = copy(po, F.<String, Object>asMap("fArr", new float[]{1, 2, 3}));
+ BinaryObject copy = copy(po, F.<String, Object>asMap("fArr", new float[]{1, 2, 3}));
assertArrayEquals(new float[] {1, 2, 3}, copy.<float[]>field("fArr"), 0);
@@ -1620,14 +1620,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
- PortableObject copy = copy(po, F.<String, Object>asMap("dArr", new double[]{1, 2, 3}));
+ BinaryObject copy = copy(po, F.<String, Object>asMap("dArr", new double[]{1, 2, 3}));
assertArrayEquals(new double[] {1, 2, 3}, copy.<double[]>field("dArr"), 0);
@@ -1643,14 +1643,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
- PortableObject copy = copy(po, F.<String, Object>asMap("cArr", new char[]{1, 2, 3}));
+ BinaryObject copy = copy(po, F.<String, Object>asMap("cArr", new char[]{1, 2, 3}));
assertArrayEquals(new char[]{1, 2, 3}, copy.<char[]>field("cArr"));
@@ -1666,14 +1666,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
- PortableObject copy = copy(po, F.<String, Object>asMap("strArr", new String[]{"str1", "str2"}));
+ BinaryObject copy = copy(po, F.<String, Object>asMap("strArr", new String[]{"str1", "str2"}));
assertArrayEquals(new String[]{"str1", "str2"}, copy.<String[]>field("strArr"));
@@ -1689,12 +1689,12 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
SimpleObject newObj = new SimpleObject();
@@ -1702,9 +1702,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
newObj.fArr = new float[] {5, 8, 0};
newObj.str = "newStr";
- PortableObject copy = copy(po, F.<String, Object>asMap("inner", newObj));
+ BinaryObject copy = copy(po, F.<String, Object>asMap("inner", newObj));
- assertEquals(newObj, copy.<PortableObject>field("inner").deserialize());
+ assertEquals(newObj, copy.<BinaryObject>field("inner").deserialize());
SimpleObject obj0 = copy.deserialize();
@@ -1718,12 +1718,12 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())
+ new BinaryTypeConfiguration(SimpleObject.class.getName())
));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
Map<String, Object> map = new HashMap<>(3, 1.0f);
@@ -1737,10 +1737,10 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
map.put("inner", newObj);
map.put("bArr", new byte[]{6, 7, 9});
- PortableObject copy = copy(po, map);
+ BinaryObject copy = copy(po, map);
assertEquals("str555", copy.<String>field("str"));
- assertEquals(newObj, copy.<PortableObject>field("inner").deserialize());
+ assertEquals(newObj, copy.<BinaryObject>field("inner").deserialize());
assertArrayEquals(new byte[]{6, 7, 9}, copy.<byte[]>field("bArr"));
SimpleObject obj0 = copy.deserialize();
@@ -1756,11 +1756,11 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
public void testPortableCopyMixed() throws Exception {
PortableMarshaller marsh = new PortableMarshaller();
- marsh.setTypeConfigurations(Arrays.asList(new PortableTypeConfiguration(SimpleObject.class.getName())));
+ marsh.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
SimpleObject obj = simpleObject();
- PortableObject po = marshal(obj, marsh);
+ BinaryObject po = marshal(obj, marsh);
Map<String, Object> map = new HashMap<>(3, 1.0f);
@@ -1777,11 +1777,11 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
map.put("bArr", new byte[]{6, 7, 9});
map.put("b", (byte)111);
- PortableObject copy = copy(po, map);
+ BinaryObject copy = copy(po, map);
assertEquals(1234, copy.<Integer>field("i").intValue());
assertEquals("str555", copy.<String>field("str"));
- assertEquals(newObj, copy.<PortableObject>field("inner").deserialize());
+ assertEquals(newObj, copy.<BinaryObject>field("inner").deserialize());
assertEquals((short)2323, copy.<Short>field("s").shortValue());
assertArrayEquals(new byte[] {6, 7, 9}, copy.<byte[]>field("bArr"));
assertEquals((byte)111, copy.<Byte>field("b").byteValue());
@@ -1805,7 +1805,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
marsh.setClassNames(Arrays.asList(SimpleObject.class.getName()));
marsh.setKeepDeserialized(true);
- PortableObject po = marshal(simpleObject(), marsh);
+ BinaryObject po = marshal(simpleObject(), marsh);
assert po.deserialize() == po.deserialize();
@@ -1822,7 +1822,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
marsh.setKeepDeserialized(true);
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())));
+ new BinaryTypeConfiguration(SimpleObject.class.getName())));
po = marshal(simpleObject(), marsh);
@@ -1832,7 +1832,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
marsh.setKeepDeserialized(false);
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(SimpleObject.class.getName())));
+ new BinaryTypeConfiguration(SimpleObject.class.getName())));
po = marshal(simpleObject(), marsh);
@@ -1842,7 +1842,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
marsh.setKeepDeserialized(true);
- PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(SimpleObject.class.getName());
+ BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(SimpleObject.class.getName());
typeCfg.setKeepDeserialized(false);
@@ -1856,7 +1856,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
marsh.setKeepDeserialized(false);
- typeCfg = new PortableTypeConfiguration(SimpleObject.class.getName());
+ typeCfg = new BinaryTypeConfiguration(SimpleObject.class.getName());
typeCfg.setKeepDeserialized(true);
@@ -1873,13 +1873,13 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
public void testOffheapPortable() throws Exception {
PortableMarshaller marsh = new PortableMarshaller();
- marsh.setTypeConfigurations(Arrays.asList(new PortableTypeConfiguration(SimpleObject.class.getName())));
+ marsh.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
PortableContext ctx = initPortableContext(marsh);
SimpleObject simpleObj = simpleObject();
- PortableObjectImpl obj = marshal(simpleObj, marsh);
+ BinaryObjectImpl obj = marshal(simpleObj, marsh);
long ptr = 0;
@@ -1890,7 +1890,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
try {
ptr = copyOffheap(obj);
- PortableObjectOffheapImpl offheapObj = new PortableObjectOffheapImpl(ctx,
+ BinaryObjectOffheapImpl offheapObj = new BinaryObjectOffheapImpl(ctx,
ptr,
0,
obj.array().length);
@@ -1903,7 +1903,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
ptr1 = copyOffheap(obj);
- PortableObjectOffheapImpl offheapObj1 = new PortableObjectOffheapImpl(ctx,
+ BinaryObjectOffheapImpl offheapObj1 = new BinaryObjectOffheapImpl(ctx,
ptr1,
0,
obj.array().length);
@@ -1916,20 +1916,20 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
checkSimpleObjectData(simpleObj, offheapObj);
- PortableObjectOffheapImpl innerOffheapObj = offheapObj.field("inner");
+ BinaryObjectOffheapImpl innerOffheapObj = offheapObj.field("inner");
assertNotNull(innerOffheapObj);
checkSimpleObjectData(simpleObj.inner, innerOffheapObj);
- obj = (PortableObjectImpl)offheapObj.heapCopy();
+ obj = (BinaryObjectImpl)offheapObj.heapCopy();
assertEquals(obj.typeId(), offheapObj.typeId());
assertEquals(obj.hashCode(), offheapObj.hashCode());
checkSimpleObjectData(simpleObj, obj);
- PortableObjectImpl innerObj = obj.field("inner");
+ BinaryObjectImpl innerObj = obj.field("inner");
assertNotNull(innerObj);
@@ -1944,7 +1944,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
ptr2 = copyOffheap(obj);
- PortableObjectOffheapImpl offheapObj2 = new PortableObjectOffheapImpl(ctx,
+ BinaryObjectOffheapImpl offheapObj2 = new BinaryObjectOffheapImpl(ctx,
ptr2,
0,
obj.array().length);
@@ -1972,7 +1972,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
marsh.setClassNames(
Arrays.asList(MySingleton.class.getName(), SingletonMarker.class.getName()));
- PortableObjectImpl portableObj = marshal(MySingleton.INSTANCE, marsh);
+ BinaryObjectImpl portableObj = marshal(MySingleton.INSTANCE, marsh);
assertTrue(portableObj.array().length <= 1024); // Check that big string was not serialized.
@@ -1989,7 +1989,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
marsh.setClassNames(Collections.singletonList(MyTestClass.class.getName()));
- PortableObjectImpl portableObj = marshal(new MyTestClass(), marsh);
+ BinaryObjectImpl portableObj = marshal(new MyTestClass(), marsh);
MyTestClass obj = portableObj.deserialize();
@@ -2004,7 +2004,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
marsh.setClassNames(Arrays.asList(ChildPortable.class.getName()));
- PortableObjectImpl portableObj = marshal(new ChildPortable(), marsh);
+ BinaryObjectImpl portableObj = marshal(new ChildPortable(), marsh);
ChildPortable singleton = portableObj.deserialize();
@@ -2030,7 +2030,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
obj1.val = BigDecimal.ZERO;
obj1.valArr = new BigDecimal[] { BigDecimal.ONE, BigDecimal.TEN };
- PortableObjectImpl portObj = marshal(obj1, marsh);
+ BinaryObjectImpl portObj = marshal(obj1, marsh);
assertEquals(obj1.val, portObj.field("val"));
assertArrayEquals(obj1.valArr, portObj.<BigDecimal[]>field("valArr"));
@@ -2077,7 +2077,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
// Checking the writer directly.
assertEquals(false, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
- try (PortableWriterExImpl writer = new PortableWriterExImpl(initPortableContext(new PortableMarshaller()))) {
+ try (BinaryWriterExImpl writer = new BinaryWriterExImpl(initPortableContext(new PortableMarshaller()))) {
assertEquals(true, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
writer.writeString("Thread local test");
@@ -2099,12 +2099,12 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
assertEquals(false, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
// Checking the builder.
- PortableBuilder builder = new PortableBuilderImpl(initPortableContext(new PortableMarshaller()),
+ BinaryObjectBuilder builder = new BinaryObjectBuilderImpl(initPortableContext(new PortableMarshaller()),
"org.gridgain.foo.bar.TestClass");
builder.setField("a", "1");
- PortableObject portableObj = builder.build();
+ BinaryObject portableObj = builder.build();
assertEquals(false, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
}
@@ -2124,7 +2124,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
try {
marsh.marshal(job2);
- } catch (PortableException e) {
+ } catch (BinaryObjectException e) {
assertEquals(true, e.getMessage().contains("Failed to register class"));
return;
}
@@ -2165,7 +2165,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
assertEquals(obj.cls1, obj2.cls1);
assertNull(obj2.cls2);
- PortableObject portObj = marshal(obj, marsh);
+ BinaryObject portObj = marshal(obj, marsh);
Class cls1 = portObj.field("cls1");
@@ -2339,7 +2339,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
* @param obj Object.
* @return Offheap address.
*/
- private long copyOffheap(PortableObjectImpl obj) {
+ private long copyOffheap(BinaryObjectImpl obj) {
byte[] arr = obj.array();
long ptr = UNSAFE.allocateMemory(arr.length);
@@ -2367,7 +2367,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
* @param off Offset.
* @return Value.
*/
- private int intFromPortable(PortableObject po, int off) {
+ private int intFromPortable(BinaryObject po, int off) {
byte[] arr = U.field(po, "arr");
return Integer.reverseBytes(U.bytesToInt(arr, off));
@@ -2399,12 +2399,12 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
* @param marsh Marshaller.
* @return Portable object.
*/
- private <T> PortableObjectImpl marshal(T obj, PortableMarshaller marsh) throws IgniteCheckedException {
+ private <T> BinaryObjectImpl marshal(T obj, PortableMarshaller marsh) throws IgniteCheckedException {
initPortableContext(marsh);
byte[] bytes = marsh.marshal(obj);
- return new PortableObjectImpl(U.<GridPortableMarshaller>field(marsh, "impl").context(),
+ return new BinaryObjectImpl(U.<GridPortableMarshaller>field(marsh, "impl").context(),
bytes, 0);
}
@@ -2412,7 +2412,9 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
* @return Portable context.
*/
protected PortableContext initPortableContext(PortableMarshaller marsh) throws IgniteCheckedException {
- PortableContext ctx = new PortableContext(META_HND, null);
+ IgniteConfiguration iCfg = new IgniteConfiguration();
+
+ PortableContext ctx = new PortableContext(META_HND, iCfg);
marsh.setContext(new MarshallerContextTestImpl(null));
@@ -2536,7 +2538,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
/**
* @return Portable object.
*/
- private TestPortableObject portableObject() {
+ private TestBinary BinaryObject() {
SimpleObject innerSimple = new SimpleObject();
innerSimple.b = 1;
@@ -2576,7 +2578,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
innerSimple.map.put(2, "str2");
innerSimple.map.put(3, "str3");
- TestPortableObject innerPortable = new TestPortableObject();
+ TestBinary innerPortable = new TestBinary();
innerPortable.b = 2;
innerPortable.s = 2;
@@ -2651,7 +2653,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
innerPortable.mapRaw.put(8, "str8");
innerPortable.mapRaw.put(9, "str9");
- TestPortableObject outer = new TestPortableObject();
+ TestBinary outer = new TestBinary();
outer.b = 4;
outer.s = 4;
@@ -2855,7 +2857,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
/** */
- private static class TestPortableObject implements PortableMarshalAware {
+ private static class TestBinary implements Binarylizable {
/** */
private byte b;
@@ -3031,13 +3033,13 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
private SimpleObject simpleRaw;
/** */
- private TestPortableObject portable;
+ private TestBinary portable;
/** */
- private TestPortableObject portableRaw;
+ private TestBinary portableRaw;
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeByte("_b", b);
writer.writeShort("_s", s);
writer.writeInt("_i", i);
@@ -3069,7 +3071,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
writer.writeObject("_simple", simple);
writer.writeObject("_portable", portable);
- PortableRawWriter raw = writer.rawWriter();
+ BinaryRawWriter raw = writer.rawWriter();
raw.writeByte(bRaw);
raw.writeShort(sRaw);
@@ -3104,7 +3106,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
b = reader.readByte("_b");
s = reader.readShort("_s");
i = reader.readInt("_i");
@@ -3136,7 +3138,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
simple = reader.readObject("_simple");
portable = reader.readObject("_portable");
- PortableRawReader raw = reader.rawReader();
+ BinaryRawReader raw = reader.rawReader();
bRaw = raw.readByte();
sRaw = raw.readShort();
@@ -3179,20 +3181,20 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
if (other == null || getClass() != other.getClass())
return false;
- TestPortableObject obj = (TestPortableObject)other;
+ TestBinary obj = (TestBinary)other;
return GridTestUtils.deepEquals(this, obj);
}
/** {@inheritDoc} */
@Override public String toString() {
- return S.toString(TestPortableObject.class, this);
+ return S.toString(TestBinary.class, this);
}
}
/**
*/
- private static class CustomSerializedObject1 implements PortableMarshalAware {
+ private static class CustomSerializedObject1 implements Binarylizable {
/** */
private int val;
@@ -3210,19 +3212,19 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
// No-op.
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
// No-op.
}
}
/**
*/
- private static class CustomSerializedObject2 implements PortableMarshalAware {
+ private static class CustomSerializedObject2 implements Binarylizable {
/** */
private int val;
@@ -3240,28 +3242,28 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
// No-op.
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
// No-op.
}
}
/**
*/
- private static class CustomSerializer1 implements PortableSerializer {
+ private static class CustomSerializer1 implements BinarySerializer {
/** {@inheritDoc} */
- @Override public void writePortable(Object obj, PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
CustomSerializedObject1 o = (CustomSerializedObject1)obj;
writer.writeInt("val", o.val * 2);
}
/** {@inheritDoc} */
- @Override public void readPortable(Object obj, PortableReader reader) throws PortableException {
+ @Override public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
CustomSerializedObject1 o = (CustomSerializedObject1)obj;
o.val = reader.readInt("val");
@@ -3270,16 +3272,16 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
/**
*/
- private static class CustomSerializer2 implements PortableSerializer {
+ private static class CustomSerializer2 implements BinarySerializer {
/** {@inheritDoc} */
- @Override public void writePortable(Object obj, PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
CustomSerializedObject2 o = (CustomSerializedObject2)obj;
writer.writeInt("val", o.val * 3);
}
/** {@inheritDoc} */
- @Override public void readPortable(Object obj, PortableReader reader) throws PortableException {
+ @Override public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
CustomSerializedObject2 o = (CustomSerializedObject2)obj;
o.val = reader.readInt("val");
@@ -3338,7 +3340,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
/**
*/
- private static class DynamicObject implements PortableMarshalAware {
+ private static class DynamicObject implements Binarylizable {
/** */
private int idx;
@@ -3370,7 +3372,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeInt("val1", val1);
if (idx > 0)
@@ -3383,7 +3385,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
val1 = reader.readInt("val1");
val2 = reader.readInt("val2");
val3 = reader.readInt("val3");
@@ -3399,7 +3401,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
/**
*/
- private static class DetachedTestObject implements PortableMarshalAware {
+ private static class DetachedTestObject implements Binarylizable {
/** */
private DetachedInnerTestObject inner1;
@@ -3429,8 +3431,8 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
- PortableRawWriterEx raw = (PortableRawWriterEx)writer.rawWriter();
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+ BinaryRawWriterEx raw = (BinaryRawWriterEx)writer.rawWriter();
raw.writeObject(inner1);
raw.writeObjectDetached(inner2);
@@ -3439,8 +3441,8 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
- PortableRawReaderEx raw = (PortableRawReaderEx)reader.rawReader();
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+ BinaryRawReaderEx raw = (BinaryRawReaderEx)reader.rawReader();
inner1 = (DetachedInnerTestObject)raw.readObject();
inner2 = raw.readObjectDetached();
@@ -3620,7 +3622,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
/**
*
*/
- private static class MyTestClass implements PortableMarshalAware {
+ private static class MyTestClass implements Binarylizable {
/** */
private boolean readyToSerialize;
@@ -3646,14 +3648,14 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
}
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
if (!readyToSerialize)
fail();
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
- s = "readPortable";
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+ s = "readBinary";
}
}
@@ -3737,7 +3739,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
/**
*
*/
- private static class DecimalMarshalAware extends DecimalReflective implements PortableMarshalAware {
+ private static class DecimalMarshalAware extends DecimalReflective implements Binarylizable {
/** */
public BigDecimal rawVal;
@@ -3745,22 +3747,22 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
public BigDecimal[] rawValArr;
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeDecimal("val", val);
writer.writeDecimalArray("valArr", valArr);
- PortableRawWriter rawWriter = writer.rawWriter();
+ BinaryRawWriter rawWriter = writer.rawWriter();
rawWriter.writeDecimal(rawVal);
rawWriter.writeDecimalArray(rawValArr);
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
val = reader.readDecimal("val");
valArr = reader.readDecimalArray("valArr");
- PortableRawReader rawReader = reader.rawReader();
+ BinaryRawReader rawReader = reader.rawReader();
rawVal = rawReader.readDecimal();
rawValArr = rawReader.readDecimalArray();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataDisabledSelfTest.java
index 05df23b..fbdb562 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataDisabledSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataDisabledSelfTest.java
@@ -17,15 +17,15 @@
package org.apache.ignite.internal.portable;
import java.util.Arrays;
-import org.apache.ignite.IgnitePortables;
+import org.apache.ignite.IgniteBinary;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableTypeConfiguration;
-import org.apache.ignite.portable.PortableWriter;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.binary.BinaryWriter;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
/**
@@ -47,8 +47,8 @@ public class GridPortableMetaDataDisabledSelfTest extends GridCommonAbstractTest
/**
* @return Portables.
*/
- private IgnitePortables portables() {
- return grid().portables();
+ private IgniteBinary portables() {
+ return grid().binary();
}
/**
@@ -67,14 +67,14 @@ public class GridPortableMetaDataDisabledSelfTest extends GridCommonAbstractTest
try {
startGrid();
- portables().toPortable(new TestObject1());
- portables().toPortable(new TestObject2());
- portables().toPortable(new TestObject3());
+ portables().toBinary(new TestObject1());
+ portables().toBinary(new TestObject2());
+ portables().toBinary(new TestObject3());
assertEquals(0, portables().metadata(TestObject1.class).fields().size());
assertEquals(0, portables().metadata(TestObject2.class).fields().size());
- PortableBuilder bldr = portables().builder("FakeType");
+ BinaryObjectBuilder bldr = portables().builder("FakeType");
bldr.setField("field1", 0).setField("field2", "value").build();
@@ -92,12 +92,12 @@ public class GridPortableMetaDataDisabledSelfTest extends GridCommonAbstractTest
public void testDisableGlobalSimpleClass() throws Exception {
marsh = new PortableMarshaller();
- PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(TestObject2.class.getName());
+ BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(TestObject2.class.getName());
typeCfg.setMetaDataEnabled(true);
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(TestObject1.class.getName()),
+ new BinaryTypeConfiguration(TestObject1.class.getName()),
typeCfg
));
@@ -106,8 +106,8 @@ public class GridPortableMetaDataDisabledSelfTest extends GridCommonAbstractTest
try {
startGrid();
- portables().toPortable(new TestObject1());
- portables().toPortable(new TestObject2());
+ portables().toBinary(new TestObject1());
+ portables().toBinary(new TestObject2());
assertEquals(0, portables().metadata(TestObject1.class).fields().size());
assertEquals(1, portables().metadata(TestObject2.class).fields().size());
@@ -123,12 +123,12 @@ public class GridPortableMetaDataDisabledSelfTest extends GridCommonAbstractTest
public void testDisableGlobalMarshalAwareClass() throws Exception {
marsh = new PortableMarshaller();
- PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(TestObject1.class.getName());
+ BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(TestObject1.class.getName());
typeCfg.setMetaDataEnabled(true);
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(TestObject2.class.getName()),
+ new BinaryTypeConfiguration(TestObject2.class.getName()),
typeCfg
));
@@ -137,8 +137,8 @@ public class GridPortableMetaDataDisabledSelfTest extends GridCommonAbstractTest
try {
startGrid();
- portables().toPortable(new TestObject1());
- portables().toPortable(new TestObject2());
+ portables().toBinary(new TestObject1());
+ portables().toBinary(new TestObject2());
assertEquals(1, portables().metadata(TestObject1.class).fields().size());
assertEquals(0, portables().metadata(TestObject2.class).fields().size());
@@ -154,20 +154,20 @@ public class GridPortableMetaDataDisabledSelfTest extends GridCommonAbstractTest
public void testDisableSimpleClass() throws Exception {
marsh = new PortableMarshaller();
- PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(TestObject1.class.getName());
+ BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(TestObject1.class.getName());
typeCfg.setMetaDataEnabled(false);
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(TestObject2.class.getName()),
+ new BinaryTypeConfiguration(TestObject2.class.getName()),
typeCfg
));
try {
startGrid();
- portables().toPortable(new TestObject1());
- portables().toPortable(new TestObject2());
+ portables().toBinary(new TestObject1());
+ portables().toBinary(new TestObject2());
assertEquals(0, portables().metadata(TestObject1.class).fields().size());
assertEquals(1, portables().metadata(TestObject2.class).fields().size());
@@ -183,20 +183,20 @@ public class GridPortableMetaDataDisabledSelfTest extends GridCommonAbstractTest
public void testDisableMarshalAwareClass() throws Exception {
marsh = new PortableMarshaller();
- PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(TestObject2.class.getName());
+ BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(TestObject2.class.getName());
typeCfg.setMetaDataEnabled(false);
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(TestObject1.class.getName()),
+ new BinaryTypeConfiguration(TestObject1.class.getName()),
typeCfg
));
try {
startGrid();
- portables().toPortable(new TestObject1());
- portables().toPortable(new TestObject2());
+ portables().toBinary(new TestObject1());
+ portables().toBinary(new TestObject2());
assertEquals(1, portables().metadata(TestObject1.class).fields().size());
assertEquals(0, portables().metadata(TestObject2.class).fields().size());
@@ -216,14 +216,14 @@ public class GridPortableMetaDataDisabledSelfTest extends GridCommonAbstractTest
/**
*/
- private static class TestObject2 implements PortableMarshalAware {
+ private static class TestObject2 implements Binarylizable {
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeInt("field", 1);
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
// No-op.
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java
index fa3c9a7..c0e2563 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java
@@ -22,17 +22,17 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
-import org.apache.ignite.IgnitePortables;
+import org.apache.ignite.IgniteBinary;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableRawWriter;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
/**
@@ -74,21 +74,21 @@ public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
/**
* @return Portables API.
*/
- protected IgnitePortables portables() {
- return grid().portables();
+ protected IgniteBinary portables() {
+ return grid().binary();
}
/**
* @throws Exception If failed.
*/
public void testGetAll() throws Exception {
- portables().toPortable(new TestObject2());
+ portables().toBinary(new TestObject2());
- Collection<PortableMetadata> metas = portables().metadata();
+ Collection<BinaryType> metas = portables().metadata();
assertEquals(2, metas.size());
- for (PortableMetadata meta : metas) {
+ for (BinaryType meta : metas) {
Collection<String> fields;
switch (meta.typeName()) {
@@ -150,7 +150,7 @@ public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
public void testNoConfiguration() throws Exception {
fail("https://issues.apache.org/jira/browse/IGNITE-1377");
- portables().toPortable(new TestObject3());
+ portables().toBinary(new TestObject3());
assertNotNull(portables().metadata(TestObject3.class));
}
@@ -159,7 +159,7 @@ public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
* @throws Exception If failed.
*/
public void testReflection() throws Exception {
- PortableMetadata meta = portables().metadata(TestObject1.class);
+ BinaryType meta = portables().metadata(TestObject1.class);
assertNotNull(meta);
@@ -190,9 +190,9 @@ public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
* @throws Exception If failed.
*/
public void testPortableMarshalAware() throws Exception {
- portables().toPortable(new TestObject2());
+ portables().toBinary(new TestObject2());
- PortableMetadata meta = portables().metadata(TestObject2.class);
+ BinaryType meta = portables().metadata(TestObject2.class);
assertNotNull(meta);
@@ -223,13 +223,13 @@ public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
* @throws Exception If failed.
*/
public void testMerge() throws Exception {
- portables().toPortable(new TestObject2());
+ portables().toBinary(new TestObject2());
idx = 1;
- portables().toPortable(new TestObject2());
+ portables().toBinary(new TestObject2());
- PortableMetadata meta = portables().metadata(TestObject2.class);
+ BinaryType meta = portables().metadata(TestObject2.class);
assertNotNull(meta);
@@ -274,11 +274,11 @@ public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
obj.decVal = BigDecimal.ZERO;
obj.decArrVal = new BigDecimal[] { BigDecimal.ONE };
- PortableObject po = portables().toPortable(obj);
+ BinaryObject po = portables().toBinary(obj);
info(po.toString());
- PortableMetadata meta = po.metaData();
+ BinaryType meta = po.type();
assertNotNull(meta);
@@ -333,9 +333,9 @@ public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
/**
*/
- private static class TestObject2 implements PortableMarshalAware {
+ private static class TestObject2 implements Binarylizable {
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeBoolean("boolVal", false);
writer.writeDate("dateVal", new Date());
writer.writeUuidArray("uuidArrVal", null);
@@ -349,14 +349,14 @@ public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
writer.writeCollection("colVal", null);
}
- PortableRawWriter raw = writer.rawWriter();
+ BinaryRawWriter raw = writer.rawWriter();
raw.writeChar((char)0);
raw.writeCollection(null);
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
// No-op.
}
}
[22/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetaDataImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetaDataImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetaDataImpl.java
new file mode 100644
index 0000000..18f538b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetaDataImpl.java
@@ -0,0 +1,150 @@
+/*
+ * 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.portable;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryRawReader;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Portable meta data implementation.
+ */
+public class BinaryMetaDataImpl implements BinaryType, Binarylizable, Externalizable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** */
+ private String typeName;
+
+ /** */
+ @GridToStringInclude
+ private Map<String, String> fields;
+
+ /** */
+ private volatile Map<Integer, String> fldIdToName;
+
+ /** */
+ private String affKeyFieldName;
+
+ /**
+ * For {@link Externalizable}.
+ */
+ public BinaryMetaDataImpl() {
+ // No-op.
+ }
+
+ /**
+ * @param typeName Type name.
+ * @param fields Fields map.
+ * @param affKeyFieldName Affinity key field name.
+ */
+ public BinaryMetaDataImpl(String typeName, @Nullable Map<String, String> fields,
+ @Nullable String affKeyFieldName) {
+ assert typeName != null;
+
+ this.typeName = typeName;
+ this.fields = fields;
+ this.affKeyFieldName = affKeyFieldName;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String typeName() {
+ return typeName;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<String> fields() {
+ return fields != null ? fields.keySet() : Collections.<String>emptyList();
+ }
+
+ /**
+ * @return Fields.
+ */
+ public Map<String, String> fields0() {
+ return fields != null ? fields : Collections.<String, String>emptyMap();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public String fieldTypeName(String fieldName) {
+ return fields != null ? fields.get(fieldName) : null;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public String affinityKeyFieldName() {
+ return affKeyFieldName;
+ }
+
+ /**
+ * @return Fields meta data.
+ */
+ public Map<String, String> fieldsMeta() {
+ return fields != null ? fields : Collections.<String, String>emptyMap();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ U.writeString(out, typeName);
+ U.writeMap(out, fields);
+ U.writeString(out, affKeyFieldName);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ typeName = U.readString(in);
+ fields = U.readMap(in);
+ affKeyFieldName = U.readString(in);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+ BinaryRawWriter raw = writer.rawWriter();
+
+ raw.writeString(typeName);
+ raw.writeString(affKeyFieldName);
+ raw.writeMap(fields);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+ BinaryRawReader raw = reader.rawReader();
+
+ typeName = raw.readString();
+ affKeyFieldName = raw.readString();
+ fields = raw.readMap();
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(BinaryMetaDataImpl.class, this);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.java
new file mode 100644
index 0000000..50b9d42
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.java
@@ -0,0 +1,245 @@
+/*
+ * 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.portable;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.IdentityHashMap;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
+import org.apache.ignite.internal.util.typedef.internal.SB;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Internal portable object interface.
+ */
+public abstract class BinaryObjectEx implements BinaryObject {
+ /**
+ * @return Length.
+ */
+ public abstract int length();
+
+ /**
+ * @return Object start.
+ */
+ public abstract int start();
+
+ /**
+ * @return {@code True} if object is array based.
+ */
+ protected abstract boolean hasArray();
+
+ /**
+ * @return Object array if object is array based, otherwise {@code null}.
+ */
+ public abstract byte[] array();
+
+ /**
+ * @return Object offheap address is object is offheap based, otherwise 0.
+ */
+ public abstract long offheapAddress();
+
+ /**
+ * Gets field value.
+ *
+ * @param fieldId Field ID.
+ * @return Field value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of any other error.
+ */
+ @Nullable public abstract <F> F field(int fieldId) throws BinaryObjectException;
+
+ /**
+ * Get field by offset.
+ *
+ * @param fieldOffset Field offset.
+ * @return Field value.
+ */
+ @Nullable protected abstract <F> F fieldByOrder(int fieldOffset);
+
+ /**
+ * @param ctx Reader context.
+ * @param fieldName Field name.
+ * @return Field value.
+ */
+ @Nullable protected abstract <F> F field(PortableReaderContext ctx, String fieldName);
+
+ /**
+ * Get schema ID.
+ *
+ * @return Schema ID.
+ */
+ protected abstract int schemaId();
+
+ /**
+ * Create schema for object.
+ *
+ * @return Schema.
+ */
+ protected abstract PortableSchema createSchema();
+
+ /** {@inheritDoc} */
+ @Override public BinaryObject clone() throws CloneNotSupportedException {
+ return (BinaryObject)super.clone();
+ }
+
+ /** {@inheritDoc} */
+ public boolean equals(Object other) {
+ if (other == this)
+ return true;
+
+ if (other == null)
+ return false;
+
+ if (!(other instanceof BinaryObjectEx))
+ return false;
+
+ BinaryObjectEx otherPo = (BinaryObjectEx)other;
+
+ if (length() != otherPo.length() || typeId() != otherPo.typeId())
+ return false;
+
+ if (hasArray()) {
+ if (otherPo.hasArray()) {
+ int len = length();
+ int end = start() + len;
+
+ byte[] arr = array();
+ byte[] otherArr = otherPo.array();
+
+ for (int i = start(), j = otherPo.start(); i < end; i++, j++) {
+ if (arr[i] != otherArr[j])
+ return false;
+ }
+
+ return true;
+ }
+ else {
+ assert otherPo.offheapAddress() > 0;
+
+ return GridUnsafeMemory.compare(otherPo.offheapAddress() + otherPo.start(), array());
+ }
+ }
+ else {
+ assert offheapAddress() > 0;
+
+ if (otherPo.hasArray())
+ return GridUnsafeMemory.compare(offheapAddress() + start(), otherPo.array());
+ else {
+ assert otherPo.offheapAddress() > 0;
+
+ return GridUnsafeMemory.compare(offheapAddress() + start(),
+ otherPo.offheapAddress() + otherPo.start(),
+ length());
+ }
+ }
+ }
+
+ /**
+ * @param ctx Reader context.
+ * @param handles Handles for already traversed objects.
+ * @return String representation.
+ */
+ private String toString(PortableReaderContext ctx, IdentityHashMap<BinaryObject, Integer> handles) {
+ int idHash = System.identityHashCode(this);
+
+ BinaryType meta;
+
+ try {
+ meta = type();
+ }
+ catch (BinaryObjectException ignore) {
+ meta = null;
+ }
+
+ if (meta == null)
+ return "PortableObject [hash=" + idHash + ", typeId=" + typeId() + ']';
+
+ handles.put(this, idHash);
+
+ SB buf = new SB(meta.typeName());
+
+ if (meta.fields() != null) {
+ buf.a(" [hash=").a(idHash);
+
+ for (String name : meta.fields()) {
+ Object val = field(ctx, name);
+
+ buf.a(", ").a(name).a('=');
+
+ if (val instanceof byte[])
+ buf.a(Arrays.toString((byte[]) val));
+ else if (val instanceof short[])
+ buf.a(Arrays.toString((short[])val));
+ else if (val instanceof int[])
+ buf.a(Arrays.toString((int[])val));
+ else if (val instanceof long[])
+ buf.a(Arrays.toString((long[])val));
+ else if (val instanceof float[])
+ buf.a(Arrays.toString((float[])val));
+ else if (val instanceof double[])
+ buf.a(Arrays.toString((double[])val));
+ else if (val instanceof char[])
+ buf.a(Arrays.toString((char[])val));
+ else if (val instanceof boolean[])
+ buf.a(Arrays.toString((boolean[]) val));
+ else if (val instanceof BigDecimal[])
+ buf.a(Arrays.toString((BigDecimal[])val));
+ else {
+ if (val instanceof BinaryObjectEx) {
+ BinaryObjectEx po = (BinaryObjectEx)val;
+
+ Integer idHash0 = handles.get(val);
+
+ if (idHash0 != null) { // Circular reference.
+ BinaryType meta0 = po.type();
+
+ assert meta0 != null;
+
+ buf.a(meta0.typeName()).a(" [hash=").a(idHash0).a(", ...]");
+ }
+ else
+ buf.a(po.toString(ctx, handles));
+ }
+ else
+ buf.a(val);
+ }
+ }
+
+ buf.a(']');
+ }
+
+ return buf.toString();
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ try {
+ PortableReaderContext ctx = new PortableReaderContext();
+
+ ctx.setPortableHandler(start(), this);
+
+ return toString(ctx, new IdentityHashMap<BinaryObject, Integer>());
+ }
+ catch (BinaryObjectException e) {
+ throw new IgniteException("Failed to create string representation of portable object.", e);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java
new file mode 100644
index 0000000..6412b7f
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java
@@ -0,0 +1,606 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridDirectTransient;
+import org.apache.ignite.internal.IgniteCodeGeneratingFail;
+import org.apache.ignite.internal.portable.streams.PortableHeapInputStream;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.U;
+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.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryField;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.UUID;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
+
+/**
+ * Portable object implementation.
+ */
+@IgniteCodeGeneratingFail // Fields arr and start should not be generated by MessageCodeGenerator.
+public final class BinaryObjectImpl extends BinaryObjectEx implements Externalizable,
+ Message, CacheObject, KeyCacheObject {
+ /** */
+ public static final byte TYPE_BINARY = 100;
+
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** */
+ @GridDirectTransient
+ private PortableContext ctx;
+
+ /** */
+ private byte[] arr;
+
+ /** */
+ private int start;
+
+ /** */
+ @GridDirectTransient
+ private Object obj;
+
+ /** */
+ @GridDirectTransient
+ private boolean detachAllowed;
+
+ /**
+ * For {@link Externalizable}.
+ */
+ public BinaryObjectImpl() {
+ // No-op.
+ }
+
+ /**
+ * @param ctx Context.
+ * @param arr Array.
+ * @param start Start.
+ */
+ public BinaryObjectImpl(PortableContext ctx, byte[] arr, int start) {
+ assert ctx != null;
+ assert arr != null;
+
+ this.ctx = ctx;
+ this.arr = arr;
+ this.start = start;
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte cacheObjectType() {
+ return TYPE_BINARY;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isPlatformType() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean internal() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+ Object obj0 = obj;
+
+ if (obj0 == null || cpy)
+ obj0 = deserializeValue();
+
+ return (T)obj0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+ if (detached())
+ return array();
+
+ int len = length();
+
+ byte[] arr0 = new byte[len];
+
+ U.arrayCopy(arr, start, arr0, 0, len);
+
+ return arr0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
+ if (detached())
+ return this;
+
+ return (BinaryObjectImpl)detach();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+ this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.processor()).portableContext();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public int length() {
+ return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TOTAL_LEN_POS);
+ }
+
+ /**
+ * @return Detached portable object.
+ */
+ public BinaryObject detach() {
+ if (!detachAllowed || detached())
+ return this;
+
+ int len = length();
+
+ byte[] arr0 = new byte[len];
+
+ U.arrayCopy(arr, start, arr0, 0, len);
+
+ return new BinaryObjectImpl(ctx, arr0, 0);
+ }
+
+ /**
+ * @return Detached or not.
+ */
+ public boolean detached() {
+ return start == 0 && length() == arr.length;
+ }
+
+ /**
+ * @param detachAllowed Detach allowed flag.
+ */
+ public void detachAllowed(boolean detachAllowed) {
+ this.detachAllowed = detachAllowed;
+ }
+
+ /**
+ * @return Context.
+ */
+ public PortableContext context() {
+ return ctx;
+ }
+
+ /**
+ * @param ctx Context.
+ */
+ public void context(PortableContext ctx) {
+ this.ctx = ctx;
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte[] array() {
+ return arr;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int start() {
+ return start;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long offheapAddress() {
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected boolean hasArray() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int typeId() {
+ return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TYPE_ID_POS);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public BinaryType type() throws BinaryObjectException {
+ if (ctx == null)
+ throw new BinaryObjectException("PortableContext is not set for the object.");
+
+ return ctx.metaData(typeId());
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override public <F> F field(String fieldName) throws BinaryObjectException {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx, arr, start, null);
+
+ return (F)reader.unmarshalField(fieldName);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override public <F> F field(int fieldId) throws BinaryObjectException {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx, arr, start, null);
+
+ return (F)reader.unmarshalField(fieldId);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override protected <F> F fieldByOrder(int order) {
+ Object val;
+
+ // Calculate field position.
+ int schemaOffset = PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+
+ short flags = PortablePrimitives.readShort(arr, start + GridPortableMarshaller.FLAGS_POS);
+ int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+
+ int fieldOffsetPos = start + schemaOffset + order * (4 + fieldOffsetSize) + 4;
+
+ int fieldPos;
+
+ if (fieldOffsetSize == PortableUtils.OFFSET_1)
+ fieldPos = start + ((int)PortablePrimitives.readByte(arr, fieldOffsetPos) & 0xFF);
+ else if (fieldOffsetSize == PortableUtils.OFFSET_2)
+ fieldPos = start + ((int)PortablePrimitives.readShort(arr, fieldOffsetPos) & 0xFFFF);
+ else
+ fieldPos = start + PortablePrimitives.readInt(arr, fieldOffsetPos);
+
+ // Read header and try performing fast lookup for well-known types (the most common types go first).
+ byte hdr = PortablePrimitives.readByte(arr, fieldPos);
+
+ switch (hdr) {
+ case INT:
+ val = PortablePrimitives.readInt(arr, fieldPos + 1);
+
+ break;
+
+ case LONG:
+ val = PortablePrimitives.readLong(arr, fieldPos + 1);
+
+ break;
+
+ case BOOLEAN:
+ val = PortablePrimitives.readBoolean(arr, fieldPos + 1);
+
+ break;
+
+ case SHORT:
+ val = PortablePrimitives.readShort(arr, fieldPos + 1);
+
+ break;
+
+ case BYTE:
+ val = PortablePrimitives.readByte(arr, fieldPos + 1);
+
+ break;
+
+ case CHAR:
+ val = PortablePrimitives.readChar(arr, fieldPos + 1);
+
+ break;
+
+ case FLOAT:
+ val = PortablePrimitives.readFloat(arr, fieldPos + 1);
+
+ break;
+
+ case DOUBLE:
+ val = PortablePrimitives.readDouble(arr, fieldPos + 1);
+
+ break;
+
+ case STRING: {
+ boolean utf = PortablePrimitives.readBoolean(arr, fieldPos + 1);
+
+ if (utf) {
+ int dataLen = PortablePrimitives.readInt(arr, fieldPos + 2);
+
+ val = new String(arr, fieldPos + 6, dataLen, UTF_8);
+ }
+ else {
+ int dataLen = PortablePrimitives.readInt(arr, fieldPos + 2);
+ char[] data = PortablePrimitives.readCharArray(arr, fieldPos + 6, dataLen);
+
+ val = String.valueOf(data);
+ }
+
+ break;
+ }
+
+ case DATE: {
+ long time = PortablePrimitives.readLong(arr, fieldPos + 1);
+
+ val = new Date(time);
+
+ break;
+ }
+
+ case TIMESTAMP: {
+ long time = PortablePrimitives.readLong(arr, fieldPos + 1);
+ int nanos = PortablePrimitives.readInt(arr, fieldPos + 1 + 8);
+
+ Timestamp ts = new Timestamp(time);
+
+ ts.setNanos(ts.getNanos() + nanos);
+
+ val = ts;
+
+ break;
+ }
+
+ case UUID: {
+ long most = PortablePrimitives.readLong(arr, fieldPos + 1);
+ long least = PortablePrimitives.readLong(arr, fieldPos + 1 + 8);
+
+ val = new UUID(most, least);
+
+ break;
+ }
+
+ case DECIMAL: {
+ int scale = PortablePrimitives.readInt(arr, fieldPos + 1);
+
+ int dataLen = PortablePrimitives.readInt(arr, fieldPos + 5);
+ byte[] data = PortablePrimitives.readByteArray(arr, fieldPos + 9, dataLen);
+
+ BigInteger intVal = new BigInteger(data);
+
+ if (scale < 0) {
+ scale &= 0x7FFFFFFF;
+
+ intVal = intVal.negate();
+ }
+
+ val = new BigDecimal(intVal, scale);
+
+ break;
+ }
+
+ case NULL:
+ val = null;
+
+ break;
+
+ default: {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx, arr, start, null);
+
+ val = reader.unmarshalFieldByAbsolutePosition(fieldPos);
+ }
+ }
+
+ return (F)val;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override protected <F> F field(PortableReaderContext rCtx, String fieldName) {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx,
+ new PortableHeapInputStream(arr),
+ start,
+ null,
+ rCtx);
+
+ return (F)reader.unmarshalField(fieldName);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean hasField(String fieldName) {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx, arr, start, null);
+
+ return reader.hasField(fieldName);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override public <T> T deserialize() throws BinaryObjectException {
+ Object obj0 = obj;
+
+ if (obj0 == null)
+ obj0 = deserializeValue();
+
+ return (T)obj0;
+
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObject clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.HASH_CODE_POS);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int schemaId() {
+ return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_ID_POS);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected PortableSchema createSchema() {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx, arr, start, null);
+
+ return reader.createSchema();
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryField fieldDescriptor(String fieldName) throws BinaryObjectException {
+ A.notNull(fieldName, "fieldName");
+
+ int typeId = typeId();
+
+ PortableSchemaRegistry schemaReg = ctx.schemaRegistry(typeId);
+
+ int fieldId = ctx.userTypeIdMapper(typeId).fieldId(typeId, fieldName);
+
+ return new BinaryFieldImpl(schemaReg, fieldName, fieldId);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(ctx);
+
+ if (detachAllowed) {
+ int len = length();
+
+ out.writeInt(len);
+ out.write(arr, start, len);
+ out.writeInt(0);
+ }
+ else {
+ out.writeInt(arr.length);
+ out.write(arr);
+ out.writeInt(start);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ ctx = (PortableContext)in.readObject();
+
+ arr = new byte[in.readInt()];
+
+ in.readFully(arr);
+
+ start = in.readInt();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+ writer.setBuffer(buf);
+
+ if (!writer.isHeaderWritten()) {
+ if (!writer.writeHeader(directType(), fieldsCount()))
+ return false;
+
+ writer.onHeaderWritten();
+ }
+
+ switch (writer.state()) {
+ case 0:
+ if (!writer.writeByteArray("arr",
+ arr,
+ detachAllowed ? start : 0,
+ detachAllowed ? length() : arr.length))
+ return false;
+
+ writer.incrementState();
+
+ case 1:
+ if (!writer.writeInt("start", detachAllowed ? 0 : start))
+ return false;
+
+ writer.incrementState();
+
+ }
+
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+ reader.setBuffer(buf);
+
+ if (!reader.beforeMessageRead())
+ return false;
+
+ switch (reader.state()) {
+ case 0:
+ arr = reader.readByteArray("arr");
+
+ if (!reader.isLastRead())
+ return false;
+
+ reader.incrementState();
+
+ case 1:
+ start = reader.readInt("start");
+
+ if (!reader.isLastRead())
+ return false;
+
+ reader.incrementState();
+
+ }
+
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte directType() {
+ return 113;
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte fieldsCount() {
+ return 3;
+ }
+
+ /**
+ * Runs value deserialization regardless of whether obj already has the deserialized value.
+ * Will set obj if descriptor is configured to keep deserialized values.
+ */
+ private Object deserializeValue() {
+ // TODO: IGNITE-1272 - Deserialize with proper class loader.
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx, arr, start, null);
+
+ Object obj0 = reader.deserialize();
+
+ PortableClassDescriptor desc = reader.descriptor();
+
+ assert desc != null;
+
+ if (desc.keepDeserialized())
+ obj = obj0;
+
+ return obj0;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectOffheapImpl.java
new file mode 100644
index 0000000..e53e9fb
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectOffheapImpl.java
@@ -0,0 +1,470 @@
+/*
+ * 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.portable;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.UUID;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.portable.streams.PortableOffheapInputStream;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.extensions.communication.MessageReader;
+import org.apache.ignite.plugin.extensions.communication.MessageWriter;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryField;
+import org.jetbrains.annotations.Nullable;
+import sun.misc.Unsafe;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
+
+/**
+ * Portable object implementation over offheap memory
+ */
+public class BinaryObjectOffheapImpl extends BinaryObjectEx implements Externalizable, CacheObject {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** */
+ private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+ /** */
+ private final PortableContext ctx;
+
+ /** */
+ private final long ptr;
+
+ /** */
+ private final int start;
+
+ /** */
+ private final int size;
+
+ /**
+ * For {@link Externalizable} (not supported).
+ */
+ public BinaryObjectOffheapImpl() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @param ctx Context.
+ * @param ptr Memory address.
+ * @param start Object start.
+ * @param size Memory size.
+ */
+ public BinaryObjectOffheapImpl(PortableContext ctx, long ptr, int start, int size) {
+ this.ctx = ctx;
+ this.ptr = ptr;
+ this.start = start;
+ this.size = size;
+ }
+
+ /**
+ * @return Heap-based copy.
+ */
+ public BinaryObject heapCopy() {
+ return new BinaryObjectImpl(ctx, U.copyMemory(ptr, size), start);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int typeId() {
+ return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TYPE_ID_POS);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int length() {
+ return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TOTAL_LEN_POS);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return UNSAFE.getInt(ptr + start + GridPortableMarshaller.HASH_CODE_POS);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int schemaId() {
+ return UNSAFE.getInt(ptr + start + GridPortableMarshaller.SCHEMA_ID_POS);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected PortableSchema createSchema() {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx,
+ new PortableOffheapInputStream(ptr, size, false),
+ start,
+ null);
+
+ return reader.createSchema();
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryField fieldDescriptor(String fieldName) throws BinaryObjectException {
+ A.notNull(fieldName, "fieldName");
+
+ int typeId = typeId();
+
+ PortableSchemaRegistry schemaReg = ctx.schemaRegistry(typeId);
+
+ int fieldId = ctx.userTypeIdMapper(typeId).fieldId(typeId, fieldName);
+
+ return new BinaryFieldImpl(schemaReg, fieldName, fieldId);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int start() {
+ return start;
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte[] array() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long offheapAddress() {
+ return ptr;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected boolean hasArray() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public BinaryType type() throws BinaryObjectException {
+ if (ctx == null)
+ throw new BinaryObjectException("PortableContext is not set for the object.");
+
+ return ctx.metaData(typeId());
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override public <F> F field(String fieldName) throws BinaryObjectException {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx,
+ new PortableOffheapInputStream(ptr, size, false),
+ start,
+ null);
+
+ return (F)reader.unmarshalField(fieldName);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override public <F> F field(int fieldId) throws BinaryObjectException {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx,
+ new PortableOffheapInputStream(ptr, size, false),
+ start,
+ null);
+
+ return (F)reader.unmarshalField(fieldId);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override protected <F> F fieldByOrder(int order) {
+ Object val;
+
+ // Calculate field position.
+ int schemaOffset = PortablePrimitives.readInt(ptr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+
+ short flags = PortablePrimitives.readShort(ptr, start + GridPortableMarshaller.FLAGS_POS);
+ int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+
+ int fieldOffsetPos = start + schemaOffset + order * (4 + fieldOffsetSize) + 4;
+
+ int fieldPos;
+
+ if (fieldOffsetSize == PortableUtils.OFFSET_1)
+ fieldPos = start + ((int)PortablePrimitives.readByte(ptr, fieldOffsetPos) & 0xFF);
+ else if (fieldOffsetSize == PortableUtils.OFFSET_2)
+ fieldPos = start + ((int)PortablePrimitives.readShort(ptr, fieldOffsetPos) & 0xFFFF);
+ else
+ fieldPos = start + PortablePrimitives.readInt(ptr, fieldOffsetPos);
+
+ // Read header and try performing fast lookup for well-known types (the most common types go first).
+ byte hdr = PortablePrimitives.readByte(ptr, fieldPos);
+
+ switch (hdr) {
+ case INT:
+ val = PortablePrimitives.readInt(ptr, fieldPos + 1);
+
+ break;
+
+ case LONG:
+ val = PortablePrimitives.readLong(ptr, fieldPos + 1);
+
+ break;
+
+ case BOOLEAN:
+ val = PortablePrimitives.readBoolean(ptr, fieldPos + 1);
+
+ break;
+
+ case SHORT:
+ val = PortablePrimitives.readShort(ptr, fieldPos + 1);
+
+ break;
+
+ case BYTE:
+ val = PortablePrimitives.readByte(ptr, fieldPos + 1);
+
+ break;
+
+ case CHAR:
+ val = PortablePrimitives.readChar(ptr, fieldPos + 1);
+
+ break;
+
+ case FLOAT:
+ val = PortablePrimitives.readFloat(ptr, fieldPos + 1);
+
+ break;
+
+ case DOUBLE:
+ val = PortablePrimitives.readDouble(ptr, fieldPos + 1);
+
+ break;
+
+ case STRING: {
+ boolean utf = PortablePrimitives.readBoolean(ptr, fieldPos + 1);
+
+ if (utf) {
+ int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 2);
+ byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 6, dataLen);
+
+ val = new String(data, UTF_8);
+ }
+ else {
+ int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 2);
+ char[] data = PortablePrimitives.readCharArray(ptr, fieldPos + 6, dataLen);
+
+ val = String.valueOf(data);
+ }
+
+ break;
+ }
+
+ case DATE: {
+ long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
+
+ val = new Date(time);
+
+ break;
+ }
+
+ case TIMESTAMP: {
+ long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
+ int nanos = PortablePrimitives.readInt(ptr, fieldPos + 1 + 8);
+
+ Timestamp ts = new Timestamp(time);
+
+ ts.setNanos(ts.getNanos() + nanos);
+
+ val = ts;
+
+ break;
+ }
+
+ case UUID: {
+ long most = PortablePrimitives.readLong(ptr, fieldPos + 1);
+ long least = PortablePrimitives.readLong(ptr, fieldPos + 1 + 8);
+
+ val = new UUID(most, least);
+
+ break;
+ }
+
+ case DECIMAL: {
+ int scale = PortablePrimitives.readInt(ptr, fieldPos + 1);
+
+ int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 5);
+ byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 9, dataLen);
+
+ BigInteger intVal = new BigInteger(data);
+
+ if (scale < 0) {
+ scale &= 0x7FFFFFFF;
+
+ intVal = intVal.negate();
+ }
+
+ val = new BigDecimal(intVal, scale);
+
+ break;
+ }
+
+ case NULL:
+ val = null;
+
+ break;
+
+ default: {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx,
+ new PortableOffheapInputStream(ptr, size, false),
+ start,
+ null);
+
+ val = reader.unmarshalFieldByAbsolutePosition(fieldPos);
+ }
+ }
+
+ return (F)val;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override protected <F> F field(PortableReaderContext rCtx, String fieldName) {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx,
+ new PortableOffheapInputStream(ptr, size, false),
+ start,
+ null,
+ rCtx);
+
+ return (F)reader.unmarshalField(fieldName);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean hasField(String fieldName) {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx,
+ new PortableOffheapInputStream(ptr, size, false),
+ start,
+ null);
+
+ return reader.hasField(fieldName);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override public <T> T deserialize() throws BinaryObjectException {
+ return (T)deserializeValue();
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("CloneDoesntCallSuperClone")
+ @Override public BinaryObject clone() throws CloneNotSupportedException {
+ return heapCopy();
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte cacheObjectType() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isPlatformType() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+ return (T)deserializeValue();
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte directType() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte fieldsCount() {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ throw new UnsupportedOperationException(); // To make sure it is not marshalled.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ throw new UnsupportedOperationException(); // To make sure it is not marshalled.
+ }
+
+ /**
+ * @return Deserialized value.
+ */
+ private Object deserializeValue() {
+ // TODO: IGNITE-1272 - Deserialize with proper class loader.
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(
+ ctx,
+ new PortableOffheapInputStream(ptr, size, false),
+ start,
+ null);
+
+ return reader.deserialize();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawReaderEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawReaderEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawReaderEx.java
new file mode 100644
index 0000000..3d7c61a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawReaderEx.java
@@ -0,0 +1,33 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawReader;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Extended reader interface.
+ */
+public interface BinaryRawReaderEx extends BinaryRawReader {
+ /**
+ * @return Object.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable public Object readObjectDetached() throws BinaryObjectException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawWriterEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawWriterEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawWriterEx.java
new file mode 100644
index 0000000..96312b4
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawWriterEx.java
@@ -0,0 +1,60 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.internal.portable.streams.PortableOutputStream;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Extended writer interface.
+ */
+public interface BinaryRawWriterEx extends BinaryRawWriter, AutoCloseable {
+ /**
+ * @param obj Object to write.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ public void writeObjectDetached(@Nullable Object obj) throws BinaryObjectException;
+
+ /**
+ * @return Output stream.
+ */
+ public PortableOutputStream out();
+
+ /**
+ * Cleans resources.
+ */
+ @Override public void close();
+
+ /**
+ * Reserve a room for an integer.
+ *
+ * @return Position in the stream where value is to be written.
+ */
+ public int reserveInt();
+
+ /**
+ * Write int value at the specific position.
+ *
+ * @param pos Position.
+ * @param val Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException If failed.
+ */
+ public void writeInt(int pos, int val) throws BinaryObjectException;
+}
\ No newline at end of file
[26/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
Merged IGNITE-950-new into IGNITE-1282
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b783d2b7
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b783d2b7
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b783d2b7
Branch: refs/heads/ignite-1282
Commit: b783d2b71a3b05cecc62d114283e8d92dffcb126
Parents: 76b65b2
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Thu Nov 5 16:09:03 2015 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Thu Nov 5 16:09:09 2015 +0300
----------------------------------------------------------------------
.../config/binary/example-ignite-binary.xml | 44 +
.../config/portable/example-ignite-portable.xml | 44 -
.../apache/ignite/examples/binary/Address.java | 72 +
.../apache/ignite/examples/binary/Employee.java | 93 +
.../ignite/examples/binary/EmployeeKey.java | 90 +
.../binary/ExampleBinaryNodeStartup.java | 36 +
.../ignite/examples/binary/Organization.java | 93 +
.../examples/binary/OrganizationType.java | 32 +
...ComputeClientBinaryTaskExecutionExample.java | 153 +
.../binary/computegrid/ComputeClientTask.java | 116 +
.../binary/computegrid/package-info.java | 21 +
.../CacheClientBinaryPutGetExample.java | 230 ++
.../datagrid/CacheClientBinaryQueryExample.java | 330 +++
.../examples/binary/datagrid/package-info.java | 21 +
.../ignite/examples/binary/package-info.java | 21 +
.../ignite/examples/portable/Address.java | 72 -
.../ignite/examples/portable/Employee.java | 93 -
.../ignite/examples/portable/EmployeeKey.java | 90 -
.../portable/ExamplePortableNodeStartup.java | 36 -
.../ignite/examples/portable/Organization.java | 93 -
.../examples/portable/OrganizationType.java | 32 -
...mputeClientPortableTaskExecutionExample.java | 154 -
.../portable/computegrid/ComputeClientTask.java | 116 -
.../portable/computegrid/package-info.java | 21 -
.../CacheClientPortablePutGetExample.java | 230 --
.../CacheClientPortableQueryExample.java | 325 --
.../portable/datagrid/package-info.java | 21 -
.../ignite/examples/portable/package-info.java | 21 -
.../CacheClientPortableExampleTest.java | 8 +-
.../ComputeClientPortableExampleTest.java | 4 +-
.../ignite/codegen/MessageCodeGenerator.java | 5 +-
.../src/main/java/org/apache/ignite/Ignite.java | 6 +-
.../java/org/apache/ignite/IgniteBinary.java | 366 +++
.../java/org/apache/ignite/IgniteCache.java | 14 +-
.../org/apache/ignite/IgniteDataStreamer.java | 16 +
.../java/org/apache/ignite/IgnitePortables.java | 370 ---
.../org/apache/ignite/binary/BinaryField.java | 46 +
.../binary/BinaryInvalidTypeException.java | 58 +
.../org/apache/ignite/binary/BinaryObject.java | 163 +
.../ignite/binary/BinaryObjectBuilder.java | 136 +
.../ignite/binary/BinaryObjectException.java | 57 +
.../apache/ignite/binary/BinaryRawReader.java | 240 ++
.../apache/ignite/binary/BinaryRawWriter.java | 225 ++
.../org/apache/ignite/binary/BinaryReader.java | 290 ++
.../apache/ignite/binary/BinarySerializer.java | 49 +
.../org/apache/ignite/binary/BinaryType.java | 59 +
.../ignite/binary/BinaryTypeConfiguration.java | 156 +
.../ignite/binary/BinaryTypeIdMapper.java | 56 +
.../org/apache/ignite/binary/BinaryWriter.java | 273 ++
.../org/apache/ignite/binary/Binarylizable.java | 48 +
.../org/apache/ignite/binary/package-info.java | 22 +
.../ignite/cache/CacheKeyConfiguration.java | 92 +
.../apache/ignite/cache/CacheTypeMetadata.java | 67 +-
.../org/apache/ignite/cache/IgniteObject.java | 60 -
.../org/apache/ignite/cache/QueryEntity.java | 217 ++
.../org/apache/ignite/cache/QueryIndex.java | 192 ++
.../org/apache/ignite/cache/QueryIndexType.java | 38 +
.../configuration/CacheConfiguration.java | 662 ++++-
.../configuration/IgniteConfiguration.java | 24 +
.../ignite/internal/GridKernalContextImpl.java | 4 +-
.../apache/ignite/internal/IgniteKernal.java | 17 +-
.../internal/client/GridClientCompute.java | 2 +-
.../impl/connection/GridClientConnection.java | 2 +-
.../GridClientConnectionManagerAdapter.java | 2 +-
.../connection/GridClientNioTcpConnection.java | 6 +-
.../communication/GridIoMessageFactory.java | 4 +-
.../swapspace/GridSwapSpaceManager.java | 34 -
.../internal/portable/BinaryFieldImpl.java | 104 +
.../portable/BinaryMetaDataCollector.java | 263 ++
.../internal/portable/BinaryMetaDataImpl.java | 150 +
.../internal/portable/BinaryObjectEx.java | 245 ++
.../internal/portable/BinaryObjectImpl.java | 606 ++++
.../portable/BinaryObjectOffheapImpl.java | 470 +++
.../internal/portable/BinaryRawReaderEx.java | 33 +
.../internal/portable/BinaryRawWriterEx.java | 60 +
.../internal/portable/BinaryReaderExImpl.java | 2774 +++++++++++++++++
.../internal/portable/BinaryWriterExImpl.java | 1915 ++++++++++++
.../portable/GridPortableMarshaller.java | 32 +-
.../portable/PortableClassDescriptor.java | 146 +-
.../internal/portable/PortableContext.java | 184 +-
.../internal/portable/PortableFieldImpl.java | 104 -
.../portable/PortableMetaDataCollector.java | 263 --
.../portable/PortableMetaDataHandler.java | 12 +-
.../internal/portable/PortableMetaDataImpl.java | 150 -
.../internal/portable/PortableObjectEx.java | 245 --
.../internal/portable/PortableObjectImpl.java | 586 ----
.../portable/PortableObjectOffheapImpl.java | 458 ---
.../internal/portable/PortableRawReaderEx.java | 33 -
.../internal/portable/PortableRawWriterEx.java | 60 -
.../portable/PortableReaderContext.java | 8 +-
.../internal/portable/PortableReaderExImpl.java | 2775 ------------------
.../ignite/internal/portable/PortableUtils.java | 14 +-
.../internal/portable/PortableWriterExImpl.java | 1915 ------------
.../builder/BinaryObjectBuilderImpl.java | 569 ++++
.../portable/builder/PortableBuilderEnum.java | 8 +-
.../portable/builder/PortableBuilderImpl.java | 570 ----
.../portable/builder/PortableBuilderReader.java | 56 +-
.../PortableBuilderSerializationAware.java | 2 +-
.../builder/PortableBuilderSerializer.java | 30 +-
.../builder/PortableEnumArrayLazyValue.java | 12 +-
.../portable/builder/PortableLazyArrayList.java | 2 +-
.../builder/PortableLazyLinkedList.java | 2 +-
.../portable/builder/PortableLazyMap.java | 2 +-
.../portable/builder/PortableLazyMapEntry.java | 2 +-
.../portable/builder/PortableLazySet.java | 4 +-
.../builder/PortableModifiableLazyValue.java | 2 +-
.../builder/PortableObjectArrayLazyValue.java | 8 +-
.../builder/PortablePlainLazyValue.java | 2 +-
.../builder/PortablePlainPortableObject.java | 22 +-
.../portable/builder/PortableValueWithType.java | 8 +-
.../streams/PortableAbstractInputStream.java | 6 +-
.../affinity/GridAffinityAssignmentCache.java | 3 +-
.../affinity/GridAffinityProcessor.java | 5 +-
.../processors/cache/CacheInvokeEntry.java | 11 +-
.../processors/cache/CacheLazyEntry.java | 23 +-
.../internal/processors/cache/CacheObject.java | 11 +-
.../processors/cache/CacheObjectAdapter.java | 2 +-
.../cache/CacheObjectByteArrayImpl.java | 7 +-
.../processors/cache/CacheObjectContext.java | 128 +-
.../processors/cache/CacheObjectImpl.java | 5 +
.../processors/cache/CacheOperationContext.java | 22 +-
.../processors/cache/GridCacheAdapter.java | 98 +-
.../cache/GridCacheConcurrentMap.java | 10 +-
.../processors/cache/GridCacheContext.java | 14 +-
.../processors/cache/GridCacheEntryEx.java | 15 +-
.../processors/cache/GridCacheEventManager.java | 31 +-
.../cache/GridCacheEvictionManager.java | 5 +-
.../processors/cache/GridCacheMapEntry.java | 153 +-
.../processors/cache/GridCacheProxyImpl.java | 4 +-
.../processors/cache/GridCacheReturn.java | 27 +-
.../processors/cache/GridCacheSwapManager.java | 37 +-
.../processors/cache/GridCacheUtils.java | 3 +
.../processors/cache/IgniteCacheProxy.java | 8 +-
.../processors/cache/IgniteInternalCache.java | 6 +-
.../processors/cache/KeyCacheObjectImpl.java | 5 +
.../CacheDataStructuresManager.java | 4 +-
.../GridDistributedCacheAdapter.java | 40 +-
.../distributed/GridDistributedCacheEntry.java | 9 +-
.../distributed/GridDistributedLockRequest.java | 17 +
.../GridDistributedTxRemoteAdapter.java | 3 +
.../distributed/dht/GridDhtCacheEntry.java | 5 +-
.../distributed/dht/GridDhtLocalPartition.java | 3 +-
.../distributed/dht/GridDhtLockFuture.java | 10 +-
.../distributed/dht/GridDhtLockRequest.java | 3 +
.../dht/GridDhtTransactionalCacheAdapter.java | 23 +-
.../distributed/dht/GridDhtTxLocalAdapter.java | 17 +-
.../distributed/dht/GridDhtTxPrepareFuture.java | 15 +-
.../cache/distributed/dht/GridDhtTxRemote.java | 12 +-
.../dht/GridPartitionedGetFuture.java | 6 +-
.../dht/atomic/GridDhtAtomicCache.java | 75 +-
.../dht/atomic/GridDhtAtomicUpdateFuture.java | 6 +-
.../dht/atomic/GridDhtAtomicUpdateRequest.java | 82 +-
.../dht/atomic/GridNearAtomicUpdateFuture.java | 15 +-
.../dht/atomic/GridNearAtomicUpdateRequest.java | 68 +-
.../atomic/GridNearAtomicUpdateResponse.java | 5 +-
.../dht/colocated/GridDhtColocatedCache.java | 29 +-
.../colocated/GridDhtColocatedLockFuture.java | 14 +-
.../dht/preloader/GridDhtForceKeysFuture.java | 2 +-
.../preloader/GridDhtPartitionDemandPool.java | 2 +-
.../distributed/near/GridNearAtomicCache.java | 4 +
.../distributed/near/GridNearCacheEntry.java | 17 +-
.../distributed/near/GridNearGetFuture.java | 47 +-
.../distributed/near/GridNearLockFuture.java | 14 +-
.../distributed/near/GridNearLockRequest.java | 2 +
.../near/GridNearTransactionalCache.java | 8 +-
.../cache/distributed/near/GridNearTxLocal.java | 9 +-
.../distributed/near/GridNearTxRemote.java | 12 +-
.../cache/local/GridLocalCacheEntry.java | 16 +-
.../cache/local/GridLocalLockFuture.java | 3 +-
.../local/atomic/GridLocalAtomicCache.java | 108 +-
.../CacheDefaultPortableAffinityKeyMapper.java | 8 +-
.../portable/CacheObjectBinaryProcessor.java | 103 +
.../CacheObjectBinaryProcessorImpl.java | 1046 +++++++
.../portable/CacheObjectPortableContext.java | 133 -
.../portable/CacheObjectPortableProcessor.java | 103 -
.../CacheObjectPortableProcessorImpl.java | 1043 -------
.../cache/portable/IgniteBinaryImpl.java | 177 ++
.../cache/portable/IgnitePortablesImpl.java | 177 --
.../cache/query/GridCacheQueryManager.java | 13 +-
.../cache/query/GridCacheQueryRequest.java | 4 +-
.../continuous/CacheContinuousQueryEvent.java | 7 +-
.../store/GridCacheStoreManagerAdapter.java | 47 +-
.../transactions/IgniteTransactionsImpl.java | 10 +-
.../cache/transactions/IgniteTxAdapter.java | 5 +-
.../cache/transactions/IgniteTxEntry.java | 54 +-
.../transactions/IgniteTxLocalAdapter.java | 109 +-
.../cache/transactions/IgniteTxLocalEx.java | 1 +
.../cache/transactions/IgniteTxManager.java | 2 +-
.../cacheobject/IgniteCacheObjectProcessor.java | 6 +
.../IgniteCacheObjectProcessorImpl.java | 9 +
.../processors/cacheobject/NoOpBinary.java | 80 +
.../datastreamer/DataStreamProcessor.java | 1 +
.../datastreamer/DataStreamerEntry.java | 6 +-
.../datastreamer/DataStreamerImpl.java | 16 +-
.../datastreamer/DataStreamerRequest.java | 58 +-
.../datastreamer/DataStreamerUpdateJob.java | 10 +-
.../platform/PlatformAbstractTarget.java | 30 +-
.../processors/platform/PlatformContext.java | 26 +-
.../platform/PlatformContextImpl.java | 55 +-
.../platform/PlatformExtendedException.java | 4 +-
.../platform/PlatformProcessorImpl.java | 6 +-
.../platform/cache/PlatformCache.java | 45 +-
.../cache/PlatformCacheEntryFilterImpl.java | 6 +-
.../cache/PlatformCacheEntryProcessorImpl.java | 12 +-
.../platform/cache/PlatformCacheIterator.java | 4 +-
.../PlatformCachePartialUpdateException.java | 4 +-
.../cache/affinity/PlatformAffinity.java | 8 +-
.../query/PlatformAbstractQueryCursor.java | 10 +-
.../PlatformContinuousQueryRemoteFilter.java | 4 +-
.../cache/query/PlatformFieldsQueryCursor.java | 4 +-
.../cache/query/PlatformQueryCursor.java | 4 +-
.../cache/store/PlatformCacheStoreCallback.java | 6 +-
.../platform/cluster/PlatformClusterGroup.java | 12 +-
.../cluster/PlatformClusterNodeFilterImpl.java | 4 +-
.../platform/compute/PlatformAbstractJob.java | 4 +-
.../platform/compute/PlatformAbstractTask.java | 6 +-
.../platform/compute/PlatformClosureJob.java | 4 +-
.../platform/compute/PlatformCompute.java | 26 +-
.../platform/compute/PlatformFullJob.java | 6 +-
.../platform/compute/PlatformFullTask.java | 12 +-
.../datastreamer/PlatformDataStreamer.java | 5 +-
.../PlatformStreamReceiverImpl.java | 4 +-
.../dotnet/PlatformDotNetCacheStore.java | 50 +-
.../PlatformDotNetConfigurationClosure.java | 16 +-
.../events/PlatformEventFilterListenerImpl.java | 6 +-
.../platform/events/PlatformEvents.java | 18 +-
.../messaging/PlatformMessageFilterImpl.java | 6 +-
.../messaging/PlatformMessageLocalFilter.java | 4 +-
.../platform/messaging/PlatformMessaging.java | 8 +-
.../services/PlatformAbstractService.java | 16 +-
.../platform/services/PlatformServices.java | 20 +-
.../transactions/PlatformTransactions.java | 5 +-
.../platform/utils/PlatformFutureUtils.java | 10 +-
.../platform/utils/PlatformReaderBiClosure.java | 4 +-
.../platform/utils/PlatformReaderClosure.java | 4 +-
.../platform/utils/PlatformUtils.java | 60 +-
.../platform/utils/PlatformWriterBiClosure.java | 4 +-
.../platform/utils/PlatformWriterClosure.java | 4 +-
.../processors/query/GridQueryIndexing.java | 18 +-
.../processors/query/GridQueryProcessor.java | 618 ++--
.../client/message/GridClientTaskRequest.java | 6 +-
.../ignite/internal/util/IgniteUtils.java | 9 +-
.../marshaller/portable/PortableMarshaller.java | 42 +-
.../apache/ignite/portable/PortableBuilder.java | 137 -
.../ignite/portable/PortableException.java | 57 -
.../apache/ignite/portable/PortableField.java | 46 -
.../ignite/portable/PortableIdMapper.java | 56 -
.../portable/PortableInvalidClassException.java | 58 -
.../ignite/portable/PortableMarshalAware.java | 48 -
.../ignite/portable/PortableMetadata.java | 61 -
.../apache/ignite/portable/PortableObject.java | 163 -
.../ignite/portable/PortableRawReader.java | 240 --
.../ignite/portable/PortableRawWriter.java | 225 --
.../apache/ignite/portable/PortableReader.java | 291 --
.../ignite/portable/PortableSerializer.java | 49 -
.../portable/PortableTypeConfiguration.java | 177 --
.../apache/ignite/portable/PortableWriter.java | 273 --
.../apache/ignite/portable/package-info.java | 22 -
.../spi/discovery/tcp/TcpDiscoverySpi.java | 2 +
.../apache/ignite/spi/swapspace/SwapKey.java | 9 +-
.../org/apache/ignite/stream/StreamAdapter.java | 3 +-
.../portable/BinaryFieldsAbstractSelfTest.java | 730 +++++
.../portable/BinaryFieldsHeapSelfTest.java | 32 +
.../portable/BinaryFieldsOffheapSelfTest.java | 61 +
...idBinaryObjectBuilderAdditionalSelfTest.java | 1289 ++++++++
.../GridBinaryObjectBuilderSelfTest.java | 1069 +++++++
...tBuilderStringAsCharsAdditionalSelfTest.java | 28 +
...inaryObjectBuilderStringAsCharsSelfTest.java | 28 +
.../GridPortableAffinityKeySelfTest.java | 10 +-
.../GridPortableBuilderAdditionalSelfTest.java | 1289 --------
.../portable/GridPortableBuilderSelfTest.java | 1069 -------
...eBuilderStringAsCharsAdditionalSelfTest.java | 28 -
...ridPortableBuilderStringAsCharsSelfTest.java | 28 -
...idPortableMarshallerCtxDisabledSelfTest.java | 27 +-
.../GridPortableMarshallerSelfTest.java | 478 +--
.../GridPortableMetaDataDisabledSelfTest.java | 64 +-
.../portable/GridPortableMetaDataSelfTest.java | 52 +-
.../portable/GridPortableWildcardsSelfTest.java | 73 +-
.../PortableCompactOffsetsAbstractSelfTest.java | 26 +-
.../PortableCompactOffsetsHeapSelfTest.java | 4 +-
.../PortableCompactOffsetsOffheapSelfTest.java | 4 +-
.../PortableFieldsAbstractSelfTest.java | 729 -----
.../portable/PortableFieldsHeapSelfTest.java | 32 -
.../portable/PortableFieldsOffheapSelfTest.java | 61 -
.../GridBinaryMarshalerAwareTestClass.java | 67 +
.../GridPortableMarshalerAwareTestClass.java | 67 -
.../mutabletest/GridPortableTestClasses.java | 6 +-
.../cache/CacheNearReaderUpdateTest.java | 62 +-
.../cache/GridCacheAbstractSelfTest.java | 9 +-
...heOffHeapTieredEvictionAbstractSelfTest.java | 2 +-
.../processors/cache/GridCacheTestEntryEx.java | 13 +-
.../cache/IgniteCachePeekModesAbstractTest.java | 30 +-
...IgniteCacheAbstractExecutionContextTest.java | 5 +
.../IgniteCacheTxExecutionContextTest.java | 2 +
...tractDistributedByteArrayValuesSelfTest.java | 4 +
...naryObjectsAbstractDataStreamerSelfTest.java | 190 ++
...aryObjectsAbstractMultiThreadedSelfTest.java | 231 ++
.../GridCacheBinaryObjectsAbstractSelfTest.java | 981 +++++++
...ntNodeBinaryObjectMetadataMultinodeTest.java | 295 ++
...CacheClientNodeBinaryObjectMetadataTest.java | 290 ++
...ClientNodePortableMetadataMultinodeTest.java | 295 --
...GridCacheClientNodePortableMetadataTest.java | 286 --
...ableObjectsAbstractDataStreamerSelfTest.java | 190 --
...bleObjectsAbstractMultiThreadedSelfTest.java | 231 --
...ridCachePortableObjectsAbstractSelfTest.java | 978 ------
.../GridCachePortableStoreAbstractSelfTest.java | 4 +-
.../GridCachePortableStoreObjectsSelfTest.java | 2 +-
...GridCachePortableStorePortablesSelfTest.java | 12 +-
...ridPortableCacheEntryMemorySizeSelfTest.java | 11 +-
...leDuplicateIndexObjectsAbstractSelfTest.java | 8 +-
.../DataStreamProcessorPortableSelfTest.java | 11 +-
.../GridDataStreamerImplSelfTest.java | 28 +-
...ridCacheAffinityRoutingPortableSelfTest.java | 10 +-
...rtableDataStreamerMultithreadedSelfTest.java | 4 +-
...tionedOnlyPortableMultithreadedSelfTest.java | 4 +-
...AtomicNearDisabledOffheapTieredSelfTest.java | 29 +
...BinaryObjectsAtomicNearDisabledSelfTest.java | 51 +
...inaryObjectsAtomicOffheapTieredSelfTest.java | 29 +
.../GridCacheBinaryObjectsAtomicSelfTest.java | 51 +
...tionedNearDisabledOffheapTieredSelfTest.java | 30 +
...yObjectsPartitionedNearDisabledSelfTest.java | 51 +
...ObjectsPartitionedOffheapTieredSelfTest.java | 30 +
...idCacheBinaryObjectsPartitionedSelfTest.java | 51 +
...acheOffHeapTieredAtomicPortableSelfTest.java | 2 +-
...eapTieredEvictionAtomicPortableSelfTest.java | 8 +-
...heOffHeapTieredEvictionPortableSelfTest.java | 8 +-
.../GridCacheOffHeapTieredPortableSelfTest.java | 2 +-
...AtomicNearDisabledOffheapTieredSelfTest.java | 29 -
...rtableObjectsAtomicNearDisabledSelfTest.java | 51 -
...tableObjectsAtomicOffheapTieredSelfTest.java | 29 -
.../GridCachePortableObjectsAtomicSelfTest.java | 51 -
...tionedNearDisabledOffheapTieredSelfTest.java | 30 -
...eObjectsPartitionedNearDisabledSelfTest.java | 51 -
...ObjectsPartitionedOffheapTieredSelfTest.java | 30 -
...CachePortableObjectsPartitionedSelfTest.java | 51 -
...ridCacheBinaryObjectsReplicatedSelfTest.java | 51 +
...dCachePortableObjectsReplicatedSelfTest.java | 51 -
...idCacheBinaryObjectsAtomicLocalSelfTest.java | 32 +
...BinaryObjectsLocalOffheapTieredSelfTest.java | 29 +
.../GridCacheBinaryObjectsLocalSelfTest.java | 51 +
...CachePortableObjectsAtomicLocalSelfTest.java | 32 -
...rtableObjectsLocalOffheapTieredSelfTest.java | 29 -
.../GridCachePortableObjectsLocalSelfTest.java | 51 -
.../DataStreamProcessorSelfTest.java | 8 +
.../loadtests/hashmap/GridHashMapLoadTest.java | 3 +-
.../PlatformComputePortableArgTask.java | 8 +-
.../platform/PlatformEventsWriteEventTask.java | 6 +-
.../file/GridFileSwapSpaceSpiSelfTest.java | 11 +-
.../ignite/testframework/junits/IgniteMock.java | 4 +-
.../multijvm/IgniteCacheProcessProxy.java | 4 +-
.../junits/multijvm/IgniteProcessProxy.java | 4 +-
.../IgnitePortableObjectsTestSuite.java | 80 +-
.../processors/query/h2/IgniteH2Indexing.java | 25 +-
.../query/h2/opt/GridH2ValueCacheObject.java | 8 +-
.../query/h2/opt/GridLuceneIndex.java | 4 +-
.../IgniteCacheAbstractFieldsQuerySelfTest.java | 3 +-
...CacheOffheapTieredMultithreadedSelfTest.java | 25 +-
...niteCacheP2pUnmarshallingQueryErrorTest.java | 19 +-
...hePartitionedQueryMultiThreadedSelfTest.java | 22 +-
.../h2/GridIndexingSpiAbstractSelfTest.java | 7 +-
.../Cache/CacheAbstractTest.cs | 2 +-
.../Config/Compute/compute-grid1.xml | 6 +-
.../org/apache/ignite/IgniteSpringBean.java | 4 +-
.../yardstick/cache/model/Organization.java | 14 +-
.../ignite/yardstick/cache/model/Person.java | 14 +-
.../ignite/yardstick/cache/model/SampleKey.java | 14 +-
.../yardstick/cache/model/SampleValue.java | 14 +-
parent/pom.xml | 7 +-
368 files changed, 22090 insertions(+), 20179 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/config/binary/example-ignite-binary.xml
----------------------------------------------------------------------
diff --git a/examples/config/binary/example-ignite-binary.xml b/examples/config/binary/example-ignite-binary.xml
new file mode 100644
index 0000000..cde15ea
--- /dev/null
+++ b/examples/config/binary/example-ignite-binary.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!--
+ Ignite configuration with all defaults and enabled p2p deployment, events and portable marshaller.
+
+ Use this configuration file when running HTTP REST examples (see 'examples/rest' folder).
+
+ When starting a standalone node, you need to execute the following command:
+ {IGNITE_HOME}/bin/ignite.{bat|sh} examples/config/portable/example-ignite-portable.xml
+
+ When starting Ignite from Java IDE, pass path to this file to Ignition:
+ Ignition.start("examples/config/portable/example-ignite-portable.xml");
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+ <!-- Imports default Ignite configuration -->
+ <import resource="../example-default.xml"/>
+
+ <bean parent="ignite.cfg">
+ <!-- Enables portable marshaller -->
+ <property name="marshaller">
+ <bean class="org.apache.ignite.marshaller.portable.PortableMarshaller"/>
+ </property>
+ </bean>
+</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/config/portable/example-ignite-portable.xml
----------------------------------------------------------------------
diff --git a/examples/config/portable/example-ignite-portable.xml b/examples/config/portable/example-ignite-portable.xml
deleted file mode 100644
index cde15ea..0000000
--- a/examples/config/portable/example-ignite-portable.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
- 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.
--->
-
-<!--
- Ignite configuration with all defaults and enabled p2p deployment, events and portable marshaller.
-
- Use this configuration file when running HTTP REST examples (see 'examples/rest' folder).
-
- When starting a standalone node, you need to execute the following command:
- {IGNITE_HOME}/bin/ignite.{bat|sh} examples/config/portable/example-ignite-portable.xml
-
- When starting Ignite from Java IDE, pass path to this file to Ignition:
- Ignition.start("examples/config/portable/example-ignite-portable.xml");
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd">
- <!-- Imports default Ignite configuration -->
- <import resource="../example-default.xml"/>
-
- <bean parent="ignite.cfg">
- <!-- Enables portable marshaller -->
- <property name="marshaller">
- <bean class="org.apache.ignite.marshaller.portable.PortableMarshaller"/>
- </property>
- </bean>
-</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/Address.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/Address.java b/examples/src/main/java/org/apache/ignite/examples/binary/Address.java
new file mode 100644
index 0000000..76d8774
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/Address.java
@@ -0,0 +1,72 @@
+/*
+ * 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.examples.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+
+/**
+ * Employee address.
+ * <p>
+ * This class implements {@link org.apache.ignite.binary.Binarylizable} only for example purposes,
+ * in order to show how to customize serialization and deserialization of
+ * binary objects.
+ */
+public class Address implements Binarylizable {
+ /** Street. */
+ private String street;
+
+ /** ZIP code. */
+ private int zip;
+
+ /**
+ * Required for binary deserialization.
+ */
+ public Address() {
+ // No-op.
+ }
+
+ /**
+ * @param street Street.
+ * @param zip ZIP code.
+ */
+ public Address(String street, int zip) {
+ this.street = street;
+ this.zip = zip;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+ writer.writeString("street", street);
+ writer.writeInt("zip", zip);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+ street = reader.readString("street");
+ zip = reader.readInt("zip");
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Address [street=" + street +
+ ", zip=" + zip + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/Employee.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/Employee.java b/examples/src/main/java/org/apache/ignite/examples/binary/Employee.java
new file mode 100644
index 0000000..744b44f
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/Employee.java
@@ -0,0 +1,93 @@
+/*
+ * 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.examples.binary;
+
+import java.util.Collection;
+
+/**
+ * This class represents employee object.
+ */
+public class Employee {
+ /** Name. */
+ private String name;
+
+ /** Salary. */
+ private long salary;
+
+ /** Address. */
+ private Address address;
+
+ /** Departments. */
+ private Collection<String> departments;
+
+ /**
+ * Required for binary deserialization.
+ */
+ public Employee() {
+ // No-op.
+ }
+
+ /**
+ * @param name Name.
+ * @param salary Salary.
+ * @param address Address.
+ * @param departments Departments.
+ */
+ public Employee(String name, long salary, Address address, Collection<String> departments) {
+ this.name = name;
+ this.salary = salary;
+ this.address = address;
+ this.departments = departments;
+ }
+
+ /**
+ * @return Name.
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * @return Salary.
+ */
+ public long salary() {
+ return salary;
+ }
+
+ /**
+ * @return Address.
+ */
+ public Address address() {
+ return address;
+ }
+
+ /**
+ * @return Departments.
+ */
+ public Collection<String> departments() {
+ return departments;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Employee [name=" + name +
+ ", salary=" + salary +
+ ", address=" + address +
+ ", departments=" + departments + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java b/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.java
new file mode 100644
index 0000000..2794230
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/EmployeeKey.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.examples.binary;
+
+/**
+ * This class represents key for employee object.
+ * <p>
+ * Used in query example to collocate employees
+ * with their organizations.
+ */
+public class EmployeeKey {
+ /** ID. */
+ private int id;
+
+ /** Organization ID. */
+ private int organizationId;
+
+ /**
+ * Required for binary deserialization.
+ */
+ public EmployeeKey() {
+ // No-op.
+ }
+
+ /**
+ * @param id ID.
+ * @param organizationId Organization ID.
+ */
+ public EmployeeKey(int id, int organizationId) {
+ this.id = id;
+ this.organizationId = organizationId;
+ }
+
+ /**
+ * @return ID.
+ */
+ public int id() {
+ return id;
+ }
+
+ /**
+ * @return Organization ID.
+ */
+ public int organizationId() {
+ return organizationId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ EmployeeKey key = (EmployeeKey)o;
+
+ return id == key.id && organizationId == key.organizationId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ int res = id;
+
+ res = 31 * res + organizationId;
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "EmployeeKey [id=" + id +
+ ", organizationId=" + organizationId + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/ExampleBinaryNodeStartup.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/ExampleBinaryNodeStartup.java b/examples/src/main/java/org/apache/ignite/examples/binary/ExampleBinaryNodeStartup.java
new file mode 100644
index 0000000..30a015b
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/ExampleBinaryNodeStartup.java
@@ -0,0 +1,36 @@
+/*
+ * 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.examples.binary;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.Ignition;
+
+/**
+ * Starts up an empty node with example configuration and binary marshaller enabled.
+ */
+public class ExampleBinaryNodeStartup {
+ /**
+ * Start up an empty node with example configuration and binary marshaller enabled.
+ *
+ * @param args Command line arguments, none required.
+ * @throws IgniteException If failed.
+ */
+ public static void main(String[] args) throws IgniteException {
+ Ignition.start("examples/config/binary/example-ignite-binary.xml");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/Organization.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/Organization.java b/examples/src/main/java/org/apache/ignite/examples/binary/Organization.java
new file mode 100644
index 0000000..b42bb27
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/Organization.java
@@ -0,0 +1,93 @@
+/*
+ * 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.examples.binary;
+
+import java.sql.Timestamp;
+
+/**
+ * This class represents organization object.
+ */
+public class Organization {
+ /** Name. */
+ private String name;
+
+ /** Address. */
+ private Address address;
+
+ /** Type. */
+ private OrganizationType type;
+
+ /** Last update time. */
+ private Timestamp lastUpdated;
+
+ /**
+ * Required for binary deserialization.
+ */
+ public Organization() {
+ // No-op.
+ }
+
+ /**
+ * @param name Name.
+ * @param address Address.
+ * @param type Type.
+ * @param lastUpdated Last update time.
+ */
+ public Organization(String name, Address address, OrganizationType type, Timestamp lastUpdated) {
+ this.name = name;
+ this.address = address;
+ this.type = type;
+ this.lastUpdated = lastUpdated;
+ }
+
+ /**
+ * @return Name.
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * @return Address.
+ */
+ public Address address() {
+ return address;
+ }
+
+ /**
+ * @return Type.
+ */
+ public OrganizationType type() {
+ return type;
+ }
+
+ /**
+ * @return Last update time.
+ */
+ public Timestamp lastUpdated() {
+ return lastUpdated;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Organization [name=" + name +
+ ", address=" + address +
+ ", type=" + type +
+ ", lastUpdated=" + lastUpdated + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/OrganizationType.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/OrganizationType.java b/examples/src/main/java/org/apache/ignite/examples/binary/OrganizationType.java
new file mode 100644
index 0000000..6548210
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/OrganizationType.java
@@ -0,0 +1,32 @@
+/*
+ * 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.examples.binary;
+
+/**
+ * Organization type enum.
+ */
+public enum OrganizationType {
+ /** Non-profit organization. */
+ NON_PROFIT,
+
+ /** Private organization. */
+ PRIVATE,
+
+ /** Government organization. */
+ GOVERNMENT
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientBinaryTaskExecutionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientBinaryTaskExecutionExample.java b/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientBinaryTaskExecutionExample.java
new file mode 100644
index 0000000..ae5d169
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientBinaryTaskExecutionExample.java
@@ -0,0 +1,153 @@
+/*
+ * 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.examples.binary.computegrid;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.examples.binary.Address;
+import org.apache.ignite.examples.binary.Employee;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ * This example demonstrates use of binary objects with task execution.
+ * Specifically it shows that binary objects are simple Java POJOs and do not require any special treatment.
+ * <p>
+ * The example executes map-reduce task that accepts collection of binary objects as an argument.
+ * Since these objects are never deserialized on remote nodes, classes are not required on classpath
+ * of these nodes.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables the binary marshaller: {@code 'ignite.{sh|bat} examples/config/binary/example-ignite-binary.xml'}.
+ * <p>
+ * Alternatively you can run {@link org.apache.ignite.examples.binary.ExampleBinaryNodeStartup} in another JVM which will
+ * start node with {@code examples/config/binary/example-ignite-binary.xml} configuration.
+ */
+public class ComputeClientBinaryTaskExecutionExample {
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ try (Ignite ignite = Ignition.start("examples/config/binary/example-ignite-binary.xml")) {
+ System.out.println();
+ System.out.println(">>> Binary objects task execution example started.");
+
+ if (ignite.cluster().forRemotes().nodes().isEmpty()) {
+ System.out.println();
+ System.out.println(">>> This example requires remote nodes to be started.");
+ System.out.println(">>> Please start at least 1 remote node.");
+ System.out.println(">>> Refer to example's javadoc for details on configuration.");
+ System.out.println();
+
+ return;
+ }
+
+ // Generate employees to calculate average salary for.
+ Collection<Employee> employees = employees();
+
+ System.out.println();
+ System.out.println(">>> Calculating average salary for employees:");
+
+ for (Employee employee : employees)
+ System.out.println(">>> " + employee);
+
+ // Convert collection of employees to collection of binary objects.
+ // This allows to send objects across nodes without requiring to have
+ // Employee class on classpath of these nodes.
+ Collection<BinaryObject> binaries = ignite.binary().toBinary(employees);
+
+ // Execute task and get average salary.
+ Long avgSalary = ignite.compute(ignite.cluster().forRemotes()).execute(new ComputeClientTask(), binaries);
+
+ System.out.println();
+ System.out.println(">>> Average salary for all employees: " + avgSalary);
+ System.out.println();
+ }
+ }
+
+ /**
+ * Creates collection of employees.
+ *
+ * @return Collection of employees.
+ */
+ private static Collection<Employee> employees() {
+ Collection<Employee> employees = new ArrayList<>();
+
+ employees.add(new Employee(
+ "James Wilson",
+ 12500,
+ new Address("1096 Eddy Street, San Francisco, CA", 94109),
+ Arrays.asList("Human Resources", "Customer Service")
+ ));
+
+ employees.add(new Employee(
+ "Daniel Adams",
+ 11000,
+ new Address("184 Fidler Drive, San Antonio, TX", 78205),
+ Arrays.asList("Development", "QA")
+ ));
+
+ employees.add(new Employee(
+ "Cristian Moss",
+ 12500,
+ new Address("667 Jerry Dove Drive, Florence, SC", 29501),
+ Arrays.asList("Logistics")
+ ));
+
+ employees.add(new Employee(
+ "Allison Mathis",
+ 25300,
+ new Address("2702 Freedom Lane, Hornitos, CA", 95325),
+ Arrays.asList("Development")
+ ));
+
+ employees.add(new Employee(
+ "Breana Robbin",
+ 6500,
+ new Address("3960 Sundown Lane, Austin, TX", 78758),
+ Arrays.asList("Sales")
+ ));
+
+ employees.add(new Employee(
+ "Philip Horsley",
+ 19800,
+ new Address("2803 Elsie Drive, Sioux Falls, SD", 57104),
+ Arrays.asList("Sales")
+ ));
+
+ employees.add(new Employee(
+ "Brian Peters",
+ 10600,
+ new Address("1407 Pearlman Avenue, Boston, MA", 12110),
+ Arrays.asList("Development", "QA")
+ ));
+
+ employees.add(new Employee(
+ "Jack Yang",
+ 12900,
+ new Address("4425 Parrish Avenue Smithsons Valley, TX", 78130),
+ Arrays.asList("Sales")
+ ));
+
+ return employees;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientTask.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientTask.java b/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientTask.java
new file mode 100644
index 0000000..36d6734
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/ComputeClientTask.java
@@ -0,0 +1,116 @@
+/*
+ * 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.examples.binary.computegrid;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeTaskSplitAdapter;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.binary.BinaryObject;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Task that is used for {@link ComputeClientBinaryTaskExecutionExample} and
+ * similar examples in .NET and C++.
+ * <p>
+ * This task calculates average salary for provided collection of employees.
+ * It splits the collection into batches of size {@code 3} and creates a job
+ * for each batch. After all jobs are executed, there results are reduced to
+ * get the average salary.
+ */
+public class ComputeClientTask extends ComputeTaskSplitAdapter<Collection<BinaryObject>, Long> {
+ /** {@inheritDoc} */
+ @Override protected Collection<? extends ComputeJob> split(
+ int gridSize,
+ Collection<BinaryObject> arg
+ ) {
+ Collection<ComputeClientJob> jobs = new ArrayList<>();
+
+ Collection<BinaryObject> employees = new ArrayList<>();
+
+ // Split provided collection into batches and
+ // create a job for each batch.
+ for (BinaryObject employee : arg) {
+ employees.add(employee);
+
+ if (employees.size() == 3) {
+ jobs.add(new ComputeClientJob(employees));
+
+ employees = new ArrayList<>(3);
+ }
+ }
+
+ if (!employees.isEmpty())
+ jobs.add(new ComputeClientJob(employees));
+
+ return jobs;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Long reduce(List<ComputeJobResult> results) {
+ long sum = 0;
+ int cnt = 0;
+
+ for (ComputeJobResult res : results) {
+ IgniteBiTuple<Long, Integer> t = res.getData();
+
+ sum += t.get1();
+ cnt += t.get2();
+ }
+
+ return sum / cnt;
+ }
+
+ /**
+ * Remote job for {@link ComputeClientTask}.
+ */
+ private static class ComputeClientJob extends ComputeJobAdapter {
+ /** Collection of employees. */
+ private final Collection<BinaryObject> employees;
+
+ /**
+ * @param employees Collection of employees.
+ */
+ private ComputeClientJob(Collection<BinaryObject> employees) {
+ this.employees = employees;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Object execute() {
+ long sum = 0;
+ int cnt = 0;
+
+ for (BinaryObject employee : employees) {
+ System.out.println(">>> Processing employee: " + employee.field("name"));
+
+ // Get salary from binary object. Note that object
+ // doesn't need to be fully deserialized.
+ long salary = employee.field("salary");
+
+ sum += salary;
+ cnt++;
+ }
+
+ return new IgniteBiTuple<>(sum, cnt);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/package-info.java b/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/package-info.java
new file mode 100644
index 0000000..e5e9d7f
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/computegrid/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Demonstrates the usage of binary objects with task execution.
+ */
+package org.apache.ignite.examples.binary.computegrid;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryPutGetExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryPutGetExample.java b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryPutGetExample.java
new file mode 100644
index 0000000..bb88ee0
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryPutGetExample.java
@@ -0,0 +1,230 @@
+/*
+ * 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.examples.binary.datagrid;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.examples.binary.Address;
+import org.apache.ignite.examples.binary.Organization;
+import org.apache.ignite.examples.binary.OrganizationType;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ * This example demonstrates use of binary objects with Ignite cache.
+ * Specifically it shows that binary objects are simple Java POJOs and do not require any special treatment.
+ * <p>
+ * The example executes several put-get operations on Ignite cache with binary values. Note that
+ * it demonstrates how binary object can be retrieved in fully-deserialized form or in binary object
+ * format using special cache projection.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables the binary marshaller: {@code 'ignite.{sh|bat} examples/config/binary/example-ignite-binary.xml'}.
+ * <p>
+ * Alternatively you can run {@link org.apache.ignite.examples.binary.ExampleBinaryNodeStartup} in another JVM which will
+ * start node with {@code examples/config/binary/example-ignite-binary.xml} configuration.
+ */
+@SuppressWarnings("TypeMayBeWeakened")
+public class CacheClientBinaryPutGetExample {
+ /** Cache name. */
+ private static final String CACHE_NAME = CacheClientBinaryPutGetExample.class.getSimpleName();
+
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ try (Ignite ignite = Ignition.start("examples/config/binary/example-ignite-binary.xml")) {
+ System.out.println();
+ System.out.println(">>> Binary objects cache put-get example started.");
+
+ CacheConfiguration<Integer, Organization> cfg = new CacheConfiguration<>();
+
+ cfg.setCacheMode(CacheMode.PARTITIONED);
+ cfg.setName(CACHE_NAME);
+ cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+
+ try (IgniteCache<Integer, Organization> cache = ignite.createCache(cfg)) {
+ if (ignite.cluster().forDataNodes(cache.getName()).nodes().isEmpty()) {
+ System.out.println();
+ System.out.println(">>> This example requires remote cache node nodes to be started.");
+ System.out.println(">>> Please start at least 1 remote cache node.");
+ System.out.println(">>> Refer to example's javadoc for details on configuration.");
+ System.out.println();
+
+ return;
+ }
+
+ putGet(cache);
+ putGetBinary(cache);
+ putGetAll(cache);
+ putGetAllBinary(cache);
+
+ System.out.println();
+ }
+ finally {
+ // Delete cache with its content completely.
+ ignite.destroyCache(CACHE_NAME);
+ }
+ }
+ }
+
+ /**
+ * Execute individual put and get.
+ *
+ * @param cache Cache.
+ */
+ private static void putGet(IgniteCache<Integer, Organization> cache) {
+ // Create new Organization binary object to store in cache.
+ Organization org = new Organization(
+ "Microsoft", // Name.
+ new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
+ OrganizationType.PRIVATE, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ // Put created data entry to cache.
+ cache.put(1, org);
+
+ // Get recently created organization as a strongly-typed fully de-serialized instance.
+ Organization orgFromCache = cache.get(1);
+
+ System.out.println();
+ System.out.println(">>> Retrieved organization instance from cache: " + orgFromCache);
+ }
+
+ /**
+ * Execute individual put and get, getting value in binary format, without de-serializing it.
+ *
+ * @param cache Cache.
+ */
+ private static void putGetBinary(IgniteCache<Integer, Organization> cache) {
+ // Create new Organization binary object to store in cache.
+ Organization org = new Organization(
+ "Microsoft", // Name.
+ new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
+ OrganizationType.PRIVATE, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ // Put created data entry to cache.
+ cache.put(1, org);
+
+ // Get cache that will get values as binary objects.
+ IgniteCache<Integer, BinaryObject> binaryCache = cache.withKeepBinary();
+
+ // Get recently created organization as a binary object.
+ BinaryObject po = binaryCache.get(1);
+
+ // Get organization's name from binary object (note that
+ // object doesn't need to be fully deserialized).
+ String name = po.field("name");
+
+ System.out.println();
+ System.out.println(">>> Retrieved organization name from binary object: " + name);
+ }
+
+ /**
+ * Execute bulk {@code putAll(...)} and {@code getAll(...)} operations.
+ *
+ * @param cache Cache.
+ */
+ private static void putGetAll(IgniteCache<Integer, Organization> cache) {
+ // Create new Organization binary objects to store in cache.
+ Organization org1 = new Organization(
+ "Microsoft", // Name.
+ new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
+ OrganizationType.PRIVATE, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ Organization org2 = new Organization(
+ "Red Cross", // Name.
+ new Address("184 Fidler Drive, San Antonio, TX", 78205), // Address.
+ OrganizationType.NON_PROFIT, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ Map<Integer, Organization> map = new HashMap<>();
+
+ map.put(1, org1);
+ map.put(2, org2);
+
+ // Put created data entries to cache.
+ cache.putAll(map);
+
+ // Get recently created organizations as a strongly-typed fully de-serialized instances.
+ Map<Integer, Organization> mapFromCache = cache.getAll(map.keySet());
+
+ System.out.println();
+ System.out.println(">>> Retrieved organization instances from cache:");
+
+ for (Organization org : mapFromCache.values())
+ System.out.println(">>> " + org);
+ }
+
+ /**
+ * Execute bulk {@code putAll(...)} and {@code getAll(...)} operations,
+ * getting values in binary format, without de-serializing it.
+ *
+ * @param cache Cache.
+ */
+ private static void putGetAllBinary(IgniteCache<Integer, Organization> cache) {
+ // Create new Organization binary objects to store in cache.
+ Organization org1 = new Organization(
+ "Microsoft", // Name.
+ new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
+ OrganizationType.PRIVATE, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ Organization org2 = new Organization(
+ "Red Cross", // Name.
+ new Address("184 Fidler Drive, San Antonio, TX", 78205), // Address.
+ OrganizationType.NON_PROFIT, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ Map<Integer, Organization> map = new HashMap<>();
+
+ map.put(1, org1);
+ map.put(2, org2);
+
+ // Put created data entries to cache.
+ cache.putAll(map);
+
+ // Get cache that will get values as binary objects.
+ IgniteCache<Integer, BinaryObject> binaryCache = cache.withKeepBinary();
+
+ // Get recently created organizations as binary objects.
+ Map<Integer, BinaryObject> poMap = binaryCache.getAll(map.keySet());
+
+ Collection<String> names = new ArrayList<>();
+
+ // Get organizations' names from binary objects (note that
+ // objects don't need to be fully deserialized).
+ for (BinaryObject po : poMap.values())
+ names.add(po.<String>field("name"));
+
+ System.out.println();
+ System.out.println(">>> Retrieved organization names from binary objects: " + names);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java
new file mode 100644
index 0000000..c93848c
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/CacheClientBinaryQueryExample.java
@@ -0,0 +1,330 @@
+/*
+ * 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.examples.binary.datagrid;
+
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import javax.cache.Cache;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.QueryIndexType;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.TextQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.examples.binary.Address;
+import org.apache.ignite.examples.binary.Employee;
+import org.apache.ignite.examples.binary.EmployeeKey;
+import org.apache.ignite.examples.binary.Organization;
+import org.apache.ignite.examples.binary.OrganizationType;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ * This example demonstrates use of binary objects with cache queries.
+ * The example populates cache with sample data and runs several SQL and full text queries over this data.
+ * <p>
+ * Remote nodes should always be started with {@link org.apache.ignite.examples.binary.ExampleBinaryNodeStartup} which starts a node with
+ * {@code examples/config/binary/example-ignite-binary.xml} configuration.
+ */
+public class CacheClientBinaryQueryExample {
+ /** Organization cache name. */
+ private static final String ORGANIZATION_CACHE_NAME = CacheClientBinaryQueryExample.class.getSimpleName()
+ + "Organizations";
+
+ /** Employee cache name. */
+ private static final String EMPLOYEE_CACHE_NAME = CacheClientBinaryQueryExample.class.getSimpleName()
+ + "Employees";
+
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ try (Ignite ignite = Ignition.start("examples/config/binary/example-ignite-binary.xml")) {
+ System.out.println();
+ System.out.println(">>> Binary objects cache query example started.");
+
+ CacheConfiguration<Integer, Organization> orgCacheCfg = new CacheConfiguration<>();
+
+ orgCacheCfg.setCacheMode(CacheMode.PARTITIONED);
+ orgCacheCfg.setName(ORGANIZATION_CACHE_NAME);
+
+ orgCacheCfg.setQueryEntities(Arrays.asList(createOrganizationQueryEntity()));
+
+ CacheConfiguration<EmployeeKey, Employee> employeeCacheCfg = new CacheConfiguration<>();
+
+ employeeCacheCfg.setCacheMode(CacheMode.PARTITIONED);
+ employeeCacheCfg.setName(EMPLOYEE_CACHE_NAME);
+
+ employeeCacheCfg.setQueryEntities(Arrays.asList(createEmployeeQueryEntity()));
+
+ try (IgniteCache<Integer, Organization> orgCache = ignite.createCache(orgCacheCfg);
+ IgniteCache<EmployeeKey, Employee> employeeCache = ignite.createCache(employeeCacheCfg)
+ ) {
+ if (ignite.cluster().forDataNodes(orgCache.getName()).nodes().isEmpty()) {
+ System.out.println();
+ System.out.println(">>> This example requires remote cache nodes to be started.");
+ System.out.println(">>> Please start at least 1 remote cache node.");
+ System.out.println(">>> Refer to example's javadoc for details on configuration.");
+ System.out.println();
+
+ return;
+ }
+
+ // Populate cache with sample data entries.
+ populateCache(orgCache, employeeCache);
+
+ // Get cache that will work with binary objects.
+ IgniteCache<BinaryObject, BinaryObject> binaryCache = employeeCache.withKeepBinary();
+
+ // Run SQL query example.
+ sqlQuery(binaryCache);
+
+ // Run SQL query with join example.
+ sqlJoinQuery(binaryCache);
+
+ // Run SQL fields query example.
+ sqlFieldsQuery(binaryCache);
+
+ // Run full text query example.
+ textQuery(binaryCache);
+
+ System.out.println();
+ }
+ finally {
+ // Delete caches with their content completely.
+ ignite.destroyCache(ORGANIZATION_CACHE_NAME);
+ ignite.destroyCache(EMPLOYEE_CACHE_NAME);
+ }
+ }
+ }
+
+ /**
+ * Create cache type metadata for {@link Employee}.
+ *
+ * @return Cache type metadata.
+ */
+ private static QueryEntity createEmployeeQueryEntity() {
+ QueryEntity employeeEntity = new QueryEntity();
+
+ employeeEntity.setValueType(Employee.class.getName());
+ employeeEntity.setKeyType(EmployeeKey.class.getName());
+
+ LinkedHashMap<String, String> fields = new LinkedHashMap<>();
+
+ fields.put("name", String.class.getName());
+ fields.put("salary", Long.class.getName());
+ fields.put("address.zip", Integer.class.getName());
+ fields.put("organizationId", Integer.class.getName());
+ fields.put("address.street", Integer.class.getName());
+
+ employeeEntity.setFields(fields);
+
+ employeeEntity.setIndexes(Arrays.asList(
+ new QueryIndex("name"),
+ new QueryIndex("salary"),
+ new QueryIndex("zip"),
+ new QueryIndex("organizationId"),
+ new QueryIndex("street", QueryIndexType.FULLTEXT)
+ ));
+
+ return employeeEntity;
+ }
+
+ /**
+ * Create cache type metadata for {@link Organization}.
+ *
+ * @return Cache type metadata.
+ */
+ private static QueryEntity createOrganizationQueryEntity() {
+ QueryEntity organizationEntity = new QueryEntity();
+
+ organizationEntity.setValueType(Organization.class.getName());
+ organizationEntity.setKeyType(Integer.class.getName());
+
+ LinkedHashMap<String, String> fields = new LinkedHashMap<>();
+
+ fields.put("name", String.class.getName());
+ fields.put("address.street", String.class.getName());
+
+ organizationEntity.setFields(fields);
+
+ organizationEntity.setIndexes(Arrays.asList(
+ new QueryIndex("name")
+ ));
+
+ return organizationEntity;
+ }
+
+ /**
+ * Queries employees that have provided ZIP code in address.
+ *
+ * @param cache Ignite cache.
+ */
+ private static void sqlQuery(IgniteCache<BinaryObject, BinaryObject> cache) {
+ SqlQuery<BinaryObject, BinaryObject> query = new SqlQuery<>(Employee.class, "zip = ?");
+
+ int zip = 94109;
+
+ QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> employees = cache.query(query.setArgs(zip));
+
+ System.out.println();
+ System.out.println(">>> Employees with zip " + zip + ':');
+
+ for (Cache.Entry<BinaryObject, BinaryObject> e : employees.getAll())
+ System.out.println(">>> " + e.getValue().deserialize());
+ }
+
+ /**
+ * Queries employees that work for organization with provided name.
+ *
+ * @param cache Ignite cache.
+ */
+ private static void sqlJoinQuery(IgniteCache<BinaryObject, BinaryObject> cache) {
+ SqlQuery<BinaryObject, BinaryObject> query = new SqlQuery<>(Employee.class,
+ "from Employee, \"" + ORGANIZATION_CACHE_NAME + "\".Organization as org " +
+ "where Employee.organizationId = org._key and org.name = ?");
+
+ String organizationName = "GridGain";
+
+ QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> employees =
+ cache.query(query.setArgs(organizationName));
+
+ System.out.println();
+ System.out.println(">>> Employees working for " + organizationName + ':');
+
+ for (Cache.Entry<BinaryObject, BinaryObject> e : employees.getAll())
+ System.out.println(">>> " + e.getValue());
+ }
+
+ /**
+ * Queries names and salaries for all employees.
+ *
+ * @param cache Ignite cache.
+ */
+ private static void sqlFieldsQuery(IgniteCache<BinaryObject, BinaryObject> cache) {
+ SqlFieldsQuery query = new SqlFieldsQuery("select name, salary from Employee");
+
+ QueryCursor<List<?>> employees = cache.query(query);
+
+ System.out.println();
+ System.out.println(">>> Employee names and their salaries:");
+
+ for (List<?> row : employees.getAll())
+ System.out.println(">>> [Name=" + row.get(0) + ", salary=" + row.get(1) + ']');
+ }
+
+ /**
+ * Queries employees that live in Texas using full-text query API.
+ *
+ * @param cache Ignite cache.
+ */
+ private static void textQuery(IgniteCache<BinaryObject, BinaryObject> cache) {
+ TextQuery<BinaryObject, BinaryObject> query = new TextQuery<>(Employee.class, "TX");
+
+ QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> employees = cache.query(query);
+
+ System.out.println();
+ System.out.println(">>> Employees living in Texas:");
+
+ for (Cache.Entry<BinaryObject, BinaryObject> e : employees.getAll())
+ System.out.println(">>> " + e.getValue().deserialize());
+ }
+
+ /**
+ * Populates cache with data.
+ *
+ * @param orgCache Organization cache.
+ * @param employeeCache Employee cache.
+ */
+ @SuppressWarnings("TypeMayBeWeakened")
+ private static void populateCache(IgniteCache<Integer, Organization> orgCache,
+ IgniteCache<EmployeeKey, Employee> employeeCache) {
+ orgCache.put(1, new Organization(
+ "GridGain",
+ new Address("1065 East Hillsdale Blvd, Foster City, CA", 94404),
+ OrganizationType.PRIVATE,
+ new Timestamp(System.currentTimeMillis())
+ ));
+
+ orgCache.put(2, new Organization(
+ "Microsoft",
+ new Address("1096 Eddy Street, San Francisco, CA", 94109),
+ OrganizationType.PRIVATE,
+ new Timestamp(System.currentTimeMillis())
+ ));
+
+ employeeCache.put(new EmployeeKey(1, 1), new Employee(
+ "James Wilson",
+ 12500,
+ new Address("1096 Eddy Street, San Francisco, CA", 94109),
+ Arrays.asList("Human Resources", "Customer Service")
+ ));
+
+ employeeCache.put(new EmployeeKey(2, 1), new Employee(
+ "Daniel Adams",
+ 11000,
+ new Address("184 Fidler Drive, San Antonio, TX", 78130),
+ Arrays.asList("Development", "QA")
+ ));
+
+ employeeCache.put(new EmployeeKey(3, 1), new Employee(
+ "Cristian Moss",
+ 12500,
+ new Address("667 Jerry Dove Drive, Florence, SC", 29501),
+ Arrays.asList("Logistics")
+ ));
+
+ employeeCache.put(new EmployeeKey(4, 2), new Employee(
+ "Allison Mathis",
+ 25300,
+ new Address("2702 Freedom Lane, San Francisco, CA", 94109),
+ Arrays.asList("Development")
+ ));
+
+ employeeCache.put(new EmployeeKey(5, 2), new Employee(
+ "Breana Robbin",
+ 6500,
+ new Address("3960 Sundown Lane, Austin, TX", 78130),
+ Arrays.asList("Sales")
+ ));
+
+ employeeCache.put(new EmployeeKey(6, 2), new Employee(
+ "Philip Horsley",
+ 19800,
+ new Address("2803 Elsie Drive, Sioux Falls, SD", 57104),
+ Arrays.asList("Sales")
+ ));
+
+ employeeCache.put(new EmployeeKey(7, 2), new Employee(
+ "Brian Peters",
+ 10600,
+ new Address("1407 Pearlman Avenue, Boston, MA", 12110),
+ Arrays.asList("Development", "QA")
+ ));
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/package-info.java b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/package-info.java
new file mode 100644
index 0000000..da65bf6
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/datagrid/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Demonstrates the usage of binary objects with cache.
+ */
+package org.apache.ignite.examples.binary.datagrid;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/binary/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/binary/package-info.java b/examples/src/main/java/org/apache/ignite/examples/binary/package-info.java
new file mode 100644
index 0000000..17bdbb5
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/binary/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Contains Ignite Binary objects classes and examples.
+ */
+package org.apache.ignite.examples.binary;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/Address.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/Address.java b/examples/src/main/java/org/apache/ignite/examples/portable/Address.java
deleted file mode 100644
index cb08b25..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/Address.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.examples.portable;
-
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
-
-/**
- * Employee address.
- * <p>
- * This class implements {@link PortableMarshalAware} only for example purposes,
- * in order to show how to customize serialization and deserialization of
- * portable objects.
- */
-public class Address implements PortableMarshalAware {
- /** Street. */
- private String street;
-
- /** ZIP code. */
- private int zip;
-
- /**
- * Required for portable deserialization.
- */
- public Address() {
- // No-op.
- }
-
- /**
- * @param street Street.
- * @param zip ZIP code.
- */
- public Address(String street, int zip) {
- this.street = street;
- this.zip = zip;
- }
-
- /** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
- writer.writeString("street", street);
- writer.writeInt("zip", zip);
- }
-
- /** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
- street = reader.readString("street");
- zip = reader.readInt("zip");
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "Address [street=" + street +
- ", zip=" + zip + ']';
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/Employee.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/Employee.java b/examples/src/main/java/org/apache/ignite/examples/portable/Employee.java
deleted file mode 100644
index 9614168..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/Employee.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.examples.portable;
-
-import java.util.Collection;
-
-/**
- * This class represents employee object.
- */
-public class Employee {
- /** Name. */
- private String name;
-
- /** Salary. */
- private long salary;
-
- /** Address. */
- private Address address;
-
- /** Departments. */
- private Collection<String> departments;
-
- /**
- * Required for portable deserialization.
- */
- public Employee() {
- // No-op.
- }
-
- /**
- * @param name Name.
- * @param salary Salary.
- * @param address Address.
- * @param departments Departments.
- */
- public Employee(String name, long salary, Address address, Collection<String> departments) {
- this.name = name;
- this.salary = salary;
- this.address = address;
- this.departments = departments;
- }
-
- /**
- * @return Name.
- */
- public String name() {
- return name;
- }
-
- /**
- * @return Salary.
- */
- public long salary() {
- return salary;
- }
-
- /**
- * @return Address.
- */
- public Address address() {
- return address;
- }
-
- /**
- * @return Departments.
- */
- public Collection<String> departments() {
- return departments;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "Employee [name=" + name +
- ", salary=" + salary +
- ", address=" + address +
- ", departments=" + departments + ']';
- }
-}
[23/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/Binarylizable.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/Binarylizable.java b/modules/core/src/main/java/org/apache/ignite/binary/Binarylizable.java
new file mode 100644
index 0000000..d09ffc8
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/Binarylizable.java
@@ -0,0 +1,48 @@
+/*
+ * 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.binary;
+
+/**
+ * Interface that allows to implement custom serialization
+ * logic for binary objects. IgniteObject is not required
+ * to implement this interface, in which case Ignite will automatically
+ * serialize binary objects using reflection.
+ * <p>
+ * This interface, in a way, is analogous to {@link java.io.Externalizable}
+ * interface, which allows users to override default serialization logic,
+ * usually for performance reasons. The only difference here is that binary
+ * serialization is already very fast and implementing custom serialization
+ * logic for binary does not provide significant performance gains.
+ */
+public interface Binarylizable {
+ /**
+ * Writes fields to provided writer.
+ *
+ * @param writer Binary object writer.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeBinary(BinaryWriter writer) throws BinaryObjectException;
+
+ /**
+ * Reads fields from provided reader.
+ *
+ * @param reader Binary object reader.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void readBinary(BinaryReader reader) throws BinaryObjectException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/package-info.java b/modules/core/src/main/java/org/apache/ignite/binary/package-info.java
new file mode 100644
index 0000000..5ebf9d8
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains Ignite Binary Objects API classes.
+ */
+package org.apache.ignite.binary;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/cache/CacheKeyConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheKeyConfiguration.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheKeyConfiguration.java
new file mode 100644
index 0000000..767b44c
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheKeyConfiguration.java
@@ -0,0 +1,92 @@
+/*
+ * 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.cache;
+
+import java.io.Serializable;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Configuration defining various aspects of cache keys without explicit usage of annotations on user classes.
+ */
+public class CacheKeyConfiguration implements Serializable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Type name. */
+ private String typeName;
+
+ /** Affinity key field name. */
+ private String affKeyFieldName;
+
+ /**
+ * Creates an empty cache key configuration that should be populated via setters.
+ */
+ public CacheKeyConfiguration() {
+ // Convenience no-op constructor.
+ }
+
+ /**
+ * Creates cache key configuration with given type name and affinity field name.
+ *
+ * @param typeName Type name.
+ * @param affKeyFieldName Affinity field name.
+ */
+ public CacheKeyConfiguration(String typeName, String affKeyFieldName) {
+ this.typeName = typeName;
+ this.affKeyFieldName = affKeyFieldName;
+ }
+
+ /**
+ * Sets type name for which affinity field name is being defined.
+ *
+ * @return Type name.
+ */
+ public String getTypeName() {
+ return typeName;
+ }
+
+ /**
+ * @param typeName Type name for which affinity field name is being defined.
+ */
+ public void setTypeName(String typeName) {
+ this.typeName = typeName;
+ }
+
+ /**
+ * Gets affinity key field name.
+ *
+ * @return Affinity key field name.
+ */
+ public String getAffinityKeyFieldName() {
+ return affKeyFieldName;
+ }
+
+ /**
+ * Sets affinity key field name.
+ *
+ * @param affKeyFieldName Affinity key field name.
+ */
+ public void setAffinityKeyFieldName(String affKeyFieldName) {
+ this.affKeyFieldName = affKeyFieldName;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(CacheKeyConfiguration.class, this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
index 95a138d..2b7205b 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheTypeMetadata.java
@@ -23,9 +23,12 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
+import javax.cache.CacheException;
import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore;
+import org.apache.ignite.internal.processors.query.GridQueryProcessor;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
/**
@@ -47,6 +50,9 @@ public class CacheTypeMetadata implements Serializable {
/** Value class used to store value in cache. */
private String valType;
+ /** Simple value type name that will be used as SQL table name.*/
+ private String simpleValType;
+
/** Optional persistent key fields (needed only if {@link CacheJdbcPojoStore} is used). */
@GridToStringInclude
private Collection<CacheTypeFieldMetadata> keyFields;
@@ -75,22 +81,20 @@ public class CacheTypeMetadata implements Serializable {
@GridToStringInclude
private Map<String, LinkedHashMap<String, IgniteBiTuple<Class<?>, Boolean>>> grps;
+ /** */
+ @GridToStringInclude
+ private Map<String,String> aliases;
+
/**
* Default constructor.
*/
public CacheTypeMetadata() {
keyFields = new ArrayList<>();
-
valFields = new ArrayList<>();
-
qryFlds = new LinkedHashMap<>();
-
ascFlds = new LinkedHashMap<>();
-
descFlds = new LinkedHashMap<>();
-
txtFlds = new LinkedHashSet<>();
-
grps = new LinkedHashMap<>();
}
@@ -99,25 +103,16 @@ public class CacheTypeMetadata implements Serializable {
*/
public CacheTypeMetadata(CacheTypeMetadata src) {
dbSchema = src.getDatabaseSchema();
-
dbTbl = src.getDatabaseTable();
-
keyType = src.getKeyType();
-
valType = src.getValueType();
-
+ simpleValType = src.simpleValType;
keyFields = new ArrayList<>(src.getKeyFields());
-
valFields = new ArrayList<>(src.getValueFields());
-
qryFlds = new LinkedHashMap<>(src.getQueryFields());
-
ascFlds = new LinkedHashMap<>(src.getAscendingFields());
-
descFlds = new LinkedHashMap<>(src.getDescendingFields());
-
txtFlds = new LinkedHashSet<>(src.getTextFields());
-
grps = new LinkedHashMap<>(src.getGroups());
}
@@ -194,12 +189,28 @@ public class CacheTypeMetadata implements Serializable {
}
/**
+ * Gets simple value type.
+ *
+ * @return Simple value type.
+ */
+ public String getSimpleValueType() {
+ return simpleValType;
+ }
+
+ /**
* Sets value type.
*
* @param valType Value type.
*/
public void setValueType(String valType) {
+ if (this.valType != null)
+ throw new CacheException("Value type can be set only once.");
+
this.valType = valType;
+
+ Class<?> cls = U.classForName(valType, null);
+
+ simpleValType = cls == null ? valType : GridQueryProcessor.typeName(cls);
}
/**
@@ -280,7 +291,10 @@ public class CacheTypeMetadata implements Serializable {
* @param ascFlds Name-to-type map for ascending-indexed fields.
*/
public void setAscendingFields(Map<String, Class<?>> ascFlds) {
- this.ascFlds = ascFlds;
+ if (ascFlds == null)
+ this.ascFlds = ascFlds;
+ else
+ this.ascFlds.putAll(ascFlds);
}
/**
@@ -337,6 +351,25 @@ public class CacheTypeMetadata implements Serializable {
this.grps = grps;
}
+ /**
+ * Sets mapping from full property name in dot notation to an alias that will be used as SQL column name.
+ * Example: {"parent.name" -> "parentName"}.
+ *
+ * @param aliases Aliases.
+ */
+ public void setAliases(Map<String,String> aliases) {
+ this.aliases = aliases;
+ }
+
+ /**
+ * Gets aliases mapping.
+ *
+ * @return Aliases.
+ */
+ public Map<String,String> getAliases() {
+ return aliases;
+ }
+
/** {@inheritDoc} */
@Override public String toString() {
return S.toString(CacheTypeMetadata.class, this);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/cache/IgniteObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/IgniteObject.java b/modules/core/src/main/java/org/apache/ignite/cache/IgniteObject.java
deleted file mode 100644
index ab926ce..0000000
--- a/modules/core/src/main/java/org/apache/ignite/cache/IgniteObject.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.cache;
-
-import java.io.Serializable;
-import org.apache.ignite.portable.PortableException;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Ignite object. Abstracted representation of a binary object form.
- */
-public interface IgniteObject extends Serializable {
- /**
- * Gets object type ID.
- *
- * @return Type ID.
- */
- public int typeId();
-
- /**
- * Gets field value.
- *
- * @param fieldName Field name.
- * @return Field value.
- * @throws PortableException In case of any other error.
- */
- @Nullable public <F> F field(String fieldName) throws PortableException;
-
- /**
- * Checks whether field is set.
- *
- * @param fieldName Field name.
- * @return {@code true} if field is set.
- */
- public boolean hasField(String fieldName);
-
- /**
- * Gets fully deserialized instance of portable object.
- *
- * @return Fully deserialized instance of portable object.
- * @throws org.apache.ignite.portable.PortableInvalidClassException If class doesn't exist.
- * @throws PortableException In case of any other error.
- */
- @Nullable public <T> T deserialize() throws PortableException;
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
new file mode 100644
index 0000000..cb84c47
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
@@ -0,0 +1,217 @@
+/*
+ * 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.cache;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.A;
+
+/**
+ * Query entity is a description of {@link org.apache.ignite.IgniteCache cache} entry (composed of key and value)
+ * in a way of how it must be indexed and can be queried.
+ */
+public class QueryEntity implements Serializable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Key type. */
+ private String keyType;
+
+ /** Value type. */
+ private String valType;
+
+ /** Fields available for query. A map from field name to type name. */
+ private LinkedHashMap<String, String> fields = new LinkedHashMap<>();
+
+ /** Aliases. */
+ private Map<String, String> aliases = new HashMap<>();
+
+ /** Collection of query indexes. */
+ private Map<String, QueryIndex> idxs = new HashMap<>();
+
+ /**
+ * Gets key type for this query pair.
+ *
+ * @return Key type.
+ */
+ public String getKeyType() {
+ return keyType;
+ }
+
+ /**
+ * Sets key type for this query pair.
+ *
+ * @param keyType Key type.
+ */
+ public void setKeyType(String keyType) {
+ this.keyType = keyType;
+ }
+
+ /**
+ * Gets value type for this query pair.
+ *
+ * @return Value type.
+ */
+ public String getValueType() {
+ return valType;
+ }
+
+ /**
+ * Sets value type for this query pair.
+ *
+ * @param valType Value type.
+ */
+ public void setValueType(String valType) {
+ this.valType = valType;
+ }
+
+ /**
+ * Gets query fields for this query pair. The order of fields is important as it defines the order
+ * of columns returned by the 'select *' queries.
+ *
+ * @return Field-to-type map.
+ */
+ public LinkedHashMap<String, String> getFields() {
+ return fields;
+ }
+
+ /**
+ * Sets query fields for this query pair. The order if fields is important as it defines the
+ * order of columns returned by the 'select *' queries.
+ *
+ * @param fields Field-to-type map.
+ */
+ public void setFields(LinkedHashMap<String, String> fields) {
+ this.fields = fields;
+ }
+
+ /**
+ * Gets a collection of index entities.
+ *
+ * @return Collection of index entities.
+ */
+ public Collection<QueryIndex> getIndexes() {
+ return idxs.values();
+ }
+
+ /**
+ * Gets aliases map.
+ *
+ * @return Aliases.
+ */
+ public Map<String, String> getAliases() {
+ return aliases;
+ }
+
+ /**
+ * Sets mapping from full property name in dot notation to an alias that will be used as SQL column name.
+ * Example: {"parent.name" -> "parentName"}.
+
+ * @param aliases Aliases map.
+ */
+ public void setAliases(Map<String, String> aliases) {
+ this.aliases = aliases;
+ }
+
+ /**
+ * Sets a collection of index entities.
+ *
+ * @param idxs Collection of index entities.
+ */
+ public void setIndexes(Collection<QueryIndex> idxs) {
+ for (QueryIndex idx : idxs) {
+ if (!F.isEmpty(idx.getFields())) {
+ if (idx.getName() == null)
+ idx.setName(defaultIndexName(idx));
+
+ if (!this.idxs.containsKey(idx.getName()))
+ this.idxs.put(idx.getName(), idx);
+ else
+ throw new IllegalArgumentException("Duplicate index name: " + idx.getName());
+ }
+ }
+ }
+
+ /**
+ * Utility method for building query entities programmatically.
+ */
+ public void addQueryField(String fullName, String type, String alias) {
+ A.notNull(fullName, "fullName");
+ A.notNull(type, "type");
+
+ fields.put(fullName, type);
+
+ if (alias != null)
+ aliases.put(fullName, alias);
+ }
+
+ /**
+ * Ensures that index with the given name exists.
+ *
+ * @param idxName Index name.
+ * @param idxType Index type.
+ */
+ public void ensureIndex(String idxName, QueryIndexType idxType) {
+ QueryIndex idx = idxs.get(idxName);
+
+ if (idx == null) {
+ idx = new QueryIndex();
+
+ idx.setName(idxName);
+ idx.setIndexType(idxType);
+
+ idxs.put(idxName, idx);
+ }
+ else
+ throw new IllegalArgumentException("An index with the same name and of a different type already exists " +
+ "[idxName=" + idxName + ", existingIdxType=" + idx.getIndexType() + ", newIdxType=" + idxType + ']');
+ }
+
+ /**
+ * Generates default index name by concatenating all index field names.
+ *
+ * @param idx Index to build name for.
+ * @return Index name.
+ */
+ public static String defaultIndexName(QueryIndex idx) {
+ StringBuilder idxName = new StringBuilder();
+
+ for (Map.Entry<String, Boolean> field : idx.getFields().entrySet()) {
+ idxName.append(field.getKey());
+
+ idxName.append('_');
+ idxName.append(field.getValue() ? "asc_" : "desc_");
+ }
+
+ for (int i = 0; i < idxName.length(); i++) {
+ char ch = idxName.charAt(i);
+
+ if (Character.isWhitespace(ch))
+ idxName.setCharAt(i, '_');
+ else
+ idxName.setCharAt(i, Character.toLowerCase(ch));
+ }
+
+ idxName.append("idx");
+
+ return idxName.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
new file mode 100644
index 0000000..f12044d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
@@ -0,0 +1,192 @@
+/*
+ * 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.cache;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+
+/**
+ * Contains list of fields to be indexed. It is possible to provide field name
+ * suffixed with index specific extension, for example for {@link QueryIndexType#SORTED sorted} index
+ * the list can be provided as following {@code (id, name asc, age desc)}.
+ */
+@SuppressWarnings("TypeMayBeWeakened")
+public class QueryIndex implements Serializable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Index name. */
+ private String name;
+
+ /** */
+ private LinkedHashMap<String, Boolean> fields;
+
+ /** */
+ private QueryIndexType type;
+
+ /**
+ * Creates an empty index. Should be populated via setters.
+ */
+ public QueryIndex() {
+ // Empty constructor.
+ }
+
+ /**
+ * Creates single-field sorted ascending index.
+ *
+ * @param name Field name.
+ */
+ public QueryIndex(String name) {
+ this(name, QueryIndexType.SORTED, true);
+ }
+
+ /**
+ * Creates single-field sorted index.
+ *
+ * @param name Field name.
+ * @param asc Ascending flag.
+ */
+ public QueryIndex(String name, boolean asc) {
+ this(name, QueryIndexType.SORTED, asc);
+ }
+
+ /**
+ * Creates index for one field.
+ * If index is sorted, then ascending sorting is used by default.
+ * To specify sort order, use the next method.
+ * This constructor should also have a corresponding setter method.
+ */
+ public QueryIndex(String field, QueryIndexType type) {
+ this(Arrays.asList(field), type);
+ }
+
+ /**
+ * Creates index for one field. The last boolean parameter
+ * is ignored for non-sorted indexes.
+ */
+ public QueryIndex(String field, QueryIndexType type, boolean asc) {
+ fields = new LinkedHashMap<>();
+ fields.put(field, asc);
+
+ this.type = type;
+ }
+
+ /**
+ * Creates index for a collection of fields. If index is sorted, fields will be sorted in
+ * ascending order.
+ *
+ * @param fields Collection of fields to create an index.
+ * @param type Index type.
+ */
+ public QueryIndex(Collection<String> fields, QueryIndexType type) {
+ this.fields = new LinkedHashMap<>();
+
+ for (String field : fields)
+ this.fields.put(field, true);
+
+ this.type = type;
+ }
+
+ /**
+ * Creates index for a collection of fields. The order of fields in the created index will be the same
+ * as iteration order in the passed map. Map value defines whether the index will be ascending.
+ *
+ * @param fields Field name to field sort direction for sorted indexes.
+ * @param type Index type.
+ */
+ public QueryIndex(LinkedHashMap<String, Boolean> fields, QueryIndexType type) {
+ this.fields = fields;
+ this.type = type;
+ }
+
+ /**
+ * Gets index name. Will be automatically set if not provided by a user.
+ *
+ * @return Index name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets index name.
+ *
+ * @param name Index name.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Gets fields included in the index.
+ *
+ * @return Collection of index fields.
+ */
+ public LinkedHashMap<String, Boolean> getFields() {
+ return fields;
+ }
+
+ /**
+ * Sets fields included in the index.
+ *
+ * @param fields Collection of index fields.
+ */
+ public void setFields(LinkedHashMap<String, Boolean> fields) {
+ this.fields = fields;
+ }
+
+ /**
+ * @return Gets a collection of field names.
+ */
+ public Collection<String> getFieldNames() {
+ return fields.keySet();
+ }
+
+ /**
+ * Sets a collection of field names altogether with the field sorting direction. Sorting direction will be
+ * ignored for non-sorted indexes.
+ *
+ * @param fields Collection of fields.
+ * @param asc Ascending flag.
+ */
+ public void setFieldNames(Collection<String> fields, boolean asc) {
+ this.fields = new LinkedHashMap<>();
+
+ for (String field : fields)
+ this.fields.put(field, asc);
+ }
+
+ /**
+ * Gets index type.
+ *
+ * @return Index type.
+ */
+ public QueryIndexType getIndexType() {
+ return type;
+ }
+
+ /**
+ * Sets index type.
+ *
+ * @param type Index type.
+ */
+ public void setIndexType(QueryIndexType type) {
+ this.type = type;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/cache/QueryIndexType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndexType.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndexType.java
new file mode 100644
index 0000000..f9b544d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndexType.java
@@ -0,0 +1,38 @@
+/*
+ * 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.cache;
+
+/**
+ * Index type.
+ */
+public enum QueryIndexType {
+ /**
+ * Sorted index.
+ */
+ SORTED,
+
+ /**
+ * Full-text index.
+ */
+ FULLTEXT,
+
+ /**
+ * Geo-spatial index.
+ */
+ GEOSPATIAL
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index ae3f21f..af0122f 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -18,8 +18,22 @@
package org.apache.ignite.configuration;
import java.io.Serializable;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.TreeSet;
import javax.cache.Cache;
+import javax.cache.CacheException;
import javax.cache.configuration.CacheEntryListenerConfiguration;
import javax.cache.configuration.CompleteConfiguration;
import javax.cache.configuration.Factory;
@@ -36,14 +50,26 @@ import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.CacheRebalanceMode;
import org.apache.ignite.cache.CacheTypeMetadata;
import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.cache.QueryIndexType;
import org.apache.ignite.cache.affinity.AffinityFunction;
import org.apache.ignite.cache.affinity.AffinityKeyMapper;
import org.apache.ignite.cache.eviction.EvictionFilter;
import org.apache.ignite.cache.eviction.EvictionPolicy;
+import org.apache.ignite.cache.query.annotations.QueryGroupIndex;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
import org.apache.ignite.cache.query.annotations.QuerySqlFunction;
+import org.apache.ignite.cache.query.annotations.QueryTextField;
import org.apache.ignite.cache.store.CacheStore;
import org.apache.ignite.cache.store.CacheStoreSessionListener;
import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor;
+import org.apache.ignite.internal.processors.query.GridQueryIndexType;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.T2;
import org.apache.ignite.internal.util.typedef.internal.A;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
@@ -51,14 +77,12 @@ import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.plugin.CachePluginConfiguration;
import org.jetbrains.annotations.Nullable;
-import javax.cache.Cache;
-import javax.cache.configuration.CompleteConfiguration;
-import javax.cache.configuration.Factory;
-import javax.cache.configuration.MutableConfiguration;
-import javax.cache.expiry.ExpiryPolicy;
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.HashSet;
+import static org.apache.ignite.internal.processors.query.GridQueryIndexType.FULLTEXT;
+import static org.apache.ignite.internal.processors.query.GridQueryIndexType.GEO_SPATIAL;
+import static org.apache.ignite.internal.processors.query.GridQueryIndexType.SORTED;
+import static org.apache.ignite.internal.processors.query.GridQueryProcessor._VAL;
+import static org.apache.ignite.internal.processors.query.GridQueryProcessor.isGeometryClass;
+import static org.apache.ignite.internal.processors.query.GridQueryProcessor.isSqlType;
/**
* This class defines grid cache configuration. This configuration is passed to
@@ -330,7 +354,7 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
private boolean sqlEscapeAll;
/** */
- private Class<?>[] indexedTypes;
+ private transient Class<?>[] indexedTypes;
/** */
private int sqlOnheapRowCacheSize = DFLT_SQL_ONHEAP_ROW_CACHE_SIZE;
@@ -347,6 +371,9 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
/** Cache store session listeners. */
private Factory<? extends CacheStoreSessionListener>[] storeSesLsnrs;
+ /** Query entities. */
+ private Collection<QueryEntity> qryEntities;
+
/** Empty constructor (all values are initialized to their defaults). */
public CacheConfiguration() {
/* No-op. */
@@ -411,6 +438,8 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
name = cc.getName();
nearCfg = cc.getNearConfiguration();
nodeFilter = cc.getNodeFilter();
+ pluginCfgs = cc.getPluginConfigurations();
+ qryEntities = cc.getQueryEntities();
rebalanceMode = cc.getRebalanceMode();
rebalanceBatchSize = cc.getRebalanceBatchSize();
rebalanceDelay = cc.getRebalanceDelay();
@@ -435,7 +464,6 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
writeBehindFlushSize = cc.getWriteBehindFlushSize();
writeBehindFlushThreadCnt = cc.getWriteBehindFlushThreadCount();
writeSync = cc.getWriteSynchronizationMode();
- pluginCfgs = cc.getPluginConfigurations();
}
/**
@@ -855,19 +883,19 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
* store implementation in some cases, but it can cause performance
* degradation due to additional serializations and deserializations
* of portable objects. You will also need to have key and value
- * classes on all nodes since portables will be deserialized when
+ * classes on all nodes since binary will be deserialized when
* store is called.
*
- * @return Keep portables in store flag.
+ * @return Keep binary in store flag.
*/
public Boolean isKeepPortableInStore() {
return keepPortableInStore;
}
/**
- * Sets keep portables in store flag.
+ * Sets keep binary in store flag.
*
- * @param keepPortableInStore Keep portables in store flag.
+ * @param keepPortableInStore Keep binary in store flag.
*/
public void setKeepPortableInStore(boolean keepPortableInStore) {
this.keepPortableInStore = keepPortableInStore;
@@ -1577,9 +1605,10 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
*
* @param typeMeta Collection of type metadata.
* @return {@code this} for chaining.
+ * @deprecated Use {@link #setQueryEntities(java.util.Collection)} instead.
*/
public CacheConfiguration<K, V> setTypeMetadata(Collection<CacheTypeMetadata> typeMeta) {
- this.typeMeta = typeMeta;
+ this.typeMeta = new ArrayList<>(typeMeta);
return this;
}
@@ -1734,21 +1763,39 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
* @return {@code this} for chaining.
*/
public CacheConfiguration<K, V> setIndexedTypes(Class<?>... indexedTypes) {
- A.ensure(indexedTypes == null || (indexedTypes.length & 1) == 0,
+ A.notNull(indexedTypes, "indexedTypes");
+
+ int len = indexedTypes.length;
+
+ if (len == 0)
+ return this;
+
+ A.ensure((len & 1) == 0,
"Number of indexed types is expected to be even. Refer to method javadoc for details.");
- if (indexedTypes != null) {
- int len = indexedTypes.length;
+ if (this.indexedTypes != null)
+ throw new CacheException("Indexed types can be set only once.");
- Class<?>[] newIndexedTypes = new Class<?>[len];
+ Class<?>[] newIndexedTypes = new Class<?>[len];
- for (int i = 0; i < len; i++)
- newIndexedTypes[i] = U.box(indexedTypes[i]);
+ for (int i = 0; i < len; i++) {
+ if (indexedTypes[i] == null)
+ throw new NullPointerException("Indexed types array contains null at index: " + i);
- this.indexedTypes = newIndexedTypes;
+ newIndexedTypes[i] = U.box(indexedTypes[i]);
+ }
+
+ if (qryEntities == null)
+ qryEntities = new ArrayList<>();
+
+ for (int i = 0; i < len; i += 2) {
+ Class<?> keyCls = newIndexedTypes[i];
+ Class<?> valCls = newIndexedTypes[i + 1];
+
+ TypeDescriptor desc = processKeyAndValueClasses(keyCls, valCls);
+
+ qryEntities.add(convert(desc));
}
- else
- this.indexedTypes = null;
return this;
}
@@ -1800,6 +1847,32 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
}
/**
+ * Gets a collection of configured query entities.
+ *
+ * @return Query entities configurations.
+ */
+ public Collection<QueryEntity> getQueryEntities() {
+ return qryEntities != null ? qryEntities : Collections.<QueryEntity>emptyList();
+ }
+
+ /**
+ * Sets query entities configuration.
+ *
+ * @param qryEntities Query entities.
+ * @return {@code this} for chaining.
+ */
+ public CacheConfiguration<K, V> setQueryEntities(Collection<QueryEntity> qryEntities) {
+ if (this.qryEntities == null)
+ this.qryEntities = new ArrayList<>(qryEntities);
+ else if (indexedTypes != null)
+ this.qryEntities.addAll(qryEntities);
+ else
+ throw new CacheException("Query entities can be set only once.");
+
+ return this;
+ }
+
+ /**
* Gets topology validator.
* <p>
* See {@link TopologyValidator} for details.
@@ -1889,6 +1962,233 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
return cfg;
}
+ /**
+ * @param desc Type descriptor.
+ * @return Type metadata.
+ */
+ static QueryEntity convert(TypeDescriptor desc) {
+ QueryEntity entity = new QueryEntity();
+
+ // Key and val types.
+ entity.setKeyType(desc.keyClass().getName());
+ entity.setValueType(desc.valueClass().getName());
+
+ for (ClassProperty prop : desc.props.values())
+ entity.addQueryField(prop.fullName(), U.box(prop.type()).getName(), prop.alias());
+
+ QueryIndex txtIdx = null;
+
+ Collection<QueryIndex> idxs = new ArrayList<>();
+
+ for (Map.Entry<String, GridQueryIndexDescriptor> idxEntry : desc.indexes().entrySet()) {
+ GridQueryIndexDescriptor idx = idxEntry.getValue();
+
+ if (idx.type() == FULLTEXT) {
+ assert txtIdx == null;
+
+ txtIdx = new QueryIndex();
+
+ txtIdx.setIndexType(QueryIndexType.FULLTEXT);
+
+ txtIdx.setFieldNames(idx.fields(), true);
+ txtIdx.setName(idxEntry.getKey());
+ }
+ else {
+ Collection<String> grp = new ArrayList<>();
+
+ for (String fieldName : idx.fields())
+ grp.add(idx.descending(fieldName) ? fieldName + " desc" : fieldName);
+
+ QueryIndex sortedIdx = new QueryIndex();
+
+ sortedIdx.setIndexType(idx.type() == SORTED ? QueryIndexType.SORTED : QueryIndexType.GEOSPATIAL);
+
+ LinkedHashMap<String, Boolean> fields = new LinkedHashMap<>();
+
+ for (String f : idx.fields())
+ fields.put(f, !idx.descending(f));
+
+ sortedIdx.setFields(fields);
+
+ sortedIdx.setName(idxEntry.getKey());
+
+ idxs.add(sortedIdx);
+ }
+ }
+
+ if (desc.valueTextIndex()) {
+ if (txtIdx == null) {
+ txtIdx = new QueryIndex();
+
+ txtIdx.setIndexType(QueryIndexType.FULLTEXT);
+
+ txtIdx.setFieldNames(Arrays.asList(_VAL), true);
+ }
+ else
+ txtIdx.getFields().put(_VAL, true);
+ }
+
+ if (txtIdx != null)
+ idxs.add(txtIdx);
+
+ if (!F.isEmpty(idxs))
+ entity.setIndexes(idxs);
+
+ return entity;
+ }
+
+ /**
+ * @param cls Class.
+ * @return Masked class.
+ */
+ private static Class<?> mask(Class<?> cls) {
+ assert cls != null;
+
+ return isSqlType(cls) ? cls : Object.class;
+ }
+
+ /**
+ * @param keyCls Key class.
+ * @param valCls Value class.
+ * @return Type descriptor.
+ */
+ static TypeDescriptor processKeyAndValueClasses(
+ Class<?> keyCls,
+ Class<?> valCls
+ ) {
+ TypeDescriptor d = new TypeDescriptor();
+
+ d.keyClass(keyCls);
+ d.valueClass(valCls);
+
+ processAnnotationsInClass(true, d.keyCls, d, null);
+ processAnnotationsInClass(false, d.valCls, d, null);
+
+ return d;
+ }
+
+ /**
+ * Process annotations for class.
+ *
+ * @param key If given class relates to key.
+ * @param cls Class.
+ * @param type Type descriptor.
+ * @param parent Parent in case of embeddable.
+ */
+ private static void processAnnotationsInClass(boolean key, Class<?> cls, TypeDescriptor type,
+ @Nullable ClassProperty parent) {
+ if (U.isJdk(cls) || isGeometryClass(cls)) {
+ if (parent == null && !key && isSqlType(cls)) { // We have to index primitive _val.
+ String idxName = _VAL + "_idx";
+
+ type.addIndex(idxName, isGeometryClass(cls) ? GEO_SPATIAL : SORTED);
+
+ type.addFieldToIndex(idxName, _VAL, 0, false);
+ }
+
+ return;
+ }
+
+ if (parent != null && parent.knowsClass(cls))
+ throw new CacheException("Recursive reference found in type: " + cls.getName());
+
+ if (parent == null) { // Check class annotation at top level only.
+ QueryTextField txtAnnCls = cls.getAnnotation(QueryTextField.class);
+
+ if (txtAnnCls != null)
+ type.valueTextIndex(true);
+
+ QueryGroupIndex grpIdx = cls.getAnnotation(QueryGroupIndex.class);
+
+ if (grpIdx != null)
+ type.addIndex(grpIdx.name(), SORTED);
+
+ QueryGroupIndex.List grpIdxList = cls.getAnnotation(QueryGroupIndex.List.class);
+
+ if (grpIdxList != null && !F.isEmpty(grpIdxList.value())) {
+ for (QueryGroupIndex idx : grpIdxList.value())
+ type.addIndex(idx.name(), SORTED);
+ }
+ }
+
+ for (Class<?> c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
+ for (Field field : c.getDeclaredFields()) {
+ QuerySqlField sqlAnn = field.getAnnotation(QuerySqlField.class);
+ QueryTextField txtAnn = field.getAnnotation(QueryTextField.class);
+
+ if (sqlAnn != null || txtAnn != null) {
+ ClassProperty prop = new ClassProperty(field);
+
+ prop.parent(parent);
+
+ processAnnotation(key, sqlAnn, txtAnn, field.getType(), prop, type);
+
+ type.addProperty(prop, true);
+ }
+ }
+
+ for (Method mtd : c.getDeclaredMethods()) {
+ QuerySqlField sqlAnn = mtd.getAnnotation(QuerySqlField.class);
+ QueryTextField txtAnn = mtd.getAnnotation(QueryTextField.class);
+
+ if (sqlAnn != null || txtAnn != null) {
+ if (mtd.getParameterTypes().length != 0)
+ throw new CacheException("Getter with QuerySqlField " +
+ "annotation cannot have parameters: " + mtd);
+
+ ClassProperty prop = new ClassProperty(mtd);
+
+ prop.parent(parent);
+
+ processAnnotation(key, sqlAnn, txtAnn, mtd.getReturnType(), prop, type);
+
+ type.addProperty(prop, true);
+ }
+ }
+ }
+ }
+
+ /**
+ * Processes annotation at field or method.
+ *
+ * @param key If given class relates to key.
+ * @param sqlAnn SQL annotation, can be {@code null}.
+ * @param txtAnn H2 text annotation, can be {@code null}.
+ * @param cls Class of field or return type for method.
+ * @param prop Current property.
+ * @param desc Class description.
+ */
+ private static void processAnnotation(boolean key, QuerySqlField sqlAnn, QueryTextField txtAnn,
+ Class<?> cls, ClassProperty prop, TypeDescriptor desc) {
+ if (sqlAnn != null) {
+ processAnnotationsInClass(key, cls, desc, prop);
+
+ if (!sqlAnn.name().isEmpty())
+ prop.alias(sqlAnn.name());
+
+ if (sqlAnn.index()) {
+ String idxName = prop.alias() + "_idx";
+
+ desc.addIndex(idxName, isGeometryClass(prop.type()) ? GEO_SPATIAL : SORTED);
+
+ desc.addFieldToIndex(idxName, prop.fullName(), 0, sqlAnn.descending());
+ }
+
+ if (!F.isEmpty(sqlAnn.groups())) {
+ for (String group : sqlAnn.groups())
+ desc.addFieldToIndex(group, prop.fullName(), 0, false);
+ }
+
+ if (!F.isEmpty(sqlAnn.orderedGroups())) {
+ for (QuerySqlField.Group idx : sqlAnn.orderedGroups())
+ desc.addFieldToIndex(idx.name(), prop.fullName(), idx.order(), idx.descending());
+ }
+ }
+
+ if (txtAnn != null)
+ desc.addFieldToTextIndex(prop.fullName());
+ }
+
/** {@inheritDoc} */
@Override public String toString() {
return S.toString(CacheConfiguration.class, this);
@@ -1908,10 +2208,318 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
/** {@inheritDoc} */
@Override public boolean equals(Object obj) {
- if (obj == null)
- return false;
+ return obj != null && obj.getClass().equals(this.getClass());
+ }
+ }
+
+ /**
+ * Descriptor of type.
+ */
+ private static class TypeDescriptor {
+ /** Value field names and types with preserved order. */
+ @GridToStringInclude
+ private final Map<String, Class<?>> fields = new LinkedHashMap<>();
+
+ /** */
+ @GridToStringExclude
+ private final Map<String, ClassProperty> props = new LinkedHashMap<>();
+
+ /** */
+ @GridToStringInclude
+ private final Map<String, IndexDescriptor> indexes = new HashMap<>();
+
+ /** */
+ private IndexDescriptor fullTextIdx;
+
+ /** */
+ private Class<?> keyCls;
+
+ /** */
+ private Class<?> valCls;
+
+ /** */
+ private boolean valTextIdx;
+
+ /**
+ * @return Indexes.
+ */
+ public Map<String, GridQueryIndexDescriptor> indexes() {
+ return Collections.<String, GridQueryIndexDescriptor>unmodifiableMap(indexes);
+ }
+
+ /**
+ * Adds index.
+ *
+ * @param idxName Index name.
+ * @param type Index type.
+ * @return Index descriptor.
+ */
+ public IndexDescriptor addIndex(String idxName, GridQueryIndexType type) {
+ IndexDescriptor idx = new IndexDescriptor(type);
+
+ if (indexes.put(idxName, idx) != null)
+ throw new CacheException("Index with name '" + idxName + "' already exists.");
+
+ return idx;
+ }
+
+ /**
+ * Adds field to index.
+ *
+ * @param idxName Index name.
+ * @param field Field name.
+ * @param orderNum Fields order number in index.
+ * @param descending Sorting order.
+ */
+ public void addFieldToIndex(String idxName, String field, int orderNum,
+ boolean descending) {
+ IndexDescriptor desc = indexes.get(idxName);
+
+ if (desc == null)
+ desc = addIndex(idxName, SORTED);
+
+ desc.addField(field, orderNum, descending);
+ }
+
+ /**
+ * Adds field to text index.
+ *
+ * @param field Field name.
+ */
+ public void addFieldToTextIndex(String field) {
+ if (fullTextIdx == null) {
+ fullTextIdx = new IndexDescriptor(FULLTEXT);
+
+ indexes.put(null, fullTextIdx);
+ }
+
+ fullTextIdx.addField(field, 0, false);
+ }
+
+ /**
+ * @return Value class.
+ */
+ public Class<?> valueClass() {
+ return valCls;
+ }
+
+ /**
+ * Sets value class.
+ *
+ * @param valCls Value class.
+ */
+ void valueClass(Class<?> valCls) {
+ this.valCls = valCls;
+ }
+
+ /**
+ * @return Key class.
+ */
+ public Class<?> keyClass() {
+ return keyCls;
+ }
+
+ /**
+ * Set key class.
+ *
+ * @param keyCls Key class.
+ */
+ void keyClass(Class<?> keyCls) {
+ this.keyCls = keyCls;
+ }
+
+ /**
+ * Adds property to the type descriptor.
+ *
+ * @param prop Property.
+ * @param failOnDuplicate Fail on duplicate flag.
+ */
+ public void addProperty(ClassProperty prop, boolean failOnDuplicate) {
+ String name = prop.fullName();
+
+ if (props.put(name, prop) != null && failOnDuplicate)
+ throw new CacheException("Property with name '" + name + "' already exists.");
+
+ fields.put(name, prop.type());
+ }
+
+ /**
+ * @return {@code true} If we need to have a fulltext index on value.
+ */
+ public boolean valueTextIndex() {
+ return valTextIdx;
+ }
+
+ /**
+ * Sets if this value should be text indexed.
+ *
+ * @param valTextIdx Flag value.
+ */
+ public void valueTextIndex(boolean valTextIdx) {
+ this.valTextIdx = valTextIdx;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(TypeDescriptor.class, this);
+ }
+ }
+
+ /**
+ * Index descriptor.
+ */
+ private static class IndexDescriptor implements GridQueryIndexDescriptor {
+ /** Fields sorted by order number. */
+ private final Collection<T2<String, Integer>> fields = new TreeSet<>(
+ new Comparator<T2<String, Integer>>() {
+ @Override public int compare(T2<String, Integer> o1, T2<String, Integer> o2) {
+ if (o1.get2().equals(o2.get2())) // Order is equal, compare field names to avoid replace in Set.
+ return o1.get1().compareTo(o2.get1());
+
+ return o1.get2() < o2.get2() ? -1 : 1;
+ }
+ });
+
+ /** Fields which should be indexed in descending order. */
+ private Collection<String> descendings;
+
+ /** */
+ private final GridQueryIndexType type;
+
+ /**
+ * @param type Type.
+ */
+ private IndexDescriptor(GridQueryIndexType type) {
+ assert type != null;
+
+ this.type = type;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<String> fields() {
+ Collection<String> res = new ArrayList<>(fields.size());
+
+ for (T2<String, Integer> t : fields)
+ res.add(t.get1());
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean descending(String field) {
+ return descendings != null && descendings.contains(field);
+ }
+
+ /**
+ * Adds field to this index.
+ *
+ * @param field Field name.
+ * @param orderNum Field order number in this index.
+ * @param descending Sort order.
+ */
+ public void addField(String field, int orderNum, boolean descending) {
+ fields.add(new T2<>(field, orderNum));
+
+ if (descending) {
+ if (descendings == null)
+ descendings = new HashSet<>();
+
+ descendings.add(field);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public GridQueryIndexType type() {
+ return type;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(IndexDescriptor.class, this);
+ }
+ }
+
+ /**
+ * Description of type property.
+ */
+ private static class ClassProperty {
+ /** */
+ private final Member member;
+
+ /** */
+ private ClassProperty parent;
+
+ /** */
+ private String name;
+
+ /** */
+ private String alias;
+
+ /**
+ * Constructor.
+ *
+ * @param member Element.
+ */
+ ClassProperty(Member member) {
+ this.member = member;
+
+ name = member instanceof Method && member.getName().startsWith("get") && member.getName().length() > 3 ?
+ member.getName().substring(3) : member.getName();
+
+ ((AccessibleObject) member).setAccessible(true);
+ }
+
+ /**
+ * @param alias Alias.
+ */
+ public void alias(String alias) {
+ this.alias = alias;
+ }
+
+ /**
+ * @return Alias.
+ */
+ String alias() {
+ return F.isEmpty(alias) ? name : alias;
+ }
+
+ /**
+ * @return Type.
+ */
+ public Class<?> type() {
+ return member instanceof Field ? ((Field)member).getType() : ((Method)member).getReturnType();
+ }
+
+ /**
+ * @param parent Parent property if this is embeddable element.
+ */
+ public void parent(ClassProperty parent) {
+ this.parent = parent;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(ClassProperty.class, this);
+ }
+
+ /**
+ * @param cls Class.
+ * @return {@code true} If this property or some parent relates to member of the given class.
+ */
+ public boolean knowsClass(Class<?> cls) {
+ return member.getDeclaringClass() == cls || (parent != null && parent.knowsClass(cls));
+ }
+
+ /**
+ * @return Full name with all parents in dot notation.
+ */
+ public String fullName() {
+ assert name != null;
+
+ if (parent == null)
+ return name;
- return obj.getClass().equals(this.getClass());
+ return parent.fullName() + '.' + name;
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
index 3d38ed9..a91aa7e 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java
@@ -31,6 +31,7 @@ import javax.net.ssl.SSLContext;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.CacheKeyConfiguration;
import org.apache.ignite.cache.store.CacheStoreSessionListener;
import org.apache.ignite.cluster.ClusterGroup;
import org.apache.ignite.cluster.ClusterNode;
@@ -427,6 +428,9 @@ public class IgniteConfiguration {
/** Platform configuration. */
private PlatformConfiguration platformCfg;
+ /** Cache key configuration. */
+ private CacheKeyConfiguration[] cacheKeyCfg;
+
/**
* Creates valid grid configuration with all default values.
*/
@@ -463,6 +467,7 @@ public class IgniteConfiguration {
atomicCfg = cfg.getAtomicConfiguration();
daemon = cfg.isDaemon();
cacheCfg = cfg.getCacheConfiguration();
+ cacheKeyCfg = cfg.getCacheKeyConfiguration();
cacheSanityCheckEnabled = cfg.isCacheSanityCheckEnabled();
connectorCfg = cfg.getConnectorConfiguration();
classLdr = cfg.getClassLoader();
@@ -1950,6 +1955,25 @@ public class IgniteConfiguration {
}
/**
+ * Gets cache key configuration.
+ *
+ * @return Cache key configuration.
+ */
+ public CacheKeyConfiguration[] getCacheKeyConfiguration() {
+ return cacheKeyCfg;
+ }
+
+ /**
+ * Sets cache key configuration.
+ * Cache key configuration defines
+ *
+ * @param cacheKeyCfg Cache key configuration.
+ */
+ public void setCacheKeyCfg(CacheKeyConfiguration... cacheKeyCfg) {
+ this.cacheKeyCfg = cacheKeyCfg;
+ }
+
+ /**
* Gets flag indicating whether cache sanity check is enabled. If enabled, then Ignite
* will perform the following checks and throw an exception if check fails:
* <ul>
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
index ebf83bd..4990dc7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
@@ -49,7 +49,7 @@ import org.apache.ignite.internal.managers.swapspace.GridSwapSpaceManager;
import org.apache.ignite.internal.processors.affinity.GridAffinityProcessor;
import org.apache.ignite.internal.processors.cache.CacheConflictResolutionManager;
import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
import org.apache.ignite.internal.processors.clock.GridClockSource;
import org.apache.ignite.internal.processors.clock.GridClockSyncProcessor;
@@ -830,7 +830,7 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
return res;
if (cls.equals(IgniteCacheObjectProcessor.class))
- return (T)new CacheObjectPortableProcessorImpl(this);
+ return (T)new CacheObjectBinaryProcessorImpl(this);
if (cls.equals(CacheConflictResolutionManager.class))
return null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index a7e62b0..88e697c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -64,7 +64,7 @@ import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteFileSystem;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteMessaging;
-import org.apache.ignite.IgnitePortables;
+import org.apache.ignite.IgniteBinary;
import org.apache.ignite.IgniteQueue;
import org.apache.ignite.IgniteScheduler;
import org.apache.ignite.IgniteServices;
@@ -102,8 +102,8 @@ import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessor;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessor;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
import org.apache.ignite.internal.processors.clock.GridClockSyncProcessor;
import org.apache.ignite.internal.processors.closure.GridClosureProcessor;
@@ -157,7 +157,6 @@ import org.apache.ignite.lifecycle.LifecycleBean;
import org.apache.ignite.lifecycle.LifecycleEventType;
import org.apache.ignite.marshaller.MarshallerExclusions;
import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
import org.apache.ignite.mxbean.ClusterLocalNodeMetricsMXBean;
import org.apache.ignite.mxbean.IgniteMXBean;
import org.apache.ignite.mxbean.ThreadPoolMXBean;
@@ -1490,6 +1489,8 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
mgr.start();
}
catch (IgniteCheckedException e) {
+ U.error(log, "Failed to start manager: " + mgr , e);
+
throw new IgniteCheckedException("Failed to start manager: " + mgr, e);
}
}
@@ -2789,8 +2790,10 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
}
/** {@inheritDoc} */
- @Override public IgnitePortables portables() {
- return ((CacheObjectPortableProcessor)ctx.cacheObjects()).portables();
+ @Override public IgniteBinary binary() {
+ IgniteCacheObjectProcessor objProc = ctx.cacheObjects();
+
+ return objProc.binary();
}
/** {@inheritDoc} */
@@ -3088,7 +3091,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
return comp;
if (cls.equals(IgniteCacheObjectProcessor.class))
- return (T)new CacheObjectPortableProcessorImpl(ctx);
+ return (T)new CacheObjectBinaryProcessorImpl(ctx);
if (cls.equals(DiscoveryNodeValidationProcessor.class))
return (T)new OsDiscoveryNodeValidationProcessor(ctx);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientCompute.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientCompute.java b/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientCompute.java
index c907779..e7255f9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientCompute.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientCompute.java
@@ -414,7 +414,7 @@ public interface GridClientCompute {
public GridClientFuture<List<GridClientNode>> refreshTopologyAsync(boolean includeAttrs, boolean includeMetrics);
/**
- * Sets keep portables flag for the next task execution in the current thread.
+ * Sets keep binary flag for the next task execution in the current thread.
*/
public GridClientCompute withKeepPortables();
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnection.java b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnection.java
index fedd15a..8bdb1d0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnection.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnection.java
@@ -313,7 +313,7 @@ public abstract class GridClientConnection {
* @param taskName Task name.
* @param arg Task argument.
* @param destNodeId Destination node ID.
- * @param keepPortables Keep portables flag.
+ * @param keepPortables Keep binary flag.
* @return Task execution result.
* @throws GridClientConnectionResetException In case of error.
* @throws GridClientClosedException If client was manually closed before request was sent over network.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnectionManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnectionManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnectionManagerAdapter.java
index f1a9af1..dedee10 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnectionManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientConnectionManagerAdapter.java
@@ -483,7 +483,7 @@ public abstract class GridClientConnectionManagerAdapter implements GridClientCo
}
/**
- * @return Get thread local used to enable keep portables mode.
+ * @return Get thread local used to enable keep binary mode.
*/
protected ThreadLocal<Boolean> keepPortablesThreadLocal() {
return null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
index eee2858..24c9c70 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/impl/connection/GridClientNioTcpConnection.java
@@ -385,7 +385,7 @@ public class GridClientNioTcpConnection extends GridClientConnection {
*
* @param msg Message to request,
* @param destId Destination node identifier.
- * @param keepPortables Keep portables flag.
+ * @param keepPortables Keep binary flag.
* @return Response object.
* @throws GridClientConnectionResetException If request failed.
* @throws GridClientClosedException If client was closed.
@@ -1037,7 +1037,7 @@ public class GridClientNioTcpConnection extends GridClientConnection {
/** Flag indicating if connected message is a forwarded. */
private final boolean forward;
- /** Keep portables flag. */
+ /** Keep binary flag. */
private final boolean keepPortables;
/** Pending message for this future. */
@@ -1101,7 +1101,7 @@ public class GridClientNioTcpConnection extends GridClientConnection {
}
/**
- * @return Keep portables flag.
+ * @return Keep binary flag.
*/
public boolean keepPortables() {
return keepPortables;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index 079015c..623da66 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -31,7 +31,7 @@ import org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean;
import org.apache.ignite.internal.managers.deployment.GridDeploymentRequest;
import org.apache.ignite.internal.managers.deployment.GridDeploymentResponse;
import org.apache.ignite.internal.managers.eventstorage.GridEventStorageMessage;
-import org.apache.ignite.internal.portable.PortableObjectImpl;
+import org.apache.ignite.internal.portable.BinaryObjectImpl;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection;
import org.apache.ignite.internal.processors.cache.CacheEntryPredicateContainsValue;
@@ -680,7 +680,7 @@ public class GridIoMessageFactory implements MessageFactory {
break;
case 113:
- msg = new PortableObjectImpl();
+ msg = new BinaryObjectImpl();
break;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
index f90cf4f..437603a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
@@ -221,22 +221,6 @@ public class GridSwapSpaceManager extends GridManagerAdapter<SwapSpaceSpi> {
}
/**
- * Writes value to swap.
- *
- * @param spaceName Space name.
- * @param key Key.
- * @param val Value.
- * @param ldr Class loader (optional).
- * @throws IgniteCheckedException If failed.
- */
- public void write(@Nullable String spaceName, Object key, @Nullable Object val, @Nullable ClassLoader ldr)
- throws IgniteCheckedException {
- assert key != null;
-
- write(spaceName, new SwapKey(key), marshal(val), ldr);
- }
-
- /**
* Removes value from swap.
*
* @param spaceName Space name.
@@ -284,24 +268,6 @@ public class GridSwapSpaceManager extends GridManagerAdapter<SwapSpaceSpi> {
}
/**
- * Removes value from swap.
- *
- * @param spaceName Space name.
- * @param key Key.
- * @param c Optional closure that takes removed value and executes after actual
- * removing. If there was no value in storage the closure is executed given
- * {@code null} value as parameter.
- * @param ldr Class loader (optional).
- * @throws IgniteCheckedException If failed.
- */
- public void remove(@Nullable String spaceName, Object key, @Nullable IgniteInClosure<byte[]> c,
- @Nullable ClassLoader ldr) throws IgniteCheckedException {
- assert key != null;
-
- remove(spaceName, new SwapKey(key), c, ldr);
- }
-
- /**
* Gets size in bytes for swap space.
*
* @param spaceName Space name.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java
new file mode 100644
index 0000000..b8a25c1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java
@@ -0,0 +1,104 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryField;
+
+/**
+ * Implementation of portable field descriptor.
+ */
+public class BinaryFieldImpl implements BinaryField {
+ /** Well-known object schemas. */
+ @GridToStringExclude
+ private final PortableSchemaRegistry schemas;
+
+ /** Field name. */
+ private final String fieldName;
+
+ /** Pre-calculated field ID. */
+ private final int fieldId;
+
+ /**
+ * Constructor.
+ *
+ * @param schemas Schemas.
+ * @param fieldName Field name.
+ * @param fieldId Field ID.
+ */
+ public BinaryFieldImpl(PortableSchemaRegistry schemas, String fieldName, int fieldId) {
+ assert schemas != null;
+ assert fieldName != null;
+ assert fieldId != 0;
+
+ this.schemas = schemas;
+ this.fieldName = fieldName;
+ this.fieldId = fieldId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String name() {
+ return fieldName;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean exists(BinaryObject obj) {
+ BinaryObjectEx obj0 = (BinaryObjectEx)obj;
+
+ return fieldOrder(obj0) != PortableSchema.ORDER_NOT_FOUND;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override public <T> T value(BinaryObject obj) {
+ BinaryObjectEx obj0 = (BinaryObjectEx)obj;
+
+ int order = fieldOrder(obj0);
+
+ return order != PortableSchema.ORDER_NOT_FOUND ? (T)obj0.fieldByOrder(order) : null;
+ }
+
+ /**
+ * Get relative field offset.
+ *
+ * @param obj Object.
+ * @return Field offset.
+ */
+ private int fieldOrder(BinaryObjectEx obj) {
+ int schemaId = obj.schemaId();
+
+ PortableSchema schema = schemas.schema(schemaId);
+
+ if (schema == null) {
+ schema = obj.createSchema();
+
+ schemas.addSchema(schemaId, schema);
+ }
+
+ assert schema != null;
+
+ return schema.order(fieldId);
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(BinaryFieldImpl.class, this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetaDataCollector.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetaDataCollector.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetaDataCollector.java
new file mode 100644
index 0000000..b053a55
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetaDataCollector.java
@@ -0,0 +1,263 @@
+/*
+ * 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.portable;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryWriter;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Writer for meta data collection.
+ */
+class BinaryMetaDataCollector implements BinaryWriter {
+ /** */
+ private final Map<String, String> meta = new HashMap<>();
+
+ /** */
+ private final String typeName;
+
+ /**
+ * @param typeName Type name.
+ */
+ BinaryMetaDataCollector(String typeName) {
+ this.typeName = typeName;
+ }
+
+ /**
+ * @return Field meta data.
+ */
+ Map<String, String> meta() {
+ return meta;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeByte(String fieldName, byte val) throws BinaryObjectException {
+ add(fieldName, byte.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeShort(String fieldName, short val) throws BinaryObjectException {
+ add(fieldName, short.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeInt(String fieldName, int val) throws BinaryObjectException {
+ add(fieldName, int.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeLong(String fieldName, long val) throws BinaryObjectException {
+ add(fieldName, long.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeFloat(String fieldName, float val) throws BinaryObjectException {
+ add(fieldName, float.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDouble(String fieldName, double val) throws BinaryObjectException {
+ add(fieldName, double.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeChar(String fieldName, char val) throws BinaryObjectException {
+ add(fieldName, char.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBoolean(String fieldName, boolean val) throws BinaryObjectException {
+ add(fieldName, boolean.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws BinaryObjectException {
+ add(fieldName, PortableClassDescriptor.Mode.DECIMAL.typeName());
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeString(String fieldName, @Nullable String val) throws BinaryObjectException {
+ add(fieldName, String.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeUuid(String fieldName, @Nullable UUID val) throws BinaryObjectException {
+ add(fieldName, UUID.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDate(String fieldName, @Nullable Date val) throws BinaryObjectException {
+ add(fieldName, Date.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws BinaryObjectException {
+ add(fieldName, Timestamp.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws BinaryObjectException {
+ add(fieldName, Enum.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws BinaryObjectException {
+ add(fieldName, Enum[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeObject(String fieldName, @Nullable Object obj) throws BinaryObjectException {
+ add(fieldName, Object.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeByteArray(String fieldName, @Nullable byte[] val) throws BinaryObjectException {
+ add(fieldName, byte[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeShortArray(String fieldName, @Nullable short[] val) throws BinaryObjectException {
+ add(fieldName, short[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeIntArray(String fieldName, @Nullable int[] val) throws BinaryObjectException {
+ add(fieldName, int[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeLongArray(String fieldName, @Nullable long[] val) throws BinaryObjectException {
+ add(fieldName, long[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeFloatArray(String fieldName, @Nullable float[] val) throws BinaryObjectException {
+ add(fieldName, float[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDoubleArray(String fieldName, @Nullable double[] val) throws BinaryObjectException {
+ add(fieldName, double[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeCharArray(String fieldName, @Nullable char[] val) throws BinaryObjectException {
+ add(fieldName, char[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBooleanArray(String fieldName, @Nullable boolean[] val) throws BinaryObjectException {
+ add(fieldName, boolean[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val) throws BinaryObjectException {
+ add(fieldName, PortableClassDescriptor.Mode.DECIMAL_ARR.typeName());
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeStringArray(String fieldName, @Nullable String[] val) throws BinaryObjectException {
+ add(fieldName, String[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws BinaryObjectException {
+ add(fieldName, UUID[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDateArray(String fieldName, @Nullable Date[] val) throws BinaryObjectException {
+ add(fieldName, Date[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws BinaryObjectException {
+ add(fieldName, Timestamp[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeObjectArray(String fieldName, @Nullable Object[] val) throws BinaryObjectException {
+ add(fieldName, Object[].class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> void writeCollection(String fieldName, @Nullable Collection<T> col)
+ throws BinaryObjectException {
+ add(fieldName, Collection.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map) throws BinaryObjectException {
+ add(fieldName, Map.class);
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryRawWriter rawWriter() {
+ return (BinaryRawWriter)Proxy.newProxyInstance(getClass().getClassLoader(),
+ new Class<?>[] { BinaryRawWriterEx.class },
+ new InvocationHandler() {
+ @Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable {
+ return null;
+ }
+ });
+ }
+
+ /**
+ * @param name Field name.
+ * @param fieldType Field type.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ private void add(String name, Class<?> fieldType) throws BinaryObjectException {
+ assert fieldType != null;
+
+ add(name, fieldType.getSimpleName());
+ }
+
+ /**
+ * @param name Field name.
+ * @param fieldTypeName Field type name.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ private void add(String name, String fieldTypeName) throws BinaryObjectException {
+ assert name != null;
+
+ String oldFieldTypeName = meta.put(name, fieldTypeName);
+
+ if (oldFieldTypeName != null && !oldFieldTypeName.equals(fieldTypeName)) {
+ throw new BinaryObjectException(
+ "Field is written twice with different types [" +
+ "typeName=" + typeName +
+ ", fieldName=" + name +
+ ", fieldTypeName1=" + oldFieldTypeName +
+ ", fieldTypeName2=" + fieldTypeName +
+ ']'
+ );
+ }
+ }
+}
\ No newline at end of file
[02/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractSelfTest.java
deleted file mode 100644
index 7ac8712..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractSelfTest.java
+++ /dev/null
@@ -1,978 +0,0 @@
-/*
- * 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.cache.portable;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import javax.cache.Cache;
-import javax.cache.processor.EntryProcessor;
-import javax.cache.processor.MutableEntry;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgnitePortables;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CachePeekMode;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.portable.PortableObjectImpl;
-import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
-import org.apache.ignite.internal.util.typedef.P2;
-import org.apache.ignite.internal.util.typedef.internal.CU;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiInClosure;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.apache.ignite.transactions.Transaction;
-import org.jetbrains.annotations.Nullable;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
-import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
-import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
-
-/**
- * Test for portable objects stored in cache.
- */
-public abstract class GridCachePortableObjectsAbstractSelfTest extends GridCommonAbstractTest {
- /** */
- public static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
- /** */
- private static final int ENTRY_CNT = 100;
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- TcpDiscoverySpi disco = new TcpDiscoverySpi();
-
- disco.setIpFinder(IP_FINDER);
-
- cfg.setDiscoverySpi(disco);
-
- CacheConfiguration cacheCfg = new CacheConfiguration();
-
- cacheCfg.setCacheMode(cacheMode());
- cacheCfg.setAtomicityMode(atomicityMode());
- cacheCfg.setNearConfiguration(nearConfiguration());
- cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
- cacheCfg.setCacheStoreFactory(singletonFactory(new TestStore()));
- cacheCfg.setReadThrough(true);
- cacheCfg.setWriteThrough(true);
- cacheCfg.setLoadPreviousValue(true);
- cacheCfg.setBackups(1);
-
- if (offheapTiered()) {
- cacheCfg.setMemoryMode(OFFHEAP_TIERED);
- cacheCfg.setOffHeapMaxMemory(0);
- }
-
- cfg.setCacheConfiguration(cacheCfg);
-
- cfg.setMarshaller(new PortableMarshaller());
-
- return cfg;
- }
-
- /**
- * @return {@code True} if should use OFFHEAP_TIERED mode.
- */
- protected boolean offheapTiered() {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override protected void beforeTestsStarted() throws Exception {
- startGridsMultiThreaded(gridCount());
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTestsStopped() throws Exception {
- stopAllGrids();
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTest() throws Exception {
- for (int i = 0; i < gridCount(); i++) {
- GridCacheAdapter<Object, Object> c = ((IgniteKernal)grid(i)).internalCache();
-
- for (GridCacheEntryEx e : c.map().entries0()) {
- Object key = e.key().value(c.context().cacheObjectContext(), false);
- Object val = CU.value(e.rawGet(), c.context(), false);
-
- if (key instanceof PortableObject)
- assert ((PortableObjectImpl)key).detached() : val;
-
- if (val instanceof PortableObject)
- assert ((PortableObjectImpl)val).detached() : val;
- }
- }
-
- IgniteCache<Object, Object> c = jcache(0);
-
- for (int i = 0; i < ENTRY_CNT; i++)
- c.remove(i);
-
- if (offheapTiered()) {
- for (int k = 0; k < 100; k++)
- c.remove(k);
- }
-
- assertEquals(0, c.size());
- }
-
- /**
- * @return Cache mode.
- */
- protected abstract CacheMode cacheMode();
-
- /**
- * @return Atomicity mode.
- */
- protected abstract CacheAtomicityMode atomicityMode();
-
- /**
- * @return Distribution mode.
- */
- protected abstract NearCacheConfiguration nearConfiguration();
-
- /**
- * @return Grid count.
- */
- protected abstract int gridCount();
-
- /**
- * @throws Exception If failed.
- */
- @SuppressWarnings("unchecked")
- public void testCircularReference() throws Exception {
- IgniteCache c = keepPortableCache();
-
- TestReferenceObject obj1 = new TestReferenceObject();
-
- obj1.obj = new TestReferenceObject(obj1);
-
- c.put(1, obj1);
-
- PortableObject po = (PortableObject)c.get(1);
-
- String str = po.toString();
-
- log.info("toString: " + str);
-
- assertNotNull(str);
-
- assertTrue("Unexpected toString: " + str,
- str.startsWith("TestReferenceObject") && str.contains("obj=TestReferenceObject ["));
-
- TestReferenceObject obj1_r = po.deserialize();
-
- assertNotNull(obj1_r);
-
- TestReferenceObject obj2_r = obj1_r.obj;
-
- assertNotNull(obj2_r);
-
- assertSame(obj1_r, obj2_r.obj);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testGet() throws Exception {
- IgniteCache<Integer, TestObject> c = jcache(0);
-
- for (int i = 0; i < ENTRY_CNT; i++)
- c.put(i, new TestObject(i));
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- TestObject obj = c.get(i);
-
- assertEquals(i, obj.val);
- }
-
- IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- PortableObject po = kpc.get(i);
-
- assertEquals(i, (int)po.field("val"));
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testIterator() throws Exception {
- IgniteCache<Integer, TestObject> c = jcache(0);
-
- Map<Integer, TestObject> entries = new HashMap<>();
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- TestObject val = new TestObject(i);
-
- c.put(i, val);
-
- entries.put(i, val);
- }
-
- IgniteCache<Integer, PortableObject> prj = ((IgniteCacheProxy)c).keepPortable();
-
- Iterator<Cache.Entry<Integer, PortableObject>> it = prj.iterator();
-
- assertTrue(it.hasNext());
-
- while (it.hasNext()) {
- Cache.Entry<Integer, PortableObject> entry = it.next();
-
- assertTrue(entries.containsKey(entry.getKey()));
-
- TestObject o = entries.get(entry.getKey());
-
- PortableObject po = entry.getValue();
-
- assertEquals(o.val, (int)po.field("val"));
-
- entries.remove(entry.getKey());
- }
-
- assertEquals(0, entries.size());
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testCollection() throws Exception {
- IgniteCache<Integer, Collection<TestObject>> c = jcache(0);
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- Collection<TestObject> col = new ArrayList<>(3);
-
- for (int j = 0; j < 3; j++)
- col.add(new TestObject(i * 10 + j));
-
- c.put(i, col);
- }
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- Collection<TestObject> col = c.get(i);
-
- assertEquals(3, col.size());
-
- Iterator<TestObject> it = col.iterator();
-
- for (int j = 0; j < 3; j++) {
- assertTrue(it.hasNext());
-
- assertEquals(i * 10 + j, it.next().val);
- }
- }
-
- IgniteCache<Integer, Collection<PortableObject>> kpc = keepPortableCache();
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- Collection<PortableObject> col = kpc.get(i);
-
- assertEquals(3, col.size());
-
- Iterator<PortableObject> it = col.iterator();
-
- for (int j = 0; j < 3; j++) {
- assertTrue(it.hasNext());
-
- assertEquals(i * 10 + j, (int)it.next().field("val"));
- }
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testMap() throws Exception {
- IgniteCache<Integer, Map<Integer, TestObject>> c = jcache(0);
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- Map<Integer, TestObject> map = U.newHashMap(3);
-
- for (int j = 0; j < 3; j++) {
- int idx = i * 10 + j;
-
- map.put(idx, new TestObject(idx));
- }
-
- c.put(i, map);
- }
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- Map<Integer, TestObject> map = c.get(i);
-
- assertEquals(3, map.size());
-
- for (int j = 0; j < 3; j++) {
- int idx = i * 10 + j;
-
- assertEquals(idx, map.get(idx).val);
- }
- }
-
- IgniteCache<Integer, Map<Integer, PortableObject>> kpc = keepPortableCache();
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- Map<Integer, PortableObject> map = kpc.get(i);
-
- assertEquals(3, map.size());
-
- for (int j = 0; j < 3; j++) {
- int idx = i * 10 + j;
-
- assertEquals(idx, (int)map.get(idx).field("val"));
- }
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testGetAsync() throws Exception {
- IgniteCache<Integer, TestObject> c = jcache(0);
-
- IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
-
- for (int i = 0; i < ENTRY_CNT; i++)
- c.put(i, new TestObject(i));
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- cacheAsync.get(i);
- TestObject obj = cacheAsync.<TestObject>future().get();
-
- assertEquals(i, obj.val);
- }
-
- IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
-
- IgniteCache<Integer, PortableObject> cachePortableAsync = kpc.withAsync();
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- cachePortableAsync.get(i);
-
- PortableObject po = cachePortableAsync.<PortableObject>future().get();
-
- assertEquals(i, (int)po.field("val"));
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testGetTx() throws Exception {
- if (atomicityMode() != TRANSACTIONAL)
- return;
-
- IgniteCache<Integer, TestObject> c = jcache(0);
-
- for (int i = 0; i < ENTRY_CNT; i++)
- c.put(i, new TestObject(i));
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
- TestObject obj = c.get(i);
-
- assertEquals(i, obj.val);
-
- tx.commit();
- }
- }
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
- TestObject obj = c.get(i);
-
- assertEquals(i, obj.val);
-
- tx.commit();
- }
- }
-
- IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
- PortableObject po = kpc.get(i);
-
- assertEquals(i, (int)po.field("val"));
-
- tx.commit();
- }
- }
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
- PortableObject po = kpc.get(i);
-
- assertEquals(i, (int)po.field("val"));
-
- tx.commit();
- }
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testGetAsyncTx() throws Exception {
- if (atomicityMode() != TRANSACTIONAL)
- return;
-
- IgniteCache<Integer, TestObject> c = jcache(0);
-
- IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
-
- for (int i = 0; i < ENTRY_CNT; i++)
- c.put(i, new TestObject(i));
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
- cacheAsync.get(i);
-
- TestObject obj = cacheAsync.<TestObject>future().get();
-
- assertEquals(i, obj.val);
-
- tx.commit();
- }
- }
-
- IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
- IgniteCache<Integer, PortableObject> cachePortableAsync = kpc.withAsync();
-
- for (int i = 0; i < ENTRY_CNT; i++) {
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
- cachePortableAsync.get(i);
-
- PortableObject po = cachePortableAsync.<PortableObject>future().get();
-
- assertEquals(i, (int)po.field("val"));
-
- tx.commit();
- }
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testGetAll() throws Exception {
- IgniteCache<Integer, TestObject> c = jcache(0);
-
- for (int i = 0; i < ENTRY_CNT; i++)
- c.put(i, new TestObject(i));
-
- for (int i = 0; i < ENTRY_CNT; ) {
- Set<Integer> keys = new HashSet<>();
-
- for (int j = 0; j < 10; j++)
- keys.add(i++);
-
- Map<Integer, TestObject> objs = c.getAll(keys);
-
- assertEquals(10, objs.size());
-
- for (Map.Entry<Integer, TestObject> e : objs.entrySet())
- assertEquals(e.getKey().intValue(), e.getValue().val);
- }
-
- IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
-
- for (int i = 0; i < ENTRY_CNT; ) {
- Set<Integer> keys = new HashSet<>();
-
- for (int j = 0; j < 10; j++)
- keys.add(i++);
-
- Map<Integer, PortableObject> objs = kpc.getAll(keys);
-
- assertEquals(10, objs.size());
-
- for (Map.Entry<Integer, PortableObject> e : objs.entrySet())
- assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testGetAllAsync() throws Exception {
- IgniteCache<Integer, TestObject> c = jcache(0);
-
- IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
-
- for (int i = 0; i < ENTRY_CNT; i++)
- c.put(i, new TestObject(i));
-
- for (int i = 0; i < ENTRY_CNT; ) {
- Set<Integer> keys = new HashSet<>();
-
- for (int j = 0; j < 10; j++)
- keys.add(i++);
-
- cacheAsync.getAll(keys);
-
- Map<Integer, TestObject> objs = cacheAsync.<Map<Integer, TestObject>>future().get();
-
- assertEquals(10, objs.size());
-
- for (Map.Entry<Integer, TestObject> e : objs.entrySet())
- assertEquals(e.getKey().intValue(), e.getValue().val);
- }
-
- IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
- IgniteCache<Integer, PortableObject> cachePortableAsync = kpc.withAsync();
-
- for (int i = 0; i < ENTRY_CNT; ) {
- Set<Integer> keys = new HashSet<>();
-
- for (int j = 0; j < 10; j++)
- keys.add(i++);
-
-
- cachePortableAsync.getAll(keys);
-
- Map<Integer, PortableObject> objs = cachePortableAsync.<Map<Integer, PortableObject>>future().get();
-
- assertEquals(10, objs.size());
-
- for (Map.Entry<Integer, PortableObject> e : objs.entrySet())
- assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testGetAllTx() throws Exception {
- if (atomicityMode() != TRANSACTIONAL)
- return;
-
- IgniteCache<Integer, TestObject> c = jcache(0);
-
- for (int i = 0; i < ENTRY_CNT; i++)
- c.put(i, new TestObject(i));
-
- for (int i = 0; i < ENTRY_CNT; ) {
- Set<Integer> keys = new HashSet<>();
-
- for (int j = 0; j < 10; j++)
- keys.add(i++);
-
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
- Map<Integer, TestObject> objs = c.getAll(keys);
-
- assertEquals(10, objs.size());
-
- for (Map.Entry<Integer, TestObject> e : objs.entrySet())
- assertEquals(e.getKey().intValue(), e.getValue().val);
-
- tx.commit();
- }
-
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
- Map<Integer, TestObject> objs = c.getAll(keys);
-
- assertEquals(10, objs.size());
-
- for (Map.Entry<Integer, TestObject> e : objs.entrySet())
- assertEquals(e.getKey().intValue(), e.getValue().val);
-
- tx.commit();
- }
- }
-
- IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
-
- for (int i = 0; i < ENTRY_CNT; ) {
- Set<Integer> keys = new HashSet<>();
-
- for (int j = 0; j < 10; j++)
- keys.add(i++);
-
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
- Map<Integer, PortableObject> objs = kpc.getAll(keys);
-
- assertEquals(10, objs.size());
-
- for (Map.Entry<Integer, PortableObject> e : objs.entrySet())
- assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
-
- tx.commit();
- }
-
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
- Map<Integer, PortableObject> objs = kpc.getAll(keys);
-
- assertEquals(10, objs.size());
-
- for (Map.Entry<Integer, PortableObject> e : objs.entrySet())
- assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
-
- tx.commit();
- }
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testGetAllAsyncTx() throws Exception {
- if (atomicityMode() != TRANSACTIONAL)
- return;
-
- IgniteCache<Integer, TestObject> c = jcache(0);
- IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
-
- for (int i = 0; i < ENTRY_CNT; i++)
- c.put(i, new TestObject(i));
-
- for (int i = 0; i < ENTRY_CNT; ) {
- Set<Integer> keys = new HashSet<>();
-
- for (int j = 0; j < 10; j++)
- keys.add(i++);
-
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
- cacheAsync.getAll(keys);
-
- Map<Integer, TestObject> objs = cacheAsync.<Map<Integer, TestObject>>future().get();
-
- assertEquals(10, objs.size());
-
- for (Map.Entry<Integer, TestObject> e : objs.entrySet())
- assertEquals(e.getKey().intValue(), e.getValue().val);
-
- tx.commit();
- }
- }
-
- IgniteCache<Integer, PortableObject> cache = keepPortableCache();
-
- for (int i = 0; i < ENTRY_CNT; ) {
- Set<Integer> keys = new HashSet<>();
-
- for (int j = 0; j < 10; j++)
- keys.add(i++);
-
- IgniteCache<Integer, PortableObject> asyncCache = cache.withAsync();
-
- try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
- asyncCache.getAll(keys);
-
- Map<Integer, PortableObject> objs = asyncCache.<Map<Integer, PortableObject>>future().get();
-
- assertEquals(10, objs.size());
-
- for (Map.Entry<Integer, PortableObject> e : objs.entrySet())
- assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
-
- tx.commit();
- }
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testLoadCache() throws Exception {
- for (int i = 0; i < gridCount(); i++)
- jcache(i).localLoadCache(null);
-
- IgniteCache<Integer, TestObject> cache = jcache(0);
-
- assertEquals(3, cache.size(CachePeekMode.PRIMARY));
-
- assertEquals(1, cache.get(1).val);
- assertEquals(2, cache.get(2).val);
- assertEquals(3, cache.get(3).val);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testLoadCacheAsync() throws Exception {
- for (int i = 0; i < gridCount(); i++) {
- IgniteCache<Object, Object> jcache = jcache(i).withAsync();
-
- jcache.loadCache(null);
-
- jcache.future().get();
- }
-
- IgniteCache<Integer, TestObject> cache = jcache(0);
-
- assertEquals(3, cache.size(CachePeekMode.PRIMARY));
-
- assertEquals(1, cache.get(1).val);
- assertEquals(2, cache.get(2).val);
- assertEquals(3, cache.get(3).val);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testLoadCacheFilteredAsync() throws Exception {
- for (int i = 0; i < gridCount(); i++) {
- IgniteCache<Integer, TestObject> c = this.<Integer, TestObject>jcache(i).withAsync();
-
- c.loadCache(new P2<Integer, TestObject>() {
- @Override public boolean apply(Integer key, TestObject val) {
- return val.val < 3;
- }
- });
-
- c.future().get();
- }
-
- IgniteCache<Integer, TestObject> cache = jcache(0);
-
- assertEquals(2, cache.size(CachePeekMode.PRIMARY));
-
- assertEquals(1, cache.get(1).val);
- assertEquals(2, cache.get(2).val);
-
- assertNull(cache.get(3));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testTransform() throws Exception {
- IgniteCache<Integer, PortableObject> c = keepPortableCache();
-
- checkTransform(primaryKey(c));
-
- if (cacheMode() != CacheMode.LOCAL) {
- checkTransform(backupKey(c));
-
- if (nearConfiguration() != null)
- checkTransform(nearKey(c));
- }
- }
-
- /**
- * @return Cache with keep portable flag.
- */
- private <K, V> IgniteCache<K, V> keepPortableCache() {
- return ignite(0).cache(null).withKeepPortable();
- }
-
- /**
- * @param key Key.
- * @throws Exception If failed.
- */
- private void checkTransform(Integer key) throws Exception {
- log.info("Transform: " + key);
-
- IgniteCache<Integer, PortableObject> c = keepPortableCache();
-
- try {
- c.invoke(key, new EntryProcessor<Integer, PortableObject, Void>() {
- @Override public Void process(MutableEntry<Integer, PortableObject> e, Object... args) {
- PortableObject val = e.getValue();
-
- assertNull("Unexpected value: " + val, val);
-
- return null;
- }
- });
-
- jcache(0).put(key, new TestObject(1));
-
- c.invoke(key, new EntryProcessor<Integer, PortableObject, Void>() {
- @Override public Void process(MutableEntry<Integer, PortableObject> e, Object... args) {
- PortableObject val = e.getValue();
-
- assertNotNull("Unexpected value: " + val, val);
-
- assertEquals(new Integer(1), val.field("val"));
-
- Ignite ignite = e.unwrap(Ignite.class);
-
- IgnitePortables portables = ignite.portables();
-
- PortableBuilder builder = portables.builder(val);
-
- builder.setField("val", 2);
-
- e.setValue(builder.build());
-
- return null;
- }
- });
-
- PortableObject obj = c.get(key);
-
- assertEquals(new Integer(2), obj.field("val"));
-
- c.invoke(key, new EntryProcessor<Integer, PortableObject, Void>() {
- @Override public Void process(MutableEntry<Integer, PortableObject> e, Object... args) {
- PortableObject val = e.getValue();
-
- assertNotNull("Unexpected value: " + val, val);
-
- assertEquals(new Integer(2), val.field("val"));
-
- e.setValue(val);
-
- return null;
- }
- });
-
- obj = c.get(key);
-
- assertEquals(new Integer(2), obj.field("val"));
-
- c.invoke(key, new EntryProcessor<Integer, PortableObject, Void>() {
- @Override public Void process(MutableEntry<Integer, PortableObject> e, Object... args) {
- PortableObject val = e.getValue();
-
- assertNotNull("Unexpected value: " + val, val);
-
- assertEquals(new Integer(2), val.field("val"));
-
- e.remove();
-
- return null;
- }
- });
-
- assertNull(c.get(key));
- }
- finally {
- c.remove(key);
- }
- }
-
- /**
- *
- */
- private static class TestObject implements PortableMarshalAware {
- /** */
- private int val;
-
- /**
- */
- private TestObject() {
- // No-op.
- }
-
- /**
- * @param val Value.
- */
- private TestObject(int val) {
- this.val = val;
- }
-
- /** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
- writer.writeInt("val", val);
- }
-
- /** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
- val = reader.readInt("val");
- }
- }
-
- /**
- *
- */
- private static class TestReferenceObject implements PortableMarshalAware {
- /** */
- private TestReferenceObject obj;
-
- /**
- */
- private TestReferenceObject() {
- // No-op.
- }
-
- /**
- * @param obj Object.
- */
- private TestReferenceObject(TestReferenceObject obj) {
- this.obj = obj;
- }
-
- /** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
- writer.writeObject("obj", obj);
- }
-
- /** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
- obj = reader.readObject("obj");
- }
- }
-
- /**
- *
- */
- private static class TestStore extends CacheStoreAdapter<Integer, Object> {
- /** {@inheritDoc} */
- @Override public void loadCache(IgniteBiInClosure<Integer, Object> clo, Object... args) {
- for (int i = 1; i <= 3; i++)
- clo.apply(i, new TestObject(i));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Object load(Integer key) {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public void write(Cache.Entry<? extends Integer, ?> e) {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public void delete(Object key) {
- // No-op.
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java
index 7c605b5..1c842e1 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java
@@ -36,7 +36,7 @@ import org.jetbrains.annotations.Nullable;
import org.jsr166.ConcurrentHashMap8;
/**
- * Tests for cache store with portables.
+ * Tests for cache store with binary.
*/
public abstract class GridCachePortableStoreAbstractSelfTest extends GridCommonAbstractTest {
/** */
@@ -76,7 +76,7 @@ public abstract class GridCachePortableStoreAbstractSelfTest extends GridCommonA
}
/**
- * @return Keep portables in store flag.
+ * @return Keep binary in store flag.
*/
protected abstract boolean keepPortableInStore();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java
index 1c1c99e..8f81572 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.cache.portable;
import java.util.Map;
/**
- * Tests for cache store with portables.
+ * Tests for cache store with binary.
*/
public class GridCachePortableStoreObjectsSelfTest extends GridCachePortableStoreAbstractSelfTest {
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java
index 5c0fc8e..95101df 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java
@@ -17,10 +17,10 @@
package org.apache.ignite.internal.processors.cache.portable;
import java.util.Map;
-import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.binary.BinaryObject;
/**
- * Tests for cache store with portables.
+ * Tests for cache store with binary.
*/
public class GridCachePortableStorePortablesSelfTest extends GridCachePortableStoreAbstractSelfTest {
/** {@inheritDoc} */
@@ -47,11 +47,11 @@ public class GridCachePortableStorePortablesSelfTest extends GridCachePortableSt
for (int idx : idxs) {
Object val = map.get(portable(new Key(idx)));
- assertTrue(String.valueOf(val), val instanceof PortableObject);
+ assertTrue(String.valueOf(val), val instanceof BinaryObject);
- PortableObject po = (PortableObject)val;
+ BinaryObject po = (BinaryObject)val;
- assertEquals("Value", po.metaData().typeName());
+ assertEquals("Value", po.type().typeName());
assertEquals(new Integer(idx), po.field("idx"));
}
}
@@ -61,6 +61,6 @@ public class GridCachePortableStorePortablesSelfTest extends GridCachePortableSt
* @return Portable object.
*/
private Object portable(Object obj) {
- return grid().portables().toPortable(obj);
+ return grid().binary().toBinary(obj);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java
index 0db650e..d277801 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java
@@ -18,6 +18,7 @@
package org.apache.ignite.internal.processors.cache.portable;
import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.portable.PortableContext;
import org.apache.ignite.internal.portable.PortableMetaDataHandler;
import org.apache.ignite.internal.processors.cache.GridCacheEntryMemorySizeSelfTest;
@@ -25,8 +26,8 @@ import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.marshaller.MarshallerContextTestImpl;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
/**
*
@@ -39,14 +40,14 @@ public class GridPortableCacheEntryMemorySizeSelfTest extends GridCacheEntryMemo
marsh.setContext(new MarshallerContextTestImpl(null));
PortableContext pCtx = new PortableContext(new PortableMetaDataHandler() {
- @Override public void addMeta(int typeId, PortableMetadata meta) throws PortableException {
+ @Override public void addMeta(int typeId, BinaryType meta) throws BinaryObjectException {
// No-op
}
- @Override public PortableMetadata metadata(int typeId) throws PortableException {
+ @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
return null;
}
- }, null);
+ }, new IgniteConfiguration());
IgniteUtils.invoke(PortableMarshaller.class, marsh, "setPortableContext", pCtx);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
index a1a623b..4b7286a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
@@ -31,7 +31,7 @@ import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.binary.BinaryObject;
/**
* Tests that portable object is the same in cache entry and in index.
@@ -96,9 +96,9 @@ public abstract class GridPortableDuplicateIndexObjectsAbstractSelfTest extends
cache.put(key, new TestPortable(fieldOneVal, fieldTwoVal));
- IgniteCache<Integer, PortableObject> prj = grid(0).cache(null).withKeepPortable();
+ IgniteCache<Integer, BinaryObject> prj = grid(0).cache(null).withKeepBinary();
- PortableObject cacheVal = prj.get(key);
+ BinaryObject cacheVal = prj.get(key);
assertEquals(fieldOneVal, cacheVal.field("fieldOne"));
assertEquals(new Integer(fieldTwoVal), cacheVal.field("fieldTwo"));
@@ -108,7 +108,7 @@ public abstract class GridPortableDuplicateIndexObjectsAbstractSelfTest extends
assertEquals(1, row.size());
- PortableObject qryVal = (PortableObject)row.get(0);
+ BinaryObject qryVal = (BinaryObject)row.get(0);
assertEquals(fieldOneVal, qryVal.field("fieldOne"));
assertEquals(new Integer(fieldTwoVal), qryVal.field("fieldTwo"));
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java
index 836440a..58adfe3 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java
@@ -20,10 +20,10 @@ package org.apache.ignite.internal.processors.cache.portable.datastreaming;
import java.util.Collection;
import java.util.Map;
import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableObject;
import org.apache.ignite.stream.StreamReceiver;
/**
@@ -46,6 +46,11 @@ public class DataStreamProcessorPortableSelfTest extends DataStreamProcessorSelf
return new TestDataReceiver();
}
+ /** {@inheritDoc} */
+ @Override protected boolean customKeepBinary() {
+ return true;
+ }
+
/**
*
*/
@@ -55,9 +60,9 @@ public class DataStreamProcessorPortableSelfTest extends DataStreamProcessorSelf
Collection<Map.Entry<String, TestObject>> entries) {
for (Map.Entry<String, TestObject> e : entries) {
assertTrue(e.getKey() instanceof String);
- assertTrue(e.getValue() instanceof PortableObject);
+ assertTrue(String.valueOf(e.getValue()), e.getValue() instanceof BinaryObject);
- TestObject obj = ((PortableObject)e.getValue()).deserialize();
+ TestObject obj = ((BinaryObject)e.getValue()).deserialize();
cache.put(e.getKey(), new TestObject(obj.val + 1));
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java
index 2f7bdb0..3bc3575 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java
@@ -31,11 +31,11 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
@@ -54,7 +54,7 @@ public class GridDataStreamerImplSelfTest extends GridCommonAbstractTest {
/** Number of keys to load via data streamer. */
private static final int KEYS_COUNT = 1000;
- /** Flag indicating should be cache configured with portables or not. */
+ /** Flag indicating should be cache configured with binary or not. */
private static boolean portables;
/** {@inheritDoc} */
@@ -221,12 +221,12 @@ public class GridDataStreamerImplSelfTest extends GridCommonAbstractTest {
}
// Read random keys. Take values as PortableObject.
- IgniteCache<Integer, PortableObject> c2 = ((IgniteCacheProxy)c).keepPortable();
+ IgniteCache<Integer, BinaryObject> c2 = ((IgniteCacheProxy)c).keepPortable();
for (int i = 0; i < 100; i ++) {
Integer k = rnd.nextInt(KEYS_COUNT);
- PortableObject v = c2.get(k);
+ BinaryObject v = c2.get(k);
assertEquals(k, v.field("val"));
}
@@ -256,7 +256,7 @@ public class GridDataStreamerImplSelfTest extends GridCommonAbstractTest {
/**
*/
- private static class TestObject implements PortableMarshalAware, Serializable {
+ private static class TestObject implements Binarylizable, Serializable {
/** */
private int val;
@@ -289,19 +289,19 @@ public class GridDataStreamerImplSelfTest extends GridCommonAbstractTest {
}
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeInt("val", val);
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
val = reader.readInt("val");
}
}
/**
*/
- private static class TestObject2 implements PortableMarshalAware, Serializable {
+ private static class TestObject2 implements Binarylizable, Serializable {
/** */
private int val;
@@ -333,12 +333,12 @@ public class GridDataStreamerImplSelfTest extends GridCommonAbstractTest {
}
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeInt("val", val);
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
val = reader.readInt("val");
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
index 155ba48..d5639fd 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
@@ -18,10 +18,11 @@
package org.apache.ignite.internal.processors.cache.portable.distributed.dht;
import java.util.Collections;
+import org.apache.ignite.cache.CacheKeyConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.processors.cache.GridCacheAffinityRoutingSelfTest;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
/**
*
@@ -31,10 +32,13 @@ public class GridCacheAffinityRoutingPortableSelfTest extends GridCacheAffinityR
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
- PortableTypeConfiguration typeCfg = new PortableTypeConfiguration();
+ BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
typeCfg.setClassName(AffinityTestKey.class.getName());
- typeCfg.setAffinityKeyFieldName("affKey");
+
+ CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(AffinityTestKey.class.getName(), "affKey");
+
+ cfg.setCacheKeyCfg(keyCfg);
PortableMarshaller marsh = new PortableMarshaller();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
index 3f8cd1c..ee95194 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.cache.portable.distributed.dht;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractDataStreamerSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractDataStreamerSelfTest;
import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
import static org.apache.ignite.cache.CacheMode.PARTITIONED;
@@ -29,7 +29,7 @@ import static org.apache.ignite.cache.CacheMode.PARTITIONED;
*
*/
public class GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest extends
- GridCachePortableObjectsAbstractDataStreamerSelfTest {
+ GridCacheBinaryObjectsAbstractDataStreamerSelfTest {
/** {@inheritDoc} */
@Override protected CacheMode cacheMode() {
return PARTITIONED;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
index 8f3a05f..7fb63db 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.cache.portable.distributed.dht;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractMultiThreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractMultiThreadedSelfTest;
import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
import static org.apache.ignite.cache.CacheMode.PARTITIONED;
@@ -29,7 +29,7 @@ import static org.apache.ignite.cache.CacheMode.PARTITIONED;
*
*/
public class GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest extends
- GridCachePortableObjectsAbstractMultiThreadedSelfTest {
+ GridCacheBinaryObjectsAbstractMultiThreadedSelfTest {
/** {@inheritDoc} */
@Override protected CacheMode cacheMode() {
return PARTITIONED;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.java
new file mode 100644
index 0000000..79c69c4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.cache.portable.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest
+ extends GridCacheBinaryObjectsAtomicNearDisabledSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean offheapTiered() {
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java
new file mode 100644
index 0000000..fe46dea
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.cache.portable.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsAtomicNearDisabledSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return ATOMIC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 3;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.java
new file mode 100644
index 0000000..d692624
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.cache.portable.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsAtomicOffheapTieredSelfTest extends GridCacheBinaryObjectsAtomicSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean offheapTiered() {
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java
new file mode 100644
index 0000000..097d51b
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.cache.portable.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsAtomicSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return ATOMIC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return new NearCacheConfiguration();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 3;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
new file mode 100644
index 0000000..fde8233
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.cache.portable.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest
+ extends GridCacheBinaryObjectsPartitionedNearDisabledSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean offheapTiered() {
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java
new file mode 100644
index 0000000..e916a55
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.cache.portable.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsPartitionedNearDisabledSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return TRANSACTIONAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 3;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java
new file mode 100644
index 0000000..c6684d8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.cache.portable.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest
+ extends GridCacheBinaryObjectsPartitionedSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean offheapTiered() {
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java
new file mode 100644
index 0000000..80a13ec
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.cache.portable.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsPartitionedSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return TRANSACTIONAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return new NearCacheConfiguration();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 3;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
index c845257..0c6b77c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
@@ -33,7 +33,7 @@ public class GridCacheOffHeapTieredAtomicPortableSelfTest extends GridCacheOffHe
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- // Enable portables.
+ // Enable binary.
IgniteConfiguration cfg = super.getConfiguration(gridName);
PortableMarshaller marsh = new PortableMarshaller();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
index 1a0d601..215567c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
@@ -21,7 +21,7 @@ import java.util.Arrays;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionAtomicSelfTest;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.binary.BinaryObject;
/**
*
@@ -29,7 +29,7 @@ import org.apache.ignite.portable.PortableObject;
public class GridCacheOffHeapTieredEvictionAtomicPortableSelfTest extends GridCacheOffHeapTieredEvictionAtomicSelfTest {
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- // Enable portables.
+ // Enable binary.
IgniteConfiguration cfg = super.getConfiguration(gridName);
PortableMarshaller marsh = new PortableMarshaller();
@@ -66,7 +66,7 @@ public class GridCacheOffHeapTieredEvictionAtomicPortableSelfTest extends GridCa
/** {@inheritDoc} */
@Override public void checkValue(Object val) {
- PortableObject obj = (PortableObject)val;
+ BinaryObject obj = (BinaryObject)val;
assertEquals(expVal, obj.field("val"));
}
@@ -87,7 +87,7 @@ public class GridCacheOffHeapTieredEvictionAtomicPortableSelfTest extends GridCa
/** {@inheritDoc} */
@Override public void checkValue(Object val) {
- PortableObject obj = (PortableObject)val;
+ BinaryObject obj = (BinaryObject)val;
assertEquals(expVal, obj.field("val"));
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
index 60eed45..674e17a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
@@ -21,7 +21,7 @@ import java.util.Arrays;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.binary.BinaryObject;
/**
*
@@ -29,7 +29,7 @@ import org.apache.ignite.portable.PortableObject;
public class GridCacheOffHeapTieredEvictionPortableSelfTest extends GridCacheOffHeapTieredEvictionSelfTest {
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- // Enable portables.
+ // Enable binary.
IgniteConfiguration cfg = super.getConfiguration(gridName);
PortableMarshaller marsh = new PortableMarshaller();
@@ -66,7 +66,7 @@ public class GridCacheOffHeapTieredEvictionPortableSelfTest extends GridCacheOff
/** {@inheritDoc} */
@Override public void checkValue(Object val) {
- PortableObject obj = (PortableObject)val;
+ BinaryObject obj = (BinaryObject)val;
assertEquals(expVal, obj.field("val"));
}
@@ -87,7 +87,7 @@ public class GridCacheOffHeapTieredEvictionPortableSelfTest extends GridCacheOff
/** {@inheritDoc} */
@Override public void checkValue(Object val) {
- PortableObject obj = (PortableObject)val;
+ BinaryObject obj = (BinaryObject)val;
assertEquals(expVal, obj.field("val"));
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
index 6170e39..9f4e2c5 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
@@ -33,7 +33,7 @@ public class GridCacheOffHeapTieredPortableSelfTest extends GridCacheOffHeapTier
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- // Enable portables.
+ // Enable binary.
IgniteConfiguration cfg = super.getConfiguration(gridName);
PortableMarshaller marsh = new PortableMarshaller();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest.java
deleted file mode 100644
index a5c28f3..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.cache.portable.distributed.dht;
-
-/**
- *
- */
-public class GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest
- extends GridCachePortableObjectsAtomicNearDisabledSelfTest {
- /** {@inheritDoc} */
- @Override protected boolean offheapTiered() {
- return true;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledSelfTest.java
deleted file mode 100644
index 696c3ed..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCachePortableObjectsAtomicNearDisabledSelfTest extends GridCachePortableObjectsAbstractSelfTest {
- /** {@inheritDoc} */
- @Override protected CacheMode cacheMode() {
- return PARTITIONED;
- }
-
- /** {@inheritDoc} */
- @Override protected CacheAtomicityMode atomicityMode() {
- return ATOMIC;
- }
-
- /** {@inheritDoc} */
- @Override protected NearCacheConfiguration nearConfiguration() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override protected int gridCount() {
- return 3;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicOffheapTieredSelfTest.java
deleted file mode 100644
index 8e04fa1..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicOffheapTieredSelfTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.cache.portable.distributed.dht;
-
-/**
- *
- */
-public class GridCachePortableObjectsAtomicOffheapTieredSelfTest extends GridCachePortableObjectsAtomicSelfTest {
- /** {@inheritDoc} */
- @Override protected boolean offheapTiered() {
- return true;
- }
-}
\ No newline at end of file
[24/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java b/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java
deleted file mode 100644
index 1c63df7..0000000
--- a/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java
+++ /dev/null
@@ -1,370 +0,0 @@
-/*
- * 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;
-
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.TreeMap;
-import java.util.UUID;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableIdMapper;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableSerializer;
-import org.apache.ignite.portable.PortableTypeConfiguration;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Defines portable objects functionality. With portable objects you are able to:
- * <ul>
- * <li>Seamlessly interoperate between Java, .NET, and C++.</li>
- * <li>Make any object portable with zero code change to your existing code.</li>
- * <li>Nest portable objects within each other.</li>
- * <li>Automatically handle {@code circular} or {@code null} references.</li>
- * <li>Automatically convert collections and maps between Java, .NET, and C++.</li>
- * <li>
- * Optionally avoid deserialization of objects on the server side
- * (objects are stored in {@link PortableObject} format).
- * </li>
- * <li>Avoid need to have concrete class definitions on the server side.</li>
- * <li>Dynamically change structure of the classes without having to restart the cluster.</li>
- * <li>Index into portable objects for querying purposes.</li>
- * </ul>
- * <h1 class="header">Working With Portables Directly</h1>
- * Once an object is defined as portable,
- * Ignite will always store it in memory in the portable (i.e. binary) format.
- * User can choose to work either with the portable format or with the deserialized form
- * (assuming that class definitions are present in the classpath).
- * <p>
- * To work with the portable format directly, user should create a special cache projection
- * using IgniteCache.withKeepPortable() method and then retrieve individual fields as needed:
- * <pre name=code class=java>
- * IgniteCache<PortableObject, PortableObject> prj = cache.withKeepPortable();
- *
- * // Convert instance of MyKey to portable format.
- * // We could also use PortableBuilder to create the key in portable format directly.
- * PortableObject key = grid.portables().toPortable(new MyKey());
- *
- * PortableObject val = prj.get(key);
- *
- * String field = val.field("myFieldName");
- * </pre>
- * Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized
- * typed objects at all times. In this case we do incur the deserialization cost. However, if
- * {@link PortableMarshaller#isKeepDeserialized()} is {@code true} then Ignite will only deserialize on the first access
- * and will cache the deserialized object, so it does not have to be deserialized again:
- * <pre name=code class=java>
- * IgniteCache<MyKey.class, MyValue.class> cache = grid.cache(null);
- *
- * MyValue val = cache.get(new MyKey());
- *
- * // Normal java getter.
- * String fieldVal = val.getMyFieldName();
- * </pre>
- * If we used, for example, one of the automatically handled portable types for a key, like integer,
- * and still wanted to work with binary portable format for values, then we would declare cache projection
- * as follows:
- * <pre name=code class=java>
- * IgniteCache<Integer.class, PortableObject> prj = cache.withKeepPortable();
- * </pre>
- * <h1 class="header">Automatic Portable Types</h1>
- * Note that only portable classes are converted to {@link PortableObject} format. Following
- * classes are never converted (e.g., {@link #toPortable(Object)} method will return original
- * object, and instances of these classes will be stored in cache without changes):
- * <ul>
- * <li>All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)</li>
- * <li>Arrays of primitives (byte[], int[], ...)</li>
- * <li>{@link String} and array of {@link String}s</li>
- * <li>{@link UUID} and array of {@link UUID}s</li>
- * <li>{@link Date} and array of {@link Date}s</li>
- * <li>{@link Timestamp} and array of {@link Timestamp}s</li>
- * <li>Enums and array of enums</li>
- * <li>
- * Maps, collections and array of objects (but objects inside
- * them will still be converted if they are portable)
- * </li>
- * </ul>
- * <h1 class="header">Working With Maps and Collections</h1>
- * All maps and collections in the portable objects are serialized automatically. When working
- * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most
- * adequate collection or map in either language. For example, {@link ArrayList} in Java will become
- * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap}
- * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary}
- * in C#, etc.
- * <h1 class="header">Building Portable Objects</h1>
- * Ignite comes with {@link PortableBuilder} which allows to build portable objects dynamically:
- * <pre name=code class=java>
- * PortableBuilder builder = Ignition.ignite().portables().builder();
- *
- * builder.typeId("MyObject");
- *
- * builder.stringField("fieldA", "A");
- * build.intField("fieldB", "B");
- *
- * PortableObject portableObj = builder.build();
- * </pre>
- * For the cases when class definition is present
- * in the class path, it is also possible to populate a standard POJO and then
- * convert it to portable format, like so:
- * <pre name=code class=java>
- * MyObject obj = new MyObject();
- *
- * obj.setFieldA("A");
- * obj.setFieldB(123);
- *
- * PortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
- * </pre>
- * NOTE: you don't need to convert typed objects to portable format before storing
- * them in cache, Ignite will do that automatically.
- * <h1 class="header">Portable Metadata</h1>
- * Even though Ignite portable protocol only works with hash codes for type and field names
- * to achieve better performance, Ignite provides metadata for all portable types which
- * can be queried ar runtime via any of the {@link IgnitePortables#metadata(Class)}
- * methods. Having metadata also allows for proper formatting of {@code PortableObject#toString()} method,
- * even when portable objects are kept in binary format only, which may be necessary for audit reasons.
- * <h1 class="header">Dynamic Structure Changes</h1>
- * Since objects are always cached in the portable binary format, server does not need to
- * be aware of the class definitions. Moreover, if class definitions are not present or not
- * used on the server, then clients can continuously change the structure of the portable
- * objects without having to restart the cluster. For example, if one client stores a
- * certain class with fields A and B, and another client stores the same class with
- * fields B and C, then the server-side portable object will have the fields A, B, and C.
- * As the structure of a portable object changes, the new fields become available for SQL queries
- * automatically.
- * <h1 class="header">Configuration</h1>
- * By default all your objects are considered as portables and no specific configuration is needed.
- * However, in some cases, like when an object is used by both Java and .Net, you may need to specify portable objects
- * explicitly by calling {@link PortableMarshaller#setClassNames(Collection)}.
- * The only requirement Ignite imposes is that your object has an empty
- * constructor. Note, that since server side does not have to know the class definition,
- * you only need to list portable objects in configuration on the client side. However, if you
- * list them on the server side as well, then you get the ability to deserialize portable objects
- * into concrete types on the server as well as on the client.
- * <p>
- * Here is an example of portable configuration (note that star (*) notation is supported):
- * <pre name=code class=xml>
- * ...
- * <!-- Explicit portable objects configuration. -->
- * <property name="marshaller">
- * <bean class="org.apache.ignite.marshaller.portable.PortableMarshaller">
- * <property name="classNames">
- * <list>
- * <value>my.package.for.portable.objects.*</value>
- * <value>org.apache.ignite.examples.client.portable.Employee</value>
- * </list>
- * </property>
- * </bean>
- * </property>
- * ...
- * </pre>
- * or from code:
- * <pre name=code class=java>
- * IgniteConfiguration cfg = new IgniteConfiguration();
- *
- * PortableMarshaller marsh = new PortableMarshaller();
- *
- * marsh.setClassNames(Arrays.asList(
- * Employee.class.getName(),
- * Address.class.getName())
- * );
- *
- * cfg.setMarshaller(marsh);
- * </pre>
- * You can also specify class name for a portable object via {@link PortableTypeConfiguration}.
- * Do it in case if you need to override other configuration properties on per-type level, like
- * ID-mapper, or serializer.
- * <h1 class="header">Custom Affinity Keys</h1>
- * Often you need to specify an alternate key (not the cache key) for affinity routing whenever
- * storing objects in cache. For example, if you are caching {@code Employee} object with
- * {@code Organization}, and want to colocate employees with organization they work for,
- * so you can process them together, you need to specify an alternate affinity key.
- * With portable objects you would have to do it as following:
- * <pre name=code class=xml>
- * <property name="marshaller">
- * <bean class="org.gridgain.grid.marshaller.portable.PortableMarshaller">
- * ...
- * <property name="typeConfigurations">
- * <list>
- * <bean class="org.apache.ignite.portable.PortableTypeConfiguration">
- * <property name="className" value="org.apache.ignite.examples.client.portable.EmployeeKey"/>
- * <property name="affinityKeyFieldName" value="organizationId"/>
- * </bean>
- * </list>
- * </property>
- * ...
- * </bean>
- * </property>
- * </pre>
- * <h1 class="header">Serialization</h1>
- * Serialization and deserialization works out-of-the-box in Ignite. However, you can provide your own custom
- * serialization logic by optionally implementing {@link PortableMarshalAware} interface, like so:
- * <pre name=code class=java>
- * public class Address implements PortableMarshalAware {
- * private String street;
- * private int zip;
- *
- * // Empty constructor required for portable deserialization.
- * public Address() {}
- *
- * @Override public void writePortable(PortableWriter writer) throws PortableException {
- * writer.writeString("street", street);
- * writer.writeInt("zip", zip);
- * }
- *
- * @Override public void readPortable(PortableReader reader) throws PortableException {
- * street = reader.readString("street");
- * zip = reader.readInt("zip");
- * }
- * }
- * </pre>
- * Alternatively, if you cannot change class definitions, you can provide custom serialization
- * logic in {@link PortableSerializer} either globally in {@link PortableMarshaller} or
- * for a specific type via {@link PortableTypeConfiguration} instance.
- * <p>
- * Similar to java serialization you can use {@code writeReplace()} and {@code readResolve()} methods.
- * <ul>
- * <li>
- * {@code readResolve} is defined as follows: {@code ANY-ACCESS-MODIFIER Object readResolve()}.
- * It may be used to replace the de-serialized object by another one of your choice.
- * </li>
- * <li>
- * {@code writeReplace} is defined as follows: {@code ANY-ACCESS-MODIFIER Object writeReplace()}. This method
- * allows the developer to provide a replacement object that will be serialized instead of the original one.
- * </li>
- * </ul>
- *
- * <h1 class="header">Custom ID Mappers</h1>
- * Ignite implementation uses name hash codes to generate IDs for class names or field names
- * internally. However, in cases when you want to provide your own ID mapping schema,
- * you can provide your own {@link PortableIdMapper} implementation.
- * <p>
- * ID-mapper may be provided either globally in {@link PortableMarshaller},
- * or for a specific type via {@link PortableTypeConfiguration} instance.
- * <h1 class="header">Query Indexing</h1>
- * Portable objects can be indexed for querying by specifying index fields in
- * {@link org.apache.ignite.cache.CacheTypeMetadata} inside of specific
- * {@link org.apache.ignite.configuration.CacheConfiguration} instance,
- * like so:
- * <pre name=code class=xml>
- * ...
- * <bean class="org.apache.ignite.cache.CacheConfiguration">
- * ...
- * <property name="typeMetadata">
- * <list>
- * <bean class="CacheTypeMetadata">
- * <property name="type" value="Employee"/>
- *
- * <!-- Fields to index in ascending order. -->
- * <property name="ascendingFields">
- * <map>
- * <entry key="name" value="java.lang.String"/>
- *
- * <!-- Nested portable objects can also be indexed. -->
- * <entry key="address.zip" value="java.lang.Integer"/>
- * </map>
- * </property>
- * </bean>
- * </list>
- * </property>
- * </bean>
- * </pre>
- */
-public interface IgnitePortables {
- /**
- * Gets type ID for given type name.
- *
- * @param typeName Type name.
- * @return Type ID.
- */
- public int typeId(String typeName);
-
- /**
- * Converts provided object to instance of {@link PortableObject}.
- *
- * @param obj Object to convert.
- * @return Converted object.
- * @throws PortableException In case of error.
- */
- public <T> T toPortable(@Nullable Object obj) throws PortableException;
-
- /**
- * Creates new portable builder.
- *
- * @param typeId ID of the type.
- * @return Newly portable builder.
- */
- public PortableBuilder builder(int typeId);
-
- /**
- * Creates new portable builder.
- *
- * @param typeName Type name.
- * @return Newly portable builder.
- */
- public PortableBuilder builder(String typeName);
-
- /**
- * Creates portable builder initialized by existing portable object.
- *
- * @param portableObj Portable object to initialize builder.
- * @return Portable builder.
- */
- public PortableBuilder builder(PortableObject portableObj);
-
- /**
- * Gets metadata for provided class.
- *
- * @param cls Class.
- * @return Metadata.
- * @throws PortableException In case of error.
- */
- @Nullable public PortableMetadata metadata(Class<?> cls) throws PortableException;
-
- /**
- * Gets metadata for provided class name.
- *
- * @param typeName Type name.
- * @return Metadata.
- * @throws PortableException In case of error.
- */
- @Nullable public PortableMetadata metadata(String typeName) throws PortableException;
-
- /**
- * Gets metadata for provided type ID.
- *
- * @param typeId Type ID.
- * @return Metadata.
- * @throws PortableException In case of error.
- */
- @Nullable public PortableMetadata metadata(int typeId) throws PortableException;
-
- /**
- * Gets metadata for all known types.
- *
- * @return Metadata.
- * @throws PortableException In case of error.
- */
- public Collection<PortableMetadata> metadata() throws PortableException;
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryField.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryField.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryField.java
new file mode 100644
index 0000000..35aa191
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryField.java
@@ -0,0 +1,46 @@
+/*
+ * 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.binary;
+
+/**
+ * Binary object field. Can be used to speed object field lookup.
+ */
+public interface BinaryField {
+ /**
+ * Get field's name.
+ *
+ * @return Name.
+ */
+ public String name();
+
+ /**
+ * Check whether field exists in the object.
+ *
+ * @param obj Object.
+ * @return {@code True} if exists.
+ */
+ public boolean exists(BinaryObject obj);
+
+ /**
+ * Get field's value from the given object.
+ *
+ * @param obj Object.
+ * @return Value.
+ */
+ public <T> T value(BinaryObject obj);
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryInvalidTypeException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryInvalidTypeException.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryInvalidTypeException.java
new file mode 100644
index 0000000..2fe1e79
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryInvalidTypeException.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.binary;
+
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Exception indicating that class needed for deserialization of binary object does not exist.
+ * <p>
+ * Thrown from {@link BinaryObject#deserialize()} method.
+ */
+public class BinaryInvalidTypeException extends BinaryObjectException {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /**
+ * Creates invalid class exception with error message.
+ *
+ * @param msg Error message.
+ */
+ public BinaryInvalidTypeException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Creates invalid class exception with {@link Throwable} as a cause.
+ *
+ * @param cause Cause.
+ */
+ public BinaryInvalidTypeException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Creates invalid class exception with error message and {@link Throwable} as a cause.
+ *
+ * @param msg Error message.
+ * @param cause Cause.
+ */
+ public BinaryInvalidTypeException(String msg, @Nullable Throwable cause) {
+ super(msg, cause);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryObject.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryObject.java
new file mode 100644
index 0000000..f48f350
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryObject.java
@@ -0,0 +1,163 @@
+/*
+ * 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.binary;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.TreeMap;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ * Wrapper for binary object in binary format. Once an object is defined as binary,
+ * Ignite will always store it in memory in the binary format.
+ * User can choose to work either with the binary format or with the deserialized form
+ * (assuming that class definitions are present in the classpath).
+ * <p>
+ * <b>NOTE:</b> user does not need to (and should not) implement this interface directly.
+ * <p>
+ * To work with the binary format directly, user should create a cache projection
+ * over {@code BinaryObject} class and then retrieve individual fields as needed:
+ * <pre name=code class=java>
+ * IgniteCache<BinaryObject, BinaryObject> prj = cache.withKeepBinary();
+ *
+ * // Convert instance of MyKey to binary format.
+ * // We could also use BinaryObjectBuilder to create the key in binary format directly.
+ * BinaryObject key = ignite.binary().toBinary(new MyKey());
+ *
+ * BinaryObject val = prj.get(key);
+ *
+ * String field = val.field("myFieldName");
+ * </pre>
+ * Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized
+ * typed objects at all times. In this case we do incur the deserialization cost. However, if
+ * {@link PortableMarshaller#isKeepDeserialized()} is {@code true} then Ignite will only deserialize on the first access
+ * and will cache the deserialized object, so it does not have to be deserialized again:
+ * <pre name=code class=java>
+ * IgniteCache<MyKey.class, MyValue.class> cache = grid.cache(null);
+ *
+ * MyValue val = cache.get(new MyKey());
+ *
+ * // Normal java getter.
+ * String fieldVal = val.getMyFieldName();
+ * </pre>
+ * <h1 class="header">Working With Maps and Collections</h1>
+ * All maps and collections in binary objects are serialized automatically. When working
+ * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most
+ * adequate collection or map in either language. For example, {@link ArrayList} in Java will become
+ * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap}
+ * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary}
+ * in C#, etc.
+ * <h1 class="header">Dynamic Structure Changes</h1>
+ * Since objects are always cached in the binary format, server does not need to
+ * be aware of the class definitions. Moreover, if class definitions are not present or not
+ * used on the server, then clients can continuously change the structure of the binary
+ * objects without having to restart the cluster. For example, if one client stores a
+ * certain class with fields A and B, and another client stores the same class with
+ * fields B and C, then the server-side binary object will have the fields A, B, and C.
+ * As the structure of a binary object changes, the new fields become available for SQL queries
+ * automatically.
+ * <h1 class="header">Building Binary Objects</h1>
+ * Ignite comes with {@link BinaryObjectBuilder} which allows to build binary objects dynamically:
+ * <pre name=code class=java>
+ * BinaryObjectBuilder builder = Ignition.ignite().binary().builder("org.project.MyObject");
+ *
+ * builder.setField("fieldA", "A");
+ * builder.setField("fieldB", "B");
+ *
+ * BinaryObject binaryObj = builder.build();
+ * </pre>
+ * For the cases when class definition is present
+ * in the class path, it is also possible to populate a standard POJO and then
+ * convert it to binary format, like so:
+ * <pre name=code class=java>
+ * MyObject obj = new MyObject();
+ *
+ * obj.setFieldA("A");
+ * obj.setFieldB(123);
+ *
+ * BinaryObject binaryObj = Ignition.ignite().binary().toBinary(obj);
+ * </pre>
+ * <h1 class="header">Binary Type Metadata</h1>
+ * Even though Ignite binary protocol only works with hash codes for type and field names
+ * to achieve better performance, Ignite provides metadata for all binary types which
+ * can be queried ar runtime via any of the {@link org.apache.ignite.IgniteBinary#metadata(Class)}
+ * methods. Having metadata also allows for proper formatting of {@code BinaryObject.toString()} method,
+ * even when binary objects are kept in binary format only, which may be necessary for audit reasons.
+ */
+public interface BinaryObject extends Serializable, Cloneable {
+ /**
+ * Gets binary object type ID.
+ *
+ * @return Type ID.
+ */
+ public int typeId();
+
+ /**
+ * Gets type information for this binary object.
+ *
+ * @return Binary object type information.
+ * @throws BinaryObjectException In case of error.
+ */
+ public BinaryType type() throws BinaryObjectException;
+
+ /**
+ * Gets field value.
+ *
+ * @param fieldName Field name.
+ * @return Field value.
+ * @throws BinaryObjectException In case of any other error.
+ * TODO ignite-1282 remove.
+ */
+ public <F> F field(String fieldName) throws BinaryObjectException;
+
+ /**
+ * Checks whether field is set.
+ ** TODO ignite-1282 remove.
+ *
+ * @param fieldName Field name.
+ * @return {@code true} if field is set.
+ */
+ public boolean hasField(String fieldName);
+
+ /**
+ * Gets field descriptor.
+ *
+ * @param fieldName Field name.
+ * @return Field descriptor.
+ * @throws BinaryObjectException If failed.
+ */
+ public BinaryField fieldDescriptor(String fieldName) throws BinaryObjectException;
+
+ /**
+ * Gets fully deserialized instance of binary object.
+ *
+ * @return Fully deserialized instance of binary object.
+ * @throws BinaryInvalidTypeException If class doesn't exist.
+ * @throws BinaryObjectException In case of any other error.
+ */
+ public <T> T deserialize() throws BinaryObjectException;
+
+ /**
+ * Copies this binary object.
+ *
+ * @return Copy of this binary object.
+ */
+ public BinaryObject clone() throws CloneNotSupportedException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryObjectBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryObjectBuilder.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryObjectBuilder.java
new file mode 100644
index 0000000..507b0fc
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryObjectBuilder.java
@@ -0,0 +1,136 @@
+/*
+ * 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.binary;
+
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Binary object builder. Provides ability to build binary objects dynamically without having class definitions.
+ * <p>
+ * Here is an example of how a binary object can be built dynamically:
+ * <pre name=code class=java>
+ * BinaryObjectBuilder builder = Ignition.ignite().binary().builder("org.project.MyObject");
+ *
+ * builder.setField("fieldA", "A");
+ * builder.setField("fieldB", "B");
+ *
+ * BinaryObject binaryObj = builder.build();
+ * </pre>
+ *
+ * <p>
+ * Also builder can be initialized by existing binary object. This allows changing some fields without affecting
+ * other fields.
+ * <pre name=code class=java>
+ * BinaryObjectBuilder builder = Ignition.ignite().binary().builder(person);
+ *
+ * builder.setField("name", "John");
+ *
+ * person = builder.build();
+ * </pre>
+ * </p>
+ *
+ * If you need to modify nested binary object you can get builder for nested object using
+ * {@link #getField(String)}, changes made on nested builder will affect parent object,
+ * for example:
+ *
+ * <pre name=code class=java>
+ * BinaryObjectBuilder personBuilder = grid.binary().createBuilder(personBinaryObj);
+ * BinaryObjectBuilder addressBuilder = personBuilder.setField("address");
+ *
+ * addressBuilder.setField("city", "New York");
+ *
+ * personBinaryObj = personBuilder.build();
+ *
+ * // Should be "New York".
+ * String city = personBinaryObj.getField("address").getField("city");
+ * </pre>
+ *
+ * @see org.apache.ignite.IgniteBinary#builder(int)
+ * @see org.apache.ignite.IgniteBinary#builder(String)
+ * @see org.apache.ignite.IgniteBinary#builder(BinaryObject)
+ */
+public interface BinaryObjectBuilder {
+ /**
+ * Returns value assigned to the specified field.
+ * If the value is a binary object instance of {@code BinaryObjectBuilder} will be returned,
+ * which can be modified.
+ * <p>
+ * Collections and maps returned from this method are modifiable.
+ *
+ * @param name Field name.
+ * @return Filed value.
+ */
+ public <T> T getField(String name);
+
+ /**
+ * Sets field value.
+ *
+ * @param name Field name.
+ * @param val Field value (cannot be {@code null}).
+ * @see BinaryObject#type()
+ */
+ public BinaryObjectBuilder setField(String name, Object val);
+
+ /**
+ * Sets field value with value type specification.
+ * <p>
+ * Field type is needed for proper metadata update.
+ *
+ * @param name Field name.
+ * @param val Field value.
+ * @param type Field type.
+ * @see BinaryObject#type()
+ */
+ public <T> BinaryObjectBuilder setField(String name, @Nullable T val, Class<? super T> type);
+
+ /**
+ * Sets field value.
+ * <p>
+ * This method should be used if field is binary object.
+ *
+ * @param name Field name.
+ * @param builder Builder for object field.
+ */
+ public BinaryObjectBuilder setField(String name, @Nullable BinaryObjectBuilder builder);
+
+ /**
+ * Removes field from this builder.
+ *
+ * @param fieldName Field name.
+ * @return {@code this} instance for chaining.
+ */
+ public BinaryObjectBuilder removeField(String fieldName);
+
+ /**
+ * Sets hash code for resulting binary object returned by {@link #build()} method.
+ * <p>
+ * If not set {@code 0} is used.
+ *
+ * @param hashCode Hash code.
+ * @return {@code this} instance for chaining.
+ */
+ public BinaryObjectBuilder hashCode(int hashCode);
+
+ /**
+ * Builds binary object.
+ *
+ * @return Binary object.
+ * @throws BinaryObjectException In case of error.
+ */
+ public BinaryObject build() throws BinaryObjectException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryObjectException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryObjectException.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryObjectException.java
new file mode 100644
index 0000000..4305382
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryObjectException.java
@@ -0,0 +1,57 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.IgniteException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Exception indicating binary object serialization error.
+ */
+public class BinaryObjectException extends IgniteException {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /**
+ * Creates binary exception with error message.
+ *
+ * @param msg Error message.
+ */
+ public BinaryObjectException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Creates binary exception with {@link Throwable} as a cause.
+ *
+ * @param cause Cause.
+ */
+ public BinaryObjectException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Creates binary exception with error message and {@link Throwable} as a cause.
+ *
+ * @param msg Error message.
+ * @param cause Cause.
+ */
+ public BinaryObjectException(String msg, @Nullable Throwable cause) {
+ super(msg, cause);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawReader.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawReader.java
new file mode 100644
index 0000000..7ff515a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawReader.java
@@ -0,0 +1,240 @@
+/*
+ * 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.binary;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Raw reader for binary objects. Raw reader does not use field name hash codes, therefore,
+ * making the format even more compact. However, if the raw reader is used,
+ * dynamic structure changes to the binary objects are not supported.
+ */
+public interface BinaryRawReader {
+ /**
+ * @return Byte value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public byte readByte() throws BinaryObjectException;
+
+ /**
+ * @return Short value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public short readShort() throws BinaryObjectException;
+
+ /**
+ * @return Integer value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public int readInt() throws BinaryObjectException;
+
+ /**
+ * @return Long value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public long readLong() throws BinaryObjectException;
+
+ /**
+ * @return Float value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public float readFloat() throws BinaryObjectException;
+
+ /**
+ * @return Double value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public double readDouble() throws BinaryObjectException;
+
+ /**
+ * @return Char value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public char readChar() throws BinaryObjectException;
+
+ /**
+ * @return Boolean value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public boolean readBoolean() throws BinaryObjectException;
+
+ /**
+ * @return Decimal value.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public BigDecimal readDecimal() throws BinaryObjectException;
+
+ /**
+ * @return String value.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public String readString() throws BinaryObjectException;
+
+ /**
+ * @return UUID.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public UUID readUuid() throws BinaryObjectException;
+
+ /**
+ * @return Date.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public Date readDate() throws BinaryObjectException;
+
+ /**
+ * @return Timestamp.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public Timestamp readTimestamp() throws BinaryObjectException;
+
+ /**
+ * @return Object.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public <T> T readObject() throws BinaryObjectException;
+
+ /**
+ * @return Byte array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public byte[] readByteArray() throws BinaryObjectException;
+
+ /**
+ * @return Short array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public short[] readShortArray() throws BinaryObjectException;
+
+ /**
+ * @return Integer array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public int[] readIntArray() throws BinaryObjectException;
+
+ /**
+ * @return Long array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public long[] readLongArray() throws BinaryObjectException;
+
+ /**
+ * @return Float array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public float[] readFloatArray() throws BinaryObjectException;
+
+ /**
+ * @return Byte array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public double[] readDoubleArray() throws BinaryObjectException;
+
+ /**
+ * @return Char array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public char[] readCharArray() throws BinaryObjectException;
+
+ /**
+ * @return Boolean array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public boolean[] readBooleanArray() throws BinaryObjectException;
+
+ /**
+ * @return Decimal array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public BigDecimal[] readDecimalArray() throws BinaryObjectException;
+
+ /**
+ * @return String array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public String[] readStringArray() throws BinaryObjectException;
+
+ /**
+ * @return UUID array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public UUID[] readUuidArray() throws BinaryObjectException;
+
+ /**
+ * @return Date array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public Date[] readDateArray() throws BinaryObjectException;
+
+ /**
+ * @return Timestamp array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public Timestamp[] readTimestampArray() throws BinaryObjectException;
+
+ /**
+ * @return Object array.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public Object[] readObjectArray() throws BinaryObjectException;
+
+ /**
+ * @return Collection.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public <T> Collection<T> readCollection() throws BinaryObjectException;
+
+ /**
+ * @param colCls Collection class.
+ * @return Collection.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public <T> Collection<T> readCollection(Class<? extends Collection<T>> colCls)
+ throws BinaryObjectException;
+
+ /**
+ * @return Map.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public <K, V> Map<K, V> readMap() throws BinaryObjectException;
+
+ /**
+ * @param mapCls Map class.
+ * @return Map.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public <K, V> Map<K, V> readMap(Class<? extends Map<K, V>> mapCls) throws BinaryObjectException;
+
+ /**
+ * @return Value.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public <T extends Enum<?>> T readEnum() throws BinaryObjectException;
+
+ /**
+ * @return Value.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable public <T extends Enum<?>> T[] readEnumArray() throws BinaryObjectException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawWriter.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawWriter.java
new file mode 100644
index 0000000..f283c06
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawWriter.java
@@ -0,0 +1,225 @@
+/*
+ * 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.binary;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Raw writer for binary object. Raw writer does not write field name hash codes, therefore,
+ * making the format even more compact. However, if the raw writer is used,
+ * dynamic structure changes to the binary objects are not supported.
+ */
+public interface BinaryRawWriter {
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeByte(byte val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeShort(short val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeInt(int val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeLong(long val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeFloat(float val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDouble(double val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeChar(char val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeBoolean(boolean val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDecimal(@Nullable BigDecimal val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeString(@Nullable String val) throws BinaryObjectException;
+
+ /**
+ * @param val UUID to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeUuid(@Nullable UUID val) throws BinaryObjectException;
+
+ /**
+ * @param val Date to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDate(@Nullable Date val) throws BinaryObjectException;
+
+ /**
+ * @param val Timestamp to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeTimestamp(@Nullable Timestamp val) throws BinaryObjectException;
+
+ /**
+ * @param obj Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeObject(@Nullable Object obj) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeByteArray(@Nullable byte[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeShortArray(@Nullable short[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeIntArray(@Nullable int[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeLongArray(@Nullable long[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeFloatArray(@Nullable float[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDoubleArray(@Nullable double[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeCharArray(@Nullable char[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeBooleanArray(@Nullable boolean[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDecimalArray(@Nullable BigDecimal[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeStringArray(@Nullable String[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeUuidArray(@Nullable UUID[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDateArray(@Nullable Date[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeTimestampArray(@Nullable Timestamp[] val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeObjectArray(@Nullable Object[] val) throws BinaryObjectException;
+
+ /**
+ * @param col Collection to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <T> void writeCollection(@Nullable Collection<T> col) throws BinaryObjectException;
+
+ /**
+ * @param map Map to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <K, V> void writeMap(@Nullable Map<K, V> map) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <T extends Enum<?>> void writeEnum(T val) throws BinaryObjectException;
+
+ /**
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <T extends Enum<?>> void writeEnumArray(T[] val) throws BinaryObjectException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryReader.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryReader.java
new file mode 100644
index 0000000..8a89a87
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryReader.java
@@ -0,0 +1,290 @@
+/*
+ * 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.binary;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Reader for portable objects used in {@link Binarylizable} implementations.
+ * Useful for the cases when user wants a fine-grained control over serialization.
+ * <p>
+ * Note that Ignite never writes full strings for field or type names. Instead,
+ * for performance reasons, Ignite writes integer hash codes for type and field names.
+ * It has been tested that hash code conflicts for the type names or the field names
+ * within the same type are virtually non-existent and, to gain performance, it is safe
+ * to work with hash codes. For the cases when hash codes for different types or fields
+ * actually do collide, Ignite provides {@link BinaryTypeIdMapper} which
+ * allows to override the automatically generated hash code IDs for the type and field names.
+ */
+public interface BinaryReader {
+ /**
+ * @param fieldName Field name.
+ * @return Byte value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public byte readByte(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Short value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public short readShort(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Integer value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public int readInt(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Long value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public long readLong(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @throws BinaryObjectException In case of error.
+ * @return Float value.
+ */
+ public float readFloat(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Double value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public double readDouble(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Char value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public char readChar(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Boolean value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public boolean readBoolean(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Decimal value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public BigDecimal readDecimal(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return String value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public String readString(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return UUID.
+ * @throws BinaryObjectException In case of error.
+ */
+ public UUID readUuid(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Date.
+ * @throws BinaryObjectException In case of error.
+ */
+ public Date readDate(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Timestamp.
+ * @throws BinaryObjectException In case of error.
+ */
+ public Timestamp readTimestamp(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Object.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <T> T readObject(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Byte array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public byte[] readByteArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Short array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public short[] readShortArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Integer array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public int[] readIntArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Long array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public long[] readLongArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Float array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public float[] readFloatArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Byte array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public double[] readDoubleArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Char array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public char[] readCharArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Boolean array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public boolean[] readBooleanArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Decimal array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public BigDecimal[] readDecimalArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return String array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public String[] readStringArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return UUID array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public UUID[] readUuidArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Date array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public Date[] readDateArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Timestamp array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public Timestamp[] readTimestampArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Object array.
+ * @throws BinaryObjectException In case of error.
+ */
+ public Object[] readObjectArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Collection.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <T> Collection<T> readCollection(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param colCls Collection class.
+ * @return Collection.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <T> Collection<T> readCollection(String fieldName, Class<? extends Collection<T>> colCls)
+ throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Map.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <K, V> Map<K, V> readMap(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param mapCls Map class.
+ * @return Map.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <K, V> Map<K, V> readMap(String fieldName, Class<? extends Map<K, V>> mapCls)
+ throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <T extends Enum<?>> T readEnum(String fieldName) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Value.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <T extends Enum<?>> T[] readEnumArray(String fieldName) throws BinaryObjectException;
+
+ /**
+ * Gets raw reader. Raw reader does not use field name hash codes, therefore,
+ * making the format even more compact. However, if the raw reader is used,
+ * dynamic structure changes to the binary objects are not supported.
+ *
+ * @return Raw reader.
+ */
+ public BinaryRawReader rawReader();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinarySerializer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinarySerializer.java b/modules/core/src/main/java/org/apache/ignite/binary/BinarySerializer.java
new file mode 100644
index 0000000..6fa4237
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinarySerializer.java
@@ -0,0 +1,49 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ * Interface that allows to implement custom serialization logic for binary objects.
+ * Can be used instead of {@link Binarylizable} in case if the class
+ * cannot be changed directly.
+ * <p>
+ * Binary serializer can be configured for all binary objects via
+ * {@link PortableMarshaller#getSerializer()} method, or for a specific
+ * binary type via {@link BinaryTypeConfiguration#getSerializer()} method.
+ */
+public interface BinarySerializer {
+ /**
+ * Writes fields to provided writer.
+ *
+ * @param obj Empty object.
+ * @param writer Binary object writer.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException;
+
+ /**
+ * Reads fields from provided reader.
+ *
+ * @param obj Empty object
+ * @param reader Binary object reader.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryType.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryType.java
new file mode 100644
index 0000000..d149fd4
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryType.java
@@ -0,0 +1,59 @@
+/*
+ * 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.binary;
+
+import java.util.Collection;
+
+/**
+ * Binary type meta data. Metadata for binary types can be accessed from any of the
+ * {@link org.apache.ignite.IgniteBinary#metadata(String)} methods.
+ * Having metadata also allows for proper formatting of {@code BinaryObject#toString()} method,
+ * even when binary objects are kept in binary format only, which may be necessary for audit reasons.
+ */
+public interface BinaryType {
+ /**
+ * Gets binary type name.
+ *
+ * @return Binary type name.
+ */
+ public String typeName();
+
+ /**
+ * Gets collection of all field names for this binary type.
+ *
+ * @return Collection of all field names for this binary type.
+ */
+ public Collection<String> fields();
+
+ /**
+ * Gets name of the field type for a given field.
+ *
+ * @param fieldName Field name.
+ * @return Field type name.
+ */
+ public String fieldTypeName(String fieldName);
+
+ /**
+ * Binary objects can optionally specify custom key-affinity mapping in the
+ * configuration. This method returns the name of the field which should be
+ * used for the key-affinity mapping.
+ *
+ * @return Affinity key field name.
+ */
+ public String affinityKeyFieldName();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryTypeConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryTypeConfiguration.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryTypeConfiguration.java
new file mode 100644
index 0000000..3b73edb
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryTypeConfiguration.java
@@ -0,0 +1,156 @@
+/*
+ * 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.binary;
+
+import java.util.Collection;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ * Defines configuration properties for a specific binary type. Providing per-type
+ * configuration is optional, as it is generally enough, and also optional, to provide global binary
+ * configuration using {@link PortableMarshaller#setClassNames(Collection)}.
+ * However, this class allows you to change configuration properties for a specific
+ * binary type without affecting configuration for other binary types.
+ * <p>
+ * Per-type binary configuration can be specified in {@link PortableMarshaller#getTypeConfigurations()} method.
+ */
+public class BinaryTypeConfiguration {
+ /** Class name. */
+ private String clsName;
+
+ /** ID mapper. */
+ private BinaryTypeIdMapper idMapper;
+
+ /** Serializer. */
+ private BinarySerializer serializer;
+
+ /** Meta data enabled flag. */
+ // TODO ignite-1282.
+ private Boolean metaDataEnabled;
+
+ /** Keep deserialized flag. */
+ private Boolean keepDeserialized;
+
+ /**
+ */
+ public BinaryTypeConfiguration() {
+ // No-op.
+ }
+
+ /**
+ * @param clsName Class name.
+ */
+ public BinaryTypeConfiguration(String clsName) {
+ this.clsName = clsName;
+ }
+
+ /**
+ * Gets type name.
+ *
+ * @return Type name.
+ */
+ public String getClassName() {
+ return clsName;
+ }
+
+ /**
+ * Sets type name.
+ *
+ * @param clsName Type name.
+ */
+ public void setClassName(String clsName) {
+ this.clsName = clsName;
+ }
+
+ /**
+ * Gets ID mapper.
+ *
+ * @return ID mapper.
+ */
+ public BinaryTypeIdMapper getIdMapper() {
+ return idMapper;
+ }
+
+ /**
+ * Sets ID mapper.
+ *
+ * @param idMapper ID mapper.
+ */
+ public void setIdMapper(BinaryTypeIdMapper idMapper) {
+ this.idMapper = idMapper;
+ }
+
+ /**
+ * Gets serializer.
+ *
+ * @return Serializer.
+ */
+ public BinarySerializer getSerializer() {
+ return serializer;
+ }
+
+ /**
+ * Sets serializer.
+ *
+ * @param serializer Serializer.
+ */
+ public void setSerializer(BinarySerializer serializer) {
+ this.serializer = serializer;
+ }
+
+ /**
+ * Defines whether meta data is collected for this type. If provided, this value will override
+ * {@link PortableMarshaller#isMetaDataEnabled()} property.
+ *
+ * @return Whether meta data is collected.
+ */
+ public Boolean isMetaDataEnabled() {
+ return metaDataEnabled;
+ }
+
+ /**
+ * @param metaDataEnabled Whether meta data is collected.
+ */
+ public void setMetaDataEnabled(Boolean metaDataEnabled) {
+ this.metaDataEnabled = metaDataEnabled;
+ }
+
+ /**
+ * Defines whether {@link BinaryObject} should cache deserialized instance. If provided,
+ * this value will override {@link PortableMarshaller#isKeepDeserialized()}
+ * property.
+ *
+ * @return Whether deserialized value is kept.
+ */
+ public Boolean isKeepDeserialized() {
+ return keepDeserialized;
+ }
+
+ /**
+ * @param keepDeserialized Whether deserialized value is kept.
+ */
+ public void setKeepDeserialized(Boolean keepDeserialized) {
+ this.keepDeserialized = keepDeserialized;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(BinaryTypeConfiguration.class, this, super.toString());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryTypeIdMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryTypeIdMapper.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryTypeIdMapper.java
new file mode 100644
index 0000000..4825f8c
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryTypeIdMapper.java
@@ -0,0 +1,56 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ * Type and field ID mapper for binary objects. Ignite never writes full
+ * strings for field or type names. Instead, for performance reasons, Ignite
+ * writes integer hash codes for type and field names. It has been tested that
+ * hash code conflicts for the type names or the field names
+ * within the same type are virtually non-existent and, to gain performance, it is safe
+ * to work with hash codes. For the cases when hash codes for different types or fields
+ * actually do collide {@code BinaryTypeIdMapper} allows to override the automatically
+ * generated hash code IDs for the type and field names.
+ * <p>
+ * Binary ID mapper can be configured for all binary objects via {@link PortableMarshaller#getIdMapper()} method,
+ * or for a specific binary type via {@link BinaryTypeConfiguration#getIdMapper()} method.
+ */
+public interface BinaryTypeIdMapper {
+ /**
+ * Gets type ID for provided class name.
+ * <p>
+ * If {@code 0} is returned, hash code of class simple name will be used.
+ *
+ * @param clsName Class name.
+ * @return Type ID.
+ */
+ public int typeId(String clsName);
+
+ /**
+ * Gets ID for provided field.
+ * <p>
+ * If {@code 0} is returned, hash code of field name will be used.
+ *
+ * @param typeId Type ID.
+ * @param fieldName Field name.
+ * @return Field ID.
+ */
+ public int fieldId(int typeId, String fieldName);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/binary/BinaryWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/binary/BinaryWriter.java b/modules/core/src/main/java/org/apache/ignite/binary/BinaryWriter.java
new file mode 100644
index 0000000..0ea4416
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryWriter.java
@@ -0,0 +1,273 @@
+/*
+ * 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.binary;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Writer for binary object used in {@link Binarylizable} implementations.
+ * Useful for the cases when user wants a fine-grained control over serialization.
+ * <p>
+ * Note that Ignite never writes full strings for field or type names. Instead,
+ * for performance reasons, Ignite writes integer hash codes for type and field names.
+ * It has been tested that hash code conflicts for the type names or the field names
+ * within the same type are virtually non-existent and, to gain performance, it is safe
+ * to work with hash codes. For the cases when hash codes for different types or fields
+ * actually do collide, Ignite provides {@link BinaryTypeIdMapper} which
+ * allows to override the automatically generated hash code IDs for the type and field names.
+ */
+public interface BinaryWriter {
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeByte(String fieldName, byte val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeShort(String fieldName, short val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeInt(String fieldName, int val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeLong(String fieldName, long val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeFloat(String fieldName, float val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDouble(String fieldName, double val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeChar(String fieldName, char val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeBoolean(String fieldName, boolean val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeString(String fieldName, @Nullable String val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val UUID to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeUuid(String fieldName, @Nullable UUID val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Date to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDate(String fieldName, @Nullable Date val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Timestamp to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param obj Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeObject(String fieldName, @Nullable Object obj) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeByteArray(String fieldName, @Nullable byte[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeShortArray(String fieldName, @Nullable short[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeIntArray(String fieldName, @Nullable int[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeLongArray(String fieldName, @Nullable long[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeFloatArray(String fieldName, @Nullable float[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDoubleArray(String fieldName, @Nullable double[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeCharArray(String fieldName, @Nullable char[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeBooleanArray(String fieldName, @Nullable boolean[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeStringArray(String fieldName, @Nullable String[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeDateArray(String fieldName, @Nullable Date[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public void writeObjectArray(String fieldName, @Nullable Object[] val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param col Collection to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <T> void writeCollection(String fieldName, @Nullable Collection<T> col) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param map Map to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws BinaryObjectException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws BinaryObjectException In case of error.
+ */
+ public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws BinaryObjectException;
+
+ /**
+ * Gets raw writer. Raw writer does not write field name hash codes, therefore,
+ * making the format even more compact. However, if the raw writer is used,
+ * dynamic structure changes to the binary objects are not supported.
+ *
+ * @return Raw writer.
+ */
+ public BinaryRawWriter rawWriter();
+}
\ No newline at end of file
[06/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderAdditionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderAdditionalSelfTest.java
deleted file mode 100644
index d8eff6d..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderAdditionalSelfTest.java
+++ /dev/null
@@ -1,1289 +0,0 @@
-/*
- * 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.portable;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import java.lang.reflect.Field;
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.UUID;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgnitePortables;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.portable.builder.PortableBuilderEnum;
-import org.apache.ignite.internal.portable.builder.PortableBuilderImpl;
-import org.apache.ignite.internal.portable.mutabletest.GridPortableMarshalerAwareTestClass;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
-import org.apache.ignite.internal.processors.cache.portable.IgnitePortablesImpl;
-import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.junit.Assert;
-
-import static org.apache.ignite.cache.CacheMode.REPLICATED;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.Address;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.AddressBook;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.Company;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectAllTypes;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectArrayList;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectContainer;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectEnum;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectInner;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectOuter;
-
-/**
- *
- */
-public class GridPortableBuilderAdditionalSelfTest extends GridCommonAbstractTest {
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- CacheConfiguration cacheCfg = new CacheConfiguration();
-
- cacheCfg.setCacheMode(REPLICATED);
-
- cfg.setCacheConfiguration(cacheCfg);
-
- PortableMarshaller marsh = new PortableMarshaller();
-
- marsh.setClassNames(Arrays.asList("org.apache.ignite.internal.portable.mutabletest.*"));
-
- marsh.setConvertStringToBytes(useUtf8());
-
- cfg.setMarshaller(marsh);
-
- return cfg;
- }
-
- /** {@inheritDoc} */
- @Override protected void beforeTestsStarted() throws Exception {
- startGrids(1);
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTestsStopped() throws Exception {
- stopAllGrids();
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTest() throws Exception {
- jcache(0).clear();
- }
-
- /**
- * @return Whether to use UTF8 strings.
- */
- protected boolean useUtf8() {
- return true;
- }
-
- /**
- * @return Portables API.
- */
- protected IgnitePortables portables() {
- return grid(0).portables();
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testSimpleTypeFieldRead() throws Exception {
- TestObjectAllTypes exp = new TestObjectAllTypes();
-
- exp.setDefaultData();
-
- PortableBuilder mutPo = wrap(exp);
-
- for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
- Object expVal = field.get(exp);
- Object actVal = mutPo.getField(field.getName());
-
- switch (field.getName()) {
- case "anEnum":
- assertEquals(((PortableBuilderEnum)actVal).getOrdinal(), ((Enum)expVal).ordinal());
- break;
-
- case "enumArr": {
- PortableBuilderEnum[] actArr = (PortableBuilderEnum[])actVal;
- Enum[] expArr = (Enum[])expVal;
-
- assertEquals(expArr.length, actArr.length);
-
- for (int i = 0; i < actArr.length; i++)
- assertEquals(expArr[i].ordinal(), actArr[i].getOrdinal());
-
- break;
- }
-
- case "entry":
- assertEquals(((Map.Entry)expVal).getKey(), ((Map.Entry)actVal).getKey());
- assertEquals(((Map.Entry)expVal).getValue(), ((Map.Entry)actVal).getValue());
- break;
-
- default:
- assertTrue(field.getName(), Objects.deepEquals(expVal, actVal));
- break;
- }
- }
- }
-
- /**
- *
- */
- public void testSimpleTypeFieldSerialize() {
- TestObjectAllTypes exp = new TestObjectAllTypes();
-
- exp.setDefaultData();
-
- PortableBuilderImpl mutPo = wrap(exp);
-
- TestObjectAllTypes res = mutPo.build().deserialize();
-
- GridTestUtils.deepEquals(exp, res);
- }
-
- /**
- * @throws Exception If any error occurs.
- */
- public void testSimpleTypeFieldOverride() throws Exception {
- TestObjectAllTypes exp = new TestObjectAllTypes();
-
- exp.setDefaultData();
-
- PortableBuilderImpl mutPo = wrap(new TestObjectAllTypes());
-
- for (Field field : TestObjectAllTypes.class.getDeclaredFields())
- mutPo.setField(field.getName(), field.get(exp));
-
- TestObjectAllTypes res = mutPo.build().deserialize();
-
- GridTestUtils.deepEquals(exp, res);
- }
-
- /**
- * @throws Exception If any error occurs.
- */
- public void testSimpleTypeFieldSetNull() throws Exception {
- TestObjectAllTypes exp = new TestObjectAllTypes();
-
- exp.setDefaultData();
-
- PortableBuilderImpl mutPo = wrap(exp);
-
- for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
- if (!field.getType().isPrimitive())
- mutPo.setField(field.getName(), null);
- }
-
- TestObjectAllTypes res = mutPo.build().deserialize();
-
- for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
- if (!field.getType().isPrimitive())
- assertNull(field.getName(), field.get(res));
- }
- }
-
- /**
- * @throws IgniteCheckedException If any error occurs.
- */
- public void testMakeCyclicDependency() throws IgniteCheckedException {
- TestObjectOuter outer = new TestObjectOuter();
- outer.inner = new TestObjectInner();
-
- PortableBuilderImpl mutOuter = wrap(outer);
-
- PortableBuilderImpl mutInner = mutOuter.getField("inner");
-
- mutInner.setField("outer", mutOuter);
- mutInner.setField("foo", mutInner);
-
- TestObjectOuter res = mutOuter.build().deserialize();
-
- assertEquals(res, res.inner.outer);
- assertEquals(res.inner, res.inner.foo);
- }
-
- /**
- *
- */
- public void testDateArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.dateArr = new Date[] {new Date(11111), new Date(11111), new Date(11111)};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- Date[] arr = mutObj.getField("dateArr");
- arr[0] = new Date(22222);
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new Date[] {new Date(22222), new Date(11111), new Date(11111)}, res.dateArr);
- }
-
- /**
- *
- */
- public void testTimestampArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.tsArr = new Timestamp[] {new Timestamp(111222333), new Timestamp(222333444)};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- Timestamp[] arr = mutObj.getField("tsArr");
- arr[0] = new Timestamp(333444555);
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new Timestamp[] {new Timestamp(333444555), new Timestamp(222333444)}, res.tsArr);
- }
-
- /**
- *
- */
- public void testUUIDArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.uuidArr = new UUID[] {new UUID(1, 1), new UUID(1, 1), new UUID(1, 1)};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- UUID[] arr = mutObj.getField("uuidArr");
- arr[0] = new UUID(2, 2);
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new UUID[] {new UUID(2, 2), new UUID(1, 1), new UUID(1, 1)}, res.uuidArr);
- }
-
- /**
- *
- */
- public void testDecimalArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.bdArr = new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- BigDecimal[] arr = mutObj.getField("bdArr");
- arr[0] = new BigDecimal(2000);
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)},
- res.bdArr);
- }
-
- /**
- *
- */
- public void testBooleanArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.zArr = new boolean[] {false, false, false};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- boolean[] arr = mutObj.getField("zArr");
- arr[0] = true;
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- boolean[] expected = new boolean[] {true, false, false};
-
- assertEquals(expected.length, res.zArr.length);
-
- for (int i = 0; i < expected.length; i++)
- assertEquals(expected[i], res.zArr[i]);
- }
-
- /**
- *
- */
- public void testCharArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.cArr = new char[] {'a', 'a', 'a'};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- char[] arr = mutObj.getField("cArr");
- arr[0] = 'b';
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new char[] {'b', 'a', 'a'}, res.cArr);
- }
-
- /**
- *
- */
- public void testDoubleArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.dArr = new double[] {1.0, 1.0, 1.0};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- double[] arr = mutObj.getField("dArr");
- arr[0] = 2.0;
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new double[] {2.0, 1.0, 1.0}, res.dArr, 0);
- }
-
- /**
- *
- */
- public void testFloatArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.fArr = new float[] {1.0f, 1.0f, 1.0f};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- float[] arr = mutObj.getField("fArr");
- arr[0] = 2.0f;
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new float[] {2.0f, 1.0f, 1.0f}, res.fArr, 0);
- }
-
- /**
- *
- */
- public void testLongArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.lArr = new long[] {1, 1, 1};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- long[] arr = mutObj.getField("lArr");
- arr[0] = 2;
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new long[] {2, 1, 1}, res.lArr);
- }
-
- /**
- *
- */
- public void testIntArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.iArr = new int[] {1, 1, 1};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- int[] arr = mutObj.getField("iArr");
- arr[0] = 2;
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new int[] {2, 1, 1}, res.iArr);
- }
-
- /**
- *
- */
- public void testShortArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.sArr = new short[] {1, 1, 1};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- short[] arr = mutObj.getField("sArr");
- arr[0] = 2;
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new short[] {2, 1, 1}, res.sArr);
- }
-
- /**
- *
- */
- public void testByteArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.bArr = new byte[] {1, 1, 1};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- byte[] arr = mutObj.getField("bArr");
- arr[0] = 2;
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new byte[] {2, 1, 1}, res.bArr);
- }
-
- /**
- *
- */
- public void testStringArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.strArr = new String[] {"a", "a", "a"};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- String[] arr = mutObj.getField("strArr");
- arr[0] = "b";
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new String[] {"b", "a", "a"}, res.strArr);
- }
-
- /**
- *
- */
- public void testModifyObjectArray() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = new Object[] {"a"};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- Object[] arr = mutObj.getField("foo");
-
- Assert.assertArrayEquals(new Object[] {"a"}, arr);
-
- arr[0] = "b";
-
- TestObjectContainer res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new Object[] {"b"}, (Object[])res.foo);
- }
-
- /**
- *
- */
- public void testOverrideObjectArrayField() {
- PortableBuilderImpl mutObj = wrap(new TestObjectContainer());
-
- Object[] createdArr = {mutObj, "a", 1, new String[] {"s", "s"}, new byte[] {1, 2}, new UUID(3, 0)};
-
- mutObj.setField("foo", createdArr.clone());
-
- TestObjectContainer res = mutObj.build().deserialize();
-
- createdArr[0] = res;
-
- assertTrue(Objects.deepEquals(createdArr, res.foo));
- }
-
- /**
- *
- */
- public void testDeepArray() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = new Object[] {new Object[] {"a", obj}};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- Object[] arr = (Object[])mutObj.<Object[]>getField("foo")[0];
-
- assertEquals("a", arr[0]);
- assertSame(mutObj, arr[1]);
-
- arr[0] = mutObj;
-
- TestObjectContainer res = mutObj.build().deserialize();
-
- arr = (Object[])((Object[])res.foo)[0];
-
- assertSame(arr[0], res);
- assertSame(arr[0], arr[1]);
- }
-
- /**
- *
- */
- public void testArrayListRead() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = Lists.newArrayList(obj, "a");
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- List<Object> list = mutObj.getField("foo");
-
- assert list.equals(Lists.newArrayList(mutObj, "a"));
- }
-
- /**
- *
- */
- public void testArrayListOverride() {
- TestObjectContainer obj = new TestObjectContainer();
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- ArrayList<Object> list = Lists.newArrayList(mutObj, "a", Lists.newArrayList(1, 2));
-
- mutObj.setField("foo", list);
-
- TestObjectContainer res = mutObj.build().deserialize();
-
- list.set(0, res);
-
- assertNotSame(list, res.foo);
- assertEquals(list, res.foo);
- }
-
- /**
- *
- */
- public void testArrayListModification() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = Lists.newArrayList("a", "b", "c");
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- List<String> list = mutObj.getField("foo");
-
- list.add("!"); // "a", "b", "c", "!"
- list.add(0, "_"); // "_", "a", "b", "c", "!"
-
- String s = list.remove(1); // "_", "b", "c", "!"
- assertEquals("a", s);
-
- assertEquals(Arrays.asList("c", "!"), list.subList(2, 4));
- assertEquals(1, list.indexOf("b"));
- assertEquals(1, list.lastIndexOf("b"));
-
- TestObjectContainer res = mutObj.build().deserialize();
-
- assertTrue(res.foo instanceof ArrayList);
- assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
- }
-
- /**
- *
- */
- public void testArrayListClear() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = Lists.newArrayList("a", "b", "c");
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- List<String> list = mutObj.getField("foo");
-
- list.clear();
-
- assertEquals(Collections.emptyList(), mutObj.build().<TestObjectContainer>deserialize().foo);
- }
-
- /**
- *
- */
- public void testArrayListWriteUnmodifiable() {
- TestObjectContainer obj = new TestObjectContainer();
-
- ArrayList<Object> src = Lists.newArrayList(obj, "a", "b", "c");
-
- obj.foo = src;
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- TestObjectContainer deserialized = mutObj.build().deserialize();
-
- List<Object> res = (List<Object>)deserialized.foo;
-
- src.set(0, deserialized);
-
- assertEquals(src, res);
- }
-
- /**
- *
- */
- public void testLinkedListRead() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = Lists.newLinkedList(Arrays.asList(obj, "a"));
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- List<Object> list = mutObj.getField("foo");
-
- assert list.equals(Lists.newLinkedList(Arrays.asList(mutObj, "a")));
- }
-
- /**
- *
- */
- public void testLinkedListOverride() {
- TestObjectContainer obj = new TestObjectContainer();
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- List<Object> list = Lists.newLinkedList(Arrays.asList(mutObj, "a", Lists.newLinkedList(Arrays.asList(1, 2))));
-
- mutObj.setField("foo", list);
-
- TestObjectContainer res = mutObj.build().deserialize();
-
- list.set(0, res);
-
- assertNotSame(list, res.foo);
- assertEquals(list, res.foo);
- }
-
- /**
- *
- */
- public void testLinkedListModification() {
- TestObjectContainer obj = new TestObjectContainer();
-
- obj.foo = Lists.newLinkedList(Arrays.asList("a", "b", "c"));
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- List<String> list = mutObj.getField("foo");
-
- list.add("!"); // "a", "b", "c", "!"
- list.add(0, "_"); // "_", "a", "b", "c", "!"
-
- String s = list.remove(1); // "_", "b", "c", "!"
- assertEquals("a", s);
-
- assertEquals(Arrays.asList("c", "!"), list.subList(2, 4));
- assertEquals(1, list.indexOf("b"));
- assertEquals(1, list.lastIndexOf("b"));
-
- TestObjectContainer res = mutObj.build().deserialize();
-
- assertTrue(res.foo instanceof LinkedList);
- assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
- }
-
- /**
- *
- */
- public void testLinkedListWriteUnmodifiable() {
- TestObjectContainer obj = new TestObjectContainer();
-
- LinkedList<Object> src = Lists.newLinkedList(Arrays.asList(obj, "a", "b", "c"));
-
- obj.foo = src;
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- TestObjectContainer deserialized = mutObj.build().deserialize();
-
- List<Object> res = (List<Object>)deserialized.foo;
-
- src.set(0, deserialized);
-
- assertEquals(src, res);
- }
-
- /**
- *
- */
- public void testHashSetRead() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = Sets.newHashSet(obj, "a");
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- Set<Object> set = mutObj.getField("foo");
-
- assert set.equals(Sets.newHashSet(mutObj, "a"));
- }
-
- /**
- *
- */
- public void testHashSetOverride() {
- TestObjectContainer obj = new TestObjectContainer();
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- Set<Object> c = Sets.newHashSet(mutObj, "a", Sets.newHashSet(1, 2));
-
- mutObj.setField("foo", c);
-
- TestObjectContainer res = mutObj.build().deserialize();
-
- c.remove(mutObj);
- c.add(res);
-
- assertNotSame(c, res.foo);
- assertEquals(c, res.foo);
- }
-
- /**
- *
- */
- public void testHashSetModification() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = Sets.newHashSet("a", "b", "c");
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- Set<String> set = mutObj.getField("foo");
-
- set.remove("b");
- set.add("!");
-
- assertEquals(Sets.newHashSet("a", "!", "c"), set);
- assertTrue(set.contains("a"));
- assertTrue(set.contains("!"));
-
- TestObjectContainer res = mutObj.build().deserialize();
-
- assertTrue(res.foo instanceof HashSet);
- assertEquals(Sets.newHashSet("a", "!", "c"), res.foo);
- }
-
- /**
- *
- */
- public void testHashSetWriteUnmodifiable() {
- TestObjectContainer obj = new TestObjectContainer();
-
- Set<Object> src = Sets.newHashSet(obj, "a", "b", "c");
-
- obj.foo = src;
-
- TestObjectContainer deserialized = wrap(obj).build().deserialize();
-
- Set<Object> res = (Set<Object>)deserialized.foo;
-
- src.remove(obj);
- src.add(deserialized);
-
- assertEquals(src, res);
- }
-
- /**
- *
- */
- public void testMapRead() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = Maps.newHashMap(ImmutableMap.of(obj, "a", "b", obj));
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- Map<Object, Object> map = mutObj.getField("foo");
-
- assert map.equals(ImmutableMap.of(mutObj, "a", "b", mutObj));
- }
-
- /**
- *
- */
- public void testMapOverride() {
- TestObjectContainer obj = new TestObjectContainer();
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- Map<Object, Object> map = Maps.newHashMap(ImmutableMap.of(mutObj, "a", "b", mutObj));
-
- mutObj.setField("foo", map);
-
- TestObjectContainer res = mutObj.build().deserialize();
-
- assertEquals(ImmutableMap.of(res, "a", "b", res), res.foo);
- }
-
- /**
- *
- */
- public void testMapModification() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b"));
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- Map<Object, Object> map = mutObj.getField("foo");
-
- map.put(3, mutObj);
- Object rmv = map.remove(1);
-
- assertEquals("a", rmv);
-
- TestObjectContainer res = mutObj.build().deserialize();
-
- assertEquals(ImmutableMap.of(2, "b", 3, res), res.foo);
- }
-
- /**
- *
- */
- public void testEnumArrayModification() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
-
- obj.enumArr = new TestObjectEnum[] {TestObjectEnum.A, TestObjectEnum.B};
-
- PortableBuilderImpl mutObj = wrap(obj);
-
- PortableBuilderEnum[] arr = mutObj.getField("enumArr");
- arr[0] = new PortableBuilderEnum(mutObj.typeId(), TestObjectEnum.B);
-
- TestObjectAllTypes res = mutObj.build().deserialize();
-
- Assert.assertArrayEquals(new TestObjectEnum[] {TestObjectEnum.A, TestObjectEnum.B}, res.enumArr);
- }
-
- /**
- *
- */
- public void testEditObjectWithRawData() {
- GridPortableMarshalerAwareTestClass obj = new GridPortableMarshalerAwareTestClass();
-
- obj.s = "a";
- obj.sRaw = "aa";
-
- PortableBuilderImpl mutableObj = wrap(obj);
-
- mutableObj.setField("s", "z");
-
- GridPortableMarshalerAwareTestClass res = mutableObj.build().deserialize();
- assertEquals("z", res.s);
- assertEquals("aa", res.sRaw);
- }
-
- /**
- *
- */
- public void testHashCode() {
- TestObjectContainer obj = new TestObjectContainer();
-
- PortableBuilderImpl mutableObj = wrap(obj);
-
- assertEquals(obj.hashCode(), mutableObj.build().hashCode());
-
- mutableObj.hashCode(25);
-
- assertEquals(25, mutableObj.build().hashCode());
- }
-
- /**
- *
- */
- public void testCollectionsInCollection() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = Lists.newArrayList(
- Lists.newArrayList(1, 2),
- Lists.newLinkedList(Arrays.asList(1, 2)),
- Sets.newHashSet("a", "b"),
- Sets.newLinkedHashSet(Arrays.asList("a", "b")),
- Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b")));
-
- TestObjectContainer deserialized = wrap(obj).build().deserialize();
-
- assertEquals(obj.foo, deserialized.foo);
- }
-
- /**
- *
- */
- public void testMapEntryModification() {
- TestObjectContainer obj = new TestObjectContainer();
- obj.foo = ImmutableMap.of(1, "a").entrySet().iterator().next();
-
- PortableBuilderImpl mutableObj = wrap(obj);
-
- Map.Entry<Object, Object> entry = mutableObj.getField("foo");
-
- assertEquals(1, entry.getKey());
- assertEquals("a", entry.getValue());
-
- entry.setValue("b");
-
- TestObjectContainer res = mutableObj.build().deserialize();
-
- assertEquals(new GridMapEntry<>(1, "b"), res.foo);
- }
-
- /**
- *
- */
- public void testMapEntryOverride() {
- TestObjectContainer obj = new TestObjectContainer();
-
- PortableBuilderImpl mutableObj = wrap(obj);
-
- mutableObj.setField("foo", new GridMapEntry<>(1, "a"));
-
- TestObjectContainer res = mutableObj.build().deserialize();
-
- assertEquals(new GridMapEntry<>(1, "a"), res.foo);
- }
-
- /**
- *
- */
- public void testMetadataChangingDoublePut() {
- PortableBuilderImpl mutableObj = wrap(new TestObjectContainer());
-
- mutableObj.setField("xx567", "a");
- mutableObj.setField("xx567", "b");
-
- mutableObj.build();
-
- PortableMetadata metadata = portables().metadata(TestObjectContainer.class);
-
- assertEquals("String", metadata.fieldTypeName("xx567"));
- }
-
- /**
- *
- */
- public void testMetadataChangingDoublePut2() {
- PortableBuilderImpl mutableObj = wrap(new TestObjectContainer());
-
- mutableObj.setField("xx567", "a");
- mutableObj.setField("xx567", "b");
-
- mutableObj.build();
-
- PortableMetadata metadata = portables().metadata(TestObjectContainer.class);
-
- assertEquals("String", metadata.fieldTypeName("xx567"));
- }
-
- /**
- *
- */
- public void testMetadataChanging() {
- TestObjectContainer c = new TestObjectContainer();
-
- PortableBuilderImpl mutableObj = wrap(c);
-
- mutableObj.setField("intField", 1);
- mutableObj.setField("intArrField", new int[] {1});
- mutableObj.setField("arrField", new String[] {"1"});
- mutableObj.setField("strField", "1");
- mutableObj.setField("colField", Lists.newArrayList("1"));
- mutableObj.setField("mapField", Maps.newHashMap(ImmutableMap.of(1, "1")));
- mutableObj.setField("enumField", TestObjectEnum.A);
- mutableObj.setField("enumArrField", new Enum[] {TestObjectEnum.A});
-
- mutableObj.build();
-
- PortableMetadata metadata = portables().metadata(c.getClass());
-
- assertTrue(metadata.fields().containsAll(Arrays.asList("intField", "intArrField", "arrField", "strField",
- "colField", "mapField", "enumField", "enumArrField")));
-
- assertEquals("int", metadata.fieldTypeName("intField"));
- assertEquals("int[]", metadata.fieldTypeName("intArrField"));
- assertEquals("String[]", metadata.fieldTypeName("arrField"));
- assertEquals("String", metadata.fieldTypeName("strField"));
- assertEquals("Collection", metadata.fieldTypeName("colField"));
- assertEquals("Map", metadata.fieldTypeName("mapField"));
- assertEquals("Enum", metadata.fieldTypeName("enumField"));
- assertEquals("Enum[]", metadata.fieldTypeName("enumArrField"));
- }
-
- /**
- *
- */
- public void testDateInObjectField() {
- TestObjectContainer obj = new TestObjectContainer();
-
- obj.foo = new Date();
-
- PortableBuilderImpl mutableObj = wrap(obj);
-
- assertEquals(Date.class, mutableObj.getField("foo").getClass());
- }
-
- /**
- *
- */
- public void testTimestampInObjectField() {
- TestObjectContainer obj = new TestObjectContainer();
-
- obj.foo = new Timestamp(100020003);
-
- PortableBuilderImpl mutableObj = wrap(obj);
-
- assertEquals(Timestamp.class, mutableObj.getField("foo").getClass());
- }
-
- /**
- *
- */
- public void testDateInCollection() {
- TestObjectContainer obj = new TestObjectContainer();
-
- obj.foo = Lists.newArrayList(new Date());
-
- PortableBuilderImpl mutableObj = wrap(obj);
-
- assertEquals(Date.class, ((List<?>)mutableObj.getField("foo")).get(0).getClass());
- }
-
- /**
- *
- */
- public void testTimestampInCollection() {
- TestObjectContainer obj = new TestObjectContainer();
-
- obj.foo = Lists.newArrayList(new Timestamp(100020003));
-
- PortableBuilderImpl mutableObj = wrap(obj);
-
- assertEquals(Timestamp.class, ((List<?>)mutableObj.getField("foo")).get(0).getClass());
- }
-
- /**
- *
- */
- @SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
- public void testDateArrayOverride() {
- TestObjectContainer obj = new TestObjectContainer();
-
- PortableBuilderImpl mutableObj = wrap(obj);
-
- Date[] arr = { new Date() };
-
- mutableObj.setField("foo", arr);
-
- TestObjectContainer res = mutableObj.build().deserialize();
-
- assertEquals(Date[].class, res.foo.getClass());
- assertTrue(Objects.deepEquals(arr, res.foo));
- }
-
- /**
- *
- */
- @SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
- public void testTimestampArrayOverride() {
- TestObjectContainer obj = new TestObjectContainer();
-
- PortableBuilderImpl mutableObj = wrap(obj);
-
- Timestamp[] arr = { new Timestamp(100020003) };
-
- mutableObj.setField("foo", arr);
-
- TestObjectContainer res = mutableObj.build().deserialize();
-
- assertEquals(Timestamp[].class, res.foo.getClass());
- assertTrue(Objects.deepEquals(arr, res.foo));
- }
-
- /**
- *
- */
- public void testChangeMap() {
- AddressBook addrBook = new AddressBook();
-
- addrBook.addCompany(new Company(1, "Google inc", 100, new Address("Saint-Petersburg", "Torzhkovskya", 1, 53), "occupation"));
- addrBook.addCompany(new Company(2, "Apple inc", 100, new Address("Saint-Petersburg", "Torzhkovskya", 1, 54), "occupation"));
- addrBook.addCompany(new Company(3, "Microsoft", 100, new Address("Saint-Petersburg", "Torzhkovskya", 1, 55), "occupation"));
- addrBook.addCompany(new Company(4, "Oracle", 100, new Address("Saint-Petersburg", "Nevskiy", 1, 1), "occupation"));
-
- PortableBuilderImpl mutableObj = wrap(addrBook);
-
- Map<String, List<PortableBuilderImpl>> map = mutableObj.getField("companyByStreet");
-
- List<PortableBuilderImpl> list = map.get("Torzhkovskya");
-
- PortableBuilderImpl company = list.get(0);
-
- assert "Google inc".equals(company.<String>getField("name"));
-
- list.remove(0);
-
- AddressBook res = mutableObj.build().deserialize();
-
- assertEquals(Arrays.asList("Nevskiy", "Torzhkovskya"), new ArrayList<>(res.getCompanyByStreet().keySet()));
-
- List<Company> torzhkovskyaCompanies = res.getCompanyByStreet().get("Torzhkovskya");
-
- assertEquals(2, torzhkovskyaCompanies.size());
- assertEquals("Apple inc", torzhkovskyaCompanies.get(0).name);
- }
-
- /**
- *
- */
- public void testSavingObjectWithNotZeroStart() {
- TestObjectOuter out = new TestObjectOuter();
- TestObjectInner inner = new TestObjectInner();
-
- out.inner = inner;
- inner.outer = out;
-
- PortableBuilderImpl builder = wrap(out);
-
- PortableBuilderImpl innerBuilder = builder.getField("inner");
-
- TestObjectInner res = innerBuilder.build().deserialize();
-
- assertSame(res, res.outer.inner);
- }
-
- /**
- *
- */
- public void testPortableObjectField() {
- TestObjectContainer container = new TestObjectContainer(toPortable(new TestObjectArrayList()));
-
- PortableBuilderImpl wrapper = wrap(container);
-
- assertTrue(wrapper.getField("foo") instanceof PortableObject);
-
- TestObjectContainer deserialized = wrapper.build().deserialize();
- assertTrue(deserialized.foo instanceof PortableObject);
- }
-
- /**
- *
- */
- public void testAssignPortableObject() {
- TestObjectContainer container = new TestObjectContainer();
-
- PortableBuilderImpl wrapper = wrap(container);
-
- wrapper.setField("foo", toPortable(new TestObjectArrayList()));
-
- TestObjectContainer deserialized = wrapper.build().deserialize();
- assertTrue(deserialized.foo instanceof TestObjectArrayList);
- }
-
- /**
- *
- */
- public void testRemoveFromNewObject() {
- PortableBuilderImpl wrapper = newWrapper(TestObjectAllTypes.class);
-
- wrapper.setField("str", "a");
-
- wrapper.removeField("str");
-
- assertNull(wrapper.build().<TestObjectAllTypes>deserialize().str);
- }
-
- /**
- *
- */
- public void testRemoveFromExistingObject() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
- obj.setDefaultData();
-
- PortableBuilderImpl wrapper = wrap(toPortable(obj));
-
- wrapper.removeField("str");
-
- assertNull(wrapper.build().<TestObjectAllTypes>deserialize().str);
- }
-
- /**
- *
- */
- public void testCyclicArrays() {
- TestObjectContainer obj = new TestObjectContainer();
-
- Object[] arr1 = new Object[1];
- Object[] arr2 = new Object[] {arr1};
-
- arr1[0] = arr2;
-
- obj.foo = arr1;
-
- TestObjectContainer res = toPortable(obj).deserialize();
-
- Object[] resArr = (Object[])res.foo;
-
- assertSame(((Object[])resArr[0])[0], resArr);
- }
-
- /**
- *
- */
- @SuppressWarnings("TypeMayBeWeakened")
- public void testCyclicArrayList() {
- TestObjectContainer obj = new TestObjectContainer();
-
- List<Object> arr1 = new ArrayList<>();
- List<Object> arr2 = new ArrayList<>();
-
- arr1.add(arr2);
- arr2.add(arr1);
-
- obj.foo = arr1;
-
- TestObjectContainer res = toPortable(obj).deserialize();
-
- List<?> resArr = (List<?>)res.foo;
-
- assertSame(((List<Object>)resArr.get(0)).get(0), resArr);
- }
-
- /**
- * @param obj Object.
- * @return Object in portable format.
- */
- private PortableObject toPortable(Object obj) {
- return portables().toPortable(obj);
- }
-
- /**
- * @param obj Object.
- * @return GridMutablePortableObject.
- */
- private PortableBuilderImpl wrap(Object obj) {
- return PortableBuilderImpl.wrap(toPortable(obj));
- }
-
- /**
- * @param aCls Class.
- * @return Wrapper.
- */
- private PortableBuilderImpl newWrapper(Class<?> aCls) {
- CacheObjectPortableProcessorImpl processor = (CacheObjectPortableProcessorImpl)(
- (IgnitePortablesImpl)portables()).processor();
-
- return new PortableBuilderImpl(processor.portableContext(), processor.typeId(aCls.getName()),
- aCls.getSimpleName());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderSelfTest.java
deleted file mode 100644
index 331d9dc..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderSelfTest.java
+++ /dev/null
@@ -1,1069 +0,0 @@
-/*
- * 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.portable;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgnitePortables;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.portable.builder.PortableBuilderImpl;
-import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectAllTypes;
-import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectContainer;
-import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectInner;
-import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectOuter;
-import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectPlainPortable;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableIdMapper;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableTypeConfiguration;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import sun.misc.Unsafe;
-
-/**
- * Portable builder test.
- */
-public class GridPortableBuilderSelfTest extends GridCommonAbstractTest {
- /** */
- private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
- /** */
- protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- PortableMarshaller marsh = new PortableMarshaller();
-
- marsh.setClassNames(Arrays.asList(Key.class.getName(), Value.class.getName(),
- "org.gridgain.grid.internal.util.portable.mutabletest.*"));
-
- PortableTypeConfiguration customIdMapper = new PortableTypeConfiguration();
-
- customIdMapper.setClassName(CustomIdMapper.class.getName());
- customIdMapper.setIdMapper(new PortableIdMapper() {
- @Override public int typeId(String clsName) {
- return ~PortableContext.DFLT_ID_MAPPER.typeId(clsName);
- }
-
- @Override public int fieldId(int typeId, String fieldName) {
- return typeId + ~PortableContext.DFLT_ID_MAPPER.fieldId(typeId, fieldName);
- }
- });
-
- marsh.setTypeConfigurations(Collections.singleton(customIdMapper));
-
- marsh.setConvertStringToBytes(useUtf8());
-
- cfg.setMarshaller(marsh);
-
- return cfg;
- }
-
- /** {@inheritDoc} */
- @Override protected void beforeTestsStarted() throws Exception {
- startGrids(1);
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTestsStopped() throws Exception {
- stopAllGrids();
- }
-
- /**
- * @return Whether to use UTF8 strings.
- */
- protected boolean useUtf8() {
- return true;
- }
-
- /**
- *
- */
- public void testAllFieldsSerialization() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
- obj.setDefaultData();
- obj.enumArr = null;
-
- TestObjectAllTypes deserialized = builder(toPortable(obj)).build().deserialize();
-
- GridTestUtils.deepEquals(obj, deserialized);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testByteField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("byteField", (byte)1);
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals((byte) 1, po.<Byte>field("byteField").byteValue());
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testShortField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("shortField", (short)1);
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals((short)1, po.<Short>field("shortField").shortValue());
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testIntField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("intField", 1);
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals(1, po.<Integer>field("intField").intValue());
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testLongField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("longField", 1L);
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals(1L, po.<Long>field("longField").longValue());
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testFloatField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("floatField", 1.0f);
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals(1.0f, po.<Float>field("floatField").floatValue(), 0);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testDoubleField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("doubleField", 1.0d);
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals(1.0d, po.<Double>field("doubleField").doubleValue(), 0);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testCharField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("charField", (char)1);
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals((char)1, po.<Character>field("charField").charValue());
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testBooleanField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("booleanField", true);
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertTrue(po.<Boolean>field("booleanField"));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testDecimalField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("decimalField", BigDecimal.TEN);
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals(BigDecimal.TEN, po.<String>field("decimalField"));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testStringField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("stringField", "str");
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals("str", po.<String>field("stringField"));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testDateField() throws Exception {
- Date date = new Date();
-
- assertEquals(date, builder("C").setField("d", date).build().<Date>field("d"));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testTimestampField() throws Exception {
- Timestamp ts = new Timestamp(new Date().getTime());
- ts.setNanos(1000);
-
- assertEquals(ts, builder("C").setField("t", ts).build().<Timestamp>field("t"));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testUuidField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- UUID uuid = UUID.randomUUID();
-
- builder.setField("uuidField", uuid);
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals(uuid, po.<UUID>field("uuidField"));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testByteArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("byteArrayField", new byte[] {1, 2, 3});
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertTrue(Arrays.equals(new byte[] {1, 2, 3}, po.<byte[]>field("byteArrayField")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testShortArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("shortArrayField", new short[] {1, 2, 3});
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertTrue(Arrays.equals(new short[] {1, 2, 3}, po.<short[]>field("shortArrayField")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testIntArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("intArrayField", new int[] {1, 2, 3});
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertTrue(Arrays.equals(new int[] {1, 2, 3}, po.<int[]>field("intArrayField")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testLongArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("longArrayField", new long[] {1, 2, 3});
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertTrue(Arrays.equals(new long[] {1, 2, 3}, po.<long[]>field("longArrayField")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testFloatArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("floatArrayField", new float[] {1, 2, 3});
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertTrue(Arrays.equals(new float[] {1, 2, 3}, po.<float[]>field("floatArrayField")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testDoubleArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("doubleArrayField", new double[] {1, 2, 3});
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertTrue(Arrays.equals(new double[] {1, 2, 3}, po.<double[]>field("doubleArrayField")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testCharArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("charArrayField", new char[] {1, 2, 3});
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertTrue(Arrays.equals(new char[] {1, 2, 3}, po.<char[]>field("charArrayField")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testBooleanArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("booleanArrayField", new boolean[] {true, false});
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- boolean[] arr = po.field("booleanArrayField");
-
- assertEquals(2, arr.length);
-
- assertTrue(arr[0]);
- assertFalse(arr[1]);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testDecimalArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("decimalArrayField", new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN});
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertTrue(Arrays.equals(new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN}, po.<String[]>field("decimalArrayField")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testStringArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("stringArrayField", new String[] {"str1", "str2", "str3"});
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertTrue(Arrays.equals(new String[] {"str1", "str2", "str3"}, po.<String[]>field("stringArrayField")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testDateArrayField() throws Exception {
- Date date1 = new Date();
- Date date2 = new Date(date1.getTime() + 1000);
-
- Date[] dateArr = new Date[] { date1, date2 };
-
- assertTrue(Arrays.equals(dateArr, builder("C").setField("da", dateArr).build().<Date[]>field("da")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testTimestampArrayField() throws Exception {
- Timestamp ts1 = new Timestamp(new Date().getTime());
- Timestamp ts2 = new Timestamp(new Date().getTime() + 1000);
-
- ts1.setNanos(1000);
- ts2.setNanos(2000);
-
- Timestamp[] tsArr = new Timestamp[] { ts1, ts2 };
-
- assertTrue(Arrays.equals(tsArr, builder("C").setField("ta", tsArr).build().<Timestamp[]>field("ta")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testUuidArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- UUID[] arr = new UUID[] {UUID.randomUUID(), UUID.randomUUID()};
-
- builder.setField("uuidArrayField", arr);
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertTrue(Arrays.equals(arr, po.<UUID[]>field("uuidArrayField")));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testObjectField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("objectField", new Value(1));
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals(1, po.<PortableObject>field("objectField").<Value>deserialize().i);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testObjectArrayField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("objectArrayField", new Value[] {new Value(1), new Value(2)});
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- Object[] arr = po.field("objectArrayField");
-
- assertEquals(2, arr.length);
-
- assertEquals(1, ((PortableObject)arr[0]).<Value>deserialize().i);
- assertEquals(2, ((PortableObject)arr[1]).<Value>deserialize().i);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testCollectionField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("collectionField", Arrays.asList(new Value(1), new Value(2)));
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- List<PortableObject> list = po.field("collectionField");
-
- assertEquals(2, list.size());
-
- assertEquals(1, list.get(0).<Value>deserialize().i);
- assertEquals(2, list.get(1).<Value>deserialize().i);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testMapField() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("mapField", F.asMap(new Key(1), new Value(1), new Key(2), new Value(2)));
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- Map<PortableObject, PortableObject> map = po.field("mapField");
-
- assertEquals(2, map.size());
-
- for (Map.Entry<PortableObject, PortableObject> e : map.entrySet())
- assertEquals(e.getKey().<Key>deserialize().i, e.getValue().<Value>deserialize().i);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testSeveralFields() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("i", 111);
- builder.setField("f", 111.111f);
- builder.setField("iArr", new int[] {1, 2, 3});
- builder.setField("obj", new Key(1));
- builder.setField("col", Arrays.asList(new Value(1), new Value(2)));
-
- PortableObject po = builder.build();
-
- assertEquals("class".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals(111, po.<Integer>field("i").intValue());
- assertEquals(111.111f, po.<Float>field("f").floatValue(), 0);
- assertTrue(Arrays.equals(new int[] {1, 2, 3}, po.<int[]>field("iArr")));
- assertEquals(1, po.<PortableObject>field("obj").<Key>deserialize().i);
-
- List<PortableObject> list = po.field("col");
-
- assertEquals(2, list.size());
-
- assertEquals(1, list.get(0).<Value>deserialize().i);
- assertEquals(2, list.get(1).<Value>deserialize().i);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testOffheapPortable() throws Exception {
- PortableBuilder builder = builder("Class");
-
- builder.hashCode(100);
-
- builder.setField("i", 111);
- builder.setField("f", 111.111f);
- builder.setField("iArr", new int[] {1, 2, 3});
- builder.setField("obj", new Key(1));
- builder.setField("col", Arrays.asList(new Value(1), new Value(2)));
-
- PortableObject po = builder.build();
-
- byte[] arr = ((CacheObjectPortableProcessorImpl)(grid(0)).context().cacheObjects()).marshal(po);
-
- long ptr = UNSAFE.allocateMemory(arr.length + 5);
-
- try {
- long ptr0 = ptr;
-
- UNSAFE.putBoolean(null, ptr0++, false);
-
- UNSAFE.putInt(ptr0, arr.length);
-
- UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr0 + 4, arr.length);
-
- PortableObject offheapObj = (PortableObject)
- ((CacheObjectPortableProcessorImpl)(grid(0)).context().cacheObjects()).unmarshal(ptr, false);
-
- assertEquals(PortableObjectOffheapImpl.class, offheapObj.getClass());
-
- assertEquals("class".hashCode(), offheapObj.typeId());
- assertEquals(100, offheapObj.hashCode());
-
- assertEquals(111, offheapObj.<Integer>field("i").intValue());
- assertEquals(111.111f, offheapObj.<Float>field("f").floatValue(), 0);
- assertTrue(Arrays.equals(new int[] {1, 2, 3}, offheapObj.<int[]>field("iArr")));
- assertEquals(1, offheapObj.<PortableObject>field("obj").<Key>deserialize().i);
-
- List<PortableObject> list = offheapObj.field("col");
-
- assertEquals(2, list.size());
-
- assertEquals(1, list.get(0).<Value>deserialize().i);
- assertEquals(2, list.get(1).<Value>deserialize().i);
-
- assertEquals(po, offheapObj);
- assertEquals(offheapObj, po);
- }
- finally {
- UNSAFE.freeMemory(ptr);
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testBuildAndDeserialize() throws Exception {
- PortableBuilder builder = builder(Value.class.getName());
-
- builder.hashCode(100);
-
- builder.setField("i", 1);
-
- PortableObject po = builder.build();
-
- assertEquals("value".hashCode(), po.typeId());
- assertEquals(100, po.hashCode());
-
- assertEquals(1, po.<Value>deserialize().i);
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testMetaData2() throws Exception {
- PortableBuilder builder = builder("org.test.MetaTest2");
-
- builder.setField("objectField", "a", Object.class);
-
- PortableObject po = builder.build();
-
- PortableMetadata meta = po.metaData();
-
- assertEquals("MetaTest2", meta.typeName());
- assertEquals("Object", meta.fieldTypeName("objectField"));
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testMetaData() throws Exception {
- PortableBuilder builder = builder("org.test.MetaTest");
-
- builder.hashCode(100);
-
- builder.setField("intField", 1);
- builder.setField("byteArrayField", new byte[] {1, 2, 3});
-
- PortableObject po = builder.build();
-
- PortableMetadata meta = po.metaData();
-
- assertEquals("MetaTest", meta.typeName());
-
- Collection<String> fields = meta.fields();
-
- assertEquals(2, fields.size());
-
- assertTrue(fields.contains("intField"));
- assertTrue(fields.contains("byteArrayField"));
-
- assertEquals("int", meta.fieldTypeName("intField"));
- assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
-
- builder = builder("org.test.MetaTest");
-
- builder.hashCode(100);
-
- builder.setField("intField", 2);
- builder.setField("uuidField", UUID.randomUUID());
-
- po = builder.build();
-
- meta = po.metaData();
-
- assertEquals("MetaTest", meta.typeName());
-
- fields = meta.fields();
-
- assertEquals(3, fields.size());
-
- assertTrue(fields.contains("intField"));
- assertTrue(fields.contains("byteArrayField"));
- assertTrue(fields.contains("uuidField"));
-
- assertEquals("int", meta.fieldTypeName("intField"));
- assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
- assertEquals("UUID", meta.fieldTypeName("uuidField"));
- }
-
- /**
- *
- */
- public void testGetFromCopiedObj() {
- PortableObject objStr = builder(TestObjectAllTypes.class.getName()).setField("str", "aaa").build();
-
- PortableBuilderImpl builder = builder(objStr);
- assertEquals("aaa", builder.getField("str"));
-
- builder.setField("str", "bbb");
- assertEquals("bbb", builder.getField("str"));
-
- assertNull(builder.getField("i_"));
- assertEquals("bbb", builder.build().<TestObjectAllTypes>deserialize().str);
- }
-
- /**
- *
- */
- public void testCopyFromInnerObjects() {
- ArrayList<Object> list = new ArrayList<>();
- list.add(new TestObjectAllTypes());
- list.add(list.get(0));
-
- TestObjectContainer c = new TestObjectContainer(list);
-
- PortableBuilderImpl builder = builder(toPortable(c));
- builder.<List>getField("foo").add("!!!");
-
- PortableObject res = builder.build();
-
- TestObjectContainer deserialized = res.deserialize();
-
- List deserializedList = (List)deserialized.foo;
-
- assertSame(deserializedList.get(0), deserializedList.get(1));
- assertEquals("!!!", deserializedList.get(2));
- assertTrue(deserializedList.get(0) instanceof TestObjectAllTypes);
- }
-
- /**
- *
- */
- public void testSetPortableObject() {
- PortableObject portableObj = builder(TestObjectContainer.class.getName())
- .setField("foo", toPortable(new TestObjectAllTypes()))
- .build();
-
- assertTrue(portableObj.<TestObjectContainer>deserialize().foo instanceof TestObjectAllTypes);
- }
-
- /**
- *
- */
- public void testPlainPortableObjectCopyFrom() {
- TestObjectPlainPortable obj = new TestObjectPlainPortable(toPortable(new TestObjectAllTypes()));
-
- PortableBuilderImpl builder = builder(toPortable(obj));
- assertTrue(builder.getField("plainPortable") instanceof PortableObject);
-
- TestObjectPlainPortable deserialized = builder.build().deserialize();
- assertTrue(deserialized.plainPortable instanceof PortableObject);
- }
-
- /**
- *
- */
- public void testRemoveFromNewObject() {
- PortableBuilder builder = builder(TestObjectAllTypes.class.getName());
-
- builder.setField("str", "a");
-
- builder.removeField("str");
-
- assertNull(builder.build().<TestObjectAllTypes>deserialize().str);
- }
-
- /**
- *
- */
- public void testRemoveFromExistingObject() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
- obj.setDefaultData();
- obj.enumArr = null;
-
- PortableBuilder builder = builder(toPortable(obj));
-
- builder.removeField("str");
-
- assertNull(builder.build().<TestObjectAllTypes>deserialize().str);
- }
-
- /**
- *
- */
- public void testRemoveFromExistingObjectAfterGet() {
- TestObjectAllTypes obj = new TestObjectAllTypes();
- obj.setDefaultData();
- obj.enumArr = null;
-
- PortableBuilderImpl builder = builder(toPortable(obj));
-
- builder.getField("i_");
-
- builder.removeField("str");
-
- assertNull(builder.build().<TestObjectAllTypes>deserialize().str);
- }
-
- /**
- * @throws IgniteCheckedException If any error occurs.
- */
- public void testDontBrokeCyclicDependency() throws IgniteCheckedException {
- TestObjectOuter outer = new TestObjectOuter();
- outer.inner = new TestObjectInner();
- outer.inner.outer = outer;
- outer.foo = "a";
-
- PortableBuilder builder = builder(toPortable(outer));
-
- builder.setField("foo", "b");
-
- TestObjectOuter res = builder.build().deserialize();
-
- assertEquals("b", res.foo);
- assertSame(res, res.inner.outer);
- }
-
- /**
- * @return Portables.
- */
- private IgnitePortables portables() {
- return grid(0).portables();
- }
-
- /**
- * @param obj Object.
- * @return Portable object.
- */
- private PortableObject toPortable(Object obj) {
- return portables().toPortable(obj);
- }
-
- /**
- * @return Builder.
- */
- private <T> PortableBuilder builder(int typeId) {
- return portables().builder(typeId);
- }
-
- /**
- * @return Builder.
- */
- private <T> PortableBuilder builder(String clsName) {
- return portables().builder(clsName);
- }
-
- /**
- * @return Builder.
- */
- private <T> PortableBuilderImpl builder(PortableObject obj) {
- return (PortableBuilderImpl)portables().builder(obj);
- }
-
- /**
- *
- */
- private static class CustomIdMapper {
- /** */
- private String str = "a";
-
- /** */
- private int i = 10;
- }
-
- /**
- */
- private static class Key {
- /** */
- private int i;
-
- /**
- */
- private Key() {
- // No-op.
- }
-
- /**
- * @param i Index.
- */
- private Key(int i) {
- this.i = i;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- Key key = (Key)o;
-
- return i == key.i;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return i;
- }
- }
-
- /**
- */
- private static class Value {
- /** */
- private int i;
-
- /**
- */
- private Value() {
- // No-op.
- }
-
- /**
- * @param i Index.
- */
- private Value(int i) {
- this.i = i;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsAdditionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsAdditionalSelfTest.java
deleted file mode 100644
index 2fce1a5..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsAdditionalSelfTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.portable;
-
-/**
- *
- */
-public class GridPortableBuilderStringAsCharsAdditionalSelfTest extends GridPortableBuilderAdditionalSelfTest {
- /** {@inheritDoc} */
- @Override protected boolean useUtf8() {
- return false;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsSelfTest.java
deleted file mode 100644
index 5c53233..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsSelfTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.portable;
-
-/**
- * Portable builder test.
- */
-public class GridPortableBuilderStringAsCharsSelfTest extends GridPortableBuilderSelfTest {
- /** {@inheritDoc} */
- @Override protected boolean useUtf8() {
- return false;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java
index bd9612c..ee91167 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java
@@ -23,14 +23,15 @@ import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Arrays;
import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.MarshallerContextAdapter;
import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
/**
@@ -39,11 +40,11 @@ import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
public class GridPortableMarshallerCtxDisabledSelfTest extends GridCommonAbstractTest {
/** */
protected static final PortableMetaDataHandler META_HND = new PortableMetaDataHandler() {
- @Override public void addMeta(int typeId, PortableMetadata meta) {
+ @Override public void addMeta(int typeId, BinaryType meta) {
// No-op.
}
- @Override public PortableMetadata metadata(int typeId) {
+ @Override public BinaryType metadata(int typeId) {
return null;
}
};
@@ -55,7 +56,7 @@ public class GridPortableMarshallerCtxDisabledSelfTest extends GridCommonAbstrac
PortableMarshaller marsh = new PortableMarshaller();
marsh.setContext(new MarshallerContextWithNoStorage());
- PortableContext context = new PortableContext(META_HND, null);
+ PortableContext context = new PortableContext(META_HND, new IgniteConfiguration());
IgniteUtils.invoke(PortableMarshaller.class, marsh, "setPortableContext", context);
@@ -77,7 +78,7 @@ public class GridPortableMarshallerCtxDisabledSelfTest extends GridCommonAbstrac
assertEquals(simpleObj, marsh.unmarshal(marsh.marshal(simpleObj), null));
- SimplePortable simplePortable = new SimplePortable();
+ SimpleBinary simplePortable = new SimpleBinary();
simplePortable.str = "portable";
simplePortable.arr = new long[] {100, 200, 300};
@@ -179,7 +180,7 @@ public class GridPortableMarshallerCtxDisabledSelfTest extends GridCommonAbstrac
/**
*
*/
- private static class SimplePortable implements PortableMarshalAware {
+ private static class SimpleBinary implements Binarylizable {
/** */
private String str;
@@ -187,13 +188,13 @@ public class GridPortableMarshallerCtxDisabledSelfTest extends GridCommonAbstrac
private long[] arr;
/** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
writer.writeString("str", str);
writer.writeLongArray("longArr", arr);
}
/** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
str = reader.readString("str");
arr = reader.readLongArray("longArr");
}
@@ -206,7 +207,7 @@ public class GridPortableMarshallerCtxDisabledSelfTest extends GridCommonAbstrac
if (o == null || getClass() != o.getClass())
return false;
- SimplePortable that = (SimplePortable)o;
+ SimpleBinary that = (SimpleBinary)o;
if (str != null ? !str.equals(that.str) : that.str != null)
return false;
[14/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
index 61975d7..d2403e4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
@@ -316,7 +316,7 @@ public final class GridDhtTxPrepareFuture extends GridCompoundFuture<IgniteInter
*
*/
private void onEntriesLocked() {
- ret = new GridCacheReturn(null, tx.localResult(), null, true);
+ ret = new GridCacheReturn(null, tx.localResult(), true, null, true);
for (IgniteTxEntry writeEntry : writes) {
IgniteTxEntry txEntry = tx.entry(writeEntry.txKey());
@@ -361,7 +361,8 @@ public final class GridDhtTxPrepareFuture extends GridCompoundFuture<IgniteInter
null,
null,
null,
- null);
+ null,
+ txEntry.keepBinary());
if (retVal || txEntry.op() == TRANSFORM) {
if (!F.isEmpty(txEntry.entryProcessors())) {
@@ -377,8 +378,8 @@ public final class GridDhtTxPrepareFuture extends GridCompoundFuture<IgniteInter
for (T2<EntryProcessor<Object, Object, Object>, Object[]> t : txEntry.entryProcessors()) {
try {
- CacheInvokeEntry<Object, Object> invokeEntry =
- new CacheInvokeEntry<>(txEntry.context(), key, val, txEntry.cached().version());
+ CacheInvokeEntry<Object, Object> invokeEntry = new CacheInvokeEntry<>(
+ txEntry.context(), key, val, txEntry.cached().version(), txEntry.keepBinary());
EntryProcessor<Object, Object, Object> processor = t.get1();
@@ -403,7 +404,7 @@ public final class GridDhtTxPrepareFuture extends GridCompoundFuture<IgniteInter
}
}
else if (retVal)
- ret.value(cacheCtx, val);
+ ret.value(cacheCtx, val, txEntry.keepBinary());
}
if (hasFilters && !cacheCtx.isAll(cached, txEntry.filters())) {
@@ -1555,10 +1556,10 @@ public final class GridDhtTxPrepareFuture extends GridCompoundFuture<IgniteInter
if (rec && !entry.isInternal())
cacheCtx.events().addEvent(entry.partition(), entry.key(), cctx.localNodeId(),
(IgniteUuid)null, null, EVT_CACHE_REBALANCE_OBJECT_LOADED, info.value(), true, null,
- false, null, null, null);
+ false, null, null, null, false);
if (retVal && !invoke)
- ret.value(cacheCtx, info.value());
+ ret.value(cacheCtx, info.value(), false);
}
break;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java
index f8be2a7..ad8a402 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java
@@ -122,9 +122,9 @@ public class GridDhtTxRemote extends GridDistributedTxRemoteAdapter {
concurrency,
isolation,
invalidate,
- timeout,
+ timeout,
txSize,
- subjId,
+ subjId,
taskNameHash
);
@@ -193,7 +193,7 @@ public class GridDhtTxRemote extends GridDistributedTxRemoteAdapter {
concurrency,
isolation,
invalidate,
- timeout,
+ timeout,
txSize,
subjId,
taskNameHash
@@ -335,7 +335,8 @@ public class GridDhtTxRemote extends GridDistributedTxRemoteAdapter {
@Nullable CacheObject val,
@Nullable Collection<T2<EntryProcessor<Object, Object, Object>, Object[]>> entryProcessors,
long ttl,
- boolean skipStore) {
+ boolean skipStore,
+ boolean keepBinary) {
checkInternal(key);
if (isSystemInvalidate())
@@ -351,7 +352,8 @@ public class GridDhtTxRemote extends GridDistributedTxRemoteAdapter {
-1L,
cached,
null,
- skipStore);
+ skipStore,
+ keepBinary);
txEntry.entryProcessors(entryProcessors);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
index febe9ba..ce736e5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridPartitionedGetFuture.java
@@ -418,7 +418,8 @@ public class GridPartitionedGetFuture<K, V> extends CacheDistributedGetFutureAda
subjId,
null,
taskName,
- expiryPlc);
+ expiryPlc,
+ !deserializePortable);
if (res != null) {
v = res.get1();
@@ -437,7 +438,8 @@ public class GridPartitionedGetFuture<K, V> extends CacheDistributedGetFutureAda
subjId,
null,
taskName,
- expiryPlc);
+ expiryPlc,
+ !deserializePortable);
}
colocated.context().evicts().touch(entry, topVer);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index 4cd9e84..255640f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -53,7 +53,6 @@ import org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
-import org.apache.ignite.internal.processors.cache.GridCacheFilterFailedException;
import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory;
import org.apache.ignite.internal.processors.cache.GridCacheOperation;
@@ -834,6 +833,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
subjId,
taskNameHash,
opCtx != null && opCtx.skipStore(),
+ opCtx != null && opCtx.isKeepBinary(),
opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES,
waitTopFut);
@@ -899,6 +899,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
subjId,
taskNameHash,
opCtx != null && opCtx.skipStore(),
+ opCtx != null && opCtx.isKeepBinary(),
opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES,
true);
@@ -971,7 +972,8 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
subjId,
null,
taskName,
- expiry);
+ expiry,
+ !deserializePortable);
// Entry was not in memory or in swap, so we remove it from cache.
if (v == null) {
@@ -1196,7 +1198,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
}
if (retVal == null)
- retVal = new GridCacheReturn(ctx, node.isLocal(), null, true);
+ retVal = new GridCacheReturn(ctx, node.isLocal(), true, null, true);
res.returnValue(retVal);
@@ -1316,11 +1318,11 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
int size = req.keys().size();
- Map<Object, Object> putMap = null;
+ Map<KeyCacheObject, CacheObject> putMap = null;
Map<KeyCacheObject, EntryProcessor<Object, Object, Object>> entryProcessorMap = null;
- Collection<Object> rmvKeys = null;
+ Collection<KeyCacheObject> rmvKeys = null;
List<CacheObject> writeVals = null;
@@ -1383,13 +1385,14 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
req.subjectId(),
entryProcessor,
taskName,
- null);
+ null,
+ req.keepBinary());
Object oldVal = null;
Object updatedVal = null;
CacheInvokeEntry<Object, Object> invokeEntry = new CacheInvokeEntry(ctx, entry.key(), old,
- entry.version());
+ entry.version(), req.keepBinary());
CacheObject updated;
@@ -1418,7 +1421,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
if (updated == null) {
if (intercept) {
- CacheLazyEntry e = new CacheLazyEntry(ctx, entry.key(), invokeEntry.key(), old, oldVal);
+ CacheLazyEntry e = new CacheLazyEntry(ctx, entry.key(), invokeEntry.key(), old, oldVal, req.keepBinary());
IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor().onBeforeRemove(e);
@@ -1460,11 +1463,11 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
if (rmvKeys == null)
rmvKeys = new ArrayList<>(size);
- rmvKeys.add(entry.key().value(ctx.cacheObjectContext(), false));
+ rmvKeys.add(entry.key());
}
else {
if (intercept) {
- CacheLazyEntry e = new CacheLazyEntry(ctx, entry.key(), invokeEntry.key(), old, oldVal);
+ CacheLazyEntry e = new CacheLazyEntry(ctx, entry.key(), invokeEntry.key(), old, oldVal, req.keepBinary());
Object val = ctx.config().getInterceptor().onBeforePut(e, updatedVal);
@@ -1508,7 +1511,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
writeVals = new ArrayList<>(size);
}
- putMap.put(CU.value(entry.key(), ctx, false), CU.value(updated, ctx, false));
+ putMap.put(entry.key(), updated);
writeVals.add(updated);
}
@@ -1533,10 +1536,11 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
req.subjectId(),
null,
taskName,
- null);
+ null,
+ req.keepBinary());
Object val = ctx.config().getInterceptor().onBeforePut(new CacheLazyEntry(ctx, entry.key(),
- old),
+ old, req.keepBinary()),
updated.value(ctx.cacheObjectContext(), false));
if (val == null)
@@ -1552,7 +1556,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
writeVals = new ArrayList<>(size);
}
- putMap.put(CU.value(entry.key(), ctx, false), CU.value(updated, ctx, false));
+ putMap.put(entry.key(), updated);
writeVals.add(updated);
}
else {
@@ -1571,10 +1575,11 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
req.subjectId(),
null,
taskName,
- null);
+ null,
+ req.keepBinary());
IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor()
- .onBeforeRemove(new CacheLazyEntry(ctx, entry.key(), old));
+ .onBeforeRemove(new CacheLazyEntry(ctx, entry.key(), old, req.keepBinary()));
if (ctx.cancelRemove(interceptorRes))
continue;
@@ -1583,7 +1588,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
if (rmvKeys == null)
rmvKeys = new ArrayList<>(size);
- rmvKeys.add(entry.key().value(ctx.cacheObjectContext(), false));
+ rmvKeys.add(entry.key());
}
filtered.add(entry);
@@ -1761,6 +1766,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
primary && writeThrough() && !req.skipStore(),
!req.skipStore(),
req.returnValue(),
+ req.keepBinary(),
expiry,
true,
true,
@@ -1876,6 +1882,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
retVal = new GridCacheReturn(ctx,
node.isLocal(),
+ req.keepBinary(),
req.returnValue() ? ret : null,
updRes.success());
}
@@ -1917,8 +1924,8 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
final GridCacheVersion ver,
ClusterNode node,
@Nullable List<CacheObject> writeVals,
- @Nullable Map<Object, Object> putMap,
- @Nullable Collection<Object> rmvKeys,
+ @Nullable Map<KeyCacheObject, CacheObject> putMap,
+ @Nullable Collection<KeyCacheObject> rmvKeys,
@Nullable Map<KeyCacheObject, EntryProcessor<Object, Object, Object>> entryProcessorMap,
@Nullable GridDhtAtomicUpdateFuture dhtFut,
CI2<GridNearAtomicUpdateRequest, GridNearAtomicUpdateResponse> completionCb,
@@ -1944,17 +1951,17 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
if (putMap != null) {
// If fast mapping, filter primary keys for write to store.
- Map<Object, Object> storeMap = req.fastMap() ?
- F.view(putMap, new P1<Object>() {
- @Override public boolean apply(Object key) {
+ Map<KeyCacheObject, CacheObject> storeMap = req.fastMap() ?
+ F.view(putMap, new P1<CacheObject>() {
+ @Override public boolean apply(CacheObject key) {
return ctx.affinity().primary(ctx.localNode(), key, req.topologyVersion());
}
}) :
putMap;
try {
- ctx.store().putAll(null, F.viewReadOnly(storeMap, new C1<Object, IgniteBiTuple<Object, GridCacheVersion>>() {
- @Override public IgniteBiTuple<Object, GridCacheVersion> apply(Object v) {
+ ctx.store().putAll(null, F.viewReadOnly(storeMap, new C1<CacheObject, IgniteBiTuple<CacheObject, GridCacheVersion>>() {
+ @Override public IgniteBiTuple<CacheObject, GridCacheVersion> apply(CacheObject v) {
return F.t(v, ver);
}
}));
@@ -1967,7 +1974,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
}
else {
// If fast mapping, filter primary keys for write to store.
- Collection<Object> storeKeys = req.fastMap() ?
+ Collection<KeyCacheObject> storeKeys = req.fastMap() ?
F.view(rmvKeys, new P1<Object>() {
@Override public boolean apply(Object key) {
return ctx.affinity().primary(ctx.localNode(), key, req.topologyVersion());
@@ -2030,6 +2037,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
/*write-through*/false,
/*read-through*/false,
/*retval*/false,
+ req.keepBinary(),
expiry,
/*event*/true,
/*metrics*/true,
@@ -2054,14 +2062,15 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
ctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(
ctx,
entry.key(),
- updRes.newValue()));
+ updRes.newValue(),
+ req.keepBinary()));
}
else {
assert op == DELETE : op;
// Old value should be already loaded for 'CacheInterceptor.onBeforeRemove'.
ctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(ctx, entry.key(),
- updRes.oldValue()));
+ updRes.oldValue(), req.keepBinary()));
}
}
@@ -2134,8 +2143,14 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
res.addFailedKeys(putMap != null ? putMap.keySet() : rmvKeys, e, ctx);
}
- if (storeErr != null)
- res.addFailedKeys(storeErr.failedKeys(), storeErr.getCause(), ctx);
+ if (storeErr != null) {
+ ArrayList<KeyCacheObject> failed = new ArrayList<>(storeErr.failedKeys().size());
+
+ for (Object failedKey : storeErr.failedKeys())
+ failed.add(ctx.toCacheKeyObject(failedKey));
+
+ res.addFailedKeys(failed, storeErr.getCause(), ctx);
+ }
return dhtFut;
}
@@ -2361,6 +2376,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
req.subjectId(),
req.taskNameHash(),
req.skipStore(),
+ req.keepBinary(),
MAX_RETRIES,
true);
@@ -2511,6 +2527,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
/*write-through*/false,
/*read-through*/false,
/*retval*/false,
+ req.keepBinary(),
/*expiry policy*/null,
/*event*/true,
/*metrics*/true,
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
index 4ace5c4..233a45a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateFuture.java
@@ -234,7 +234,8 @@ public class GridDhtAtomicUpdateFuture extends GridFutureAdapter<Void>
this.updateReq.subjectId(),
this.updateReq.taskNameHash(),
forceTransformBackups ? this.updateReq.invokeArguments() : null,
- cctx.deploymentEnabled());
+ cctx.deploymentEnabled(),
+ this.updateReq.keepBinary());
mappings.put(nodeId, updateReq);
}
@@ -290,7 +291,8 @@ public class GridDhtAtomicUpdateFuture extends GridFutureAdapter<Void>
this.updateReq.subjectId(),
this.updateReq.taskNameHash(),
forceTransformBackups ? this.updateReq.invokeArguments() : null,
- cctx.deploymentEnabled());
+ cctx.deploymentEnabled(),
+ this.updateReq.keepBinary());
mappings.put(nodeId, updateReq);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
index e55cac9..7b95042 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java
@@ -139,6 +139,9 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
/** Task name hash. */
private int taskNameHash;
+ /** Keep portable flag. */
+ private boolean keepBinary;
+
/**
* Empty constructor required by {@link Externalizable}.
*/
@@ -172,7 +175,8 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
UUID subjId,
int taskNameHash,
Object[] invokeArgs,
- boolean addDepInfo
+ boolean addDepInfo,
+ boolean keepBinary
) {
assert invokeArgs == null || forceTransformBackups;
@@ -187,6 +191,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
this.taskNameHash = taskNameHash;
this.invokeArgs = invokeArgs;
this.addDepInfo = addDepInfo;
+ this.keepBinary = keepBinary;
keys = new ArrayList<>();
@@ -419,6 +424,13 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
}
/**
+ * @return Keep portable flag.
+ */
+ public boolean keepBinary() {
+ return keepBinary;
+ }
+
+ /**
* @param idx Key index.
* @return Value.
*/
@@ -642,84 +654,90 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
writer.incrementState();
case 9:
- if (!writer.writeCollection("keys", keys, MessageCollectionItemType.MSG))
+ if (!writer.writeBoolean("keepBinary", keepBinary))
return false;
writer.incrementState();
case 10:
- if (!writer.writeCollection("nearEntryProcessorsBytes", nearEntryProcessorsBytes, MessageCollectionItemType.BYTE_ARR))
+ if (!writer.writeCollection("keys", keys, MessageCollectionItemType.MSG))
return false;
writer.incrementState();
case 11:
- if (!writer.writeMessage("nearExpireTimes", nearExpireTimes))
+ if (!writer.writeCollection("nearEntryProcessorsBytes", nearEntryProcessorsBytes, MessageCollectionItemType.BYTE_ARR))
return false;
writer.incrementState();
case 12:
- if (!writer.writeCollection("nearKeys", nearKeys, MessageCollectionItemType.MSG))
+ if (!writer.writeMessage("nearExpireTimes", nearExpireTimes))
return false;
writer.incrementState();
case 13:
- if (!writer.writeMessage("nearTtls", nearTtls))
+ if (!writer.writeCollection("nearKeys", nearKeys, MessageCollectionItemType.MSG))
return false;
writer.incrementState();
case 14:
- if (!writer.writeCollection("nearVals", nearVals, MessageCollectionItemType.MSG))
+ if (!writer.writeMessage("nearTtls", nearTtls))
return false;
writer.incrementState();
case 15:
- if (!writer.writeUuid("nodeId", nodeId))
+ if (!writer.writeCollection("nearVals", nearVals, MessageCollectionItemType.MSG))
return false;
writer.incrementState();
case 16:
- if (!writer.writeUuid("subjId", subjId))
+ if (!writer.writeUuid("nodeId", nodeId))
return false;
writer.incrementState();
case 17:
- if (!writer.writeByte("syncMode", syncMode != null ? (byte)syncMode.ordinal() : -1))
+ if (!writer.writeUuid("subjId", subjId))
return false;
writer.incrementState();
case 18:
- if (!writer.writeInt("taskNameHash", taskNameHash))
+ if (!writer.writeByte("syncMode", syncMode != null ? (byte)syncMode.ordinal() : -1))
return false;
writer.incrementState();
case 19:
- if (!writer.writeMessage("topVer", topVer))
+ if (!writer.writeInt("taskNameHash", taskNameHash))
return false;
writer.incrementState();
case 20:
- if (!writer.writeMessage("ttls", ttls))
+ if (!writer.writeMessage("topVer", topVer))
return false;
writer.incrementState();
case 21:
- if (!writer.writeCollection("vals", vals, MessageCollectionItemType.MSG))
+ if (!writer.writeMessage("ttls", ttls))
return false;
writer.incrementState();
case 22:
+ if (!writer.writeCollection("vals", vals, MessageCollectionItemType.MSG))
+ return false;
+
+ writer.incrementState();
+
+ case 23:
if (!writer.writeMessage("writeVer", writeVer))
return false;
@@ -790,7 +808,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
case 9:
- keys = reader.readCollection("keys", MessageCollectionItemType.MSG);
+ keepBinary = reader.readBoolean("keepBinary");
if (!reader.isLastRead())
return false;
@@ -798,7 +816,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
case 10:
- nearEntryProcessorsBytes = reader.readCollection("nearEntryProcessorsBytes", MessageCollectionItemType.BYTE_ARR);
+ keys = reader.readCollection("keys", MessageCollectionItemType.MSG);
if (!reader.isLastRead())
return false;
@@ -806,7 +824,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
case 11:
- nearExpireTimes = reader.readMessage("nearExpireTimes");
+ nearEntryProcessorsBytes = reader.readCollection("nearEntryProcessorsBytes", MessageCollectionItemType.BYTE_ARR);
if (!reader.isLastRead())
return false;
@@ -814,7 +832,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
case 12:
- nearKeys = reader.readCollection("nearKeys", MessageCollectionItemType.MSG);
+ nearExpireTimes = reader.readMessage("nearExpireTimes");
if (!reader.isLastRead())
return false;
@@ -822,7 +840,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
case 13:
- nearTtls = reader.readMessage("nearTtls");
+ nearKeys = reader.readCollection("nearKeys", MessageCollectionItemType.MSG);
if (!reader.isLastRead())
return false;
@@ -830,7 +848,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
case 14:
- nearVals = reader.readCollection("nearVals", MessageCollectionItemType.MSG);
+ nearTtls = reader.readMessage("nearTtls");
if (!reader.isLastRead())
return false;
@@ -838,7 +856,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
case 15:
- nodeId = reader.readUuid("nodeId");
+ nearVals = reader.readCollection("nearVals", MessageCollectionItemType.MSG);
if (!reader.isLastRead())
return false;
@@ -846,7 +864,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
case 16:
- subjId = reader.readUuid("subjId");
+ nodeId = reader.readUuid("nodeId");
if (!reader.isLastRead())
return false;
@@ -854,6 +872,14 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
case 17:
+ subjId = reader.readUuid("subjId");
+
+ if (!reader.isLastRead())
+ return false;
+
+ reader.incrementState();
+
+ case 18:
byte syncModeOrd;
syncModeOrd = reader.readByte("syncMode");
@@ -865,7 +891,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
- case 18:
+ case 19:
taskNameHash = reader.readInt("taskNameHash");
if (!reader.isLastRead())
@@ -873,7 +899,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
- case 19:
+ case 20:
topVer = reader.readMessage("topVer");
if (!reader.isLastRead())
@@ -881,7 +907,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
- case 20:
+ case 21:
ttls = reader.readMessage("ttls");
if (!reader.isLastRead())
@@ -889,7 +915,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
- case 21:
+ case 22:
vals = reader.readCollection("vals", MessageCollectionItemType.MSG);
if (!reader.isLastRead())
@@ -897,7 +923,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
reader.incrementState();
- case 22:
+ case 23:
writeVer = reader.readMessage("writeVer");
if (!reader.isLastRead())
@@ -917,7 +943,7 @@ public class GridDhtAtomicUpdateRequest extends GridCacheMessage implements Grid
/** {@inheritDoc} */
@Override public byte fieldsCount() {
- return 23;
+ return 24;
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
index ae662c8..02c62d8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateFuture.java
@@ -138,6 +138,9 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
/** Skip store flag. */
private final boolean skipStore;
+ /** */
+ private final boolean keepBinary;
+
/** Wait for topology future flag. */
private final boolean waitTopFut;
@@ -184,6 +187,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
UUID subjId,
int taskNameHash,
boolean skipStore,
+ boolean keepBinary,
int remapCnt,
boolean waitTopFut
) {
@@ -209,6 +213,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
this.subjId = subjId;
this.taskNameHash = taskNameHash;
this.skipStore = skipStore;
+ this.keepBinary = keepBinary;
this.waitTopFut = waitTopFut;
if (log == null)
@@ -474,7 +479,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
cctx.io().send(req.nodeId(), req, cctx.ioPolicy());
if (syncMode == FULL_ASYNC)
- onDone(new GridCacheReturn(cctx, true, null, true));
+ onDone(new GridCacheReturn(cctx, true, true, null, true));
}
catch (IgniteCheckedException e) {
state.onSendError(req, e);
@@ -523,7 +528,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
}
if (syncMode == FULL_ASYNC)
- onDone(new GridCacheReturn(cctx, true, null, true));
+ onDone(new GridCacheReturn(cctx, true, true, null, true));
}
/**
@@ -893,7 +898,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
assert pendingMappings != null;
if (size == 0)
- onDone(new GridCacheReturn(cctx, true, null, true));
+ onDone(new GridCacheReturn(cctx, true, true, null, true));
else
doUpdate(pendingMappings);
}
@@ -1050,6 +1055,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
subjId,
taskNameHash,
skipStore,
+ keepBinary,
cctx.kernalContext().clientNode(),
cctx.deploymentEnabled());
@@ -1143,6 +1149,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
subjId,
taskNameHash,
skipStore,
+ keepBinary,
cctx.kernalContext().clientNode(),
cctx.deploymentEnabled());
@@ -1188,7 +1195,7 @@ public class GridNearAtomicUpdateFuture extends GridFutureAdapter<Object>
Collection<Object> keys = new ArrayList<>(failedKeys.size());
for (KeyCacheObject key : failedKeys)
- keys.add(key.value(cctx.cacheObjectContext(), false));
+ keys.add(cctx.cacheObjectContext().unwrapPortableIfNeeded(key, keepBinary, false));
err0.add(keys, err, topVer);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
index 33fa4bd..b7100dd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateRequest.java
@@ -151,6 +151,9 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
/** */
private boolean clientReq;
+ /** Keep portable flag. */
+ private boolean keepBinary;
+
/**
* Empty constructor required by {@link Externalizable}.
*/
@@ -197,6 +200,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
@Nullable UUID subjId,
int taskNameHash,
boolean skipStore,
+ boolean keepBinary,
boolean clientReq,
boolean addDepInfo
) {
@@ -219,6 +223,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
this.subjId = subjId;
this.taskNameHash = taskNameHash;
this.skipStore = skipStore;
+ this.keepBinary = keepBinary;
this.clientReq = clientReq;
this.addDepInfo = addDepInfo;
@@ -336,6 +341,13 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
}
/**
+ * @return Keep portable flag.
+ */
+ public boolean keepBinary() {
+ return keepBinary;
+ }
+
+ /**
* @param key Key to add.
* @param val Optional update value.
* @param conflictTtl Conflict TTL (optional).
@@ -685,66 +697,72 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
writer.incrementState();
case 14:
- if (!writer.writeCollection("keys", keys, MessageCollectionItemType.MSG))
+ if (!writer.writeBoolean("keepBinary", keepBinary))
return false;
writer.incrementState();
case 15:
- if (!writer.writeByte("op", op != null ? (byte)op.ordinal() : -1))
+ if (!writer.writeCollection("keys", keys, MessageCollectionItemType.MSG))
return false;
writer.incrementState();
case 16:
- if (!writer.writeBoolean("retval", retval))
+ if (!writer.writeByte("op", op != null ? (byte)op.ordinal() : -1))
return false;
writer.incrementState();
case 17:
- if (!writer.writeBoolean("skipStore", skipStore))
+ if (!writer.writeBoolean("retval", retval))
return false;
writer.incrementState();
case 18:
- if (!writer.writeUuid("subjId", subjId))
+ if (!writer.writeBoolean("skipStore", skipStore))
return false;
writer.incrementState();
case 19:
- if (!writer.writeByte("syncMode", syncMode != null ? (byte)syncMode.ordinal() : -1))
+ if (!writer.writeUuid("subjId", subjId))
return false;
writer.incrementState();
case 20:
- if (!writer.writeInt("taskNameHash", taskNameHash))
+ if (!writer.writeByte("syncMode", syncMode != null ? (byte)syncMode.ordinal() : -1))
return false;
writer.incrementState();
case 21:
- if (!writer.writeBoolean("topLocked", topLocked))
+ if (!writer.writeInt("taskNameHash", taskNameHash))
return false;
writer.incrementState();
case 22:
- if (!writer.writeMessage("topVer", topVer))
+ if (!writer.writeBoolean("topLocked", topLocked))
return false;
writer.incrementState();
case 23:
- if (!writer.writeMessage("updateVer", updateVer))
+ if (!writer.writeMessage("topVer", topVer))
return false;
writer.incrementState();
case 24:
+ if (!writer.writeMessage("updateVer", updateVer))
+ return false;
+
+ writer.incrementState();
+
+ case 25:
if (!writer.writeCollection("vals", vals, MessageCollectionItemType.MSG))
return false;
@@ -855,7 +873,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
reader.incrementState();
case 14:
- keys = reader.readCollection("keys", MessageCollectionItemType.MSG);
+ keepBinary = reader.readBoolean("keepBinary");
if (!reader.isLastRead())
return false;
@@ -863,6 +881,14 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
reader.incrementState();
case 15:
+ keys = reader.readCollection("keys", MessageCollectionItemType.MSG);
+
+ if (!reader.isLastRead())
+ return false;
+
+ reader.incrementState();
+
+ case 16:
byte opOrd;
opOrd = reader.readByte("op");
@@ -874,7 +900,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
reader.incrementState();
- case 16:
+ case 17:
retval = reader.readBoolean("retval");
if (!reader.isLastRead())
@@ -882,7 +908,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
reader.incrementState();
- case 17:
+ case 18:
skipStore = reader.readBoolean("skipStore");
if (!reader.isLastRead())
@@ -890,7 +916,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
reader.incrementState();
- case 18:
+ case 19:
subjId = reader.readUuid("subjId");
if (!reader.isLastRead())
@@ -898,7 +924,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
reader.incrementState();
- case 19:
+ case 20:
byte syncModeOrd;
syncModeOrd = reader.readByte("syncMode");
@@ -910,7 +936,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
reader.incrementState();
- case 20:
+ case 21:
taskNameHash = reader.readInt("taskNameHash");
if (!reader.isLastRead())
@@ -918,7 +944,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
reader.incrementState();
- case 21:
+ case 22:
topLocked = reader.readBoolean("topLocked");
if (!reader.isLastRead())
@@ -926,7 +952,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
reader.incrementState();
- case 22:
+ case 23:
topVer = reader.readMessage("topVer");
if (!reader.isLastRead())
@@ -934,7 +960,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
reader.incrementState();
- case 23:
+ case 24:
updateVer = reader.readMessage("updateVer");
if (!reader.isLastRead())
@@ -942,7 +968,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
reader.incrementState();
- case 24:
+ case 25:
vals = reader.readCollection("vals", MessageCollectionItemType.MSG);
if (!reader.isLastRead())
@@ -962,7 +988,7 @@ public class GridNearAtomicUpdateRequest extends GridCacheMessage implements Gri
/** {@inheritDoc} */
@Override public byte fieldsCount() {
- return 25;
+ return 26;
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java
index 6536af3..b164e7e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java
@@ -377,12 +377,11 @@ public class GridNearAtomicUpdateResponse extends GridCacheMessage implements Gr
* @param e Error cause.
* @param ctx Context.
*/
- public synchronized void addFailedKeys(Collection<Object> keys, Throwable e, GridCacheContext ctx) {
+ public synchronized void addFailedKeys(Collection<KeyCacheObject> keys, Throwable e, GridCacheContext ctx) {
if (failedKeys == null)
failedKeys = new ArrayList<>(keys.size());
- for (Object key : keys)
- failedKeys.add(ctx.toCacheKeyObject(key));
+ failedKeys.addAll(keys);
if (err == null)
err = new IgniteCheckedException("Failed to update keys on primary node.");
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
index f03b461..907c68d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
@@ -216,7 +216,7 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
false,
opCtx != null && opCtx.skipStore());
}
- });
+ }, opCtx);
}
AffinityTopologyVersion topVer = tx == null ?
@@ -351,7 +351,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
subjId,
null,
taskName,
- expiryPlc);
+ expiryPlc,
+ !deserializePortable);
if (res != null) {
v = res.get1();
@@ -370,7 +371,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
subjId,
null,
taskName,
- expiryPlc);
+ expiryPlc,
+ !deserializePortable);
}
// Entry was not in memory or in swap, so we remove it from cache.
@@ -487,7 +489,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
timeout,
accessTtl,
CU.empty0(),
- opCtx != null && opCtx.skipStore());
+ opCtx != null && opCtx.skipStore(),
+ opCtx != null && opCtx.isKeepBinary());
// Future will be added to mvcc only if it was mapped to remote nodes.
fut.map();
@@ -746,7 +749,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
final long timeout,
final long accessTtl,
@Nullable final CacheEntryPredicate[] filter,
- final boolean skipStore
+ final boolean skipStore,
+ final boolean keepBinary
) {
assert keys != null;
@@ -769,7 +773,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
timeout,
accessTtl,
filter,
- skipStore);
+ skipStore,
+ keepBinary);
}
catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
@@ -793,7 +798,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
timeout,
accessTtl,
filter,
- skipStore);
+ skipStore,
+ keepBinary);
}
}
);
@@ -827,7 +833,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
final long timeout,
final long accessTtl,
@Nullable final CacheEntryPredicate[] filter,
- boolean skipStore) {
+ boolean skipStore,
+ boolean keepBinary) {
int cnt = keys.size();
if (tx == null) {
@@ -843,7 +850,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
threadId,
accessTtl,
filter,
- skipStore);
+ skipStore,
+ keepBinary);
// Add before mapping.
if (!ctx.mvcc().addFuture(fut))
@@ -909,7 +917,8 @@ public class GridDhtColocatedCache<K, V> extends GridDhtTransactionalCacheAdapte
tx.implicit(),
txRead,
accessTtl,
- skipStore);
+ skipStore,
+ keepBinary);
return new GridDhtEmbeddedFuture<>(
new C2<GridCacheReturn, Exception, Exception>() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
index 365b46b..13b3cab 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java
@@ -143,6 +143,9 @@ public final class GridDhtColocatedLockFuture extends GridCompoundIdentityFuture
/** Skip store flag. */
private final boolean skipStore;
+ /** Keep binary. */
+ private final boolean keepBinary;
+
/**
* @param cctx Registry.
* @param keys Keys to lock.
@@ -163,7 +166,8 @@ public final class GridDhtColocatedLockFuture extends GridCompoundIdentityFuture
long timeout,
long accessTtl,
CacheEntryPredicate[] filter,
- boolean skipStore) {
+ boolean skipStore,
+ boolean keepBinary) {
super(cctx.kernalContext(), CU.boolReducer());
assert keys != null;
@@ -177,6 +181,7 @@ public final class GridDhtColocatedLockFuture extends GridCompoundIdentityFuture
this.accessTtl = accessTtl;
this.filter = filter;
this.skipStore = skipStore;
+ this.keepBinary = keepBinary;
ignoreInterrupts(true);
@@ -851,6 +856,7 @@ public final class GridDhtColocatedLockFuture extends GridCompoundIdentityFuture
inTx() ? tx.taskNameHash() : 0,
read ? accessTtl : -1L,
skipStore,
+ keepBinary,
clientFirst,
cctx.deploymentEnabled());
@@ -1021,7 +1027,8 @@ public final class GridDhtColocatedLockFuture extends GridCompoundIdentityFuture
timeout,
accessTtl,
filter,
- skipStore);
+ skipStore,
+ keepBinary);
// Add new future.
add(new GridEmbeddedFuture<>(
@@ -1431,7 +1438,8 @@ public final class GridDhtColocatedLockFuture extends GridCompoundIdentityFuture
false,
CU.subjectId(tx, cctx.shared()),
null,
- tx == null ? null : tx.resolveTaskName());
+ tx == null ? null : tx.resolveTaskName(),
+ keepBinary);
}
i++;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
index db0e780..7970a44 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
@@ -553,7 +553,7 @@ public final class GridDhtForceKeysFuture<K, V> extends GridCompoundFuture<Objec
if (rec && !entry.isInternal())
cctx.events().addEvent(entry.partition(), entry.key(), cctx.localNodeId(),
(IgniteUuid)null, null, EVT_CACHE_REBALANCE_OBJECT_LOADED, info.value(), true, null,
- false, null, null, null);
+ false, null, null, null, false);
}
}
catch (IgniteCheckedException e) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandPool.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandPool.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandPool.java
index e993a88..e1ca25b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandPool.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionDemandPool.java
@@ -556,7 +556,7 @@ public class GridDhtPartitionDemandPool {
if (cctx.events().isRecordable(EVT_CACHE_REBALANCE_OBJECT_LOADED) && !cached.isInternal())
cctx.events().addEvent(cached.partition(), cached.key(), cctx.localNodeId(),
(IgniteUuid)null, null, EVT_CACHE_REBALANCE_OBJECT_LOADED, entry.value(), true, null,
- false, null, null, null);
+ false, null, null, null, false);
}
else if (log.isDebugEnabled())
log.debug("Rebalancing entry is already in cache (will ignore) [key=" + cached.key() +
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java
index 1bf03a9..648a248 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearAtomicCache.java
@@ -195,6 +195,7 @@ public class GridNearAtomicCache<K, V> extends GridNearCacheAdapter<K, V> {
null,
ttl,
expireTime,
+ req.keepBinary(),
req.nodeId(),
req.subjectId(),
taskName);
@@ -224,6 +225,7 @@ public class GridNearAtomicCache<K, V> extends GridNearCacheAdapter<K, V> {
@Nullable byte[] valBytes,
long ttl,
long expireTime,
+ boolean keepPortable,
UUID nodeId,
UUID subjId,
String taskName
@@ -249,6 +251,7 @@ public class GridNearAtomicCache<K, V> extends GridNearCacheAdapter<K, V> {
/*write-through*/false,
/*read-through*/false,
/*retval*/false,
+ keepPortable,
/**expiry policy*/null,
/*event*/true,
/*metrics*/true,
@@ -347,6 +350,7 @@ public class GridNearAtomicCache<K, V> extends GridNearCacheAdapter<K, V> {
/*write-through*/false,
/*read-through*/false,
/*retval*/false,
+ req.keepBinary(),
null,
/*event*/true,
/*metrics*/true,
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
index d558cc5..afdc5f1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheEntry.java
@@ -376,6 +376,7 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry {
long ttl,
long expireTime,
boolean evt,
+ boolean keepBinary,
AffinityTopologyVersion topVer,
UUID subjId)
throws IgniteCheckedException, GridCacheEntryRemovedException {
@@ -417,8 +418,20 @@ public class GridNearCacheEntry extends GridDistributedCacheEntry {
}
if (evt && cctx.events().isRecordable(EVT_CACHE_OBJECT_READ))
- cctx.events().addEvent(partition(), key, tx, null, EVT_CACHE_OBJECT_READ,
- val, val != null, old, hasVal, subjId, null, null);
+ cctx.events().addEvent(
+ partition(),
+ key,
+ tx,
+ null,
+ EVT_CACHE_OBJECT_READ,
+ val,
+ val != null,
+ old,
+ hasVal,
+ subjId,
+ null,
+ null,
+ keepBinary);
return ret;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
index ae1d43c..685b998 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java
@@ -270,9 +270,30 @@ public final class GridNearGetFuture<K, V> extends CacheDistributedGetFutureAdap
Map<KeyCacheObject, GridNearCacheEntry> savedEntries = null;
- // Assign keys to primary nodes.
- for (KeyCacheObject key : keys)
- savedEntries = map(key, mappings, topVer, mapped, savedEntries);
+ {
+ boolean success = false;
+
+ try {
+ // Assign keys to primary nodes.
+ for (KeyCacheObject key : keys)
+ savedEntries = map(key, mappings, topVer, mapped, savedEntries);
+
+ success = true;
+ }
+ finally {
+ // Exception has been thrown, must release reserved near entries.
+ if (!success) {
+ GridCacheVersion obsolete = cctx.versions().next(topVer);
+
+ for (GridNearCacheEntry reserved : savedEntries.values()) {
+ reserved.releaseEviction();
+
+ if (reserved.markObsolete(obsolete))
+ reserved.context().cache().removeEntry(reserved);
+ }
+ }
+ }
+ }
if (isDone())
return;
@@ -419,7 +440,8 @@ public final class GridNearGetFuture<K, V> extends CacheDistributedGetFutureAdap
subjId,
null,
taskName,
- expiryPlc);
+ expiryPlc,
+ !deserializePortable);
if (res != null) {
v = res.get1();
@@ -438,7 +460,8 @@ public final class GridNearGetFuture<K, V> extends CacheDistributedGetFutureAdap
subjId,
null,
taskName,
- expiryPlc);
+ expiryPlc,
+ !deserializePortable);
}
}
@@ -466,7 +489,8 @@ public final class GridNearGetFuture<K, V> extends CacheDistributedGetFutureAdap
subjId,
null,
taskName,
- expiryPlc);
+ expiryPlc,
+ !deserializePortable);
if (res != null) {
v = res.get1();
@@ -485,7 +509,8 @@ public final class GridNearGetFuture<K, V> extends CacheDistributedGetFutureAdap
subjId,
null,
taskName,
- expiryPlc);
+ expiryPlc,
+ !deserializePortable);
}
// Entry was not in memory or in swap, so we remove it from cache.
@@ -537,11 +562,8 @@ public final class GridNearGetFuture<K, V> extends CacheDistributedGetFutureAdap
add(new GridFinishedFuture<>(Collections.singletonMap(key0, val0)));
}
else {
- K key0 = key.value(cctx.cacheObjectContext(), true);
- V val0 = v.value(cctx.cacheObjectContext(), true);
-
- val0 = (V)cctx.unwrapPortableIfNeeded(val0, !deserializePortable);
- key0 = (K)cctx.unwrapPortableIfNeeded(key0, !deserializePortable);
+ K key0 = (K)cctx.unwrapPortableIfNeeded(key, !deserializePortable);
+ V val0 = (V)cctx.unwrapPortableIfNeeded(v, !deserializePortable);
add(new GridFinishedFuture<>(Collections.singletonMap(key0, val0)));
}
@@ -697,6 +719,7 @@ public final class GridNearGetFuture<K, V> extends CacheDistributedGetFutureAdap
info.ttl(),
info.expireTime(),
true,
+ !deserializePortable,
topVer,
subjId);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
index c5b55bd..21aa457 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java
@@ -152,6 +152,9 @@ public final class GridNearLockFuture extends GridCompoundIdentityFuture<Boolean
/** Skip store flag. */
private final boolean skipStore;
+ /** Keep binary context flag. */
+ private final boolean keepBinary;
+
/**
* @param cctx Registry.
* @param keys Keys to lock.
@@ -172,7 +175,8 @@ public final class GridNearLockFuture extends GridCompoundIdentityFuture<Boolean
long timeout,
long accessTtl,
CacheEntryPredicate[] filter,
- boolean skipStore) {
+ boolean skipStore,
+ boolean keepBinary) {
super(cctx.kernalContext(), CU.boolReducer());
assert keys != null;
@@ -186,6 +190,7 @@ public final class GridNearLockFuture extends GridCompoundIdentityFuture<Boolean
this.accessTtl = accessTtl;
this.filter = filter;
this.skipStore = skipStore;
+ this.keepBinary = keepBinary;
ignoreInterrupts(true);
@@ -968,6 +973,7 @@ public final class GridNearLockFuture extends GridCompoundIdentityFuture<Boolean
inTx() ? tx.taskNameHash() : 0,
read ? accessTtl : -1L,
skipStore,
+ keepBinary,
clientFirst,
cctx.deploymentEnabled());
@@ -1150,7 +1156,8 @@ public final class GridNearLockFuture extends GridCompoundIdentityFuture<Boolean
hasBytes,
CU.subjectId(tx, cctx.shared()),
null,
- inTx() ? tx.resolveTaskName() : null);
+ inTx() ? tx.resolveTaskName() : null,
+ keepBinary);
if (cctx.cache().configuration().isStatisticsEnabled())
cctx.cache().metrics0().onRead(oldVal != null);
@@ -1540,7 +1547,8 @@ public final class GridNearLockFuture extends GridCompoundIdentityFuture<Boolean
hasOldVal,
CU.subjectId(tx, cctx.shared()),
null,
- inTx() ? tx.resolveTaskName() : null);
+ inTx() ? tx.resolveTaskName() : null,
+ keepBinary);
if (cctx.cache().configuration().isStatisticsEnabled())
cctx.cache().metrics0().onRead(false);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
index 165da84..4d875d2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockRequest.java
@@ -145,6 +145,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
int taskNameHash,
long accessTtl,
boolean skipStore,
+ boolean keepBinary,
boolean firstClientReq,
boolean addDepInfo
@@ -164,6 +165,7 @@ public class GridNearLockRequest extends GridDistributedLockRequest {
keyCnt,
txSize,
skipStore,
+ keepBinary,
addDepInfo);
assert topVer.compareTo(AffinityTopologyVersion.ZERO) > 0;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
index 0e8aa0d..65a054c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
@@ -147,7 +147,7 @@ public class GridNearTransactionalCache<K, V> extends GridNearCacheAdapter<K, V>
false,
skipStore);
}
- });
+ }, opCtx);
}
subjId = ctx.subjectIdPerCall(subjId, opCtx);
@@ -340,7 +340,8 @@ public class GridNearTransactionalCache<K, V> extends GridNearCacheAdapter<K, V>
GridCacheOperation.NOOP,
null /*Value.*/,
null /*dr version*/,
- req.skipStore());
+ req.skipStore(),
+ req.keepBinary());
}
// Add remote candidate before reordering.
@@ -454,7 +455,8 @@ public class GridNearTransactionalCache<K, V> extends GridNearCacheAdapter<K, V>
timeout,
accessTtl,
CU.empty0(),
- opCtx != null && opCtx.skipStore());
+ opCtx != null && opCtx.skipStore(),
+ opCtx != null && opCtx.isKeepBinary());
if (!ctx.mvcc().addFuture(fut))
throw new IllegalStateException("Duplicate future ID: " + fut);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index 883c285..e27d632 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -350,6 +350,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
final Collection<KeyCacheObject> keys,
boolean skipVals,
final boolean needVer,
+ boolean keepBinary,
final GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c
) {
if (cacheCtx.isNear()) {
@@ -410,7 +411,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
else {
assert cacheCtx.isLocal();
- return super.loadMissing(cacheCtx, readThrough, async, keys, skipVals, needVer, c);
+ return super.loadMissing(cacheCtx, readThrough, async, keys, skipVals, keepBinary, needVer, c);
}
}
@@ -1079,7 +1080,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
boolean implicit,
boolean read,
long accessTtl,
- boolean skipStore) {
+ boolean skipStore,
+ boolean keepBinary) {
assert pessimistic();
try {
@@ -1108,7 +1110,8 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter {
isolation,
accessTtl,
CU.empty0(),
- skipStore);
+ skipStore,
+ keepBinary);
return new GridEmbeddedFuture<>(
fut,
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
index 87c68b2..58ee0c6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java
@@ -117,7 +117,7 @@ public class GridNearTxRemote extends GridDistributedTxRemoteAdapter {
concurrency,
isolation,
invalidate,
- timeout,
+ timeout,
txSize,
subjId,
taskNameHash
@@ -187,9 +187,9 @@ public class GridNearTxRemote extends GridDistributedTxRemoteAdapter {
concurrency,
isolation,
invalidate,
- timeout,
+ timeout,
txSize,
- subjId,
+ subjId,
taskNameHash
);
@@ -356,7 +356,8 @@ public class GridNearTxRemote extends GridDistributedTxRemoteAdapter {
GridCacheOperation op,
CacheObject val,
@Nullable GridCacheVersion drVer,
- boolean skipStore
+ boolean skipStore,
+ boolean keepBinary
) throws IgniteCheckedException {
checkInternal(key);
@@ -389,7 +390,8 @@ public class GridNearTxRemote extends GridDistributedTxRemoteAdapter {
-1L,
cached,
drVer,
- skipStore);
+ skipStore,
+ keepBinary);
writeMap.put(key, txEntry);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCacheEntry.java
index 85ed881..0ceae20 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalCacheEntry.java
@@ -84,7 +84,9 @@ public class GridLocalCacheEntry extends GridCacheMapEntry {
long timeout,
boolean reenter,
boolean tx,
- boolean implicitSingle) throws GridCacheEntryRemovedException {
+ boolean implicitSingle,
+ boolean keepBinary
+ ) throws GridCacheEntryRemovedException {
GridCacheMvccCandidate prev;
GridCacheMvccCandidate cand;
GridCacheMvccCandidate owner;
@@ -141,7 +143,7 @@ public class GridLocalCacheEntry extends GridCacheMapEntry {
// Event notification.
if (cctx.events().isRecordable(EVT_CACHE_OBJECT_LOCKED))
cctx.events().addEvent(partition(), key, cand.nodeId(), cand, EVT_CACHE_OBJECT_LOCKED, val, hasVal,
- val, hasVal, null, null, null);
+ val, hasVal, null, null, null, keepBinary);
}
checkOwnerChanged(prev, owner);
@@ -207,7 +209,8 @@ public class GridLocalCacheEntry extends GridCacheMapEntry {
@Override public boolean tmLock(IgniteInternalTx tx,
long timeout,
@Nullable GridCacheVersion serOrder,
- GridCacheVersion serReadVer)
+ GridCacheVersion serReadVer,
+ boolean keepBinary)
throws GridCacheEntryRemovedException {
GridCacheMvccCandidate cand = addLocal(
tx.threadId(),
@@ -217,7 +220,8 @@ public class GridLocalCacheEntry extends GridCacheMapEntry {
timeout,
/*reenter*/false,
/*tx*/true,
- tx.implicitSingle()
+ tx.implicitSingle(),
+ keepBinary
);
if (cand != null) {
@@ -352,7 +356,7 @@ public class GridLocalCacheEntry extends GridCacheMapEntry {
// Event notification.
if (cctx.events().isRecordable(EVT_CACHE_OBJECT_UNLOCKED))
cctx.events().addEvent(partition(), key, prev.nodeId(), prev, EVT_CACHE_OBJECT_UNLOCKED, val, hasVal,
- val, hasVal, null, null, null);
+ val, hasVal, null, null, null, true);
}
checkOwnerChanged(prev, owner);
@@ -408,7 +412,7 @@ public class GridLocalCacheEntry extends GridCacheMapEntry {
// Event notification.
if (cctx.events().isRecordable(EVT_CACHE_OBJECT_UNLOCKED))
cctx.events().addEvent(partition(), key, doomed.nodeId(), doomed, EVT_CACHE_OBJECT_UNLOCKED,
- val, hasVal, val, hasVal, null, null, null);
+ val, hasVal, val, hasVal, null, null, null, true);
}
checkOwnerChanged(prev, owner);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalLockFuture.java
index cb14b4c..64820ef 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/GridLocalLockFuture.java
@@ -230,7 +230,8 @@ public final class GridLocalLockFuture<K, V> extends GridFutureAdapter<Boolean>
timeout,
!inTx(),
inTx(),
- implicitSingle()
+ implicitSingle(),
+ true
);
entries.add(entry);
[19/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
index e61cba7..8fcbc86 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
@@ -17,28 +17,6 @@
package org.apache.ignite.internal.portable;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.IgnitionEx;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
-import org.apache.ignite.internal.util.GridConcurrentHashSet;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.internal.util.typedef.T2;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.marshaller.MarshallerContext;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableIdMapper;
-import org.apache.ignite.portable.PortableInvalidClassException;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableSerializer;
-import org.apache.ignite.portable.PortableTypeConfiguration;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-
import java.io.Externalizable;
import java.io.File;
import java.io.IOException;
@@ -71,6 +49,30 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cache.CacheKeyConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryTypeIdMapper;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinarySerializer;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.util.GridConcurrentHashSet;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.marshaller.MarshallerContext;
+import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
/**
* Portable context.
@@ -83,10 +85,10 @@ public class PortableContext implements Externalizable {
private static final ClassLoader dfltLdr = U.gridClassLoader();
/** */
- static final PortableIdMapper DFLT_ID_MAPPER = new IdMapperWrapper(null);
+ static final BinaryTypeIdMapper DFLT_ID_MAPPER = new IdMapperWrapper(null);
/** */
- static final PortableIdMapper BASIC_CLS_ID_MAPPER = new BasicClassIdMapper();
+ static final BinaryTypeIdMapper BASIC_CLS_ID_MAPPER = new BasicClassIdMapper();
/** */
static final char[] LOWER_CASE_CHARS;
@@ -126,10 +128,10 @@ public class PortableContext implements Externalizable {
private final Map<Class<? extends Map>, Byte> mapTypes = new HashMap<>();
/** */
- private final ConcurrentMap<Integer, PortableIdMapper> mappers = new ConcurrentHashMap8<>(0);
+ private final ConcurrentMap<Integer, BinaryTypeIdMapper> mappers = new ConcurrentHashMap8<>(0);
/** */
- private final Map<String, PortableIdMapper> typeMappers = new ConcurrentHashMap8<>(0);
+ private final Map<String, BinaryTypeIdMapper> typeMappers = new ConcurrentHashMap8<>(0);
/** */
private Map<Integer, Boolean> metaEnabled = new HashMap<>(0);
@@ -144,6 +146,9 @@ public class PortableContext implements Externalizable {
private String gridName;
/** */
+ private IgniteConfiguration igniteCfg;
+
+ /** */
private final OptimizedMarshaller optmMarsh = new OptimizedMarshaller();
/** */
@@ -167,13 +172,15 @@ public class PortableContext implements Externalizable {
/**
* @param metaHnd Meta data handler.
- * @param gridName Grid name.
+ * @param igniteCfg Ignite configuration.
*/
- public PortableContext(PortableMetaDataHandler metaHnd, @Nullable String gridName) {
+ public PortableContext(PortableMetaDataHandler metaHnd, @Nullable IgniteConfiguration igniteCfg) {
assert metaHnd != null;
this.metaHnd = metaHnd;
- this.gridName = gridName;
+ this.igniteCfg = igniteCfg;
+
+ gridName = igniteCfg.getGridName();
colTypes.put(ArrayList.class, GridPortableMarshaller.ARR_LIST);
colTypes.put(LinkedList.class, GridPortableMarshaller.LINKED_LIST);
@@ -240,15 +247,15 @@ public class PortableContext implements Externalizable {
// IDs range [200..1000] is used by Ignite internal APIs.
- registerPredefinedType(PortableObjectImpl.class, 200);
- registerPredefinedType(PortableMetaDataImpl.class, 201);
+ registerPredefinedType(BinaryObjectImpl.class, 200);
+ registerPredefinedType(BinaryMetaDataImpl.class, 201);
}
/**
* @param marsh Portable marshaller.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
- public void configure(PortableMarshaller marsh) throws PortableException {
+ public void configure(PortableMarshaller marsh) throws BinaryObjectException {
if (marsh == null)
return;
@@ -279,20 +286,20 @@ public class PortableContext implements Externalizable {
* @param globalKeepDeserialized Keep deserialized flag.
* @param clsNames Class names.
* @param typeCfgs Type configurations.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
private void configure(
- PortableIdMapper globalIdMapper,
- PortableSerializer globalSerializer,
+ BinaryTypeIdMapper globalIdMapper,
+ BinarySerializer globalSerializer,
boolean globalMetaDataEnabled,
boolean globalKeepDeserialized,
Collection<String> clsNames,
- Collection<PortableTypeConfiguration> typeCfgs
- ) throws PortableException {
+ Collection<BinaryTypeConfiguration> typeCfgs
+ ) throws BinaryObjectException {
TypeDescriptors descs = new TypeDescriptors();
if (clsNames != null) {
- PortableIdMapper idMapper = new IdMapperWrapper(globalIdMapper);
+ BinaryTypeIdMapper idMapper = new IdMapperWrapper(globalIdMapper);
for (String clsName : clsNames) {
if (clsName.endsWith(".*")) { // Package wildcard
@@ -308,21 +315,28 @@ public class PortableContext implements Externalizable {
}
}
+ Map<String, String> affFields = new HashMap<>();
+
+ if (!F.isEmpty(igniteCfg.getCacheKeyConfiguration())) {
+ for (CacheKeyConfiguration keyCfg : igniteCfg.getCacheKeyConfiguration())
+ affFields.put(keyCfg.getTypeName(), keyCfg.getAffinityKeyFieldName());
+ }
+
if (typeCfgs != null) {
- for (PortableTypeConfiguration typeCfg : typeCfgs) {
+ for (BinaryTypeConfiguration typeCfg : typeCfgs) {
String clsName = typeCfg.getClassName();
if (clsName == null)
- throw new PortableException("Class name is required for portable type configuration.");
+ throw new BinaryObjectException("Class name is required for portable type configuration.");
- PortableIdMapper idMapper = globalIdMapper;
+ BinaryTypeIdMapper idMapper = globalIdMapper;
if (typeCfg.getIdMapper() != null)
idMapper = typeCfg.getIdMapper();
idMapper = new IdMapperWrapper(idMapper);
- PortableSerializer serializer = globalSerializer;
+ BinarySerializer serializer = globalSerializer;
if (typeCfg.getSerializer() != null)
serializer = typeCfg.getSerializer();
@@ -336,11 +350,11 @@ public class PortableContext implements Externalizable {
String pkgName = clsName.substring(0, clsName.length() - 2);
for (String clsName0 : classesInPackage(pkgName))
- descs.add(clsName0, idMapper, serializer, typeCfg.getAffinityKeyFieldName(),
+ descs.add(clsName0, idMapper, serializer, affFields.get(clsName0),
metaDataEnabled, keepDeserialized, true);
}
else
- descs.add(clsName, idMapper, serializer, typeCfg.getAffinityKeyFieldName(),
+ descs.add(clsName, idMapper, serializer, affFields.get(clsName),
metaDataEnabled, keepDeserialized, false);
}
}
@@ -422,10 +436,10 @@ public class PortableContext implements Externalizable {
/**
* @param cls Class.
* @return Class descriptor.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
public PortableClassDescriptor descriptorForClass(Class<?> cls)
- throws PortableException {
+ throws BinaryObjectException {
assert cls != null;
PortableClassDescriptor desc = descByCls.get(cls);
@@ -475,14 +489,14 @@ public class PortableContext implements Externalizable {
if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr)) != null)
return desc;
- throw new PortableInvalidClassException(e);
+ throw new BinaryInvalidTypeException(e);
}
catch (IgniteCheckedException e) {
// Class might have been loaded by default class loader.
if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr)) != null)
return desc;
- throw new PortableException("Failed resolve class for ID: " + typeId, e);
+ throw new BinaryObjectException("Failed resolve class for ID: " + typeId, e);
}
if (desc == null) {
@@ -541,7 +555,7 @@ public class PortableContext implements Externalizable {
String typeName = typeName(cls.getName());
- PortableIdMapper idMapper = userTypeIdMapper(typeName);
+ BinaryTypeIdMapper idMapper = userTypeIdMapper(typeName);
int typeId = idMapper.typeId(typeName);
@@ -549,7 +563,7 @@ public class PortableContext implements Externalizable {
registered = marshCtx.registerClass(typeId, cls);
}
catch (IgniteCheckedException e) {
- throw new PortableException("Failed to register class.", e);
+ throw new BinaryObjectException("Failed to register class.", e);
}
PortableClassDescriptor desc = new PortableClassDescriptor(this,
@@ -639,8 +653,8 @@ public class PortableContext implements Externalizable {
* @param typeId Type ID.
* @return Instance of ID mapper.
*/
- public PortableIdMapper userTypeIdMapper(int typeId) {
- PortableIdMapper idMapper = mappers.get(typeId);
+ public BinaryTypeIdMapper userTypeIdMapper(int typeId) {
+ BinaryTypeIdMapper idMapper = mappers.get(typeId);
if (idMapper != null)
return idMapper;
@@ -655,15 +669,15 @@ public class PortableContext implements Externalizable {
* @param typeName Type name.
* @return Instance of ID mapper.
*/
- private PortableIdMapper userTypeIdMapper(String typeName) {
- PortableIdMapper idMapper = typeMappers.get(typeName);
+ private BinaryTypeIdMapper userTypeIdMapper(String typeName) {
+ BinaryTypeIdMapper idMapper = typeMappers.get(typeName);
return idMapper != null ? idMapper : DFLT_ID_MAPPER;
}
/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
- U.writeString(out, gridName);
+ U.writeString(out, igniteCfg.getGridName());
}
/** {@inheritDoc} */
@@ -682,7 +696,7 @@ public class PortableContext implements Externalizable {
if (g == null)
throw new IllegalStateException("Failed to find grid for name: " + gridName);
- return ((CacheObjectPortableProcessorImpl)g.context().cacheObjects()).portableContext();
+ return ((CacheObjectBinaryProcessorImpl)g.context().cacheObjects()).portableContext();
}
catch (IllegalStateException e) {
throw U.withCause(new InvalidObjectException(e.getMessage()), e);
@@ -726,16 +740,16 @@ public class PortableContext implements Externalizable {
* @param affKeyFieldName Affinity key field name.
* @param metaDataEnabled Metadata enabled flag.
* @param keepDeserialized Keep deserialized flag.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
@SuppressWarnings("ErrorNotRethrown")
public void registerUserType(String clsName,
- PortableIdMapper idMapper,
- @Nullable PortableSerializer serializer,
+ BinaryTypeIdMapper idMapper,
+ @Nullable BinarySerializer serializer,
@Nullable String affKeyFieldName,
boolean metaDataEnabled,
boolean keepDeserialized)
- throws PortableException {
+ throws BinaryObjectException {
assert idMapper != null;
Class<?> cls = null;
@@ -751,10 +765,10 @@ public class PortableContext implements Externalizable {
//Workaround for IGNITE-1358
if (predefinedTypes.get(id) != null)
- throw new PortableException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
+ throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
if (mappers.put(id, idMapper) != null)
- throw new PortableException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
+ throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
String typeName = typeName(clsName);
@@ -787,15 +801,15 @@ public class PortableContext implements Externalizable {
descByCls.put(cls, desc);
}
- metaHnd.addMeta(id, new PortableMetaDataImpl(typeName, fieldsMeta, affKeyFieldName));
+ metaHnd.addMeta(id, new BinaryMetaDataImpl(typeName, fieldsMeta, affKeyFieldName));
}
/**
* @param typeId Type ID.
* @return Meta data.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
- @Nullable public PortableMetadata metaData(int typeId) throws PortableException {
+ @Nullable public BinaryType metaData(int typeId) throws BinaryObjectException {
return metaHnd != null ? metaHnd.metadata(typeId) : null;
}
@@ -834,18 +848,18 @@ public class PortableContext implements Externalizable {
* @param typeId Type ID.
* @param typeName Type name.
* @param fields Fields map.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
- public void updateMetaData(int typeId, String typeName, Map<String, String> fields) throws PortableException {
- updateMetaData(typeId, new PortableMetaDataImpl(typeName, fields, null));
+ public void updateMetaData(int typeId, String typeName, Map<String, String> fields) throws BinaryObjectException {
+ updateMetaData(typeId, new BinaryMetaDataImpl(typeName, fields, null));
}
/**
* @param typeId Type ID.
* @param meta Meta data.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
- public void updateMetaData(int typeId, PortableMetaDataImpl meta) throws PortableException {
+ public void updateMetaData(int typeId, BinaryMetaDataImpl meta) throws BinaryObjectException {
metaHnd.addMeta(typeId, meta);
}
@@ -983,14 +997,14 @@ public class PortableContext implements Externalizable {
/**
*/
- private static class IdMapperWrapper implements PortableIdMapper {
+ private static class IdMapperWrapper implements BinaryTypeIdMapper {
/** */
- private final PortableIdMapper mapper;
+ private final BinaryTypeIdMapper mapper;
/**
* @param mapper Custom ID mapper.
*/
- private IdMapperWrapper(@Nullable PortableIdMapper mapper) {
+ private IdMapperWrapper(@Nullable BinaryTypeIdMapper mapper) {
this.mapper = mapper;
}
@@ -1018,7 +1032,7 @@ public class PortableContext implements Externalizable {
/**
* Basic class ID mapper.
*/
- private static class BasicClassIdMapper implements PortableIdMapper {
+ private static class BasicClassIdMapper implements BinaryTypeIdMapper {
/** {@inheritDoc} */
@Override public int typeId(String clsName) {
return clsName.hashCode();
@@ -1047,16 +1061,16 @@ public class PortableContext implements Externalizable {
* @param metadataEnabled Metadata enabled flag.
* @param keepDeserialized Keep deserialized flag.
* @param canOverride Whether this descriptor can be override.
- * @throws PortableException If failed.
+ * @throws org.apache.ignite.binary.BinaryObjectException If failed.
*/
private void add(String clsName,
- PortableIdMapper idMapper,
- PortableSerializer serializer,
+ BinaryTypeIdMapper idMapper,
+ BinarySerializer serializer,
String affKeyFieldName,
boolean metadataEnabled,
boolean keepDeserialized,
boolean canOverride)
- throws PortableException {
+ throws BinaryObjectException {
TypeDescriptor desc = new TypeDescriptor(clsName,
idMapper,
serializer,
@@ -1091,10 +1105,10 @@ public class PortableContext implements Externalizable {
private final String clsName;
/** ID mapper. */
- private PortableIdMapper idMapper;
+ private BinaryTypeIdMapper idMapper;
/** Serializer. */
- private PortableSerializer serializer;
+ private BinarySerializer serializer;
/** Affinity key field name. */
private String affKeyFieldName;
@@ -1119,7 +1133,7 @@ public class PortableContext implements Externalizable {
* @param keepDeserialized Keep deserialized flag.
* @param canOverride Whether this descriptor can be override.
*/
- private TypeDescriptor(String clsName, PortableIdMapper idMapper, PortableSerializer serializer,
+ private TypeDescriptor(String clsName, BinaryTypeIdMapper idMapper, BinarySerializer serializer,
String affKeyFieldName, boolean metadataEnabled, boolean keepDeserialized,
boolean canOverride) {
this.clsName = clsName;
@@ -1135,9 +1149,9 @@ public class PortableContext implements Externalizable {
* Override portable class descriptor.
*
* @param other Other descriptor.
- * @throws PortableException If failed.
+ * @throws org.apache.ignite.binary.BinaryObjectException If failed.
*/
- private void override(TypeDescriptor other) throws PortableException {
+ private void override(TypeDescriptor other) throws BinaryObjectException {
assert clsName.equals(other.clsName);
if (canOverride) {
@@ -1149,7 +1163,7 @@ public class PortableContext implements Externalizable {
canOverride = other.canOverride;
}
else if (!other.canOverride)
- throw new PortableException("Duplicate explicit class definition in configuration: " + clsName);
+ throw new BinaryObjectException("Duplicate explicit class definition in configuration: " + clsName);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableFieldImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableFieldImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableFieldImpl.java
deleted file mode 100644
index 80b0a6d..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableFieldImpl.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.portable.PortableField;
-import org.apache.ignite.portable.PortableObject;
-
-/**
- * Implementation of portable field descriptor.
- */
-public class PortableFieldImpl implements PortableField {
- /** Well-known object schemas. */
- @GridToStringExclude
- private final PortableSchemaRegistry schemas;
-
- /** Field name. */
- private final String fieldName;
-
- /** Pre-calculated field ID. */
- private final int fieldId;
-
- /**
- * Constructor.
- *
- * @param schemas Schemas.
- * @param fieldName Field name.
- * @param fieldId Field ID.
- */
- public PortableFieldImpl(PortableSchemaRegistry schemas, String fieldName, int fieldId) {
- assert schemas != null;
- assert fieldName != null;
- assert fieldId != 0;
-
- this.schemas = schemas;
- this.fieldName = fieldName;
- this.fieldId = fieldId;
- }
-
- /** {@inheritDoc} */
- @Override public String name() {
- return fieldName;
- }
-
- /** {@inheritDoc} */
- @Override public boolean exists(PortableObject obj) {
- PortableObjectEx obj0 = (PortableObjectEx)obj;
-
- return fieldOrder(obj0) != PortableSchema.ORDER_NOT_FOUND;
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override public <T> T value(PortableObject obj) {
- PortableObjectEx obj0 = (PortableObjectEx)obj;
-
- int order = fieldOrder(obj0);
-
- return order != PortableSchema.ORDER_NOT_FOUND ? (T)obj0.fieldByOrder(order) : null;
- }
-
- /**
- * Get relative field offset.
- *
- * @param obj Object.
- * @return Field offset.
- */
- private int fieldOrder(PortableObjectEx obj) {
- int schemaId = obj.schemaId();
-
- PortableSchema schema = schemas.schema(schemaId);
-
- if (schema == null) {
- schema = obj.createSchema();
-
- schemas.addSchema(schemaId, schema);
- }
-
- assert schema != null;
-
- return schema.order(fieldId);
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(PortableFieldImpl.class, this);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataCollector.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataCollector.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataCollector.java
deleted file mode 100644
index 9a88bfb..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataCollector.java
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * 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.portable;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableRawWriter;
-import org.apache.ignite.portable.PortableWriter;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Writer for meta data collection.
- */
-class PortableMetaDataCollector implements PortableWriter {
- /** */
- private final Map<String, String> meta = new HashMap<>();
-
- /** */
- private final String typeName;
-
- /**
- * @param typeName Type name.
- */
- PortableMetaDataCollector(String typeName) {
- this.typeName = typeName;
- }
-
- /**
- * @return Field meta data.
- */
- Map<String, String> meta() {
- return meta;
- }
-
- /** {@inheritDoc} */
- @Override public void writeByte(String fieldName, byte val) throws PortableException {
- add(fieldName, byte.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeShort(String fieldName, short val) throws PortableException {
- add(fieldName, short.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeInt(String fieldName, int val) throws PortableException {
- add(fieldName, int.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeLong(String fieldName, long val) throws PortableException {
- add(fieldName, long.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeFloat(String fieldName, float val) throws PortableException {
- add(fieldName, float.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDouble(String fieldName, double val) throws PortableException {
- add(fieldName, double.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeChar(String fieldName, char val) throws PortableException {
- add(fieldName, char.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeBoolean(String fieldName, boolean val) throws PortableException {
- add(fieldName, boolean.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws PortableException {
- add(fieldName, PortableClassDescriptor.Mode.DECIMAL.typeName());
- }
-
- /** {@inheritDoc} */
- @Override public void writeString(String fieldName, @Nullable String val) throws PortableException {
- add(fieldName, String.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeUuid(String fieldName, @Nullable UUID val) throws PortableException {
- add(fieldName, UUID.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDate(String fieldName, @Nullable Date val) throws PortableException {
- add(fieldName, Date.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws PortableException {
- add(fieldName, Timestamp.class);
- }
-
- /** {@inheritDoc} */
- @Override public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws PortableException {
- add(fieldName, Enum.class);
- }
-
- /** {@inheritDoc} */
- @Override public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws PortableException {
- add(fieldName, Enum[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeObject(String fieldName, @Nullable Object obj) throws PortableException {
- add(fieldName, Object.class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeByteArray(String fieldName, @Nullable byte[] val) throws PortableException {
- add(fieldName, byte[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeShortArray(String fieldName, @Nullable short[] val) throws PortableException {
- add(fieldName, short[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeIntArray(String fieldName, @Nullable int[] val) throws PortableException {
- add(fieldName, int[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeLongArray(String fieldName, @Nullable long[] val) throws PortableException {
- add(fieldName, long[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeFloatArray(String fieldName, @Nullable float[] val) throws PortableException {
- add(fieldName, float[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDoubleArray(String fieldName, @Nullable double[] val) throws PortableException {
- add(fieldName, double[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeCharArray(String fieldName, @Nullable char[] val) throws PortableException {
- add(fieldName, char[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeBooleanArray(String fieldName, @Nullable boolean[] val) throws PortableException {
- add(fieldName, boolean[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val) throws PortableException {
- add(fieldName, PortableClassDescriptor.Mode.DECIMAL_ARR.typeName());
- }
-
- /** {@inheritDoc} */
- @Override public void writeStringArray(String fieldName, @Nullable String[] val) throws PortableException {
- add(fieldName, String[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws PortableException {
- add(fieldName, UUID[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDateArray(String fieldName, @Nullable Date[] val) throws PortableException {
- add(fieldName, Date[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws PortableException {
- add(fieldName, Timestamp[].class);
- }
-
- /** {@inheritDoc} */
- @Override public void writeObjectArray(String fieldName, @Nullable Object[] val) throws PortableException {
- add(fieldName, Object[].class);
- }
-
- /** {@inheritDoc} */
- @Override public <T> void writeCollection(String fieldName, @Nullable Collection<T> col)
- throws PortableException {
- add(fieldName, Collection.class);
- }
-
- /** {@inheritDoc} */
- @Override public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map) throws PortableException {
- add(fieldName, Map.class);
- }
-
- /** {@inheritDoc} */
- @Override public PortableRawWriter rawWriter() {
- return (PortableRawWriter)Proxy.newProxyInstance(getClass().getClassLoader(),
- new Class<?>[] { PortableRawWriterEx.class },
- new InvocationHandler() {
- @Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable {
- return null;
- }
- });
- }
-
- /**
- * @param name Field name.
- * @param fieldType Field type.
- * @throws PortableException In case of error.
- */
- private void add(String name, Class<?> fieldType) throws PortableException {
- assert fieldType != null;
-
- add(name, fieldType.getSimpleName());
- }
-
- /**
- * @param name Field name.
- * @param fieldTypeName Field type name.
- * @throws PortableException In case of error.
- */
- private void add(String name, String fieldTypeName) throws PortableException {
- assert name != null;
-
- String oldFieldTypeName = meta.put(name, fieldTypeName);
-
- if (oldFieldTypeName != null && !oldFieldTypeName.equals(fieldTypeName)) {
- throw new PortableException(
- "Field is written twice with different types [" +
- "typeName=" + typeName +
- ", fieldName=" + name +
- ", fieldTypeName1=" + oldFieldTypeName +
- ", fieldTypeName2=" + fieldTypeName +
- ']'
- );
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataHandler.java
index e03d67f..8b2eef2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataHandler.java
@@ -17,8 +17,8 @@
package org.apache.ignite.internal.portable;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
/**
* Portable meta data handler.
@@ -29,16 +29,16 @@ public interface PortableMetaDataHandler {
*
* @param typeId Type ID.
* @param meta Meta data.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
- public void addMeta(int typeId, PortableMetadata meta) throws PortableException;
+ public void addMeta(int typeId, BinaryType meta) throws BinaryObjectException;
/**
* Gets meta data for provided type ID.
*
* @param typeId Type ID.
* @return Meta data.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
- public PortableMetadata metadata(int typeId) throws PortableException;
+ public BinaryType metadata(int typeId) throws BinaryObjectException;
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataImpl.java
deleted file mode 100644
index 1d26007..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataImpl.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * 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.portable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import org.apache.ignite.internal.util.tostring.GridToStringInclude;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableRawReader;
-import org.apache.ignite.portable.PortableRawWriter;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Portable meta data implementation.
- */
-public class PortableMetaDataImpl implements PortableMetadata, PortableMarshalAware, Externalizable {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** */
- private String typeName;
-
- /** */
- @GridToStringInclude
- private Map<String, String> fields;
-
- /** */
- private volatile Map<Integer, String> fldIdToName;
-
- /** */
- private String affKeyFieldName;
-
- /**
- * For {@link Externalizable}.
- */
- public PortableMetaDataImpl() {
- // No-op.
- }
-
- /**
- * @param typeName Type name.
- * @param fields Fields map.
- * @param affKeyFieldName Affinity key field name.
- */
- public PortableMetaDataImpl(String typeName, @Nullable Map<String, String> fields,
- @Nullable String affKeyFieldName) {
- assert typeName != null;
-
- this.typeName = typeName;
- this.fields = fields;
- this.affKeyFieldName = affKeyFieldName;
- }
-
- /** {@inheritDoc} */
- @Override public String typeName() {
- return typeName;
- }
-
- /** {@inheritDoc} */
- @Override public Collection<String> fields() {
- return fields != null ? fields.keySet() : Collections.<String>emptyList();
- }
-
- /**
- * @return Fields.
- */
- public Map<String, String> fields0() {
- return fields != null ? fields : Collections.<String, String>emptyMap();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public String fieldTypeName(String fieldName) {
- return fields != null ? fields.get(fieldName) : null;
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public String affinityKeyFieldName() {
- return affKeyFieldName;
- }
-
- /**
- * @return Fields meta data.
- */
- public Map<String, String> fieldsMeta() {
- return fields != null ? fields : Collections.<String, String>emptyMap();
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- U.writeString(out, typeName);
- U.writeMap(out, fields);
- U.writeString(out, affKeyFieldName);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- typeName = U.readString(in);
- fields = U.readMap(in);
- affKeyFieldName = U.readString(in);
- }
-
- /** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
- PortableRawWriter raw = writer.rawWriter();
-
- raw.writeString(typeName);
- raw.writeString(affKeyFieldName);
- raw.writeMap(fields);
- }
-
- /** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
- PortableRawReader raw = reader.rawReader();
-
- typeName = raw.readString();
- affKeyFieldName = raw.readString();
- fields = raw.readMap();
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(PortableMetaDataImpl.class, this);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
deleted file mode 100644
index d6d7f50..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * 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.portable;
-
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.IdentityHashMap;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
-import org.apache.ignite.internal.util.typedef.internal.SB;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Internal portable object interface.
- */
-public abstract class PortableObjectEx implements PortableObject {
- /**
- * @return Length.
- */
- public abstract int length();
-
- /**
- * @return Object start.
- */
- public abstract int start();
-
- /**
- * @return {@code True} if object is array based.
- */
- protected abstract boolean hasArray();
-
- /**
- * @return Object array if object is array based, otherwise {@code null}.
- */
- public abstract byte[] array();
-
- /**
- * @return Object offheap address is object is offheap based, otherwise 0.
- */
- public abstract long offheapAddress();
-
- /**
- * Gets field value.
- *
- * @param fieldId Field ID.
- * @return Field value.
- * @throws PortableException In case of any other error.
- */
- @Nullable public abstract <F> F field(int fieldId) throws PortableException;
-
- /**
- * Get field by offset.
- *
- * @param fieldOffset Field offset.
- * @return Field value.
- */
- @Nullable protected abstract <F> F fieldByOrder(int fieldOffset);
-
- /**
- * @param ctx Reader context.
- * @param fieldName Field name.
- * @return Field value.
- */
- @Nullable protected abstract <F> F field(PortableReaderContext ctx, String fieldName);
-
- /**
- * Get schema ID.
- *
- * @return Schema ID.
- */
- protected abstract int schemaId();
-
- /**
- * Create schema for object.
- *
- * @return Schema.
- */
- protected abstract PortableSchema createSchema();
-
- /** {@inheritDoc} */
- @Override public PortableObject clone() throws CloneNotSupportedException {
- return (PortableObject)super.clone();
- }
-
- /** {@inheritDoc} */
- public boolean equals(Object other) {
- if (other == this)
- return true;
-
- if (other == null)
- return false;
-
- if (!(other instanceof PortableObjectEx))
- return false;
-
- PortableObjectEx otherPo = (PortableObjectEx)other;
-
- if (length() != otherPo.length() || typeId() != otherPo.typeId())
- return false;
-
- if (hasArray()) {
- if (otherPo.hasArray()) {
- int len = length();
- int end = start() + len;
-
- byte[] arr = array();
- byte[] otherArr = otherPo.array();
-
- for (int i = start(), j = otherPo.start(); i < end; i++, j++) {
- if (arr[i] != otherArr[j])
- return false;
- }
-
- return true;
- }
- else {
- assert otherPo.offheapAddress() > 0;
-
- return GridUnsafeMemory.compare(otherPo.offheapAddress() + otherPo.start(), array());
- }
- }
- else {
- assert offheapAddress() > 0;
-
- if (otherPo.hasArray())
- return GridUnsafeMemory.compare(offheapAddress() + start(), otherPo.array());
- else {
- assert otherPo.offheapAddress() > 0;
-
- return GridUnsafeMemory.compare(offheapAddress() + start(),
- otherPo.offheapAddress() + otherPo.start(),
- length());
- }
- }
- }
-
- /**
- * @param ctx Reader context.
- * @param handles Handles for already traversed objects.
- * @return String representation.
- */
- private String toString(PortableReaderContext ctx, IdentityHashMap<PortableObject, Integer> handles) {
- int idHash = System.identityHashCode(this);
-
- PortableMetadata meta;
-
- try {
- meta = metaData();
- }
- catch (PortableException ignore) {
- meta = null;
- }
-
- if (meta == null)
- return "PortableObject [hash=" + idHash + ", typeId=" + typeId() + ']';
-
- handles.put(this, idHash);
-
- SB buf = new SB(meta.typeName());
-
- if (meta.fields() != null) {
- buf.a(" [hash=").a(idHash);
-
- for (String name : meta.fields()) {
- Object val = field(ctx, name);
-
- buf.a(", ").a(name).a('=');
-
- if (val instanceof byte[])
- buf.a(Arrays.toString((byte[]) val));
- else if (val instanceof short[])
- buf.a(Arrays.toString((short[])val));
- else if (val instanceof int[])
- buf.a(Arrays.toString((int[])val));
- else if (val instanceof long[])
- buf.a(Arrays.toString((long[])val));
- else if (val instanceof float[])
- buf.a(Arrays.toString((float[])val));
- else if (val instanceof double[])
- buf.a(Arrays.toString((double[])val));
- else if (val instanceof char[])
- buf.a(Arrays.toString((char[])val));
- else if (val instanceof boolean[])
- buf.a(Arrays.toString((boolean[]) val));
- else if (val instanceof BigDecimal[])
- buf.a(Arrays.toString((BigDecimal[])val));
- else {
- if (val instanceof PortableObjectEx) {
- PortableObjectEx po = (PortableObjectEx)val;
-
- Integer idHash0 = handles.get(val);
-
- if (idHash0 != null) { // Circular reference.
- PortableMetadata meta0 = po.metaData();
-
- assert meta0 != null;
-
- buf.a(meta0.typeName()).a(" [hash=").a(idHash0).a(", ...]");
- }
- else
- buf.a(po.toString(ctx, handles));
- }
- else
- buf.a(val);
- }
- }
-
- buf.a(']');
- }
-
- return buf.toString();
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- try {
- PortableReaderContext ctx = new PortableReaderContext();
-
- ctx.setPortableHandler(start(), this);
-
- return toString(ctx, new IdentityHashMap<PortableObject, Integer>());
- }
- catch (PortableException e) {
- throw new IgniteException("Failed to create string representation of portable object.", e);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
deleted file mode 100644
index 1d1be2b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
+++ /dev/null
@@ -1,586 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.GridDirectTransient;
-import org.apache.ignite.internal.IgniteCodeGeneratingFail;
-import org.apache.ignite.internal.portable.streams.PortableHeapInputStream;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
-import org.apache.ignite.internal.util.typedef.internal.A;
-import org.apache.ignite.internal.util.typedef.internal.U;
-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.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableField;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.jetbrains.annotations.Nullable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.sql.Timestamp;
-import java.util.Date;
-import java.util.UUID;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
-
-/**
- * Portable object implementation.
- */
-@IgniteCodeGeneratingFail // Fields arr and start should not be generated by MessageCodeGenerator.
-public final class PortableObjectImpl extends PortableObjectEx implements Externalizable,
- Message, CacheObject, KeyCacheObject {
- /** */
- public static final byte TYPE_PORTABLE = 100;
-
- /** */
- private static final long serialVersionUID = 0L;
-
- /** */
- @GridDirectTransient
- private PortableContext ctx;
-
- /** */
- private byte[] arr;
-
- /** */
- private int start;
-
- /** */
- @GridDirectTransient
- private Object obj;
-
- /** */
- @GridDirectTransient
- private boolean detachAllowed;
-
- /**
- * For {@link Externalizable}.
- */
- public PortableObjectImpl() {
- // No-op.
- }
-
- /**
- * @param ctx Context.
- * @param arr Array.
- * @param start Start.
- */
- public PortableObjectImpl(PortableContext ctx, byte[] arr, int start) {
- assert ctx != null;
- assert arr != null;
-
- this.ctx = ctx;
- this.arr = arr;
- this.start = start;
- }
-
- /** {@inheritDoc} */
- @Override public byte type() {
- return TYPE_PORTABLE;
- }
-
- /** {@inheritDoc} */
- @Override public boolean internal() {
- return false;
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
- return (T)this;
- }
-
- /** {@inheritDoc} */
- @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
- if (detached())
- return array();
-
- int len = length();
-
- byte[] arr0 = new byte[len];
-
- U.arrayCopy(arr, start, arr0, 0, len);
-
- return arr0;
- }
-
- /** {@inheritDoc} */
- @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
- if (detached())
- return this;
-
- return (PortableObjectImpl)detach();
- }
-
- /** {@inheritDoc} */
- @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
- this.ctx = ((CacheObjectPortableProcessorImpl)ctx.processor()).portableContext();
- }
-
- /** {@inheritDoc} */
- @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public int length() {
- return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TOTAL_LEN_POS);
- }
-
- /**
- * @return Detached portable object.
- */
- public PortableObject detach() {
- if (!detachAllowed || detached())
- return this;
-
- int len = length();
-
- byte[] arr0 = new byte[len];
-
- U.arrayCopy(arr, start, arr0, 0, len);
-
- return new PortableObjectImpl(ctx, arr0, 0);
- }
-
- /**
- * @return Detached or not.
- */
- public boolean detached() {
- return start == 0 && length() == arr.length;
- }
-
- /**
- * @param detachAllowed Detach allowed flag.
- */
- public void detachAllowed(boolean detachAllowed) {
- this.detachAllowed = detachAllowed;
- }
-
- /**
- * @return Context.
- */
- public PortableContext context() {
- return ctx;
- }
-
- /**
- * @param ctx Context.
- */
- public void context(PortableContext ctx) {
- this.ctx = ctx;
- }
-
- /** {@inheritDoc} */
- @Override public byte[] array() {
- return arr;
- }
-
- /** {@inheritDoc} */
- @Override public int start() {
- return start;
- }
-
- /** {@inheritDoc} */
- @Override public long offheapAddress() {
- return 0;
- }
-
- /** {@inheritDoc} */
- @Override protected boolean hasArray() {
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public int typeId() {
- return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TYPE_ID_POS);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public PortableMetadata metaData() throws PortableException {
- if (ctx == null)
- throw new PortableException("PortableContext is not set for the object.");
-
- return ctx.metaData(typeId());
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override public <F> F field(String fieldName) throws PortableException {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx, arr, start, null);
-
- return (F)reader.unmarshalField(fieldName);
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override public <F> F field(int fieldId) throws PortableException {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx, arr, start, null);
-
- return (F)reader.unmarshalField(fieldId);
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override protected <F> F fieldByOrder(int order) {
- Object val;
-
- // Calculate field position.
- int schemaOffset = PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-
- short flags = PortablePrimitives.readShort(arr, start + GridPortableMarshaller.FLAGS_POS);
- int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
-
- int fieldOffsetPos = start + schemaOffset + order * (4 + fieldOffsetSize) + 4;
-
- int fieldPos;
-
- if (fieldOffsetSize == PortableUtils.OFFSET_1)
- fieldPos = start + ((int)PortablePrimitives.readByte(arr, fieldOffsetPos) & 0xFF);
- else if (fieldOffsetSize == PortableUtils.OFFSET_2)
- fieldPos = start + ((int)PortablePrimitives.readShort(arr, fieldOffsetPos) & 0xFFFF);
- else
- fieldPos = start + PortablePrimitives.readInt(arr, fieldOffsetPos);
-
- // Read header and try performing fast lookup for well-known types (the most common types go first).
- byte hdr = PortablePrimitives.readByte(arr, fieldPos);
-
- switch (hdr) {
- case INT:
- val = PortablePrimitives.readInt(arr, fieldPos + 1);
-
- break;
-
- case LONG:
- val = PortablePrimitives.readLong(arr, fieldPos + 1);
-
- break;
-
- case BOOLEAN:
- val = PortablePrimitives.readBoolean(arr, fieldPos + 1);
-
- break;
-
- case SHORT:
- val = PortablePrimitives.readShort(arr, fieldPos + 1);
-
- break;
-
- case BYTE:
- val = PortablePrimitives.readByte(arr, fieldPos + 1);
-
- break;
-
- case CHAR:
- val = PortablePrimitives.readChar(arr, fieldPos + 1);
-
- break;
-
- case FLOAT:
- val = PortablePrimitives.readFloat(arr, fieldPos + 1);
-
- break;
-
- case DOUBLE:
- val = PortablePrimitives.readDouble(arr, fieldPos + 1);
-
- break;
-
- case STRING: {
- boolean utf = PortablePrimitives.readBoolean(arr, fieldPos + 1);
-
- if (utf) {
- int dataLen = PortablePrimitives.readInt(arr, fieldPos + 2);
-
- val = new String(arr, fieldPos + 6, dataLen, UTF_8);
- }
- else {
- int dataLen = PortablePrimitives.readInt(arr, fieldPos + 2);
- char[] data = PortablePrimitives.readCharArray(arr, fieldPos + 6, dataLen);
-
- val = String.valueOf(data);
- }
-
- break;
- }
-
- case DATE: {
- long time = PortablePrimitives.readLong(arr, fieldPos + 1);
-
- val = new Date(time);
-
- break;
- }
-
- case TIMESTAMP: {
- long time = PortablePrimitives.readLong(arr, fieldPos + 1);
- int nanos = PortablePrimitives.readInt(arr, fieldPos + 1 + 8);
-
- Timestamp ts = new Timestamp(time);
-
- ts.setNanos(ts.getNanos() + nanos);
-
- val = ts;
-
- break;
- }
-
- case UUID: {
- long most = PortablePrimitives.readLong(arr, fieldPos + 1);
- long least = PortablePrimitives.readLong(arr, fieldPos + 1 + 8);
-
- val = new UUID(most, least);
-
- break;
- }
-
- case DECIMAL: {
- int scale = PortablePrimitives.readInt(arr, fieldPos + 1);
-
- int dataLen = PortablePrimitives.readInt(arr, fieldPos + 5);
- byte[] data = PortablePrimitives.readByteArray(arr, fieldPos + 9, dataLen);
-
- BigInteger intVal = new BigInteger(data);
-
- if (scale < 0) {
- scale &= 0x7FFFFFFF;
-
- intVal = intVal.negate();
- }
-
- val = new BigDecimal(intVal, scale);
-
- break;
- }
-
- case NULL:
- val = null;
-
- break;
-
- default: {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx, arr, start, null);
-
- val = reader.unmarshalFieldByAbsolutePosition(fieldPos);
- }
- }
-
- return (F)val;
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override protected <F> F field(PortableReaderContext rCtx, String fieldName) {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx,
- new PortableHeapInputStream(arr),
- start,
- null,
- rCtx);
-
- return (F)reader.unmarshalField(fieldName);
- }
-
- /** {@inheritDoc} */
- @Override public boolean hasField(String fieldName) {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx, arr, start, null);
-
- return reader.hasField(fieldName);
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override public <T> T deserialize() throws PortableException {
- Object obj0 = obj;
-
- if (obj0 == null) {
- // TODO: IGNITE-1272 - Deserialize with proper class loader.
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx, arr, start, null);
-
- obj0 = reader.deserialize();
-
- PortableClassDescriptor desc = reader.descriptor();
-
- assert desc != null;
-
- if (desc.keepDeserialized())
- obj = obj0;
- }
-
- return (T)obj0;
- }
-
- /** {@inheritDoc} */
- @Override public PortableObject clone() throws CloneNotSupportedException {
- return super.clone();
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.HASH_CODE_POS);
- }
-
- /** {@inheritDoc} */
- @Override protected int schemaId() {
- return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_ID_POS);
- }
-
- /** {@inheritDoc} */
- @Override protected PortableSchema createSchema() {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx, arr, start, null);
-
- return reader.createSchema();
- }
-
- /** {@inheritDoc} */
- @Override public PortableField fieldDescriptor(String fieldName) throws PortableException {
- A.notNull(fieldName, "fieldName");
-
- int typeId = typeId();
-
- PortableSchemaRegistry schemaReg = ctx.schemaRegistry(typeId);
-
- int fieldId = ctx.userTypeIdMapper(typeId).fieldId(typeId, fieldName);
-
- return new PortableFieldImpl(schemaReg, fieldName, fieldId);
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(ctx);
-
- if (detachAllowed) {
- int len = length();
-
- out.writeInt(len);
- out.write(arr, start, len);
- out.writeInt(0);
- }
- else {
- out.writeInt(arr.length);
- out.write(arr);
- out.writeInt(start);
- }
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- ctx = (PortableContext)in.readObject();
-
- arr = new byte[in.readInt()];
-
- in.readFully(arr);
-
- start = in.readInt();
- }
-
- /** {@inheritDoc} */
- @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
- writer.setBuffer(buf);
-
- if (!writer.isHeaderWritten()) {
- if (!writer.writeHeader(directType(), fieldsCount()))
- return false;
-
- writer.onHeaderWritten();
- }
-
- switch (writer.state()) {
- case 0:
- if (!writer.writeByteArray("arr",
- arr,
- detachAllowed ? start : 0,
- detachAllowed ? length() : arr.length))
- return false;
-
- writer.incrementState();
-
- case 1:
- if (!writer.writeInt("start", detachAllowed ? 0 : start))
- return false;
-
- writer.incrementState();
-
- }
-
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
- reader.setBuffer(buf);
-
- if (!reader.beforeMessageRead())
- return false;
-
- switch (reader.state()) {
- case 0:
- arr = reader.readByteArray("arr");
-
- if (!reader.isLastRead())
- return false;
-
- reader.incrementState();
-
- case 1:
- start = reader.readInt("start");
-
- if (!reader.isLastRead())
- return false;
-
- reader.incrementState();
-
- }
-
- return true;
- }
-
- /** {@inheritDoc} */
- @Override public byte directType() {
- return 113;
- }
-
- /** {@inheritDoc} */
- @Override public byte fieldsCount() {
- return 3;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
deleted file mode 100644
index 3027f76..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
+++ /dev/null
@@ -1,458 +0,0 @@
-/*
- * 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.portable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.sql.Timestamp;
-import java.util.Date;
-import java.util.UUID;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.streams.PortableOffheapInputStream;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.internal.A;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.plugin.extensions.communication.MessageReader;
-import org.apache.ignite.plugin.extensions.communication.MessageWriter;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableField;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.jetbrains.annotations.Nullable;
-import sun.misc.Unsafe;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
-
-/**
- * Portable object implementation over offheap memory
- */
-public class PortableObjectOffheapImpl extends PortableObjectEx implements Externalizable, CacheObject {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** */
- private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
- /** */
- private final PortableContext ctx;
-
- /** */
- private final long ptr;
-
- /** */
- private final int start;
-
- /** */
- private final int size;
-
- /**
- * For {@link Externalizable} (not supported).
- */
- public PortableObjectOffheapImpl() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @param ctx Context.
- * @param ptr Memory address.
- * @param start Object start.
- * @param size Memory size.
- */
- public PortableObjectOffheapImpl(PortableContext ctx, long ptr, int start, int size) {
- this.ctx = ctx;
- this.ptr = ptr;
- this.start = start;
- this.size = size;
- }
-
- /**
- * @return Heap-based copy.
- */
- public PortableObject heapCopy() {
- return new PortableObjectImpl(ctx, U.copyMemory(ptr, size), start);
- }
-
- /** {@inheritDoc} */
- @Override public int typeId() {
- return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TYPE_ID_POS);
- }
-
- /** {@inheritDoc} */
- @Override public int length() {
- return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TOTAL_LEN_POS);
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return UNSAFE.getInt(ptr + start + GridPortableMarshaller.HASH_CODE_POS);
- }
-
- /** {@inheritDoc} */
- @Override protected int schemaId() {
- return UNSAFE.getInt(ptr + start + GridPortableMarshaller.SCHEMA_ID_POS);
- }
-
- /** {@inheritDoc} */
- @Override protected PortableSchema createSchema() {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx,
- new PortableOffheapInputStream(ptr, size, false),
- start,
- null);
-
- return reader.createSchema();
- }
-
- /** {@inheritDoc} */
- @Override public PortableField fieldDescriptor(String fieldName) throws PortableException {
- A.notNull(fieldName, "fieldName");
-
- int typeId = typeId();
-
- PortableSchemaRegistry schemaReg = ctx.schemaRegistry(typeId);
-
- int fieldId = ctx.userTypeIdMapper(typeId).fieldId(typeId, fieldName);
-
- return new PortableFieldImpl(schemaReg, fieldName, fieldId);
- }
-
- /** {@inheritDoc} */
- @Override public int start() {
- return start;
- }
-
- /** {@inheritDoc} */
- @Override public byte[] array() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public long offheapAddress() {
- return ptr;
- }
-
- /** {@inheritDoc} */
- @Override protected boolean hasArray() {
- return false;
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public PortableMetadata metaData() throws PortableException {
- if (ctx == null)
- throw new PortableException("PortableContext is not set for the object.");
-
- return ctx.metaData(typeId());
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override public <F> F field(String fieldName) throws PortableException {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx,
- new PortableOffheapInputStream(ptr, size, false),
- start,
- null);
-
- return (F)reader.unmarshalField(fieldName);
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override public <F> F field(int fieldId) throws PortableException {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx,
- new PortableOffheapInputStream(ptr, size, false),
- start,
- null);
-
- return (F)reader.unmarshalField(fieldId);
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override protected <F> F fieldByOrder(int order) {
- Object val;
-
- // Calculate field position.
- int schemaOffset = PortablePrimitives.readInt(ptr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-
- short flags = PortablePrimitives.readShort(ptr, start + GridPortableMarshaller.FLAGS_POS);
- int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
-
- int fieldOffsetPos = start + schemaOffset + order * (4 + fieldOffsetSize) + 4;
-
- int fieldPos;
-
- if (fieldOffsetSize == PortableUtils.OFFSET_1)
- fieldPos = start + ((int)PortablePrimitives.readByte(ptr, fieldOffsetPos) & 0xFF);
- else if (fieldOffsetSize == PortableUtils.OFFSET_2)
- fieldPos = start + ((int)PortablePrimitives.readShort(ptr, fieldOffsetPos) & 0xFFFF);
- else
- fieldPos = start + PortablePrimitives.readInt(ptr, fieldOffsetPos);
-
- // Read header and try performing fast lookup for well-known types (the most common types go first).
- byte hdr = PortablePrimitives.readByte(ptr, fieldPos);
-
- switch (hdr) {
- case INT:
- val = PortablePrimitives.readInt(ptr, fieldPos + 1);
-
- break;
-
- case LONG:
- val = PortablePrimitives.readLong(ptr, fieldPos + 1);
-
- break;
-
- case BOOLEAN:
- val = PortablePrimitives.readBoolean(ptr, fieldPos + 1);
-
- break;
-
- case SHORT:
- val = PortablePrimitives.readShort(ptr, fieldPos + 1);
-
- break;
-
- case BYTE:
- val = PortablePrimitives.readByte(ptr, fieldPos + 1);
-
- break;
-
- case CHAR:
- val = PortablePrimitives.readChar(ptr, fieldPos + 1);
-
- break;
-
- case FLOAT:
- val = PortablePrimitives.readFloat(ptr, fieldPos + 1);
-
- break;
-
- case DOUBLE:
- val = PortablePrimitives.readDouble(ptr, fieldPos + 1);
-
- break;
-
- case STRING: {
- boolean utf = PortablePrimitives.readBoolean(ptr, fieldPos + 1);
-
- if (utf) {
- int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 2);
- byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 6, dataLen);
-
- val = new String(data, UTF_8);
- }
- else {
- int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 2);
- char[] data = PortablePrimitives.readCharArray(ptr, fieldPos + 6, dataLen);
-
- val = String.valueOf(data);
- }
-
- break;
- }
-
- case DATE: {
- long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
-
- val = new Date(time);
-
- break;
- }
-
- case TIMESTAMP: {
- long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
- int nanos = PortablePrimitives.readInt(ptr, fieldPos + 1 + 8);
-
- Timestamp ts = new Timestamp(time);
-
- ts.setNanos(ts.getNanos() + nanos);
-
- val = ts;
-
- break;
- }
-
- case UUID: {
- long most = PortablePrimitives.readLong(ptr, fieldPos + 1);
- long least = PortablePrimitives.readLong(ptr, fieldPos + 1 + 8);
-
- val = new UUID(most, least);
-
- break;
- }
-
- case DECIMAL: {
- int scale = PortablePrimitives.readInt(ptr, fieldPos + 1);
-
- int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 5);
- byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 9, dataLen);
-
- BigInteger intVal = new BigInteger(data);
-
- if (scale < 0) {
- scale &= 0x7FFFFFFF;
-
- intVal = intVal.negate();
- }
-
- val = new BigDecimal(intVal, scale);
-
- break;
- }
-
- case NULL:
- val = null;
-
- break;
-
- default: {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx,
- new PortableOffheapInputStream(ptr, size, false),
- start,
- null);
-
- val = reader.unmarshalFieldByAbsolutePosition(fieldPos);
- }
- }
-
- return (F)val;
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override protected <F> F field(PortableReaderContext rCtx, String fieldName) {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx,
- new PortableOffheapInputStream(ptr, size, false),
- start,
- null,
- rCtx);
-
- return (F)reader.unmarshalField(fieldName);
- }
-
- /** {@inheritDoc} */
- @Override public boolean hasField(String fieldName) {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx,
- new PortableOffheapInputStream(ptr, size, false),
- start,
- null);
-
- return reader.hasField(fieldName);
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override public <T> T deserialize() throws PortableException {
- // TODO: IGNITE-1272 - Deserialize with proper class loader.
- PortableReaderExImpl reader = new PortableReaderExImpl(
- ctx,
- new PortableOffheapInputStream(ptr, size, false),
- start,
- null);
-
- return (T)reader.deserialize();
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("CloneDoesntCallSuperClone")
- @Override public PortableObject clone() throws CloneNotSupportedException {
- return heapCopy();
- }
-
- /** {@inheritDoc} */
- @Override public byte type() {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
- return (T)this;
- }
-
- /** {@inheritDoc} */
- @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @Override public byte directType() {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @Override public byte fieldsCount() {
- throw new UnsupportedOperationException();
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- throw new UnsupportedOperationException(); // To make sure it is not marshalled.
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- throw new UnsupportedOperationException(); // To make sure it is not marshalled.
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawReaderEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawReaderEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawReaderEx.java
deleted file mode 100644
index e703f2f..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawReaderEx.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableRawReader;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Extended reader interface.
- */
-public interface PortableRawReaderEx extends PortableRawReader {
- /**
- * @return Object.
- * @throws PortableException In case of error.
- */
- @Nullable public Object readObjectDetached() throws PortableException;
-}
\ No newline at end of file
[07/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderAdditionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderAdditionalSelfTest.java
new file mode 100644
index 0000000..039ae3d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderAdditionalSelfTest.java
@@ -0,0 +1,1289 @@
+/*
+ * 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.portable;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.portable.builder.PortableBuilderEnum;
+import org.apache.ignite.internal.portable.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.portable.mutabletest.GridBinaryMarshalerAwareTestClass;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.processors.cache.portable.IgniteBinaryImpl;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Assert;
+
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.Address;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.AddressBook;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.Company;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectAllTypes;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectArrayList;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectContainer;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectEnum;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectInner;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectOuter;
+
+/**
+ *
+ */
+public class GridBinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ CacheConfiguration cacheCfg = new CacheConfiguration();
+
+ cacheCfg.setCacheMode(REPLICATED);
+
+ cfg.setCacheConfiguration(cacheCfg);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList("org.apache.ignite.internal.portable.mutabletest.*"));
+
+ marsh.setConvertStringToBytes(useUtf8());
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGrids(1);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ jcache(0).clear();
+ }
+
+ /**
+ * @return Whether to use UTF8 strings.
+ */
+ protected boolean useUtf8() {
+ return true;
+ }
+
+ /**
+ * @return Portables API.
+ */
+ protected IgniteBinary portables() {
+ return grid(0).binary();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testSimpleTypeFieldRead() throws Exception {
+ TestObjectAllTypes exp = new TestObjectAllTypes();
+
+ exp.setDefaultData();
+
+ BinaryObjectBuilder mutPo = wrap(exp);
+
+ for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
+ Object expVal = field.get(exp);
+ Object actVal = mutPo.getField(field.getName());
+
+ switch (field.getName()) {
+ case "anEnum":
+ assertEquals(((PortableBuilderEnum)actVal).getOrdinal(), ((Enum)expVal).ordinal());
+ break;
+
+ case "enumArr": {
+ PortableBuilderEnum[] actArr = (PortableBuilderEnum[])actVal;
+ Enum[] expArr = (Enum[])expVal;
+
+ assertEquals(expArr.length, actArr.length);
+
+ for (int i = 0; i < actArr.length; i++)
+ assertEquals(expArr[i].ordinal(), actArr[i].getOrdinal());
+
+ break;
+ }
+
+ case "entry":
+ assertEquals(((Map.Entry)expVal).getKey(), ((Map.Entry)actVal).getKey());
+ assertEquals(((Map.Entry)expVal).getValue(), ((Map.Entry)actVal).getValue());
+ break;
+
+ default:
+ assertTrue(field.getName(), Objects.deepEquals(expVal, actVal));
+ break;
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public void testSimpleTypeFieldSerialize() {
+ TestObjectAllTypes exp = new TestObjectAllTypes();
+
+ exp.setDefaultData();
+
+ BinaryObjectBuilderImpl mutPo = wrap(exp);
+
+ TestObjectAllTypes res = mutPo.build().deserialize();
+
+ GridTestUtils.deepEquals(exp, res);
+ }
+
+ /**
+ * @throws Exception If any error occurs.
+ */
+ public void testSimpleTypeFieldOverride() throws Exception {
+ TestObjectAllTypes exp = new TestObjectAllTypes();
+
+ exp.setDefaultData();
+
+ BinaryObjectBuilderImpl mutPo = wrap(new TestObjectAllTypes());
+
+ for (Field field : TestObjectAllTypes.class.getDeclaredFields())
+ mutPo.setField(field.getName(), field.get(exp));
+
+ TestObjectAllTypes res = mutPo.build().deserialize();
+
+ GridTestUtils.deepEquals(exp, res);
+ }
+
+ /**
+ * @throws Exception If any error occurs.
+ */
+ public void testSimpleTypeFieldSetNull() throws Exception {
+ TestObjectAllTypes exp = new TestObjectAllTypes();
+
+ exp.setDefaultData();
+
+ BinaryObjectBuilderImpl mutPo = wrap(exp);
+
+ for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
+ if (!field.getType().isPrimitive())
+ mutPo.setField(field.getName(), null);
+ }
+
+ TestObjectAllTypes res = mutPo.build().deserialize();
+
+ for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
+ if (!field.getType().isPrimitive())
+ assertNull(field.getName(), field.get(res));
+ }
+ }
+
+ /**
+ * @throws IgniteCheckedException If any error occurs.
+ */
+ public void testMakeCyclicDependency() throws IgniteCheckedException {
+ TestObjectOuter outer = new TestObjectOuter();
+ outer.inner = new TestObjectInner();
+
+ BinaryObjectBuilderImpl mutOuter = wrap(outer);
+
+ BinaryObjectBuilderImpl mutInner = mutOuter.getField("inner");
+
+ mutInner.setField("outer", mutOuter);
+ mutInner.setField("foo", mutInner);
+
+ TestObjectOuter res = mutOuter.build().deserialize();
+
+ assertEquals(res, res.inner.outer);
+ assertEquals(res.inner, res.inner.foo);
+ }
+
+ /**
+ *
+ */
+ public void testDateArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.dateArr = new Date[] {new Date(11111), new Date(11111), new Date(11111)};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ Date[] arr = mutObj.getField("dateArr");
+ arr[0] = new Date(22222);
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new Date[] {new Date(22222), new Date(11111), new Date(11111)}, res.dateArr);
+ }
+
+ /**
+ *
+ */
+ public void testTimestampArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.tsArr = new Timestamp[] {new Timestamp(111222333), new Timestamp(222333444)};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ Timestamp[] arr = mutObj.getField("tsArr");
+ arr[0] = new Timestamp(333444555);
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new Timestamp[] {new Timestamp(333444555), new Timestamp(222333444)}, res.tsArr);
+ }
+
+ /**
+ *
+ */
+ public void testUUIDArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.uuidArr = new UUID[] {new UUID(1, 1), new UUID(1, 1), new UUID(1, 1)};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ UUID[] arr = mutObj.getField("uuidArr");
+ arr[0] = new UUID(2, 2);
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new UUID[] {new UUID(2, 2), new UUID(1, 1), new UUID(1, 1)}, res.uuidArr);
+ }
+
+ /**
+ *
+ */
+ public void testDecimalArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.bdArr = new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ BigDecimal[] arr = mutObj.getField("bdArr");
+ arr[0] = new BigDecimal(2000);
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)},
+ res.bdArr);
+ }
+
+ /**
+ *
+ */
+ public void testBooleanArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.zArr = new boolean[] {false, false, false};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ boolean[] arr = mutObj.getField("zArr");
+ arr[0] = true;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ boolean[] expected = new boolean[] {true, false, false};
+
+ assertEquals(expected.length, res.zArr.length);
+
+ for (int i = 0; i < expected.length; i++)
+ assertEquals(expected[i], res.zArr[i]);
+ }
+
+ /**
+ *
+ */
+ public void testCharArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.cArr = new char[] {'a', 'a', 'a'};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ char[] arr = mutObj.getField("cArr");
+ arr[0] = 'b';
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new char[] {'b', 'a', 'a'}, res.cArr);
+ }
+
+ /**
+ *
+ */
+ public void testDoubleArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.dArr = new double[] {1.0, 1.0, 1.0};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ double[] arr = mutObj.getField("dArr");
+ arr[0] = 2.0;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new double[] {2.0, 1.0, 1.0}, res.dArr, 0);
+ }
+
+ /**
+ *
+ */
+ public void testFloatArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.fArr = new float[] {1.0f, 1.0f, 1.0f};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ float[] arr = mutObj.getField("fArr");
+ arr[0] = 2.0f;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new float[] {2.0f, 1.0f, 1.0f}, res.fArr, 0);
+ }
+
+ /**
+ *
+ */
+ public void testLongArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.lArr = new long[] {1, 1, 1};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ long[] arr = mutObj.getField("lArr");
+ arr[0] = 2;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new long[] {2, 1, 1}, res.lArr);
+ }
+
+ /**
+ *
+ */
+ public void testIntArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.iArr = new int[] {1, 1, 1};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ int[] arr = mutObj.getField("iArr");
+ arr[0] = 2;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new int[] {2, 1, 1}, res.iArr);
+ }
+
+ /**
+ *
+ */
+ public void testShortArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.sArr = new short[] {1, 1, 1};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ short[] arr = mutObj.getField("sArr");
+ arr[0] = 2;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new short[] {2, 1, 1}, res.sArr);
+ }
+
+ /**
+ *
+ */
+ public void testByteArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.bArr = new byte[] {1, 1, 1};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ byte[] arr = mutObj.getField("bArr");
+ arr[0] = 2;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new byte[] {2, 1, 1}, res.bArr);
+ }
+
+ /**
+ *
+ */
+ public void testStringArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.strArr = new String[] {"a", "a", "a"};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ String[] arr = mutObj.getField("strArr");
+ arr[0] = "b";
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new String[] {"b", "a", "a"}, res.strArr);
+ }
+
+ /**
+ *
+ */
+ public void testModifyObjectArray() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = new Object[] {"a"};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ Object[] arr = mutObj.getField("foo");
+
+ Assert.assertArrayEquals(new Object[] {"a"}, arr);
+
+ arr[0] = "b";
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new Object[] {"b"}, (Object[])res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testOverrideObjectArrayField() {
+ BinaryObjectBuilderImpl mutObj = wrap(new TestObjectContainer());
+
+ Object[] createdArr = {mutObj, "a", 1, new String[] {"s", "s"}, new byte[] {1, 2}, new UUID(3, 0)};
+
+ mutObj.setField("foo", createdArr.clone());
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ createdArr[0] = res;
+
+ assertTrue(Objects.deepEquals(createdArr, res.foo));
+ }
+
+ /**
+ *
+ */
+ public void testDeepArray() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = new Object[] {new Object[] {"a", obj}};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ Object[] arr = (Object[])mutObj.<Object[]>getField("foo")[0];
+
+ assertEquals("a", arr[0]);
+ assertSame(mutObj, arr[1]);
+
+ arr[0] = mutObj;
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ arr = (Object[])((Object[])res.foo)[0];
+
+ assertSame(arr[0], res);
+ assertSame(arr[0], arr[1]);
+ }
+
+ /**
+ *
+ */
+ public void testArrayListRead() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Lists.newArrayList(obj, "a");
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ List<Object> list = mutObj.getField("foo");
+
+ assert list.equals(Lists.newArrayList(mutObj, "a"));
+ }
+
+ /**
+ *
+ */
+ public void testArrayListOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ ArrayList<Object> list = Lists.newArrayList(mutObj, "a", Lists.newArrayList(1, 2));
+
+ mutObj.setField("foo", list);
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ list.set(0, res);
+
+ assertNotSame(list, res.foo);
+ assertEquals(list, res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testArrayListModification() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Lists.newArrayList("a", "b", "c");
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ List<String> list = mutObj.getField("foo");
+
+ list.add("!"); // "a", "b", "c", "!"
+ list.add(0, "_"); // "_", "a", "b", "c", "!"
+
+ String s = list.remove(1); // "_", "b", "c", "!"
+ assertEquals("a", s);
+
+ assertEquals(Arrays.asList("c", "!"), list.subList(2, 4));
+ assertEquals(1, list.indexOf("b"));
+ assertEquals(1, list.lastIndexOf("b"));
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ assertTrue(res.foo instanceof ArrayList);
+ assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testArrayListClear() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Lists.newArrayList("a", "b", "c");
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ List<String> list = mutObj.getField("foo");
+
+ list.clear();
+
+ assertEquals(Collections.emptyList(), mutObj.build().<TestObjectContainer>deserialize().foo);
+ }
+
+ /**
+ *
+ */
+ public void testArrayListWriteUnmodifiable() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ ArrayList<Object> src = Lists.newArrayList(obj, "a", "b", "c");
+
+ obj.foo = src;
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ TestObjectContainer deserialized = mutObj.build().deserialize();
+
+ List<Object> res = (List<Object>)deserialized.foo;
+
+ src.set(0, deserialized);
+
+ assertEquals(src, res);
+ }
+
+ /**
+ *
+ */
+ public void testLinkedListRead() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Lists.newLinkedList(Arrays.asList(obj, "a"));
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ List<Object> list = mutObj.getField("foo");
+
+ assert list.equals(Lists.newLinkedList(Arrays.asList(mutObj, "a")));
+ }
+
+ /**
+ *
+ */
+ public void testLinkedListOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ List<Object> list = Lists.newLinkedList(Arrays.asList(mutObj, "a", Lists.newLinkedList(Arrays.asList(1, 2))));
+
+ mutObj.setField("foo", list);
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ list.set(0, res);
+
+ assertNotSame(list, res.foo);
+ assertEquals(list, res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testLinkedListModification() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ obj.foo = Lists.newLinkedList(Arrays.asList("a", "b", "c"));
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ List<String> list = mutObj.getField("foo");
+
+ list.add("!"); // "a", "b", "c", "!"
+ list.add(0, "_"); // "_", "a", "b", "c", "!"
+
+ String s = list.remove(1); // "_", "b", "c", "!"
+ assertEquals("a", s);
+
+ assertEquals(Arrays.asList("c", "!"), list.subList(2, 4));
+ assertEquals(1, list.indexOf("b"));
+ assertEquals(1, list.lastIndexOf("b"));
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ assertTrue(res.foo instanceof LinkedList);
+ assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testLinkedListWriteUnmodifiable() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ LinkedList<Object> src = Lists.newLinkedList(Arrays.asList(obj, "a", "b", "c"));
+
+ obj.foo = src;
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ TestObjectContainer deserialized = mutObj.build().deserialize();
+
+ List<Object> res = (List<Object>)deserialized.foo;
+
+ src.set(0, deserialized);
+
+ assertEquals(src, res);
+ }
+
+ /**
+ *
+ */
+ public void testHashSetRead() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Sets.newHashSet(obj, "a");
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ Set<Object> set = mutObj.getField("foo");
+
+ assert set.equals(Sets.newHashSet(mutObj, "a"));
+ }
+
+ /**
+ *
+ */
+ public void testHashSetOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ Set<Object> c = Sets.newHashSet(mutObj, "a", Sets.newHashSet(1, 2));
+
+ mutObj.setField("foo", c);
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ c.remove(mutObj);
+ c.add(res);
+
+ assertNotSame(c, res.foo);
+ assertEquals(c, res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testHashSetModification() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Sets.newHashSet("a", "b", "c");
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ Set<String> set = mutObj.getField("foo");
+
+ set.remove("b");
+ set.add("!");
+
+ assertEquals(Sets.newHashSet("a", "!", "c"), set);
+ assertTrue(set.contains("a"));
+ assertTrue(set.contains("!"));
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ assertTrue(res.foo instanceof HashSet);
+ assertEquals(Sets.newHashSet("a", "!", "c"), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testHashSetWriteUnmodifiable() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ Set<Object> src = Sets.newHashSet(obj, "a", "b", "c");
+
+ obj.foo = src;
+
+ TestObjectContainer deserialized = wrap(obj).build().deserialize();
+
+ Set<Object> res = (Set<Object>)deserialized.foo;
+
+ src.remove(obj);
+ src.add(deserialized);
+
+ assertEquals(src, res);
+ }
+
+ /**
+ *
+ */
+ public void testMapRead() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Maps.newHashMap(ImmutableMap.of(obj, "a", "b", obj));
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ Map<Object, Object> map = mutObj.getField("foo");
+
+ assert map.equals(ImmutableMap.of(mutObj, "a", "b", mutObj));
+ }
+
+ /**
+ *
+ */
+ public void testMapOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ Map<Object, Object> map = Maps.newHashMap(ImmutableMap.of(mutObj, "a", "b", mutObj));
+
+ mutObj.setField("foo", map);
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ assertEquals(ImmutableMap.of(res, "a", "b", res), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testMapModification() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b"));
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ Map<Object, Object> map = mutObj.getField("foo");
+
+ map.put(3, mutObj);
+ Object rmv = map.remove(1);
+
+ assertEquals("a", rmv);
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ assertEquals(ImmutableMap.of(2, "b", 3, res), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testEnumArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.enumArr = new TestObjectEnum[] {TestObjectEnum.A, TestObjectEnum.B};
+
+ BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+ PortableBuilderEnum[] arr = mutObj.getField("enumArr");
+ arr[0] = new PortableBuilderEnum(mutObj.typeId(), TestObjectEnum.B);
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new TestObjectEnum[] {TestObjectEnum.A, TestObjectEnum.B}, res.enumArr);
+ }
+
+ /**
+ *
+ */
+ public void testEditObjectWithRawData() {
+ GridBinaryMarshalerAwareTestClass obj = new GridBinaryMarshalerAwareTestClass();
+
+ obj.s = "a";
+ obj.sRaw = "aa";
+
+ BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+ mutableObj.setField("s", "z");
+
+ GridBinaryMarshalerAwareTestClass res = mutableObj.build().deserialize();
+ assertEquals("z", res.s);
+ assertEquals("aa", res.sRaw);
+ }
+
+ /**
+ *
+ */
+ public void testHashCode() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+ assertEquals(obj.hashCode(), mutableObj.build().hashCode());
+
+ mutableObj.hashCode(25);
+
+ assertEquals(25, mutableObj.build().hashCode());
+ }
+
+ /**
+ *
+ */
+ public void testCollectionsInCollection() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Lists.newArrayList(
+ Lists.newArrayList(1, 2),
+ Lists.newLinkedList(Arrays.asList(1, 2)),
+ Sets.newHashSet("a", "b"),
+ Sets.newLinkedHashSet(Arrays.asList("a", "b")),
+ Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b")));
+
+ TestObjectContainer deserialized = wrap(obj).build().deserialize();
+
+ assertEquals(obj.foo, deserialized.foo);
+ }
+
+ /**
+ *
+ */
+ public void testMapEntryModification() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = ImmutableMap.of(1, "a").entrySet().iterator().next();
+
+ BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+ Map.Entry<Object, Object> entry = mutableObj.getField("foo");
+
+ assertEquals(1, entry.getKey());
+ assertEquals("a", entry.getValue());
+
+ entry.setValue("b");
+
+ TestObjectContainer res = mutableObj.build().deserialize();
+
+ assertEquals(new GridMapEntry<>(1, "b"), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testMapEntryOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+ mutableObj.setField("foo", new GridMapEntry<>(1, "a"));
+
+ TestObjectContainer res = mutableObj.build().deserialize();
+
+ assertEquals(new GridMapEntry<>(1, "a"), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testMetadataChangingDoublePut() {
+ BinaryObjectBuilderImpl mutableObj = wrap(new TestObjectContainer());
+
+ mutableObj.setField("xx567", "a");
+ mutableObj.setField("xx567", "b");
+
+ mutableObj.build();
+
+ BinaryType metadata = portables().metadata(TestObjectContainer.class);
+
+ assertEquals("String", metadata.fieldTypeName("xx567"));
+ }
+
+ /**
+ *
+ */
+ public void testMetadataChangingDoublePut2() {
+ BinaryObjectBuilderImpl mutableObj = wrap(new TestObjectContainer());
+
+ mutableObj.setField("xx567", "a");
+ mutableObj.setField("xx567", "b");
+
+ mutableObj.build();
+
+ BinaryType metadata = portables().metadata(TestObjectContainer.class);
+
+ assertEquals("String", metadata.fieldTypeName("xx567"));
+ }
+
+ /**
+ *
+ */
+ public void testMetadataChanging() {
+ TestObjectContainer c = new TestObjectContainer();
+
+ BinaryObjectBuilderImpl mutableObj = wrap(c);
+
+ mutableObj.setField("intField", 1);
+ mutableObj.setField("intArrField", new int[] {1});
+ mutableObj.setField("arrField", new String[] {"1"});
+ mutableObj.setField("strField", "1");
+ mutableObj.setField("colField", Lists.newArrayList("1"));
+ mutableObj.setField("mapField", Maps.newHashMap(ImmutableMap.of(1, "1")));
+ mutableObj.setField("enumField", TestObjectEnum.A);
+ mutableObj.setField("enumArrField", new Enum[] {TestObjectEnum.A});
+
+ mutableObj.build();
+
+ BinaryType metadata = portables().metadata(c.getClass());
+
+ assertTrue(metadata.fields().containsAll(Arrays.asList("intField", "intArrField", "arrField", "strField",
+ "colField", "mapField", "enumField", "enumArrField")));
+
+ assertEquals("int", metadata.fieldTypeName("intField"));
+ assertEquals("int[]", metadata.fieldTypeName("intArrField"));
+ assertEquals("String[]", metadata.fieldTypeName("arrField"));
+ assertEquals("String", metadata.fieldTypeName("strField"));
+ assertEquals("Collection", metadata.fieldTypeName("colField"));
+ assertEquals("Map", metadata.fieldTypeName("mapField"));
+ assertEquals("Enum", metadata.fieldTypeName("enumField"));
+ assertEquals("Enum[]", metadata.fieldTypeName("enumArrField"));
+ }
+
+ /**
+ *
+ */
+ public void testDateInObjectField() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ obj.foo = new Date();
+
+ BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+ assertEquals(Date.class, mutableObj.getField("foo").getClass());
+ }
+
+ /**
+ *
+ */
+ public void testTimestampInObjectField() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ obj.foo = new Timestamp(100020003);
+
+ BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+ assertEquals(Timestamp.class, mutableObj.getField("foo").getClass());
+ }
+
+ /**
+ *
+ */
+ public void testDateInCollection() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ obj.foo = Lists.newArrayList(new Date());
+
+ BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+ assertEquals(Date.class, ((List<?>)mutableObj.getField("foo")).get(0).getClass());
+ }
+
+ /**
+ *
+ */
+ public void testTimestampInCollection() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ obj.foo = Lists.newArrayList(new Timestamp(100020003));
+
+ BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+ assertEquals(Timestamp.class, ((List<?>)mutableObj.getField("foo")).get(0).getClass());
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
+ public void testDateArrayOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+ Date[] arr = { new Date() };
+
+ mutableObj.setField("foo", arr);
+
+ TestObjectContainer res = mutableObj.build().deserialize();
+
+ assertEquals(Date[].class, res.foo.getClass());
+ assertTrue(Objects.deepEquals(arr, res.foo));
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
+ public void testTimestampArrayOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+ Timestamp[] arr = { new Timestamp(100020003) };
+
+ mutableObj.setField("foo", arr);
+
+ TestObjectContainer res = mutableObj.build().deserialize();
+
+ assertEquals(Timestamp[].class, res.foo.getClass());
+ assertTrue(Objects.deepEquals(arr, res.foo));
+ }
+
+ /**
+ *
+ */
+ public void testChangeMap() {
+ AddressBook addrBook = new AddressBook();
+
+ addrBook.addCompany(new Company(1, "Google inc", 100, new Address("Saint-Petersburg", "Torzhkovskya", 1, 53), "occupation"));
+ addrBook.addCompany(new Company(2, "Apple inc", 100, new Address("Saint-Petersburg", "Torzhkovskya", 1, 54), "occupation"));
+ addrBook.addCompany(new Company(3, "Microsoft", 100, new Address("Saint-Petersburg", "Torzhkovskya", 1, 55), "occupation"));
+ addrBook.addCompany(new Company(4, "Oracle", 100, new Address("Saint-Petersburg", "Nevskiy", 1, 1), "occupation"));
+
+ BinaryObjectBuilderImpl mutableObj = wrap(addrBook);
+
+ Map<String, List<BinaryObjectBuilderImpl>> map = mutableObj.getField("companyByStreet");
+
+ List<BinaryObjectBuilderImpl> list = map.get("Torzhkovskya");
+
+ BinaryObjectBuilderImpl company = list.get(0);
+
+ assert "Google inc".equals(company.<String>getField("name"));
+
+ list.remove(0);
+
+ AddressBook res = mutableObj.build().deserialize();
+
+ assertEquals(Arrays.asList("Nevskiy", "Torzhkovskya"), new ArrayList<>(res.getCompanyByStreet().keySet()));
+
+ List<Company> torzhkovskyaCompanies = res.getCompanyByStreet().get("Torzhkovskya");
+
+ assertEquals(2, torzhkovskyaCompanies.size());
+ assertEquals("Apple inc", torzhkovskyaCompanies.get(0).name);
+ }
+
+ /**
+ *
+ */
+ public void testSavingObjectWithNotZeroStart() {
+ TestObjectOuter out = new TestObjectOuter();
+ TestObjectInner inner = new TestObjectInner();
+
+ out.inner = inner;
+ inner.outer = out;
+
+ BinaryObjectBuilderImpl builder = wrap(out);
+
+ BinaryObjectBuilderImpl innerBuilder = builder.getField("inner");
+
+ TestObjectInner res = innerBuilder.build().deserialize();
+
+ assertSame(res, res.outer.inner);
+ }
+
+ /**
+ *
+ */
+ public void testPortableObjectField() {
+ TestObjectContainer container = new TestObjectContainer(toPortable(new TestObjectArrayList()));
+
+ BinaryObjectBuilderImpl wrapper = wrap(container);
+
+ assertTrue(wrapper.getField("foo") instanceof BinaryObject);
+
+ TestObjectContainer deserialized = wrapper.build().deserialize();
+ assertTrue(deserialized.foo instanceof BinaryObject);
+ }
+
+ /**
+ *
+ */
+ public void testAssignPortableObject() {
+ TestObjectContainer container = new TestObjectContainer();
+
+ BinaryObjectBuilderImpl wrapper = wrap(container);
+
+ wrapper.setField("foo", toPortable(new TestObjectArrayList()));
+
+ TestObjectContainer deserialized = wrapper.build().deserialize();
+ assertTrue(deserialized.foo instanceof TestObjectArrayList);
+ }
+
+ /**
+ *
+ */
+ public void testRemoveFromNewObject() {
+ BinaryObjectBuilderImpl wrapper = newWrapper(TestObjectAllTypes.class);
+
+ wrapper.setField("str", "a");
+
+ wrapper.removeField("str");
+
+ assertNull(wrapper.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ *
+ */
+ public void testRemoveFromExistingObject() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+ obj.setDefaultData();
+
+ BinaryObjectBuilderImpl wrapper = wrap(toPortable(obj));
+
+ wrapper.removeField("str");
+
+ assertNull(wrapper.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ *
+ */
+ public void testCyclicArrays() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ Object[] arr1 = new Object[1];
+ Object[] arr2 = new Object[] {arr1};
+
+ arr1[0] = arr2;
+
+ obj.foo = arr1;
+
+ TestObjectContainer res = toPortable(obj).deserialize();
+
+ Object[] resArr = (Object[])res.foo;
+
+ assertSame(((Object[])resArr[0])[0], resArr);
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("TypeMayBeWeakened")
+ public void testCyclicArrayList() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ List<Object> arr1 = new ArrayList<>();
+ List<Object> arr2 = new ArrayList<>();
+
+ arr1.add(arr2);
+ arr2.add(arr1);
+
+ obj.foo = arr1;
+
+ TestObjectContainer res = toPortable(obj).deserialize();
+
+ List<?> resArr = (List<?>)res.foo;
+
+ assertSame(((List<Object>)resArr.get(0)).get(0), resArr);
+ }
+
+ /**
+ * @param obj Object.
+ * @return Object in portable format.
+ */
+ private BinaryObject toPortable(Object obj) {
+ return portables().toBinary(obj);
+ }
+
+ /**
+ * @param obj Object.
+ * @return GridMutablePortableObject.
+ */
+ private BinaryObjectBuilderImpl wrap(Object obj) {
+ return BinaryObjectBuilderImpl.wrap(toPortable(obj));
+ }
+
+ /**
+ * @param aCls Class.
+ * @return Wrapper.
+ */
+ private BinaryObjectBuilderImpl newWrapper(Class<?> aCls) {
+ CacheObjectBinaryProcessorImpl processor = (CacheObjectBinaryProcessorImpl)(
+ (IgniteBinaryImpl)portables()).processor();
+
+ return new BinaryObjectBuilderImpl(processor.portableContext(), processor.typeId(aCls.getName()),
+ aCls.getSimpleName());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderSelfTest.java
new file mode 100644
index 0000000..925a61c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderSelfTest.java
@@ -0,0 +1,1069 @@
+/*
+ * 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.portable;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.portable.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectAllTypes;
+import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectContainer;
+import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectInner;
+import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectOuter;
+import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectPlainPortable;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryTypeIdMapper;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import sun.misc.Unsafe;
+
+/**
+ * Portable builder test.
+ */
+public class GridBinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+ /** */
+ protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(Key.class.getName(), Value.class.getName(),
+ "org.gridgain.grid.internal.util.portable.mutabletest.*"));
+
+ BinaryTypeConfiguration customIdMapper = new BinaryTypeConfiguration();
+
+ customIdMapper.setClassName(CustomIdMapper.class.getName());
+ customIdMapper.setIdMapper(new BinaryTypeIdMapper() {
+ @Override public int typeId(String clsName) {
+ return ~PortableContext.DFLT_ID_MAPPER.typeId(clsName);
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return typeId + ~PortableContext.DFLT_ID_MAPPER.fieldId(typeId, fieldName);
+ }
+ });
+
+ marsh.setTypeConfigurations(Collections.singleton(customIdMapper));
+
+ marsh.setConvertStringToBytes(useUtf8());
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGrids(1);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @return Whether to use UTF8 strings.
+ */
+ protected boolean useUtf8() {
+ return true;
+ }
+
+ /**
+ *
+ */
+ public void testAllFieldsSerialization() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+ obj.setDefaultData();
+ obj.enumArr = null;
+
+ TestObjectAllTypes deserialized = builder(toPortable(obj)).build().deserialize();
+
+ GridTestUtils.deepEquals(obj, deserialized);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testByteField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("byteField", (byte)1);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals((byte) 1, po.<Byte>field("byteField").byteValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testShortField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("shortField", (short)1);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals((short)1, po.<Short>field("shortField").shortValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testIntField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("intField", 1);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1, po.<Integer>field("intField").intValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLongField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("longField", 1L);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1L, po.<Long>field("longField").longValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFloatField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("floatField", 1.0f);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1.0f, po.<Float>field("floatField").floatValue(), 0);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDoubleField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("doubleField", 1.0d);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1.0d, po.<Double>field("doubleField").doubleValue(), 0);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCharField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("charField", (char)1);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals((char)1, po.<Character>field("charField").charValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBooleanField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("booleanField", true);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(po.<Boolean>field("booleanField"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDecimalField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("decimalField", BigDecimal.TEN);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(BigDecimal.TEN, po.<String>field("decimalField"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testStringField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("stringField", "str");
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals("str", po.<String>field("stringField"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDateField() throws Exception {
+ Date date = new Date();
+
+ assertEquals(date, builder("C").setField("d", date).build().<Date>field("d"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTimestampField() throws Exception {
+ Timestamp ts = new Timestamp(new Date().getTime());
+ ts.setNanos(1000);
+
+ assertEquals(ts, builder("C").setField("t", ts).build().<Timestamp>field("t"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testUuidField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ UUID uuid = UUID.randomUUID();
+
+ builder.setField("uuidField", uuid);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(uuid, po.<UUID>field("uuidField"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testByteArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("byteArrayField", new byte[] {1, 2, 3});
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new byte[] {1, 2, 3}, po.<byte[]>field("byteArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testShortArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("shortArrayField", new short[] {1, 2, 3});
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new short[] {1, 2, 3}, po.<short[]>field("shortArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testIntArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("intArrayField", new int[] {1, 2, 3});
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new int[] {1, 2, 3}, po.<int[]>field("intArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLongArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("longArrayField", new long[] {1, 2, 3});
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new long[] {1, 2, 3}, po.<long[]>field("longArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFloatArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("floatArrayField", new float[] {1, 2, 3});
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new float[] {1, 2, 3}, po.<float[]>field("floatArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDoubleArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("doubleArrayField", new double[] {1, 2, 3});
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new double[] {1, 2, 3}, po.<double[]>field("doubleArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCharArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("charArrayField", new char[] {1, 2, 3});
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new char[] {1, 2, 3}, po.<char[]>field("charArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBooleanArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("booleanArrayField", new boolean[] {true, false});
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ boolean[] arr = po.field("booleanArrayField");
+
+ assertEquals(2, arr.length);
+
+ assertTrue(arr[0]);
+ assertFalse(arr[1]);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDecimalArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("decimalArrayField", new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN});
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN}, po.<String[]>field("decimalArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testStringArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("stringArrayField", new String[] {"str1", "str2", "str3"});
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new String[] {"str1", "str2", "str3"}, po.<String[]>field("stringArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDateArrayField() throws Exception {
+ Date date1 = new Date();
+ Date date2 = new Date(date1.getTime() + 1000);
+
+ Date[] dateArr = new Date[] { date1, date2 };
+
+ assertTrue(Arrays.equals(dateArr, builder("C").setField("da", dateArr).build().<Date[]>field("da")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTimestampArrayField() throws Exception {
+ Timestamp ts1 = new Timestamp(new Date().getTime());
+ Timestamp ts2 = new Timestamp(new Date().getTime() + 1000);
+
+ ts1.setNanos(1000);
+ ts2.setNanos(2000);
+
+ Timestamp[] tsArr = new Timestamp[] { ts1, ts2 };
+
+ assertTrue(Arrays.equals(tsArr, builder("C").setField("ta", tsArr).build().<Timestamp[]>field("ta")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testUuidArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ UUID[] arr = new UUID[] {UUID.randomUUID(), UUID.randomUUID()};
+
+ builder.setField("uuidArrayField", arr);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(arr, po.<UUID[]>field("uuidArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testObjectField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("objectField", new Value(1));
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1, po.<BinaryObject>field("objectField").<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testObjectArrayField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("objectArrayField", new Value[] {new Value(1), new Value(2)});
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ Object[] arr = po.field("objectArrayField");
+
+ assertEquals(2, arr.length);
+
+ assertEquals(1, ((BinaryObject)arr[0]).<Value>deserialize().i);
+ assertEquals(2, ((BinaryObject)arr[1]).<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCollectionField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("collectionField", Arrays.asList(new Value(1), new Value(2)));
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ List<BinaryObject> list = po.field("collectionField");
+
+ assertEquals(2, list.size());
+
+ assertEquals(1, list.get(0).<Value>deserialize().i);
+ assertEquals(2, list.get(1).<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMapField() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("mapField", F.asMap(new Key(1), new Value(1), new Key(2), new Value(2)));
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ Map<BinaryObject, BinaryObject> map = po.field("mapField");
+
+ assertEquals(2, map.size());
+
+ for (Map.Entry<BinaryObject, BinaryObject> e : map.entrySet())
+ assertEquals(e.getKey().<Key>deserialize().i, e.getValue().<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testSeveralFields() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("i", 111);
+ builder.setField("f", 111.111f);
+ builder.setField("iArr", new int[] {1, 2, 3});
+ builder.setField("obj", new Key(1));
+ builder.setField("col", Arrays.asList(new Value(1), new Value(2)));
+
+ BinaryObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(111, po.<Integer>field("i").intValue());
+ assertEquals(111.111f, po.<Float>field("f").floatValue(), 0);
+ assertTrue(Arrays.equals(new int[] {1, 2, 3}, po.<int[]>field("iArr")));
+ assertEquals(1, po.<BinaryObject>field("obj").<Key>deserialize().i);
+
+ List<BinaryObject> list = po.field("col");
+
+ assertEquals(2, list.size());
+
+ assertEquals(1, list.get(0).<Value>deserialize().i);
+ assertEquals(2, list.get(1).<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testOffheapPortable() throws Exception {
+ BinaryObjectBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("i", 111);
+ builder.setField("f", 111.111f);
+ builder.setField("iArr", new int[] {1, 2, 3});
+ builder.setField("obj", new Key(1));
+ builder.setField("col", Arrays.asList(new Value(1), new Value(2)));
+
+ BinaryObject po = builder.build();
+
+ byte[] arr = ((CacheObjectBinaryProcessorImpl)(grid(0)).context().cacheObjects()).marshal(po);
+
+ long ptr = UNSAFE.allocateMemory(arr.length + 5);
+
+ try {
+ long ptr0 = ptr;
+
+ UNSAFE.putBoolean(null, ptr0++, false);
+
+ UNSAFE.putInt(ptr0, arr.length);
+
+ UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr0 + 4, arr.length);
+
+ BinaryObject offheapObj = (BinaryObject)
+ ((CacheObjectBinaryProcessorImpl)(grid(0)).context().cacheObjects()).unmarshal(ptr, false);
+
+ assertEquals(BinaryObjectOffheapImpl.class, offheapObj.getClass());
+
+ assertEquals("class".hashCode(), offheapObj.typeId());
+ assertEquals(100, offheapObj.hashCode());
+
+ assertEquals(111, offheapObj.<Integer>field("i").intValue());
+ assertEquals(111.111f, offheapObj.<Float>field("f").floatValue(), 0);
+ assertTrue(Arrays.equals(new int[] {1, 2, 3}, offheapObj.<int[]>field("iArr")));
+ assertEquals(1, offheapObj.<BinaryObject>field("obj").<Key>deserialize().i);
+
+ List<BinaryObject> list = offheapObj.field("col");
+
+ assertEquals(2, list.size());
+
+ assertEquals(1, list.get(0).<Value>deserialize().i);
+ assertEquals(2, list.get(1).<Value>deserialize().i);
+
+ assertEquals(po, offheapObj);
+ assertEquals(offheapObj, po);
+ }
+ finally {
+ UNSAFE.freeMemory(ptr);
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBuildAndDeserialize() throws Exception {
+ BinaryObjectBuilder builder = builder(Value.class.getName());
+
+ builder.hashCode(100);
+
+ builder.setField("i", 1);
+
+ BinaryObject po = builder.build();
+
+ assertEquals("value".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1, po.<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMetaData2() throws Exception {
+ BinaryObjectBuilder builder = builder("org.test.MetaTest2");
+
+ builder.setField("objectField", "a", Object.class);
+
+ BinaryObject po = builder.build();
+
+ BinaryType meta = po.type();
+
+ assertEquals("MetaTest2", meta.typeName());
+ assertEquals("Object", meta.fieldTypeName("objectField"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMetaData() throws Exception {
+ BinaryObjectBuilder builder = builder("org.test.MetaTest");
+
+ builder.hashCode(100);
+
+ builder.setField("intField", 1);
+ builder.setField("byteArrayField", new byte[] {1, 2, 3});
+
+ BinaryObject po = builder.build();
+
+ BinaryType meta = po.type();
+
+ assertEquals("MetaTest", meta.typeName());
+
+ Collection<String> fields = meta.fields();
+
+ assertEquals(2, fields.size());
+
+ assertTrue(fields.contains("intField"));
+ assertTrue(fields.contains("byteArrayField"));
+
+ assertEquals("int", meta.fieldTypeName("intField"));
+ assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
+
+ builder = builder("org.test.MetaTest");
+
+ builder.hashCode(100);
+
+ builder.setField("intField", 2);
+ builder.setField("uuidField", UUID.randomUUID());
+
+ po = builder.build();
+
+ meta = po.type();
+
+ assertEquals("MetaTest", meta.typeName());
+
+ fields = meta.fields();
+
+ assertEquals(3, fields.size());
+
+ assertTrue(fields.contains("intField"));
+ assertTrue(fields.contains("byteArrayField"));
+ assertTrue(fields.contains("uuidField"));
+
+ assertEquals("int", meta.fieldTypeName("intField"));
+ assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
+ assertEquals("UUID", meta.fieldTypeName("uuidField"));
+ }
+
+ /**
+ *
+ */
+ public void testGetFromCopiedObj() {
+ BinaryObject objStr = builder(TestObjectAllTypes.class.getName()).setField("str", "aaa").build();
+
+ BinaryObjectBuilderImpl builder = builder(objStr);
+ assertEquals("aaa", builder.getField("str"));
+
+ builder.setField("str", "bbb");
+ assertEquals("bbb", builder.getField("str"));
+
+ assertNull(builder.getField("i_"));
+ assertEquals("bbb", builder.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ *
+ */
+ public void testCopyFromInnerObjects() {
+ ArrayList<Object> list = new ArrayList<>();
+ list.add(new TestObjectAllTypes());
+ list.add(list.get(0));
+
+ TestObjectContainer c = new TestObjectContainer(list);
+
+ BinaryObjectBuilderImpl builder = builder(toPortable(c));
+ builder.<List>getField("foo").add("!!!");
+
+ BinaryObject res = builder.build();
+
+ TestObjectContainer deserialized = res.deserialize();
+
+ List deserializedList = (List)deserialized.foo;
+
+ assertSame(deserializedList.get(0), deserializedList.get(1));
+ assertEquals("!!!", deserializedList.get(2));
+ assertTrue(deserializedList.get(0) instanceof TestObjectAllTypes);
+ }
+
+ /**
+ *
+ */
+ public void testSetPortableObject() {
+ BinaryObject portableObj = builder(TestObjectContainer.class.getName())
+ .setField("foo", toPortable(new TestObjectAllTypes()))
+ .build();
+
+ assertTrue(portableObj.<TestObjectContainer>deserialize().foo instanceof TestObjectAllTypes);
+ }
+
+ /**
+ *
+ */
+ public void testPlainPortableObjectCopyFrom() {
+ TestObjectPlainPortable obj = new TestObjectPlainPortable(toPortable(new TestObjectAllTypes()));
+
+ BinaryObjectBuilderImpl builder = builder(toPortable(obj));
+ assertTrue(builder.getField("plainPortable") instanceof BinaryObject);
+
+ TestObjectPlainPortable deserialized = builder.build().deserialize();
+ assertTrue(deserialized.plainPortable instanceof BinaryObject);
+ }
+
+ /**
+ *
+ */
+ public void testRemoveFromNewObject() {
+ BinaryObjectBuilder builder = builder(TestObjectAllTypes.class.getName());
+
+ builder.setField("str", "a");
+
+ builder.removeField("str");
+
+ assertNull(builder.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ *
+ */
+ public void testRemoveFromExistingObject() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+ obj.setDefaultData();
+ obj.enumArr = null;
+
+ BinaryObjectBuilder builder = builder(toPortable(obj));
+
+ builder.removeField("str");
+
+ assertNull(builder.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ *
+ */
+ public void testRemoveFromExistingObjectAfterGet() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+ obj.setDefaultData();
+ obj.enumArr = null;
+
+ BinaryObjectBuilderImpl builder = builder(toPortable(obj));
+
+ builder.getField("i_");
+
+ builder.removeField("str");
+
+ assertNull(builder.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ * @throws IgniteCheckedException If any error occurs.
+ */
+ public void testDontBrokeCyclicDependency() throws IgniteCheckedException {
+ TestObjectOuter outer = new TestObjectOuter();
+ outer.inner = new TestObjectInner();
+ outer.inner.outer = outer;
+ outer.foo = "a";
+
+ BinaryObjectBuilder builder = builder(toPortable(outer));
+
+ builder.setField("foo", "b");
+
+ TestObjectOuter res = builder.build().deserialize();
+
+ assertEquals("b", res.foo);
+ assertSame(res, res.inner.outer);
+ }
+
+ /**
+ * @return Portables.
+ */
+ private IgniteBinary portables() {
+ return grid(0).binary();
+ }
+
+ /**
+ * @param obj Object.
+ * @return Portable object.
+ */
+ private BinaryObject toPortable(Object obj) {
+ return portables().toBinary(obj);
+ }
+
+ /**
+ * @return Builder.
+ */
+ private <T> BinaryObjectBuilder builder(int typeId) {
+ return portables().builder(typeId);
+ }
+
+ /**
+ * @return Builder.
+ */
+ private <T> BinaryObjectBuilder builder(String clsName) {
+ return portables().builder(clsName);
+ }
+
+ /**
+ * @return Builder.
+ */
+ private <T> BinaryObjectBuilderImpl builder(BinaryObject obj) {
+ return (BinaryObjectBuilderImpl)portables().builder(obj);
+ }
+
+ /**
+ *
+ */
+ private static class CustomIdMapper {
+ /** */
+ private String str = "a";
+
+ /** */
+ private int i = 10;
+ }
+
+ /**
+ */
+ private static class Key {
+ /** */
+ private int i;
+
+ /**
+ */
+ private Key() {
+ // No-op.
+ }
+
+ /**
+ * @param i Index.
+ */
+ private Key(int i) {
+ this.i = i;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ Key key = (Key)o;
+
+ return i == key.i;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return i;
+ }
+ }
+
+ /**
+ */
+ private static class Value {
+ /** */
+ private int i;
+
+ /**
+ */
+ private Value() {
+ // No-op.
+ }
+
+ /**
+ * @param i Index.
+ */
+ private Value(int i) {
+ this.i = i;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderStringAsCharsAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderStringAsCharsAdditionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderStringAsCharsAdditionalSelfTest.java
new file mode 100644
index 0000000..e9eb92c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderStringAsCharsAdditionalSelfTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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.portable;
+
+/**
+ *
+ */
+public class GridBinaryObjectBuilderStringAsCharsAdditionalSelfTest extends GridBinaryObjectBuilderAdditionalSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean useUtf8() {
+ return false;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderStringAsCharsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderStringAsCharsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderStringAsCharsSelfTest.java
new file mode 100644
index 0000000..050dc66
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridBinaryObjectBuilderStringAsCharsSelfTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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.portable;
+
+/**
+ * Portable builder test.
+ */
+public class GridBinaryObjectBuilderStringAsCharsSelfTest extends GridBinaryObjectBuilderSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean useUtf8() {
+ return false;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
index 59084db..748c423 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
@@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.ignite.Ignite;
+import org.apache.ignite.cache.CacheKeyConfiguration;
import org.apache.ignite.cache.affinity.Affinity;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
@@ -32,7 +33,7 @@ import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProces
import org.apache.ignite.lang.IgniteCallable;
import org.apache.ignite.lang.IgniteRunnable;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
@@ -58,15 +59,18 @@ public class GridPortableAffinityKeySelfTest extends GridCommonAbstractTest {
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
- PortableTypeConfiguration typeCfg = new PortableTypeConfiguration();
+ BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
typeCfg.setClassName(TestObject.class.getName());
- typeCfg.setAffinityKeyFieldName("affKey");
PortableMarshaller marsh = new PortableMarshaller();
marsh.setTypeConfigurations(Collections.singleton(typeCfg));
+ CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestObject.class.getName(), "affKey");
+
+ cfg.setCacheKeyCfg(keyCfg);
+
cfg.setMarshaller(marsh);
if (!gridName.equals(getTestGridName(GRID_CNT))) {
[25/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/EmployeeKey.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/EmployeeKey.java b/examples/src/main/java/org/apache/ignite/examples/portable/EmployeeKey.java
deleted file mode 100644
index f322167..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/EmployeeKey.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.examples.portable;
-
-/**
- * This class represents key for employee object.
- * <p>
- * Used in query example to collocate employees
- * with their organizations.
- */
-public class EmployeeKey {
- /** ID. */
- private int id;
-
- /** Organization ID. */
- private int organizationId;
-
- /**
- * Required for portable deserialization.
- */
- public EmployeeKey() {
- // No-op.
- }
-
- /**
- * @param id ID.
- * @param organizationId Organization ID.
- */
- public EmployeeKey(int id, int organizationId) {
- this.id = id;
- this.organizationId = organizationId;
- }
-
- /**
- * @return ID.
- */
- public int id() {
- return id;
- }
-
- /**
- * @return Organization ID.
- */
- public int organizationId() {
- return organizationId;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- EmployeeKey key = (EmployeeKey)o;
-
- return id == key.id && organizationId == key.organizationId;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- int res = id;
-
- res = 31 * res + organizationId;
-
- return res;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "EmployeeKey [id=" + id +
- ", organizationId=" + organizationId + ']';
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/ExamplePortableNodeStartup.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/ExamplePortableNodeStartup.java b/examples/src/main/java/org/apache/ignite/examples/portable/ExamplePortableNodeStartup.java
deleted file mode 100644
index 87a41f7..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/ExamplePortableNodeStartup.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.examples.portable;
-
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.Ignition;
-
-/**
- * Starts up an empty node with example configuration and portable marshaller enabled.
- */
-public class ExamplePortableNodeStartup {
- /**
- * Start up an empty node with example configuration and portable marshaller enabled.
- *
- * @param args Command line arguments, none required.
- * @throws IgniteException If failed.
- */
- public static void main(String[] args) throws IgniteException {
- Ignition.start("examples/config/portable/example-ignite-portable.xml");
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/Organization.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/Organization.java b/examples/src/main/java/org/apache/ignite/examples/portable/Organization.java
deleted file mode 100644
index f52cac1..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/Organization.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.examples.portable;
-
-import java.sql.Timestamp;
-
-/**
- * This class represents organization object.
- */
-public class Organization {
- /** Name. */
- private String name;
-
- /** Address. */
- private Address address;
-
- /** Type. */
- private OrganizationType type;
-
- /** Last update time. */
- private Timestamp lastUpdated;
-
- /**
- * Required for portable deserialization.
- */
- public Organization() {
- // No-op.
- }
-
- /**
- * @param name Name.
- * @param address Address.
- * @param type Type.
- * @param lastUpdated Last update time.
- */
- public Organization(String name, Address address, OrganizationType type, Timestamp lastUpdated) {
- this.name = name;
- this.address = address;
- this.type = type;
- this.lastUpdated = lastUpdated;
- }
-
- /**
- * @return Name.
- */
- public String name() {
- return name;
- }
-
- /**
- * @return Address.
- */
- public Address address() {
- return address;
- }
-
- /**
- * @return Type.
- */
- public OrganizationType type() {
- return type;
- }
-
- /**
- * @return Last update time.
- */
- public Timestamp lastUpdated() {
- return lastUpdated;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return "Organization [name=" + name +
- ", address=" + address +
- ", type=" + type +
- ", lastUpdated=" + lastUpdated + ']';
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/OrganizationType.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/OrganizationType.java b/examples/src/main/java/org/apache/ignite/examples/portable/OrganizationType.java
deleted file mode 100644
index c753e2d..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/OrganizationType.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.examples.portable;
-
-/**
- * Organization type enum.
- */
-public enum OrganizationType {
- /** Non-profit organization. */
- NON_PROFIT,
-
- /** Private organization. */
- PRIVATE,
-
- /** Government organization. */
- GOVERNMENT
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientPortableTaskExecutionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientPortableTaskExecutionExample.java b/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientPortableTaskExecutionExample.java
deleted file mode 100644
index 34d9cde..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientPortableTaskExecutionExample.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * 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.examples.portable.computegrid;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.examples.portable.Address;
-import org.apache.ignite.examples.portable.Employee;
-import org.apache.ignite.examples.portable.ExamplePortableNodeStartup;
-import org.apache.ignite.portable.PortableObject;
-
-/**
- * This example demonstrates use of portable objects with task execution.
- * Specifically it shows that portable objects are simple Java POJOs and do not require any special treatment.
- * <p>
- * The example executes map-reduce task that accepts collection of portable objects as an argument.
- * Since these objects are never deserialized on remote nodes, classes are not required on classpath
- * of these nodes.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables the portable marshaller: {@code 'ignite.{sh|bat} examples/config/portable/example-ignite-portable.xml'}.
- * <p>
- * Alternatively you can run {@link ExamplePortableNodeStartup} in another JVM which will
- * start node with {@code examples/config/portable/example-ignite-portable.xml} configuration.
- */
-public class ComputeClientPortableTaskExecutionExample {
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- */
- public static void main(String[] args) {
- try (Ignite ignite = Ignition.start("examples/config/portable/example-ignite-portable.xml")) {
- System.out.println();
- System.out.println(">>> Portable objects task execution example started.");
-
- if (ignite.cluster().forRemotes().nodes().isEmpty()) {
- System.out.println();
- System.out.println(">>> This example requires remote nodes to be started.");
- System.out.println(">>> Please start at least 1 remote node.");
- System.out.println(">>> Refer to example's javadoc for details on configuration.");
- System.out.println();
-
- return;
- }
-
- // Generate employees to calculate average salary for.
- Collection<Employee> employees = employees();
-
- System.out.println();
- System.out.println(">>> Calculating average salary for employees:");
-
- for (Employee employee : employees)
- System.out.println(">>> " + employee);
-
- // Convert collection of employees to collection of portable objects.
- // This allows to send objects across nodes without requiring to have
- // Employee class on classpath of these nodes.
- Collection<PortableObject> portables = ignite.portables().toPortable(employees);
-
- // Execute task and get average salary.
- Long avgSalary = ignite.compute(ignite.cluster().forRemotes()).execute(new ComputeClientTask(), portables);
-
- System.out.println();
- System.out.println(">>> Average salary for all employees: " + avgSalary);
- System.out.println();
- }
- }
-
- /**
- * Creates collection of employees.
- *
- * @return Collection of employees.
- */
- private static Collection<Employee> employees() {
- Collection<Employee> employees = new ArrayList<>();
-
- employees.add(new Employee(
- "James Wilson",
- 12500,
- new Address("1096 Eddy Street, San Francisco, CA", 94109),
- Arrays.asList("Human Resources", "Customer Service")
- ));
-
- employees.add(new Employee(
- "Daniel Adams",
- 11000,
- new Address("184 Fidler Drive, San Antonio, TX", 78205),
- Arrays.asList("Development", "QA")
- ));
-
- employees.add(new Employee(
- "Cristian Moss",
- 12500,
- new Address("667 Jerry Dove Drive, Florence, SC", 29501),
- Arrays.asList("Logistics")
- ));
-
- employees.add(new Employee(
- "Allison Mathis",
- 25300,
- new Address("2702 Freedom Lane, Hornitos, CA", 95325),
- Arrays.asList("Development")
- ));
-
- employees.add(new Employee(
- "Breana Robbin",
- 6500,
- new Address("3960 Sundown Lane, Austin, TX", 78758),
- Arrays.asList("Sales")
- ));
-
- employees.add(new Employee(
- "Philip Horsley",
- 19800,
- new Address("2803 Elsie Drive, Sioux Falls, SD", 57104),
- Arrays.asList("Sales")
- ));
-
- employees.add(new Employee(
- "Brian Peters",
- 10600,
- new Address("1407 Pearlman Avenue, Boston, MA", 12110),
- Arrays.asList("Development", "QA")
- ));
-
- employees.add(new Employee(
- "Jack Yang",
- 12900,
- new Address("4425 Parrish Avenue Smithsons Valley, TX", 78130),
- Arrays.asList("Sales")
- ));
-
- return employees;
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientTask.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientTask.java b/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientTask.java
deleted file mode 100644
index 0eee8c6..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientTask.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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.examples.portable.computegrid;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.compute.ComputeJob;
-import org.apache.ignite.compute.ComputeJobAdapter;
-import org.apache.ignite.compute.ComputeJobResult;
-import org.apache.ignite.compute.ComputeTaskSplitAdapter;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.portable.PortableObject;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Task that is used for {@link ComputeClientPortableTaskExecutionExample} and
- * similar examples in .NET and C++.
- * <p>
- * This task calculates average salary for provided collection of employees.
- * It splits the collection into batches of size {@code 3} and creates a job
- * for each batch. After all jobs are executed, there results are reduced to
- * get the average salary.
- */
-public class ComputeClientTask extends ComputeTaskSplitAdapter<Collection<PortableObject>, Long> {
- /** {@inheritDoc} */
- @Override protected Collection<? extends ComputeJob> split(
- int gridSize,
- Collection<PortableObject> arg
- ) {
- Collection<ComputeClientJob> jobs = new ArrayList<>();
-
- Collection<PortableObject> employees = new ArrayList<>();
-
- // Split provided collection into batches and
- // create a job for each batch.
- for (PortableObject employee : arg) {
- employees.add(employee);
-
- if (employees.size() == 3) {
- jobs.add(new ComputeClientJob(employees));
-
- employees = new ArrayList<>(3);
- }
- }
-
- if (!employees.isEmpty())
- jobs.add(new ComputeClientJob(employees));
-
- return jobs;
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Long reduce(List<ComputeJobResult> results) {
- long sum = 0;
- int cnt = 0;
-
- for (ComputeJobResult res : results) {
- IgniteBiTuple<Long, Integer> t = res.getData();
-
- sum += t.get1();
- cnt += t.get2();
- }
-
- return sum / cnt;
- }
-
- /**
- * Remote job for {@link ComputeClientTask}.
- */
- private static class ComputeClientJob extends ComputeJobAdapter {
- /** Collection of employees. */
- private final Collection<PortableObject> employees;
-
- /**
- * @param employees Collection of employees.
- */
- private ComputeClientJob(Collection<PortableObject> employees) {
- this.employees = employees;
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Object execute() {
- long sum = 0;
- int cnt = 0;
-
- for (PortableObject employee : employees) {
- System.out.println(">>> Processing employee: " + employee.field("name"));
-
- // Get salary from portable object. Note that object
- // doesn't need to be fully deserialized.
- long salary = employee.field("salary");
-
- sum += salary;
- cnt++;
- }
-
- return new IgniteBiTuple<>(sum, cnt);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/package-info.java b/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/package-info.java
deleted file mode 100644
index 469128c..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/package-info.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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.
- */
-
-/**
- * Demonstrates the usage of portable objects with task execution.
- */
-package org.apache.ignite.examples.portable.computegrid;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortablePutGetExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortablePutGetExample.java b/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortablePutGetExample.java
deleted file mode 100644
index 77c5d95..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortablePutGetExample.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * 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.examples.portable.datagrid;
-
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.portable.Address;
-import org.apache.ignite.examples.portable.ExamplePortableNodeStartup;
-import org.apache.ignite.examples.portable.Organization;
-import org.apache.ignite.examples.portable.OrganizationType;
-import org.apache.ignite.portable.PortableObject;
-
-/**
- * This example demonstrates use of portable objects with Ignite cache.
- * Specifically it shows that portable objects are simple Java POJOs and do not require any special treatment.
- * <p>
- * The example executes several put-get operations on Ignite cache with portable values. Note that
- * it demonstrates how portable object can be retrieved in fully-deserialized form or in portable object
- * format using special cache projection.
- * <p>
- * Remote nodes should always be started with special configuration file which
- * enables the portable marshaller: {@code 'ignite.{sh|bat} examples/config/portable/example-ignite-portable.xml'}.
- * <p>
- * Alternatively you can run {@link ExamplePortableNodeStartup} in another JVM which will
- * start node with {@code examples/config/portable/example-ignite-portable.xml} configuration.
- */
-public class CacheClientPortablePutGetExample {
- /** Cache name. */
- private static final String CACHE_NAME = CacheClientPortablePutGetExample.class.getSimpleName();
-
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- */
- public static void main(String[] args) {
- try (Ignite ignite = Ignition.start("examples/config/portable/example-ignite-portable.xml")) {
- System.out.println();
- System.out.println(">>> Portable objects cache put-get example started.");
-
- CacheConfiguration<Integer, Organization> cfg = new CacheConfiguration<>();
-
- cfg.setCacheMode(CacheMode.PARTITIONED);
- cfg.setName(CACHE_NAME);
- cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
-
- try (IgniteCache<Integer, Organization> cache = ignite.createCache(cfg)) {
- if (ignite.cluster().forDataNodes(cache.getName()).nodes().isEmpty()) {
- System.out.println();
- System.out.println(">>> This example requires remote cache node nodes to be started.");
- System.out.println(">>> Please start at least 1 remote cache node.");
- System.out.println(">>> Refer to example's javadoc for details on configuration.");
- System.out.println();
-
- return;
- }
-
- putGet(cache);
- putGetPortable(cache);
- putGetAll(cache);
- putGetAllPortable(cache);
-
- System.out.println();
- }
- finally {
- // Delete cache with its content completely.
- ignite.destroyCache(CACHE_NAME);
- }
- }
- }
-
- /**
- * Execute individual put and get.
- *
- * @param cache Cache.
- */
- private static void putGet(IgniteCache<Integer, Organization> cache) {
- // Create new Organization portable object to store in cache.
- Organization org = new Organization(
- "Microsoft", // Name.
- new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
- OrganizationType.PRIVATE, // Type.
- new Timestamp(System.currentTimeMillis())); // Last update time.
-
- // Put created data entry to cache.
- cache.put(1, org);
-
- // Get recently created organization as a strongly-typed fully de-serialized instance.
- Organization orgFromCache = cache.get(1);
-
- System.out.println();
- System.out.println(">>> Retrieved organization instance from cache: " + orgFromCache);
- }
-
- /**
- * Execute individual put and get, getting value in portable format, without de-serializing it.
- *
- * @param cache Cache.
- */
- private static void putGetPortable(IgniteCache<Integer, Organization> cache) {
- // Create new Organization portable object to store in cache.
- Organization org = new Organization(
- "Microsoft", // Name.
- new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
- OrganizationType.PRIVATE, // Type.
- new Timestamp(System.currentTimeMillis())); // Last update time.
-
- // Put created data entry to cache.
- cache.put(1, org);
-
- // Get cache that will get values as portable objects.
- IgniteCache<Integer, PortableObject> portableCache = cache.withKeepPortable();
-
- // Get recently created organization as a portable object.
- PortableObject po = portableCache.get(1);
-
- // Get organization's name from portable object (note that
- // object doesn't need to be fully deserialized).
- String name = po.field("name");
-
- System.out.println();
- System.out.println(">>> Retrieved organization name from portable object: " + name);
- }
-
- /**
- * Execute bulk {@code putAll(...)} and {@code getAll(...)} operations.
- *
- * @param cache Cache.
- */
- private static void putGetAll(IgniteCache<Integer, Organization> cache) {
- // Create new Organization portable objects to store in cache.
- Organization org1 = new Organization(
- "Microsoft", // Name.
- new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
- OrganizationType.PRIVATE, // Type.
- new Timestamp(System.currentTimeMillis())); // Last update time.
-
- Organization org2 = new Organization(
- "Red Cross", // Name.
- new Address("184 Fidler Drive, San Antonio, TX", 78205), // Address.
- OrganizationType.NON_PROFIT, // Type.
- new Timestamp(System.currentTimeMillis())); // Last update time.
-
- Map<Integer, Organization> map = new HashMap<>();
-
- map.put(1, org1);
- map.put(2, org2);
-
- // Put created data entries to cache.
- cache.putAll(map);
-
- // Get recently created organizations as a strongly-typed fully de-serialized instances.
- Map<Integer, Organization> mapFromCache = cache.getAll(map.keySet());
-
- System.out.println();
- System.out.println(">>> Retrieved organization instances from cache:");
-
- for (Organization org : mapFromCache.values())
- System.out.println(">>> " + org);
- }
-
- /**
- * Execute bulk {@code putAll(...)} and {@code getAll(...)} operations,
- * getting values in portable format, without de-serializing it.
- *
- * @param cache Cache.
- */
- private static void putGetAllPortable(IgniteCache<Integer, Organization> cache) {
- // Create new Organization portable objects to store in cache.
- Organization org1 = new Organization(
- "Microsoft", // Name.
- new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
- OrganizationType.PRIVATE, // Type.
- new Timestamp(System.currentTimeMillis())); // Last update time.
-
- Organization org2 = new Organization(
- "Red Cross", // Name.
- new Address("184 Fidler Drive, San Antonio, TX", 78205), // Address.
- OrganizationType.NON_PROFIT, // Type.
- new Timestamp(System.currentTimeMillis())); // Last update time.
-
- Map<Integer, Organization> map = new HashMap<>();
-
- map.put(1, org1);
- map.put(2, org2);
-
- // Put created data entries to cache.
- cache.putAll(map);
-
- // Get cache that will get values as portable objects.
- IgniteCache<Integer, PortableObject> portableCache = cache.withKeepPortable();
-
- // Get recently created organizations as portable objects.
- Map<Integer, PortableObject> poMap = portableCache.getAll(map.keySet());
-
- Collection<String> names = new ArrayList<>();
-
- // Get organizations' names from portable objects (note that
- // objects don't need to be fully deserialized).
- for (PortableObject po : poMap.values())
- names.add(po.<String>field("name"));
-
- System.out.println();
- System.out.println(">>> Retrieved organization names from portable objects: " + names);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortableQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortableQueryExample.java b/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortableQueryExample.java
deleted file mode 100644
index 3170864..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortableQueryExample.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * 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.examples.portable.datagrid;
-
-import java.sql.Timestamp;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.cache.Cache;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.Ignition;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CacheTypeMetadata;
-import org.apache.ignite.cache.query.QueryCursor;
-import org.apache.ignite.cache.query.SqlFieldsQuery;
-import org.apache.ignite.cache.query.SqlQuery;
-import org.apache.ignite.cache.query.TextQuery;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.examples.portable.Address;
-import org.apache.ignite.examples.portable.Employee;
-import org.apache.ignite.examples.portable.EmployeeKey;
-import org.apache.ignite.examples.portable.ExamplePortableNodeStartup;
-import org.apache.ignite.examples.portable.Organization;
-import org.apache.ignite.examples.portable.OrganizationType;
-import org.apache.ignite.portable.PortableObject;
-
-/**
- * This example demonstrates use of portable objects with cache queries.
- * The example populates cache with sample data and runs several SQL and full text queries over this data.
- * <p>
- * Remote nodes should always be started with {@link ExamplePortableNodeStartup} which starts a node with
- * {@code examples/config/portable/example-ignite-portable.xml} configuration.
- */
-public class CacheClientPortableQueryExample {
- /** Organization cache name. */
- private static final String ORGANIZATION_CACHE_NAME = CacheClientPortableQueryExample.class.getSimpleName()
- + "Organizations";
-
- /** Employee cache name. */
- private static final String EMPLOYEE_CACHE_NAME = CacheClientPortableQueryExample.class.getSimpleName()
- + "Employees";
-
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- */
- public static void main(String[] args) {
- try (Ignite ignite = Ignition.start("examples/config/portable/example-ignite-portable.xml")) {
- System.out.println();
- System.out.println(">>> Portable objects cache query example started.");
-
- CacheConfiguration<Integer, Organization> orgCacheCfg = new CacheConfiguration<>();
-
- orgCacheCfg.setCacheMode(CacheMode.PARTITIONED);
- orgCacheCfg.setName(ORGANIZATION_CACHE_NAME);
-
- orgCacheCfg.setTypeMetadata(Arrays.asList(createOrganizationTypeMetadata()));
-
- CacheConfiguration<EmployeeKey, Employee> employeeCacheCfg = new CacheConfiguration<>();
-
- employeeCacheCfg.setCacheMode(CacheMode.PARTITIONED);
- employeeCacheCfg.setName(EMPLOYEE_CACHE_NAME);
-
- employeeCacheCfg.setTypeMetadata(Arrays.asList(createEmployeeTypeMetadata()));
-
- try (IgniteCache<Integer, Organization> orgCache = ignite.createCache(orgCacheCfg);
- IgniteCache<EmployeeKey, Employee> employeeCache = ignite.createCache(employeeCacheCfg)
- ) {
- if (ignite.cluster().forDataNodes(orgCache.getName()).nodes().isEmpty()) {
- System.out.println();
- System.out.println(">>> This example requires remote cache nodes to be started.");
- System.out.println(">>> Please start at least 1 remote cache node.");
- System.out.println(">>> Refer to example's javadoc for details on configuration.");
- System.out.println();
-
- return;
- }
-
- // Populate cache with sample data entries.
- populateCache(orgCache, employeeCache);
-
- // Get cache that will work with portable objects.
- IgniteCache<PortableObject, PortableObject> portableCache = employeeCache.withKeepPortable();
-
- // Run SQL query example.
- sqlQuery(portableCache);
-
- // Run SQL query with join example.
- sqlJoinQuery(portableCache);
-
- // Run SQL fields query example.
- sqlFieldsQuery(portableCache);
-
- // Run full text query example.
- textQuery(portableCache);
-
- System.out.println();
- }
- finally {
- // Delete caches with their content completely.
- ignite.destroyCache(ORGANIZATION_CACHE_NAME);
- ignite.destroyCache(EMPLOYEE_CACHE_NAME);
- }
- }
- }
-
- /**
- * Create cache type metadata for {@link Employee}.
- *
- * @return Cache type metadata.
- */
- private static CacheTypeMetadata createEmployeeTypeMetadata() {
- CacheTypeMetadata employeeTypeMeta = new CacheTypeMetadata();
-
- employeeTypeMeta.setValueType(Employee.class);
-
- employeeTypeMeta.setKeyType(EmployeeKey.class);
-
- Map<String, Class<?>> ascFields = new HashMap<>();
-
- ascFields.put("name", String.class);
- ascFields.put("salary", Long.class);
- ascFields.put("address.zip", Integer.class);
- ascFields.put("organizationId", Integer.class);
-
- employeeTypeMeta.setAscendingFields(ascFields);
-
- employeeTypeMeta.setTextFields(Arrays.asList("address.street"));
-
- return employeeTypeMeta;
- }
-
- /**
- * Create cache type metadata for {@link Organization}.
- *
- * @return Cache type metadata.
- */
- private static CacheTypeMetadata createOrganizationTypeMetadata() {
- CacheTypeMetadata organizationTypeMeta = new CacheTypeMetadata();
-
- organizationTypeMeta.setValueType(Organization.class);
-
- organizationTypeMeta.setKeyType(Integer.class);
-
- Map<String, Class<?>> ascFields = new HashMap<>();
-
- ascFields.put("name", String.class);
-
- Map<String, Class<?>> queryFields = new HashMap<>();
-
- queryFields.put("address.street", String.class);
-
- organizationTypeMeta.setAscendingFields(ascFields);
-
- organizationTypeMeta.setQueryFields(queryFields);
-
- return organizationTypeMeta;
- }
-
- /**
- * Queries employees that have provided ZIP code in address.
- *
- * @param cache Ignite cache.
- */
- private static void sqlQuery(IgniteCache<PortableObject, PortableObject> cache) {
- SqlQuery<PortableObject, PortableObject> query = new SqlQuery<>(Employee.class, "zip = ?");
-
- int zip = 94109;
-
- QueryCursor<Cache.Entry<PortableObject, PortableObject>> employees = cache.query(query.setArgs(zip));
-
- System.out.println();
- System.out.println(">>> Employees with zip " + zip + ':');
-
- for (Cache.Entry<PortableObject, PortableObject> e : employees.getAll())
- System.out.println(">>> " + e.getValue().deserialize());
- }
-
- /**
- * Queries employees that work for organization with provided name.
- *
- * @param cache Ignite cache.
- */
- private static void sqlJoinQuery(IgniteCache<PortableObject, PortableObject> cache) {
- SqlQuery<PortableObject, PortableObject> query = new SqlQuery<>(Employee.class,
- "from Employee, \"" + ORGANIZATION_CACHE_NAME + "\".Organization as org " +
- "where Employee.organizationId = org._key and org.name = ?");
-
- String organizationName = "GridGain";
-
- QueryCursor<Cache.Entry<PortableObject, PortableObject>> employees =
- cache.query(query.setArgs(organizationName));
-
- System.out.println();
- System.out.println(">>> Employees working for " + organizationName + ':');
-
- for (Cache.Entry<PortableObject, PortableObject> e : employees.getAll())
- System.out.println(">>> " + e.getValue());
- }
-
- /**
- * Queries names and salaries for all employees.
- *
- * @param cache Ignite cache.
- */
- private static void sqlFieldsQuery(IgniteCache<PortableObject, PortableObject> cache) {
- SqlFieldsQuery query = new SqlFieldsQuery("select name, salary from Employee");
-
- QueryCursor<List<?>> employees = cache.query(query);
-
- System.out.println();
- System.out.println(">>> Employee names and their salaries:");
-
- for (List<?> row : employees.getAll())
- System.out.println(">>> [Name=" + row.get(0) + ", salary=" + row.get(1) + ']');
- }
-
- /**
- * Queries employees that live in Texas using full-text query API.
- *
- * @param cache Ignite cache.
- */
- private static void textQuery(IgniteCache<PortableObject, PortableObject> cache) {
- TextQuery<PortableObject, PortableObject> query = new TextQuery<>(Employee.class, "TX");
-
- QueryCursor<Cache.Entry<PortableObject, PortableObject>> employees = cache.query(query);
-
- System.out.println();
- System.out.println(">>> Employees living in Texas:");
-
- for (Cache.Entry<PortableObject, PortableObject> e : employees.getAll())
- System.out.println(">>> " + e.getValue().deserialize());
- }
-
- /**
- * Populates cache with data.
- *
- * @param orgCache Organization cache.
- * @param employeeCache Employee cache.
- */
- private static void populateCache(IgniteCache<Integer, Organization> orgCache,
- IgniteCache<EmployeeKey, Employee> employeeCache) {
- orgCache.put(1, new Organization(
- "GridGain",
- new Address("1065 East Hillsdale Blvd, Foster City, CA", 94404),
- OrganizationType.PRIVATE,
- new Timestamp(System.currentTimeMillis())
- ));
-
- orgCache.put(2, new Organization(
- "Microsoft",
- new Address("1096 Eddy Street, San Francisco, CA", 94109),
- OrganizationType.PRIVATE,
- new Timestamp(System.currentTimeMillis())
- ));
-
- employeeCache.put(new EmployeeKey(1, 1), new Employee(
- "James Wilson",
- 12500,
- new Address("1096 Eddy Street, San Francisco, CA", 94109),
- Arrays.asList("Human Resources", "Customer Service")
- ));
-
- employeeCache.put(new EmployeeKey(2, 1), new Employee(
- "Daniel Adams",
- 11000,
- new Address("184 Fidler Drive, San Antonio, TX", 78130),
- Arrays.asList("Development", "QA")
- ));
-
- employeeCache.put(new EmployeeKey(3, 1), new Employee(
- "Cristian Moss",
- 12500,
- new Address("667 Jerry Dove Drive, Florence, SC", 29501),
- Arrays.asList("Logistics")
- ));
-
- employeeCache.put(new EmployeeKey(4, 2), new Employee(
- "Allison Mathis",
- 25300,
- new Address("2702 Freedom Lane, San Francisco, CA", 94109),
- Arrays.asList("Development")
- ));
-
- employeeCache.put(new EmployeeKey(5, 2), new Employee(
- "Breana Robbin",
- 6500,
- new Address("3960 Sundown Lane, Austin, TX", 78130),
- Arrays.asList("Sales")
- ));
-
- employeeCache.put(new EmployeeKey(6, 2), new Employee(
- "Philip Horsley",
- 19800,
- new Address("2803 Elsie Drive, Sioux Falls, SD", 57104),
- Arrays.asList("Sales")
- ));
-
- employeeCache.put(new EmployeeKey(7, 2), new Employee(
- "Brian Peters",
- 10600,
- new Address("1407 Pearlman Avenue, Boston, MA", 12110),
- Arrays.asList("Development", "QA")
- ));
- }
-}
-
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/package-info.java b/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/package-info.java
deleted file mode 100644
index b24f233..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/package-info.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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.
- */
-
-/**
- * Demonstrates the usage of portable objects with cache.
- */
-package org.apache.ignite.examples.portable.datagrid;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/main/java/org/apache/ignite/examples/portable/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/package-info.java b/examples/src/main/java/org/apache/ignite/examples/portable/package-info.java
deleted file mode 100644
index 4301027..0000000
--- a/examples/src/main/java/org/apache/ignite/examples/portable/package-info.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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.
- */
-
-/**
- * Contains portable classes and examples.
- */
-package org.apache.ignite.examples.portable;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java b/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java
index 6ea1484..22261e2 100644
--- a/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java
+++ b/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java
@@ -17,8 +17,8 @@
package org.apache.ignite.examples;
-import org.apache.ignite.examples.portable.datagrid.CacheClientPortablePutGetExample;
-import org.apache.ignite.examples.portable.datagrid.CacheClientPortableQueryExample;
+import org.apache.ignite.examples.binary.datagrid.CacheClientBinaryPutGetExample;
+import org.apache.ignite.examples.binary.datagrid.CacheClientBinaryQueryExample;
import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
/**
@@ -34,13 +34,13 @@ public class CacheClientPortableExampleTest extends GridAbstractExamplesTest {
* @throws Exception If failed.
*/
public void testPortablePutGetExample() throws Exception {
- CacheClientPortablePutGetExample.main(new String[] {});
+ CacheClientBinaryPutGetExample.main(new String[] {});
}
/**
* @throws Exception If failed.
*/
public void testPortableQueryExample() throws Exception {
- CacheClientPortableQueryExample.main(new String[] {});
+ CacheClientBinaryQueryExample.main(new String[] {});
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java b/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java
index 2223aec..44d8776 100644
--- a/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java
+++ b/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java
@@ -16,7 +16,7 @@
*/
package org.apache.ignite.examples;
-import org.apache.ignite.examples.portable.computegrid.ComputeClientPortableTaskExecutionExample;
+import org.apache.ignite.examples.binary.computegrid.ComputeClientBinaryTaskExecutionExample;
import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
/**
@@ -32,6 +32,6 @@ public class ComputeClientPortableExampleTest extends GridAbstractExamplesTest {
* @throws Exception If failed.
*/
public void testPortableTaskExecutionExample() throws Exception {
- ComputeClientPortableTaskExecutionExample.main(new String[] {});
+ ComputeClientBinaryTaskExecutionExample.main(new String[] {});
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java b/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
index 8d9a3f5..b8ccc03 100644
--- a/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
+++ b/modules/codegen/src/main/java/org/apache/ignite/codegen/MessageCodeGenerator.java
@@ -43,6 +43,7 @@ import org.apache.ignite.internal.GridDirectCollection;
import org.apache.ignite.internal.GridDirectMap;
import org.apache.ignite.internal.GridDirectTransient;
import org.apache.ignite.internal.IgniteCodeGeneratingFail;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridNearAtomicUpdateRequest;
import org.apache.ignite.internal.util.typedef.internal.SB;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteUuid;
@@ -165,7 +166,9 @@ public class MessageCodeGenerator {
MessageCodeGenerator gen = new MessageCodeGenerator(srcDir);
- gen.generateAll(true);
+// gen.generateAll(true);
+
+ gen.generateAndWrite(GridNearAtomicUpdateRequest.class);
// gen.generateAndWrite(DataStreamerEntry.class);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/Ignite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java
index f2c180b..d320744 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignite.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java
@@ -469,11 +469,11 @@ public interface Ignite extends AutoCloseable {
public <T extends IgnitePlugin> T plugin(String name) throws PluginNotFoundException;
/**
- * Gets an instance of {@link IgnitePortables} interface.
+ * Gets an instance of {@link IgniteBinary} interface.
*
- * @return Instance of {@link IgnitePortables} interface.
+ * @return Instance of {@link IgniteBinary} interface.
*/
- public IgnitePortables portables();
+ public IgniteBinary binary();
/**
* Closes {@code this} instance of grid. This method is identical to calling
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/IgniteBinary.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteBinary.java b/modules/core/src/main/java/org/apache/ignite/IgniteBinary.java
new file mode 100644
index 0000000..71be821
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteBinary.java
@@ -0,0 +1,366 @@
+/*
+ * 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;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.TreeMap;
+import java.util.UUID;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Defines portable objects functionality. With portable objects you are able to:
+ * <ul>
+ * <li>Seamlessly interoperate between Java, .NET, and C++.</li>
+ * <li>Make any object portable with zero code change to your existing code.</li>
+ * <li>Nest portable objects within each other.</li>
+ * <li>Automatically handle {@code circular} or {@code null} references.</li>
+ * <li>Automatically convert collections and maps between Java, .NET, and C++.</li>
+ * <li>
+ * Optionally avoid deserialization of objects on the server side
+ * (objects are stored in {@link org.apache.ignite.binary.BinaryObject} format).
+ * </li>
+ * <li>Avoid need to have concrete class definitions on the server side.</li>
+ * <li>Dynamically change structure of the classes without having to restart the cluster.</li>
+ * <li>Index into portable objects for querying purposes.</li>
+ * </ul>
+ * <h1 class="header">Working With Portables Directly</h1>
+ * Once an object is defined as portable,
+ * Ignite will always store it in memory in the portable (i.e. binary) format.
+ * User can choose to work either with the portable format or with the deserialized form
+ * (assuming that class definitions are present in the classpath).
+ * <p>
+ * To work with the portable format directly, user should create a special cache projection
+ * using IgniteCache.withKeepBinary() method and then retrieve individual fields as needed:
+ * <pre name=code class=java>
+ * IgniteCache<PortableObject, PortableObject> prj = cache.withKeepBinary();
+ *
+ * // Convert instance of MyKey to portable format.
+ * // We could also use PortableBuilder to create the key in portable format directly.
+ * PortableObject key = grid.binary().toBinary(new MyKey());
+ *
+ * PortableObject val = prj.get(key);
+ *
+ * String field = val.field("myFieldName");
+ * </pre>
+ * Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized
+ * typed objects at all times. In this case we do incur the deserialization cost. However, if
+ * {@link PortableMarshaller#isKeepDeserialized()} is {@code true} then Ignite will only deserialize on the first access
+ * and will cache the deserialized object, so it does not have to be deserialized again:
+ * <pre name=code class=java>
+ * IgniteCache<MyKey.class, MyValue.class> cache = grid.cache(null);
+ *
+ * MyValue val = cache.get(new MyKey());
+ *
+ * // Normal java getter.
+ * String fieldVal = val.getMyFieldName();
+ * </pre>
+ * If we used, for example, one of the automatically handled portable types for a key, like integer,
+ * and still wanted to work with binary portable format for values, then we would declare cache projection
+ * as follows:
+ * <pre name=code class=java>
+ * IgniteCache<Integer.class, PortableObject> prj = cache.withKeepBinary();
+ * </pre>
+ * <h1 class="header">Automatic Portable Types</h1>
+ * Note that only portable classes are converted to {@link org.apache.ignite.binary.BinaryObject} format. Following
+ * classes are never converted (e.g., {@link #toBinary(Object)} method will return original
+ * object, and instances of these classes will be stored in cache without changes):
+ * <ul>
+ * <li>All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)</li>
+ * <li>Arrays of primitives (byte[], int[], ...)</li>
+ * <li>{@link String} and array of {@link String}s</li>
+ * <li>{@link UUID} and array of {@link UUID}s</li>
+ * <li>{@link Date} and array of {@link Date}s</li>
+ * <li>{@link Timestamp} and array of {@link Timestamp}s</li>
+ * <li>Enums and array of enums</li>
+ * <li>
+ * Maps, collections and array of objects (but objects inside
+ * them will still be converted if they are portable)
+ * </li>
+ * </ul>
+ * <h1 class="header">Working With Maps and Collections</h1>
+ * All maps and collections in the portable objects are serialized automatically. When working
+ * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most
+ * adequate collection or map in either language. For example, {@link ArrayList} in Java will become
+ * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap}
+ * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary}
+ * in C#, etc.
+ * <h1 class="header">Building Portable Objects</h1>
+ * Ignite comes with {@link org.apache.ignite.binary.BinaryObjectBuilder} which allows to build portable objects dynamically:
+ * <pre name=code class=java>
+ * PortableBuilder builder = Ignition.ignite().binary().builder();
+ *
+ * builder.typeId("MyObject");
+ *
+ * builder.stringField("fieldA", "A");
+ * build.intField("fieldB", "B");
+ *
+ * PortableObject portableObj = builder.build();
+ * </pre>
+ * For the cases when class definition is present
+ * in the class path, it is also possible to populate a standard POJO and then
+ * convert it to portable format, like so:
+ * <pre name=code class=java>
+ * MyObject obj = new MyObject();
+ *
+ * obj.setFieldA("A");
+ * obj.setFieldB(123);
+ *
+ * PortableObject portableObj = Ignition.ignite().binary().toBinary(obj);
+ * </pre>
+ * NOTE: you don't need to convert typed objects to portable format before storing
+ * them in cache, Ignite will do that automatically.
+ * <h1 class="header">Portable Metadata</h1>
+ * Even though Ignite portable protocol only works with hash codes for type and field names
+ * to achieve better performance, Ignite provides metadata for all portable types which
+ * can be queried ar runtime via any of the {@link IgniteBinary#metadata(Class)}
+ * methods. Having metadata also allows for proper formatting of {@code PortableObject#toString()} method,
+ * even when portable objects are kept in binary format only, which may be necessary for audit reasons.
+ * <h1 class="header">Dynamic Structure Changes</h1>
+ * Since objects are always cached in the portable binary format, server does not need to
+ * be aware of the class definitions. Moreover, if class definitions are not present or not
+ * used on the server, then clients can continuously change the structure of the portable
+ * objects without having to restart the cluster. For example, if one client stores a
+ * certain class with fields A and B, and another client stores the same class with
+ * fields B and C, then the server-side portable object will have the fields A, B, and C.
+ * As the structure of a portable object changes, the new fields become available for SQL queries
+ * automatically.
+ * <h1 class="header">Configuration</h1>
+ * By default all your objects are considered as binary and no specific configuration is needed.
+ * However, in some cases, like when an object is used by both Java and .Net, you may need to specify portable objects
+ * explicitly by calling {@link PortableMarshaller#setClassNames(Collection)}.
+ * The only requirement Ignite imposes is that your object has an empty
+ * constructor. Note, that since server side does not have to know the class definition,
+ * you only need to list portable objects in configuration on the client side. However, if you
+ * list them on the server side as well, then you get the ability to deserialize portable objects
+ * into concrete types on the server as well as on the client.
+ * <p>
+ * Here is an example of portable configuration (note that star (*) notation is supported):
+ * <pre name=code class=xml>
+ * ...
+ * <!-- Explicit portable objects configuration. -->
+ * <property name="marshaller">
+ * <bean class="org.apache.ignite.marshaller.portable.PortableMarshaller">
+ * <property name="classNames">
+ * <list>
+ * <value>my.package.for.portable.objects.*</value>
+ * <value>org.apache.ignite.examples.client.portable.Employee</value>
+ * </list>
+ * </property>
+ * </bean>
+ * </property>
+ * ...
+ * </pre>
+ * or from code:
+ * <pre name=code class=java>
+ * IgniteConfiguration cfg = new IgniteConfiguration();
+ *
+ * PortableMarshaller marsh = new PortableMarshaller();
+ *
+ * marsh.setClassNames(Arrays.asList(
+ * Employee.class.getName(),
+ * Address.class.getName())
+ * );
+ *
+ * cfg.setMarshaller(marsh);
+ * </pre>
+ * You can also specify class name for a portable object via {@link org.apache.ignite.binary.BinaryTypeConfiguration}.
+ * Do it in case if you need to override other configuration properties on per-type level, like
+ * ID-mapper, or serializer.
+ * <h1 class="header">Custom Affinity Keys</h1>
+ * Often you need to specify an alternate key (not the cache key) for affinity routing whenever
+ * storing objects in cache. For example, if you are caching {@code Employee} object with
+ * {@code Organization}, and want to colocate employees with organization they work for,
+ * so you can process them together, you need to specify an alternate affinity key.
+ * With portable objects you would have to do it as following:
+ * <pre name=code class=xml>
+ * <property name="marshaller">
+ * <bean class="org.gridgain.grid.marshaller.portable.PortableMarshaller">
+ * ...
+ * <property name="typeConfigurations">
+ * <list>
+ * <bean class="org.apache.ignite.portable.PortableTypeConfiguration">
+ * <property name="className" value="org.apache.ignite.examples.client.portable.EmployeeKey"/>
+ * <property name="affinityKeyFieldName" value="organizationId"/>
+ * </bean>
+ * </list>
+ * </property>
+ * ...
+ * </bean>
+ * </property>
+ * </pre>
+ * <h1 class="header">Serialization</h1>
+ * Serialization and deserialization works out-of-the-box in Ignite. However, you can provide your own custom
+ * serialization logic by optionally implementing {@link org.apache.ignite.binary.Binarylizable} interface, like so:
+ * <pre name=code class=java>
+ * public class Address implements PortableMarshalAware {
+ * private String street;
+ * private int zip;
+ *
+ * // Empty constructor required for portable deserialization.
+ * public Address() {}
+ *
+ * @Override public void writeBinary(PortableWriter writer) throws PortableException {
+ * writer.writeString("street", street);
+ * writer.writeInt("zip", zip);
+ * }
+ *
+ * @Override public void readBinary(PortableReader reader) throws PortableException {
+ * street = reader.readString("street");
+ * zip = reader.readInt("zip");
+ * }
+ * }
+ * </pre>
+ * Alternatively, if you cannot change class definitions, you can provide custom serialization
+ * logic in {@link org.apache.ignite.binary.BinarySerializer} either globally in {@link PortableMarshaller} or
+ * for a specific type via {@link org.apache.ignite.binary.BinaryTypeConfiguration} instance.
+ * <p>
+ * Similar to java serialization you can use {@code writeReplace()} and {@code readResolve()} methods.
+ * <ul>
+ * <li>
+ * {@code readResolve} is defined as follows: {@code ANY-ACCESS-MODIFIER Object readResolve()}.
+ * It may be used to replace the de-serialized object by another one of your choice.
+ * </li>
+ * <li>
+ * {@code writeReplace} is defined as follows: {@code ANY-ACCESS-MODIFIER Object writeReplace()}. This method
+ * allows the developer to provide a replacement object that will be serialized instead of the original one.
+ * </li>
+ * </ul>
+ *
+ * <h1 class="header">Custom ID Mappers</h1>
+ * Ignite implementation uses name hash codes to generate IDs for class names or field names
+ * internally. However, in cases when you want to provide your own ID mapping schema,
+ * you can provide your own {@link org.apache.ignite.binary.BinaryTypeIdMapper} implementation.
+ * <p>
+ * ID-mapper may be provided either globally in {@link PortableMarshaller},
+ * or for a specific type via {@link org.apache.ignite.binary.BinaryTypeConfiguration} instance.
+ * <h1 class="header">Query Indexing</h1>
+ * Portable objects can be indexed for querying by specifying index fields in
+ * {@link org.apache.ignite.cache.CacheTypeMetadata} inside of specific
+ * {@link org.apache.ignite.configuration.CacheConfiguration} instance,
+ * like so:
+ * <pre name=code class=xml>
+ * ...
+ * <bean class="org.apache.ignite.cache.CacheConfiguration">
+ * ...
+ * <property name="typeMetadata">
+ * <list>
+ * <bean class="CacheTypeMetadata">
+ * <property name="type" value="Employee"/>
+ *
+ * <!-- Fields to index in ascending order. -->
+ * <property name="ascendingFields">
+ * <map>
+ * <entry key="name" value="java.lang.String"/>
+ *
+ * <!-- Nested portable objects can also be indexed. -->
+ * <entry key="address.zip" value="java.lang.Integer"/>
+ * </map>
+ * </property>
+ * </bean>
+ * </list>
+ * </property>
+ * </bean>
+ * </pre>
+ */
+public interface IgniteBinary {
+ /**
+ * Gets type ID for given type name.
+ *
+ * @param typeName Type name.
+ * @return Type ID.
+ */
+ public int typeId(String typeName);
+
+ /**
+ * Converts provided object to instance of {@link org.apache.ignite.binary.BinaryObject}.
+ *
+ * @param obj Object to convert.
+ * @return Converted object.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ public <T> T toBinary(@Nullable Object obj) throws BinaryObjectException;
+
+ /**
+ * Creates new portable builder.
+ *
+ * @param typeId ID of the type.
+ * @return Newly portable builder.
+ */
+ public BinaryObjectBuilder builder(int typeId) throws BinaryObjectException;
+
+ /**
+ * Creates new portable builder.
+ *
+ * @param typeName Type name.
+ * @return Newly portable builder.
+ */
+ public BinaryObjectBuilder builder(String typeName) throws BinaryObjectException;
+
+ /**
+ * Creates portable builder initialized by existing portable object.
+ *
+ * @param portableObj Portable object to initialize builder.
+ * @return Portable builder.
+ */
+ public BinaryObjectBuilder builder(BinaryObject portableObj) throws BinaryObjectException;
+
+ /**
+ * Gets metadata for provided class.
+ *
+ * @param cls Class.
+ * @return Metadata.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ public BinaryType metadata(Class<?> cls) throws BinaryObjectException;
+
+ /**
+ * Gets metadata for provided class name.
+ *
+ * @param typeName Type name.
+ * @return Metadata.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ public BinaryType metadata(String typeName) throws BinaryObjectException;
+
+ /**
+ * Gets metadata for provided type ID.
+ *
+ * @param typeId Type ID.
+ * @return Metadata.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ public BinaryType metadata(int typeId) throws BinaryObjectException;
+
+ /**
+ * Gets metadata for all known types.
+ *
+ * @return Metadata.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ public Collection<BinaryType> metadata() throws BinaryObjectException;
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
index e0f9f55..099a3f4 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -132,9 +132,9 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
public IgniteCache<K, V> withNoRetries();
/**
- * Returns cache that will operate with portable objects.
+ * Returns cache that will operate with binary objects.
* <p>
- * Cache returned by this method will not be forced to deserialize portable objects,
+ * Cache returned by this method will not be forced to deserialize binary objects,
* so keys and values will be returned from cache API methods without changes. Therefore,
* signature of the cache can contain only following types:
* <ul>
@@ -153,21 +153,21 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
* </ul>
* <p>
* For example, if you use {@link Integer} as a key and {@code Value} class as a value
- * (which will be stored in portable format), you should acquire following projection
+ * (which will be stored in binary format), you should acquire following projection
* to avoid deserialization:
* <pre>
- * IgniteCache<Integer, PortableObject> prj = cache.withKeepPortable();
+ * IgniteCache<Integer, BinaryObject> prj = cache.withKeepBinary();
*
* // Value is not deserialized and returned in portable format.
- * PortableObject po = prj.get(1);
+ * BinaryObject po = prj.get(1);
* </pre>
* <p>
- * Note that this method makes sense only if cache is working in portable mode ({@link PortableMarshaller} is used).
+ * Note that this method makes sense only if cache is working in binary mode ({@link PortableMarshaller} is used).
* If not, this method is no-op and will return current cache.
*
* @return New cache instance for portable objects.
*/
- public <K1, V1> IgniteCache<K1, V1> withKeepPortable();
+ public <K1, V1> IgniteCache<K1, V1> withKeepBinary();
/**
* Executes {@link #localLoadCache(IgniteBiPredicate, Object...)} on all cache nodes.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java b/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
index 79bd163..20d0057 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteDataStreamer.java
@@ -146,6 +146,22 @@ public interface IgniteDataStreamer<K, V> extends AutoCloseable {
public void skipStore(boolean skipStore);
/**
+ * Gets flag indicating that objects should be kept in binary format when passed to the stream receiver.
+ * Default is {@code false}.
+ *
+ * @return Skip store flag.
+ */
+ public boolean keepBinary();
+
+ /**
+ * Sets flag indicating that objects should be kept in binary format when passes to the steam receiver.
+ * Default is {@code false}.
+ *
+ * @param keepBinary Keep binary flag.
+ */
+ public void keepBinary(boolean keepBinary);
+
+ /**
* Gets size of per node key-value pairs buffer.
*
* @return Per node buffer size.
[20/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
new file mode 100644
index 0000000..c1d9e6e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
@@ -0,0 +1,1915 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryTypeIdMapper;
+import org.apache.ignite.internal.portable.streams.PortableHeapOutputStream;
+import org.apache.ignite.internal.portable.streams.PortableOutputStream;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryWriter;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.lang.reflect.InvocationTargetException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.IdentityHashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CLASS;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.COL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLAGS_POS;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP_ENTRY;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.OPTM_MARSH;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.PORTABLE_OBJ;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.SCHEMA_ID_POS;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TOTAL_LEN_POS;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID_ARR;
+
+/**
+ * Portable writer implementation.
+ */
+public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, ObjectOutput {
+ /** Length: integer. */
+ private static final int LEN_INT = 4;
+
+ /** */
+ private static final int INIT_CAP = 1024;
+
+ /** FNV1 hash offset basis. */
+ private static final int FNV1_OFFSET_BASIS = 0x811C9DC5;
+
+ /** FNV1 hash prime. */
+ private static final int FNV1_PRIME = 0x01000193;
+
+ /** Maximum offset which fits in 1 byte. */
+ private static final int MAX_OFFSET_1 = 1 << 8;
+
+ /** Maximum offset which fits in 2 bytes. */
+ private static final int MAX_OFFSET_2 = 1 << 16;
+
+ /** Thread-local schema. */
+ private static final ThreadLocal<SchemaHolder> SCHEMA = new ThreadLocal<>();
+
+ /** */
+ private final PortableContext ctx;
+
+ /** */
+ private final int start;
+
+ /** */
+ private Class<?> cls;
+
+ /** */
+ private int typeId;
+
+ /** Raw offset position. */
+ private int rawOffPos;
+
+ /** */
+ private boolean metaEnabled;
+
+ /** */
+ private int metaHashSum;
+
+ /** Handles. */
+ private Map<Object, Integer> handles;
+
+ /** Output stream. */
+ private PortableOutputStream out;
+
+ /** Schema. */
+ private SchemaHolder schema;
+
+ /** Schema ID. */
+ private int schemaId;
+
+ /** Amount of written fields. */
+ private int fieldCnt;
+
+ /** ID mapper. */
+ private BinaryTypeIdMapper idMapper;
+
+ /**
+ * @param ctx Context.
+ */
+ BinaryWriterExImpl(PortableContext ctx) {
+ this(ctx, new PortableHeapOutputStream(INIT_CAP));
+ }
+
+ /**
+ * @param ctx Context.
+ * @param out Output stream.
+ */
+ BinaryWriterExImpl(PortableContext ctx, PortableOutputStream out) {
+ this(ctx, out, new IdentityHashMap<Object, Integer>());
+ }
+
+ /**
+ * @param ctx Context.
+ * @param out Output stream.
+ * @param handles Handles.
+ */
+ private BinaryWriterExImpl(PortableContext ctx, PortableOutputStream out, Map<Object, Integer> handles) {
+ this.ctx = ctx;
+ this.out = out;
+ this.handles = handles;
+
+ start = out.position();
+ }
+
+ /**
+ * @param ctx Context.
+ * @param typeId Type ID.
+ */
+ public BinaryWriterExImpl(PortableContext ctx, int typeId, boolean metaEnabled) {
+ this(ctx);
+
+ this.typeId = typeId;
+ this.metaEnabled = metaEnabled;
+ }
+
+ /**
+ * Close the writer releasing resources if necessary.
+ */
+ @Override public void close() {
+ out.close();
+ }
+
+ /**
+ * @return Meta data hash sum or {@code null} if meta data is disabled.
+ */
+ @Nullable Integer metaDataHashSum() {
+ return metaEnabled ? metaHashSum : null;
+ }
+
+ /**
+ * @param obj Object.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void marshal(Object obj) throws BinaryObjectException {
+ marshal(obj, true);
+ }
+
+ /**
+ * @param obj Object.
+ * @param enableReplace Object replacing enabled flag.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void marshal(Object obj, boolean enableReplace) throws BinaryObjectException {
+ assert obj != null;
+
+ cls = obj.getClass();
+
+ PortableClassDescriptor desc = ctx.descriptorForClass(cls);
+
+ if (desc == null)
+ throw new BinaryObjectException("Object is not portable: [class=" + cls + ']');
+
+ if (desc.excluded()) {
+ doWriteByte(NULL);
+ return;
+ }
+
+ if (desc.useOptimizedMarshaller()) {
+ writeByte(OPTM_MARSH);
+
+ try {
+ byte[] arr = ctx.optimizedMarsh().marshal(obj);
+
+ writeInt(arr.length);
+
+ write(arr);
+ }
+ catch (IgniteCheckedException e) {
+ throw new BinaryObjectException("Failed to marshal object with optimized marshaller: " + obj, e);
+ }
+
+ return;
+ }
+
+ if (enableReplace && desc.getWriteReplaceMethod() != null) {
+ Object replacedObj;
+
+ try {
+ replacedObj = desc.getWriteReplaceMethod().invoke(obj);
+ }
+ catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ catch (InvocationTargetException e) {
+ if (e.getTargetException() instanceof BinaryObjectException)
+ throw (BinaryObjectException)e.getTargetException();
+
+ throw new BinaryObjectException("Failed to execute writeReplace() method on " + obj, e);
+ }
+
+ if (replacedObj == null) {
+ doWriteByte(NULL);
+ return;
+ }
+
+ marshal(replacedObj, false);
+
+ return;
+ }
+
+ typeId = desc.typeId();
+
+ metaEnabled = ctx.isMetaDataEnabled(typeId);
+
+ desc.write(obj, this);
+ }
+
+ /**
+ * @param obj Object.
+ * @return Handle.
+ */
+ int handle(Object obj) {
+ assert obj != null;
+
+ Integer h = handles.get(obj);
+
+ if (h != null)
+ return out.position() - h;
+ else {
+ handles.put(obj, out.position());
+
+ return -1;
+ }
+ }
+
+ /**
+ * @return Array.
+ */
+ public byte[] array() {
+ return out.arrayCopy();
+ }
+
+ /**
+ * @return Stream current position.
+ */
+ int position() {
+ return out.position();
+ }
+
+ /**
+ * Sets new position.
+ *
+ * @param pos Position.
+ */
+ void position(int pos) {
+ out.position(pos);
+ }
+
+ /**
+ * @param bytes Number of bytes to reserve.
+ * @return Offset.
+ */
+ public int reserve(int bytes) {
+ int pos = out.position();
+
+ out.position(pos + bytes);
+
+ return pos;
+ }
+
+ /**
+ * Perform post-write activity. This includes:
+ * - writing object length;
+ * - writing schema offset;
+ * - writing schema to the tail.
+ *
+ * @param userType User type flag.
+ */
+ public void postWrite(boolean userType) {
+ if (schema != null) {
+ // Write schema ID.
+ out.writeInt(start + SCHEMA_ID_POS, schemaId);
+
+ // Write schema offset.
+ out.writeInt(start + SCHEMA_OR_RAW_OFF_POS, out.position() - start);
+
+ // Write the schema.
+ int offsetByteCnt = schema.write(this, fieldCnt);
+
+ // Write raw offset if needed.
+ if (rawOffPos != 0)
+ out.writeInt(rawOffPos - start);
+
+ if (offsetByteCnt == PortableUtils.OFFSET_1) {
+ int flags = (userType ? PortableUtils.FLAG_USR_TYP : 0) | PortableUtils.FLAG_OFFSET_ONE_BYTE;
+
+ out.writeShort(start + FLAGS_POS, (short)flags);
+ }
+ else if (offsetByteCnt == PortableUtils.OFFSET_2) {
+ int flags = (userType ? PortableUtils.FLAG_USR_TYP : 0) | PortableUtils.FLAG_OFFSET_TWO_BYTES;
+
+ out.writeShort(start + FLAGS_POS, (short)flags);
+ }
+ }
+ else {
+ // Write raw-only flag is needed.
+ int flags = (userType ? PortableUtils.FLAG_USR_TYP : 0) | PortableUtils.FLAG_RAW_ONLY;
+
+ out.writeShort(start + FLAGS_POS, (short)flags);
+
+ // If there are no schema, we are free to write raw offset to schema offset.
+ out.writeInt(start + SCHEMA_OR_RAW_OFF_POS, (rawOffPos == 0 ? out.position() : rawOffPos) - start);
+ }
+
+ // 5. Write length.
+ out.writeInt(start + TOTAL_LEN_POS, out.position() - start);
+ }
+
+ /**
+ * Pop schema.
+ */
+ public void popSchema() {
+ if (schema != null) {
+ assert fieldCnt > 0;
+
+ schema.pop(fieldCnt);
+ }
+ }
+
+ /**
+ * @param val Byte array.
+ */
+ public void write(byte[] val) {
+ assert val != null;
+
+ out.writeByteArray(val);
+ }
+
+ /**
+ * @param val Byte array.
+ * @param off Offset.
+ * @param len Length.
+ */
+ public void write(byte[] val, int off, int len) {
+ assert val != null;
+
+ out.write(val, off, len);
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void doWriteByte(byte val) {
+ out.writeByte(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void doWriteShort(short val) {
+ out.writeShort(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void doWriteInt(int val) {
+ out.writeInt(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void doWriteLong(long val) {
+ out.writeLong(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void doWriteFloat(float val) {
+ out.writeFloat(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void doWriteDouble(double val) {
+ out.writeDouble(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void doWriteChar(char val) {
+ out.writeChar(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void doWriteBoolean(boolean val) {
+ out.writeBoolean(val);
+ }
+
+ /**
+ * @param val String value.
+ */
+ public void doWriteDecimal(@Nullable BigDecimal val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(DECIMAL);
+
+ BigInteger intVal = val.unscaledValue();
+
+ if (intVal.signum() == -1) {
+ intVal = intVal.negate();
+
+ out.writeInt(val.scale() | 0x80000000);
+ }
+ else
+ out.writeInt(val.scale());
+
+ byte[] vals = intVal.toByteArray();
+
+ out.writeInt(vals.length);
+ out.writeByteArray(vals);
+ }
+ }
+
+ /**
+ * @param val String value.
+ */
+ public void doWriteString(@Nullable String val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(STRING);
+
+ if (ctx.isConvertString()) {
+ doWriteBoolean(true);
+
+ byte[] strArr = val.getBytes(UTF_8);
+
+ doWriteInt(strArr.length);
+
+ out.writeByteArray(strArr);
+ }
+ else {
+ doWriteBoolean(false);
+
+ char[] strArr = val.toCharArray();
+
+ doWriteInt(strArr.length);
+
+ out.writeCharArray(strArr);
+ }
+ }
+ }
+
+ /**
+ * @param uuid UUID.
+ */
+ public void doWriteUuid(@Nullable UUID uuid) {
+ if (uuid == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(UUID);
+ doWriteLong(uuid.getMostSignificantBits());
+ doWriteLong(uuid.getLeastSignificantBits());
+ }
+ }
+
+ /**
+ * @param date Date.
+ */
+ public void doWriteDate(@Nullable Date date) {
+ if (date == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(DATE);
+ doWriteLong(date.getTime());
+ }
+ }
+
+ /**
+ * @param ts Timestamp.
+ */
+ public void doWriteTimestamp(@Nullable Timestamp ts) {
+ if (ts== null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(TIMESTAMP);
+ doWriteLong(ts.getTime());
+ doWriteInt(ts.getNanos() % 1000000);
+ }
+ }
+
+ /**
+ * Write object.
+ *
+ * @param obj Object.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ public void doWriteObject(@Nullable Object obj) throws BinaryObjectException {
+ if (obj == null)
+ doWriteByte(NULL);
+ else {
+ BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, handles);
+
+ writer.marshal(obj);
+ }
+ }
+
+ /**
+ * @param val Byte array.
+ */
+ void doWriteByteArray(@Nullable byte[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(BYTE_ARR);
+ doWriteInt(val.length);
+
+ out.writeByteArray(val);
+ }
+ }
+
+ /**
+ * @param val Short array.
+ */
+ void doWriteShortArray(@Nullable short[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(SHORT_ARR);
+ doWriteInt(val.length);
+
+ out.writeShortArray(val);
+ }
+ }
+
+ /**
+ * @param val Integer array.
+ */
+ void doWriteIntArray(@Nullable int[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(INT_ARR);
+ doWriteInt(val.length);
+
+ out.writeIntArray(val);
+ }
+ }
+
+ /**
+ * @param val Long array.
+ */
+ void doWriteLongArray(@Nullable long[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(LONG_ARR);
+ doWriteInt(val.length);
+
+ out.writeLongArray(val);
+ }
+ }
+
+ /**
+ * @param val Float array.
+ */
+ void doWriteFloatArray(@Nullable float[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(FLOAT_ARR);
+ doWriteInt(val.length);
+
+ out.writeFloatArray(val);
+ }
+ }
+
+ /**
+ * @param val Double array.
+ */
+ void doWriteDoubleArray(@Nullable double[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(DOUBLE_ARR);
+ doWriteInt(val.length);
+
+ out.writeDoubleArray(val);
+ }
+ }
+
+ /**
+ * @param val Char array.
+ */
+ void doWriteCharArray(@Nullable char[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(CHAR_ARR);
+ doWriteInt(val.length);
+
+ out.writeCharArray(val);
+ }
+ }
+
+ /**
+ * @param val Boolean array.
+ */
+ void doWriteBooleanArray(@Nullable boolean[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(BOOLEAN_ARR);
+ doWriteInt(val.length);
+
+ out.writeBooleanArray(val);
+ }
+ }
+
+ /**
+ * @param val Array of strings.
+ */
+ void doWriteDecimalArray(@Nullable BigDecimal[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(DECIMAL_ARR);
+ doWriteInt(val.length);
+
+ for (BigDecimal str : val)
+ doWriteDecimal(str);
+ }
+ }
+
+ /**
+ * @param val Array of strings.
+ */
+ void doWriteStringArray(@Nullable String[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(STRING_ARR);
+ doWriteInt(val.length);
+
+ for (String str : val)
+ doWriteString(str);
+ }
+ }
+
+ /**
+ * @param val Array of UUIDs.
+ */
+ void doWriteUuidArray(@Nullable UUID[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(UUID_ARR);
+ doWriteInt(val.length);
+
+ for (UUID uuid : val)
+ doWriteUuid(uuid);
+ }
+ }
+
+ /**
+ * @param val Array of dates.
+ */
+ void doWriteDateArray(@Nullable Date[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(DATE_ARR);
+ doWriteInt(val.length);
+
+ for (Date date : val)
+ doWriteDate(date);
+ }
+ }
+
+ /**
+ * @param val Array of timestamps.
+ */
+ void doWriteTimestampArray(@Nullable Timestamp[] val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ doWriteByte(TIMESTAMP_ARR);
+ doWriteInt(val.length);
+
+ for (Timestamp ts : val)
+ doWriteTimestamp(ts);
+ }
+ }
+
+ /**
+ * @param val Array of objects.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void doWriteObjectArray(@Nullable Object[] val) throws BinaryObjectException {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(val))
+ return;
+
+ PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType());
+
+ doWriteByte(OBJ_ARR);
+
+ if (desc.registered())
+ doWriteInt(desc.typeId());
+ else {
+ doWriteInt(UNREGISTERED_TYPE_ID);
+ doWriteString(val.getClass().getComponentType().getName());
+ }
+
+ doWriteInt(val.length);
+
+ for (Object obj : val)
+ doWriteObject(obj);
+ }
+ }
+
+ /**
+ * @param col Collection.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void doWriteCollection(@Nullable Collection<?> col) throws BinaryObjectException {
+ if (col == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(col))
+ return;
+
+ doWriteByte(COL);
+ doWriteInt(col.size());
+ doWriteByte(ctx.collectionType(col.getClass()));
+
+ for (Object obj : col)
+ doWriteObject(obj);
+ }
+ }
+
+ /**
+ * @param map Map.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void doWriteMap(@Nullable Map<?, ?> map) throws BinaryObjectException {
+ if (map == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(map))
+ return;
+
+ doWriteByte(MAP);
+ doWriteInt(map.size());
+ doWriteByte(ctx.mapType(map.getClass()));
+
+ for (Map.Entry<?, ?> e : map.entrySet()) {
+ doWriteObject(e.getKey());
+ doWriteObject(e.getValue());
+ }
+ }
+ }
+
+ /**
+ * @param e Map entry.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void doWriteMapEntry(@Nullable Map.Entry<?, ?> e) throws BinaryObjectException {
+ if (e == null)
+ doWriteByte(NULL);
+ else {
+ if (tryWriteAsHandle(e))
+ return;
+
+ doWriteByte(MAP_ENTRY);
+ doWriteObject(e.getKey());
+ doWriteObject(e.getValue());
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ void doWriteEnum(@Nullable Enum<?> val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass());
+
+ doWriteByte(ENUM);
+
+ if (desc.registered())
+ doWriteInt(desc.typeId());
+ else {
+ doWriteInt(UNREGISTERED_TYPE_ID);
+ doWriteString(val.getClass().getName());
+ }
+
+ doWriteInt(val.ordinal());
+ }
+ }
+
+ /**
+ * @param val Array.
+ */
+ void doWriteEnumArray(@Nullable Object[] val) {
+ assert val == null || val.getClass().getComponentType().isEnum();
+
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType());
+ doWriteByte(ENUM_ARR);
+
+ if (desc.registered())
+ doWriteInt(desc.typeId());
+ else {
+ doWriteInt(UNREGISTERED_TYPE_ID);
+ doWriteString(val.getClass().getComponentType().getName());
+ }
+
+ doWriteInt(val.length);
+
+ // TODO: Denis: Redundant data for each element of the array.
+ for (Object o : val)
+ doWriteEnum((Enum<?>)o);
+ }
+ }
+
+ /**
+ * @param val Class.
+ */
+ void doWriteClass(@Nullable Class val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ PortableClassDescriptor desc = ctx.descriptorForClass(val);
+
+ doWriteByte(CLASS);
+
+ if (desc.registered())
+ doWriteInt(desc.typeId());
+ else {
+ doWriteInt(UNREGISTERED_TYPE_ID);
+ doWriteString(val.getClass().getName());
+ }
+ }
+ }
+
+ /**
+ * @param po Portable object.
+ */
+ public void doWritePortableObject(@Nullable BinaryObjectImpl po) {
+ if (po == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(PORTABLE_OBJ);
+
+ byte[] poArr = po.array();
+
+ doWriteInt(poArr.length);
+
+ out.writeByteArray(poArr);
+
+ doWriteInt(po.start());
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeByteField(@Nullable Byte val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(BYTE);
+ doWriteByte(val);
+ }
+ }
+
+ /**
+ * @param val Class.
+ */
+ void writeClassField(@Nullable Class val) {
+ doWriteClass(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeShortField(@Nullable Short val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(SHORT);
+ doWriteShort(val);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeIntField(@Nullable Integer val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(INT);
+ doWriteInt(val);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeLongField(@Nullable Long val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(LONG);
+ doWriteLong(val);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeFloatField(@Nullable Float val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(FLOAT);
+ doWriteFloat(val);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeDoubleField(@Nullable Double val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(DOUBLE);
+ doWriteDouble(val);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeCharField(@Nullable Character val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(CHAR);
+ doWriteChar(val);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeBooleanField(@Nullable Boolean val) {
+ if (val == null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(BOOLEAN);
+ doWriteBoolean(val);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeDecimalField(@Nullable BigDecimal val) {
+ doWriteDecimal(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeStringField(@Nullable String val) {
+ doWriteString(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeUuidField(@Nullable UUID val) {
+ doWriteUuid(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeDateField(@Nullable Date val) {
+ doWriteDate(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeTimestampField(@Nullable Timestamp val) {
+ doWriteTimestamp(val);
+ }
+
+ /**
+ * @param obj Object.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void writeObjectField(@Nullable Object obj) throws BinaryObjectException {
+ doWriteObject(obj);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeByteArrayField(@Nullable byte[] val) {
+ doWriteByteArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeShortArrayField(@Nullable short[] val) {
+ doWriteShortArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeIntArrayField(@Nullable int[] val) {
+ doWriteIntArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeLongArrayField(@Nullable long[] val) {
+ doWriteLongArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeFloatArrayField(@Nullable float[] val) {
+ doWriteFloatArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeDoubleArrayField(@Nullable double[] val) {
+ doWriteDoubleArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeCharArrayField(@Nullable char[] val) {
+ doWriteCharArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeBooleanArrayField(@Nullable boolean[] val) {
+ doWriteBooleanArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeDecimalArrayField(@Nullable BigDecimal[] val) {
+ doWriteDecimalArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeStringArrayField(@Nullable String[] val) {
+ doWriteStringArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeUuidArrayField(@Nullable UUID[] val) {
+ doWriteUuidArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeDateArrayField(@Nullable Date[] val) {
+ doWriteDateArray(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeTimestampArrayField(@Nullable Timestamp[] val) {
+ doWriteTimestampArray(val);
+ }
+
+ /**
+ * @param val Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void writeObjectArrayField(@Nullable Object[] val) throws BinaryObjectException {
+ doWriteObjectArray(val);
+ }
+
+ /**
+ * @param col Collection.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void writeCollectionField(@Nullable Collection<?> col) throws BinaryObjectException {
+ doWriteCollection(col);
+ }
+
+ /**
+ * @param map Map.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void writeMapField(@Nullable Map<?, ?> map) throws BinaryObjectException {
+ doWriteMap(map);
+ }
+
+ /**
+ * @param e Map entry.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void writeMapEntryField(@Nullable Map.Entry<?, ?> e) throws BinaryObjectException {
+ doWriteMapEntry(e);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeEnumField(@Nullable Enum<?> val) {
+ doWriteEnum(val);
+ }
+
+ /**
+ * @param val Value.
+ */
+ void writeEnumArrayField(@Nullable Object[] val) {
+ doWriteEnumArray(val);
+ }
+
+ /**
+ * @param po Portable object.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ void writePortableObjectField(@Nullable BinaryObjectImpl po) throws BinaryObjectException {
+ doWritePortableObject(po);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeByte(String fieldName, byte val) throws BinaryObjectException {
+ writeFieldId(fieldName, BYTE);
+ writeByteField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeByte(byte val) throws BinaryObjectException {
+ doWriteByte(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeShort(String fieldName, short val) throws BinaryObjectException {
+ writeFieldId(fieldName, SHORT);
+ writeShortField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeShort(short val) throws BinaryObjectException {
+ doWriteShort(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeInt(String fieldName, int val) throws BinaryObjectException {
+ writeFieldId(fieldName, INT);
+ writeIntField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeInt(int val) throws BinaryObjectException {
+ doWriteInt(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeLong(String fieldName, long val) throws BinaryObjectException {
+ writeFieldId(fieldName, LONG);
+ writeLongField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeLong(long val) throws BinaryObjectException {
+ doWriteLong(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeFloat(String fieldName, float val) throws BinaryObjectException {
+ writeFieldId(fieldName, FLOAT);
+ writeFloatField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeFloat(float val) throws BinaryObjectException {
+ doWriteFloat(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDouble(String fieldName, double val) throws BinaryObjectException {
+ writeFieldId(fieldName, DOUBLE);
+ writeDoubleField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDouble(double val) throws BinaryObjectException {
+ doWriteDouble(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeChar(String fieldName, char val) throws BinaryObjectException {
+ writeFieldId(fieldName, CHAR);
+ writeCharField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeChar(char val) throws BinaryObjectException {
+ doWriteChar(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBoolean(String fieldName, boolean val) throws BinaryObjectException {
+ writeFieldId(fieldName, BOOLEAN);
+ writeBooleanField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBoolean(boolean val) throws BinaryObjectException {
+ doWriteBoolean(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws BinaryObjectException {
+ writeFieldId(fieldName, DECIMAL);
+ writeDecimalField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDecimal(@Nullable BigDecimal val) throws BinaryObjectException {
+ doWriteDecimal(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeString(String fieldName, @Nullable String val) throws BinaryObjectException {
+ writeFieldId(fieldName, STRING);
+ writeStringField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeString(@Nullable String val) throws BinaryObjectException {
+ doWriteString(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeUuid(String fieldName, @Nullable UUID val) throws BinaryObjectException {
+ writeFieldId(fieldName, UUID);
+ writeUuidField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeUuid(@Nullable UUID val) throws BinaryObjectException {
+ doWriteUuid(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDate(String fieldName, @Nullable Date val) throws BinaryObjectException {
+ writeFieldId(fieldName, DATE);
+ writeDateField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDate(@Nullable Date val) throws BinaryObjectException {
+ doWriteDate(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws BinaryObjectException {
+ writeFieldId(fieldName, TIMESTAMP);
+ writeTimestampField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeTimestamp(@Nullable Timestamp val) throws BinaryObjectException {
+ doWriteTimestamp(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeObject(String fieldName, @Nullable Object obj) throws BinaryObjectException {
+ writeFieldId(fieldName, OBJ);
+ writeObjectField(obj);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeObject(@Nullable Object obj) throws BinaryObjectException {
+ doWriteObject(obj);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeObjectDetached(@Nullable Object obj) throws BinaryObjectException {
+ if (obj == null)
+ doWriteByte(NULL);
+ else {
+ BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, new IdentityHashMap<Object, Integer>());
+
+ writer.marshal(obj);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeByteArray(String fieldName, @Nullable byte[] val) throws BinaryObjectException {
+ writeFieldId(fieldName, BYTE_ARR);
+ writeByteArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeByteArray(@Nullable byte[] val) throws BinaryObjectException {
+ doWriteByteArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeShortArray(String fieldName, @Nullable short[] val) throws BinaryObjectException {
+ writeFieldId(fieldName, SHORT_ARR);
+ writeShortArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeShortArray(@Nullable short[] val) throws BinaryObjectException {
+ doWriteShortArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeIntArray(String fieldName, @Nullable int[] val) throws BinaryObjectException {
+ writeFieldId(fieldName, INT_ARR);
+ writeIntArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeIntArray(@Nullable int[] val) throws BinaryObjectException {
+ doWriteIntArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeLongArray(String fieldName, @Nullable long[] val) throws BinaryObjectException {
+ writeFieldId(fieldName, LONG_ARR);
+ writeLongArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeLongArray(@Nullable long[] val) throws BinaryObjectException {
+ doWriteLongArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeFloatArray(String fieldName, @Nullable float[] val) throws BinaryObjectException {
+ writeFieldId(fieldName, FLOAT_ARR);
+ writeFloatArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeFloatArray(@Nullable float[] val) throws BinaryObjectException {
+ doWriteFloatArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDoubleArray(String fieldName, @Nullable double[] val)
+ throws BinaryObjectException {
+ writeFieldId(fieldName, DOUBLE_ARR);
+ writeDoubleArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDoubleArray(@Nullable double[] val) throws BinaryObjectException {
+ doWriteDoubleArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeCharArray(String fieldName, @Nullable char[] val) throws BinaryObjectException {
+ writeFieldId(fieldName, CHAR_ARR);
+ writeCharArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeCharArray(@Nullable char[] val) throws BinaryObjectException {
+ doWriteCharArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBooleanArray(String fieldName, @Nullable boolean[] val)
+ throws BinaryObjectException {
+ writeFieldId(fieldName, BOOLEAN_ARR);
+ writeBooleanArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBooleanArray(@Nullable boolean[] val) throws BinaryObjectException {
+ doWriteBooleanArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val)
+ throws BinaryObjectException {
+ writeFieldId(fieldName, DECIMAL_ARR);
+ writeDecimalArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDecimalArray(@Nullable BigDecimal[] val) throws BinaryObjectException {
+ doWriteDecimalArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeStringArray(String fieldName, @Nullable String[] val)
+ throws BinaryObjectException {
+ writeFieldId(fieldName, STRING_ARR);
+ writeStringArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeStringArray(@Nullable String[] val) throws BinaryObjectException {
+ doWriteStringArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws BinaryObjectException {
+ writeFieldId(fieldName, UUID_ARR);
+ writeUuidArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeUuidArray(@Nullable UUID[] val) throws BinaryObjectException {
+ doWriteUuidArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDateArray(String fieldName, @Nullable Date[] val) throws BinaryObjectException {
+ writeFieldId(fieldName, DATE_ARR);
+ writeDateArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeDateArray(@Nullable Date[] val) throws BinaryObjectException {
+ doWriteDateArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws BinaryObjectException {
+ writeFieldId(fieldName, TIMESTAMP_ARR);
+ writeTimestampArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeTimestampArray(@Nullable Timestamp[] val) throws BinaryObjectException {
+ doWriteTimestampArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeObjectArray(String fieldName, @Nullable Object[] val) throws BinaryObjectException {
+ writeFieldId(fieldName, OBJ_ARR);
+ writeObjectArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeObjectArray(@Nullable Object[] val) throws BinaryObjectException {
+ doWriteObjectArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> void writeCollection(String fieldName, @Nullable Collection<T> col)
+ throws BinaryObjectException {
+ writeFieldId(fieldName, COL);
+ writeCollectionField(col);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> void writeCollection(@Nullable Collection<T> col) throws BinaryObjectException {
+ doWriteCollection(col);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map)
+ throws BinaryObjectException {
+ writeFieldId(fieldName, MAP);
+ writeMapField(map);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <K, V> void writeMap(@Nullable Map<K, V> map) throws BinaryObjectException {
+ doWriteMap(map);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws BinaryObjectException {
+ writeFieldId(fieldName, ENUM);
+ writeEnumField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T extends Enum<?>> void writeEnum(T val) throws BinaryObjectException {
+ doWriteEnum(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws BinaryObjectException {
+ writeFieldId(fieldName, ENUM_ARR);
+ writeEnumArrayField(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T extends Enum<?>> void writeEnumArray(T[] val) throws BinaryObjectException {
+ doWriteEnumArray(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryRawWriter rawWriter() {
+ if (rawOffPos == 0)
+ rawOffPos = out.position();
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ @Override public PortableOutputStream out() {
+ return out;
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("NullableProblems")
+ @Override public void writeBytes(String s) throws IOException {
+ int len = s.length();
+
+ writeInt(len);
+
+ for (int i = 0; i < len; i++)
+ writeByte(s.charAt(i));
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("NullableProblems")
+ @Override public void writeChars(String s) throws IOException {
+ int len = s.length();
+
+ writeInt(len);
+
+ for (int i = 0; i < len; i++)
+ writeChar(s.charAt(i));
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("NullableProblems")
+ @Override public void writeUTF(String s) throws IOException {
+ writeString(s);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeByte(int v) throws IOException {
+ doWriteByte((byte) v);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeShort(int v) throws IOException {
+ doWriteShort((short) v);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeChar(int v) throws IOException {
+ doWriteChar((char) v);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(int b) throws IOException {
+ doWriteByte((byte) b);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void flush() throws IOException {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public int reserveInt() {
+ return reserve(LEN_INT);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeInt(int pos, int val) throws BinaryObjectException {
+ out.writeInt(pos, val);
+ }
+
+ /**
+ * @param fieldName Field name.
+ * @throws org.apache.ignite.binary.BinaryObjectException If fields are not allowed.
+ */
+ private void writeFieldId(String fieldName, byte fieldType) throws BinaryObjectException {
+ A.notNull(fieldName, "fieldName");
+
+ if (rawOffPos != 0)
+ throw new BinaryObjectException("Individual field can't be written after raw writer is acquired " +
+ "via rawWriter() method. Consider fixing serialization logic for class: " + cls.getName());
+
+ if (idMapper == null)
+ idMapper = ctx.userTypeIdMapper(typeId);
+
+ int id = idMapper.fieldId(typeId, fieldName);
+
+ writeFieldId(id);
+
+ if (metaEnabled)
+ metaHashSum = 31 * metaHashSum + (id + fieldType);
+ }
+
+ /**
+ * Write field ID.
+ * @param fieldId Field ID.
+ */
+ public void writeFieldId(int fieldId) {
+ int fieldOff = out.position() - start;
+
+ if (schema == null) {
+ schema = SCHEMA.get();
+
+ if (schema == null) {
+ schema = new SchemaHolder();
+
+ SCHEMA.set(schema);
+ }
+
+ // Initialize offset when the first field is written.
+ schemaId = FNV1_OFFSET_BASIS;
+ }
+
+ // Advance schema hash.
+ int schemaId0 = schemaId ^ (fieldId & 0xFF);
+ schemaId0 = schemaId0 * FNV1_PRIME;
+ schemaId0 = schemaId0 ^ ((fieldId >> 8) & 0xFF);
+ schemaId0 = schemaId0 * FNV1_PRIME;
+ schemaId0 = schemaId0 ^ ((fieldId >> 16) & 0xFF);
+ schemaId0 = schemaId0 * FNV1_PRIME;
+ schemaId0 = schemaId0 ^ ((fieldId >> 24) & 0xFF);
+ schemaId0 = schemaId0 * FNV1_PRIME;
+
+ schemaId = schemaId0;
+
+ schema.push(fieldId, fieldOff);
+
+ fieldCnt++;
+ }
+
+ /**
+ * Attempts to write the object as a handle.
+ *
+ * @param obj Object to write.
+ * @return {@code true} if the object has been written as a handle.
+ */
+ boolean tryWriteAsHandle(Object obj) {
+ int handle = handle(obj);
+
+ if (handle >= 0) {
+ doWriteByte(GridPortableMarshaller.HANDLE);
+ doWriteInt(handle);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Create new writer with same context.
+ *
+ * @param typeId type
+ * @return New writer.
+ */
+ public BinaryWriterExImpl newWriter(int typeId) {
+ BinaryWriterExImpl res = new BinaryWriterExImpl(ctx, out, handles);
+
+ res.typeId = typeId;
+
+ return res;
+ }
+
+ /**
+ * @return Portable context.
+ */
+ public PortableContext context() {
+ return ctx;
+ }
+
+ /**
+ * Schema holder.
+ */
+ private static class SchemaHolder {
+ /** Grow step. */
+ private static final int GROW_STEP = 64;
+
+ /** Maximum stable size. */
+ private static final int MAX_SIZE = 1024;
+
+ /** Data. */
+ private int[] data;
+
+ /** Index. */
+ private int idx;
+
+ /**
+ * Constructor.
+ */
+ public SchemaHolder() {
+ data = new int[GROW_STEP];
+ }
+
+ /**
+ * Push another frame.
+ *
+ * @param id Field ID.
+ * @param off Field offset.
+ */
+ public void push(int id, int off) {
+ if (idx == data.length) {
+ int[] data0 = new int[data.length + GROW_STEP];
+
+ System.arraycopy(data, 0, data0, 0, data.length);
+
+ data = data0;
+ }
+
+ data[idx] = id;
+ data[idx + 1] = off;
+
+ idx += 2;
+ }
+
+ /**
+ * Write collected frames and pop them.
+ *
+ * @param writer Writer.
+ * @param fieldCnt Count.
+ * @return Amount of bytes dedicated to
+ */
+ public int write(BinaryWriterExImpl writer, int fieldCnt) {
+ int startIdx = idx - fieldCnt * 2;
+
+ assert startIdx >= 0;
+
+ int lastOffset = data[idx - 1];
+
+ int res;
+
+ if (lastOffset < MAX_OFFSET_1) {
+ for (int idx0 = startIdx; idx0 < idx; ) {
+ writer.writeInt(data[idx0++]);
+ writer.writeByte((byte) data[idx0++]);
+ }
+
+ res = PortableUtils.OFFSET_1;
+ }
+ else if (lastOffset < MAX_OFFSET_2) {
+ for (int idx0 = startIdx; idx0 < idx; ) {
+ writer.writeInt(data[idx0++]);
+ writer.writeShort((short)data[idx0++]);
+ }
+
+ res = PortableUtils.OFFSET_2;
+ }
+ else {
+ for (int idx0 = startIdx; idx0 < idx; ) {
+ writer.writeInt(data[idx0++]);
+ writer.writeInt(data[idx0++]);
+ }
+
+ res = PortableUtils.OFFSET_4;
+ }
+
+ return res;
+ }
+
+ /**
+ * Pop current object's frame.
+ */
+ public void pop(int fieldCnt) {
+ idx = idx - fieldCnt * 2;
+
+ // Shrink data array if needed.
+ if (idx == 0 && data.length > MAX_SIZE)
+ data = new int[MAX_SIZE];
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
index 9afe2ee..056a7c7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
@@ -19,7 +19,7 @@ package org.apache.ignite.internal.portable;
import org.apache.ignite.internal.portable.streams.PortableInputStream;
import org.apache.ignite.internal.portable.streams.PortableOutputStream;
-import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.binary.BinaryObjectException;
import org.jetbrains.annotations.Nullable;
/**
@@ -232,13 +232,13 @@ public class GridPortableMarshaller {
/**
* @param obj Object to marshal.
* @return Byte array.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
- public byte[] marshal(@Nullable Object obj) throws PortableException {
+ public byte[] marshal(@Nullable Object obj) throws BinaryObjectException {
if (obj == null)
return new byte[] { NULL };
- try (PortableWriterExImpl writer = new PortableWriterExImpl(ctx)) {
+ try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) {
writer.marshal(obj);
return writer.array();
@@ -248,13 +248,13 @@ public class GridPortableMarshaller {
/**
* @param bytes Bytes array.
* @return Portable object.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
@SuppressWarnings("unchecked")
- @Nullable public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws PortableException {
+ @Nullable public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws BinaryObjectException {
assert bytes != null;
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx, bytes, 0, clsLdr);
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx, bytes, 0, clsLdr);
return (T)reader.unmarshal();
}
@@ -262,10 +262,10 @@ public class GridPortableMarshaller {
/**
* @param in Input stream.
* @return Portable object.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
@SuppressWarnings("unchecked")
- @Nullable public <T> T unmarshal(PortableInputStream in) throws PortableException {
+ @Nullable public <T> T unmarshal(PortableInputStream in) throws BinaryObjectException {
return (T)reader(in).unmarshal();
}
@@ -273,17 +273,17 @@ public class GridPortableMarshaller {
* @param arr Byte array.
* @param ldr Class loader.
* @return Deserialized object.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
@SuppressWarnings("unchecked")
- @Nullable public <T> T deserialize(byte[] arr, @Nullable ClassLoader ldr) throws PortableException {
+ @Nullable public <T> T deserialize(byte[] arr, @Nullable ClassLoader ldr) throws BinaryObjectException {
assert arr != null;
assert arr.length > 0;
if (arr[0] == NULL)
return null;
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx, arr, 0, ldr);
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx, arr, 0, ldr);
return (T)reader.deserialize();
}
@@ -294,8 +294,8 @@ public class GridPortableMarshaller {
* @param out Output stream.
* @return Writer.
*/
- public PortableWriterExImpl writer(PortableOutputStream out) {
- return new PortableWriterExImpl(ctx, out);
+ public BinaryWriterExImpl writer(PortableOutputStream out) {
+ return new BinaryWriterExImpl(ctx, out);
}
/**
@@ -304,9 +304,9 @@ public class GridPortableMarshaller {
* @param in Input stream.
* @return Reader.
*/
- public PortableReaderExImpl reader(PortableInputStream in) {
+ public BinaryReaderExImpl reader(PortableInputStream in) {
// TODO: IGNITE-1272 - Is class loader needed here?
- return new PortableReaderExImpl(ctx, in, in.position(), null);
+ return new BinaryReaderExImpl(ctx, in, in.position(), null);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
index aa72017..b95dc3d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
@@ -23,10 +23,6 @@ import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.MarshallerExclusions;
import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableIdMapper;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableSerializer;
import org.jetbrains.annotations.Nullable;
import java.io.Externalizable;
@@ -47,6 +43,10 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.UUID;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryTypeIdMapper;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinarySerializer;
import static java.lang.reflect.Modifier.isStatic;
import static java.lang.reflect.Modifier.isTransient;
@@ -62,10 +62,10 @@ public class PortableClassDescriptor {
private final Class<?> cls;
/** */
- private final PortableSerializer serializer;
+ private final BinarySerializer serializer;
/** ID mapper. */
- private final PortableIdMapper idMapper;
+ private final BinaryTypeIdMapper idMapper;
/** */
private final Mode mode;
@@ -118,7 +118,7 @@ public class PortableClassDescriptor {
* @param keepDeserialized Keep deserialized flag.
* @param registered Whether typeId has been successfully registered by MarshallerContext or not.
* @param predefined Whether the class is predefined or not.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
PortableClassDescriptor(
PortableContext ctx,
@@ -126,13 +126,13 @@ public class PortableClassDescriptor {
boolean userType,
int typeId,
String typeName,
- @Nullable PortableIdMapper idMapper,
- @Nullable PortableSerializer serializer,
+ @Nullable BinaryTypeIdMapper idMapper,
+ @Nullable BinarySerializer serializer,
boolean metaDataEnabled,
boolean keepDeserialized,
boolean registered,
boolean predefined
- ) throws PortableException {
+ ) throws BinaryObjectException {
assert ctx != null;
assert cls != null;
@@ -225,12 +225,12 @@ public class PortableClassDescriptor {
String name = f.getName();
if (!names.add(name))
- throw new PortableException("Duplicate field name: " + name);
+ throw new BinaryObjectException("Duplicate field name: " + name);
int fieldId = idMapper.fieldId(typeId, name);
if (!ids.add(fieldId))
- throw new PortableException("Duplicate field ID: " + name);
+ throw new BinaryObjectException("Duplicate field ID: " + name);
FieldInfo fieldInfo = new FieldInfo(f, fieldId);
@@ -246,7 +246,7 @@ public class PortableClassDescriptor {
default:
// Should never happen.
- throw new PortableException("Invalid mode: " + mode);
+ throw new BinaryObjectException("Invalid mode: " + mode);
}
if (mode == Mode.PORTABLE || mode == Mode.EXTERNALIZABLE || mode == Mode.OBJECT) {
@@ -316,7 +316,7 @@ public class PortableClassDescriptor {
*
* @return ID mapper.
*/
- public PortableIdMapper idMapper() {
+ public BinaryTypeIdMapper idMapper() {
return idMapper;
}
@@ -337,9 +337,9 @@ public class PortableClassDescriptor {
/**
* @param obj Object.
* @param writer Writer.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
- void write(Object obj, PortableWriterExImpl writer) throws PortableException {
+ void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
assert obj != null;
assert writer != null;
@@ -423,62 +423,62 @@ public class PortableClassDescriptor {
break;
case SHORT_ARR:
- writer.doWriteShortArray((short[]) obj);
+ writer.doWriteShortArray((short[])obj);
break;
case INT_ARR:
- writer.doWriteIntArray((int[]) obj);
+ writer.doWriteIntArray((int[])obj);
break;
case LONG_ARR:
- writer.doWriteLongArray((long[]) obj);
+ writer.doWriteLongArray((long[])obj);
break;
case FLOAT_ARR:
- writer.doWriteFloatArray((float[]) obj);
+ writer.doWriteFloatArray((float[])obj);
break;
case DOUBLE_ARR:
- writer.doWriteDoubleArray((double[]) obj);
+ writer.doWriteDoubleArray((double[])obj);
break;
case CHAR_ARR:
- writer.doWriteCharArray((char[]) obj);
+ writer.doWriteCharArray((char[])obj);
break;
case BOOLEAN_ARR:
- writer.doWriteBooleanArray((boolean[]) obj);
+ writer.doWriteBooleanArray((boolean[])obj);
break;
case DECIMAL_ARR:
- writer.doWriteDecimalArray((BigDecimal[]) obj);
+ writer.doWriteDecimalArray((BigDecimal[])obj);
break;
case STRING_ARR:
- writer.doWriteStringArray((String[]) obj);
+ writer.doWriteStringArray((String[])obj);
break;
case UUID_ARR:
- writer.doWriteUuidArray((UUID[]) obj);
+ writer.doWriteUuidArray((UUID[])obj);
break;
case DATE_ARR:
- writer.doWriteDateArray((Date[]) obj);
+ writer.doWriteDateArray((Date[])obj);
break;
case TIMESTAMP_ARR:
- writer.doWriteTimestampArray((Timestamp[]) obj);
+ writer.doWriteTimestampArray((Timestamp[])obj);
break;
@@ -518,7 +518,7 @@ public class PortableClassDescriptor {
break;
case PORTABLE_OBJ:
- writer.doWritePortableObject((PortableObjectImpl)obj);
+ writer.doWritePortableObject((BinaryObjectImpl)obj);
break;
@@ -526,9 +526,9 @@ public class PortableClassDescriptor {
if (writeHeader(obj, writer)) {
try {
if (serializer != null)
- serializer.writePortable(obj, writer);
+ serializer.writeBinary(obj, writer);
else
- ((PortableMarshalAware) obj).writePortable(writer);
+ ((Binarylizable)obj).writeBinary(writer);
writer.postWrite(userType);
}
@@ -536,14 +536,14 @@ public class PortableClassDescriptor {
writer.popSchema();
}
- if (obj.getClass() != PortableMetaDataImpl.class
+ if (obj.getClass() != BinaryMetaDataImpl.class
&& ctx.isMetaDataChanged(typeId, writer.metaDataHashSum())) {
- PortableMetaDataCollector metaCollector = new PortableMetaDataCollector(typeName);
+ BinaryMetaDataCollector metaCollector = new BinaryMetaDataCollector(typeName);
if (serializer != null)
- serializer.writePortable(obj, metaCollector);
+ serializer.writeBinary(obj, metaCollector);
else
- ((PortableMarshalAware)obj).writePortable(metaCollector);
+ ((Binarylizable)obj).writeBinary(metaCollector);
ctx.updateMetaData(typeId, typeName, metaCollector.meta());
}
@@ -561,7 +561,7 @@ public class PortableClassDescriptor {
writer.postWrite(userType);
}
catch (IOException e) {
- throw new PortableException("Failed to write Externalizable object: " + obj, e);
+ throw new BinaryObjectException("Failed to write Externalizable object: " + obj, e);
}
finally {
writer.popSchema();
@@ -593,9 +593,9 @@ public class PortableClassDescriptor {
/**
* @param reader Reader.
* @return Object.
- * @throws PortableException If failed.
+ * @throws org.apache.ignite.binary.BinaryObjectException If failed.
*/
- Object read(PortableReaderExImpl reader) throws PortableException {
+ Object read(BinaryReaderExImpl reader) throws BinaryObjectException {
assert reader != null;
Object res;
@@ -607,9 +607,9 @@ public class PortableClassDescriptor {
reader.setHandler(res);
if (serializer != null)
- serializer.readPortable(res, reader);
+ serializer.readBinary(res, reader);
else
- ((PortableMarshalAware)res).readPortable(reader);
+ ((Binarylizable)res).readBinary(reader);
break;
@@ -622,7 +622,7 @@ public class PortableClassDescriptor {
((Externalizable)res).readExternal(reader);
}
catch (IOException | ClassNotFoundException e) {
- throw new PortableException("Failed to read Externalizable object: " +
+ throw new BinaryObjectException("Failed to read Externalizable object: " +
res.getClass().getName(), e);
}
@@ -654,10 +654,10 @@ public class PortableClassDescriptor {
throw new RuntimeException(e);
}
catch (InvocationTargetException e) {
- if (e.getTargetException() instanceof PortableException)
- throw (PortableException)e.getTargetException();
+ if (e.getTargetException() instanceof BinaryObjectException)
+ throw (BinaryObjectException)e.getTargetException();
- throw new PortableException("Failed to execute readResolve() method on " + res, e);
+ throw new BinaryObjectException("Failed to execute readResolve() method on " + res, e);
}
}
@@ -669,7 +669,7 @@ public class PortableClassDescriptor {
* @param writer Writer.
* @return Whether further write is needed.
*/
- private boolean writeHeader(Object obj, PortableWriterExImpl writer) {
+ private boolean writeHeader(Object obj, BinaryWriterExImpl writer) {
if (writer.tryWriteAsHandle(obj))
return false;
@@ -686,25 +686,25 @@ public class PortableClassDescriptor {
/**
* @return Instance.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
- private Object newInstance() throws PortableException {
+ private Object newInstance() throws BinaryObjectException {
assert ctor != null;
try {
return ctor.newInstance();
}
catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
- throw new PortableException("Failed to instantiate instance: " + cls, e);
+ throw new BinaryObjectException("Failed to instantiate instance: " + cls, e);
}
}
/**
* @param cls Class.
* @return Constructor.
- * @throws PortableException If constructor doesn't exist.
+ * @throws org.apache.ignite.binary.BinaryObjectException If constructor doesn't exist.
*/
- @Nullable private static Constructor<?> constructor(Class<?> cls) throws PortableException {
+ @Nullable private static Constructor<?> constructor(Class<?> cls) throws BinaryObjectException {
assert cls != null;
try {
@@ -715,7 +715,7 @@ public class PortableClassDescriptor {
return ctor;
}
catch (IgniteCheckedException e) {
- throw new PortableException("Failed to get constructor for class: " + cls.getName(), e);
+ throw new BinaryObjectException("Failed to get constructor for class: " + cls.getName(), e);
}
}
@@ -807,9 +807,9 @@ public class PortableClassDescriptor {
return Mode.TIMESTAMP_ARR;
else if (cls.isArray())
return cls.getComponentType().isEnum() ? Mode.ENUM_ARR : Mode.OBJ_ARR;
- else if (cls == PortableObjectImpl.class)
+ else if (cls == BinaryObjectImpl.class)
return Mode.PORTABLE_OBJ;
- else if (PortableMarshalAware.class.isAssignableFrom(cls))
+ else if (Binarylizable.class.isAssignableFrom(cls))
return Mode.PORTABLE;
else if (Externalizable.class.isAssignableFrom(cls))
return Mode.EXTERNALIZABLE;
@@ -819,7 +819,7 @@ public class PortableClassDescriptor {
return Mode.COL;
else if (Map.class.isAssignableFrom(cls))
return Mode.MAP;
- else if (cls == PortableObjectImpl.class)
+ else if (cls == BinaryObjectImpl.class)
return Mode.PORTABLE_OBJ;
else if (cls.isEnum())
return Mode.ENUM;
@@ -865,9 +865,9 @@ public class PortableClassDescriptor {
/**
* @param obj Object.
* @param writer Writer.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
- public void write(Object obj, PortableWriterExImpl writer) throws PortableException {
+ public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
assert obj != null;
assert writer != null;
@@ -879,7 +879,7 @@ public class PortableClassDescriptor {
val = field.get(obj);
}
catch (IllegalAccessException e) {
- throw new PortableException("Failed to get value for field: " + field, e);
+ throw new BinaryObjectException("Failed to get value for field: " + field, e);
}
switch (mode) {
@@ -954,62 +954,62 @@ public class PortableClassDescriptor {
break;
case SHORT_ARR:
- writer.writeShortArrayField((short[]) val);
+ writer.writeShortArrayField((short[])val);
break;
case INT_ARR:
- writer.writeIntArrayField((int[]) val);
+ writer.writeIntArrayField((int[])val);
break;
case LONG_ARR:
- writer.writeLongArrayField((long[]) val);
+ writer.writeLongArrayField((long[])val);
break;
case FLOAT_ARR:
- writer.writeFloatArrayField((float[]) val);
+ writer.writeFloatArrayField((float[])val);
break;
case DOUBLE_ARR:
- writer.writeDoubleArrayField((double[]) val);
+ writer.writeDoubleArrayField((double[])val);
break;
case CHAR_ARR:
- writer.writeCharArrayField((char[]) val);
+ writer.writeCharArrayField((char[])val);
break;
case BOOLEAN_ARR:
- writer.writeBooleanArrayField((boolean[]) val);
+ writer.writeBooleanArrayField((boolean[])val);
break;
case DECIMAL_ARR:
- writer.writeDecimalArrayField((BigDecimal[]) val);
+ writer.writeDecimalArrayField((BigDecimal[])val);
break;
case STRING_ARR:
- writer.writeStringArrayField((String[]) val);
+ writer.writeStringArrayField((String[])val);
break;
case UUID_ARR:
- writer.writeUuidArrayField((UUID[]) val);
+ writer.writeUuidArrayField((UUID[])val);
break;
case DATE_ARR:
- writer.writeDateArrayField((Date[]) val);
+ writer.writeDateArrayField((Date[])val);
break;
case TIMESTAMP_ARR:
- writer.writeTimestampArrayField((Timestamp[]) val);
+ writer.writeTimestampArrayField((Timestamp[])val);
break;
@@ -1034,7 +1034,7 @@ public class PortableClassDescriptor {
break;
case PORTABLE_OBJ:
- writer.writePortableObjectField((PortableObjectImpl)val);
+ writer.writePortableObjectField((BinaryObjectImpl)val);
break;
@@ -1068,9 +1068,9 @@ public class PortableClassDescriptor {
/**
* @param obj Object.
* @param reader Reader.
- * @throws PortableException In case of error.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
*/
- public void read(Object obj, PortableReaderExImpl reader) throws PortableException {
+ public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
Object val = null;
switch (mode) {
@@ -1260,7 +1260,7 @@ public class PortableClassDescriptor {
field.set(obj, val);
}
catch (IllegalAccessException e) {
- throw new PortableException("Failed to set value for field: " + field, e);
+ throw new BinaryObjectException("Failed to set value for field: " + field, e);
}
}
}
[08/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java
deleted file mode 100644
index ce7063a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * 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.portable;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.TreeMap;
-import org.apache.ignite.IgnitePortables;
-import org.apache.ignite.cache.IgniteObject;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Wrapper for portable object in portable binary format. Once an object is defined as portable,
- * Ignite will always store it in memory in the portable (i.e. binary) format.
- * User can choose to work either with the portable format or with the deserialized form
- * (assuming that class definitions are present in the classpath).
- * <p>
- * <b>NOTE:</b> user does not need to (and should not) implement this interface directly.
- * <p>
- * To work with the portable format directly, user should create a cache projection
- * over {@code PortableObject} class and then retrieve individual fields as needed:
- * <pre name=code class=java>
- * IgniteCache<PortableObject, PortableObject> prj = cache.withKeepPortable();
- *
- * // Convert instance of MyKey to portable format.
- * // We could also use GridPortableBuilder to create the key in portable format directly.
- * PortableObject key = grid.portables().toPortable(new MyKey());
- *
- * PortableObject val = prj.get(key);
- *
- * String field = val.field("myFieldName");
- * </pre>
- * Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized
- * typed objects at all times. In this case we do incur the deserialization cost. However, if
- * {@link PortableMarshaller#isKeepDeserialized()} is {@code true} then Ignite will only deserialize on the first access
- * and will cache the deserialized object, so it does not have to be deserialized again:
- * <pre name=code class=java>
- * IgniteCache<MyKey.class, MyValue.class> cache = grid.cache(null);
- *
- * MyValue val = cache.get(new MyKey());
- *
- * // Normal java getter.
- * String fieldVal = val.getMyFieldName();
- * </pre>
- * <h1 class="header">Working With Maps and Collections</h1>
- * All maps and collections in the portable objects are serialized automatically. When working
- * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most
- * adequate collection or map in either language. For example, {@link ArrayList} in Java will become
- * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap}
- * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary}
- * in C#, etc.
- * <h1 class="header">Dynamic Structure Changes</h1>
- * Since objects are always cached in the portable binary format, server does not need to
- * be aware of the class definitions. Moreover, if class definitions are not present or not
- * used on the server, then clients can continuously change the structure of the portable
- * objects without having to restart the cluster. For example, if one client stores a
- * certain class with fields A and B, and another client stores the same class with
- * fields B and C, then the server-side portable object will have the fields A, B, and C.
- * As the structure of a portable object changes, the new fields become available for SQL queries
- * automatically.
- * <h1 class="header">Building Portable Objects</h1>
- * Ignite comes with {@link PortableBuilder} which allows to build portable objects dynamically:
- * <pre name=code class=java>
- * PortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject");
- *
- * builder.setField("fieldA", "A");
- * builder.setField("fieldB", "B");
- *
- * PortableObject portableObj = builder.build();
- * </pre>
- * For the cases when class definition is present
- * in the class path, it is also possible to populate a standard POJO and then
- * convert it to portable format, like so:
- * <pre name=code class=java>
- * MyObject obj = new MyObject();
- *
- * obj.setFieldA("A");
- * obj.setFieldB(123);
- *
- * PortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
- * </pre>
- * <h1 class="header">Portable Metadata</h1>
- * Even though Ignite portable protocol only works with hash codes for type and field names
- * to achieve better performance, Ignite provides metadata for all portable types which
- * can be queried ar runtime via any of the {@link IgnitePortables#metadata(Class)}
- * methods. Having metadata also allows for proper formatting of {@code PortableObject.toString()} method,
- * even when portable objects are kept in binary format only, which may be necessary for audit reasons.
- */
-public interface PortableObject extends IgniteObject, Cloneable {
- /**
- * Gets portable object type ID.
- *
- * @return Type ID.
- */
- @Override public int typeId();
-
- /**
- * Gets meta data for this portable object.
- *
- * @return Meta data.
- * @throws PortableException In case of error.
- */
- @Nullable public PortableMetadata metaData() throws PortableException;
-
- /**
- * Gets field value.
- *
- * @param fieldName Field name.
- * @return Field value.
- * @throws PortableException In case of any other error.
- */
- @Override @Nullable public <F> F field(String fieldName) throws PortableException;
-
- /**
- * Checks whether field is set.
- *
- * @param fieldName Field name.
- * @return {@code true} if field is set.
- */
- @Override public boolean hasField(String fieldName);
-
- /**
- * Gets field descriptor.
- *
- * @param fieldName Field name.
- * @return Field descriptor.
- * @throws PortableException If failed.
- */
- public PortableField fieldDescriptor(String fieldName) throws PortableException;
-
- /**
- * Gets fully deserialized instance of portable object.
- *
- * @return Fully deserialized instance of portable object.
- * @throws PortableInvalidClassException If class doesn't exist.
- * @throws PortableException In case of any other error.
- */
- @Override @Nullable public <T> T deserialize() throws PortableException;
-
- /**
- * Copies this portable object.
- *
- * @return Copy of this portable object.
- */
- public PortableObject clone() throws CloneNotSupportedException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java
deleted file mode 100644
index 4b3dc4c..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * 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.portable;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Raw reader for portable objects. Raw reader does not use field name hash codes, therefore,
- * making the format even more compact. However, if the raw reader is used,
- * dynamic structure changes to the portable objects are not supported.
- */
-public interface PortableRawReader {
- /**
- * @return Byte value.
- * @throws PortableException In case of error.
- */
- public byte readByte() throws PortableException;
-
- /**
- * @return Short value.
- * @throws PortableException In case of error.
- */
- public short readShort() throws PortableException;
-
- /**
- * @return Integer value.
- * @throws PortableException In case of error.
- */
- public int readInt() throws PortableException;
-
- /**
- * @return Long value.
- * @throws PortableException In case of error.
- */
- public long readLong() throws PortableException;
-
- /**
- * @return Float value.
- * @throws PortableException In case of error.
- */
- public float readFloat() throws PortableException;
-
- /**
- * @return Double value.
- * @throws PortableException In case of error.
- */
- public double readDouble() throws PortableException;
-
- /**
- * @return Char value.
- * @throws PortableException In case of error.
- */
- public char readChar() throws PortableException;
-
- /**
- * @return Boolean value.
- * @throws PortableException In case of error.
- */
- public boolean readBoolean() throws PortableException;
-
- /**
- * @return Decimal value.
- * @throws PortableException In case of error.
- */
- @Nullable public BigDecimal readDecimal() throws PortableException;
-
- /**
- * @return String value.
- * @throws PortableException In case of error.
- */
- @Nullable public String readString() throws PortableException;
-
- /**
- * @return UUID.
- * @throws PortableException In case of error.
- */
- @Nullable public UUID readUuid() throws PortableException;
-
- /**
- * @return Date.
- * @throws PortableException In case of error.
- */
- @Nullable public Date readDate() throws PortableException;
-
- /**
- * @return Timestamp.
- * @throws PortableException In case of error.
- */
- @Nullable public Timestamp readTimestamp() throws PortableException;
-
- /**
- * @return Object.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> T readObject() throws PortableException;
-
- /**
- * @return Byte array.
- * @throws PortableException In case of error.
- */
- @Nullable public byte[] readByteArray() throws PortableException;
-
- /**
- * @return Short array.
- * @throws PortableException In case of error.
- */
- @Nullable public short[] readShortArray() throws PortableException;
-
- /**
- * @return Integer array.
- * @throws PortableException In case of error.
- */
- @Nullable public int[] readIntArray() throws PortableException;
-
- /**
- * @return Long array.
- * @throws PortableException In case of error.
- */
- @Nullable public long[] readLongArray() throws PortableException;
-
- /**
- * @return Float array.
- * @throws PortableException In case of error.
- */
- @Nullable public float[] readFloatArray() throws PortableException;
-
- /**
- * @return Byte array.
- * @throws PortableException In case of error.
- */
- @Nullable public double[] readDoubleArray() throws PortableException;
-
- /**
- * @return Char array.
- * @throws PortableException In case of error.
- */
- @Nullable public char[] readCharArray() throws PortableException;
-
- /**
- * @return Boolean array.
- * @throws PortableException In case of error.
- */
- @Nullable public boolean[] readBooleanArray() throws PortableException;
-
- /**
- * @return Decimal array.
- * @throws PortableException In case of error.
- */
- @Nullable public BigDecimal[] readDecimalArray() throws PortableException;
-
- /**
- * @return String array.
- * @throws PortableException In case of error.
- */
- @Nullable public String[] readStringArray() throws PortableException;
-
- /**
- * @return UUID array.
- * @throws PortableException In case of error.
- */
- @Nullable public UUID[] readUuidArray() throws PortableException;
-
- /**
- * @return Date array.
- * @throws PortableException In case of error.
- */
- @Nullable public Date[] readDateArray() throws PortableException;
-
- /**
- * @return Timestamp array.
- * @throws PortableException In case of error.
- */
- @Nullable public Timestamp[] readTimestampArray() throws PortableException;
-
- /**
- * @return Object array.
- * @throws PortableException In case of error.
- */
- @Nullable public Object[] readObjectArray() throws PortableException;
-
- /**
- * @return Collection.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> Collection<T> readCollection() throws PortableException;
-
- /**
- * @param colCls Collection class.
- * @return Collection.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> Collection<T> readCollection(Class<? extends Collection<T>> colCls)
- throws PortableException;
-
- /**
- * @return Map.
- * @throws PortableException In case of error.
- */
- @Nullable public <K, V> Map<K, V> readMap() throws PortableException;
-
- /**
- * @param mapCls Map class.
- * @return Map.
- * @throws PortableException In case of error.
- */
- @Nullable public <K, V> Map<K, V> readMap(Class<? extends Map<K, V>> mapCls) throws PortableException;
-
- /**
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable public <T extends Enum<?>> T readEnum() throws PortableException;
-
- /**
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable public <T extends Enum<?>> T[] readEnumArray() throws PortableException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java
deleted file mode 100644
index 245f755..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * 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.portable;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Raw writer for portable object. Raw writer does not write field name hash codes, therefore,
- * making the format even more compact. However, if the raw writer is used,
- * dynamic structure changes to the portable objects are not supported.
- */
-public interface PortableRawWriter {
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeByte(byte val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeShort(short val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeInt(int val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeLong(long val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeFloat(float val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDouble(double val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeChar(char val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeBoolean(boolean val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDecimal(@Nullable BigDecimal val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeString(@Nullable String val) throws PortableException;
-
- /**
- * @param val UUID to write.
- * @throws PortableException In case of error.
- */
- public void writeUuid(@Nullable UUID val) throws PortableException;
-
- /**
- * @param val Date to write.
- * @throws PortableException In case of error.
- */
- public void writeDate(@Nullable Date val) throws PortableException;
-
- /**
- * @param val Timestamp to write.
- * @throws PortableException In case of error.
- */
- public void writeTimestamp(@Nullable Timestamp val) throws PortableException;
-
- /**
- * @param obj Value to write.
- * @throws PortableException In case of error.
- */
- public void writeObject(@Nullable Object obj) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeByteArray(@Nullable byte[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeShortArray(@Nullable short[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeIntArray(@Nullable int[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeLongArray(@Nullable long[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeFloatArray(@Nullable float[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDoubleArray(@Nullable double[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeCharArray(@Nullable char[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeBooleanArray(@Nullable boolean[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDecimalArray(@Nullable BigDecimal[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeStringArray(@Nullable String[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeUuidArray(@Nullable UUID[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDateArray(@Nullable Date[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeTimestampArray(@Nullable Timestamp[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeObjectArray(@Nullable Object[] val) throws PortableException;
-
- /**
- * @param col Collection to write.
- * @throws PortableException In case of error.
- */
- public <T> void writeCollection(@Nullable Collection<T> col) throws PortableException;
-
- /**
- * @param map Map to write.
- * @throws PortableException In case of error.
- */
- public <K, V> void writeMap(@Nullable Map<K, V> map) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public <T extends Enum<?>> void writeEnum(T val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public <T extends Enum<?>> void writeEnumArray(T[] val) throws PortableException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java
deleted file mode 100644
index f2b1cda..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * 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.portable;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Reader for portable objects used in {@link PortableMarshalAware} implementations.
- * Useful for the cases when user wants a fine-grained control over serialization.
- * <p>
- * Note that Ignite never writes full strings for field or type names. Instead,
- * for performance reasons, Ignite writes integer hash codes for type and field names.
- * It has been tested that hash code conflicts for the type names or the field names
- * within the same type are virtually non-existent and, to gain performance, it is safe
- * to work with hash codes. For the cases when hash codes for different types or fields
- * actually do collide, Ignite provides {@link PortableIdMapper} which
- * allows to override the automatically generated hash code IDs for the type and field names.
- */
-public interface PortableReader {
- /**
- * @param fieldName Field name.
- * @return Byte value.
- * @throws PortableException In case of error.
- */
- public byte readByte(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Short value.
- * @throws PortableException In case of error.
- */
- public short readShort(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Integer value.
- * @throws PortableException In case of error.
- */
- public int readInt(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Long value.
- * @throws PortableException In case of error.
- */
- public long readLong(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @throws PortableException In case of error.
- * @return Float value.
- */
- public float readFloat(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Double value.
- * @throws PortableException In case of error.
- */
- public double readDouble(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Char value.
- * @throws PortableException In case of error.
- */
- public char readChar(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Boolean value.
- * @throws PortableException In case of error.
- */
- public boolean readBoolean(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Decimal value.
- * @throws PortableException In case of error.
- */
- @Nullable public BigDecimal readDecimal(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return String value.
- * @throws PortableException In case of error.
- */
- @Nullable public String readString(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return UUID.
- * @throws PortableException In case of error.
- */
- @Nullable public UUID readUuid(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Date.
- * @throws PortableException In case of error.
- */
- @Nullable public Date readDate(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Timestamp.
- * @throws PortableException In case of error.
- */
- @Nullable public Timestamp readTimestamp(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Object.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> T readObject(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Byte array.
- * @throws PortableException In case of error.
- */
- @Nullable public byte[] readByteArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Short array.
- * @throws PortableException In case of error.
- */
- @Nullable public short[] readShortArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Integer array.
- * @throws PortableException In case of error.
- */
- @Nullable public int[] readIntArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Long array.
- * @throws PortableException In case of error.
- */
- @Nullable public long[] readLongArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Float array.
- * @throws PortableException In case of error.
- */
- @Nullable public float[] readFloatArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Byte array.
- * @throws PortableException In case of error.
- */
- @Nullable public double[] readDoubleArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Char array.
- * @throws PortableException In case of error.
- */
- @Nullable public char[] readCharArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Boolean array.
- * @throws PortableException In case of error.
- */
- @Nullable public boolean[] readBooleanArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Decimal array.
- * @throws PortableException In case of error.
- */
- @Nullable public BigDecimal[] readDecimalArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return String array.
- * @throws PortableException In case of error.
- */
- @Nullable public String[] readStringArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return UUID array.
- * @throws PortableException In case of error.
- */
- @Nullable public UUID[] readUuidArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Date array.
- * @throws PortableException In case of error.
- */
- @Nullable public Date[] readDateArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Timestamp array.
- * @throws PortableException In case of error.
- */
- @Nullable public Timestamp[] readTimestampArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Object array.
- * @throws PortableException In case of error.
- */
- @Nullable public Object[] readObjectArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Collection.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> Collection<T> readCollection(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param colCls Collection class.
- * @return Collection.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> Collection<T> readCollection(String fieldName, Class<? extends Collection<T>> colCls)
- throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Map.
- * @throws PortableException In case of error.
- */
- @Nullable public <K, V> Map<K, V> readMap(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param mapCls Map class.
- * @return Map.
- * @throws PortableException In case of error.
- */
- @Nullable public <K, V> Map<K, V> readMap(String fieldName, Class<? extends Map<K, V>> mapCls)
- throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable public <T extends Enum<?>> T readEnum(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable public <T extends Enum<?>> T[] readEnumArray(String fieldName) throws PortableException;
-
- /**
- * Gets raw reader. Raw reader does not use field name hash codes, therefore,
- * making the format even more compact. However, if the raw reader is used,
- * dynamic structure changes to the portable objects are not supported.
- *
- * @return Raw reader.
- */
- public PortableRawReader rawReader();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java
deleted file mode 100644
index 90ee562..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-
-/**
- * Interface that allows to implement custom serialization logic for portable objects.
- * Can be used instead of {@link PortableMarshalAware} in case if the class
- * cannot be changed directly.
- * <p>
- * Portable serializer can be configured for all portable objects via
- * {@link PortableMarshaller#getSerializer()} method, or for a specific
- * portable type via {@link PortableTypeConfiguration#getSerializer()} method.
- */
-public interface PortableSerializer {
- /**
- * Writes fields to provided writer.
- *
- * @param obj Empty object.
- * @param writer Portable object writer.
- * @throws PortableException In case of error.
- */
- public void writePortable(Object obj, PortableWriter writer) throws PortableException;
-
- /**
- * Reads fields from provided reader.
- *
- * @param obj Empty object
- * @param reader Portable object reader.
- * @throws PortableException In case of error.
- */
- public void readPortable(Object obj, PortableReader reader) throws PortableException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java
deleted file mode 100644
index 68f0514..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * 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.portable;
-
-import java.sql.Timestamp;
-import java.util.Collection;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-
-/**
- * Defines configuration properties for a specific portable type. Providing per-type
- * configuration is optional, as it is generally enough, and also optional, to provide global portable
- * configuration using {@link PortableMarshaller#setClassNames(Collection)}.
- * However, this class allows you to change configuration properties for a specific
- * portable type without affecting configuration for other portable types.
- * <p>
- * Per-type portable configuration can be specified in {@link PortableMarshaller#getTypeConfigurations()} method.
- */
-public class PortableTypeConfiguration {
- /** Class name. */
- private String clsName;
-
- /** ID mapper. */
- private PortableIdMapper idMapper;
-
- /** Serializer. */
- private PortableSerializer serializer;
-
- /** Meta data enabled flag. */
- private Boolean metaDataEnabled;
-
- /** Keep deserialized flag. */
- private Boolean keepDeserialized;
-
- /** Affinity key field name. */
- private String affKeyFieldName;
-
- /**
- */
- public PortableTypeConfiguration() {
- // No-op.
- }
-
- /**
- * @param clsName Class name.
- */
- public PortableTypeConfiguration(String clsName) {
- this.clsName = clsName;
- }
-
- /**
- * Gets type name.
- *
- * @return Type name.
- */
- public String getClassName() {
- return clsName;
- }
-
- /**
- * Sets type name.
- *
- * @param clsName Type name.
- */
- public void setClassName(String clsName) {
- this.clsName = clsName;
- }
-
- /**
- * Gets ID mapper.
- *
- * @return ID mapper.
- */
- public PortableIdMapper getIdMapper() {
- return idMapper;
- }
-
- /**
- * Sets ID mapper.
- *
- * @param idMapper ID mapper.
- */
- public void setIdMapper(PortableIdMapper idMapper) {
- this.idMapper = idMapper;
- }
-
- /**
- * Gets serializer.
- *
- * @return Serializer.
- */
- public PortableSerializer getSerializer() {
- return serializer;
- }
-
- /**
- * Sets serializer.
- *
- * @param serializer Serializer.
- */
- public void setSerializer(PortableSerializer serializer) {
- this.serializer = serializer;
- }
-
- /**
- * Defines whether meta data is collected for this type. If provided, this value will override
- * {@link PortableMarshaller#isMetaDataEnabled()} property.
- *
- * @return Whether meta data is collected.
- */
- public Boolean isMetaDataEnabled() {
- return metaDataEnabled;
- }
-
- /**
- * @param metaDataEnabled Whether meta data is collected.
- */
- public void setMetaDataEnabled(Boolean metaDataEnabled) {
- this.metaDataEnabled = metaDataEnabled;
- }
-
- /**
- * Defines whether {@link PortableObject} should cache deserialized instance. If provided,
- * this value will override {@link PortableMarshaller#isKeepDeserialized()}
- * property.
- *
- * @return Whether deserialized value is kept.
- */
- public Boolean isKeepDeserialized() {
- return keepDeserialized;
- }
-
- /**
- * @param keepDeserialized Whether deserialized value is kept.
- */
- public void setKeepDeserialized(Boolean keepDeserialized) {
- this.keepDeserialized = keepDeserialized;
- }
-
- /**
- * Gets affinity key field name.
- *
- * @return Affinity key field name.
- */
- public String getAffinityKeyFieldName() {
- return affKeyFieldName;
- }
-
- /**
- * Sets affinity key field name.
- *
- * @param affKeyFieldName Affinity key field name.
- */
- public void setAffinityKeyFieldName(String affKeyFieldName) {
- this.affKeyFieldName = affKeyFieldName;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(PortableTypeConfiguration.class, this, super.toString());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java
deleted file mode 100644
index 99bd5c6..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * 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.portable;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Writer for portable object used in {@link PortableMarshalAware} implementations.
- * Useful for the cases when user wants a fine-grained control over serialization.
- * <p>
- * Note that Ignite never writes full strings for field or type names. Instead,
- * for performance reasons, Ignite writes integer hash codes for type and field names.
- * It has been tested that hash code conflicts for the type names or the field names
- * within the same type are virtually non-existent and, to gain performance, it is safe
- * to work with hash codes. For the cases when hash codes for different types or fields
- * actually do collide, Ignite provides {@link PortableIdMapper} which
- * allows to override the automatically generated hash code IDs for the type and field names.
- */
-public interface PortableWriter {
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeByte(String fieldName, byte val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeShort(String fieldName, short val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeInt(String fieldName, int val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeLong(String fieldName, long val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeFloat(String fieldName, float val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDouble(String fieldName, double val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeChar(String fieldName, char val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeBoolean(String fieldName, boolean val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeString(String fieldName, @Nullable String val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val UUID to write.
- * @throws PortableException In case of error.
- */
- public void writeUuid(String fieldName, @Nullable UUID val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Date to write.
- * @throws PortableException In case of error.
- */
- public void writeDate(String fieldName, @Nullable Date val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Timestamp to write.
- * @throws PortableException In case of error.
- */
- public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param obj Value to write.
- * @throws PortableException In case of error.
- */
- public void writeObject(String fieldName, @Nullable Object obj) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeByteArray(String fieldName, @Nullable byte[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeShortArray(String fieldName, @Nullable short[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeIntArray(String fieldName, @Nullable int[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeLongArray(String fieldName, @Nullable long[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeFloatArray(String fieldName, @Nullable float[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDoubleArray(String fieldName, @Nullable double[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeCharArray(String fieldName, @Nullable char[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeBooleanArray(String fieldName, @Nullable boolean[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeStringArray(String fieldName, @Nullable String[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDateArray(String fieldName, @Nullable Date[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeObjectArray(String fieldName, @Nullable Object[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param col Collection to write.
- * @throws PortableException In case of error.
- */
- public <T> void writeCollection(String fieldName, @Nullable Collection<T> col) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param map Map to write.
- * @throws PortableException In case of error.
- */
- public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws PortableException;
-
- /**
- * Gets raw writer. Raw writer does not write field name hash codes, therefore,
- * making the format even more compact. However, if the raw writer is used,
- * dynamic structure changes to the portable objects are not supported.
- *
- * @return Raw writer.
- */
- public PortableRawWriter rawWriter();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/package-info.java b/modules/core/src/main/java/org/apache/ignite/portable/package-info.java
deleted file mode 100644
index 0105b15..0000000
--- a/modules/core/src/main/java/org/apache/ignite/portable/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Contains portable objects API classes.
- */
-package org.apache.ignite.portable;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
index 6254605..e3a02cb 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
@@ -44,6 +44,7 @@ import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocketFactory;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteAuthenticationException;
+import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteLogger;
@@ -59,6 +60,7 @@ import org.apache.ignite.internal.util.typedef.internal.LT;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.lang.IgniteCallable;
import org.apache.ignite.lang.IgniteInClosure;
import org.apache.ignite.lang.IgniteProductVersion;
import org.apache.ignite.lang.IgniteUuid;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapKey.java b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapKey.java
index fb22be2..fb028b4 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapKey.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapKey.java
@@ -17,6 +17,7 @@
package org.apache.ignite.spi.swapspace;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
@@ -44,7 +45,8 @@ public class SwapKey {
* @param key Key.
*/
public SwapKey(Object key) {
- this(key, Integer.MAX_VALUE, null);
+ this.key = key;
+ part = Integer.MAX_VALUE;
}
/**
@@ -52,7 +54,8 @@ public class SwapKey {
* @param part Partition.
*/
public SwapKey(Object key, int part) {
- this(key, part, null);
+ this.key = key;
+ this.part = part;
}
/**
@@ -60,7 +63,7 @@ public class SwapKey {
* @param part Part.
* @param keyBytes Key bytes.
*/
- public SwapKey(Object key, int part, @Nullable byte[] keyBytes) {
+ public SwapKey(KeyCacheObject key, int part, @Nullable byte[] keyBytes) {
assert key != null;
assert part >= 0;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java b/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java
index e7d224c..48559a9 100644
--- a/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java
@@ -33,11 +33,10 @@ import org.apache.ignite.IgniteDataStreamer;
* <li>A single tuple extractor, which extracts either no or 1 tuple out of a message. See
* see {@link #setTupleExtractor(StreamTupleExtractor)}.</li>
* <li>A multiple tuple extractor, which is capable of extracting multiple tuples out of a single message, in the
- * form of a {@link Map<K, V>}. See {@link #setMultipleTupleExtractor(StreamMultipleTupleExtractor)}.</li>
+ * form of a {@link Map}. See {@link #setMultipleTupleExtractor(StreamMultipleTupleExtractor)}.</li>
* </ol>
*/
public abstract class StreamAdapter<T, K, V> {
-
/** Tuple extractor extracting a single tuple from an event */
private StreamSingleTupleExtractor<T, K, V> singleTupleExtractor;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java
new file mode 100644
index 0000000..1db3f0b
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java
@@ -0,0 +1,730 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.binary.BinaryField;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.UUID;
+
+/**
+ * Contains tests for portable object fields.
+ */
+public abstract class BinaryFieldsAbstractSelfTest extends GridCommonAbstractTest {
+ /** Dummy metadata handler. */
+ protected static final PortableMetaDataHandler META_HND = new PortableMetaDataHandler() {
+ @Override public void addMeta(int typeId, BinaryType meta) {
+ // No-op.
+ }
+
+ @Override public BinaryType metadata(int typeId) {
+ return null;
+ }
+ };
+
+ /** Marshaller. */
+ protected PortableMarshaller dfltMarsh;
+
+ /**
+ * Create marshaller.
+ *
+ * @param stringAsBytes Whether to marshal strings as bytes (UTF8).
+ * @return Portable marshaller.
+ * @throws Exception If failed.
+ */
+ protected static PortableMarshaller createMarshaller(boolean stringAsBytes) throws Exception {
+ PortableContext ctx = new PortableContext(META_HND, new IgniteConfiguration());
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setConvertStringToBytes(stringAsBytes);
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new BinaryTypeConfiguration(TestObject.class.getName()),
+ new BinaryTypeConfiguration(TestOuterObject.class.getName()),
+ new BinaryTypeConfiguration(TestInnerObject.class.getName())
+ ));
+
+ marsh.setContext(new MarshallerContextTestImpl(null));
+
+ IgniteUtils.invoke(PortableMarshaller.class, marsh, "setPortableContext", ctx);
+
+ return marsh;
+ }
+
+ /**
+ * Get portable context for the current marshaller.
+ *
+ * @param marsh Marshaller.
+ * @return Portable context.
+ */
+ protected static PortableContext portableContext(PortableMarshaller marsh) {
+ GridPortableMarshaller impl = U.field(marsh, "impl");
+
+ return impl.context();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ dfltMarsh = createMarshaller(true);
+ }
+
+ /**
+ * Test byte field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testByte() throws Exception {
+ check("fByte");
+ }
+
+ /**
+ * Test byte array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testByteArray() throws Exception {
+ check("fByteArr");
+ }
+
+ /**
+ * Test boolean field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testBoolean() throws Exception {
+ check("fBool");
+ }
+
+ /**
+ * Test boolean array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testBooleanArray() throws Exception {
+ check("fBoolArr");
+ }
+
+ /**
+ * Test short field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testShort() throws Exception {
+ check("fShort");
+ }
+
+ /**
+ * Test short array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testShortArray() throws Exception {
+ check("fShortArr");
+ }
+
+ /**
+ * Test char field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testChar() throws Exception {
+ check("fChar");
+ }
+
+ /**
+ * Test char array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testCharArray() throws Exception {
+ check("fCharArr");
+ }
+
+ /**
+ * Test int field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testInt() throws Exception {
+ check("fInt");
+ }
+
+ /**
+ * Test int array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testIntArray() throws Exception {
+ check("fIntArr");
+ }
+
+ /**
+ * Test long field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testLong() throws Exception {
+ check("fLong");
+ }
+
+ /**
+ * Test long array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testLongArray() throws Exception {
+ check("fLongArr");
+ }
+
+ /**
+ * Test float field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testFloat() throws Exception {
+ check("fFloat");
+ }
+
+ /**
+ * Test float array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testFloatArray() throws Exception {
+ check("fFloatArr");
+ }
+
+ /**
+ * Test double field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testDouble() throws Exception {
+ check("fDouble");
+ }
+
+ /**
+ * Test double array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testDoubleArray() throws Exception {
+ check("fDoubleArr");
+ }
+
+ /**
+ * Test string field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testString() throws Exception {
+ check("fString");
+ }
+
+ /**
+ * Test string field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testStringAsChars() throws Exception {
+ PortableMarshaller marsh = createMarshaller(false);
+
+ checkNormal(marsh, "fString", true);
+ checkNested(marsh, "fString", true);
+ }
+
+ /**
+ * Test string array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testStringArray() throws Exception {
+ check("fStringArr");
+ }
+
+ /**
+ * Test date field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testDate() throws Exception {
+ check("fDate");
+ }
+
+ /**
+ * Test date array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testDateArray() throws Exception {
+ check("fDateArr");
+ }
+
+ /**
+ * Test timestamp field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testTimestamp() throws Exception {
+ check("fTimestamp");
+ }
+
+ /**
+ * Test timestamp array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testTimestampArray() throws Exception {
+ check("fTimestampArr");
+ }
+
+ /**
+ * Test UUID field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testUuid() throws Exception {
+ check("fUuid");
+ }
+
+ /**
+ * Test UUID array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testUuidArray() throws Exception {
+ check("fUuidArr");
+ }
+
+ /**
+ * Test decimal field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testDecimal() throws Exception {
+ check("fDecimal");
+ }
+
+ /**
+ * Test decimal array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testDecimalArray() throws Exception {
+ check("fDecimalArr");
+ }
+
+ /**
+ * Test object field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testObject() throws Exception {
+ check("fObj");
+ }
+
+ /**
+ * Test object array field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testObjectArray() throws Exception {
+ check("fObjArr");
+ }
+
+ /**
+ * Test null field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testNull() throws Exception {
+ check("fNull");
+ }
+
+ /**
+ * Test missing field.
+ *
+ * @throws Exception If failed.
+ */
+ public void testMissing() throws Exception {
+ String fieldName = "fMissing";
+
+ checkNormal(dfltMarsh, fieldName, false);
+ checkNested(dfltMarsh, fieldName, false);
+ }
+
+ /**
+ * Check field resolution in both normal and nested modes.
+ *
+ * @param fieldName Field name.
+ * @throws Exception If failed.
+ */
+ public void check(String fieldName) throws Exception {
+ checkNormal(dfltMarsh, fieldName, true);
+ checkNested(dfltMarsh, fieldName, true);
+ }
+
+ /**
+ * Check field.
+ *
+ * @param marsh Marshaller.
+ * @param fieldName Field name.
+ * @param exists Whether field should exist.
+ * @throws Exception If failed.
+ */
+ private void checkNormal(PortableMarshaller marsh, String fieldName, boolean exists) throws Exception {
+ TestContext testCtx = context(marsh, fieldName);
+
+ check0(fieldName, testCtx, exists);
+ }
+
+ /**
+ * Check nested field.
+ *
+ * @param marsh Marshaller.
+ * @param fieldName Field name.
+ * @param exists Whether field should exist.
+ * @throws Exception If failed.
+ */
+ private void checkNested(PortableMarshaller marsh, String fieldName, boolean exists) throws Exception {
+ TestContext testCtx = nestedContext(marsh, fieldName);
+
+ check0(fieldName, testCtx, exists);
+ }
+
+ /**
+ * Internal check routine.
+ *
+ * @param fieldName Field name.
+ * @param ctx Context.
+ * @param exists Whether field should exist.
+ * @throws Exception If failed.
+ */
+ private void check0(String fieldName, TestContext ctx, boolean exists) throws Exception {
+ Object val = ctx.field.value(ctx.portObj);
+
+ if (exists) {
+ assertTrue(ctx.field.exists(ctx.portObj));
+
+ Object expVal = U.field(ctx.obj, fieldName);
+
+ if (val instanceof BinaryObject)
+ val = ((BinaryObject) val).deserialize();
+
+ if (val != null && val.getClass().isArray()) {
+ assertNotNull(expVal);
+
+ if (val instanceof byte[])
+ assertTrue(Arrays.equals((byte[]) expVal, (byte[]) val));
+ else if (val instanceof boolean[])
+ assertTrue(Arrays.equals((boolean[]) expVal, (boolean[]) val));
+ else if (val instanceof short[])
+ assertTrue(Arrays.equals((short[]) expVal, (short[]) val));
+ else if (val instanceof char[])
+ assertTrue(Arrays.equals((char[]) expVal, (char[]) val));
+ else if (val instanceof int[])
+ assertTrue(Arrays.equals((int[]) expVal, (int[]) val));
+ else if (val instanceof long[])
+ assertTrue(Arrays.equals((long[]) expVal, (long[]) val));
+ else if (val instanceof float[])
+ assertTrue(Arrays.equals((float[]) expVal, (float[]) val));
+ else if (val instanceof double[])
+ assertTrue(Arrays.equals((double[]) expVal, (double[]) val));
+ else {
+ Object[] expVal0 = (Object[])expVal;
+ Object[] val0 = (Object[])val;
+
+ assertEquals(expVal0.length, val0.length);
+
+ for (int i = 0; i < expVal0.length; i++) {
+ Object expItem = expVal0[i];
+ Object item = val0[i];
+
+ if (item instanceof BinaryObject)
+ item = ((BinaryObject)item).deserialize();
+
+ assertEquals(expItem, item);
+ }
+ }
+ }
+ else
+ assertEquals(expVal, val);
+ }
+ else {
+ assertFalse(ctx.field.exists(ctx.portObj));
+
+ assert val == null;
+ }
+ }
+
+ /**
+ * Get test context.
+ *
+ * @param marsh Portable marshaller.
+ * @param fieldName Field name.
+ * @return Test context.
+ * @throws Exception If failed.
+ */
+ private TestContext context(PortableMarshaller marsh, String fieldName) throws Exception {
+ TestObject obj = createObject();
+
+ BinaryObjectEx portObj = toPortable(marsh, obj);
+
+ BinaryField field = portObj.fieldDescriptor(fieldName);
+
+ return new TestContext(obj, portObj, field);
+ }
+
+ /**
+ * Get test context with nested test object.
+ *
+ * @param marsh Portable marshaller.
+ * @param fieldName Field name.
+ * @return Test context.
+ * @throws Exception If failed.
+ */
+ private TestContext nestedContext(PortableMarshaller marsh, String fieldName)
+ throws Exception {
+ TestObject obj = createObject();
+ TestOuterObject outObj = new TestOuterObject(obj);
+
+ BinaryObjectEx portOutObj = toPortable(marsh, outObj);
+ BinaryObjectEx portObj = portOutObj.field("fInner");
+
+ assert portObj != null;
+
+ BinaryField field = portObj.fieldDescriptor(fieldName);
+
+ return new TestContext(obj, portObj, field);
+ }
+
+ /**
+ * Create test object.
+ *
+ * @return Test object.
+ */
+ private TestObject createObject() {
+ return new TestObject(0);
+ }
+
+ /**
+ * Convert object to portable object.
+ *
+ * @param marsh Marshaller.
+ * @param obj Object.
+ * @return Portable object.
+ * @throws Exception If failed.
+ */
+ protected abstract BinaryObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception;
+
+ /**
+ * Outer test object.
+ */
+ @SuppressWarnings("UnusedDeclaration")
+ public static class TestOuterObject {
+ /** Inner object. */
+ public TestObject fInner;
+
+ /**
+ * Default constructor.
+ */
+ public TestOuterObject() {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param fInner Inner object.
+ */
+ public TestOuterObject(TestObject fInner) {
+ this.fInner = fInner;
+ }
+ }
+
+ /**
+ * Test object class, c
+ */
+ @SuppressWarnings("UnusedDeclaration")
+ public static class TestObject {
+ /** Primitive fields. */
+ public byte fByte;
+ public boolean fBool;
+ public short fShort;
+ public char fChar;
+ public int fInt;
+ public long fLong;
+ public float fFloat;
+ public double fDouble;
+
+ public byte[] fByteArr;
+ public boolean[] fBoolArr;
+ public short[] fShortArr;
+ public char[] fCharArr;
+ public int[] fIntArr;
+ public long[] fLongArr;
+ public float[] fFloatArr;
+ public double[] fDoubleArr;
+
+ /** Special fields. */
+ public String fString;
+ public Date fDate;
+ public Timestamp fTimestamp;
+ public UUID fUuid;
+ public BigDecimal fDecimal;
+
+ public String[] fStringArr;
+ public Date[] fDateArr;
+ public Timestamp[] fTimestampArr;
+ public UUID[] fUuidArr;
+ public BigDecimal[] fDecimalArr;
+
+ /** Nested object. */
+ public TestInnerObject fObj;
+
+ public TestInnerObject[] fObjArr;
+
+ /** Field which is always set to null. */
+ public Object fNull;
+
+ /**
+ * Default constructor.
+ */
+ public TestObject() {
+ // No-op.
+ }
+
+ /**
+ * Non-default constructor.
+ *
+ * @param ignore Ignored.
+ */
+ public TestObject(int ignore) {
+ fByte = 1;
+ fBool = true;
+ fShort = 2;
+ fChar = 3;
+ fInt = 4;
+ fLong = 5;
+ fFloat = 6.6f;
+ fDouble = 7.7;
+
+ fByteArr = new byte[] { 1, 2 };
+ fBoolArr = new boolean[] { true, false };
+ fShortArr = new short[] { 2, 3 };
+ fCharArr = new char[] { 3, 4 };
+ fIntArr = new int[] { 4, 5 };
+ fLongArr = new long[] { 5, 6 };
+ fFloatArr = new float[] { 6.6f, 7.7f };
+ fDoubleArr = new double[] { 7.7, 8.8 };
+
+ fString = "8";
+ fDate = new Date();
+ fTimestamp = new Timestamp(new Date().getTime() + 1);
+ fUuid = UUID.randomUUID();
+ fDecimal = new BigDecimal(9);
+
+ fStringArr = new String[] { "8", "9" };
+ fDateArr = new Date[] { new Date(), new Date(new Date().getTime() + 1) };
+ fTimestampArr =
+ new Timestamp[] { new Timestamp(new Date().getTime() + 1), new Timestamp(new Date().getTime() + 2) };
+ fUuidArr = new UUID[] { UUID.randomUUID(), UUID.randomUUID() };
+ fDecimalArr = new BigDecimal[] { new BigDecimal(9), new BigDecimal(10) };
+
+ fObj = new TestInnerObject(10);
+ fObjArr = new TestInnerObject[] { new TestInnerObject(10), new TestInnerObject(11) };
+ }
+ }
+
+ /**
+ * Inner test object.
+ */
+ @SuppressWarnings("UnusedDeclaration")
+ public static class TestInnerObject {
+ /** Value. */
+ private int val;
+
+ /**
+ * Default constructor.
+ */
+ public TestInnerObject() {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param val Value.
+ */
+ public TestInnerObject(int val) {
+ this.val = val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object other) {
+ return other != null && other instanceof TestInnerObject && val == ((TestInnerObject)(other)).val;
+ }
+ }
+
+ /**
+ * Test context.
+ */
+ public static class TestContext {
+ /** Object. */
+ public final TestObject obj;
+
+ /** Portable object. */
+ public final BinaryObjectEx portObj;
+
+ /** Field. */
+ public final BinaryField field;
+
+ /**
+ * Constructor.
+ *
+ * @param obj Object.
+ * @param portObj Portable object.
+ * @param field Field.
+ */
+ public TestContext(TestObject obj, BinaryObjectEx portObj, BinaryField field) {
+ this.obj = obj;
+ this.portObj = portObj;
+ this.field = field;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java
new file mode 100644
index 0000000..0140c53
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ * Field tests for heap-based portables.
+ */
+public class BinaryFieldsHeapSelfTest extends BinaryFieldsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected BinaryObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception {
+ byte[] bytes = marsh.marshal(obj);
+
+ return new BinaryObjectImpl(portableContext(marsh), bytes, 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java
new file mode 100644
index 0000000..1bd0f72
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.eclipse.jetty.util.ConcurrentHashSet;
+import sun.misc.Unsafe;
+
+/**
+ * Field tests for heap-based portables.
+ */
+public class BinaryFieldsOffheapSelfTest extends BinaryFieldsAbstractSelfTest {
+ /** Unsafe instance. */
+ private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+ /** Byte array offset for unsafe mechanics. */
+ protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+ /** Allocated unsafe pointer. */
+ private final ConcurrentHashSet<Long> ptrs = new ConcurrentHashSet<>();
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ // Cleanup allocated objects.
+ for (Long ptr : ptrs)
+ UNSAFE.freeMemory(ptr);
+
+ ptrs.clear();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected BinaryObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception {
+ byte[] arr = marsh.marshal(obj);
+
+ long ptr = UNSAFE.allocateMemory(arr.length);
+
+ ptrs.add(ptr);
+
+ UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
+
+ return new BinaryObjectOffheapImpl(portableContext(marsh), ptr, 0, arr.length);
+ }
+}
[18/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawWriterEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawWriterEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawWriterEx.java
deleted file mode 100644
index a59f157..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawWriterEx.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.internal.portable.streams.PortableOutputStream;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableRawWriter;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Extended writer interface.
- */
-public interface PortableRawWriterEx extends PortableRawWriter, AutoCloseable {
- /**
- * @param obj Object to write.
- * @throws PortableException In case of error.
- */
- public void writeObjectDetached(@Nullable Object obj) throws PortableException;
-
- /**
- * @return Output stream.
- */
- public PortableOutputStream out();
-
- /**
- * Cleans resources.
- */
- @Override public void close();
-
- /**
- * Reserve a room for an integer.
- *
- * @return Position in the stream where value is to be written.
- */
- public int reserveInt();
-
- /**
- * Write int value at the specific position.
- *
- * @param pos Position.
- * @param val Value.
- * @throws PortableException If failed.
- */
- public void writeInt(int pos, int val) throws PortableException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
index 51fc407..869f81d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
@@ -20,8 +20,8 @@ package org.apache.ignite.internal.portable;
import java.util.HashMap;
import java.util.Map;
import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.portable.PortableObject;
import org.jetbrains.annotations.Nullable;
/**
@@ -32,7 +32,7 @@ class PortableReaderContext {
private Object oHandles;
/** */
- private Map<Integer, PortableObject> poHandles;
+ private Map<Integer, BinaryObject> poHandles;
/**
* @param handle Handle.
@@ -62,7 +62,7 @@ class PortableReaderContext {
* @param handle Handle.
* @param po Portable object.
*/
- void setPortableHandler(int handle, PortableObject po) {
+ void setPortableHandler(int handle, BinaryObject po) {
assert po != null;
if (poHandles == null)
@@ -94,7 +94,7 @@ class PortableReaderContext {
* @param handle Handle.
* @return Object.
*/
- @Nullable PortableObject getPortableByHandle(int handle) {
+ @Nullable BinaryObject getPortableByHandle(int handle) {
return poHandles != null ? poHandles.get(handle) : null;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
deleted file mode 100644
index b5decba..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
+++ /dev/null
@@ -1,2775 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.streams.PortableHeapInputStream;
-import org.apache.ignite.internal.portable.streams.PortableInputStream;
-import org.apache.ignite.internal.util.GridEnumCache;
-import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.internal.util.typedef.internal.SB;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableIdMapper;
-import org.apache.ignite.portable.PortableInvalidClassException;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableRawReader;
-import org.apache.ignite.portable.PortableReader;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.io.ByteArrayInputStream;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.lang.reflect.Array;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Properties;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentSkipListSet;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ARR_LIST;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CLASS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.COL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CONC_HASH_MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CONC_SKIP_LIST_SET;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DFLT_HDR_LEN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.HANDLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.HASH_MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.HASH_SET;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LINKED_HASH_MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LINKED_HASH_SET;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LINKED_LIST;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP_ENTRY;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJECT_TYPE_ID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OPTM_MARSH;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.PORTABLE_OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.PROPERTIES_MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TREE_MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TREE_SET;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.USER_COL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.USER_SET;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID_ARR;
-
-/**
- * Portable reader implementation.
- */
-@SuppressWarnings("unchecked")
-public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx, ObjectInput {
- /** Length of a single field descriptor. */
- private static final int FIELD_DESC_LEN = 16;
-
- /** */
- private final PortableContext ctx;
-
- /** */
- private final PortableInputStream in;
-
- /** */
- private final int start;
-
- /** */
- private final PortableReaderContext rCtx;
-
- /** */
- private final ClassLoader ldr;
-
- /** */
- private PortableClassDescriptor desc;
-
- /** Flag indicating that object header was parsed. */
- private boolean hdrParsed;
-
- /** Type ID. */
- private int typeId;
-
- /** Raw offset. */
- private int rawOff;
-
- /** */
- private int hdrLen;
-
- /** Footer start. */
- private int footerStart;
-
- /** Footer end. */
- private int footerLen;
-
- /** ID mapper. */
- private PortableIdMapper idMapper;
-
- /** Schema Id. */
- private int schemaId;
-
- /** Offset size in bytes. */
- private int offsetSize;
-
- /** Object schema. */
- private PortableSchema schema;
-
- /**
- * @param ctx Context.
- * @param arr Array.
- * @param start Start.
- * @param ldr Class loader.
- */
- public PortableReaderExImpl(PortableContext ctx, byte[] arr, int start, ClassLoader ldr) {
- this(ctx, new PortableHeapInputStream(arr), start, ldr, new PortableReaderContext());
- }
-
- /**
- * @param ctx Context.
- * @param in Input stream.
- * @param start Start.
- */
- PortableReaderExImpl(PortableContext ctx, PortableInputStream in, int start, ClassLoader ldr) {
- this(ctx, in, start, ldr, new PortableReaderContext());
- }
-
- /**
- * @param ctx Context.
- * @param in Input stream.
- * @param start Start.
- * @param rCtx Context.
- */
- PortableReaderExImpl(PortableContext ctx, PortableInputStream in, int start, ClassLoader ldr,
- PortableReaderContext rCtx) {
- this.ctx = ctx;
- this.in = in;
- this.start = start;
- this.ldr = ldr;
- this.rCtx = rCtx;
-
- in.position(start);
- }
-
- /**
- * Preloads typeId from the input array.
- */
- private void parseHeaderIfNeeded() {
- if (hdrParsed)
- return;
-
- int retPos = in.position();
-
- in.position(start);
-
- byte hdr = in.readByte();
-
- if (hdr != GridPortableMarshaller.OBJ)
- throw new PortableException("Invalid header [pos=" + retPos + "expected=" + GridPortableMarshaller.OBJ +
- ", actual=" + hdr + ']');
-
- PortableUtils.checkProtocolVersion(in.readByte());
-
- short flags = in.readShort();
-
- offsetSize = PortableUtils.fieldOffsetSize(flags);
-
- typeId = in.readIntPositioned(start + GridPortableMarshaller.TYPE_ID_POS);
-
- IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(in, start, offsetSize);
-
- footerStart = footer.get1();
- footerLen = footer.get2() - footerStart;
-
- schemaId = in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_ID_POS);
-
- rawOff = PortableUtils.rawOffsetAbsolute(in, start, offsetSize);
-
- if (typeId == UNREGISTERED_TYPE_ID) {
- // Skip to the class name position.
- in.position(start + GridPortableMarshaller.DFLT_HDR_LEN);
-
- int off = in.position();
-
- Class cls = doReadClass(typeId);
-
- // registers class by typeId, at least locally if the cache is not ready yet.
- PortableClassDescriptor desc = ctx.descriptorForClass(cls);
-
- typeId = desc.typeId();
-
- int clsNameLen = in.position() - off;
-
- hdrLen = DFLT_HDR_LEN + clsNameLen;
- }
- else
- hdrLen = DFLT_HDR_LEN;
-
- // Restore state.
- in.position(retPos);
-
- hdrParsed = true;
- }
-
- /**
- * @return Descriptor.
- */
- PortableClassDescriptor descriptor() {
- return desc;
- }
-
- /**
- * @return Unmarshalled value.
- * @throws PortableException In case of error.
- */
- @Nullable Object unmarshal() throws PortableException {
- return unmarshal(false);
- }
-
- /**
- * @param offset Offset in the array.
- * @return Unmarshalled value.
- * @throws PortableException In case of error.
- */
- public Object unmarshal(int offset) throws PortableException {
- in.position(offset);
-
- return in.position() >= 0 ? unmarshal() : null;
- }
-
- /**
- * @param fieldName Field name.
- * @return Unmarshalled value.
- * @throws PortableException In case of error.
- */
- @Nullable Object unmarshalField(String fieldName) throws PortableException {
- return hasField(fieldName) ? unmarshal() : null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Unmarshalled value.
- * @throws PortableException In case of error.
- */
- @Nullable Object unmarshalField(int fieldId) throws PortableException {
- parseHeaderIfNeeded();
-
- return hasField(fieldId) ? unmarshal() : null;
- }
-
- /**
- * Unmarshal field by absolute position.
- *
- * @param pos Absolute position.
- * @return Field value.
- * @throws PortableException In case of error.
- */
- @Nullable Object unmarshalFieldByAbsolutePosition(int pos) throws PortableException {
- parseHeaderIfNeeded();
-
- in.position(pos);
-
- return unmarshal();
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Byte readByte(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(BYTE) == Flag.NULL)
- return null;
-
- return in.readByte();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Short readShort(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(SHORT) == Flag.NULL)
- return null;
-
- return in.readShort();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Integer readInt(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(INT) == Flag.NULL)
- return null;
-
- return in.readInt();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Long readLong(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(LONG) == Flag.NULL)
- return null;
-
- return in.readLong();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Float readFloat(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(FLOAT) == Flag.NULL)
- return null;
-
- return in.readFloat();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Double readDouble(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(DOUBLE) == Flag.NULL)
- return null;
-
- return in.readDouble();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Character readChar(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(CHAR) == Flag.NULL)
- return null;
-
- return in.readChar();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Boolean readBoolean(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(BOOLEAN) == Flag.NULL)
- return null;
-
- return in.readBoolean();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable BigDecimal readDecimal(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(DECIMAL) == Flag.NULL)
- return null;
-
- return doReadDecimal();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable String readString(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(STRING) == Flag.NULL)
- return null;
-
- return doReadString();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable UUID readUuid(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(UUID) == Flag.NULL)
- return null;
-
- return doReadUuid();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Date readDate(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(DATE) == Flag.NULL)
- return null;
-
- return doReadDate();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Timestamp readTimestamp(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(TIMESTAMP) == Flag.NULL)
- return null;
-
- return doReadTimestamp();
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Object readObject(int fieldId) throws PortableException {
- return hasField(fieldId) ? doReadObject() : null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable byte[] readByteArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(BYTE_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadByteArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable short[] readShortArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(SHORT_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadShortArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable int[] readIntArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(INT_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadIntArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable long[] readLongArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(LONG_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadLongArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable float[] readFloatArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(FLOAT_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadFloatArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable double[] readDoubleArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(DOUBLE_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadDoubleArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable char[] readCharArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(CHAR_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadCharArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable boolean[] readBooleanArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(BOOLEAN_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadBooleanArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable BigDecimal[] readDecimalArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(DECIMAL_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadDecimalArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable String[] readStringArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(STRING_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadStringArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable UUID[] readUuidArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(UUID_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadUuidArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Date[] readDateArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(DATE_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadDateArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Timestamp[] readTimestampArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(TIMESTAMP_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadTimestampArray();
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Object[] readObjectArray(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(OBJ_ARR);
-
- if (flag == Flag.NORMAL)
- return doReadObjectArray(true);
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @param cls Collection class.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable <T> Collection<T> readCollection(int fieldId, @Nullable Class<? extends Collection> cls)
- throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(COL);
-
- if (flag == Flag.NORMAL)
- return (Collection<T>)doReadCollection(true, cls);
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @param cls Map class.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Map<?, ?> readMap(int fieldId, @Nullable Class<? extends Map> cls)
- throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(MAP);
-
- if (flag == Flag.NORMAL)
- return doReadMap(true, cls);
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Value.
- * @throws PortableException On case of error.
- */
- @Nullable Map.Entry<?, ?> readMapEntry(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(MAP_ENTRY);
-
- if (flag == Flag.NORMAL)
- return doReadMapEntry(true);
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Portable object.
- * @throws PortableException In case of error.
- */
- @Nullable PortableObject readPortableObject(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(PORTABLE_OBJ) == Flag.NULL)
- return null;
-
- return new PortableObjectImpl(ctx, doReadByteArray(), in.readInt());
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @param cls Class.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Enum<?> readEnum(int fieldId, @Nullable Class<?> cls) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(ENUM) == Flag.NULL)
- return null;
-
- // Revisit: why have we started writing Class for enums in their serialized form?
- if (cls == null)
- cls = doReadClass();
- else
- doReadClass();
-
- Object[] vals = GridEnumCache.get(cls);
-
- return (Enum<?>)vals[in.readInt()];
- }
- else
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @param cls Class.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable Object[] readEnumArray(int fieldId, @Nullable Class<?> cls) throws PortableException {
- if (hasField(fieldId)) {
- Flag flag = checkFlag(ENUM_ARR);
-
- if (flag == Flag.NORMAL) {
- if (cls == null)
- cls = doReadClass();
- else
- doReadClass();
-
- return doReadEnumArray(cls);
- }
- else if (flag == Flag.HANDLE)
- return readHandleField();
- }
-
- return null;
- }
-
- /**
- * @param fieldId Field ID.
- * @return Field class.
- * @throws PortableException In case of error.
- */
- @Nullable Class<?> readClass(int fieldId) throws PortableException {
- if (hasField(fieldId)) {
- if (checkFlag(CLASS) == Flag.NULL)
- return null;
-
- return doReadClass();
- }
-
- return null;
- }
-
- /**
- * @param obj Object.
- */
- void setHandler(Object obj) {
- rCtx.setObjectHandler(start, obj);
- }
-
- /**
- * @param obj Object.
- * @param pos Position.
- */
- void setHandler(Object obj, int pos) {
- rCtx.setObjectHandler(pos, obj);
- }
-
- /**
- * Recreating field value from a handle.
- *
- * @param <T> Field type.
- * @return Field.
- */
- private <T> T readHandleField() {
- int handle = (in.position() - 1) - in.readInt();
-
- Object obj = rCtx.getObjectByHandle(handle);
-
- if (obj == null) {
- in.position(handle);
-
- obj = doReadObject();
- }
-
- return (T)obj;
- }
- /** {@inheritDoc} */
- @Override public byte readByte(String fieldName) throws PortableException {
- Byte val = readByte(fieldId(fieldName));
-
- return val != null ? val : 0;
- }
-
- /** {@inheritDoc} */
- @Override public byte readByte() throws PortableException {
- return in.readByte();
- }
-
- /** {@inheritDoc} */
- @Override public short readShort(String fieldName) throws PortableException {
- Short val = readShort(fieldId(fieldName));
-
- return val != null ? val : 0;
- }
-
- /** {@inheritDoc} */
- @Override public short readShort() throws PortableException {
- return in.readShort();
- }
-
- /** {@inheritDoc} */
- @Override public int readInt(String fieldName) throws PortableException {
- Integer val = readInt(fieldId(fieldName));
-
- return val != null ? val : 0;
- }
-
- /** {@inheritDoc} */
- @Override public int readInt() throws PortableException {
- return in.readInt();
- }
-
- /** {@inheritDoc} */
- @Override public long readLong(String fieldName) throws PortableException {
- Long val = readLong(fieldId(fieldName));
-
- return val != null ? val : 0;
- }
-
- /** {@inheritDoc} */
- @Override public long readLong() throws PortableException {
- return in.readLong();
- }
-
- /** {@inheritDoc} */
- @Override public float readFloat(String fieldName) throws PortableException {
- Float val = readFloat(fieldId(fieldName));
-
- return val != null ? val : 0;
- }
-
- /** {@inheritDoc} */
- @Override public float readFloat() throws PortableException {
- return in.readFloat();
- }
-
- /** {@inheritDoc} */
- @Override public double readDouble(String fieldName) throws PortableException {
- Double val = readDouble(fieldId(fieldName));
-
- return val != null ? val : 0;
- }
-
- /** {@inheritDoc} */
- @Override public double readDouble() throws PortableException {
- return in.readDouble();
- }
-
- /** {@inheritDoc} */
- @Override public char readChar(String fieldName) throws PortableException {
- Character val = readChar(fieldId(fieldName));
-
- return val != null ? val : 0;
- }
-
- /** {@inheritDoc} */
- @Override public char readChar() throws PortableException {
- return in.readChar();
- }
-
- /** {@inheritDoc} */
- @Override public boolean readBoolean(String fieldName) throws PortableException {
- Boolean val = readBoolean(fieldId(fieldName));
-
- return val != null ? val : false;
- }
-
- /** {@inheritDoc} */
- @Override public boolean readBoolean() throws PortableException {
- return in.readBoolean();
- }
-
- /** {@inheritDoc} */
- @Override @Nullable public BigDecimal readDecimal(String fieldName) throws PortableException {
- return readDecimal(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Override @Nullable public BigDecimal readDecimal() throws PortableException {
- if (checkFlag(DECIMAL) == Flag.NULL)
- return null;
-
- return doReadDecimal();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public String readString(String fieldName) throws PortableException {
- return readString(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public String readString() throws PortableException {
- if (checkFlag(STRING) == Flag.NULL)
- return null;
-
- return doReadString();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public UUID readUuid(String fieldName) throws PortableException {
- return readUuid(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public UUID readUuid() throws PortableException {
- if (checkFlag(UUID) == Flag.NULL)
- return null;
-
- return doReadUuid();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Date readDate(String fieldName) throws PortableException {
- return readDate(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Date readDate() throws PortableException {
- if (checkFlag(DATE) == Flag.NULL)
- return null;
-
- return doReadDate();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Timestamp readTimestamp(String fieldName) throws PortableException {
- return readTimestamp(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Timestamp readTimestamp() throws PortableException {
- if (checkFlag(TIMESTAMP) == Flag.NULL)
- return null;
-
- return doReadTimestamp();
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Nullable @Override public <T> T readObject(String fieldName) throws PortableException {
- return (T)readObject(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Override public Object readObject() throws PortableException {
- return doReadObject();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Object readObjectDetached() throws PortableException {
- return unmarshal(true);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public byte[] readByteArray(String fieldName) throws PortableException {
- return readByteArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public byte[] readByteArray() throws PortableException {
- if (checkFlag(BYTE_ARR) == Flag.NULL)
- return null;
-
- return doReadByteArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public short[] readShortArray(String fieldName) throws PortableException {
- return readShortArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public short[] readShortArray() throws PortableException {
- if (checkFlag(SHORT_ARR) == Flag.NULL)
- return null;
-
- return doReadShortArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public int[] readIntArray(String fieldName) throws PortableException {
- return readIntArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public int[] readIntArray() throws PortableException {
- if (checkFlag(INT_ARR) == Flag.NULL)
- return null;
-
- return doReadIntArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public long[] readLongArray(String fieldName) throws PortableException {
- return readLongArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public long[] readLongArray() throws PortableException {
- if (checkFlag(LONG_ARR) == Flag.NULL)
- return null;
-
- return doReadLongArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public float[] readFloatArray(String fieldName) throws PortableException {
- return readFloatArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public float[] readFloatArray() throws PortableException {
- if (checkFlag(FLOAT_ARR) == Flag.NULL)
- return null;
-
- return doReadFloatArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public double[] readDoubleArray(String fieldName) throws PortableException {
- return readDoubleArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public double[] readDoubleArray() throws PortableException {
- if (checkFlag(DOUBLE_ARR) == Flag.NULL)
- return null;
-
- return doReadDoubleArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public char[] readCharArray(String fieldName) throws PortableException {
- return readCharArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public char[] readCharArray() throws PortableException {
- if (checkFlag(CHAR_ARR) == Flag.NULL)
- return null;
-
- return doReadCharArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public boolean[] readBooleanArray(String fieldName) throws PortableException {
- return readBooleanArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public boolean[] readBooleanArray() throws PortableException {
- if (checkFlag(BOOLEAN_ARR) == Flag.NULL)
- return null;
-
- return doReadBooleanArray();
- }
-
- /** {@inheritDoc} */
- @Override @Nullable public BigDecimal[] readDecimalArray(String fieldName) throws PortableException {
- return readDecimalArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Override @Nullable public BigDecimal[] readDecimalArray() throws PortableException {
- if (checkFlag(DECIMAL_ARR) == Flag.NULL)
- return null;
-
- return doReadDecimalArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public String[] readStringArray(String fieldName) throws PortableException {
- return readStringArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public String[] readStringArray() throws PortableException {
- if (checkFlag(STRING_ARR) == Flag.NULL)
- return null;
-
- return doReadStringArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public UUID[] readUuidArray(String fieldName) throws PortableException {
- return readUuidArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public UUID[] readUuidArray() throws PortableException {
- if (checkFlag(UUID_ARR) == Flag.NULL)
- return null;
-
- return doReadUuidArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Date[] readDateArray(String fieldName) throws PortableException {
- return readDateArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Timestamp[] readTimestampArray(String fieldName) throws PortableException {
- return readTimestampArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Date[] readDateArray() throws PortableException {
- if (checkFlag(DATE_ARR) == Flag.NULL)
- return null;
-
- return doReadDateArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Timestamp[] readTimestampArray() throws PortableException {
- if (checkFlag(TIMESTAMP_ARR) == Flag.NULL)
- return null;
-
- return doReadTimestampArray();
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Object[] readObjectArray(String fieldName) throws PortableException {
- return readObjectArray(fieldId(fieldName));
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Object[] readObjectArray() throws PortableException {
- if (checkFlag(OBJ_ARR) == Flag.NULL)
- return null;
-
- return doReadObjectArray(true);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <T> Collection<T> readCollection(String fieldName) throws PortableException {
- return readCollection(fieldId(fieldName), null);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <T> Collection<T> readCollection() throws PortableException {
- if (checkFlag(COL) == Flag.NULL)
- return null;
-
- return (Collection<T>)doReadCollection(true, null);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <T> Collection<T> readCollection(String fieldName,
- Class<? extends Collection<T>> colCls) throws PortableException {
- return readCollection(fieldId(fieldName), colCls);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <T> Collection<T> readCollection(Class<? extends Collection<T>> colCls)
- throws PortableException {
- if (checkFlag(COL) == Flag.NULL)
- return null;
-
- return (Collection<T>)doReadCollection(true, colCls);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <K, V> Map<K, V> readMap(String fieldName) throws PortableException {
- return (Map<K, V>)readMap(fieldId(fieldName), null);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <K, V> Map<K, V> readMap() throws PortableException {
- if (checkFlag(MAP) == Flag.NULL)
- return null;
-
- return (Map<K, V>)doReadMap(true, null);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <K, V> Map<K, V> readMap(String fieldName, Class<? extends Map<K, V>> mapCls)
- throws PortableException {
- return (Map<K, V>)readMap(fieldId(fieldName), mapCls);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <K, V> Map<K, V> readMap(Class<? extends Map<K, V>> mapCls)
- throws PortableException {
- if (checkFlag(MAP) == Flag.NULL)
- return null;
-
- return (Map<K, V>)doReadMap(true, mapCls);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <T extends Enum<?>> T readEnum(String fieldName)
- throws PortableException {
- return (T)readEnum(fieldId(fieldName), null);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <T extends Enum<?>> T readEnum() throws PortableException {
- if (checkFlag(ENUM) == Flag.NULL)
- return null;
-
- Class cls = doReadClass();
-
- return (T)doReadEnum(cls);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <T extends Enum<?>> T[] readEnumArray(String fieldName)
- throws PortableException {
- return (T[])readEnumArray(fieldId(fieldName), null);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public <T extends Enum<?>> T[] readEnumArray() throws PortableException {
- if (checkFlag(ENUM_ARR) == Flag.NULL)
- return null;
-
- Class cls = doReadClass();
-
- return (T[])doReadEnumArray(cls);
- }
-
- /**
- * Ensure that type flag is either null or contains expected value.
- *
- * @param expFlag Expected value.
- * @return Flag.
- * @throws PortableException If flag is neither null, nor expected.
- */
- private Flag checkFlag(byte expFlag) {
- byte flag = in.readByte();
-
- if (flag == NULL)
- return Flag.NULL;
- else if (flag == HANDLE)
- return Flag.HANDLE;
- else if (flag != expFlag) {
- int pos = in.position() - 1;
-
- throw new PortableException("Unexpected flag value [pos=" + pos + ", expected=" + expFlag +
- ", actual=" + flag + ']');
- }
-
- return Flag.NORMAL;
- }
-
- /**
- * @param fieldName Field name.
- * @return {@code True} if field is set.
- */
- public boolean hasField(String fieldName) {
- return hasField(fieldId(fieldName));
- }
-
- /**
- * @param fieldId Field ID.
- * @return {@code True} if field is set.
- */
- private boolean hasField(int fieldId) {
- return fieldOffset(fieldId) != 0;
- }
-
- /** {@inheritDoc} */
- @Override public PortableRawReader rawReader() {
- in.position(rawOff);
-
- return this;
- }
-
- /**
- * @return Unmarshalled value.
- * @throws PortableException In case of error.
- */
- @Nullable private Object unmarshal(boolean detach) throws PortableException {
- int start = in.position();
-
- byte flag = in.readByte();
-
- switch (flag) {
- case NULL:
- return null;
-
- case HANDLE:
- int handle = start - in.readInt();
-
- PortableObject handledPo = rCtx.getPortableByHandle(handle);
-
- if (handledPo != null)
- return handledPo;
-
- in.position(handle);
-
- return unmarshal();
-
- case OBJ:
- PortableUtils.checkProtocolVersion(in.readByte());
-
- PortableObjectEx po;
-
- if (detach) {
- in.position(start + GridPortableMarshaller.TOTAL_LEN_POS);
-
- int len = in.readInt();
-
- in.position(start);
-
- po = new PortableObjectImpl(ctx, in.readByteArray(len), 0);
- }
- else
- po = in.offheapPointer() > 0
- ? new PortableObjectOffheapImpl(ctx, in.offheapPointer(), start,
- in.remaining() + in.position())
- : new PortableObjectImpl(ctx, in.array(), start);
-
- rCtx.setPortableHandler(start, po);
-
- in.position(start + po.length());
-
- return po;
-
- case BYTE:
- return in.readByte();
-
- case SHORT:
- return in.readShort();
-
- case INT:
- return in.readInt();
-
- case LONG:
- return in.readLong();
-
- case FLOAT:
- return in.readFloat();
-
- case DOUBLE:
- return in.readDouble();
-
- case CHAR:
- return in.readChar();
-
- case BOOLEAN:
- return in.readBoolean();
-
- case DECIMAL:
- return doReadDecimal();
-
- case STRING:
- return doReadString();
-
- case UUID:
- return doReadUuid();
-
- case DATE:
- return doReadDate();
-
- case TIMESTAMP:
- return doReadTimestamp();
-
- case BYTE_ARR:
- return doReadByteArray();
-
- case SHORT_ARR:
- return doReadShortArray();
-
- case INT_ARR:
- return doReadIntArray();
-
- case LONG_ARR:
- return doReadLongArray();
-
- case FLOAT_ARR:
- return doReadFloatArray();
-
- case DOUBLE_ARR:
- return doReadDoubleArray();
-
- case CHAR_ARR:
- return doReadCharArray();
-
- case BOOLEAN_ARR:
- return doReadBooleanArray();
-
- case DECIMAL_ARR:
- return doReadDecimalArray();
-
- case STRING_ARR:
- return doReadStringArray();
-
- case UUID_ARR:
- return doReadUuidArray();
-
- case DATE_ARR:
- return doReadDateArray();
-
- case TIMESTAMP_ARR:
- return doReadTimestampArray();
-
- case OBJ_ARR:
- return doReadObjectArray(false);
-
- case COL:
- return doReadCollection(false, null);
-
- case MAP:
- return doReadMap(false, null);
-
- case MAP_ENTRY:
- return doReadMapEntry(false);
-
- case PORTABLE_OBJ:
- return doReadPortableObject();
-
- case ENUM:
- return doReadEnum(doReadClass());
-
- case ENUM_ARR:
- return doReadEnumArray(doReadClass());
-
- case CLASS:
- return doReadClass();
-
- case OPTM_MARSH:
- int len = in.readInt();
-
- ByteArrayInputStream input = new ByteArrayInputStream(in.array(), in.position(), len);
-
- Object obj;
-
- try {
- obj = ctx.optimizedMarsh().unmarshal(input, null);
- }
- catch (IgniteCheckedException e) {
- throw new PortableException("Failed to unmarshal object with optmMarsh marshaller", e);
- }
-
- return obj;
-
- default:
- throw new PortableException("Invalid flag value: " + flag);
- }
- }
-
- /**
- * @return Value.
- */
- private BigDecimal doReadDecimal() {
- int scale = in.readInt();
- byte[] mag = doReadByteArray();
-
- BigInteger intVal = new BigInteger(mag);
-
- if (scale < 0) {
- scale &= 0x7FFFFFFF;
-
- intVal = intVal.negate();
- }
-
- return new BigDecimal(intVal, scale);
- }
-
- /**
- * @return Value.
- */
- private String doReadString() {
- if (in.readBoolean()) {
- if (!in.hasArray())
- return new String(doReadByteArray(), UTF_8);
-
- int strLen = in.readInt();
- int strOff = in.position();
-
- String res = new String(in.array(), strOff, strLen, UTF_8);
-
- in.position(in.position() + strLen);
-
- return res;
- }
- else
- return String.valueOf(doReadCharArray());
- }
-
- /**
- * @return Value.
- */
- private UUID doReadUuid() {
- return new UUID(in.readLong(), in.readLong());
- }
-
- /**
- * @return Value.
- */
- private Date doReadDate() {
- long time = in.readLong();
-
- return new Date(time);
- }
-
- /**
- * @return Value.
- */
- private Timestamp doReadTimestamp() {
- long time = in.readLong();
- int nanos = in.readInt();
-
- Timestamp ts = new Timestamp(time);
-
- ts.setNanos(ts.getNanos() + nanos);
-
- return ts;
- }
-
- /**
- * @return Object.
- * @throws PortableException In case of error.
- */
- @Nullable private Object doReadObject() throws PortableException {
- PortableReaderExImpl reader = new PortableReaderExImpl(ctx, in, in.position(), ldr, rCtx);
-
- return reader.deserialize();
- }
-
- /**
- * @return Deserialized object.
- * @throws PortableException If failed.
- */
- @Nullable Object deserialize() throws PortableException {
- Object obj;
-
- byte flag = in.readByte();
-
- switch (flag) {
- case NULL:
- obj = null;
-
- break;
-
- case HANDLE:
- int handle = start - in.readInt();
-
- obj = rCtx.getObjectByHandle(handle);
-
- if (obj == null) {
- int retPos = in.position();
-
- in.position(handle);
-
- obj = doReadObject();
-
- in.position(retPos);
- }
-
- break;
-
- case OBJ:
- parseHeaderIfNeeded();
-
- assert typeId != UNREGISTERED_TYPE_ID;
-
- PortableUtils.checkProtocolVersion(in.readByte());
-
- boolean userType = PortableUtils.isUserType(this.readShort());
-
- // Skip typeId and hash code.
- in.position(in.position() + 8);
-
- desc = ctx.descriptorForTypeId(userType, typeId, ldr);
-
- int len = in.readInt();
-
- in.position(start + hdrLen);
-
- if (desc == null)
- throw new PortableInvalidClassException("Unknown type ID: " + typeId);
-
- obj = desc.read(this);
-
- in.position(start + len);
-
- break;
-
- case BYTE:
- obj = in.readByte();
-
- break;
-
- case SHORT:
- obj = in.readShort();
-
- break;
-
- case INT:
- obj = in.readInt();
-
- break;
-
- case LONG:
- obj = in.readLong();
-
- break;
-
- case FLOAT:
- obj = in.readFloat();
-
- break;
-
- case DOUBLE:
- obj = in.readDouble();
-
- break;
-
- case CHAR:
- obj = in.readChar();
-
- break;
-
- case BOOLEAN:
- obj = in.readBoolean();
-
- break;
-
- case DECIMAL:
- obj = doReadDecimal();
-
- break;
-
- case STRING:
- obj = doReadString();
-
- break;
-
- case UUID:
- obj = doReadUuid();
-
- break;
-
- case DATE:
- obj = doReadDate();
-
- break;
-
- case TIMESTAMP:
- obj = doReadTimestamp();
-
- break;
-
- case BYTE_ARR:
- obj = doReadByteArray();
-
- break;
-
- case SHORT_ARR:
- obj = doReadShortArray();
-
- break;
-
- case INT_ARR:
- obj = doReadIntArray();
-
- break;
-
- case LONG_ARR:
- obj = doReadLongArray();
-
- break;
-
- case FLOAT_ARR:
- obj = doReadFloatArray();
-
- break;
-
- case DOUBLE_ARR:
- obj = doReadDoubleArray();
-
- break;
-
- case CHAR_ARR:
- obj = doReadCharArray();
-
- break;
-
- case BOOLEAN_ARR:
- obj = doReadBooleanArray();
-
- break;
-
- case DECIMAL_ARR:
- obj = doReadDecimalArray();
-
- break;
-
- case STRING_ARR:
- obj = doReadStringArray();
-
- break;
-
- case UUID_ARR:
- obj = doReadUuidArray();
-
- break;
-
- case DATE_ARR:
- obj = doReadDateArray();
-
- break;
-
- case TIMESTAMP_ARR:
- obj = doReadTimestampArray();
-
- break;
-
- case OBJ_ARR:
- obj = doReadObjectArray(true);
-
- break;
-
- case COL:
- obj = doReadCollection(true, null);
-
- break;
-
- case MAP:
- obj = doReadMap(true, null);
-
- break;
-
- case MAP_ENTRY:
- obj = doReadMapEntry(true);
-
- break;
-
- case PORTABLE_OBJ:
- obj = doReadPortableObject();
-
- ((PortableObjectImpl)obj).context(ctx);
-
- if (!GridPortableMarshaller.KEEP_PORTABLES.get())
- obj = ((PortableObject)obj).deserialize();
-
- break;
-
- case ENUM:
- obj = doReadEnum(doReadClass());
-
- break;
-
- case ENUM_ARR:
- obj = doReadEnumArray(doReadClass());
-
- break;
-
- case CLASS:
- obj = doReadClass();
-
- break;
-
- case OPTM_MARSH:
- int dataLen = in.readInt();
-
- ByteArrayInputStream input = new ByteArrayInputStream(in.array(), in.position(), dataLen);
-
- try {
- obj = ctx.optimizedMarsh().unmarshal(input, null);
- }
- catch (IgniteCheckedException e) {
- throw new PortableException("Failed to unmarshal object with optimized marshaller", e);
- }
-
- in.position(in.position() + dataLen);
-
- break;
-
- default:
- throw new PortableException("Invalid flag value: " + flag);
- }
-
- return obj;
- }
-
- /**
- * @return Value.
- */
- private byte[] doReadByteArray() {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- byte[] arr = in.readByteArray(len);
-
- setHandler(arr, hPos);
-
- return arr;
- }
-
- /**
- * @return Value.
- */
- private short[] doReadShortArray() {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- short[] arr = in.readShortArray(len);
-
- setHandler(arr, hPos);
-
- return arr;
- }
-
- /**
- * @return Value.
- */
- private int[] doReadIntArray() {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- int[] arr = in.readIntArray(len);
-
- setHandler(arr, hPos);
-
- return arr;
- }
-
- /**
- * @return Value.
- */
- private long[] doReadLongArray() {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- long[] arr = in.readLongArray(len);
-
- setHandler(arr, hPos);
-
- return arr;
- }
-
- /**
- * @return Value.
- */
- private float[] doReadFloatArray() {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- float[] arr = in.readFloatArray(len);
-
- setHandler(arr, hPos);
-
- return arr;
- }
-
- /**
- * @return Value.
- */
- private double[] doReadDoubleArray() {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- double[] arr = in.readDoubleArray(len);
-
- setHandler(arr, hPos);
-
- return arr;
- }
-
- /**
- * @return Value.
- */
- private char[] doReadCharArray() {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- char[] arr = in.readCharArray(len);
-
- setHandler(arr, hPos);
-
- return arr;
- }
-
- /**
- * @return Value.
- */
- private boolean[] doReadBooleanArray() {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- boolean[] arr = in.readBooleanArray(len);
-
- setHandler(arr, hPos);
-
- return arr;
- }
-
- /**
- * @return Value.
- * @throws PortableException In case of error.
- */
- private BigDecimal[] doReadDecimalArray() throws PortableException {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- BigDecimal[] arr = new BigDecimal[len];
-
- setHandler(arr, hPos);
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == NULL)
- arr[i] = null;
- else {
- if (flag != DECIMAL)
- throw new PortableException("Invalid flag value: " + flag);
-
- arr[i] = doReadDecimal();
- }
- }
-
- return arr;
- }
-
- /**
- * @return Value.
- * @throws PortableException In case of error.
- */
- private String[] doReadStringArray() throws PortableException {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- String[] arr = new String[len];
-
- setHandler(arr, hPos);
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == NULL)
- arr[i] = null;
- else {
- if (flag != STRING)
- throw new PortableException("Invalid flag value: " + flag);
-
- arr[i] = doReadString();
- }
- }
-
- return arr;
- }
-
- /**
- * @return Value.
- * @throws PortableException In case of error.
- */
- private UUID[] doReadUuidArray() throws PortableException {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- UUID[] arr = new UUID[len];
-
- setHandler(arr, hPos);
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == NULL)
- arr[i] = null;
- else {
- if (flag != UUID)
- throw new PortableException("Invalid flag value: " + flag);
-
- arr[i] = doReadUuid();
- }
- }
-
- return arr;
- }
-
- /**
- * @return Value.
- * @throws PortableException In case of error.
- */
- private Date[] doReadDateArray() throws PortableException {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- Date[] arr = new Date[len];
-
- setHandler(arr, hPos);
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == NULL)
- arr[i] = null;
- else {
- if (flag != DATE)
- throw new PortableException("Invalid flag value: " + flag);
-
- arr[i] = doReadDate();
- }
- }
-
- return arr;
- }
-
- /**
- * @return Value.
- * @throws PortableException In case of error.
- */
- private Timestamp[] doReadTimestampArray() throws PortableException {
- int hPos = in.position() - 1;
-
- int len = in.readInt();
-
- Timestamp[] arr = new Timestamp[len];
-
- setHandler(arr, hPos);
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == NULL)
- arr[i] = null;
- else {
- if (flag != TIMESTAMP)
- throw new PortableException("Invalid flag value: " + flag);
-
- arr[i] = doReadTimestamp();
- }
- }
-
- return arr;
- }
-
- /**
- * @param deep Deep flag.
- * @return Value.
- * @throws PortableException In case of error.
- */
- private Object[] doReadObjectArray(boolean deep) throws PortableException {
- int hPos = in.position() - 1;
-
- Class compType = doReadClass();
-
- int len = in.readInt();
-
- Object[] arr = deep ? (Object[])Array.newInstance(compType, len) : new Object[len];
-
- setHandler(arr, hPos);
-
- for (int i = 0; i < len; i++)
- arr[i] = deep ? doReadObject() : unmarshal();
-
- return arr;
- }
-
- /**
- * @param deep Deep flag.
- * @param cls Collection class.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @SuppressWarnings("unchecked")
- private Collection<?> doReadCollection(boolean deep, @Nullable Class<? extends Collection> cls)
- throws PortableException {
- int hPos = in.position() - 1;
-
- int size = in.readInt();
-
- assert size >= 0;
-
- byte colType = in.readByte();
-
- Collection<Object> col;
-
- if (cls != null) {
- try {
- Constructor<? extends Collection> cons = cls.getConstructor();
-
- col = cons.newInstance();
- }
- catch (NoSuchMethodException ignored) {
- throw new PortableException("Collection class doesn't have public default constructor: " +
- cls.getName());
- }
- catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
- throw new PortableException("Failed to instantiate collection: " + cls.getName(), e);
- }
- }
- else {
- switch (colType) {
- case ARR_LIST:
- col = new ArrayList<>(size);
-
- break;
-
- case LINKED_LIST:
- col = new LinkedList<>();
-
- break;
-
- case HASH_SET:
- col = U.newHashSet(size);
-
- break;
-
- case LINKED_HASH_SET:
- col = U.newLinkedHashSet(size);
-
- break;
-
- case TREE_SET:
- col = new TreeSet<>();
-
- break;
-
- case CONC_SKIP_LIST_SET:
- col = new ConcurrentSkipListSet<>();
-
- break;
-
- case USER_SET:
- col = U.newHashSet(size);
-
- break;
-
- case USER_COL:
- col = new ArrayList<>(size);
-
- break;
-
- default:
- throw new PortableException("Invalid collection type: " + colType);
- }
- }
-
- setHandler(col, hPos);
-
- for (int i = 0; i < size; i++)
- col.add(deep ? doReadObject() : unmarshal());
-
- return col;
- }
-
- /**
- * @param deep Deep flag.
- * @param cls Map class.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @SuppressWarnings("unchecked")
- private Map<?, ?> doReadMap(boolean deep, @Nullable Class<? extends Map> cls)
- throws PortableException {
- int hPos = in.position() - 1;
-
- int size = in.readInt();
-
- assert size >= 0;
-
- byte mapType = in.readByte();
-
- Map<Object, Object> map;
-
- if (cls != null) {
- try {
- Constructor<? extends Map> cons = cls.getConstructor();
-
- map = cons.newInstance();
- }
- catch (NoSuchMethodException ignored) {
- throw new PortableException("Map class doesn't have public default constructor: " +
- cls.getName());
- }
- catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
- throw new PortableException("Failed to instantiate map: " + cls.getName(), e);
- }
- }
- else {
- switch (mapType) {
- case HASH_MAP:
- map = U.newHashMap(size);
-
- break;
-
- case LINKED_HASH_MAP:
- map = U.newLinkedHashMap(size);
-
- break;
-
- case TREE_MAP:
- map = new TreeMap<>();
-
- break;
-
- case CONC_HASH_MAP:
- map = new ConcurrentHashMap<>(size);
-
- break;
-
- case USER_COL:
- map = U.newHashMap(size);
-
- break;
-
- case PROPERTIES_MAP:
- map = new Properties();
-
- break;
-
- default:
- throw new PortableException("Invalid map type: " + mapType);
- }
- }
-
- setHandler(map, hPos);
-
- for (int i = 0; i < size; i++)
- map.put(deep ? doReadObject() : unmarshal(), deep ? doReadObject() : unmarshal());
-
- return map;
- }
-
- /**
- * @param deep Deep flag.
- * @return Value.
- * @throws PortableException In case of error.
- */
- private Map.Entry<?, ?> doReadMapEntry(boolean deep) throws PortableException {
- int hPos = in.position() - 1;
-
- Object val1 = deep ? doReadObject() : unmarshal();
- Object val2 = deep ? doReadObject() : unmarshal();
-
- GridMapEntry entry = new GridMapEntry<>(val1, val2);
-
- setHandler(entry, hPos);
-
- return entry;
- }
-
- /**
- * @return Value.
- */
- private PortableObject doReadPortableObject() {
- if (in.offheapPointer() > 0) {
- int len = in.readInt();
-
- int pos = in.position();
-
- in.position(in.position() + len);
-
- int start = in.readInt();
-
- return new PortableObjectOffheapImpl(ctx, in.offheapPointer() + pos, start, len);
- }
- else {
- byte[] arr = doReadByteArray();
- int start = in.readInt();
-
- return new PortableObjectImpl(ctx, arr, start);
- }
- }
-
- /**
- * @param cls Enum class.
- * @return Value.
- */
- private Enum<?> doReadEnum(Class<?> cls) throws PortableException {
- if (!cls.isEnum())
- throw new PortableException("Class does not represent enum type: " + cls.getName());
-
- int ord = in.readInt();
-
- return ord >= 0 ? (Enum<?>)GridEnumCache.get(cls)[ord] : null;
- }
-
- /**
- * @param cls Enum class.
- * @return Value.
- */
- private Object[] doReadEnumArray(Class<?> cls) throws PortableException {
- int len = in.readInt();
-
- Object[] arr = (Object[])Array.newInstance(cls, len);
-
- for (int i = 0; i < len; i++) {
- byte flag = in.readByte();
-
- if (flag == NULL)
- arr[i] = null;
- else
- arr[i] = doReadEnum(doReadClass());
- }
-
- return arr;
- }
-
- /**
- * @return Value.
- */
- private Class doReadClass() throws PortableException {
- return doReadClass(in.readInt());
- }
-
- /**
- * @param typeId Type id.
- * @return Value.
- */
- private Class doReadClass(int typeId) throws PortableException {
- Class cls;
-
- if (typeId == OBJECT_TYPE_ID)
- return Object.class;
-
- if (typeId != UNREGISTERED_TYPE_ID)
- cls = ctx.descriptorForTypeId(true, typeId, ldr).describedClass();
- else {
- byte flag = in.readByte();
-
- if (flag != STRING)
- throw new PortableException("No class definition for typeId: " + typeId);
-
- String clsName = doReadString();
-
- try {
- cls = U.forName(clsName, ldr);
- }
- catch (ClassNotFoundException e) {
- throw new PortableInvalidClassException("Failed to load the class: " + clsName, e);
- }
-
- // forces registering of class by type id, at least locally
- ctx.descriptorForClass(cls);
- }
-
- return cls;
- }
-
- /**
- * @param name Field name.
- * @return Field offset.
- */
- private int fieldId(String name) {
- assert name != null;
-
- parseHeaderIfNeeded();
-
- assert typeId != UNREGISTERED_TYPE_ID;
-
- if (idMapper == null)
- idMapper = ctx.userTypeIdMapper(typeId);
-
- return idMapper.fieldId(typeId, name);
- }
-
- /**
- * Create schema.
- *
- * @return Schema.
- */
- public PortableSchema createSchema() {
- parseHeaderIfNeeded();
-
- LinkedHashMap<Integer, Integer> fields = new LinkedHashMap<>();
-
- int searchPos = footerStart;
- int searchEnd = searchPos + footerLen;
-
- int idx = 0;
-
- while (searchPos < searchEnd) {
- int fieldId = in.readIntPositioned(searchPos);
-
- fields.put(fieldId, idx++);
-
- searchPos += 4 + offsetSize;
- }
-
- return new PortableSchema(fields);
- }
-
- /**
- * @param id Field ID.
- * @return Field offset.
- */
- private int fieldOffset(int id) {
- assert hdrLen != 0;
-
- if (footerLen == 0)
- return 0;
-
- int searchPos = footerStart;
- int searchTail = searchPos + footerLen;
-
- if (hasLowFieldsCount(footerLen)) {
- while (true) {
- if (searchPos >= searchTail)
- return 0;
-
- int id0 = in.readIntPositioned(searchPos);
-
- if (id0 == id) {
- int pos = start + PortableUtils.fieldOffsetRelative(in, searchPos + 4, offsetSize);
-
- in.position(pos);
-
- return pos;
- }
-
- searchPos += 4 + offsetSize;
- }
- }
- else {
- PortableSchema schema0 = schema;
-
- if (schema0 == null) {
- schema0 = ctx.schemaRegistry(typeId).schema(schemaId);
-
- if (schema0 == null) {
- schema0 = createSchema();
-
- ctx.schemaRegistry(typeId).addSchema(schemaId, schema0);
- }
-
- schema = schema0;
- }
-
- int order = schema.order(id);
-
- if (order != PortableSchema.ORDER_NOT_FOUND) {
- int offsetPos = footerStart + order * (4 + offsetSize) + 4;
-
- int pos = start + PortableUtils.fieldOffsetRelative(in, offsetPos, offsetSize);
-
- in.position(pos);
-
- return pos;
- }
- else
- return 0;
- }
- }
-
- /**
- * Check whether object has low amount of fields.
- *
- * @param footerLen Footer length.
- */
- private boolean hasLowFieldsCount(int footerLen) {
- assert hdrParsed;
-
- return footerLen < (FIELD_DESC_LEN << 4);
- }
-
- /** {@inheritDoc} */
- @Override public int readUnsignedByte() throws IOException {
- return readByte() & 0xff;
- }
-
- /** {@inheritDoc} */
- @Override public int readUnsignedShort() throws IOException {
- return readShort() & 0xffff;
- }
-
- /** {@inheritDoc} */
- @Override public String readLine() throws IOException {
- SB sb = new SB();
-
- int b;
-
- while ((b = read()) >= 0) {
- char c = (char)b;
-
- switch (c) {
- case '\n':
- return sb.toString();
-
- case '\r':
- b = read();
-
- if (b < 0 || b == '\n')
- return sb.toString();
- else
- sb.a((char)b);
-
- break;
-
- default:
- sb.a(c);
- }
- }
-
- return sb.toString();
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("ConstantConditions")
- @NotNull @Override public String readUTF() throws IOException {
- return readString();
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("NullableProblems")
- @Override public void readFully(byte[] b) throws IOException {
- readFully(b, 0, b.length);
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("NullableProblems")
- @Override public void readFully(byte[] b, int off, int len) throws IOException {
- int cnt = in.read(b, off, len);
-
- if (cnt < len)
- throw new EOFException();
- }
-
- /** {@inheritDoc} */
- @Override public int skipBytes(int n) throws IOException {
- int toSkip = Math.min(in.remaining(), n);
-
- in.position(in.position() + toSkip);
-
- return toSkip;
- }
-
- /** {@inheritDoc} */
- @Override public int read() throws IOException {
- return readByte();
- }
-
- /** {@inheritDoc} */
- @Override public int read(byte[] b) throws IOException {
- return read(b, 0, b.length);
- }
-
- /** {@inheritDoc} */
- @Override public int read(byte[] b, int off, int len) throws IOException {
- return in.read(b, off, len);
- }
-
- /** {@inheritDoc} */
- @Override public long skip(long n) throws IOException {
- return skipBytes((int) n);
- }
-
- /** {@inheritDoc} */
- @Override public int available() throws IOException {
- return in.remaining();
- }
-
- /** {@inheritDoc} */
- @Override public void close() throws IOException {
- // No-op.
- }
-
- /**
- * Flag.
- */
- private static enum Flag {
- /** Null. */
- NULL,
-
- /** Handle. */
- HANDLE,
-
- /** Regular. */
- NORMAL
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
index e0368b6..fe97e7e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
@@ -21,8 +21,8 @@ import org.apache.ignite.internal.portable.builder.PortableLazyValue;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryObject;
import org.jetbrains.annotations.Nullable;
import org.jsr166.ConcurrentHashMap8;
@@ -122,7 +122,7 @@ public class PortableUtils {
* @param writer Writer.
* @param userType User type flag.
*/
- public static void writeFlags(PortableWriterExImpl writer, boolean userType) {
+ public static void writeFlags(BinaryWriterExImpl writer, boolean userType) {
short val = 0;
if (userType)
@@ -244,7 +244,7 @@ public class PortableUtils {
* @param writer W
* @param val Value.
*/
- public static void writePlainObject(PortableWriterExImpl writer, Object val) {
+ public static void writePlainObject(BinaryWriterExImpl writer, Object val) {
Byte flag = PLAIN_CLASS_TO_FLAG.get(val.getClass());
if (flag == null)
@@ -495,7 +495,7 @@ public class PortableUtils {
public static boolean isPortableType(Class<?> cls) {
assert cls != null;
- return PortableObject.class.isAssignableFrom(cls) ||
+ return BinaryObject.class.isAssignableFrom(cls) ||
PORTABLE_CLS.contains(cls) ||
cls.isEnum() ||
(cls.isArray() && cls.getComponentType().isEnum());
@@ -544,7 +544,7 @@ public class PortableUtils {
*/
public static void checkProtocolVersion(byte protoVer) {
if (PROTO_VER != protoVer)
- throw new PortableException("Unsupported protocol version: " + protoVer);
+ throw new BinaryObjectException("Unsupported protocol version: " + protoVer);
}
/**
@@ -557,7 +557,7 @@ public class PortableUtils {
* @param clsName Class name (optional).
* @return Position where length should be written.
*/
- public static int writeHeader(PortableWriterExImpl writer, boolean usrTyp, int typeId, int hashCode,
+ public static int writeHeader(BinaryWriterExImpl writer, boolean usrTyp, int typeId, int hashCode,
@Nullable String clsName) {
writer.doWriteByte(GridPortableMarshaller.OBJ);
writer.doWriteByte(GridPortableMarshaller.PROTO_VER);
[10/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinity.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinity.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinity.java
index 0d2098b..c4e0350 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinity.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinity.java
@@ -25,8 +25,8 @@ import org.apache.ignite.cache.affinity.Affinity;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
@@ -114,7 +114,7 @@ public class PlatformAffinity extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected long processInStreamOutLong(int type, PortableRawReaderEx reader) throws IgniteCheckedException {
+ @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException {
switch (type) {
case OP_PARTITION:
return aff.partition(reader.readObjectDetached());
@@ -165,7 +165,7 @@ public class PlatformAffinity extends PlatformAbstractTarget {
/** {@inheritDoc} */
@SuppressWarnings({"IfMayBeConditional", "ConstantConditions"})
- @Override protected void processInStreamOutStream(int type, PortableRawReaderEx reader, PortableRawWriterEx writer)
+ @Override protected void processInStreamOutStream(int type, BinaryRawReaderEx reader, BinaryRawWriterEx writer)
throws IgniteCheckedException {
switch (type) {
case OP_PRIMARY_PARTITIONS: {
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformAbstractQueryCursor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformAbstractQueryCursor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformAbstractQueryCursor.java
index 6c2c873..8c24d23 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformAbstractQueryCursor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformAbstractQueryCursor.java
@@ -19,7 +19,7 @@ package org.apache.ignite.internal.processors.platform.cache.query;
import java.util.Iterator;
import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.cache.query.QueryCursorEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
import org.apache.ignite.internal.processors.platform.PlatformContext;
@@ -62,7 +62,7 @@ public abstract class PlatformAbstractQueryCursor<T> extends PlatformAbstractTar
}
/** {@inheritDoc} */
- @Override protected void processOutStream(int type, final PortableRawWriterEx writer) throws IgniteCheckedException {
+ @Override protected void processOutStream(int type, final BinaryRawWriterEx writer) throws IgniteCheckedException {
switch (type) {
case OP_GET_BATCH: {
assert iter != null : "iterator() has not been called";
@@ -157,7 +157,7 @@ public abstract class PlatformAbstractQueryCursor<T> extends PlatformAbstractTar
* @param writer Writer.
* @param val Value.
*/
- protected abstract void write(PortableRawWriterEx writer, T val);
+ protected abstract void write(BinaryRawWriterEx writer, T val);
/**
* Query cursor consumer.
@@ -167,7 +167,7 @@ public abstract class PlatformAbstractQueryCursor<T> extends PlatformAbstractTar
private final PlatformAbstractQueryCursor<T> cursor;
/** Writer. */
- private final PortableRawWriterEx writer;
+ private final BinaryRawWriterEx writer;
/** Count. */
private int cnt;
@@ -177,7 +177,7 @@ public abstract class PlatformAbstractQueryCursor<T> extends PlatformAbstractTar
*
* @param writer Writer.
*/
- public Consumer(PlatformAbstractQueryCursor<T> cursor, PortableRawWriterEx writer) {
+ public Consumer(PlatformAbstractQueryCursor<T> cursor, BinaryRawWriterEx writer) {
this.cursor = cursor;
this.writer = writer;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryRemoteFilter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryRemoteFilter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryRemoteFilter.java
index 71aa38c..9f67118 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryRemoteFilter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryRemoteFilter.java
@@ -18,7 +18,7 @@
package org.apache.ignite.internal.processors.platform.cache.query;
import org.apache.ignite.Ignite;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;
@@ -115,7 +115,7 @@ public class PlatformContinuousQueryRemoteFilter implements PlatformContinuousQu
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(filter);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformFieldsQueryCursor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformFieldsQueryCursor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformFieldsQueryCursor.java
index 44a4f14..035e927 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformFieldsQueryCursor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformFieldsQueryCursor.java
@@ -18,7 +18,7 @@
package org.apache.ignite.internal.processors.platform.cache.query;
import java.util.List;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.cache.query.QueryCursorEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
@@ -38,7 +38,7 @@ public class PlatformFieldsQueryCursor extends PlatformAbstractQueryCursor<List<
}
/** {@inheritDoc} */
- @Override protected void write(PortableRawWriterEx writer, List vals) {
+ @Override protected void write(BinaryRawWriterEx writer, List vals) {
assert vals != null;
writer.writeInt(vals.size());
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformQueryCursor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformQueryCursor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformQueryCursor.java
index 410e4de..fe94e65 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformQueryCursor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformQueryCursor.java
@@ -18,7 +18,7 @@
package org.apache.ignite.internal.processors.platform.cache.query;
import javax.cache.Cache;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.cache.query.QueryCursorEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
@@ -38,7 +38,7 @@ public class PlatformQueryCursor extends PlatformAbstractQueryCursor<Cache.Entry
}
/** {@inheritDoc} */
- @Override protected void write(PortableRawWriterEx writer, Cache.Entry val) {
+ @Override protected void write(BinaryRawWriterEx writer, Cache.Entry val) {
writer.writeObjectDetached(val.getKey());
writer.writeObjectDetached(val.getValue());
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/store/PlatformCacheStoreCallback.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/store/PlatformCacheStoreCallback.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/store/PlatformCacheStoreCallback.java
index a741f0f..45110ce 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/store/PlatformCacheStoreCallback.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/store/PlatformCacheStoreCallback.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.processors.platform.cache.store;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -45,7 +45,7 @@ public abstract class PlatformCacheStoreCallback {
public void invoke(long memPtr) {
if (memPtr > 0) {
try (PlatformMemory mem = ctx.memory().get(memPtr)) {
- PortableRawReaderEx reader = ctx.reader(mem);
+ BinaryRawReaderEx reader = ctx.reader(mem);
invoke0(reader);
}
@@ -57,5 +57,5 @@ public abstract class PlatformCacheStoreCallback {
*
* @param reader Reader.
*/
- protected abstract void invoke0(PortableRawReaderEx reader);
+ protected abstract void invoke0(BinaryRawReaderEx reader);
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterGroup.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterGroup.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterGroup.java
index a1c8516..fc47a4b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterGroup.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterGroup.java
@@ -24,8 +24,8 @@ import org.apache.ignite.IgniteCluster;
import org.apache.ignite.cluster.ClusterMetrics;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.internal.cluster.ClusterGroupEx;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
@@ -94,7 +94,7 @@ public class PlatformClusterGroup extends PlatformAbstractTarget {
/** {@inheritDoc} */
@SuppressWarnings("deprecation")
- @Override protected void processOutStream(int type, PortableRawWriterEx writer) throws IgniteCheckedException {
+ @Override protected void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
switch (type) {
case OP_METRICS:
platformCtx.writeClusterMetrics(writer, prj.metrics());
@@ -113,7 +113,7 @@ public class PlatformClusterGroup extends PlatformAbstractTarget {
/** {@inheritDoc} */
@SuppressWarnings({"ConstantConditions", "deprecation"})
- @Override protected void processInStreamOutStream(int type, PortableRawReaderEx reader, PortableRawWriterEx writer)
+ @Override protected void processInStreamOutStream(int type, BinaryRawReaderEx reader, BinaryRawWriterEx writer)
throws IgniteCheckedException {
switch (type) {
case OP_METRICS_FILTERED: {
@@ -194,7 +194,7 @@ public class PlatformClusterGroup extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected long processInStreamOutLong(int type, PortableRawReaderEx reader) throws IgniteCheckedException {
+ @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException {
switch (type) {
case OP_PING_NODE:
return pingNode(reader.readUuid()) ? TRUE : FALSE;
@@ -205,7 +205,7 @@ public class PlatformClusterGroup extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected Object processInStreamOutObject(int type, PortableRawReaderEx reader) throws IgniteCheckedException {
+ @Override protected Object processInStreamOutObject(int type, BinaryRawReaderEx reader) throws IgniteCheckedException {
switch (type) {
case OP_FOR_NODE_IDS: {
Collection<UUID> ids = PlatformUtils.readCollection(reader);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterNodeFilterImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterNodeFilterImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterNodeFilterImpl.java
index 5ba9a85..92aabd8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterNodeFilterImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterNodeFilterImpl.java
@@ -19,7 +19,7 @@ package org.apache.ignite.internal.processors.platform.cluster;
import org.apache.ignite.Ignite;
import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractPredicate;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -56,7 +56,7 @@ public class PlatformClusterNodeFilterImpl extends PlatformAbstractPredicate imp
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(pred);
ctx.writeNode(writer, clusterNode);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractJob.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractJob.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractJob.java
index bf9d9e4..462f2c4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractJob.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractJob.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.platform.compute;
import java.io.Externalizable;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.PlatformProcessor;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -105,7 +105,7 @@ public abstract class PlatformAbstractJob implements PlatformJob, Externalizable
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(job);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractTask.java
index b17dd97..c293c51 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractTask.java
@@ -24,7 +24,7 @@ import org.apache.ignite.IgniteException;
import org.apache.ignite.compute.ComputeJobResult;
import org.apache.ignite.compute.ComputeJobResultPolicy;
import org.apache.ignite.compute.ComputeTask;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.PlatformNativeException;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -86,7 +86,7 @@ public abstract class PlatformAbstractTask implements ComputeTask<Object, Void>
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
writer.writeUuid(res.getNode().id());
writer.writeBoolean(res.isCancelled());
@@ -151,7 +151,7 @@ public abstract class PlatformAbstractTask implements ComputeTask<Object, Void>
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
if (e0 == null) {
writer.writeBoolean(false);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformClosureJob.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformClosureJob.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformClosureJob.java
index 9bd7d60..b35f31c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformClosureJob.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformClosureJob.java
@@ -21,7 +21,7 @@ import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -69,7 +69,7 @@ public class PlatformClosureJob extends PlatformAbstractJob {
in.synchronize();
- PortableRawReaderEx reader = ctx.reader(in);
+ BinaryRawReaderEx reader = ctx.reader(in);
return PlatformUtils.readInvocationResult(ctx, reader);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
index 638b4b1..05db49d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
@@ -25,15 +25,15 @@ import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteCompute;
import org.apache.ignite.internal.IgniteComputeImpl;
import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.portable.PortableObjectImpl;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryObjectImpl;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.util.typedef.C1;
import org.apache.ignite.lang.IgniteFuture;
import org.apache.ignite.lang.IgniteInClosure;
-import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.binary.BinaryObject;
import static org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.TC_SUBGRID;
@@ -75,7 +75,7 @@ public class PlatformCompute extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected long processInStreamOutLong(int type, PortableRawReaderEx reader) throws IgniteCheckedException {
+ @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException {
switch (type) {
case OP_UNICAST:
processClosures(reader.readLong(), reader, false, false);
@@ -104,7 +104,7 @@ public class PlatformCompute extends PlatformAbstractTarget {
* @param reader Reader.
* @param broadcast broadcast flag.
*/
- private void processClosures(long taskPtr, PortableRawReaderEx reader, boolean broadcast, boolean affinity) {
+ private void processClosures(long taskPtr, BinaryRawReaderEx reader, boolean broadcast, boolean affinity) {
PlatformAbstractTask task;
int size = reader.readInt();
@@ -165,12 +165,12 @@ public class PlatformCompute extends PlatformAbstractTarget {
* @param reader Reader.
* @return Closure job.
*/
- private PlatformJob nextClosureJob(PlatformAbstractTask task, PortableRawReaderEx reader) {
+ private PlatformJob nextClosureJob(PlatformAbstractTask task, BinaryRawReaderEx reader) {
return platformCtx.createClosureJob(task, reader.readLong(), reader.readObjectDetached());
}
/** {@inheritDoc} */
- @Override protected void processInStreamOutStream(int type, PortableRawReaderEx reader, PortableRawWriterEx writer)
+ @Override protected void processInStreamOutStream(int type, BinaryRawReaderEx reader, BinaryRawWriterEx writer)
throws IgniteCheckedException {
switch (type) {
case OP_EXEC:
@@ -256,7 +256,7 @@ public class PlatformCompute extends PlatformAbstractTarget {
* @param reader Reader.
* @return Task result.
*/
- protected Object executeJavaTask(PortableRawReaderEx reader, boolean async) {
+ protected Object executeJavaTask(BinaryRawReaderEx reader, boolean async) {
String taskName = reader.readString();
boolean keepPortable = reader.readBoolean();
Object arg = reader.readObjectDetached();
@@ -268,8 +268,8 @@ public class PlatformCompute extends PlatformAbstractTarget {
if (async)
compute0 = compute0.withAsync();
- if (!keepPortable && arg instanceof PortableObjectImpl)
- arg = ((PortableObject)arg).deserialize();
+ if (!keepPortable && arg instanceof BinaryObjectImpl)
+ arg = ((BinaryObject)arg).deserialize();
Object res = compute0.execute(taskName, arg);
@@ -295,7 +295,7 @@ public class PlatformCompute extends PlatformAbstractTarget {
* @return Result.
*/
private Object toPortable(Object src) {
- return platformCtx.kernalContext().grid().portables().toPortable(src);
+ return platformCtx.kernalContext().grid().binary().toBinary(src);
}
/**
@@ -304,7 +304,7 @@ public class PlatformCompute extends PlatformAbstractTarget {
* @param reader Reader.
* @return Node IDs.
*/
- protected Collection<UUID> readNodeIds(PortableRawReaderEx reader) {
+ protected Collection<UUID> readNodeIds(BinaryRawReaderEx reader) {
if (reader.readBoolean()) {
int len = reader.readInt();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullJob.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullJob.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullJob.java
index cfed735..9302c03 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullJob.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullJob.java
@@ -21,7 +21,7 @@ import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.PlatformProcessor;
import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
@@ -120,7 +120,7 @@ public class PlatformFullJob extends PlatformAbstractJob {
in.synchronize();
- PortableRawReaderEx reader = ctx.reader(in);
+ BinaryRawReaderEx reader = ctx.reader(in);
return PlatformUtils.readInvocationResult(ctx, reader);
}
@@ -209,7 +209,7 @@ public class PlatformFullJob extends PlatformAbstractJob {
in.synchronize();
- PortableRawReaderEx reader = ctx.reader(in);
+ BinaryRawReaderEx reader = ctx.reader(in);
if (res)
job = reader.readObjectDetached();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullTask.java
index b96d445..d789003 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullTask.java
@@ -27,8 +27,8 @@ import org.apache.ignite.compute.ComputeJob;
import org.apache.ignite.compute.ComputeTaskNoResultCache;
import org.apache.ignite.internal.IgniteComputeImpl;
import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -83,7 +83,7 @@ public final class PlatformFullTask extends PlatformAbstractTask {
try (PlatformMemory outMem = memMgr.allocate()) {
PlatformOutputStream out = outMem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
write(writer, nodes, subgrid);
@@ -96,7 +96,7 @@ public final class PlatformFullTask extends PlatformAbstractTask {
in.synchronize();
- PortableRawReaderEx reader = ctx.reader(in);
+ BinaryRawReaderEx reader = ctx.reader(in);
return read(reader, nodes);
}
@@ -114,7 +114,7 @@ public final class PlatformFullTask extends PlatformAbstractTask {
* @param nodes Current topology nodes.
* @param subgrid Subgrid.
*/
- private void write(PortableRawWriterEx writer, Collection<ClusterNode> nodes, List<ClusterNode> subgrid) {
+ private void write(BinaryRawWriterEx writer, Collection<ClusterNode> nodes, List<ClusterNode> subgrid) {
GridDiscoveryManager discoMgr = ctx.kernalContext().discovery();
long curTopVer = discoMgr.topologyVersion();
@@ -145,7 +145,7 @@ public final class PlatformFullTask extends PlatformAbstractTask {
* @param nodes Current topology nodes.
* @return Map result.
*/
- private Map<ComputeJob, ClusterNode> read(PortableRawReaderEx reader, Collection<ClusterNode> nodes) {
+ private Map<ComputeJob, ClusterNode> read(BinaryRawReaderEx reader, Collection<ClusterNode> nodes) {
if (reader.readBoolean()) {
if (!reader.readBoolean())
return null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformDataStreamer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformDataStreamer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformDataStreamer.java
index ef64ef9..794ab0b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformDataStreamer.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformDataStreamer.java
@@ -24,13 +24,14 @@ import org.apache.ignite.events.DiscoveryEvent;
import org.apache.ignite.events.Event;
import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils;
import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.internal.util.typedef.internal.U;
import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
import static org.apache.ignite.events.EventType.EVT_NODE_JOINED;
@@ -87,7 +88,7 @@ public class PlatformDataStreamer extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected long processInStreamOutLong(int type, PortableRawReaderEx reader) throws IgniteCheckedException {
+ @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException {
switch (type) {
case OP_UPDATE:
int plc = reader.readInt();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformStreamReceiverImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformStreamReceiverImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformStreamReceiverImpl.java
index 92250c0..5915496 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformStreamReceiverImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformStreamReceiverImpl.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.platform.datastreamer;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractPredicate;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.cache.PlatformCache;
@@ -76,7 +76,7 @@ public class PlatformStreamReceiverImpl extends PlatformAbstractPredicate implem
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(pred);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
index 0c2e564..25521dc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
@@ -21,8 +21,8 @@ import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.store.CacheStore;
import org.apache.ignite.cache.store.CacheStoreSession;
import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.cache.store.PlatformCacheStore;
import org.apache.ignite.internal.processors.platform.cache.store.PlatformCacheStoreCallback;
@@ -149,8 +149,8 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
try {
final GridTuple<V> val = new GridTuple<>();
- doInvoke(new IgniteInClosureX<PortableRawWriterEx>() {
- @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException {
+ doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
+ @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
writer.writeByte(OP_LOAD);
writer.writeLong(session());
writer.writeString(ses.cacheName());
@@ -170,8 +170,8 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
try {
final Map<K, V> loaded = new HashMap<>();
- doInvoke(new IgniteInClosureX<PortableRawWriterEx>() {
- @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException {
+ doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
+ @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
writer.writeByte(OP_LOAD_ALL);
writer.writeLong(session());
writer.writeString(ses.cacheName());
@@ -189,8 +189,8 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
/** {@inheritDoc} */
@Override public void loadCache(final IgniteBiInClosure<K, V> clo, final @Nullable Object... args) {
try {
- doInvoke(new IgniteInClosureX<PortableRawWriterEx>() {
- @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException {
+ doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
+ @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
writer.writeByte(OP_LOAD_CACHE);
writer.writeLong(session());
writer.writeString(ses.cacheName());
@@ -206,8 +206,8 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
/** {@inheritDoc} */
@Override public void write(final Cache.Entry<? extends K, ? extends V> entry) {
try {
- doInvoke(new IgniteInClosureX<PortableRawWriterEx>() {
- @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException {
+ doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
+ @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
writer.writeByte(OP_PUT);
writer.writeLong(session());
writer.writeString(ses.cacheName());
@@ -225,8 +225,8 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
@SuppressWarnings({"NullableProblems", "unchecked"})
@Override public void writeAll(final Collection<Cache.Entry<? extends K, ? extends V>> entries) {
try {
- doInvoke(new IgniteInClosureX<PortableRawWriterEx>() {
- @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException {
+ doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
+ @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
Map<K, V> map = new AbstractMap<K, V>() {
@Override public int size() {
return entries.size();
@@ -266,8 +266,8 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
/** {@inheritDoc} */
@Override public void delete(final Object key) {
try {
- doInvoke(new IgniteInClosureX<PortableRawWriterEx>() {
- @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException {
+ doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
+ @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
writer.writeByte(OP_RMV);
writer.writeLong(session());
writer.writeString(ses.cacheName());
@@ -283,8 +283,8 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
/** {@inheritDoc} */
@Override public void deleteAll(final Collection<?> keys) {
try {
- doInvoke(new IgniteInClosureX<PortableRawWriterEx>() {
- @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException {
+ doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
+ @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
writer.writeByte(OP_RMV_ALL);
writer.writeLong(session());
writer.writeString(ses.cacheName());
@@ -300,8 +300,8 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
/** {@inheritDoc} */
@Override public void sessionEnd(final boolean commit) {
try {
- doInvoke(new IgniteInClosureX<PortableRawWriterEx>() {
- @Override public void applyx(PortableRawWriterEx writer) throws IgniteCheckedException {
+ doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
+ @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
writer.writeByte(OP_SES_END);
writer.writeLong(session());
writer.writeString(ses.cacheName());
@@ -329,7 +329,7 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
try (PlatformMemory mem = platformCtx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = platformCtx.writer(out);
+ BinaryRawWriterEx writer = platformCtx.writer(out);
write(writer, convertPortable);
@@ -345,7 +345,7 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
* @param writer Writer.
* @param convertPortable Convert portable flag.
*/
- protected void write(PortableRawWriterEx writer, boolean convertPortable) {
+ protected void write(BinaryRawWriterEx writer, boolean convertPortable) {
writer.writeString(typName);
writer.writeBoolean(convertPortable);
writer.writeMap(props);
@@ -378,12 +378,12 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
* @return Result.
* @throws org.apache.ignite.IgniteCheckedException If failed.
*/
- protected int doInvoke(IgniteInClosureX<PortableRawWriterEx> task, @Nullable PlatformCacheStoreCallback cb)
+ protected int doInvoke(IgniteInClosureX<BinaryRawWriterEx> task, @Nullable PlatformCacheStoreCallback cb)
throws IgniteCheckedException{
try (PlatformMemory mem = platformCtx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = platformCtx.writer(out);
+ BinaryRawWriterEx writer = platformCtx.writer(out);
task.apply(writer);
@@ -425,7 +425,7 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
- @Override protected void invoke0(PortableRawReaderEx reader) {
+ @Override protected void invoke0(BinaryRawReaderEx reader) {
val.set((V)reader.readObjectDetached());
}
}
@@ -451,7 +451,7 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
- @Override protected void invoke0(PortableRawReaderEx reader) {
+ @Override protected void invoke0(BinaryRawReaderEx reader) {
loaded.put((K) reader.readObjectDetached(), (V) reader.readObjectDetached());
}
}
@@ -477,7 +477,7 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
- @Override protected void invoke0(PortableRawReaderEx reader) {
+ @Override protected void invoke0(BinaryRawReaderEx reader) {
clo.apply((K) reader.readObjectDetached(), (V) reader.readObjectDetached());
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
index 2c8664c..60c0693 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
@@ -25,7 +25,7 @@ import org.apache.ignite.internal.MarshallerContextImpl;
import org.apache.ignite.internal.portable.GridPortableMarshaller;
import org.apache.ignite.internal.portable.PortableContext;
import org.apache.ignite.internal.portable.PortableMetaDataHandler;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractConfigurationClosure;
import org.apache.ignite.internal.processors.platform.lifecycle.PlatformLifecycleBean;
import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
@@ -39,8 +39,8 @@ import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.platform.dotnet.PlatformDotNetConfiguration;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
import org.apache.ignite.platform.dotnet.PlatformDotNetLifecycleBean;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
import java.util.ArrayList;
import java.util.Collections;
@@ -137,7 +137,7 @@ public class PlatformDotNetConfigurationClosure extends PlatformAbstractConfigur
try (PlatformMemory inMem = memMgr.allocate()) {
PlatformOutputStream out = outMem.output();
- PortableRawWriterEx writer = marshaller().writer(out);
+ BinaryRawWriterEx writer = marshaller().writer(out);
PlatformUtils.writeDotNetConfiguration(writer, interopCfg.unwrap());
@@ -229,15 +229,15 @@ public class PlatformDotNetConfigurationClosure extends PlatformAbstractConfigur
private static GridPortableMarshaller marshaller() {
try {
PortableContext ctx = new PortableContext(new PortableMetaDataHandler() {
- @Override public void addMeta(int typeId, PortableMetadata meta)
- throws PortableException {
+ @Override public void addMeta(int typeId, BinaryType meta)
+ throws BinaryObjectException {
// No-op.
}
- @Override public PortableMetadata metadata(int typeId) throws PortableException {
+ @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
return null;
}
- }, null);
+ }, new IgniteConfiguration());
PortableMarshaller marsh = new PortableMarshaller();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEventFilterListenerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEventFilterListenerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEventFilterListenerImpl.java
index bbcb60f..a19f07e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEventFilterListenerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEventFilterListenerImpl.java
@@ -19,7 +19,7 @@ package org.apache.ignite.internal.processors.platform.events;
import org.apache.ignite.events.Event;
import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.PlatformEventFilterListener;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -125,7 +125,7 @@ public class PlatformEventFilterListenerImpl implements PlatformEventFilterListe
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
ctx.writeEvent(writer, evt);
@@ -151,7 +151,7 @@ public class PlatformEventFilterListenerImpl implements PlatformEventFilterListe
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObjectDetached(pred);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEvents.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEvents.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEvents.java
index 8585526..a1af469 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEvents.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEvents.java
@@ -24,8 +24,8 @@ import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteEvents;
import org.apache.ignite.events.Event;
import org.apache.ignite.events.EventAdapter;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
import org.apache.ignite.internal.processors.platform.PlatformEventFilterListener;
import org.apache.ignite.internal.processors.platform.PlatformContext;
@@ -137,7 +137,7 @@ public class PlatformEvents extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected long processInStreamOutLong(int type, PortableRawReaderEx reader)
+ @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader)
throws IgniteCheckedException {
switch (type) {
case OP_RECORD_LOCAL:
@@ -168,7 +168,7 @@ public class PlatformEvents extends PlatformAbstractTarget {
/** {@inheritDoc} */
@SuppressWarnings({"IfMayBeConditional", "ConstantConditions", "unchecked"})
- @Override protected void processInStreamOutStream(int type, PortableRawReaderEx reader, PortableRawWriterEx writer)
+ @Override protected void processInStreamOutStream(int type, BinaryRawReaderEx reader, BinaryRawWriterEx writer)
throws IgniteCheckedException {
switch (type) {
case OP_LOCAL_QUERY: {
@@ -256,7 +256,7 @@ public class PlatformEvents extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected void processOutStream(int type, PortableRawWriterEx writer) throws IgniteCheckedException {
+ @Override protected void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
switch (type) {
case OP_GET_ENABLED_EVENTS:
writeEventTypes(events.enabledEvents(), writer);
@@ -292,7 +292,7 @@ public class PlatformEvents extends PlatformAbstractTarget {
* @param reader Reader
* @return Event types, or null.
*/
- private int[] readEventTypes(PortableRawReaderEx reader) {
+ private int[] readEventTypes(BinaryRawReaderEx reader) {
return reader.readIntArray();
}
@@ -302,7 +302,7 @@ public class PlatformEvents extends PlatformAbstractTarget {
* @param writer Writer
* @param types Types.
*/
- private void writeEventTypes(int[] types, PortableRawWriterEx writer) {
+ private void writeEventTypes(int[] types, BinaryRawWriterEx writer) {
if (types == null) {
writer.writeIntArray(null);
@@ -349,7 +349,7 @@ public class PlatformEvents extends PlatformAbstractTarget {
}
/** <inheritDoc /> */
- @Override public void write(PortableRawWriterEx writer, Object obj, Throwable err) {
+ @Override public void write(BinaryRawWriterEx writer, Object obj, Throwable err) {
platformCtx.writeEvent(writer, (EventAdapter)obj);
}
@@ -379,7 +379,7 @@ public class PlatformEvents extends PlatformAbstractTarget {
/** <inheritDoc /> */
@SuppressWarnings("unchecked")
- @Override public void write(PortableRawWriterEx writer, Object obj, Throwable err) {
+ @Override public void write(BinaryRawWriterEx writer, Object obj, Throwable err) {
Collection<EventAdapter> events = (Collection<EventAdapter>)obj;
writer.writeInt(events.size());
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageFilterImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageFilterImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageFilterImpl.java
index 67d5bbb..9e1b086 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageFilterImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageFilterImpl.java
@@ -18,7 +18,7 @@
package org.apache.ignite.internal.processors.platform.messaging;
import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractPredicate;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -62,7 +62,7 @@ public class PlatformMessageFilterImpl extends PlatformAbstractPredicate impleme
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(uuid);
writer.writeObject(m);
@@ -83,7 +83,7 @@ public class PlatformMessageFilterImpl extends PlatformAbstractPredicate impleme
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(pred);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageLocalFilter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageLocalFilter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageLocalFilter.java
index 50643e1..de3f255 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageLocalFilter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageLocalFilter.java
@@ -18,7 +18,7 @@
package org.apache.ignite.internal.processors.platform.messaging;
import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;
@@ -58,7 +58,7 @@ public class PlatformMessageLocalFilter implements PlatformMessageFilter {
try (PlatformMemory mem = platformCtx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = platformCtx.writer(out);
+ BinaryRawWriterEx writer = platformCtx.writer(out);
writer.writeObject(uuid);
writer.writeObject(m);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessaging.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessaging.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessaging.java
index 6dfd570..603d3db 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessaging.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessaging.java
@@ -19,8 +19,8 @@ package org.apache.ignite.internal.processors.platform.messaging;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteMessaging;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.message.PlatformMessageFilter;
@@ -84,7 +84,7 @@ public class PlatformMessaging extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected long processInStreamOutLong(int type, PortableRawReaderEx reader)
+ @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader)
throws IgniteCheckedException {
switch (type) {
case OP_SEND:
@@ -135,7 +135,7 @@ public class PlatformMessaging extends PlatformAbstractTarget {
/** {@inheritDoc} */
@SuppressWarnings({"IfMayBeConditional", "ConstantConditions", "unchecked"})
- @Override protected void processInStreamOutStream(int type, PortableRawReaderEx reader, PortableRawWriterEx writer)
+ @Override protected void processInStreamOutStream(int type, BinaryRawReaderEx reader, BinaryRawWriterEx writer)
throws IgniteCheckedException {
switch (type) {
case OP_REMOTE_LISTEN:{
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformAbstractService.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformAbstractService.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformAbstractService.java
index 0b9ee53..18ab012 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformAbstractService.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformAbstractService.java
@@ -23,8 +23,8 @@ import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -84,7 +84,7 @@ public abstract class PlatformAbstractService implements PlatformService, Extern
try (PlatformMemory mem = platformCtx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = platformCtx.writer(out);
+ BinaryRawWriterEx writer = platformCtx.writer(out);
writer.writeBoolean(srvKeepPortable);
writer.writeObject(svc);
@@ -108,7 +108,7 @@ public abstract class PlatformAbstractService implements PlatformService, Extern
try (PlatformMemory mem = platformCtx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = platformCtx.writer(out);
+ BinaryRawWriterEx writer = platformCtx.writer(out);
writer.writeBoolean(srvKeepPortable);
@@ -131,7 +131,7 @@ public abstract class PlatformAbstractService implements PlatformService, Extern
try (PlatformMemory mem = platformCtx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = platformCtx.writer(out);
+ BinaryRawWriterEx writer = platformCtx.writer(out);
writer.writeBoolean(srvKeepPortable);
@@ -152,7 +152,7 @@ public abstract class PlatformAbstractService implements PlatformService, Extern
* @param ctx Context.
* @param writer Writer.
*/
- private void writeServiceContext(ServiceContext ctx, PortableRawWriterEx writer) {
+ private void writeServiceContext(ServiceContext ctx, BinaryRawWriterEx writer) {
writer.writeString(ctx.name());
writer.writeUuid(ctx.executionId());
writer.writeBoolean(ctx.isCancelled());
@@ -175,7 +175,7 @@ public abstract class PlatformAbstractService implements PlatformService, Extern
try (PlatformMemory outMem = platformCtx.memory().allocate()) {
PlatformOutputStream out = outMem.output();
- PortableRawWriterEx writer = platformCtx.writer(out);
+ BinaryRawWriterEx writer = platformCtx.writer(out);
writer.writeBoolean(srvKeepPortable);
writer.writeString(mthdName);
@@ -195,7 +195,7 @@ public abstract class PlatformAbstractService implements PlatformService, Extern
try (PlatformMemory inMem = platformCtx.memory().allocate()) {
PlatformInputStream in = inMem.input();
- PortableRawReaderEx reader = platformCtx.reader(in);
+ BinaryRawReaderEx reader = platformCtx.reader(in);
platformCtx.gateway().serviceInvokeMethod(ptr, outMem.pointer(), inMem.pointer());
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java
index bfa4570..320d5a9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java
@@ -22,8 +22,8 @@ import java.util.Map;
import java.util.UUID;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteServices;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.dotnet.PlatformDotNetService;
@@ -128,7 +128,7 @@ public class PlatformServices extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected long processInStreamOutLong(int type, PortableRawReaderEx reader)
+ @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader)
throws IgniteCheckedException {
switch (type) {
case OP_DOTNET_DEPLOY: {
@@ -169,7 +169,7 @@ public class PlatformServices extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected void processInStreamOutStream(int type, PortableRawReaderEx reader, PortableRawWriterEx writer)
+ @Override protected void processInStreamOutStream(int type, BinaryRawReaderEx reader, BinaryRawWriterEx writer)
throws IgniteCheckedException {
switch (type) {
case OP_DOTNET_SERVICES: {
@@ -177,7 +177,7 @@ public class PlatformServices extends PlatformAbstractTarget {
PlatformUtils.writeNullableCollection(writer, svcs,
new PlatformWriterClosure<Service>() {
- @Override public void write(PortableRawWriterEx writer, Service svc) {
+ @Override public void write(BinaryRawWriterEx writer, Service svc) {
writer.writeLong(((PlatformService) svc).pointer());
}
},
@@ -197,8 +197,8 @@ public class PlatformServices extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected void processInObjectStreamOutStream(int type, Object arg, PortableRawReaderEx reader,
- PortableRawWriterEx writer) throws IgniteCheckedException {
+ @Override protected void processInObjectStreamOutStream(int type, Object arg, BinaryRawReaderEx reader,
+ BinaryRawWriterEx writer) throws IgniteCheckedException {
switch (type) {
case OP_DOTNET_INVOKE: {
assert arg != null;
@@ -235,13 +235,13 @@ public class PlatformServices extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected void processOutStream(int type, PortableRawWriterEx writer) throws IgniteCheckedException {
+ @Override protected void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
switch (type) {
case OP_DESCRIPTORS: {
Collection<ServiceDescriptor> descs = services.serviceDescriptors();
PlatformUtils.writeCollection(writer, descs, new PlatformWriterClosure<ServiceDescriptor>() {
- @Override public void write(PortableRawWriterEx writer, ServiceDescriptor d) {
+ @Override public void write(BinaryRawWriterEx writer, ServiceDescriptor d) {
writer.writeString(d.name());
writer.writeString(d.cacheName());
writer.writeInt(d.maxPerNodeCount());
@@ -252,7 +252,7 @@ public class PlatformServices extends PlatformAbstractTarget {
Map<UUID, Integer> top = d.topologySnapshot();
PlatformUtils.writeMap(writer, top, new PlatformWriterBiClosure<UUID, Integer>() {
- @Override public void write(PortableRawWriterEx writer, UUID key, Integer val) {
+ @Override public void write(BinaryRawWriterEx writer, UUID key, Integer val) {
writer.writeUuid(key);
writer.writeInt(val);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/transactions/PlatformTransactions.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/transactions/PlatformTransactions.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/transactions/PlatformTransactions.java
index c143212..5f5f5c3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/transactions/PlatformTransactions.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/transactions/PlatformTransactions.java
@@ -18,13 +18,12 @@
package org.apache.ignite.internal.processors.platform.transactions;
import java.sql.Timestamp;
-import java.util.Date;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteTransactions;
import org.apache.ignite.configuration.TransactionConfiguration;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils;
@@ -232,7 +231,7 @@ public class PlatformTransactions extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected void processOutStream(int type, PortableRawWriterEx writer) throws IgniteCheckedException {
+ @Override protected void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
switch (type) {
case OP_CACHE_CONFIG_PARAMETERS:
TransactionConfiguration txCfg = platformCtx.kernalContext().config().getTransactionConfiguration();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformFutureUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformFutureUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformFutureUtils.java
index 0019986..335be4d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformFutureUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformFutureUtils.java
@@ -18,7 +18,7 @@
package org.apache.ignite.internal.processors.platform.utils;
import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway;
@@ -164,7 +164,7 @@ public class PlatformFutureUtils {
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx outWriter = ctx.writer(out);
+ BinaryRawWriterEx outWriter = ctx.writer(out);
outWriter.writeObjectDetached(res);
@@ -244,7 +244,7 @@ public class PlatformFutureUtils {
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx outWriter = ctx.writer(out);
+ BinaryRawWriterEx outWriter = ctx.writer(out);
outWriter.writeString(err.getClass().getName());
outWriter.writeString(err.getMessage());
@@ -276,7 +276,7 @@ public class PlatformFutureUtils {
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx outWriter = ctx.writer(out);
+ BinaryRawWriterEx outWriter = ctx.writer(out);
writer.write(outWriter, obj, err);
@@ -299,7 +299,7 @@ public class PlatformFutureUtils {
* @param obj Object.
* @param err Error.
*/
- public void write(PortableRawWriterEx writer, Object obj, Throwable err);
+ public void write(BinaryRawWriterEx writer, Object obj, Throwable err);
/**
* Determines whether this writer can write given data.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderBiClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderBiClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderBiClosure.java
index 79759e9..199cf72 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderBiClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderBiClosure.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.processors.platform.utils;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
import org.apache.ignite.lang.IgniteBiTuple;
/**
@@ -30,5 +30,5 @@ public interface PlatformReaderBiClosure<T1, T2> {
* @param reader Reader.
* @return Object.
*/
- IgniteBiTuple<T1, T2> read(PortableRawReaderEx reader);
+ IgniteBiTuple<T1, T2> read(BinaryRawReaderEx reader);
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderClosure.java
index 2d9b44a..9330606 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderClosure.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.processors.platform.utils;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
/**
* Reader closure.
@@ -30,5 +30,5 @@ public interface PlatformReaderClosure<T> {
* @param reader Reader.
* @return Object.
*/
- T read(PortableRawReaderEx reader);
+ T read(BinaryRawReaderEx reader);
}
\ No newline at end of file
[17/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
deleted file mode 100644
index 542c897..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
+++ /dev/null
@@ -1,1915 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.streams.PortableHeapOutputStream;
-import org.apache.ignite.internal.portable.streams.PortableOutputStream;
-import org.apache.ignite.internal.util.typedef.internal.A;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableIdMapper;
-import org.apache.ignite.portable.PortableRawWriter;
-import org.apache.ignite.portable.PortableWriter;
-import org.jetbrains.annotations.Nullable;
-
-import java.io.IOException;
-import java.io.ObjectOutput;
-import java.lang.reflect.InvocationTargetException;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.IdentityHashMap;
-import java.util.Map;
-import java.util.UUID;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CLASS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.COL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLAGS_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP_ENTRY;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OPTM_MARSH;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.PORTABLE_OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SCHEMA_ID_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TOTAL_LEN_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID_ARR;
-
-/**
- * Portable writer implementation.
- */
-public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx, ObjectOutput {
- /** Length: integer. */
- private static final int LEN_INT = 4;
-
- /** */
- private static final int INIT_CAP = 1024;
-
- /** FNV1 hash offset basis. */
- private static final int FNV1_OFFSET_BASIS = 0x811C9DC5;
-
- /** FNV1 hash prime. */
- private static final int FNV1_PRIME = 0x01000193;
-
- /** Maximum offset which fits in 1 byte. */
- private static final int MAX_OFFSET_1 = 1 << 8;
-
- /** Maximum offset which fits in 2 bytes. */
- private static final int MAX_OFFSET_2 = 1 << 16;
-
- /** Thread-local schema. */
- private static final ThreadLocal<SchemaHolder> SCHEMA = new ThreadLocal<>();
-
- /** */
- private final PortableContext ctx;
-
- /** */
- private final int start;
-
- /** */
- private Class<?> cls;
-
- /** */
- private int typeId;
-
- /** Raw offset position. */
- private int rawOffPos;
-
- /** */
- private boolean metaEnabled;
-
- /** */
- private int metaHashSum;
-
- /** Handles. */
- private Map<Object, Integer> handles;
-
- /** Output stream. */
- private PortableOutputStream out;
-
- /** Schema. */
- private SchemaHolder schema;
-
- /** Schema ID. */
- private int schemaId;
-
- /** Amount of written fields. */
- private int fieldCnt;
-
- /** ID mapper. */
- private PortableIdMapper idMapper;
-
- /**
- * @param ctx Context.
- */
- PortableWriterExImpl(PortableContext ctx) {
- this(ctx, new PortableHeapOutputStream(INIT_CAP));
- }
-
- /**
- * @param ctx Context.
- * @param out Output stream.
- */
- PortableWriterExImpl(PortableContext ctx, PortableOutputStream out) {
- this(ctx, out, new IdentityHashMap<Object, Integer>());
- }
-
- /**
- * @param ctx Context.
- * @param out Output stream.
- * @param handles Handles.
- */
- private PortableWriterExImpl(PortableContext ctx, PortableOutputStream out, Map<Object, Integer> handles) {
- this.ctx = ctx;
- this.out = out;
- this.handles = handles;
-
- start = out.position();
- }
-
- /**
- * @param ctx Context.
- * @param typeId Type ID.
- */
- public PortableWriterExImpl(PortableContext ctx, int typeId, boolean metaEnabled) {
- this(ctx);
-
- this.typeId = typeId;
- this.metaEnabled = metaEnabled;
- }
-
- /**
- * Close the writer releasing resources if necessary.
- */
- @Override public void close() {
- out.close();
- }
-
- /**
- * @return Meta data hash sum or {@code null} if meta data is disabled.
- */
- @Nullable Integer metaDataHashSum() {
- return metaEnabled ? metaHashSum : null;
- }
-
- /**
- * @param obj Object.
- * @throws PortableException In case of error.
- */
- void marshal(Object obj) throws PortableException {
- marshal(obj, true);
- }
-
- /**
- * @param obj Object.
- * @param enableReplace Object replacing enabled flag.
- * @throws PortableException In case of error.
- */
- void marshal(Object obj, boolean enableReplace) throws PortableException {
- assert obj != null;
-
- cls = obj.getClass();
-
- PortableClassDescriptor desc = ctx.descriptorForClass(cls);
-
- if (desc == null)
- throw new PortableException("Object is not portable: [class=" + cls + ']');
-
- if (desc.excluded()) {
- doWriteByte(NULL);
- return;
- }
-
- if (desc.useOptimizedMarshaller()) {
- writeByte(OPTM_MARSH);
-
- try {
- byte[] arr = ctx.optimizedMarsh().marshal(obj);
-
- writeInt(arr.length);
-
- write(arr);
- }
- catch (IgniteCheckedException e) {
- throw new PortableException("Failed to marshal object with optimized marshaller: " + obj, e);
- }
-
- return;
- }
-
- if (enableReplace && desc.getWriteReplaceMethod() != null) {
- Object replacedObj;
-
- try {
- replacedObj = desc.getWriteReplaceMethod().invoke(obj);
- }
- catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- }
- catch (InvocationTargetException e) {
- if (e.getTargetException() instanceof PortableException)
- throw (PortableException)e.getTargetException();
-
- throw new PortableException("Failed to execute writeReplace() method on " + obj, e);
- }
-
- if (replacedObj == null) {
- doWriteByte(NULL);
- return;
- }
-
- marshal(replacedObj, false);
-
- return;
- }
-
- typeId = desc.typeId();
-
- metaEnabled = ctx.isMetaDataEnabled(typeId);
-
- desc.write(obj, this);
- }
-
- /**
- * @param obj Object.
- * @return Handle.
- */
- int handle(Object obj) {
- assert obj != null;
-
- Integer h = handles.get(obj);
-
- if (h != null)
- return out.position() - h;
- else {
- handles.put(obj, out.position());
-
- return -1;
- }
- }
-
- /**
- * @return Array.
- */
- public byte[] array() {
- return out.arrayCopy();
- }
-
- /**
- * @return Stream current position.
- */
- int position() {
- return out.position();
- }
-
- /**
- * Sets new position.
- *
- * @param pos Position.
- */
- void position(int pos) {
- out.position(pos);
- }
-
- /**
- * @param bytes Number of bytes to reserve.
- * @return Offset.
- */
- public int reserve(int bytes) {
- int pos = out.position();
-
- out.position(pos + bytes);
-
- return pos;
- }
-
- /**
- * Perform post-write activity. This includes:
- * - writing object length;
- * - writing schema offset;
- * - writing schema to the tail.
- *
- * @param userType User type flag.
- */
- public void postWrite(boolean userType) {
- if (schema != null) {
- // Write schema ID.
- out.writeInt(start + SCHEMA_ID_POS, schemaId);
-
- // Write schema offset.
- out.writeInt(start + SCHEMA_OR_RAW_OFF_POS, out.position() - start);
-
- // Write the schema.
- int offsetByteCnt = schema.write(this, fieldCnt);
-
- // Write raw offset if needed.
- if (rawOffPos != 0)
- out.writeInt(rawOffPos - start);
-
- if (offsetByteCnt == PortableUtils.OFFSET_1) {
- int flags = (userType ? PortableUtils.FLAG_USR_TYP : 0) | PortableUtils.FLAG_OFFSET_ONE_BYTE;
-
- out.writeShort(start + FLAGS_POS, (short)flags);
- }
- else if (offsetByteCnt == PortableUtils.OFFSET_2) {
- int flags = (userType ? PortableUtils.FLAG_USR_TYP : 0) | PortableUtils.FLAG_OFFSET_TWO_BYTES;
-
- out.writeShort(start + FLAGS_POS, (short)flags);
- }
- }
- else {
- // Write raw-only flag is needed.
- int flags = (userType ? PortableUtils.FLAG_USR_TYP : 0) | PortableUtils.FLAG_RAW_ONLY;
-
- out.writeShort(start + FLAGS_POS, (short)flags);
-
- // If there are no schema, we are free to write raw offset to schema offset.
- out.writeInt(start + SCHEMA_OR_RAW_OFF_POS, (rawOffPos == 0 ? out.position() : rawOffPos) - start);
- }
-
- // 5. Write length.
- out.writeInt(start + TOTAL_LEN_POS, out.position() - start);
- }
-
- /**
- * Pop schema.
- */
- public void popSchema() {
- if (schema != null) {
- assert fieldCnt > 0;
-
- schema.pop(fieldCnt);
- }
- }
-
- /**
- * @param val Byte array.
- */
- public void write(byte[] val) {
- assert val != null;
-
- out.writeByteArray(val);
- }
-
- /**
- * @param val Byte array.
- * @param off Offset.
- * @param len Length.
- */
- public void write(byte[] val, int off, int len) {
- assert val != null;
-
- out.write(val, off, len);
- }
-
- /**
- * @param val Value.
- */
- public void doWriteByte(byte val) {
- out.writeByte(val);
- }
-
- /**
- * @param val Value.
- */
- public void doWriteShort(short val) {
- out.writeShort(val);
- }
-
- /**
- * @param val Value.
- */
- public void doWriteInt(int val) {
- out.writeInt(val);
- }
-
- /**
- * @param val Value.
- */
- public void doWriteLong(long val) {
- out.writeLong(val);
- }
-
- /**
- * @param val Value.
- */
- public void doWriteFloat(float val) {
- out.writeFloat(val);
- }
-
- /**
- * @param val Value.
- */
- public void doWriteDouble(double val) {
- out.writeDouble(val);
- }
-
- /**
- * @param val Value.
- */
- public void doWriteChar(char val) {
- out.writeChar(val);
- }
-
- /**
- * @param val Value.
- */
- public void doWriteBoolean(boolean val) {
- out.writeBoolean(val);
- }
-
- /**
- * @param val String value.
- */
- public void doWriteDecimal(@Nullable BigDecimal val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- doWriteByte(DECIMAL);
-
- BigInteger intVal = val.unscaledValue();
-
- if (intVal.signum() == -1) {
- intVal = intVal.negate();
-
- out.writeInt(val.scale() | 0x80000000);
- }
- else
- out.writeInt(val.scale());
-
- byte[] vals = intVal.toByteArray();
-
- out.writeInt(vals.length);
- out.writeByteArray(vals);
- }
- }
-
- /**
- * @param val String value.
- */
- public void doWriteString(@Nullable String val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- doWriteByte(STRING);
-
- if (ctx.isConvertString()) {
- doWriteBoolean(true);
-
- byte[] strArr = val.getBytes(UTF_8);
-
- doWriteInt(strArr.length);
-
- out.writeByteArray(strArr);
- }
- else {
- doWriteBoolean(false);
-
- char[] strArr = val.toCharArray();
-
- doWriteInt(strArr.length);
-
- out.writeCharArray(strArr);
- }
- }
- }
-
- /**
- * @param uuid UUID.
- */
- public void doWriteUuid(@Nullable UUID uuid) {
- if (uuid == null)
- doWriteByte(NULL);
- else {
- doWriteByte(UUID);
- doWriteLong(uuid.getMostSignificantBits());
- doWriteLong(uuid.getLeastSignificantBits());
- }
- }
-
- /**
- * @param date Date.
- */
- public void doWriteDate(@Nullable Date date) {
- if (date == null)
- doWriteByte(NULL);
- else {
- doWriteByte(DATE);
- doWriteLong(date.getTime());
- }
- }
-
- /**
- * @param ts Timestamp.
- */
- public void doWriteTimestamp(@Nullable Timestamp ts) {
- if (ts== null)
- doWriteByte(NULL);
- else {
- doWriteByte(TIMESTAMP);
- doWriteLong(ts.getTime());
- doWriteInt(ts.getNanos() % 1000000);
- }
- }
-
- /**
- * Write object.
- *
- * @param obj Object.
- * @throws PortableException In case of error.
- */
- public void doWriteObject(@Nullable Object obj) throws PortableException {
- if (obj == null)
- doWriteByte(NULL);
- else {
- PortableWriterExImpl writer = new PortableWriterExImpl(ctx, out, handles);
-
- writer.marshal(obj);
- }
- }
-
- /**
- * @param val Byte array.
- */
- void doWriteByteArray(@Nullable byte[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(BYTE_ARR);
- doWriteInt(val.length);
-
- out.writeByteArray(val);
- }
- }
-
- /**
- * @param val Short array.
- */
- void doWriteShortArray(@Nullable short[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(SHORT_ARR);
- doWriteInt(val.length);
-
- out.writeShortArray(val);
- }
- }
-
- /**
- * @param val Integer array.
- */
- void doWriteIntArray(@Nullable int[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(INT_ARR);
- doWriteInt(val.length);
-
- out.writeIntArray(val);
- }
- }
-
- /**
- * @param val Long array.
- */
- void doWriteLongArray(@Nullable long[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(LONG_ARR);
- doWriteInt(val.length);
-
- out.writeLongArray(val);
- }
- }
-
- /**
- * @param val Float array.
- */
- void doWriteFloatArray(@Nullable float[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(FLOAT_ARR);
- doWriteInt(val.length);
-
- out.writeFloatArray(val);
- }
- }
-
- /**
- * @param val Double array.
- */
- void doWriteDoubleArray(@Nullable double[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(DOUBLE_ARR);
- doWriteInt(val.length);
-
- out.writeDoubleArray(val);
- }
- }
-
- /**
- * @param val Char array.
- */
- void doWriteCharArray(@Nullable char[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(CHAR_ARR);
- doWriteInt(val.length);
-
- out.writeCharArray(val);
- }
- }
-
- /**
- * @param val Boolean array.
- */
- void doWriteBooleanArray(@Nullable boolean[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(BOOLEAN_ARR);
- doWriteInt(val.length);
-
- out.writeBooleanArray(val);
- }
- }
-
- /**
- * @param val Array of strings.
- */
- void doWriteDecimalArray(@Nullable BigDecimal[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(DECIMAL_ARR);
- doWriteInt(val.length);
-
- for (BigDecimal str : val)
- doWriteDecimal(str);
- }
- }
-
- /**
- * @param val Array of strings.
- */
- void doWriteStringArray(@Nullable String[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(STRING_ARR);
- doWriteInt(val.length);
-
- for (String str : val)
- doWriteString(str);
- }
- }
-
- /**
- * @param val Array of UUIDs.
- */
- void doWriteUuidArray(@Nullable UUID[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(UUID_ARR);
- doWriteInt(val.length);
-
- for (UUID uuid : val)
- doWriteUuid(uuid);
- }
- }
-
- /**
- * @param val Array of dates.
- */
- void doWriteDateArray(@Nullable Date[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(DATE_ARR);
- doWriteInt(val.length);
-
- for (Date date : val)
- doWriteDate(date);
- }
- }
-
- /**
- * @param val Array of timestamps.
- */
- void doWriteTimestampArray(@Nullable Timestamp[] val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- doWriteByte(TIMESTAMP_ARR);
- doWriteInt(val.length);
-
- for (Timestamp ts : val)
- doWriteTimestamp(ts);
- }
- }
-
- /**
- * @param val Array of objects.
- * @throws PortableException In case of error.
- */
- void doWriteObjectArray(@Nullable Object[] val) throws PortableException {
- if (val == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(val))
- return;
-
- PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType());
-
- doWriteByte(OBJ_ARR);
-
- if (desc.registered())
- doWriteInt(desc.typeId());
- else {
- doWriteInt(UNREGISTERED_TYPE_ID);
- doWriteString(val.getClass().getComponentType().getName());
- }
-
- doWriteInt(val.length);
-
- for (Object obj : val)
- doWriteObject(obj);
- }
- }
-
- /**
- * @param col Collection.
- * @throws PortableException In case of error.
- */
- void doWriteCollection(@Nullable Collection<?> col) throws PortableException {
- if (col == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(col))
- return;
-
- doWriteByte(COL);
- doWriteInt(col.size());
- doWriteByte(ctx.collectionType(col.getClass()));
-
- for (Object obj : col)
- doWriteObject(obj);
- }
- }
-
- /**
- * @param map Map.
- * @throws PortableException In case of error.
- */
- void doWriteMap(@Nullable Map<?, ?> map) throws PortableException {
- if (map == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(map))
- return;
-
- doWriteByte(MAP);
- doWriteInt(map.size());
- doWriteByte(ctx.mapType(map.getClass()));
-
- for (Map.Entry<?, ?> e : map.entrySet()) {
- doWriteObject(e.getKey());
- doWriteObject(e.getValue());
- }
- }
- }
-
- /**
- * @param e Map entry.
- * @throws PortableException In case of error.
- */
- void doWriteMapEntry(@Nullable Map.Entry<?, ?> e) throws PortableException {
- if (e == null)
- doWriteByte(NULL);
- else {
- if (tryWriteAsHandle(e))
- return;
-
- doWriteByte(MAP_ENTRY);
- doWriteObject(e.getKey());
- doWriteObject(e.getValue());
- }
- }
-
- /**
- * @param val Value.
- */
- void doWriteEnum(@Nullable Enum<?> val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass());
-
- doWriteByte(ENUM);
-
- if (desc.registered())
- doWriteInt(desc.typeId());
- else {
- doWriteInt(UNREGISTERED_TYPE_ID);
- doWriteString(val.getClass().getName());
- }
-
- doWriteInt(val.ordinal());
- }
- }
-
- /**
- * @param val Array.
- */
- void doWriteEnumArray(@Nullable Object[] val) {
- assert val == null || val.getClass().getComponentType().isEnum();
-
- if (val == null)
- doWriteByte(NULL);
- else {
- PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType());
- doWriteByte(ENUM_ARR);
-
- if (desc.registered())
- doWriteInt(desc.typeId());
- else {
- doWriteInt(UNREGISTERED_TYPE_ID);
- doWriteString(val.getClass().getComponentType().getName());
- }
-
- doWriteInt(val.length);
-
- // TODO: Denis: Redundant data for each element of the array.
- for (Object o : val)
- doWriteEnum((Enum<?>)o);
- }
- }
-
- /**
- * @param val Class.
- */
- void doWriteClass(@Nullable Class val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- PortableClassDescriptor desc = ctx.descriptorForClass(val);
-
- doWriteByte(CLASS);
-
- if (desc.registered())
- doWriteInt(desc.typeId());
- else {
- doWriteInt(UNREGISTERED_TYPE_ID);
- doWriteString(val.getClass().getName());
- }
- }
- }
-
- /**
- * @param po Portable object.
- */
- public void doWritePortableObject(@Nullable PortableObjectImpl po) {
- if (po == null)
- doWriteByte(NULL);
- else {
- doWriteByte(PORTABLE_OBJ);
-
- byte[] poArr = po.array();
-
- doWriteInt(poArr.length);
-
- out.writeByteArray(poArr);
-
- doWriteInt(po.start());
- }
- }
-
- /**
- * @param val Value.
- */
- void writeByteField(@Nullable Byte val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- doWriteByte(BYTE);
- doWriteByte(val);
- }
- }
-
- /**
- * @param val Class.
- */
- void writeClassField(@Nullable Class val) {
- doWriteClass(val);
- }
-
- /**
- * @param val Value.
- */
- void writeShortField(@Nullable Short val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- doWriteByte(SHORT);
- doWriteShort(val);
- }
- }
-
- /**
- * @param val Value.
- */
- void writeIntField(@Nullable Integer val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- doWriteByte(INT);
- doWriteInt(val);
- }
- }
-
- /**
- * @param val Value.
- */
- void writeLongField(@Nullable Long val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- doWriteByte(LONG);
- doWriteLong(val);
- }
- }
-
- /**
- * @param val Value.
- */
- void writeFloatField(@Nullable Float val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- doWriteByte(FLOAT);
- doWriteFloat(val);
- }
- }
-
- /**
- * @param val Value.
- */
- void writeDoubleField(@Nullable Double val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- doWriteByte(DOUBLE);
- doWriteDouble(val);
- }
- }
-
- /**
- * @param val Value.
- */
- void writeCharField(@Nullable Character val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- doWriteByte(CHAR);
- doWriteChar(val);
- }
- }
-
- /**
- * @param val Value.
- */
- void writeBooleanField(@Nullable Boolean val) {
- if (val == null)
- doWriteByte(NULL);
- else {
- doWriteByte(BOOLEAN);
- doWriteBoolean(val);
- }
- }
-
- /**
- * @param val Value.
- */
- void writeDecimalField(@Nullable BigDecimal val) {
- doWriteDecimal(val);
- }
-
- /**
- * @param val Value.
- */
- void writeStringField(@Nullable String val) {
- doWriteString(val);
- }
-
- /**
- * @param val Value.
- */
- void writeUuidField(@Nullable UUID val) {
- doWriteUuid(val);
- }
-
- /**
- * @param val Value.
- */
- void writeDateField(@Nullable Date val) {
- doWriteDate(val);
- }
-
- /**
- * @param val Value.
- */
- void writeTimestampField(@Nullable Timestamp val) {
- doWriteTimestamp(val);
- }
-
- /**
- * @param obj Object.
- * @throws PortableException In case of error.
- */
- void writeObjectField(@Nullable Object obj) throws PortableException {
- doWriteObject(obj);
- }
-
- /**
- * @param val Value.
- */
- void writeByteArrayField(@Nullable byte[] val) {
- doWriteByteArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeShortArrayField(@Nullable short[] val) {
- doWriteShortArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeIntArrayField(@Nullable int[] val) {
- doWriteIntArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeLongArrayField(@Nullable long[] val) {
- doWriteLongArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeFloatArrayField(@Nullable float[] val) {
- doWriteFloatArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeDoubleArrayField(@Nullable double[] val) {
- doWriteDoubleArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeCharArrayField(@Nullable char[] val) {
- doWriteCharArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeBooleanArrayField(@Nullable boolean[] val) {
- doWriteBooleanArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeDecimalArrayField(@Nullable BigDecimal[] val) {
- doWriteDecimalArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeStringArrayField(@Nullable String[] val) {
- doWriteStringArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeUuidArrayField(@Nullable UUID[] val) {
- doWriteUuidArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeDateArrayField(@Nullable Date[] val) {
- doWriteDateArray(val);
- }
-
- /**
- * @param val Value.
- */
- void writeTimestampArrayField(@Nullable Timestamp[] val) {
- doWriteTimestampArray(val);
- }
-
- /**
- * @param val Value.
- * @throws PortableException In case of error.
- */
- void writeObjectArrayField(@Nullable Object[] val) throws PortableException {
- doWriteObjectArray(val);
- }
-
- /**
- * @param col Collection.
- * @throws PortableException In case of error.
- */
- void writeCollectionField(@Nullable Collection<?> col) throws PortableException {
- doWriteCollection(col);
- }
-
- /**
- * @param map Map.
- * @throws PortableException In case of error.
- */
- void writeMapField(@Nullable Map<?, ?> map) throws PortableException {
- doWriteMap(map);
- }
-
- /**
- * @param e Map entry.
- * @throws PortableException In case of error.
- */
- void writeMapEntryField(@Nullable Map.Entry<?, ?> e) throws PortableException {
- doWriteMapEntry(e);
- }
-
- /**
- * @param val Value.
- */
- void writeEnumField(@Nullable Enum<?> val) {
- doWriteEnum(val);
- }
-
- /**
- * @param val Value.
- */
- void writeEnumArrayField(@Nullable Object[] val) {
- doWriteEnumArray(val);
- }
-
- /**
- * @param po Portable object.
- * @throws PortableException In case of error.
- */
- void writePortableObjectField(@Nullable PortableObjectImpl po) throws PortableException {
- doWritePortableObject(po);
- }
-
- /** {@inheritDoc} */
- @Override public void writeByte(String fieldName, byte val) throws PortableException {
- writeFieldId(fieldName, BYTE);
- writeByteField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeByte(byte val) throws PortableException {
- doWriteByte(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeShort(String fieldName, short val) throws PortableException {
- writeFieldId(fieldName, SHORT);
- writeShortField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeShort(short val) throws PortableException {
- doWriteShort(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeInt(String fieldName, int val) throws PortableException {
- writeFieldId(fieldName, INT);
- writeIntField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeInt(int val) throws PortableException {
- doWriteInt(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeLong(String fieldName, long val) throws PortableException {
- writeFieldId(fieldName, LONG);
- writeLongField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeLong(long val) throws PortableException {
- doWriteLong(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeFloat(String fieldName, float val) throws PortableException {
- writeFieldId(fieldName, FLOAT);
- writeFloatField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeFloat(float val) throws PortableException {
- doWriteFloat(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDouble(String fieldName, double val) throws PortableException {
- writeFieldId(fieldName, DOUBLE);
- writeDoubleField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDouble(double val) throws PortableException {
- doWriteDouble(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeChar(String fieldName, char val) throws PortableException {
- writeFieldId(fieldName, CHAR);
- writeCharField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeChar(char val) throws PortableException {
- doWriteChar(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeBoolean(String fieldName, boolean val) throws PortableException {
- writeFieldId(fieldName, BOOLEAN);
- writeBooleanField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeBoolean(boolean val) throws PortableException {
- doWriteBoolean(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws PortableException {
- writeFieldId(fieldName, DECIMAL);
- writeDecimalField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDecimal(@Nullable BigDecimal val) throws PortableException {
- doWriteDecimal(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeString(String fieldName, @Nullable String val) throws PortableException {
- writeFieldId(fieldName, STRING);
- writeStringField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeString(@Nullable String val) throws PortableException {
- doWriteString(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeUuid(String fieldName, @Nullable UUID val) throws PortableException {
- writeFieldId(fieldName, UUID);
- writeUuidField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeUuid(@Nullable UUID val) throws PortableException {
- doWriteUuid(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDate(String fieldName, @Nullable Date val) throws PortableException {
- writeFieldId(fieldName, DATE);
- writeDateField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDate(@Nullable Date val) throws PortableException {
- doWriteDate(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws PortableException {
- writeFieldId(fieldName, TIMESTAMP);
- writeTimestampField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeTimestamp(@Nullable Timestamp val) throws PortableException {
- doWriteTimestamp(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeObject(String fieldName, @Nullable Object obj) throws PortableException {
- writeFieldId(fieldName, OBJ);
- writeObjectField(obj);
- }
-
- /** {@inheritDoc} */
- @Override public void writeObject(@Nullable Object obj) throws PortableException {
- doWriteObject(obj);
- }
-
- /** {@inheritDoc} */
- @Override public void writeObjectDetached(@Nullable Object obj) throws PortableException {
- if (obj == null)
- doWriteByte(NULL);
- else {
- PortableWriterExImpl writer = new PortableWriterExImpl(ctx, out, new IdentityHashMap<Object, Integer>());
-
- writer.marshal(obj);
- }
- }
-
- /** {@inheritDoc} */
- @Override public void writeByteArray(String fieldName, @Nullable byte[] val) throws PortableException {
- writeFieldId(fieldName, BYTE_ARR);
- writeByteArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeByteArray(@Nullable byte[] val) throws PortableException {
- doWriteByteArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeShortArray(String fieldName, @Nullable short[] val) throws PortableException {
- writeFieldId(fieldName, SHORT_ARR);
- writeShortArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeShortArray(@Nullable short[] val) throws PortableException {
- doWriteShortArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeIntArray(String fieldName, @Nullable int[] val) throws PortableException {
- writeFieldId(fieldName, INT_ARR);
- writeIntArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeIntArray(@Nullable int[] val) throws PortableException {
- doWriteIntArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeLongArray(String fieldName, @Nullable long[] val) throws PortableException {
- writeFieldId(fieldName, LONG_ARR);
- writeLongArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeLongArray(@Nullable long[] val) throws PortableException {
- doWriteLongArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeFloatArray(String fieldName, @Nullable float[] val) throws PortableException {
- writeFieldId(fieldName, FLOAT_ARR);
- writeFloatArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeFloatArray(@Nullable float[] val) throws PortableException {
- doWriteFloatArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDoubleArray(String fieldName, @Nullable double[] val)
- throws PortableException {
- writeFieldId(fieldName, DOUBLE_ARR);
- writeDoubleArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDoubleArray(@Nullable double[] val) throws PortableException {
- doWriteDoubleArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeCharArray(String fieldName, @Nullable char[] val) throws PortableException {
- writeFieldId(fieldName, CHAR_ARR);
- writeCharArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeCharArray(@Nullable char[] val) throws PortableException {
- doWriteCharArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeBooleanArray(String fieldName, @Nullable boolean[] val)
- throws PortableException {
- writeFieldId(fieldName, BOOLEAN_ARR);
- writeBooleanArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeBooleanArray(@Nullable boolean[] val) throws PortableException {
- doWriteBooleanArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val)
- throws PortableException {
- writeFieldId(fieldName, DECIMAL_ARR);
- writeDecimalArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDecimalArray(@Nullable BigDecimal[] val) throws PortableException {
- doWriteDecimalArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeStringArray(String fieldName, @Nullable String[] val)
- throws PortableException {
- writeFieldId(fieldName, STRING_ARR);
- writeStringArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeStringArray(@Nullable String[] val) throws PortableException {
- doWriteStringArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws PortableException {
- writeFieldId(fieldName, UUID_ARR);
- writeUuidArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeUuidArray(@Nullable UUID[] val) throws PortableException {
- doWriteUuidArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDateArray(String fieldName, @Nullable Date[] val) throws PortableException {
- writeFieldId(fieldName, DATE_ARR);
- writeDateArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeDateArray(@Nullable Date[] val) throws PortableException {
- doWriteDateArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws PortableException {
- writeFieldId(fieldName, TIMESTAMP_ARR);
- writeTimestampArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeTimestampArray(@Nullable Timestamp[] val) throws PortableException {
- doWriteTimestampArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeObjectArray(String fieldName, @Nullable Object[] val) throws PortableException {
- writeFieldId(fieldName, OBJ_ARR);
- writeObjectArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public void writeObjectArray(@Nullable Object[] val) throws PortableException {
- doWriteObjectArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public <T> void writeCollection(String fieldName, @Nullable Collection<T> col)
- throws PortableException {
- writeFieldId(fieldName, COL);
- writeCollectionField(col);
- }
-
- /** {@inheritDoc} */
- @Override public <T> void writeCollection(@Nullable Collection<T> col) throws PortableException {
- doWriteCollection(col);
- }
-
- /** {@inheritDoc} */
- @Override public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map)
- throws PortableException {
- writeFieldId(fieldName, MAP);
- writeMapField(map);
- }
-
- /** {@inheritDoc} */
- @Override public <K, V> void writeMap(@Nullable Map<K, V> map) throws PortableException {
- doWriteMap(map);
- }
-
- /** {@inheritDoc} */
- @Override public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws PortableException {
- writeFieldId(fieldName, ENUM);
- writeEnumField(val);
- }
-
- /** {@inheritDoc} */
- @Override public <T extends Enum<?>> void writeEnum(T val) throws PortableException {
- doWriteEnum(val);
- }
-
- /** {@inheritDoc} */
- @Override public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws PortableException {
- writeFieldId(fieldName, ENUM_ARR);
- writeEnumArrayField(val);
- }
-
- /** {@inheritDoc} */
- @Override public <T extends Enum<?>> void writeEnumArray(T[] val) throws PortableException {
- doWriteEnumArray(val);
- }
-
- /** {@inheritDoc} */
- @Override public PortableRawWriter rawWriter() {
- if (rawOffPos == 0)
- rawOffPos = out.position();
-
- return this;
- }
-
- /** {@inheritDoc} */
- @Override public PortableOutputStream out() {
- return out;
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("NullableProblems")
- @Override public void writeBytes(String s) throws IOException {
- int len = s.length();
-
- writeInt(len);
-
- for (int i = 0; i < len; i++)
- writeByte(s.charAt(i));
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("NullableProblems")
- @Override public void writeChars(String s) throws IOException {
- int len = s.length();
-
- writeInt(len);
-
- for (int i = 0; i < len; i++)
- writeChar(s.charAt(i));
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("NullableProblems")
- @Override public void writeUTF(String s) throws IOException {
- writeString(s);
- }
-
- /** {@inheritDoc} */
- @Override public void writeByte(int v) throws IOException {
- doWriteByte((byte) v);
- }
-
- /** {@inheritDoc} */
- @Override public void writeShort(int v) throws IOException {
- doWriteShort((short) v);
- }
-
- /** {@inheritDoc} */
- @Override public void writeChar(int v) throws IOException {
- doWriteChar((char) v);
- }
-
- /** {@inheritDoc} */
- @Override public void write(int b) throws IOException {
- doWriteByte((byte) b);
- }
-
- /** {@inheritDoc} */
- @Override public void flush() throws IOException {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override public int reserveInt() {
- return reserve(LEN_INT);
- }
-
- /** {@inheritDoc} */
- @Override public void writeInt(int pos, int val) throws PortableException {
- out.writeInt(pos, val);
- }
-
- /**
- * @param fieldName Field name.
- * @throws PortableException If fields are not allowed.
- */
- private void writeFieldId(String fieldName, byte fieldType) throws PortableException {
- A.notNull(fieldName, "fieldName");
-
- if (rawOffPos != 0)
- throw new PortableException("Individual field can't be written after raw writer is acquired " +
- "via rawWriter() method. Consider fixing serialization logic for class: " + cls.getName());
-
- if (idMapper == null)
- idMapper = ctx.userTypeIdMapper(typeId);
-
- int id = idMapper.fieldId(typeId, fieldName);
-
- writeFieldId(id);
-
- if (metaEnabled)
- metaHashSum = 31 * metaHashSum + (id + fieldType);
- }
-
- /**
- * Write field ID.
- * @param fieldId Field ID.
- */
- public void writeFieldId(int fieldId) {
- int fieldOff = out.position() - start;
-
- if (schema == null) {
- schema = SCHEMA.get();
-
- if (schema == null) {
- schema = new SchemaHolder();
-
- SCHEMA.set(schema);
- }
-
- // Initialize offset when the first field is written.
- schemaId = FNV1_OFFSET_BASIS;
- }
-
- // Advance schema hash.
- int schemaId0 = schemaId ^ (fieldId & 0xFF);
- schemaId0 = schemaId0 * FNV1_PRIME;
- schemaId0 = schemaId0 ^ ((fieldId >> 8) & 0xFF);
- schemaId0 = schemaId0 * FNV1_PRIME;
- schemaId0 = schemaId0 ^ ((fieldId >> 16) & 0xFF);
- schemaId0 = schemaId0 * FNV1_PRIME;
- schemaId0 = schemaId0 ^ ((fieldId >> 24) & 0xFF);
- schemaId0 = schemaId0 * FNV1_PRIME;
-
- schemaId = schemaId0;
-
- schema.push(fieldId, fieldOff);
-
- fieldCnt++;
- }
-
- /**
- * Attempts to write the object as a handle.
- *
- * @param obj Object to write.
- * @return {@code true} if the object has been written as a handle.
- */
- boolean tryWriteAsHandle(Object obj) {
- int handle = handle(obj);
-
- if (handle >= 0) {
- doWriteByte(GridPortableMarshaller.HANDLE);
- doWriteInt(handle);
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Create new writer with same context.
- *
- * @param typeId type
- * @return New writer.
- */
- public PortableWriterExImpl newWriter(int typeId) {
- PortableWriterExImpl res = new PortableWriterExImpl(ctx, out, handles);
-
- res.typeId = typeId;
-
- return res;
- }
-
- /**
- * @return Portable context.
- */
- public PortableContext context() {
- return ctx;
- }
-
- /**
- * Schema holder.
- */
- private static class SchemaHolder {
- /** Grow step. */
- private static final int GROW_STEP = 64;
-
- /** Maximum stable size. */
- private static final int MAX_SIZE = 1024;
-
- /** Data. */
- private int[] data;
-
- /** Index. */
- private int idx;
-
- /**
- * Constructor.
- */
- public SchemaHolder() {
- data = new int[GROW_STEP];
- }
-
- /**
- * Push another frame.
- *
- * @param id Field ID.
- * @param off Field offset.
- */
- public void push(int id, int off) {
- if (idx == data.length) {
- int[] data0 = new int[data.length + GROW_STEP];
-
- System.arraycopy(data, 0, data0, 0, data.length);
-
- data = data0;
- }
-
- data[idx] = id;
- data[idx + 1] = off;
-
- idx += 2;
- }
-
- /**
- * Write collected frames and pop them.
- *
- * @param writer Writer.
- * @param fieldCnt Count.
- * @return Amount of bytes dedicated to
- */
- public int write(PortableWriterExImpl writer, int fieldCnt) {
- int startIdx = idx - fieldCnt * 2;
-
- assert startIdx >= 0;
-
- int lastOffset = data[idx - 1];
-
- int res;
-
- if (lastOffset < MAX_OFFSET_1) {
- for (int idx0 = startIdx; idx0 < idx; ) {
- writer.writeInt(data[idx0++]);
- writer.writeByte((byte) data[idx0++]);
- }
-
- res = PortableUtils.OFFSET_1;
- }
- else if (lastOffset < MAX_OFFSET_2) {
- for (int idx0 = startIdx; idx0 < idx; ) {
- writer.writeInt(data[idx0++]);
- writer.writeShort((short)data[idx0++]);
- }
-
- res = PortableUtils.OFFSET_2;
- }
- else {
- for (int idx0 = startIdx; idx0 < idx; ) {
- writer.writeInt(data[idx0++]);
- writer.writeInt(data[idx0++]);
- }
-
- res = PortableUtils.OFFSET_4;
- }
-
- return res;
- }
-
- /**
- * Pop current object's frame.
- */
- public void pop(int fieldCnt) {
- idx = idx - fieldCnt * 2;
-
- // Shrink data array if needed.
- if (idx == 0 && data.length > MAX_SIZE)
- data = new int[MAX_SIZE];
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
new file mode 100644
index 0000000..8844660
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
@@ -0,0 +1,569 @@
+/*
+ * 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.portable.builder;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.portable.BinaryObjectImpl;
+import org.apache.ignite.internal.portable.BinaryObjectOffheapImpl;
+import org.apache.ignite.internal.portable.BinaryWriterExImpl;
+import org.apache.ignite.internal.portable.GridPortableMarshaller;
+import org.apache.ignite.internal.portable.PortableContext;
+import org.apache.ignite.internal.portable.PortableUtils;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.util.GridArgumentCheck;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DFLT_HDR_LEN;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLAGS_POS;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.HASH_CODE_POS;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.PROTO_VER_POS;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TYPE_ID_POS;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
+
+/**
+ *
+ */
+public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
+ /** */
+ private static final Object REMOVED_FIELD_MARKER = new Object();
+
+ /** */
+ private final PortableContext ctx;
+
+ /** */
+ private final int typeId;
+
+ /** May be null. */
+ private String typeName;
+
+ /** May be null. */
+ private String clsNameToWrite;
+
+ /** */
+ private boolean registeredType = true;
+
+ /** */
+ private Map<String, Object> assignedVals;
+
+ /** */
+ private Map<Integer, Object> readCache;
+
+ /** Position of object in source array, or -1 if object is not created from PortableObject. */
+ private final int start;
+
+ /** Flags. */
+ private final short flags;
+
+ /** Total header length */
+ private final int hdrLen;
+
+ /** Context of PortableObject reading process. Or {@code null} if object is not created from PortableObject. */
+ private final PortableBuilderReader reader;
+
+ /** */
+ private int hashCode;
+
+ /**
+ * @param clsName Class name.
+ * @param ctx Portable context.
+ */
+ public BinaryObjectBuilderImpl(PortableContext ctx, String clsName) {
+ this(ctx, ctx.typeId(clsName), PortableContext.typeName(clsName));
+ }
+
+ /**
+ * @param typeId Type ID.
+ * @param ctx Portable context.
+ */
+ public BinaryObjectBuilderImpl(PortableContext ctx, int typeId) {
+ this(ctx, typeId, null);
+ }
+
+ /**
+ * @param typeName Type name.
+ * @param ctx Context.
+ * @param typeId Type id.
+ */
+ public BinaryObjectBuilderImpl(PortableContext ctx, int typeId, String typeName) {
+ this.typeId = typeId;
+ this.typeName = typeName;
+ this.ctx = ctx;
+
+ start = -1;
+ flags = -1;
+ reader = null;
+ hdrLen = DFLT_HDR_LEN;
+
+ readCache = Collections.emptyMap();
+ }
+
+ /**
+ * @param obj Object to wrap.
+ */
+ public BinaryObjectBuilderImpl(BinaryObjectImpl obj) {
+ this(new PortableBuilderReader(obj), obj.start());
+
+ reader.registerObject(this);
+ }
+
+ /**
+ * @param reader ctx
+ * @param start Start.
+ */
+ BinaryObjectBuilderImpl(PortableBuilderReader reader, int start) {
+ this.reader = reader;
+ this.start = start;
+ this.flags = reader.readShortPositioned(start + FLAGS_POS);
+
+ byte ver = reader.readBytePositioned(start + PROTO_VER_POS);
+
+ PortableUtils.checkProtocolVersion(ver);
+
+ int typeId = reader.readIntPositioned(start + TYPE_ID_POS);
+ ctx = reader.portableContext();
+ hashCode = reader.readIntPositioned(start + HASH_CODE_POS);
+
+ if (typeId == UNREGISTERED_TYPE_ID) {
+ int mark = reader.position();
+
+ reader.position(start + DFLT_HDR_LEN);
+
+ clsNameToWrite = reader.readString();
+
+ Class cls;
+
+ try {
+ // TODO: IGNITE-1272 - Is class loader needed here?
+ cls = U.forName(clsNameToWrite, null);
+ }
+ catch (ClassNotFoundException e) {
+ throw new BinaryInvalidTypeException("Failed to load the class: " + clsNameToWrite, e);
+ }
+
+ this.typeId = ctx.descriptorForClass(cls).typeId();
+
+ registeredType = false;
+
+ hdrLen = reader.position() - mark;
+
+ reader.position(mark);
+ }
+ else {
+ this.typeId = typeId;
+ hdrLen = DFLT_HDR_LEN;
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObject build() {
+ try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, typeId, false)) {
+
+ PortableBuilderSerializer serializationCtx = new PortableBuilderSerializer();
+
+ serializationCtx.registerObjectWriting(this, 0);
+
+ serializeTo(writer, serializationCtx);
+
+ byte[] arr = writer.array();
+
+ return new BinaryObjectImpl(ctx, arr, 0);
+ }
+ }
+
+ /**
+ * @param writer Writer.
+ * @param serializer Serializer.
+ */
+ void serializeTo(BinaryWriterExImpl writer, PortableBuilderSerializer serializer) {
+ try {
+ PortableUtils.writeHeader(writer,
+ true,
+ registeredType ? typeId : UNREGISTERED_TYPE_ID,
+ hashCode,
+ registeredType ? null : clsNameToWrite);
+
+ Set<Integer> remainsFlds = null;
+
+ if (reader != null) {
+ Map<Integer, Object> assignedFldsById;
+
+ if (assignedVals != null) {
+ assignedFldsById = U.newHashMap(assignedVals.size());
+
+ for (Map.Entry<String, Object> entry : assignedVals.entrySet()) {
+ int fldId = ctx.fieldId(typeId, entry.getKey());
+
+ assignedFldsById.put(fldId, entry.getValue());
+ }
+
+ remainsFlds = assignedFldsById.keySet();
+ } else
+ assignedFldsById = Collections.emptyMap();
+
+ // Get footer details.
+ int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+
+ IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start, fieldOffsetSize);
+
+ int footerPos = footer.get1();
+ int footerEnd = footer.get2();
+
+ // Get raw position.
+ int rawPos = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize);
+
+ // Position reader on data.
+ reader.position(start + hdrLen);
+
+ while (reader.position() + 4 < rawPos) {
+ int fieldId = reader.readIntPositioned(footerPos);
+ int fieldLen = fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldOffsetSize).get2();
+
+ int postPos = reader.position() + fieldLen; // Position where reader will be placed afterwards.
+
+ footerPos += 4 + fieldOffsetSize;
+
+ if (assignedFldsById.containsKey(fieldId)) {
+ Object assignedVal = assignedFldsById.remove(fieldId);
+
+ if (assignedVal != REMOVED_FIELD_MARKER) {
+ writer.writeFieldId(fieldId);
+
+ serializer.writeValue(writer, assignedVal);
+ }
+ }
+ else {
+ int type = fieldLen != 0 ? reader.readByte(0) : 0;
+
+ if (fieldLen != 0 && !PortableUtils.isPlainArrayType(type) && PortableUtils.isPlainType(type)) {
+ writer.writeFieldId(fieldId);
+
+ writer.write(reader.array(), reader.position(), fieldLen);
+ }
+ else {
+ writer.writeFieldId(fieldId);
+
+ Object val;
+
+ if (fieldLen == 0)
+ val = null;
+ else if (readCache == null) {
+ val = reader.parseValue();
+
+ assert reader.position() == postPos;
+ }
+ else
+ val = readCache.get(fieldId);
+
+ serializer.writeValue(writer, val);
+ }
+ }
+
+ reader.position(postPos);
+ }
+ }
+
+ if (assignedVals != null && (remainsFlds == null || !remainsFlds.isEmpty())) {
+ boolean metadataEnabled = ctx.isMetaDataEnabled(typeId);
+
+ BinaryType metadata = null;
+
+ if (metadataEnabled)
+ metadata = ctx.metaData(typeId);
+
+ Map<String, String> newFldsMetadata = null;
+
+ for (Map.Entry<String, Object> entry : assignedVals.entrySet()) {
+ Object val = entry.getValue();
+
+ if (val == REMOVED_FIELD_MARKER)
+ continue;
+
+ String name = entry.getKey();
+
+ int fldId = ctx.fieldId(typeId, name);
+
+ if (remainsFlds != null && !remainsFlds.contains(fldId))
+ continue;
+
+ writer.writeFieldId(fldId);
+
+ serializer.writeValue(writer, val);
+
+ if (metadataEnabled) {
+ String oldFldTypeName = metadata == null ? null : metadata.fieldTypeName(name);
+
+ String newFldTypeName;
+
+ if (val instanceof PortableValueWithType)
+ newFldTypeName = ((PortableValueWithType) val).typeName();
+ else {
+ byte type = PortableUtils.typeByClass(val.getClass());
+
+ newFldTypeName = CacheObjectBinaryProcessorImpl.fieldTypeName(type);
+ }
+
+ if (oldFldTypeName == null) {
+ // It's a new field, we have to add it to metadata.
+
+ if (newFldsMetadata == null)
+ newFldsMetadata = new HashMap<>();
+
+ newFldsMetadata.put(name, newFldTypeName);
+ }
+ else {
+ String objTypeName =
+ CacheObjectBinaryProcessorImpl.FIELD_TYPE_NAMES[GridPortableMarshaller.OBJ];
+
+ if (!objTypeName.equals(oldFldTypeName) && !oldFldTypeName.equals(newFldTypeName)) {
+ throw new BinaryObjectException(
+ "Wrong value has been set [" +
+ "typeName=" + (typeName == null ? metadata.typeName() : typeName) +
+ ", fieldName=" + name +
+ ", fieldType=" + oldFldTypeName +
+ ", assignedValueType=" + newFldTypeName + ']'
+ );
+ }
+ }
+ }
+ }
+
+ if (newFldsMetadata != null) {
+ String typeName = this.typeName;
+
+ if (typeName == null)
+ typeName = metadata.typeName();
+
+ ctx.updateMetaData(typeId, typeName, newFldsMetadata);
+ }
+ }
+
+ if (reader != null) {
+ // Write raw data if any.
+ int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+
+ int rawOff = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize);
+ int footerStart = PortableUtils.footerStartAbsolute(reader, start);
+
+ if (rawOff < footerStart) {
+ writer.rawWriter();
+
+ writer.write(reader.array(), rawOff, footerStart - rawOff);
+ }
+
+ // Shift reader to the end of the object.
+ reader.position(start + PortableUtils.length(reader, start));
+ }
+
+ writer.postWrite(true);
+ }
+ finally {
+ writer.popSchema();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilderImpl hashCode(int hashCode) {
+ this.hashCode = hashCode;
+
+ return this;
+ }
+
+ /**
+ * Get field position and length.
+ *
+ * @param footerPos Field position inside the footer (absolute).
+ * @param footerEnd Footer end (absolute).
+ * @param rawPos Raw data position (absolute).
+ * @param fieldOffsetSize Size of field's offset.
+ * @return Tuple with field position and length.
+ */
+ private IgniteBiTuple<Integer, Integer> fieldPositionAndLength(int footerPos, int footerEnd, int rawPos,
+ int fieldOffsetSize) {
+ // Get field offset first.
+ int fieldOffset = PortableUtils.fieldOffsetRelative(reader, footerPos + 4, fieldOffsetSize);
+ int fieldPos = start + fieldOffset;
+
+ // Get field length.
+ int fieldLen;
+
+ if (footerPos + 4 + fieldOffsetSize == footerEnd)
+ // This is the last field, compare to raw offset.
+ fieldLen = rawPos - fieldPos;
+ else {
+ // Field is somewhere in the middle, get difference with the next offset.
+ int nextFieldOffset = PortableUtils.fieldOffsetRelative(reader, footerPos + 4 + fieldOffsetSize + 4,
+ fieldOffsetSize);
+
+ fieldLen = nextFieldOffset - fieldOffset;
+ }
+
+ return F.t(fieldPos, fieldLen);
+ }
+
+ /**
+ * Initialize read cache if needed.
+ */
+ private void ensureReadCacheInit() {
+ if (readCache == null) {
+ int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+
+ Map<Integer, Object> readCache = new HashMap<>();
+
+ IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start, fieldOffsetSize);
+
+ int footerPos = footer.get1();
+ int footerEnd = footer.get2();
+
+ int rawPos = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize);
+
+ while (footerPos + 4 < footerEnd) {
+ int fieldId = reader.readIntPositioned(footerPos);
+
+ IgniteBiTuple<Integer, Integer> posAndLen =
+ fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldOffsetSize);
+
+ Object val = reader.getValueQuickly(posAndLen.get1(), posAndLen.get2());
+
+ readCache.put(fieldId, val);
+
+ // Shift current footer position.
+ footerPos += 4 + fieldOffsetSize;
+ }
+
+ this.readCache = readCache;
+ }
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override public <T> T getField(String name) {
+ Object val;
+
+ if (assignedVals != null && assignedVals.containsKey(name)) {
+ val = assignedVals.get(name);
+
+ if (val == REMOVED_FIELD_MARKER)
+ return null;
+ }
+ else {
+ ensureReadCacheInit();
+
+ int fldId = ctx.fieldId(typeId, name);
+
+ val = readCache.get(fldId);
+ }
+
+ return (T)PortableUtils.unwrapLazy(val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilder setField(String name, Object val) {
+ GridArgumentCheck.notNull(val, name);
+
+ if (assignedVals == null)
+ assignedVals = new LinkedHashMap<>();
+
+ Object oldVal = assignedVals.put(name, val);
+
+ if (oldVal instanceof PortableValueWithType) {
+ ((PortableValueWithType)oldVal).value(val);
+
+ assignedVals.put(name, oldVal);
+ }
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> BinaryObjectBuilder setField(String name, @Nullable T val, Class<? super T> type) {
+ if (assignedVals == null)
+ assignedVals = new LinkedHashMap<>();
+
+ //int fldId = ctx.fieldId(typeId, fldName);
+
+ assignedVals.put(name, new PortableValueWithType(PortableUtils.typeByClass(type), val));
+
+ return this;
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilder setField(String name, @Nullable BinaryObjectBuilder builder) {
+ if (builder == null)
+ return setField(name, null, Object.class);
+ else
+ return setField(name, (Object)builder);
+ }
+
+ /**
+ * Removes field from portable object.
+ *
+ * @param name Field name.
+ * @return {@code this} instance for chaining.
+ */
+ @Override public BinaryObjectBuilderImpl removeField(String name) {
+ if (assignedVals == null)
+ assignedVals = new LinkedHashMap<>();
+
+ assignedVals.put(name, REMOVED_FIELD_MARKER);
+
+ return this;
+ }
+
+ /**
+ * Creates builder initialized by specified portable object.
+ *
+ * @param obj Portable object to initialize builder.
+ * @return New builder.
+ */
+ public static BinaryObjectBuilderImpl wrap(BinaryObject obj) {
+ BinaryObjectImpl heapObj;
+
+ if (obj instanceof BinaryObjectOffheapImpl)
+ heapObj = (BinaryObjectImpl)((BinaryObjectOffheapImpl)obj).heapCopy();
+ else
+ heapObj = (BinaryObjectImpl)obj;
+
+ return new BinaryObjectBuilderImpl(heapObj);
+ }
+
+ /**
+ * @return Object start position in source array.
+ */
+ int start() {
+ return start;
+ }
+
+ /**
+ * @return Object type id.
+ */
+ public int typeId() {
+ return typeId;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java
index 1472d56..9eb77b4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java
@@ -18,9 +18,9 @@
package org.apache.ignite.internal.portable.builder;
import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableWriterExImpl;
+import org.apache.ignite.internal.portable.BinaryWriterExImpl;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.portable.PortableInvalidClassException;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
/**
*
@@ -61,7 +61,7 @@ public class PortableBuilderEnum implements PortableBuilderSerializationAware {
cls = U.forName(reader.readString(), null);
}
catch (ClassNotFoundException e) {
- throw new PortableInvalidClassException("Failed to load the class: " + clsName, e);
+ throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
}
this.typeId = reader.portableContext().descriptorForClass(cls).typeId();
@@ -82,7 +82,7 @@ public class PortableBuilderEnum implements PortableBuilderSerializationAware {
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
writer.writeByte(GridPortableMarshaller.ENUM);
if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
[04/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
index 349f152..22125af 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
@@ -19,12 +19,13 @@ package org.apache.ignite.internal.portable;
import java.util.Arrays;
import java.util.Map;
+import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.MarshallerContextTestImpl;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableIdMapper;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.binary.BinaryTypeIdMapper;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
/**
@@ -33,11 +34,11 @@ import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
/** */
private static final PortableMetaDataHandler META_HND = new PortableMetaDataHandler() {
- @Override public void addMeta(int typeId, PortableMetadata meta) {
+ @Override public void addMeta(int typeId, BinaryType meta) {
// No-op.
}
- @Override public PortableMetadata metadata(int typeId) {
+ @Override public BinaryType metadata(int typeId) {
return null;
}
};
@@ -46,7 +47,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
* @return Portable context.
*/
private PortableContext portableContext() {
- return new PortableContext(META_HND, null);
+ return new PortableContext(META_HND, new IgniteConfiguration());
}
/**
@@ -91,7 +92,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = portableMarshaller();
- marsh.setIdMapper(new PortableIdMapper() {
+ marsh.setIdMapper(new BinaryTypeIdMapper() {
@SuppressWarnings("IfMayBeConditional")
@Override public int typeId(String clsName) {
if (clsName.endsWith("1"))
@@ -116,7 +117,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
ctx.configure(marsh);
- Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+ Map<String, BinaryTypeIdMapper> typeMappers = U.field(ctx, "typeMappers");
assertEquals(3, typeMappers.size());
@@ -134,8 +135,8 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = portableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
- new PortableTypeConfiguration("unknown.*")
+ new BinaryTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
+ new BinaryTypeConfiguration("unknown.*")
));
ctx.configure(marsh);
@@ -157,7 +158,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = portableMarshaller();
- marsh.setIdMapper(new PortableIdMapper() {
+ marsh.setIdMapper(new BinaryTypeIdMapper() {
@SuppressWarnings("IfMayBeConditional")
@Override public int typeId(String clsName) {
if (clsName.endsWith("1"))
@@ -176,13 +177,13 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
});
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
- new PortableTypeConfiguration("unknown.*")
+ new BinaryTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
+ new BinaryTypeConfiguration("unknown.*")
));
ctx.configure(marsh);
- Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+ Map<String, BinaryTypeIdMapper> typeMappers = U.field(ctx, "typeMappers");
assertEquals(3, typeMappers.size());
@@ -199,7 +200,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = portableMarshaller();
- marsh.setIdMapper(new PortableIdMapper() {
+ marsh.setIdMapper(new BinaryTypeIdMapper() {
@SuppressWarnings("IfMayBeConditional")
@Override public int typeId(String clsName) {
if (clsName.endsWith("1"))
@@ -218,13 +219,13 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
});
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
- new PortableTypeConfiguration("unknown.*")
+ new BinaryTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
+ new BinaryTypeConfiguration("unknown.*")
));
ctx.configure(marsh);
- Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+ Map<String, BinaryTypeIdMapper> typeMappers = U.field(ctx, "typeMappers");
assertEquals(3, typeMappers.size());
@@ -245,10 +246,10 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
"org.apache.ignite.internal.portable.test.*"
));
- PortableTypeConfiguration typeCfg = new PortableTypeConfiguration();
+ BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
typeCfg.setClassName("org.apache.ignite.internal.portable.test.GridPortableTestClass2");
- typeCfg.setIdMapper(new PortableIdMapper() {
+ typeCfg.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 100;
}
@@ -270,7 +271,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
assertTrue(typeIds.containsKey("innerclass".hashCode()));
assertFalse(typeIds.containsKey("gridportabletestclass2".hashCode()));
- Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+ Map<String, BinaryTypeIdMapper> typeMappers = U.field(ctx, "typeMappers");
assertEquals(100, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
}
@@ -306,7 +307,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = portableMarshaller();
- marsh.setIdMapper(new PortableIdMapper() {
+ marsh.setIdMapper(new BinaryTypeIdMapper() {
@SuppressWarnings("IfMayBeConditional")
@Override public int typeId(String clsName) {
if (clsName.endsWith("1"))
@@ -329,7 +330,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
ctx.configure(marsh);
- Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+ Map<String, BinaryTypeIdMapper> typeMappers = U.field(ctx, "typeMappers");
assertEquals(3, typeMappers.size());
@@ -346,8 +347,8 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = portableMarshaller();
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration("org.apache.ignite.portable.testjar.*"),
- new PortableTypeConfiguration("unknown.*")
+ new BinaryTypeConfiguration("org.apache.ignite.portable.testjar.*"),
+ new BinaryTypeConfiguration("unknown.*")
));
ctx.configure(marsh);
@@ -368,7 +369,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = portableMarshaller();
- marsh.setIdMapper(new PortableIdMapper() {
+ marsh.setIdMapper(new BinaryTypeIdMapper() {
@SuppressWarnings("IfMayBeConditional")
@Override public int typeId(String clsName) {
if (clsName.endsWith("1"))
@@ -385,13 +386,13 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
});
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration("org.apache.ignite.portable.testjar.*"),
- new PortableTypeConfiguration("unknown.*")
+ new BinaryTypeConfiguration("org.apache.ignite.portable.testjar.*"),
+ new BinaryTypeConfiguration("unknown.*")
));
ctx.configure(marsh);
- Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+ Map<String, BinaryTypeIdMapper> typeMappers = U.field(ctx, "typeMappers");
assertEquals(3, typeMappers.size());
@@ -407,7 +408,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
PortableMarshaller marsh = portableMarshaller();
- marsh.setIdMapper(new PortableIdMapper() {
+ marsh.setIdMapper(new BinaryTypeIdMapper() {
@SuppressWarnings("IfMayBeConditional")
@Override public int typeId(String clsName) {
if (clsName.endsWith("1"))
@@ -424,13 +425,13 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
});
marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration("org.apache.ignite.portable.testjar.*"),
- new PortableTypeConfiguration("unknown.*")
+ new BinaryTypeConfiguration("org.apache.ignite.portable.testjar.*"),
+ new BinaryTypeConfiguration("unknown.*")
));
ctx.configure(marsh);
- Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+ Map<String, BinaryTypeIdMapper> typeMappers = U.field(ctx, "typeMappers");
assertEquals(3, typeMappers.size());
@@ -450,10 +451,10 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
"org.apache.ignite.portable.testjar.*"
));
- PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(
+ BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(
"org.apache.ignite.portable.testjar.GridPortableTestClass2");
- typeCfg.setIdMapper(new PortableIdMapper() {
+ typeCfg.setIdMapper(new BinaryTypeIdMapper() {
@Override public int typeId(String clsName) {
return 100;
}
@@ -473,7 +474,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
- Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+ Map<String, BinaryTypeIdMapper> typeMappers = U.field(ctx, "typeMappers");
assertEquals(3, typeMappers.size());
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsAbstractSelfTest.java
index 28058de..db3c821 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsAbstractSelfTest.java
@@ -17,16 +17,16 @@
package org.apache.ignite.internal.portable;
+import java.util.Arrays;
+import org.apache.ignite.binary.BinaryField;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.marshaller.MarshallerContextTestImpl;
import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableField;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableTypeConfiguration;
import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import java.util.Arrays;
-
/**
* Contains tests for compact offsets.
*/
@@ -39,11 +39,11 @@ public abstract class PortableCompactOffsetsAbstractSelfTest extends GridCommonA
/** Dummy metadata handler. */
protected static final PortableMetaDataHandler META_HND = new PortableMetaDataHandler() {
- @Override public void addMeta(int typeId, PortableMetadata meta) {
+ @Override public void addMeta(int typeId, BinaryType meta) {
// No-op.
}
- @Override public PortableMetadata metadata(int typeId) {
+ @Override public BinaryType metadata(int typeId) {
return null;
}
};
@@ -58,11 +58,11 @@ public abstract class PortableCompactOffsetsAbstractSelfTest extends GridCommonA
@Override protected void beforeTest() throws Exception {
super.beforeTest();
- ctx = new PortableContext(META_HND, null);
+ ctx = new PortableContext(META_HND, new IgniteConfiguration());
marsh = new PortableMarshaller();
- marsh.setTypeConfigurations(Arrays.asList(new PortableTypeConfiguration(TestObject.class.getName())));
+ marsh.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(TestObject.class.getName())));
marsh.setContext(new MarshallerContextTestImpl(null));
IgniteUtils.invoke(PortableMarshaller.class, marsh, "setPortableContext", ctx);
@@ -123,7 +123,7 @@ public abstract class PortableCompactOffsetsAbstractSelfTest extends GridCommonA
private void check(int len) throws Exception {
TestObject obj = new TestObject(len);
- PortableObjectEx portObj = toPortable(marsh, obj);
+ BinaryObjectEx portObj = toPortable(marsh, obj);
// 1. Test portable object content.
assert portObj.hasField("field1");
@@ -139,8 +139,8 @@ public abstract class PortableCompactOffsetsAbstractSelfTest extends GridCommonA
assert obj.field2 == field2;
// 2. Test fields API.
- PortableField field1Desc = portObj.fieldDescriptor("field1");
- PortableField field2Desc = portObj.fieldDescriptor("field2");
+ BinaryField field1Desc = portObj.fieldDescriptor("field1");
+ BinaryField field2Desc = portObj.fieldDescriptor("field2");
assert field1Desc.exists(portObj);
assert field2Desc.exists(portObj);
@@ -165,7 +165,7 @@ public abstract class PortableCompactOffsetsAbstractSelfTest extends GridCommonA
* @return Portable object.
* @throws Exception If failed.
*/
- protected abstract PortableObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception;
+ protected abstract BinaryObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception;
/**
* Test object.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsHeapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsHeapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsHeapSelfTest.java
index 826f972..ebdef38 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsHeapSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsHeapSelfTest.java
@@ -24,9 +24,9 @@ import org.apache.ignite.marshaller.portable.PortableMarshaller;
*/
public class PortableCompactOffsetsHeapSelfTest extends PortableCompactOffsetsAbstractSelfTest {
/** {@inheritDoc} */
- @Override protected PortableObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception {
+ @Override protected BinaryObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception {
byte[] bytes = marsh.marshal(obj);
- return new PortableObjectImpl(ctx, bytes, 0);
+ return new BinaryObjectImpl(ctx, bytes, 0);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsOffheapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsOffheapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsOffheapSelfTest.java
index 9ad1c67..e3b6bda 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsOffheapSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableCompactOffsetsOffheapSelfTest.java
@@ -47,7 +47,7 @@ public class PortableCompactOffsetsOffheapSelfTest extends PortableCompactOffset
}
/** {@inheritDoc} */
- @Override protected PortableObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception {
+ @Override protected BinaryObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception {
byte[] arr = marsh.marshal(obj);
long ptr = UNSAFE.allocateMemory(arr.length);
@@ -56,6 +56,6 @@ public class PortableCompactOffsetsOffheapSelfTest extends PortableCompactOffset
UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
- return new PortableObjectOffheapImpl(ctx, ptr, 0, arr.length);
+ return new BinaryObjectOffheapImpl(ctx, ptr, 0, arr.length);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java
deleted file mode 100644
index 0d712dc..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsAbstractSelfTest.java
+++ /dev/null
@@ -1,729 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableField;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableTypeConfiguration;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.UUID;
-
-/**
- * Contains tests for portable object fields.
- */
-public abstract class PortableFieldsAbstractSelfTest extends GridCommonAbstractTest {
- /** Dummy metadata handler. */
- protected static final PortableMetaDataHandler META_HND = new PortableMetaDataHandler() {
- @Override public void addMeta(int typeId, PortableMetadata meta) {
- // No-op.
- }
-
- @Override public PortableMetadata metadata(int typeId) {
- return null;
- }
- };
-
- /** Marshaller. */
- protected PortableMarshaller dfltMarsh;
-
- /**
- * Create marshaller.
- *
- * @param stringAsBytes Whether to marshal strings as bytes (UTF8).
- * @return Portable marshaller.
- * @throws Exception If failed.
- */
- protected static PortableMarshaller createMarshaller(boolean stringAsBytes) throws Exception {
- PortableContext ctx = new PortableContext(META_HND, null);
-
- PortableMarshaller marsh = new PortableMarshaller();
-
- marsh.setConvertStringToBytes(stringAsBytes);
-
- marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(TestObject.class.getName()),
- new PortableTypeConfiguration(TestOuterObject.class.getName()),
- new PortableTypeConfiguration(TestInnerObject.class.getName())
- ));
-
- marsh.setContext(new MarshallerContextTestImpl(null));
-
- IgniteUtils.invoke(PortableMarshaller.class, marsh, "setPortableContext", ctx);
-
- return marsh;
- }
-
- /**
- * Get portable context for the current marshaller.
- *
- * @param marsh Marshaller.
- * @return Portable context.
- */
- protected static PortableContext portableContext(PortableMarshaller marsh) {
- GridPortableMarshaller impl = U.field(marsh, "impl");
-
- return impl.context();
- }
-
- /** {@inheritDoc} */
- @Override protected void beforeTest() throws Exception {
- super.beforeTest();
-
- dfltMarsh = createMarshaller(true);
- }
-
- /**
- * Test byte field.
- *
- * @throws Exception If failed.
- */
- public void testByte() throws Exception {
- check("fByte");
- }
-
- /**
- * Test byte array field.
- *
- * @throws Exception If failed.
- */
- public void testByteArray() throws Exception {
- check("fByteArr");
- }
-
- /**
- * Test boolean field.
- *
- * @throws Exception If failed.
- */
- public void testBoolean() throws Exception {
- check("fBool");
- }
-
- /**
- * Test boolean array field.
- *
- * @throws Exception If failed.
- */
- public void testBooleanArray() throws Exception {
- check("fBoolArr");
- }
-
- /**
- * Test short field.
- *
- * @throws Exception If failed.
- */
- public void testShort() throws Exception {
- check("fShort");
- }
-
- /**
- * Test short array field.
- *
- * @throws Exception If failed.
- */
- public void testShortArray() throws Exception {
- check("fShortArr");
- }
-
- /**
- * Test char field.
- *
- * @throws Exception If failed.
- */
- public void testChar() throws Exception {
- check("fChar");
- }
-
- /**
- * Test char array field.
- *
- * @throws Exception If failed.
- */
- public void testCharArray() throws Exception {
- check("fCharArr");
- }
-
- /**
- * Test int field.
- *
- * @throws Exception If failed.
- */
- public void testInt() throws Exception {
- check("fInt");
- }
-
- /**
- * Test int array field.
- *
- * @throws Exception If failed.
- */
- public void testIntArray() throws Exception {
- check("fIntArr");
- }
-
- /**
- * Test long field.
- *
- * @throws Exception If failed.
- */
- public void testLong() throws Exception {
- check("fLong");
- }
-
- /**
- * Test long array field.
- *
- * @throws Exception If failed.
- */
- public void testLongArray() throws Exception {
- check("fLongArr");
- }
-
- /**
- * Test float field.
- *
- * @throws Exception If failed.
- */
- public void testFloat() throws Exception {
- check("fFloat");
- }
-
- /**
- * Test float array field.
- *
- * @throws Exception If failed.
- */
- public void testFloatArray() throws Exception {
- check("fFloatArr");
- }
-
- /**
- * Test double field.
- *
- * @throws Exception If failed.
- */
- public void testDouble() throws Exception {
- check("fDouble");
- }
-
- /**
- * Test double array field.
- *
- * @throws Exception If failed.
- */
- public void testDoubleArray() throws Exception {
- check("fDoubleArr");
- }
-
- /**
- * Test string field.
- *
- * @throws Exception If failed.
- */
- public void testString() throws Exception {
- check("fString");
- }
-
- /**
- * Test string field.
- *
- * @throws Exception If failed.
- */
- public void testStringAsChars() throws Exception {
- PortableMarshaller marsh = createMarshaller(false);
-
- checkNormal(marsh, "fString", true);
- checkNested(marsh, "fString", true);
- }
-
- /**
- * Test string array field.
- *
- * @throws Exception If failed.
- */
- public void testStringArray() throws Exception {
- check("fStringArr");
- }
-
- /**
- * Test date field.
- *
- * @throws Exception If failed.
- */
- public void testDate() throws Exception {
- check("fDate");
- }
-
- /**
- * Test date array field.
- *
- * @throws Exception If failed.
- */
- public void testDateArray() throws Exception {
- check("fDateArr");
- }
-
- /**
- * Test timestamp field.
- *
- * @throws Exception If failed.
- */
- public void testTimestamp() throws Exception {
- check("fTimestamp");
- }
-
- /**
- * Test timestamp array field.
- *
- * @throws Exception If failed.
- */
- public void testTimestampArray() throws Exception {
- check("fTimestampArr");
- }
-
- /**
- * Test UUID field.
- *
- * @throws Exception If failed.
- */
- public void testUuid() throws Exception {
- check("fUuid");
- }
-
- /**
- * Test UUID array field.
- *
- * @throws Exception If failed.
- */
- public void testUuidArray() throws Exception {
- check("fUuidArr");
- }
-
- /**
- * Test decimal field.
- *
- * @throws Exception If failed.
- */
- public void testDecimal() throws Exception {
- check("fDecimal");
- }
-
- /**
- * Test decimal array field.
- *
- * @throws Exception If failed.
- */
- public void testDecimalArray() throws Exception {
- check("fDecimalArr");
- }
-
- /**
- * Test object field.
- *
- * @throws Exception If failed.
- */
- public void testObject() throws Exception {
- check("fObj");
- }
-
- /**
- * Test object array field.
- *
- * @throws Exception If failed.
- */
- public void testObjectArray() throws Exception {
- check("fObjArr");
- }
-
- /**
- * Test null field.
- *
- * @throws Exception If failed.
- */
- public void testNull() throws Exception {
- check("fNull");
- }
-
- /**
- * Test missing field.
- *
- * @throws Exception If failed.
- */
- public void testMissing() throws Exception {
- String fieldName = "fMissing";
-
- checkNormal(dfltMarsh, fieldName, false);
- checkNested(dfltMarsh, fieldName, false);
- }
-
- /**
- * Check field resolution in both normal and nested modes.
- *
- * @param fieldName Field name.
- * @throws Exception If failed.
- */
- public void check(String fieldName) throws Exception {
- checkNormal(dfltMarsh, fieldName, true);
- checkNested(dfltMarsh, fieldName, true);
- }
-
- /**
- * Check field.
- *
- * @param marsh Marshaller.
- * @param fieldName Field name.
- * @param exists Whether field should exist.
- * @throws Exception If failed.
- */
- private void checkNormal(PortableMarshaller marsh, String fieldName, boolean exists) throws Exception {
- TestContext testCtx = context(marsh, fieldName);
-
- check0(fieldName, testCtx, exists);
- }
-
- /**
- * Check nested field.
- *
- * @param marsh Marshaller.
- * @param fieldName Field name.
- * @param exists Whether field should exist.
- * @throws Exception If failed.
- */
- private void checkNested(PortableMarshaller marsh, String fieldName, boolean exists) throws Exception {
- TestContext testCtx = nestedContext(marsh, fieldName);
-
- check0(fieldName, testCtx, exists);
- }
-
- /**
- * Internal check routine.
- *
- * @param fieldName Field name.
- * @param ctx Context.
- * @param exists Whether field should exist.
- * @throws Exception If failed.
- */
- private void check0(String fieldName, TestContext ctx, boolean exists) throws Exception {
- Object val = ctx.field.value(ctx.portObj);
-
- if (exists) {
- assertTrue(ctx.field.exists(ctx.portObj));
-
- Object expVal = U.field(ctx.obj, fieldName);
-
- if (val instanceof PortableObject)
- val = ((PortableObject) val).deserialize();
-
- if (val != null && val.getClass().isArray()) {
- assertNotNull(expVal);
-
- if (val instanceof byte[])
- assertTrue(Arrays.equals((byte[]) expVal, (byte[]) val));
- else if (val instanceof boolean[])
- assertTrue(Arrays.equals((boolean[]) expVal, (boolean[]) val));
- else if (val instanceof short[])
- assertTrue(Arrays.equals((short[]) expVal, (short[]) val));
- else if (val instanceof char[])
- assertTrue(Arrays.equals((char[]) expVal, (char[]) val));
- else if (val instanceof int[])
- assertTrue(Arrays.equals((int[]) expVal, (int[]) val));
- else if (val instanceof long[])
- assertTrue(Arrays.equals((long[]) expVal, (long[]) val));
- else if (val instanceof float[])
- assertTrue(Arrays.equals((float[]) expVal, (float[]) val));
- else if (val instanceof double[])
- assertTrue(Arrays.equals((double[]) expVal, (double[]) val));
- else {
- Object[] expVal0 = (Object[])expVal;
- Object[] val0 = (Object[])val;
-
- assertEquals(expVal0.length, val0.length);
-
- for (int i = 0; i < expVal0.length; i++) {
- Object expItem = expVal0[i];
- Object item = val0[i];
-
- if (item instanceof PortableObject)
- item = ((PortableObject)item).deserialize();
-
- assertEquals(expItem, item);
- }
- }
- }
- else
- assertEquals(expVal, val);
- }
- else {
- assertFalse(ctx.field.exists(ctx.portObj));
-
- assert val == null;
- }
- }
-
- /**
- * Get test context.
- *
- * @param marsh Portable marshaller.
- * @param fieldName Field name.
- * @return Test context.
- * @throws Exception If failed.
- */
- private TestContext context(PortableMarshaller marsh, String fieldName) throws Exception {
- TestObject obj = createObject();
-
- PortableObjectEx portObj = toPortable(marsh, obj);
-
- PortableField field = portObj.fieldDescriptor(fieldName);
-
- return new TestContext(obj, portObj, field);
- }
-
- /**
- * Get test context with nested test object.
- *
- * @param marsh Portable marshaller.
- * @param fieldName Field name.
- * @return Test context.
- * @throws Exception If failed.
- */
- private TestContext nestedContext(PortableMarshaller marsh, String fieldName)
- throws Exception {
- TestObject obj = createObject();
- TestOuterObject outObj = new TestOuterObject(obj);
-
- PortableObjectEx portOutObj = toPortable(marsh, outObj);
- PortableObjectEx portObj = portOutObj.field("fInner");
-
- assert portObj != null;
-
- PortableField field = portObj.fieldDescriptor(fieldName);
-
- return new TestContext(obj, portObj, field);
- }
-
- /**
- * Create test object.
- *
- * @return Test object.
- */
- private TestObject createObject() {
- return new TestObject(0);
- }
-
- /**
- * Convert object to portable object.
- *
- * @param marsh Marshaller.
- * @param obj Object.
- * @return Portable object.
- * @throws Exception If failed.
- */
- protected abstract PortableObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception;
-
- /**
- * Outer test object.
- */
- @SuppressWarnings("UnusedDeclaration")
- public static class TestOuterObject {
- /** Inner object. */
- public TestObject fInner;
-
- /**
- * Default constructor.
- */
- public TestOuterObject() {
- // No-op.
- }
-
- /**
- * Constructor.
- *
- * @param fInner Inner object.
- */
- public TestOuterObject(TestObject fInner) {
- this.fInner = fInner;
- }
- }
-
- /**
- * Test object class, c
- */
- @SuppressWarnings("UnusedDeclaration")
- public static class TestObject {
- /** Primitive fields. */
- public byte fByte;
- public boolean fBool;
- public short fShort;
- public char fChar;
- public int fInt;
- public long fLong;
- public float fFloat;
- public double fDouble;
-
- public byte[] fByteArr;
- public boolean[] fBoolArr;
- public short[] fShortArr;
- public char[] fCharArr;
- public int[] fIntArr;
- public long[] fLongArr;
- public float[] fFloatArr;
- public double[] fDoubleArr;
-
- /** Special fields. */
- public String fString;
- public Date fDate;
- public Timestamp fTimestamp;
- public UUID fUuid;
- public BigDecimal fDecimal;
-
- public String[] fStringArr;
- public Date[] fDateArr;
- public Timestamp[] fTimestampArr;
- public UUID[] fUuidArr;
- public BigDecimal[] fDecimalArr;
-
- /** Nested object. */
- public TestInnerObject fObj;
-
- public TestInnerObject[] fObjArr;
-
- /** Field which is always set to null. */
- public Object fNull;
-
- /**
- * Default constructor.
- */
- public TestObject() {
- // No-op.
- }
-
- /**
- * Non-default constructor.
- *
- * @param ignore Ignored.
- */
- public TestObject(int ignore) {
- fByte = 1;
- fBool = true;
- fShort = 2;
- fChar = 3;
- fInt = 4;
- fLong = 5;
- fFloat = 6.6f;
- fDouble = 7.7;
-
- fByteArr = new byte[] { 1, 2 };
- fBoolArr = new boolean[] { true, false };
- fShortArr = new short[] { 2, 3 };
- fCharArr = new char[] { 3, 4 };
- fIntArr = new int[] { 4, 5 };
- fLongArr = new long[] { 5, 6 };
- fFloatArr = new float[] { 6.6f, 7.7f };
- fDoubleArr = new double[] { 7.7, 8.8 };
-
- fString = "8";
- fDate = new Date();
- fTimestamp = new Timestamp(new Date().getTime() + 1);
- fUuid = UUID.randomUUID();
- fDecimal = new BigDecimal(9);
-
- fStringArr = new String[] { "8", "9" };
- fDateArr = new Date[] { new Date(), new Date(new Date().getTime() + 1) };
- fTimestampArr =
- new Timestamp[] { new Timestamp(new Date().getTime() + 1), new Timestamp(new Date().getTime() + 2) };
- fUuidArr = new UUID[] { UUID.randomUUID(), UUID.randomUUID() };
- fDecimalArr = new BigDecimal[] { new BigDecimal(9), new BigDecimal(10) };
-
- fObj = new TestInnerObject(10);
- fObjArr = new TestInnerObject[] { new TestInnerObject(10), new TestInnerObject(11) };
- }
- }
-
- /**
- * Inner test object.
- */
- @SuppressWarnings("UnusedDeclaration")
- public static class TestInnerObject {
- /** Value. */
- private int val;
-
- /**
- * Default constructor.
- */
- public TestInnerObject() {
- // No-op.
- }
-
- /**
- * Constructor.
- *
- * @param val Value.
- */
- public TestInnerObject(int val) {
- this.val = val;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return val;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object other) {
- return other != null && other instanceof TestInnerObject && val == ((TestInnerObject)(other)).val;
- }
- }
-
- /**
- * Test context.
- */
- public static class TestContext {
- /** Object. */
- public final TestObject obj;
-
- /** Portable object. */
- public final PortableObjectEx portObj;
-
- /** Field. */
- public final PortableField field;
-
- /**
- * Constructor.
- *
- * @param obj Object.
- * @param portObj Portable object.
- * @param field Field.
- */
- public TestContext(TestObject obj, PortableObjectEx portObj, PortableField field) {
- this.obj = obj;
- this.portObj = portObj;
- this.field = field;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsHeapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsHeapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsHeapSelfTest.java
deleted file mode 100644
index c7feeab..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsHeapSelfTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-
-/**
- * Field tests for heap-based portables.
- */
-public class PortableFieldsHeapSelfTest extends PortableFieldsAbstractSelfTest {
- /** {@inheritDoc} */
- @Override protected PortableObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception {
- byte[] bytes = marsh.marshal(obj);
-
- return new PortableObjectImpl(portableContext(marsh), bytes, 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsOffheapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsOffheapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsOffheapSelfTest.java
deleted file mode 100644
index 44bb8a1..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/PortableFieldsOffheapSelfTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.eclipse.jetty.util.ConcurrentHashSet;
-import sun.misc.Unsafe;
-
-/**
- * Field tests for heap-based portables.
- */
-public class PortableFieldsOffheapSelfTest extends PortableFieldsAbstractSelfTest {
- /** Unsafe instance. */
- private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
- /** Byte array offset for unsafe mechanics. */
- protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
- /** Allocated unsafe pointer. */
- private final ConcurrentHashSet<Long> ptrs = new ConcurrentHashSet<>();
-
- /** {@inheritDoc} */
- @Override protected void afterTest() throws Exception {
- super.afterTest();
-
- // Cleanup allocated objects.
- for (Long ptr : ptrs)
- UNSAFE.freeMemory(ptr);
-
- ptrs.clear();
- }
-
- /** {@inheritDoc} */
- @Override protected PortableObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception {
- byte[] arr = marsh.marshal(obj);
-
- long ptr = UNSAFE.allocateMemory(arr.length);
-
- ptrs.add(ptr);
-
- UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
-
- return new PortableObjectOffheapImpl(portableContext(marsh), ptr, 0, arr.length);
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridBinaryMarshalerAwareTestClass.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridBinaryMarshalerAwareTestClass.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridBinaryMarshalerAwareTestClass.java
new file mode 100644
index 0000000..aad0e87
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridBinaryMarshalerAwareTestClass.java
@@ -0,0 +1,67 @@
+/*
+ * 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.portable.mutabletest;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryRawReader;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.testframework.GridTestUtils;
+
+/**
+ *
+ */
+public class GridBinaryMarshalerAwareTestClass implements Binarylizable {
+ /** */
+ public String s;
+
+ /** */
+ public String sRaw;
+
+ /** {@inheritDoc} */
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+ writer.writeString("s", s);
+
+ BinaryRawWriter raw = writer.rawWriter();
+
+ raw.writeString(sRaw);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+ s = reader.readString("s");
+
+ BinaryRawReader raw = reader.rawReader();
+
+ sRaw = raw.readString();
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("FloatingPointEquality")
+ @Override public boolean equals(Object other) {
+ return this == other || GridTestUtils.deepEquals(this, other);
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(GridBinaryMarshalerAwareTestClass.class, this);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java
deleted file mode 100644
index 3244331..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.portable.mutabletest;
-
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableRawReader;
-import org.apache.ignite.portable.PortableRawWriter;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
-import org.apache.ignite.testframework.GridTestUtils;
-
-/**
- *
- */
-public class GridPortableMarshalerAwareTestClass implements PortableMarshalAware {
- /** */
- public String s;
-
- /** */
- public String sRaw;
-
- /** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
- writer.writeString("s", s);
-
- PortableRawWriter raw = writer.rawWriter();
-
- raw.writeString(sRaw);
- }
-
- /** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
- s = reader.readString("s");
-
- PortableRawReader raw = reader.rawReader();
-
- sRaw = raw.readString();
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("FloatingPointEquality")
- @Override public boolean equals(Object other) {
- return this == other || GridTestUtils.deepEquals(this, other);
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(GridPortableMarshalerAwareTestClass.class, this);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
index a2ae71f..69687ab 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
@@ -32,7 +32,7 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.binary.BinaryObject;
/**
*
@@ -106,7 +106,7 @@ public class GridPortableTestClasses {
*/
public static class TestObjectPlainPortable {
/** */
- public PortableObject plainPortable;
+ public BinaryObject plainPortable;
/**
*
@@ -118,7 +118,7 @@ public class GridPortableTestClasses {
/**
* @param plainPortable Object.
*/
- public TestObjectPlainPortable(PortableObject plainPortable) {
+ public TestObjectPlainPortable(BinaryObject plainPortable) {
this.plainPortable = plainPortable;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearReaderUpdateTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearReaderUpdateTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearReaderUpdateTest.java
index e267620..50a622f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearReaderUpdateTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheNearReaderUpdateTest.java
@@ -121,24 +121,46 @@ public class CacheNearReaderUpdateTest extends GridCommonAbstractTest {
/**
* @throws Exception If failed.
*/
- public void testGetUpdateMultithreaded() throws Exception {
- fail("https://issues.apache.org/jira/browse/IGNITE-627");
+ public void testNoBackups() throws Exception {
+ testGetUpdateMultithreaded(cacheConfiguration(PARTITIONED, FULL_SYNC, 0, false, false));
+ }
- List<CacheConfiguration<Integer, Integer>> cfgs = new ArrayList<>();
+ /**
+ * @throws Exception If failed.
+ */
+ public void testOneBackup() throws Exception {
+ testGetUpdateMultithreaded(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false));
+ }
- cfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 0, false, false));
- cfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false));
- cfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, true));
- cfgs.add(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, true, false));
+ /**
+ * @throws Exception If failed.
+ */
+ public void testOneBackupNearEnabled() throws Exception {
+ testGetUpdateMultithreaded(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, true));
+ }
- {
- CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false);
+ /**
+ * @throws Exception If failed.
+ */
+ public void testOneBackupStoreEnabled() throws Exception {
+ testGetUpdateMultithreaded(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, true, false));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testOneBackupOffheap() throws Exception {
+ CacheConfiguration<Integer, Integer> ccfg = cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false);
- GridTestUtils.setMemoryMode(null, ccfg, GridTestUtils.TestMemoryMode.OFFHEAP_TIERED, 0, 0);
+ GridTestUtils.setMemoryMode(null, ccfg, GridTestUtils.TestMemoryMode.OFFHEAP_TIERED, 0, 0);
- cfgs.add(ccfg);
- }
+ testGetUpdateMultithreaded(ccfg);
+ }
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetUpdateMultithreaded(CacheConfiguration<Integer, Integer> ccfg) throws Exception {
final List<Ignite> putNodes = new ArrayList<>();
for (int i = 0; i < SRVS + CLIENTS - 1; i++)
@@ -149,18 +171,16 @@ public class CacheNearReaderUpdateTest extends GridCommonAbstractTest {
getNodes.add(ignite(SRVS + CLIENTS - 1));
getNodes.add(ignite(0));
- for (CacheConfiguration<Integer, Integer> ccfg : cfgs) {
- logCacheInfo(ccfg);
+ logCacheInfo(ccfg);
- getUpdateMultithreaded(ccfg, putNodes, getNodes, null, null);
+ getUpdateMultithreaded(ccfg, putNodes, getNodes, null, null);
- if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
- getUpdateMultithreaded(ccfg, putNodes, getNodes, PESSIMISTIC, REPEATABLE_READ);
+ if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
+ getUpdateMultithreaded(ccfg, putNodes, getNodes, PESSIMISTIC, REPEATABLE_READ);
- getUpdateMultithreaded(ccfg, putNodes, getNodes, OPTIMISTIC, REPEATABLE_READ);
+ getUpdateMultithreaded(ccfg, putNodes, getNodes, OPTIMISTIC, REPEATABLE_READ);
- getUpdateMultithreaded(ccfg, putNodes, getNodes, OPTIMISTIC, SERIALIZABLE);
- }
+ getUpdateMultithreaded(ccfg, putNodes, getNodes, OPTIMISTIC, SERIALIZABLE);
}
}
@@ -177,6 +197,8 @@ public class CacheNearReaderUpdateTest extends GridCommonAbstractTest {
final List<Ignite> getNodes,
final TransactionConcurrency concurrency,
final TransactionIsolation isolation) throws Exception {
+ fail("https://issues.apache.org/jira/browse/IGNITE-627");
+
log.info("Execute updates [concurrency=" + concurrency + ", isolation=" + isolation + ']');
final Ignite ignite0 = ignite(0);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
index f8fc3ae..52fbf4c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractSelfTest.java
@@ -38,6 +38,7 @@ import org.apache.ignite.internal.IgniteKernal;
import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
import org.apache.ignite.internal.util.lang.GridAbsPredicateX;
import org.apache.ignite.internal.util.typedef.CI1;
+import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.P1;
import org.apache.ignite.internal.util.typedef.R1;
import org.apache.ignite.internal.util.typedef.X;
@@ -241,7 +242,11 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest {
cfg.setAtomicityMode(atomicityMode());
cfg.setWriteSynchronizationMode(writeSynchronization());
cfg.setNearConfiguration(nearConfiguration());
- cfg.setIndexedTypes(indexedTypes());
+
+ Class<?>[] idxTypes = indexedTypes();
+
+ if (!F.isEmpty(idxTypes))
+ cfg.setIndexedTypes(idxTypes);
if (cacheMode() == PARTITIONED)
cfg.setBackups(1);
@@ -560,4 +565,4 @@ public abstract class GridCacheAbstractSelfTest extends GridCommonAbstractTest {
return cacheStore();
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredEvictionAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredEvictionAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredEvictionAbstractSelfTest.java
index 33c2b53..cd82739 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredEvictionAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheOffHeapTieredEvictionAbstractSelfTest.java
@@ -169,7 +169,7 @@ public abstract class GridCacheOffHeapTieredEvictionAbstractSelfTest extends Gri
* @throws Exception If failed.
*/
public void testTransform() throws Exception {
- final IgniteCache<Integer, Object> cache = grid(0).cache(null);
+ final IgniteCache<Integer, Object> cache = grid(0).cache(null).withKeepBinary();
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override public Void call() throws Exception {
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
index abb2767..4820f54 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheTestEntryEx.java
@@ -437,7 +437,8 @@ public class GridCacheTestEntryEx extends GridMetadataAwareAdapter implements Gr
UUID subjId,
Object transformClo,
String taskName,
- @Nullable IgniteCacheExpiryPolicy expiryPlc) {
+ @Nullable IgniteCacheExpiryPolicy expiryPlc,
+ boolean keepBinary) {
return val;
}
@@ -451,7 +452,8 @@ public class GridCacheTestEntryEx extends GridMetadataAwareAdapter implements Gr
UUID subjId,
Object transformClo,
String taskName,
- @Nullable IgniteCacheExpiryPolicy expiryPlc) {
+ @Nullable IgniteCacheExpiryPolicy expiryPlc,
+ boolean keepBinary) {
assert false;
return null;
@@ -472,6 +474,7 @@ public class GridCacheTestEntryEx extends GridMetadataAwareAdapter implements Gr
long ttl,
boolean evt,
boolean metrics,
+ boolean keepPortable,
AffinityTopologyVersion topVer,
CacheEntryPredicate[] filter,
GridDrType drType,
@@ -493,6 +496,7 @@ public class GridCacheTestEntryEx extends GridMetadataAwareAdapter implements Gr
boolean writeThrough,
boolean readThrough,
boolean retval,
+ boolean keepPortable,
@Nullable ExpiryPolicy expiryPlc,
boolean evt,
boolean metrics,
@@ -515,6 +519,7 @@ public class GridCacheTestEntryEx extends GridMetadataAwareAdapter implements Gr
boolean writeThrough,
boolean readThrough,
boolean retval,
+ boolean keepPortable,
@Nullable IgniteCacheExpiryPolicy expiryPlc,
boolean evt,
boolean metrics,
@@ -545,6 +550,7 @@ public class GridCacheTestEntryEx extends GridMetadataAwareAdapter implements Gr
boolean retval,
boolean evt,
boolean metrics,
+ boolean keepPortable,
AffinityTopologyVersion topVer,
CacheEntryPredicate[] filter,
GridDrType drType,
@@ -578,7 +584,8 @@ public class GridCacheTestEntryEx extends GridMetadataAwareAdapter implements Gr
@Override public boolean tmLock(IgniteInternalTx tx,
long timeout,
@Nullable GridCacheVersion serOrder,
- GridCacheVersion serReadVer) {
+ GridCacheVersion serReadVer,
+ boolean keepBinary) {
assert false; return false;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
index 89610e7..056affc 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCachePeekModesAbstractTest.java
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.cache.Cache;
+import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CacheMemoryMode;
import org.apache.ignite.cache.CachePeekMode;
@@ -35,6 +36,7 @@ import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteKernal;
import org.apache.ignite.internal.util.typedef.T2;
import org.apache.ignite.spi.IgniteSpiCloseableIterator;
@@ -260,16 +262,26 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
for (Integer key : keys)
cache0.put(key, val);
- SwapSpaceSpi swap = ignite(nodeIdx).configuration().getSwapSpaceSpi();
+ Ignite ignite = ignite(nodeIdx);
+
+ SwapSpaceSpi swap = ignite.configuration().getSwapSpaceSpi();
+
+ GridCacheAdapter<Integer, String> internalCache =
+ ((IgniteKernal)ignite).context().cache().internalCache();
+
+ CacheObjectContext coctx = internalCache.context().cacheObjectContext();
Set<Integer> swapKeys = new HashSet<>();
- IgniteSpiCloseableIterator<Integer> it = swap.keyIterator(SPACE_NAME, null);
+ IgniteSpiCloseableIterator<KeyCacheObject> it = swap.keyIterator(SPACE_NAME, null);
assertNotNull(it);
- while (it.hasNext())
- assertTrue(swapKeys.add(it.next()));
+ while (it.hasNext()) {
+ KeyCacheObject next = it.next();
+
+ assertTrue(swapKeys.add((Integer)next.value(coctx, false)));
+ }
assertFalse(swapKeys.isEmpty());
@@ -277,9 +289,6 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
Set<Integer> offheapKeys = new HashSet<>();
- GridCacheAdapter<Integer, String> internalCache =
- ((IgniteKernal)ignite(nodeIdx)).context().cache().internalCache();
-
Iterator<Map.Entry<Integer, String>> offheapIt;
if (internalCache.context().isNear())
@@ -645,7 +654,7 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
private T2<List<Integer>, List<Integer>> swapKeys(int nodeIdx) {
SwapSpaceSpi swap = ignite(nodeIdx).configuration().getSwapSpaceSpi();
- IgniteSpiCloseableIterator<Integer> it = swap.keyIterator(SPACE_NAME, null);
+ IgniteSpiCloseableIterator<KeyCacheObject> it = swap.keyIterator(SPACE_NAME, null);
assertNotNull(it);
@@ -656,8 +665,11 @@ public abstract class IgniteCachePeekModesAbstractTest extends IgniteCacheAbstra
List<Integer> primary = new ArrayList<>();
List<Integer> backups = new ArrayList<>();
+ CacheObjectContext coctx = ((IgniteEx)ignite(nodeIdx)).context().cache().internalCache()
+ .context().cacheObjectContext();
+
while (it.hasNext()) {
- Integer key = it.next();
+ Integer key = it.next().value(coctx, false);
if (aff.isPrimary(node, key))
primary.add(key);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheAbstractExecutionContextTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheAbstractExecutionContextTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheAbstractExecutionContextTest.java
index c04c934..80c339c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheAbstractExecutionContextTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheAbstractExecutionContextTest.java
@@ -23,6 +23,8 @@ import org.apache.ignite.IgniteCache;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.processors.cache.IgniteCacheAbstractTest;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
import org.apache.ignite.testframework.GridTestExternalClassLoader;
import org.apache.ignite.testframework.config.GridTestProperties;
@@ -63,6 +65,9 @@ public abstract class IgniteCacheAbstractExecutionContextTest extends IgniteCach
* @throws Exception If failed.
*/
public void testUsersClassLoader() throws Exception {
+ if (F.eq(GridTestProperties.getProperty(GridTestProperties.MARSH_CLASS_NAME), PortableMarshaller.class.getName()))
+ fail("https://issues.apache.org/jira/browse/IGNITE-1272");
+
UsersClassLoader testClassLdr = (UsersClassLoader)grid(0).configuration().getClassLoader();
Object val = testClassLdr.loadClass(TEST_VALUE).newInstance();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheTxExecutionContextTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheTxExecutionContextTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheTxExecutionContextTest.java
index 1cde3f8..aaefc90 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheTxExecutionContextTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheTxExecutionContextTest.java
@@ -21,6 +21,8 @@ import org.apache.ignite.cache.CacheAtomicWriteOrderMode;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.testframework.config.GridTestProperties;
import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.CLOCK;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractDistributedByteArrayValuesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractDistributedByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractDistributedByteArrayValuesSelfTest.java
index 29d9387..fde16ec 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractDistributedByteArrayValuesSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheAbstractDistributedByteArrayValuesSelfTest.java
@@ -336,6 +336,8 @@ public abstract class GridCacheAbstractDistributedByteArrayValuesSelfTest extend
private void testTransactionMixed0(IgniteCache<Integer, Object>[] caches, TransactionConcurrency concurrency,
Integer key1, byte[] val1, @Nullable Integer key2, @Nullable Object val2) throws Exception {
for (IgniteCache<Integer, Object> cache : caches) {
+ info("Checking cache: " + cache.getName());
+
Transaction tx = cache.unwrap(Ignite.class).transactions().txStart(concurrency, REPEATABLE_READ);
try {
@@ -351,6 +353,8 @@ public abstract class GridCacheAbstractDistributedByteArrayValuesSelfTest extend
}
for (IgniteCache<Integer, Object> cacheInner : caches) {
+ info("Getting value from cache: " + cacheInner.getName());
+
tx = cacheInner.unwrap(Ignite.class).transactions().txStart(concurrency, REPEATABLE_READ);
try {
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java
new file mode 100644
index 0000000..c1144b6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java
@@ -0,0 +1,190 @@
+/*
+ * 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.cache.portable;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jsr166.LongAdder8;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public abstract class GridCacheBinaryObjectsAbstractDataStreamerSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final int THREAD_CNT = 64;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ CacheConfiguration cacheCfg = new CacheConfiguration();
+
+ cacheCfg.setCacheMode(cacheMode());
+ cacheCfg.setAtomicityMode(atomicityMode());
+ cacheCfg.setNearConfiguration(nearConfiguration());
+ cacheCfg.setWriteSynchronizationMode(writeSynchronizationMode());
+
+ cfg.setCacheConfiguration(cacheCfg);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new BinaryTypeConfiguration(TestObject.class.getName())));
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /**
+ * @return Sync mode.
+ */
+ protected CacheWriteSynchronizationMode writeSynchronizationMode() {
+ return PRIMARY_SYNC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGridsMultiThreaded(gridCount());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @return Cache mode.
+ */
+ protected abstract CacheMode cacheMode();
+
+ /**
+ * @return Atomicity mode.
+ */
+ protected abstract CacheAtomicityMode atomicityMode();
+
+ /**
+ * @return Near configuration.
+ */
+ protected abstract NearCacheConfiguration nearConfiguration();
+
+ /**
+ * @return Grid count.
+ */
+ protected int gridCount() {
+ return 1;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("BusyWait")
+ public void testGetPut() throws Exception {
+ final AtomicBoolean flag = new AtomicBoolean();
+
+ final LongAdder8 cnt = new LongAdder8();
+
+ try (IgniteDataStreamer<Object, Object> ldr = grid(0).dataStreamer(null)) {
+ IgniteInternalFuture<?> f = multithreadedAsync(
+ new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ while (!flag.get()) {
+ ldr.addData(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
+
+ cnt.add(1);
+ }
+
+ return null;
+ }
+ },
+ THREAD_CNT
+ );
+
+ for (int i = 0; i < 30 && !f.isDone(); i++)
+ Thread.sleep(1000);
+
+ flag.set(true);
+
+ f.get();
+ }
+
+ info("Operations in 30 sec: " + cnt.sum());
+ }
+
+ /**
+ */
+ private static class TestObject implements Binarylizable, Serializable {
+ /** */
+ private int val;
+
+ /**
+ */
+ private TestObject() {
+ // No-op.
+ }
+
+ /**
+ * @param val Value.
+ */
+ private TestObject(int val) {
+ this.val = val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return obj instanceof TestObject && ((TestObject)obj).val == val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+ writer.writeInt("val", val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+ val = reader.readInt("val");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java
new file mode 100644
index 0000000..b626093
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java
@@ -0,0 +1,231 @@
+/*
+ * 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.cache.portable;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jsr166.LongAdder8;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public abstract class GridCacheBinaryObjectsAbstractMultiThreadedSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final int THREAD_CNT = 64;
+
+ /** */
+ private static final AtomicInteger idxGen = new AtomicInteger();
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ CacheConfiguration cacheCfg = new CacheConfiguration();
+
+ cacheCfg.setCacheMode(cacheMode());
+ cacheCfg.setAtomicityMode(atomicityMode());
+ cacheCfg.setNearConfiguration(nearConfiguration());
+ cacheCfg.setWriteSynchronizationMode(writeSynchronizationMode());
+
+ cfg.setCacheConfiguration(cacheCfg);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new BinaryTypeConfiguration(TestObject.class.getName())));
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /**
+ * @return Sync mode.
+ */
+ protected CacheWriteSynchronizationMode writeSynchronizationMode() {
+ return PRIMARY_SYNC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGridsMultiThreaded(gridCount());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @return Cache mode.
+ */
+ protected abstract CacheMode cacheMode();
+
+ /**
+ * @return Atomicity mode.
+ */
+ protected abstract CacheAtomicityMode atomicityMode();
+
+ /**
+ * @return Distribution mode.
+ */
+ protected abstract NearCacheConfiguration nearConfiguration();
+
+ /**
+ * @return Grid count.
+ */
+ protected int gridCount() {
+ return 1;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("BusyWait") public void testGetPut() throws Exception {
+ final AtomicBoolean flag = new AtomicBoolean();
+
+ final LongAdder8 cnt = new LongAdder8();
+
+ IgniteInternalFuture<?> f = multithreadedAsync(
+ new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ int threadId = idxGen.getAndIncrement() % 2;
+
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ while (!flag.get()) {
+ IgniteCache<Object, Object> c = jcache(rnd.nextInt(gridCount()));
+
+ switch (threadId) {
+ case 0:
+ // Put/get/remove portable -> portable.
+
+ c.put(new TestObject(rnd.nextInt(10000)), new TestObject(rnd.nextInt(10000)));
+
+ IgniteCache<Object, Object> p2 = ((IgniteCacheProxy<Object, Object>)c).keepPortable();
+
+ BinaryObject v = (BinaryObject)p2.get(new TestObject(rnd.nextInt(10000)));
+
+ if (v != null)
+ v.deserialize();
+
+ c.remove(new TestObject(rnd.nextInt(10000)));
+
+ break;
+
+ case 1:
+ // Put/get int -> portable.
+ c.put(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
+
+ IgniteCache<Integer, BinaryObject> p4 = ((IgniteCacheProxy<Object, Object>)c).keepPortable();
+
+ BinaryObject v1 = p4.get(rnd.nextInt(10000));
+
+ if (v1 != null)
+ v1.deserialize();
+
+ p4.remove(rnd.nextInt(10000));
+
+ break;
+
+ default:
+ assert false;
+ }
+
+ cnt.add(3);
+ }
+
+ return null;
+ }
+ },
+ THREAD_CNT
+ );
+
+ for (int i = 0; i < 30 && !f.isDone(); i++)
+ Thread.sleep(1000);
+
+ flag.set(true);
+
+ f.get();
+
+ info("Operations in 30 sec: " + cnt.sum());
+ }
+
+ /**
+ */
+ private static class TestObject implements Binarylizable, Serializable {
+ /** */
+ private int val;
+
+ /**
+ */
+ private TestObject() {
+ // No-op.
+ }
+
+ /**
+ * @param val Value.
+ */
+ private TestObject(int val) {
+ this.val = val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return obj instanceof TestObject && ((TestObject)obj).val == val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+ writer.writeInt("val", val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+ val = reader.readInt("val");
+ }
+ }
+}
\ No newline at end of file
[21/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
new file mode 100644
index 0000000..5ec981b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
@@ -0,0 +1,2774 @@
+/*
+ * 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.portable;
+
+import java.io.ByteArrayInputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentSkipListSet;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryTypeIdMapper;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+import org.apache.ignite.binary.BinaryRawReader;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.internal.portable.streams.PortableHeapInputStream;
+import org.apache.ignite.internal.portable.streams.PortableInputStream;
+import org.apache.ignite.internal.util.GridEnumCache;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.internal.util.typedef.internal.SB;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.ARR_LIST;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CLASS;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.COL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CONC_HASH_MAP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CONC_SKIP_LIST_SET;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DFLT_HDR_LEN;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.HANDLE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.HASH_MAP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.HASH_SET;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LINKED_HASH_MAP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LINKED_HASH_SET;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LINKED_LIST;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP_ENTRY;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJECT_TYPE_ID;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.OPTM_MARSH;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.PORTABLE_OBJ;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.PROPERTIES_MAP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TREE_MAP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TREE_SET;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.USER_COL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.USER_SET;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID_ARR;
+
+/**
+ * Portable reader implementation.
+ */
+@SuppressWarnings("unchecked")
+public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, ObjectInput {
+ /** Length of a single field descriptor. */
+ private static final int FIELD_DESC_LEN = 16;
+
+ /** */
+ private final PortableContext ctx;
+
+ /** */
+ private final PortableInputStream in;
+
+ /** */
+ private final int start;
+
+ /** */
+ private final PortableReaderContext rCtx;
+
+ /** */
+ private final ClassLoader ldr;
+
+ /** */
+ private PortableClassDescriptor desc;
+
+ /** Flag indicating that object header was parsed. */
+ private boolean hdrParsed;
+
+ /** Type ID. */
+ private int typeId;
+
+ /** Raw offset. */
+ private int rawOff;
+
+ /** */
+ private int hdrLen;
+
+ /** Footer start. */
+ private int footerStart;
+
+ /** Footer end. */
+ private int footerLen;
+
+ /** ID mapper. */
+ private BinaryTypeIdMapper idMapper;
+
+ /** Schema Id. */
+ private int schemaId;
+
+ /** Offset size in bytes. */
+ private int offsetSize;
+
+ /** Object schema. */
+ private PortableSchema schema;
+
+ /**
+ * @param ctx Context.
+ * @param arr Array.
+ * @param start Start.
+ * @param ldr Class loader.
+ */
+ public BinaryReaderExImpl(PortableContext ctx, byte[] arr, int start, ClassLoader ldr) {
+ this(ctx, new PortableHeapInputStream(arr), start, ldr, new PortableReaderContext());
+ }
+
+ /**
+ * @param ctx Context.
+ * @param in Input stream.
+ * @param start Start.
+ */
+ BinaryReaderExImpl(PortableContext ctx, PortableInputStream in, int start, ClassLoader ldr) {
+ this(ctx, in, start, ldr, new PortableReaderContext());
+ }
+
+ /**
+ * @param ctx Context.
+ * @param in Input stream.
+ * @param start Start.
+ * @param rCtx Context.
+ */
+ BinaryReaderExImpl(PortableContext ctx, PortableInputStream in, int start, ClassLoader ldr,
+ PortableReaderContext rCtx) {
+ this.ctx = ctx;
+ this.in = in;
+ this.start = start;
+ this.ldr = ldr;
+ this.rCtx = rCtx;
+
+ in.position(start);
+ }
+
+ /**
+ * Preloads typeId from the input array.
+ */
+ private void parseHeaderIfNeeded() {
+ if (hdrParsed)
+ return;
+
+ int retPos = in.position();
+
+ in.position(start);
+
+ byte hdr = in.readByte();
+
+ if (hdr != GridPortableMarshaller.OBJ)
+ throw new BinaryObjectException("Invalid header [pos=" + retPos + "expected=" + GridPortableMarshaller.OBJ +
+ ", actual=" + hdr + ']');
+
+ PortableUtils.checkProtocolVersion(in.readByte());
+
+ short flags = in.readShort();
+
+ offsetSize = PortableUtils.fieldOffsetSize(flags);
+
+ typeId = in.readIntPositioned(start + GridPortableMarshaller.TYPE_ID_POS);
+
+ IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(in, start, offsetSize);
+
+ footerStart = footer.get1();
+ footerLen = footer.get2() - footerStart;
+
+ schemaId = in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_ID_POS);
+
+ rawOff = PortableUtils.rawOffsetAbsolute(in, start, offsetSize);
+
+ if (typeId == UNREGISTERED_TYPE_ID) {
+ // Skip to the class name position.
+ in.position(start + GridPortableMarshaller.DFLT_HDR_LEN);
+
+ int off = in.position();
+
+ Class cls = doReadClass(typeId);
+
+ // registers class by typeId, at least locally if the cache is not ready yet.
+ PortableClassDescriptor desc = ctx.descriptorForClass(cls);
+
+ typeId = desc.typeId();
+
+ int clsNameLen = in.position() - off;
+
+ hdrLen = DFLT_HDR_LEN + clsNameLen;
+ }
+ else
+ hdrLen = DFLT_HDR_LEN;
+
+ // Restore state.
+ in.position(retPos);
+
+ hdrParsed = true;
+ }
+
+ /**
+ * @return Descriptor.
+ */
+ PortableClassDescriptor descriptor() {
+ return desc;
+ }
+
+ /**
+ * @return Unmarshalled value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Object unmarshal() throws BinaryObjectException {
+ return unmarshal(false);
+ }
+
+ /**
+ * @param offset Offset in the array.
+ * @return Unmarshalled value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ public Object unmarshal(int offset) throws BinaryObjectException {
+ in.position(offset);
+
+ return in.position() >= 0 ? unmarshal() : null;
+ }
+
+ /**
+ * @param fieldName Field name.
+ * @return Unmarshalled value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Object unmarshalField(String fieldName) throws BinaryObjectException {
+ return hasField(fieldName) ? unmarshal() : null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Unmarshalled value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Object unmarshalField(int fieldId) throws BinaryObjectException {
+ parseHeaderIfNeeded();
+
+ return hasField(fieldId) ? unmarshal() : null;
+ }
+
+ /**
+ * Unmarshal field by absolute position.
+ *
+ * @param pos Absolute position.
+ * @return Field value.
+ * @throws BinaryObjectException In case of error.
+ */
+ @Nullable Object unmarshalFieldByAbsolutePosition(int pos) throws BinaryObjectException {
+ parseHeaderIfNeeded();
+
+ in.position(pos);
+
+ return unmarshal();
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Byte readByte(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(BYTE) == Flag.NULL)
+ return null;
+
+ return in.readByte();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Short readShort(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(SHORT) == Flag.NULL)
+ return null;
+
+ return in.readShort();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Integer readInt(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(INT) == Flag.NULL)
+ return null;
+
+ return in.readInt();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Long readLong(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(LONG) == Flag.NULL)
+ return null;
+
+ return in.readLong();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Float readFloat(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(FLOAT) == Flag.NULL)
+ return null;
+
+ return in.readFloat();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Double readDouble(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(DOUBLE) == Flag.NULL)
+ return null;
+
+ return in.readDouble();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Character readChar(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(CHAR) == Flag.NULL)
+ return null;
+
+ return in.readChar();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Boolean readBoolean(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(BOOLEAN) == Flag.NULL)
+ return null;
+
+ return in.readBoolean();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable BigDecimal readDecimal(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(DECIMAL) == Flag.NULL)
+ return null;
+
+ return doReadDecimal();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable String readString(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(STRING) == Flag.NULL)
+ return null;
+
+ return doReadString();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable UUID readUuid(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(UUID) == Flag.NULL)
+ return null;
+
+ return doReadUuid();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Date readDate(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(DATE) == Flag.NULL)
+ return null;
+
+ return doReadDate();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Timestamp readTimestamp(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(TIMESTAMP) == Flag.NULL)
+ return null;
+
+ return doReadTimestamp();
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Object readObject(int fieldId) throws BinaryObjectException {
+ return hasField(fieldId) ? doReadObject() : null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable byte[] readByteArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(BYTE_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadByteArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable short[] readShortArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(SHORT_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadShortArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable int[] readIntArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(INT_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadIntArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable long[] readLongArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(LONG_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadLongArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable float[] readFloatArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(FLOAT_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadFloatArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable double[] readDoubleArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(DOUBLE_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadDoubleArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable char[] readCharArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(CHAR_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadCharArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable boolean[] readBooleanArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(BOOLEAN_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadBooleanArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable BigDecimal[] readDecimalArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(DECIMAL_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadDecimalArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable String[] readStringArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(STRING_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadStringArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable UUID[] readUuidArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(UUID_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadUuidArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Date[] readDateArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(DATE_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadDateArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Timestamp[] readTimestampArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(TIMESTAMP_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadTimestampArray();
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Object[] readObjectArray(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(OBJ_ARR);
+
+ if (flag == Flag.NORMAL)
+ return doReadObjectArray(true);
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @param cls Collection class.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable <T> Collection<T> readCollection(int fieldId, @Nullable Class<? extends Collection> cls)
+ throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(COL);
+
+ if (flag == Flag.NORMAL)
+ return (Collection<T>)doReadCollection(true, cls);
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @param cls Map class.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Map<?, ?> readMap(int fieldId, @Nullable Class<? extends Map> cls)
+ throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(MAP);
+
+ if (flag == Flag.NORMAL)
+ return doReadMap(true, cls);
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException On case of error.
+ */
+ @Nullable Map.Entry<?, ?> readMapEntry(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(MAP_ENTRY);
+
+ if (flag == Flag.NORMAL)
+ return doReadMapEntry(true);
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Portable object.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable BinaryObject readPortableObject(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(PORTABLE_OBJ) == Flag.NULL)
+ return null;
+
+ return new BinaryObjectImpl(ctx, doReadByteArray(), in.readInt());
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @param cls Class.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Enum<?> readEnum(int fieldId, @Nullable Class<?> cls) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(ENUM) == Flag.NULL)
+ return null;
+
+ // Revisit: why have we started writing Class for enums in their serialized form?
+ if (cls == null)
+ cls = doReadClass();
+ else
+ doReadClass();
+
+ Object[] vals = GridEnumCache.get(cls);
+
+ return (Enum<?>)vals[in.readInt()];
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @param cls Class.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Object[] readEnumArray(int fieldId, @Nullable Class<?> cls) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ Flag flag = checkFlag(ENUM_ARR);
+
+ if (flag == Flag.NORMAL) {
+ if (cls == null)
+ cls = doReadClass();
+ else
+ doReadClass();
+
+ return doReadEnumArray(cls);
+ }
+ else if (flag == Flag.HANDLE)
+ return readHandleField();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return Field class.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable Class<?> readClass(int fieldId) throws BinaryObjectException {
+ if (hasField(fieldId)) {
+ if (checkFlag(CLASS) == Flag.NULL)
+ return null;
+
+ return doReadClass();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param obj Object.
+ */
+ void setHandler(Object obj) {
+ rCtx.setObjectHandler(start, obj);
+ }
+
+ /**
+ * @param obj Object.
+ * @param pos Position.
+ */
+ void setHandler(Object obj, int pos) {
+ rCtx.setObjectHandler(pos, obj);
+ }
+
+ /**
+ * Recreating field value from a handle.
+ *
+ * @param <T> Field type.
+ * @return Field.
+ */
+ private <T> T readHandleField() {
+ int handle = (in.position() - 1) - in.readInt();
+
+ Object obj = rCtx.getObjectByHandle(handle);
+
+ if (obj == null) {
+ in.position(handle);
+
+ obj = doReadObject();
+ }
+
+ return (T)obj;
+ }
+ /** {@inheritDoc} */
+ @Override public byte readByte(String fieldName) throws BinaryObjectException {
+ Byte val = readByte(fieldId(fieldName));
+
+ return val != null ? val : 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte readByte() throws BinaryObjectException {
+ return in.readByte();
+ }
+
+ /** {@inheritDoc} */
+ @Override public short readShort(String fieldName) throws BinaryObjectException {
+ Short val = readShort(fieldId(fieldName));
+
+ return val != null ? val : 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public short readShort() throws BinaryObjectException {
+ return in.readShort();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int readInt(String fieldName) throws BinaryObjectException {
+ Integer val = readInt(fieldId(fieldName));
+
+ return val != null ? val : 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int readInt() throws BinaryObjectException {
+ return in.readInt();
+ }
+
+ /** {@inheritDoc} */
+ @Override public long readLong(String fieldName) throws BinaryObjectException {
+ Long val = readLong(fieldId(fieldName));
+
+ return val != null ? val : 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long readLong() throws BinaryObjectException {
+ return in.readLong();
+ }
+
+ /** {@inheritDoc} */
+ @Override public float readFloat(String fieldName) throws BinaryObjectException {
+ Float val = readFloat(fieldId(fieldName));
+
+ return val != null ? val : 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public float readFloat() throws BinaryObjectException {
+ return in.readFloat();
+ }
+
+ /** {@inheritDoc} */
+ @Override public double readDouble(String fieldName) throws BinaryObjectException {
+ Double val = readDouble(fieldId(fieldName));
+
+ return val != null ? val : 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public double readDouble() throws BinaryObjectException {
+ return in.readDouble();
+ }
+
+ /** {@inheritDoc} */
+ @Override public char readChar(String fieldName) throws BinaryObjectException {
+ Character val = readChar(fieldId(fieldName));
+
+ return val != null ? val : 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public char readChar() throws BinaryObjectException {
+ return in.readChar();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean readBoolean(String fieldName) throws BinaryObjectException {
+ Boolean val = readBoolean(fieldId(fieldName));
+
+ return val != null ? val : false;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean readBoolean() throws BinaryObjectException {
+ return in.readBoolean();
+ }
+
+ /** {@inheritDoc} */
+ @Override @Nullable public BigDecimal readDecimal(String fieldName) throws BinaryObjectException {
+ return readDecimal(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Override @Nullable public BigDecimal readDecimal() throws BinaryObjectException {
+ if (checkFlag(DECIMAL) == Flag.NULL)
+ return null;
+
+ return doReadDecimal();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public String readString(String fieldName) throws BinaryObjectException {
+ return readString(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public String readString() throws BinaryObjectException {
+ if (checkFlag(STRING) == Flag.NULL)
+ return null;
+
+ return doReadString();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public UUID readUuid(String fieldName) throws BinaryObjectException {
+ return readUuid(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public UUID readUuid() throws BinaryObjectException {
+ if (checkFlag(UUID) == Flag.NULL)
+ return null;
+
+ return doReadUuid();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Date readDate(String fieldName) throws BinaryObjectException {
+ return readDate(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Date readDate() throws BinaryObjectException {
+ if (checkFlag(DATE) == Flag.NULL)
+ return null;
+
+ return doReadDate();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Timestamp readTimestamp(String fieldName) throws BinaryObjectException {
+ return readTimestamp(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Timestamp readTimestamp() throws BinaryObjectException {
+ if (checkFlag(TIMESTAMP) == Flag.NULL)
+ return null;
+
+ return doReadTimestamp();
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Nullable @Override public <T> T readObject(String fieldName) throws BinaryObjectException {
+ return (T)readObject(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object readObject() throws BinaryObjectException {
+ return doReadObject();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Object readObjectDetached() throws BinaryObjectException {
+ return unmarshal(true);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public byte[] readByteArray(String fieldName) throws BinaryObjectException {
+ return readByteArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public byte[] readByteArray() throws BinaryObjectException {
+ if (checkFlag(BYTE_ARR) == Flag.NULL)
+ return null;
+
+ return doReadByteArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public short[] readShortArray(String fieldName) throws BinaryObjectException {
+ return readShortArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public short[] readShortArray() throws BinaryObjectException {
+ if (checkFlag(SHORT_ARR) == Flag.NULL)
+ return null;
+
+ return doReadShortArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public int[] readIntArray(String fieldName) throws BinaryObjectException {
+ return readIntArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public int[] readIntArray() throws BinaryObjectException {
+ if (checkFlag(INT_ARR) == Flag.NULL)
+ return null;
+
+ return doReadIntArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public long[] readLongArray(String fieldName) throws BinaryObjectException {
+ return readLongArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public long[] readLongArray() throws BinaryObjectException {
+ if (checkFlag(LONG_ARR) == Flag.NULL)
+ return null;
+
+ return doReadLongArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public float[] readFloatArray(String fieldName) throws BinaryObjectException {
+ return readFloatArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public float[] readFloatArray() throws BinaryObjectException {
+ if (checkFlag(FLOAT_ARR) == Flag.NULL)
+ return null;
+
+ return doReadFloatArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public double[] readDoubleArray(String fieldName) throws BinaryObjectException {
+ return readDoubleArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public double[] readDoubleArray() throws BinaryObjectException {
+ if (checkFlag(DOUBLE_ARR) == Flag.NULL)
+ return null;
+
+ return doReadDoubleArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public char[] readCharArray(String fieldName) throws BinaryObjectException {
+ return readCharArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public char[] readCharArray() throws BinaryObjectException {
+ if (checkFlag(CHAR_ARR) == Flag.NULL)
+ return null;
+
+ return doReadCharArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public boolean[] readBooleanArray(String fieldName) throws BinaryObjectException {
+ return readBooleanArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public boolean[] readBooleanArray() throws BinaryObjectException {
+ if (checkFlag(BOOLEAN_ARR) == Flag.NULL)
+ return null;
+
+ return doReadBooleanArray();
+ }
+
+ /** {@inheritDoc} */
+ @Override @Nullable public BigDecimal[] readDecimalArray(String fieldName) throws BinaryObjectException {
+ return readDecimalArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Override @Nullable public BigDecimal[] readDecimalArray() throws BinaryObjectException {
+ if (checkFlag(DECIMAL_ARR) == Flag.NULL)
+ return null;
+
+ return doReadDecimalArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public String[] readStringArray(String fieldName) throws BinaryObjectException {
+ return readStringArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public String[] readStringArray() throws BinaryObjectException {
+ if (checkFlag(STRING_ARR) == Flag.NULL)
+ return null;
+
+ return doReadStringArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public UUID[] readUuidArray(String fieldName) throws BinaryObjectException {
+ return readUuidArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public UUID[] readUuidArray() throws BinaryObjectException {
+ if (checkFlag(UUID_ARR) == Flag.NULL)
+ return null;
+
+ return doReadUuidArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Date[] readDateArray(String fieldName) throws BinaryObjectException {
+ return readDateArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Timestamp[] readTimestampArray(String fieldName) throws BinaryObjectException {
+ return readTimestampArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Date[] readDateArray() throws BinaryObjectException {
+ if (checkFlag(DATE_ARR) == Flag.NULL)
+ return null;
+
+ return doReadDateArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Timestamp[] readTimestampArray() throws BinaryObjectException {
+ if (checkFlag(TIMESTAMP_ARR) == Flag.NULL)
+ return null;
+
+ return doReadTimestampArray();
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Object[] readObjectArray(String fieldName) throws BinaryObjectException {
+ return readObjectArray(fieldId(fieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Object[] readObjectArray() throws BinaryObjectException {
+ if (checkFlag(OBJ_ARR) == Flag.NULL)
+ return null;
+
+ return doReadObjectArray(true);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <T> Collection<T> readCollection(String fieldName) throws BinaryObjectException {
+ return readCollection(fieldId(fieldName), null);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <T> Collection<T> readCollection() throws BinaryObjectException {
+ if (checkFlag(COL) == Flag.NULL)
+ return null;
+
+ return (Collection<T>)doReadCollection(true, null);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <T> Collection<T> readCollection(String fieldName,
+ Class<? extends Collection<T>> colCls) throws BinaryObjectException {
+ return readCollection(fieldId(fieldName), colCls);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <T> Collection<T> readCollection(Class<? extends Collection<T>> colCls)
+ throws BinaryObjectException {
+ if (checkFlag(COL) == Flag.NULL)
+ return null;
+
+ return (Collection<T>)doReadCollection(true, colCls);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <K, V> Map<K, V> readMap(String fieldName) throws BinaryObjectException {
+ return (Map<K, V>)readMap(fieldId(fieldName), null);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <K, V> Map<K, V> readMap() throws BinaryObjectException {
+ if (checkFlag(MAP) == Flag.NULL)
+ return null;
+
+ return (Map<K, V>)doReadMap(true, null);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <K, V> Map<K, V> readMap(String fieldName, Class<? extends Map<K, V>> mapCls)
+ throws BinaryObjectException {
+ return (Map<K, V>)readMap(fieldId(fieldName), mapCls);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <K, V> Map<K, V> readMap(Class<? extends Map<K, V>> mapCls)
+ throws BinaryObjectException {
+ if (checkFlag(MAP) == Flag.NULL)
+ return null;
+
+ return (Map<K, V>)doReadMap(true, mapCls);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <T extends Enum<?>> T readEnum(String fieldName)
+ throws BinaryObjectException {
+ return (T)readEnum(fieldId(fieldName), null);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <T extends Enum<?>> T readEnum() throws BinaryObjectException {
+ if (checkFlag(ENUM) == Flag.NULL)
+ return null;
+
+ Class cls = doReadClass();
+
+ return (T)doReadEnum(cls);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <T extends Enum<?>> T[] readEnumArray(String fieldName)
+ throws BinaryObjectException {
+ return (T[])readEnumArray(fieldId(fieldName), null);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public <T extends Enum<?>> T[] readEnumArray() throws BinaryObjectException {
+ if (checkFlag(ENUM_ARR) == Flag.NULL)
+ return null;
+
+ Class cls = doReadClass();
+
+ return (T[])doReadEnumArray(cls);
+ }
+
+ /**
+ * Ensure that type flag is either null or contains expected value.
+ *
+ * @param expFlag Expected value.
+ * @return Flag.
+ * @throws org.apache.ignite.binary.BinaryObjectException If flag is neither null, nor expected.
+ */
+ private Flag checkFlag(byte expFlag) {
+ byte flag = in.readByte();
+
+ if (flag == NULL)
+ return Flag.NULL;
+ else if (flag == HANDLE)
+ return Flag.HANDLE;
+ else if (flag != expFlag) {
+ int pos = in.position() - 1;
+
+ throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected=" + expFlag +
+ ", actual=" + flag + ']');
+ }
+
+ return Flag.NORMAL;
+ }
+
+ /**
+ * @param fieldName Field name.
+ * @return {@code True} if field is set.
+ */
+ public boolean hasField(String fieldName) {
+ return hasField(fieldId(fieldName));
+ }
+
+ /**
+ * @param fieldId Field ID.
+ * @return {@code True} if field is set.
+ */
+ private boolean hasField(int fieldId) {
+ return fieldOffset(fieldId) != 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryRawReader rawReader() {
+ in.position(rawOff);
+
+ return this;
+ }
+
+ /**
+ * @return Unmarshalled value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable private Object unmarshal(boolean detach) throws BinaryObjectException {
+ int start = in.position();
+
+ byte flag = in.readByte();
+
+ switch (flag) {
+ case NULL:
+ return null;
+
+ case HANDLE:
+ int handle = start - in.readInt();
+
+ BinaryObject handledPo = rCtx.getPortableByHandle(handle);
+
+ if (handledPo != null)
+ return handledPo;
+
+ in.position(handle);
+
+ return unmarshal();
+
+ case OBJ:
+ PortableUtils.checkProtocolVersion(in.readByte());
+
+ BinaryObjectEx po;
+
+ if (detach) {
+ in.position(start + GridPortableMarshaller.TOTAL_LEN_POS);
+
+ int len = in.readInt();
+
+ in.position(start);
+
+ po = new BinaryObjectImpl(ctx, in.readByteArray(len), 0);
+ }
+ else
+ po = in.offheapPointer() > 0
+ ? new BinaryObjectOffheapImpl(ctx, in.offheapPointer(), start,
+ in.remaining() + in.position())
+ : new BinaryObjectImpl(ctx, in.array(), start);
+
+ rCtx.setPortableHandler(start, po);
+
+ in.position(start + po.length());
+
+ return po;
+
+ case BYTE:
+ return in.readByte();
+
+ case SHORT:
+ return in.readShort();
+
+ case INT:
+ return in.readInt();
+
+ case LONG:
+ return in.readLong();
+
+ case FLOAT:
+ return in.readFloat();
+
+ case DOUBLE:
+ return in.readDouble();
+
+ case CHAR:
+ return in.readChar();
+
+ case BOOLEAN:
+ return in.readBoolean();
+
+ case DECIMAL:
+ return doReadDecimal();
+
+ case STRING:
+ return doReadString();
+
+ case UUID:
+ return doReadUuid();
+
+ case DATE:
+ return doReadDate();
+
+ case TIMESTAMP:
+ return doReadTimestamp();
+
+ case BYTE_ARR:
+ return doReadByteArray();
+
+ case SHORT_ARR:
+ return doReadShortArray();
+
+ case INT_ARR:
+ return doReadIntArray();
+
+ case LONG_ARR:
+ return doReadLongArray();
+
+ case FLOAT_ARR:
+ return doReadFloatArray();
+
+ case DOUBLE_ARR:
+ return doReadDoubleArray();
+
+ case CHAR_ARR:
+ return doReadCharArray();
+
+ case BOOLEAN_ARR:
+ return doReadBooleanArray();
+
+ case DECIMAL_ARR:
+ return doReadDecimalArray();
+
+ case STRING_ARR:
+ return doReadStringArray();
+
+ case UUID_ARR:
+ return doReadUuidArray();
+
+ case DATE_ARR:
+ return doReadDateArray();
+
+ case TIMESTAMP_ARR:
+ return doReadTimestampArray();
+
+ case OBJ_ARR:
+ return doReadObjectArray(false);
+
+ case COL:
+ return doReadCollection(false, null);
+
+ case MAP:
+ return doReadMap(false, null);
+
+ case MAP_ENTRY:
+ return doReadMapEntry(false);
+
+ case PORTABLE_OBJ:
+ return doReadPortableObject();
+
+ case ENUM:
+ return doReadEnum(doReadClass());
+
+ case ENUM_ARR:
+ return doReadEnumArray(doReadClass());
+
+ case CLASS:
+ return doReadClass();
+
+ case OPTM_MARSH:
+ int len = in.readInt();
+
+ ByteArrayInputStream input = new ByteArrayInputStream(in.array(), in.position(), len);
+
+ Object obj;
+
+ try {
+ obj = ctx.optimizedMarsh().unmarshal(input, null);
+ }
+ catch (IgniteCheckedException e) {
+ throw new BinaryObjectException("Failed to unmarshal object with optmMarsh marshaller", e);
+ }
+
+ return obj;
+
+ default:
+ throw new BinaryObjectException("Invalid flag value: " + flag);
+ }
+ }
+
+ /**
+ * @return Value.
+ */
+ private BigDecimal doReadDecimal() {
+ int scale = in.readInt();
+ byte[] mag = doReadByteArray();
+
+ BigInteger intVal = new BigInteger(mag);
+
+ if (scale < 0) {
+ scale &= 0x7FFFFFFF;
+
+ intVal = intVal.negate();
+ }
+
+ return new BigDecimal(intVal, scale);
+ }
+
+ /**
+ * @return Value.
+ */
+ private String doReadString() {
+ if (in.readBoolean()) {
+ if (!in.hasArray())
+ return new String(doReadByteArray(), UTF_8);
+
+ int strLen = in.readInt();
+ int strOff = in.position();
+
+ String res = new String(in.array(), strOff, strLen, UTF_8);
+
+ in.position(in.position() + strLen);
+
+ return res;
+ }
+ else
+ return String.valueOf(doReadCharArray());
+ }
+
+ /**
+ * @return Value.
+ */
+ private UUID doReadUuid() {
+ return new UUID(in.readLong(), in.readLong());
+ }
+
+ /**
+ * @return Value.
+ */
+ private Date doReadDate() {
+ long time = in.readLong();
+
+ return new Date(time);
+ }
+
+ /**
+ * @return Value.
+ */
+ private Timestamp doReadTimestamp() {
+ long time = in.readLong();
+ int nanos = in.readInt();
+
+ Timestamp ts = new Timestamp(time);
+
+ ts.setNanos(ts.getNanos() + nanos);
+
+ return ts;
+ }
+
+ /**
+ * @return Object.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @Nullable private Object doReadObject() throws BinaryObjectException {
+ BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx, in, in.position(), ldr, rCtx);
+
+ return reader.deserialize();
+ }
+
+ /**
+ * @return Deserialized object.
+ * @throws org.apache.ignite.binary.BinaryObjectException If failed.
+ */
+ @Nullable Object deserialize() throws BinaryObjectException {
+ Object obj;
+
+ byte flag = in.readByte();
+
+ switch (flag) {
+ case NULL:
+ obj = null;
+
+ break;
+
+ case HANDLE:
+ int handle = start - in.readInt();
+
+ obj = rCtx.getObjectByHandle(handle);
+
+ if (obj == null) {
+ int retPos = in.position();
+
+ in.position(handle);
+
+ obj = doReadObject();
+
+ in.position(retPos);
+ }
+
+ break;
+
+ case OBJ:
+ parseHeaderIfNeeded();
+
+ assert typeId != UNREGISTERED_TYPE_ID;
+
+ PortableUtils.checkProtocolVersion(in.readByte());
+
+ boolean userType = PortableUtils.isUserType(this.readShort());
+
+ // Skip typeId and hash code.
+ in.position(in.position() + 8);
+
+ desc = ctx.descriptorForTypeId(userType, typeId, ldr);
+
+ int len = in.readInt();
+
+ in.position(start + hdrLen);
+
+ if (desc == null)
+ throw new BinaryInvalidTypeException("Unknown type ID: " + typeId);
+
+ obj = desc.read(this);
+
+ in.position(start + len);
+
+ break;
+
+ case BYTE:
+ obj = in.readByte();
+
+ break;
+
+ case SHORT:
+ obj = in.readShort();
+
+ break;
+
+ case INT:
+ obj = in.readInt();
+
+ break;
+
+ case LONG:
+ obj = in.readLong();
+
+ break;
+
+ case FLOAT:
+ obj = in.readFloat();
+
+ break;
+
+ case DOUBLE:
+ obj = in.readDouble();
+
+ break;
+
+ case CHAR:
+ obj = in.readChar();
+
+ break;
+
+ case BOOLEAN:
+ obj = in.readBoolean();
+
+ break;
+
+ case DECIMAL:
+ obj = doReadDecimal();
+
+ break;
+
+ case STRING:
+ obj = doReadString();
+
+ break;
+
+ case UUID:
+ obj = doReadUuid();
+
+ break;
+
+ case DATE:
+ obj = doReadDate();
+
+ break;
+
+ case TIMESTAMP:
+ obj = doReadTimestamp();
+
+ break;
+
+ case BYTE_ARR:
+ obj = doReadByteArray();
+
+ break;
+
+ case SHORT_ARR:
+ obj = doReadShortArray();
+
+ break;
+
+ case INT_ARR:
+ obj = doReadIntArray();
+
+ break;
+
+ case LONG_ARR:
+ obj = doReadLongArray();
+
+ break;
+
+ case FLOAT_ARR:
+ obj = doReadFloatArray();
+
+ break;
+
+ case DOUBLE_ARR:
+ obj = doReadDoubleArray();
+
+ break;
+
+ case CHAR_ARR:
+ obj = doReadCharArray();
+
+ break;
+
+ case BOOLEAN_ARR:
+ obj = doReadBooleanArray();
+
+ break;
+
+ case DECIMAL_ARR:
+ obj = doReadDecimalArray();
+
+ break;
+
+ case STRING_ARR:
+ obj = doReadStringArray();
+
+ break;
+
+ case UUID_ARR:
+ obj = doReadUuidArray();
+
+ break;
+
+ case DATE_ARR:
+ obj = doReadDateArray();
+
+ break;
+
+ case TIMESTAMP_ARR:
+ obj = doReadTimestampArray();
+
+ break;
+
+ case OBJ_ARR:
+ obj = doReadObjectArray(true);
+
+ break;
+
+ case COL:
+ obj = doReadCollection(true, null);
+
+ break;
+
+ case MAP:
+ obj = doReadMap(true, null);
+
+ break;
+
+ case MAP_ENTRY:
+ obj = doReadMapEntry(true);
+
+ break;
+
+ case PORTABLE_OBJ:
+ obj = doReadPortableObject();
+
+ ((BinaryObjectImpl)obj).context(ctx);
+
+ if (!GridPortableMarshaller.KEEP_PORTABLES.get())
+ obj = ((BinaryObject)obj).deserialize();
+
+ break;
+
+ case ENUM:
+ obj = doReadEnum(doReadClass());
+
+ break;
+
+ case ENUM_ARR:
+ obj = doReadEnumArray(doReadClass());
+
+ break;
+
+ case CLASS:
+ obj = doReadClass();
+
+ break;
+
+ case OPTM_MARSH:
+ int dataLen = in.readInt();
+
+ ByteArrayInputStream input = new ByteArrayInputStream(in.array(), in.position(), dataLen);
+
+ try {
+ obj = ctx.optimizedMarsh().unmarshal(input, null);
+ }
+ catch (IgniteCheckedException e) {
+ throw new BinaryObjectException("Failed to unmarshal object with optimized marshaller", e);
+ }
+
+ in.position(in.position() + dataLen);
+
+ break;
+
+ default:
+ throw new BinaryObjectException("Invalid flag value: " + flag);
+ }
+
+ return obj;
+ }
+
+ /**
+ * @return Value.
+ */
+ private byte[] doReadByteArray() {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ byte[] arr = in.readByteArray(len);
+
+ setHandler(arr, hPos);
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ */
+ private short[] doReadShortArray() {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ short[] arr = in.readShortArray(len);
+
+ setHandler(arr, hPos);
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ */
+ private int[] doReadIntArray() {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ int[] arr = in.readIntArray(len);
+
+ setHandler(arr, hPos);
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ */
+ private long[] doReadLongArray() {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ long[] arr = in.readLongArray(len);
+
+ setHandler(arr, hPos);
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ */
+ private float[] doReadFloatArray() {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ float[] arr = in.readFloatArray(len);
+
+ setHandler(arr, hPos);
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ */
+ private double[] doReadDoubleArray() {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ double[] arr = in.readDoubleArray(len);
+
+ setHandler(arr, hPos);
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ */
+ private char[] doReadCharArray() {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ char[] arr = in.readCharArray(len);
+
+ setHandler(arr, hPos);
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ */
+ private boolean[] doReadBooleanArray() {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ boolean[] arr = in.readBooleanArray(len);
+
+ setHandler(arr, hPos);
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ private BigDecimal[] doReadDecimalArray() throws BinaryObjectException {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ BigDecimal[] arr = new BigDecimal[len];
+
+ setHandler(arr, hPos);
+
+ for (int i = 0; i < len; i++) {
+ byte flag = in.readByte();
+
+ if (flag == NULL)
+ arr[i] = null;
+ else {
+ if (flag != DECIMAL)
+ throw new BinaryObjectException("Invalid flag value: " + flag);
+
+ arr[i] = doReadDecimal();
+ }
+ }
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ private String[] doReadStringArray() throws BinaryObjectException {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ String[] arr = new String[len];
+
+ setHandler(arr, hPos);
+
+ for (int i = 0; i < len; i++) {
+ byte flag = in.readByte();
+
+ if (flag == NULL)
+ arr[i] = null;
+ else {
+ if (flag != STRING)
+ throw new BinaryObjectException("Invalid flag value: " + flag);
+
+ arr[i] = doReadString();
+ }
+ }
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ private UUID[] doReadUuidArray() throws BinaryObjectException {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ UUID[] arr = new UUID[len];
+
+ setHandler(arr, hPos);
+
+ for (int i = 0; i < len; i++) {
+ byte flag = in.readByte();
+
+ if (flag == NULL)
+ arr[i] = null;
+ else {
+ if (flag != UUID)
+ throw new BinaryObjectException("Invalid flag value: " + flag);
+
+ arr[i] = doReadUuid();
+ }
+ }
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ private Date[] doReadDateArray() throws BinaryObjectException {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ Date[] arr = new Date[len];
+
+ setHandler(arr, hPos);
+
+ for (int i = 0; i < len; i++) {
+ byte flag = in.readByte();
+
+ if (flag == NULL)
+ arr[i] = null;
+ else {
+ if (flag != DATE)
+ throw new BinaryObjectException("Invalid flag value: " + flag);
+
+ arr[i] = doReadDate();
+ }
+ }
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ private Timestamp[] doReadTimestampArray() throws BinaryObjectException {
+ int hPos = in.position() - 1;
+
+ int len = in.readInt();
+
+ Timestamp[] arr = new Timestamp[len];
+
+ setHandler(arr, hPos);
+
+ for (int i = 0; i < len; i++) {
+ byte flag = in.readByte();
+
+ if (flag == NULL)
+ arr[i] = null;
+ else {
+ if (flag != TIMESTAMP)
+ throw new BinaryObjectException("Invalid flag value: " + flag);
+
+ arr[i] = doReadTimestamp();
+ }
+ }
+
+ return arr;
+ }
+
+ /**
+ * @param deep Deep flag.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ private Object[] doReadObjectArray(boolean deep) throws BinaryObjectException {
+ int hPos = in.position() - 1;
+
+ Class compType = doReadClass();
+
+ int len = in.readInt();
+
+ Object[] arr = deep ? (Object[])Array.newInstance(compType, len) : new Object[len];
+
+ setHandler(arr, hPos);
+
+ for (int i = 0; i < len; i++)
+ arr[i] = deep ? doReadObject() : unmarshal();
+
+ return arr;
+ }
+
+ /**
+ * @param deep Deep flag.
+ * @param cls Collection class.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @SuppressWarnings("unchecked")
+ private Collection<?> doReadCollection(boolean deep, @Nullable Class<? extends Collection> cls)
+ throws BinaryObjectException {
+ int hPos = in.position() - 1;
+
+ int size = in.readInt();
+
+ assert size >= 0;
+
+ byte colType = in.readByte();
+
+ Collection<Object> col;
+
+ if (cls != null) {
+ try {
+ Constructor<? extends Collection> cons = cls.getConstructor();
+
+ col = cons.newInstance();
+ }
+ catch (NoSuchMethodException ignored) {
+ throw new BinaryObjectException("Collection class doesn't have public default constructor: " +
+ cls.getName());
+ }
+ catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
+ throw new BinaryObjectException("Failed to instantiate collection: " + cls.getName(), e);
+ }
+ }
+ else {
+ switch (colType) {
+ case ARR_LIST:
+ col = new ArrayList<>(size);
+
+ break;
+
+ case LINKED_LIST:
+ col = new LinkedList<>();
+
+ break;
+
+ case HASH_SET:
+ col = U.newHashSet(size);
+
+ break;
+
+ case LINKED_HASH_SET:
+ col = U.newLinkedHashSet(size);
+
+ break;
+
+ case TREE_SET:
+ col = new TreeSet<>();
+
+ break;
+
+ case CONC_SKIP_LIST_SET:
+ col = new ConcurrentSkipListSet<>();
+
+ break;
+
+ case USER_SET:
+ col = U.newHashSet(size);
+
+ break;
+
+ case USER_COL:
+ col = new ArrayList<>(size);
+
+ break;
+
+ default:
+ throw new BinaryObjectException("Invalid collection type: " + colType);
+ }
+ }
+
+ setHandler(col, hPos);
+
+ for (int i = 0; i < size; i++)
+ col.add(deep ? doReadObject() : unmarshal());
+
+ return col;
+ }
+
+ /**
+ * @param deep Deep flag.
+ * @param cls Map class.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ @SuppressWarnings("unchecked")
+ private Map<?, ?> doReadMap(boolean deep, @Nullable Class<? extends Map> cls)
+ throws BinaryObjectException {
+ int hPos = in.position() - 1;
+
+ int size = in.readInt();
+
+ assert size >= 0;
+
+ byte mapType = in.readByte();
+
+ Map<Object, Object> map;
+
+ if (cls != null) {
+ try {
+ Constructor<? extends Map> cons = cls.getConstructor();
+
+ map = cons.newInstance();
+ }
+ catch (NoSuchMethodException ignored) {
+ throw new BinaryObjectException("Map class doesn't have public default constructor: " +
+ cls.getName());
+ }
+ catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
+ throw new BinaryObjectException("Failed to instantiate map: " + cls.getName(), e);
+ }
+ }
+ else {
+ switch (mapType) {
+ case HASH_MAP:
+ map = U.newHashMap(size);
+
+ break;
+
+ case LINKED_HASH_MAP:
+ map = U.newLinkedHashMap(size);
+
+ break;
+
+ case TREE_MAP:
+ map = new TreeMap<>();
+
+ break;
+
+ case CONC_HASH_MAP:
+ map = new ConcurrentHashMap<>(size);
+
+ break;
+
+ case USER_COL:
+ map = U.newHashMap(size);
+
+ break;
+
+ case PROPERTIES_MAP:
+ map = new Properties();
+
+ break;
+
+ default:
+ throw new BinaryObjectException("Invalid map type: " + mapType);
+ }
+ }
+
+ setHandler(map, hPos);
+
+ for (int i = 0; i < size; i++)
+ map.put(deep ? doReadObject() : unmarshal(), deep ? doReadObject() : unmarshal());
+
+ return map;
+ }
+
+ /**
+ * @param deep Deep flag.
+ * @return Value.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ private Map.Entry<?, ?> doReadMapEntry(boolean deep) throws BinaryObjectException {
+ int hPos = in.position() - 1;
+
+ Object val1 = deep ? doReadObject() : unmarshal();
+ Object val2 = deep ? doReadObject() : unmarshal();
+
+ GridMapEntry entry = new GridMapEntry<>(val1, val2);
+
+ setHandler(entry, hPos);
+
+ return entry;
+ }
+
+ /**
+ * @return Value.
+ */
+ private BinaryObject doReadPortableObject() {
+ if (in.offheapPointer() > 0) {
+ int len = in.readInt();
+
+ int pos = in.position();
+
+ in.position(in.position() + len);
+
+ int start = in.readInt();
+
+ return new BinaryObjectOffheapImpl(ctx, in.offheapPointer() + pos, start, len);
+ }
+ else {
+ byte[] arr = doReadByteArray();
+ int start = in.readInt();
+
+ return new BinaryObjectImpl(ctx, arr, start);
+ }
+ }
+
+ /**
+ * @param cls Enum class.
+ * @return Value.
+ */
+ private Enum<?> doReadEnum(Class<?> cls) throws BinaryObjectException {
+ if (!cls.isEnum())
+ throw new BinaryObjectException("Class does not represent enum type: " + cls.getName());
+
+ int ord = in.readInt();
+
+ return ord >= 0 ? (Enum<?>)GridEnumCache.get(cls)[ord] : null;
+ }
+
+ /**
+ * @param cls Enum class.
+ * @return Value.
+ */
+ private Object[] doReadEnumArray(Class<?> cls) throws BinaryObjectException {
+ int len = in.readInt();
+
+ Object[] arr = (Object[])Array.newInstance(cls, len);
+
+ for (int i = 0; i < len; i++) {
+ byte flag = in.readByte();
+
+ if (flag == NULL)
+ arr[i] = null;
+ else
+ arr[i] = doReadEnum(doReadClass());
+ }
+
+ return arr;
+ }
+
+ /**
+ * @return Value.
+ */
+ private Class doReadClass() throws BinaryObjectException {
+ return doReadClass(in.readInt());
+ }
+
+ /**
+ * @param typeId Type id.
+ * @return Value.
+ */
+ private Class doReadClass(int typeId) throws BinaryObjectException {
+ Class cls;
+
+ if (typeId == OBJECT_TYPE_ID)
+ return Object.class;
+
+ if (typeId != UNREGISTERED_TYPE_ID)
+ cls = ctx.descriptorForTypeId(true, typeId, ldr).describedClass();
+ else {
+ byte flag = in.readByte();
+
+ if (flag != STRING)
+ throw new BinaryObjectException("No class definition for typeId: " + typeId);
+
+ String clsName = doReadString();
+
+ try {
+ cls = U.forName(clsName, ldr);
+ }
+ catch (ClassNotFoundException e) {
+ throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
+ }
+
+ // forces registering of class by type id, at least locally
+ ctx.descriptorForClass(cls);
+ }
+
+ return cls;
+ }
+
+ /**
+ * @param name Field name.
+ * @return Field offset.
+ */
+ private int fieldId(String name) {
+ assert name != null;
+
+ parseHeaderIfNeeded();
+
+ assert typeId != UNREGISTERED_TYPE_ID;
+
+ if (idMapper == null)
+ idMapper = ctx.userTypeIdMapper(typeId);
+
+ return idMapper.fieldId(typeId, name);
+ }
+
+ /**
+ * Create schema.
+ *
+ * @return Schema.
+ */
+ public PortableSchema createSchema() {
+ parseHeaderIfNeeded();
+
+ LinkedHashMap<Integer, Integer> fields = new LinkedHashMap<>();
+
+ int searchPos = footerStart;
+ int searchEnd = searchPos + footerLen;
+
+ int idx = 0;
+
+ while (searchPos < searchEnd) {
+ int fieldId = in.readIntPositioned(searchPos);
+
+ fields.put(fieldId, idx++);
+
+ searchPos += 4 + offsetSize;
+ }
+
+ return new PortableSchema(fields);
+ }
+
+ /**
+ * @param id Field ID.
+ * @return Field offset.
+ */
+ private int fieldOffset(int id) {
+ assert hdrLen != 0;
+
+ if (footerLen == 0)
+ return 0;
+
+ int searchPos = footerStart;
+ int searchTail = searchPos + footerLen;
+
+ if (hasLowFieldsCount(footerLen)) {
+ while (true) {
+ if (searchPos >= searchTail)
+ return 0;
+
+ int id0 = in.readIntPositioned(searchPos);
+
+ if (id0 == id) {
+ int pos = start + PortableUtils.fieldOffsetRelative(in, searchPos + 4, offsetSize);
+
+ in.position(pos);
+
+ return pos;
+ }
+
+ searchPos += 4 + offsetSize;
+ }
+ }
+ else {
+ PortableSchema schema0 = schema;
+
+ if (schema0 == null) {
+ schema0 = ctx.schemaRegistry(typeId).schema(schemaId);
+
+ if (schema0 == null) {
+ schema0 = createSchema();
+
+ ctx.schemaRegistry(typeId).addSchema(schemaId, schema0);
+ }
+
+ schema = schema0;
+ }
+
+ int order = schema.order(id);
+
+ if (order != PortableSchema.ORDER_NOT_FOUND) {
+ int offsetPos = footerStart + order * (4 + offsetSize) + 4;
+
+ int pos = start + PortableUtils.fieldOffsetRelative(in, offsetPos, offsetSize);
+
+ in.position(pos);
+
+ return pos;
+ }
+ else
+ return 0;
+ }
+ }
+
+ /**
+ * Check whether object has low amount of fields.
+ *
+ * @param footerLen Footer length.
+ */
+ private boolean hasLowFieldsCount(int footerLen) {
+ assert hdrParsed;
+
+ return footerLen < (FIELD_DESC_LEN << 4);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int readUnsignedByte() throws IOException {
+ return readByte() & 0xff;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int readUnsignedShort() throws IOException {
+ return readShort() & 0xffff;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String readLine() throws IOException {
+ SB sb = new SB();
+
+ int b;
+
+ while ((b = read()) >= 0) {
+ char c = (char)b;
+
+ switch (c) {
+ case '\n':
+ return sb.toString();
+
+ case '\r':
+ b = read();
+
+ if (b < 0 || b == '\n')
+ return sb.toString();
+ else
+ sb.a((char)b);
+
+ break;
+
+ default:
+ sb.a(c);
+ }
+ }
+
+ return sb.toString();
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("ConstantConditions")
+ @NotNull @Override public String readUTF() throws IOException {
+ return readString();
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("NullableProblems")
+ @Override public void readFully(byte[] b) throws IOException {
+ readFully(b, 0, b.length);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("NullableProblems")
+ @Override public void readFully(byte[] b, int off, int len) throws IOException {
+ int cnt = in.read(b, off, len);
+
+ if (cnt < len)
+ throw new EOFException();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int skipBytes(int n) throws IOException {
+ int toSkip = Math.min(in.remaining(), n);
+
+ in.position(in.position() + toSkip);
+
+ return toSkip;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int read() throws IOException {
+ return readByte();
+ }
+
+ /** {@inheritDoc} */
+ @Override public int read(byte[] b) throws IOException {
+ return read(b, 0, b.length);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int read(byte[] b, int off, int len) throws IOException {
+ return in.read(b, off, len);
+ }
+
+ /** {@inheritDoc} */
+ @Override public long skip(long n) throws IOException {
+ return skipBytes((int) n);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int available() throws IOException {
+ return in.remaining();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void close() throws IOException {
+ // No-op.
+ }
+
+ /**
+ * Flag.
+ */
+ private static enum Flag {
+ /** Null. */
+ NULL,
+
+ /** Handle. */
+ HANDLE,
+
+ /** Regular. */
+ NORMAL
+ }
+}
[11/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
index 82e5f2a..214ba45 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalAdapter.java
@@ -218,8 +218,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
timeout,
invalidate,
storeEnabled,
- onePhaseCommit,
- txSize,
+ onePhaseCommit,
+ txSize,
subjId,
taskNameHash
);
@@ -432,6 +432,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
final Collection<KeyCacheObject> keys,
boolean skipVals,
boolean needVer,
+ boolean keepBinary,
final GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c
) {
assert cacheCtx.isLocal() : cacheCtx.name();
@@ -467,7 +468,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
CU.subjectId(this, cctx),
null,
resolveTaskName(),
- expiryPlc);
+ expiryPlc,
+ txEntry == null ? keepBinary : txEntry.keepBinary());
if (res == null) {
if (misses == null)
@@ -722,9 +724,13 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
}
if (intercept) {
- Object interceptorVal = cacheCtx.config().getInterceptor()
- .onBeforePut(new CacheLazyEntry(cacheCtx, key, e.cached().rawGetOrUnmarshal(true)),
- CU.value(val, cacheCtx, false));
+ Object interceptorVal = cacheCtx.config().getInterceptor().onBeforePut(
+ new CacheLazyEntry(
+ cacheCtx,
+ key,
+ e.cached().rawGetOrUnmarshal(true),
+ e.keepBinary()),
+ cacheCtx.cacheObjectContext().unwrapPortableIfNeeded(val, e.keepBinary(), false));
if (interceptorVal == null)
continue;
@@ -739,7 +745,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
if (putMap == null)
putMap = new LinkedHashMap<>(writeMap().size(), 1.0f);
- putMap.put(CU.value(key, cacheCtx, false), F.t(CU.value(val, cacheCtx, false), ver));
+ putMap.put(key, F.<Object, GridCacheVersion>t(val, ver));
}
}
else if (op == DELETE) {
@@ -768,7 +774,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
if (intercept) {
IgniteBiTuple<Boolean, Object> t = cacheCtx.config().getInterceptor().onBeforeRemove(
- new CacheLazyEntry(cacheCtx, key, e.cached().rawGetOrUnmarshal(true)));
+ new CacheLazyEntry(cacheCtx, key, e.cached().rawGetOrUnmarshal(true), e.keepBinary()));
if (cacheCtx.cancelRemove(t))
continue;
@@ -781,7 +787,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
if (rmvCol == null)
rmvCol = new ArrayList<>();
- rmvCol.add(key.value(cacheCtx.cacheObjectContext(), false));
+ rmvCol.add(key);
}
}
else if (log.isDebugEnabled())
@@ -1018,6 +1024,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
txEntry.ttl(),
evt,
metrics,
+ txEntry.keepBinary(),
topVer,
null,
cached.detached() ? DR_NONE : drType,
@@ -1038,6 +1045,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
txEntry.ttl(),
false,
metrics,
+ txEntry.keepBinary(),
topVer,
CU.empty0(),
DR_NONE,
@@ -1057,6 +1065,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
false,
evt,
metrics,
+ txEntry.keepBinary(),
topVer,
null,
cached.detached() ? DR_NONE : drType,
@@ -1074,6 +1083,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
false,
false,
metrics,
+ txEntry.keepBinary(),
topVer,
CU.empty0(),
DR_NONE,
@@ -1415,7 +1425,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
CU.subjectId(this, cctx),
transformClo,
resolveTaskName(),
- null);
+ null,
+ txEntry.keepBinary());
if (val != null) {
if (!readCommitted() && !skipVals)
@@ -1474,7 +1485,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
CU.subjectId(this, cctx),
null,
resolveTaskName(),
- accessPlc) : null;
+ accessPlc,
+ !deserializePortable) : null;
if (res != null) {
val = res.get1();
@@ -1493,7 +1505,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
CU.subjectId(this, cctx),
null,
resolveTaskName(),
- accessPlc);
+ accessPlc,
+ !deserializePortable);
}
if (val != null) {
@@ -1524,7 +1537,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
-1L,
-1L,
null,
- skipStore);
+ skipStore,
+ !deserializePortable);
// As optimization, mark as checked immediately
// for non-pessimistic if value is not null.
@@ -1648,6 +1662,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
missedMap.keySet(),
skipVals,
needReadVer,
+ !deserializePortable,
new GridInClosure3<KeyCacheObject, Object, GridCacheVersion>() {
@Override public void apply(KeyCacheObject key, Object val, GridCacheVersion loadVer) {
if (isRollbackOnly()) {
@@ -1782,8 +1797,9 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
// Load keys only after the locks have been acquired.
for (KeyCacheObject cacheKey : lockKeys) {
- K keyVal =
- (K)(keepCacheObjects ? cacheKey : cacheKey.value(cacheCtx.cacheObjectContext(), false));
+ K keyVal = (K)
+ (keepCacheObjects ? cacheKey :
+ cacheCtx.cacheObjectContext().unwrapPortableIfNeeded(cacheKey, !deserializePortable));
if (retMap.containsKey(keyVal))
// We already have a return value.
@@ -1816,7 +1832,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
CU.subjectId(IgniteTxLocalAdapter.this, cctx),
transformClo,
resolveTaskName(),
- null);
+ null,
+ txEntry.keepBinary());
// If value is in cache and passed the filter.
if (val != null) {
@@ -2047,7 +2064,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
@Nullable Map<KeyCacheObject, GridCacheDrInfo> drPutMap,
@Nullable Map<KeyCacheObject, GridCacheVersion> drRmvMap,
boolean skipStore,
- final boolean singleRmv
+ final boolean singleRmv,
+ final boolean keepBinary
) {
assert retval || invokeMap == null;
@@ -2152,7 +2170,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
CU.subjectId(this, cctx),
entryProcessor,
resolveTaskName(),
- null) : null;
+ null,
+ keepBinary) : null;
if (res != null) {
old = res.get1();
@@ -2171,7 +2190,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
CU.subjectId(this, cctx),
entryProcessor,
resolveTaskName(),
- null);
+ null,
+ keepBinary);
}
}
catch (ClusterTopologyCheckedException e) {
@@ -2186,7 +2206,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
if (old != null && hasFilters && !filter(entry.context(), cacheKey, old, filter)) {
skipped = skip(skipped, cacheKey);
- ret.set(cacheCtx, old, false);
+ ret.set(cacheCtx, old, false, keepBinary);
if (!readCommitted()) {
// Enlist failed filters as reads for non-read-committed mode,
@@ -2202,7 +2222,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
-1L,
-1L,
null,
- skipStore);
+ skipStore,
+ keepBinary);
txEntry.markValid();
@@ -2233,7 +2254,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
drTtl,
drExpireTime,
drVer,
- skipStore);
+ skipStore,
+ keepBinary);
if (!implicit() && readCommitted() && !cacheCtx.offheapTiered())
cacheCtx.evicts().touch(entry, topologyVersion());
@@ -2255,7 +2277,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
assert txEntry.op() != TRANSFORM : txEntry;
if (retval)
- ret.set(cacheCtx, null, true);
+ ret.set(cacheCtx, null, true, keepBinary);
else
ret.success(true);
}
@@ -2268,7 +2290,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
}
if (retval && !transform)
- ret.set(cacheCtx, old, true);
+ ret.set(cacheCtx, old, true, keepBinary);
else {
if (txEntry.op() == TRANSFORM) {
GridCacheVersion ver;
@@ -2296,7 +2318,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
// Pessimistic.
else {
if (retval && !transform)
- ret.set(cacheCtx, old, true);
+ ret.set(cacheCtx, old, true, keepBinary);
else
ret.success(true);
}
@@ -2324,7 +2346,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
if (hasFilters && !filter(entry.context(), cacheKey, v, filter)) {
skipped = skip(skipped, cacheKey);
- ret.set(cacheCtx, v, false);
+ ret.set(cacheCtx, v, false, keepBinary);
continue;
}
@@ -2343,7 +2365,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
drTtl,
drExpireTime,
drVer,
- skipStore);
+ skipStore,
+ keepBinary);
enlisted.add(cacheKey);
@@ -2370,7 +2393,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
txEntry.markValid();
if (retval && !transform)
- ret.set(cacheCtx, v, true);
+ ret.set(cacheCtx, v, true, keepBinary);
else
ret.success(true);
}
@@ -2391,6 +2414,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
missedForLoad,
skipVals,
needReadVer,
+ keepBinary,
new GridInClosure3<KeyCacheObject, Object, GridCacheVersion>() {
@Override public void apply(KeyCacheObject key,
@Nullable Object val,
@@ -2412,7 +2436,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
assert !hasFilters && !retval;
assert val == null || Boolean.TRUE.equals(val) : val;
- ret.set(cacheCtx, null, val != null);
+ ret.set(cacheCtx, null, val != null, keepBinary);
}
else {
CacheObject cacheVal = cacheCtx.toCacheObject(val);
@@ -2437,7 +2461,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
else {
boolean success = !hasFilters || isAll(e.context(), key, cacheVal, filter);
- ret.set(cacheCtx, cacheVal, success);
+ ret.set(cacheCtx, cacheVal, success, keepBinary);
}
}
}
@@ -2559,7 +2583,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
CU.subjectId(this, cctx),
null,
resolveTaskName(),
- null);
+ null,
+ txEntry.keepBinary());
}
}
else {
@@ -2587,7 +2612,7 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
}
}
else
- ret.value(cacheCtx, v);
+ ret.value(cacheCtx, v, txEntry.keepBinary());
}
boolean pass = F.isEmpty(filter) || cacheCtx.isAll(cached, filter);
@@ -2665,7 +2690,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
for (T2<EntryProcessor<Object, Object, Object>, Object[]> t : txEntry.entryProcessors()) {
CacheInvokeEntry<Object, Object> invokeEntry =
- new CacheInvokeEntry(txEntry.context(), txEntry.key(), key0, cacheVal, val0, ver);
+ new CacheInvokeEntry(txEntry.context(), txEntry.key(), key0, cacheVal, val0, ver,
+ txEntry.keepBinary());
EntryProcessor<Object, Object, ?> entryProcessor = t.get1();
@@ -2805,7 +2831,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
drMap,
null,
opCtx != null && opCtx.skipStore(),
- false);
+ false,
+ opCtx != null && opCtx.isKeepBinary());
if (pessimistic()) {
// Loose all skipped.
@@ -3032,7 +3059,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
null,
drMap,
opCtx != null && opCtx.skipStore(),
- singleRmv
+ singleRmv,
+ opCtx != null && opCtx.isKeepBinary()
);
if (log.isDebugEnabled())
@@ -3157,12 +3185,12 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
* Checks if portable values should be deserialized.
*
* @param cacheCtx Cache context.
- * @return {@code True} if portables should be deserialized, {@code false} otherwise.
+ * @return {@code True} if binary should be deserialized, {@code false} otherwise.
*/
private boolean deserializePortables(GridCacheContext cacheCtx) {
CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
- return opCtx == null || !opCtx.isKeepPortable();
+ return opCtx == null || !opCtx.isKeepBinary();
}
/**
@@ -3283,7 +3311,9 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
long drTtl,
long drExpireTime,
@Nullable GridCacheVersion drVer,
- boolean skipStore) {
+ boolean skipStore,
+ boolean keepBinary
+ ) {
assert invokeArgs == null || op == TRANSFORM;
IgniteTxKey key = entry.txKey();
@@ -3353,7 +3383,8 @@ public abstract class IgniteTxLocalAdapter extends IgniteTxAdapter
entry,
filter,
drVer,
- skipStore);
+ skipStore,
+ keepBinary);
txEntry.conflictExpireTime(drExpireTime);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalEx.java
index 0d83338..08f2e43 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxLocalEx.java
@@ -166,5 +166,6 @@ public interface IgniteTxLocalEx extends IgniteInternalTx {
Collection<KeyCacheObject> keys,
boolean skipVals,
boolean needVer,
+ boolean keepBinary,
GridInClosure3<KeyCacheObject, Object, GridCacheVersion> c);
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
index 1f51b8a..ec0a318 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java
@@ -1404,7 +1404,7 @@ public class IgniteTxManager extends GridCacheSharedManagerAdapter {
assert serReadVer == null || (tx.optimistic() && tx.serializable()) : txEntry1;
- if (!entry1.tmLock(tx, timeout, serOrder, serReadVer)) {
+ if (!entry1.tmLock(tx, timeout, serOrder, serReadVer, txEntry1.keepBinary())) {
// Unlock locks locked so far.
for (IgniteTxEntry txEntry2 : entries) {
if (txEntry2 == txEntry1)
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
index ecbe294..239b1b9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessor.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal.processors.cacheobject;
+import org.apache.ignite.IgniteBinary;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.configuration.CacheConfiguration;
@@ -164,4 +165,9 @@ public interface IgniteCacheObjectProcessor extends GridProcessor {
* @return {@code True} if object is of known immutable type.
*/
public boolean immutable(Object obj);
+
+ /**
+ * @return Ignite binary interface.
+ */
+ public IgniteBinary binary();
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
index 0bc102e..0d36e0e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/IgniteCacheObjectProcessorImpl.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.UUID;
+import org.apache.ignite.IgniteBinary;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.cache.CacheMemoryMode;
@@ -56,6 +57,9 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
/** Immutable classes. */
private static final Collection<Class<?>> IMMUTABLE_CLS = new HashSet<>();
+ /** */
+ private IgniteBinary noOpBinary = new NoOpBinary();
+
/**
*
*/
@@ -82,6 +86,11 @@ public class IgniteCacheObjectProcessorImpl extends GridProcessorAdapter impleme
}
/** {@inheritDoc} */
+ @Override public IgniteBinary binary() {
+ return noOpBinary;
+ }
+
+ /** {@inheritDoc} */
@Nullable @Override public CacheObject prepareForCache(@Nullable CacheObject obj, GridCacheContext cctx) {
if (obj == null)
return null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/NoOpBinary.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/NoOpBinary.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/NoOpBinary.java
new file mode 100644
index 0000000..c20f278
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cacheobject/NoOpBinary.java
@@ -0,0 +1,80 @@
+/*
+ * 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.cacheobject;
+
+import java.util.Collection;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ *
+ */
+public class NoOpBinary implements IgniteBinary {
+ /** {@inheritDoc} */
+ @Override public int typeId(String typeName) {
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> T toBinary(@Nullable Object obj) throws BinaryObjectException {
+ throw unsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilder builder(int typeId) throws BinaryObjectException {
+ throw unsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilder builder(String typeName) throws BinaryObjectException {
+ throw unsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilder builder(BinaryObject portableObj) throws BinaryObjectException {
+ throw unsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryType metadata(Class<?> cls) throws BinaryObjectException {
+ throw unsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryType metadata(String typeName) throws BinaryObjectException {
+ throw unsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
+ throw unsupported();
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<BinaryType> metadata() throws BinaryObjectException {
+ throw unsupported();
+ }
+
+ /** {@inheritDoc} */
+ private BinaryObjectException unsupported() {
+ return new BinaryObjectException("Binary marshaller is not configured.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessor.java
index 5150d83..a2aab77 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessor.java
@@ -289,6 +289,7 @@ public class DataStreamProcessor<K, V> extends GridProcessorAdapter {
col,
req.ignoreDeploymentOwnership(),
req.skipStore(),
+ req.keepBinary(),
updater);
Exception err = null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerEntry.java
index 982b691..874d2e2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerEntry.java
@@ -82,10 +82,10 @@ public class DataStreamerEntry implements Map.Entry<KeyCacheObject, CacheObject>
* @param ctx Cache context.
* @return Map entry unwrapping internal key and value.
*/
- public <K, V> Map.Entry<K, V> toEntry(final GridCacheContext ctx) {
+ public <K, V> Map.Entry<K, V> toEntry(final GridCacheContext ctx, final boolean keepBinary) {
return new Map.Entry<K, V>() {
@Override public K getKey() {
- return key.value(ctx.cacheObjectContext(), false);
+ return (K)ctx.cacheObjectContext().unwrapPortableIfNeeded(key, keepBinary, false);
}
@Override public V setValue(V val) {
@@ -93,7 +93,7 @@ public class DataStreamerEntry implements Map.Entry<KeyCacheObject, CacheObject>
}
@Override public V getValue() {
- return val != null ? val.<V>value(ctx.cacheObjectContext(), false) : null;
+ return (V)ctx.cacheObjectContext().unwrapPortableIfNeeded(val, keepBinary, false);
}
};
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
index 2190bf6..27eff0c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImpl.java
@@ -211,6 +211,9 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
private boolean skipStore;
/** */
+ private boolean keepBinary;
+
+ /** */
private int maxRemapCnt = DFLT_MAX_REMAP_CNT;
/** Whether a warning at {@link DataStreamerImpl#allowOverwrite()} printed */
@@ -405,6 +408,16 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
}
/** {@inheritDoc} */
+ @Override public boolean keepBinary() {
+ return keepBinary;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void keepBinary(boolean keepBinary) {
+ this.keepBinary = keepBinary;
+ }
+
+ /** {@inheritDoc} */
@Override @Nullable public String cacheName() {
return cacheName;
}
@@ -1243,7 +1256,7 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
if (isLocNode) {
fut = ctx.closure().callLocalSafe(
- new DataStreamerUpdateJob(ctx, log, cacheName, entries, false, skipStore, rcvr), false);
+ new DataStreamerUpdateJob(ctx, log, cacheName, entries, false, skipStore, keepBinary, rcvr), false);
locFuts.add(fut);
@@ -1331,6 +1344,7 @@ public class DataStreamerImpl<K, V> implements IgniteDataStreamer<K, V>, Delayed
entries,
true,
skipStore,
+ keepBinary,
dep != null ? dep.deployMode() : null,
dep != null ? jobPda0.deployClass().getName() : null,
dep != null ? dep.userVersion() : null,
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerRequest.java
index c1a1528..3d65304 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerRequest.java
@@ -64,6 +64,9 @@ public class DataStreamerRequest implements Message {
/** */
private boolean skipStore;
+ /** Keep binary flag. */
+ private boolean keepBinary;
+
/** */
private DeploymentMode depMode;
@@ -117,6 +120,7 @@ public class DataStreamerRequest implements Message {
Collection<DataStreamerEntry> entries,
boolean ignoreDepOwnership,
boolean skipStore,
+ boolean keepBinary,
DeploymentMode depMode,
String sampleClsName,
String userVer,
@@ -133,6 +137,7 @@ public class DataStreamerRequest implements Message {
this.entries = entries;
this.ignoreDepOwnership = ignoreDepOwnership;
this.skipStore = skipStore;
+ this.keepBinary = keepBinary;
this.depMode = depMode;
this.sampleClsName = sampleClsName;
this.userVer = userVer;
@@ -192,6 +197,13 @@ public class DataStreamerRequest implements Message {
}
/**
+ * @return Keep binary flag.
+ */
+ public boolean keepBinary() {
+ return keepBinary;
+ }
+
+ /**
* @return Deployment mode.
*/
public DeploymentMode deploymentMode() {
@@ -294,48 +306,54 @@ public class DataStreamerRequest implements Message {
writer.incrementState();
case 6:
- if (!writer.writeMap("ldrParticipants", ldrParticipants, MessageCollectionItemType.UUID, MessageCollectionItemType.IGNITE_UUID))
+ if (!writer.writeBoolean("keepBinary", keepBinary))
return false;
writer.incrementState();
case 7:
- if (!writer.writeLong("reqId", reqId))
+ if (!writer.writeMap("ldrParticipants", ldrParticipants, MessageCollectionItemType.UUID, MessageCollectionItemType.IGNITE_UUID))
return false;
writer.incrementState();
case 8:
- if (!writer.writeByteArray("resTopicBytes", resTopicBytes))
+ if (!writer.writeLong("reqId", reqId))
return false;
writer.incrementState();
case 9:
- if (!writer.writeString("sampleClsName", sampleClsName))
+ if (!writer.writeByteArray("resTopicBytes", resTopicBytes))
return false;
writer.incrementState();
case 10:
- if (!writer.writeBoolean("skipStore", skipStore))
+ if (!writer.writeString("sampleClsName", sampleClsName))
return false;
writer.incrementState();
case 11:
- if (!writer.writeMessage("topVer", topVer))
+ if (!writer.writeBoolean("skipStore", skipStore))
return false;
writer.incrementState();
case 12:
- if (!writer.writeByteArray("updaterBytes", updaterBytes))
+ if (!writer.writeMessage("topVer", topVer))
return false;
writer.incrementState();
case 13:
+ if (!writer.writeByteArray("updaterBytes", updaterBytes))
+ return false;
+
+ writer.incrementState();
+
+ case 14:
if (!writer.writeString("userVer", userVer))
return false;
@@ -407,7 +425,7 @@ public class DataStreamerRequest implements Message {
reader.incrementState();
case 6:
- ldrParticipants = reader.readMap("ldrParticipants", MessageCollectionItemType.UUID, MessageCollectionItemType.IGNITE_UUID, false);
+ keepBinary = reader.readBoolean("keepBinary");
if (!reader.isLastRead())
return false;
@@ -415,7 +433,7 @@ public class DataStreamerRequest implements Message {
reader.incrementState();
case 7:
- reqId = reader.readLong("reqId");
+ ldrParticipants = reader.readMap("ldrParticipants", MessageCollectionItemType.UUID, MessageCollectionItemType.IGNITE_UUID, false);
if (!reader.isLastRead())
return false;
@@ -423,7 +441,7 @@ public class DataStreamerRequest implements Message {
reader.incrementState();
case 8:
- resTopicBytes = reader.readByteArray("resTopicBytes");
+ reqId = reader.readLong("reqId");
if (!reader.isLastRead())
return false;
@@ -431,7 +449,7 @@ public class DataStreamerRequest implements Message {
reader.incrementState();
case 9:
- sampleClsName = reader.readString("sampleClsName");
+ resTopicBytes = reader.readByteArray("resTopicBytes");
if (!reader.isLastRead())
return false;
@@ -439,7 +457,7 @@ public class DataStreamerRequest implements Message {
reader.incrementState();
case 10:
- skipStore = reader.readBoolean("skipStore");
+ sampleClsName = reader.readString("sampleClsName");
if (!reader.isLastRead())
return false;
@@ -447,7 +465,7 @@ public class DataStreamerRequest implements Message {
reader.incrementState();
case 11:
- topVer = reader.readMessage("topVer");
+ skipStore = reader.readBoolean("skipStore");
if (!reader.isLastRead())
return false;
@@ -455,7 +473,7 @@ public class DataStreamerRequest implements Message {
reader.incrementState();
case 12:
- updaterBytes = reader.readByteArray("updaterBytes");
+ topVer = reader.readMessage("topVer");
if (!reader.isLastRead())
return false;
@@ -463,6 +481,14 @@ public class DataStreamerRequest implements Message {
reader.incrementState();
case 13:
+ updaterBytes = reader.readByteArray("updaterBytes");
+
+ if (!reader.isLastRead())
+ return false;
+
+ reader.incrementState();
+
+ case 14:
userVer = reader.readString("userVer");
if (!reader.isLastRead())
@@ -482,6 +508,6 @@ public class DataStreamerRequest implements Message {
/** {@inheritDoc} */
@Override public byte fieldsCount() {
- return 14;
+ return 15;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerUpdateJob.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerUpdateJob.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerUpdateJob.java
index 42084a3..c49087f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerUpdateJob.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerUpdateJob.java
@@ -56,6 +56,9 @@ class DataStreamerUpdateJob implements GridPlainCallable<Object> {
/** */
private final StreamReceiver rcvr;
+ /** */
+ private boolean keepBinary;
+
/**
* @param ctx Context.
* @param log Log.
@@ -72,6 +75,7 @@ class DataStreamerUpdateJob implements GridPlainCallable<Object> {
Collection<DataStreamerEntry> col,
boolean ignoreDepOwnership,
boolean skipStore,
+ boolean keepBinary,
StreamReceiver<?, ?> rcvr) {
this.ctx = ctx;
this.log = log;
@@ -83,6 +87,7 @@ class DataStreamerUpdateJob implements GridPlainCallable<Object> {
this.col = col;
this.ignoreDepOwnership = ignoreDepOwnership;
this.skipStore = skipStore;
+ this.keepBinary = keepBinary;
this.rcvr = rcvr;
}
@@ -99,6 +104,9 @@ class DataStreamerUpdateJob implements GridPlainCallable<Object> {
if (skipStore)
cache = (IgniteCacheProxy<?, ?>)cache.withSkipStore();
+ if (keepBinary)
+ cache = (IgniteCacheProxy<?, ?>)cache.withKeepBinary();
+
if (ignoreDepOwnership)
cache.context().deploy().ignoreOwnership(true);
@@ -122,7 +130,7 @@ class DataStreamerUpdateJob implements GridPlainCallable<Object> {
if (unwrapEntries()) {
Collection<Map.Entry> col0 = F.viewReadOnly(col, new C1<DataStreamerEntry, Map.Entry>() {
@Override public Map.Entry apply(DataStreamerEntry e) {
- return e.toEntry(cctx);
+ return e.toEntry(cctx, keepBinary);
}
});
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractTarget.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractTarget.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractTarget.java
index 0f46517..09cb29d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractTarget.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractTarget.java
@@ -20,8 +20,8 @@ package org.apache.ignite.internal.processors.platform;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;
import org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils;
@@ -62,7 +62,7 @@ public abstract class PlatformAbstractTarget implements PlatformTarget {
/** {@inheritDoc} */
@Override public long inStreamOutLong(int type, long memPtr) throws Exception {
try (PlatformMemory mem = platformCtx.memory().get(memPtr)) {
- PortableRawReaderEx reader = platformCtx.reader(mem);
+ BinaryRawReaderEx reader = platformCtx.reader(mem);
if (type == OP_META) {
platformCtx.processMetadata(reader);
@@ -80,7 +80,7 @@ public abstract class PlatformAbstractTarget implements PlatformTarget {
/** {@inheritDoc} */
@Override public Object inStreamOutObject(int type, long memPtr) throws Exception {
try (PlatformMemory mem = platformCtx.memory().get(memPtr)) {
- PortableRawReaderEx reader = platformCtx.reader(mem);
+ BinaryRawReaderEx reader = platformCtx.reader(mem);
return processInStreamOutObject(type, reader);
}
@@ -104,7 +104,7 @@ public abstract class PlatformAbstractTarget implements PlatformTarget {
try (PlatformMemory mem = platformCtx.memory().get(memPtr)) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = platformCtx.writer(out);
+ BinaryRawWriterEx writer = platformCtx.writer(out);
processOutStream(type, writer);
@@ -128,12 +128,12 @@ public abstract class PlatformAbstractTarget implements PlatformTarget {
/** {@inheritDoc} */
@Override public void inStreamOutStream(int type, long inMemPtr, long outMemPtr) throws Exception {
try (PlatformMemory inMem = platformCtx.memory().get(inMemPtr)) {
- PortableRawReaderEx reader = platformCtx.reader(inMem);
+ BinaryRawReaderEx reader = platformCtx.reader(inMem);
try (PlatformMemory outMem = platformCtx.memory().get(outMemPtr)) {
PlatformOutputStream out = outMem.output();
- PortableRawWriterEx writer = platformCtx.writer(out);
+ BinaryRawWriterEx writer = platformCtx.writer(out);
processInStreamOutStream(type, reader, writer);
@@ -148,12 +148,12 @@ public abstract class PlatformAbstractTarget implements PlatformTarget {
/** {@inheritDoc} */
@Override public void inObjectStreamOutStream(int type, Object arg, long inMemPtr, long outMemPtr) throws Exception {
try (PlatformMemory inMem = platformCtx.memory().get(inMemPtr)) {
- PortableRawReaderEx reader = platformCtx.reader(inMem);
+ BinaryRawReaderEx reader = platformCtx.reader(inMem);
try (PlatformMemory outMem = platformCtx.memory().get(outMemPtr)) {
PlatformOutputStream out = outMem.output();
- PortableRawWriterEx writer = platformCtx.writer(out);
+ BinaryRawWriterEx writer = platformCtx.writer(out);
processInObjectStreamOutStream(type, arg, reader, writer);
@@ -233,7 +233,7 @@ public abstract class PlatformAbstractTarget implements PlatformTarget {
* @return Result.
* @throws IgniteCheckedException In case of exception.
*/
- protected long processInStreamOutLong(int type, PortableRawReaderEx reader) throws IgniteCheckedException {
+ protected long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException {
return throwUnsupported(type);
}
@@ -245,7 +245,7 @@ public abstract class PlatformAbstractTarget implements PlatformTarget {
* @param writer Portable writer.
* @throws IgniteCheckedException In case of exception.
*/
- protected void processInStreamOutStream(int type, PortableRawReaderEx reader, PortableRawWriterEx writer)
+ protected void processInStreamOutStream(int type, BinaryRawReaderEx reader, BinaryRawWriterEx writer)
throws IgniteCheckedException {
throwUnsupported(type);
}
@@ -258,7 +258,7 @@ public abstract class PlatformAbstractTarget implements PlatformTarget {
* @return Result.
* @throws IgniteCheckedException In case of exception.
*/
- protected Object processInStreamOutObject(int type, PortableRawReaderEx reader) throws IgniteCheckedException {
+ protected Object processInStreamOutObject(int type, BinaryRawReaderEx reader) throws IgniteCheckedException {
return throwUnsupported(type);
}
@@ -271,8 +271,8 @@ public abstract class PlatformAbstractTarget implements PlatformTarget {
* @param writer Portable writer.
* @throws IgniteCheckedException In case of exception.
*/
- protected void processInObjectStreamOutStream(int type, @Nullable Object arg, PortableRawReaderEx reader,
- PortableRawWriterEx writer) throws IgniteCheckedException {
+ protected void processInObjectStreamOutStream(int type, @Nullable Object arg, BinaryRawReaderEx reader,
+ BinaryRawWriterEx writer) throws IgniteCheckedException {
throwUnsupported(type);
}
@@ -293,7 +293,7 @@ public abstract class PlatformAbstractTarget implements PlatformTarget {
* @param writer Portable writer.
* @throws IgniteCheckedException In case of exception.
*/
- protected void processOutStream(int type, PortableRawWriterEx writer) throws IgniteCheckedException {
+ protected void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
throwUnsupported(type);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContext.java
index a9b7d02..12eb36e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContext.java
@@ -21,8 +21,8 @@ import org.apache.ignite.cluster.ClusterMetrics;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.events.Event;
import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter;
import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryProcessor;
import org.apache.ignite.internal.processors.platform.cache.query.PlatformContinuousQuery;
@@ -71,7 +71,7 @@ public interface PlatformContext {
* @param mem Memory.
* @return Reader.
*/
- public PortableRawReaderEx reader(PlatformMemory mem);
+ public BinaryRawReaderEx reader(PlatformMemory mem);
/**
* Get memory reader.
@@ -79,7 +79,7 @@ public interface PlatformContext {
* @param in Input.
* @return Reader.
*/
- public PortableRawReaderEx reader(PlatformInputStream in);
+ public BinaryRawReaderEx reader(PlatformInputStream in);
/**
* Get memory writer.
@@ -87,7 +87,7 @@ public interface PlatformContext {
* @param mem Memory.
* @return Writer.
*/
- public PortableRawWriterEx writer(PlatformMemory mem);
+ public BinaryRawWriterEx writer(PlatformMemory mem);
/**
* Get memory writer.
@@ -95,7 +95,7 @@ public interface PlatformContext {
* @param out Output.
* @return Writer.
*/
- public PortableRawWriterEx writer(PlatformOutputStream out);
+ public BinaryRawWriterEx writer(PlatformOutputStream out);
/**
* Sends node info to native platform, if necessary.
@@ -110,7 +110,7 @@ public interface PlatformContext {
* @param writer Writer.
* @param node Node.
*/
- public void writeNode(PortableRawWriterEx writer, ClusterNode node);
+ public void writeNode(BinaryRawWriterEx writer, ClusterNode node);
/**
* Writes multiple node ids to a stream and sends node info to native platform, if necessary.
@@ -118,14 +118,14 @@ public interface PlatformContext {
* @param writer Writer.
* @param nodes Nodes.
*/
- public void writeNodes(PortableRawWriterEx writer, Collection<ClusterNode> nodes);
+ public void writeNodes(BinaryRawWriterEx writer, Collection<ClusterNode> nodes);
/**
* Process metadata from the platform.
*
* @param reader Reader.
*/
- public void processMetadata(PortableRawReaderEx reader);
+ public void processMetadata(BinaryRawReaderEx reader);
/**
* Write metadata for the given type ID.
@@ -133,14 +133,14 @@ public interface PlatformContext {
* @param writer Writer.
* @param typeId Type ID.
*/
- public void writeMetadata(PortableRawWriterEx writer, int typeId);
+ public void writeMetadata(BinaryRawWriterEx writer, int typeId);
/**
* Write all available metadata.
*
* @param writer Writer.
*/
- public void writeAllMetadata(PortableRawWriterEx writer);
+ public void writeAllMetadata(BinaryRawWriterEx writer);
/**
* Write cluster metrics.
@@ -148,7 +148,7 @@ public interface PlatformContext {
* @param writer Writer.
* @param metrics Metrics.
*/
- public void writeClusterMetrics(PortableRawWriterEx writer, @Nullable ClusterMetrics metrics);
+ public void writeClusterMetrics(BinaryRawWriterEx writer, @Nullable ClusterMetrics metrics);
/**
*
@@ -190,7 +190,7 @@ public interface PlatformContext {
* @param writer Writer.
* @param evt Event.
*/
- public void writeEvent(PortableRawWriterEx writer, Event evt);
+ public void writeEvent(BinaryRawWriterEx writer, Event evt);
/**
* Create local event filter.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
index 177a732..c513600 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
@@ -34,10 +34,10 @@ import org.apache.ignite.events.SwapSpaceEvent;
import org.apache.ignite.events.TaskEvent;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableMetaDataImpl;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
+import org.apache.ignite.internal.portable.BinaryMetaDataImpl;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter;
import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilterImpl;
import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryProcessor;
@@ -70,13 +70,12 @@ import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.T4;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.binary.BinaryType;
import org.jetbrains.annotations.Nullable;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Collections;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -105,7 +104,7 @@ public class PlatformContextImpl implements PlatformContext {
private final PlatformCallbackGateway gate;
/** Cache object processor. */
- private final CacheObjectPortableProcessorImpl cacheObjProc;
+ private final CacheObjectBinaryProcessorImpl cacheObjProc;
/** Node ids that has been sent to native platform. */
private final Set<UUID> sentNodes = Collections.newSetFromMap(new ConcurrentHashMap<UUID, Boolean>());
@@ -150,7 +149,7 @@ public class PlatformContextImpl implements PlatformContext {
this.gate = gate;
this.mem = mem;
- cacheObjProc = (CacheObjectPortableProcessorImpl)ctx.cacheObjects();
+ cacheObjProc = (CacheObjectBinaryProcessorImpl)ctx.cacheObjects();
marsh = cacheObjProc.marshaller();
}
@@ -171,22 +170,22 @@ public class PlatformContextImpl implements PlatformContext {
}
/** {@inheritDoc} */
- @Override public PortableRawReaderEx reader(PlatformMemory mem) {
+ @Override public BinaryRawReaderEx reader(PlatformMemory mem) {
return reader(mem.input());
}
/** {@inheritDoc} */
- @Override public PortableRawReaderEx reader(PlatformInputStream in) {
+ @Override public BinaryRawReaderEx reader(PlatformInputStream in) {
return marsh.reader(in);
}
/** {@inheritDoc} */
- @Override public PortableRawWriterEx writer(PlatformMemory mem) {
+ @Override public BinaryRawWriterEx writer(PlatformMemory mem) {
return writer(mem.output());
}
/** {@inheritDoc} */
- @Override public PortableRawWriterEx writer(PlatformOutputStream out) {
+ @Override public BinaryRawWriterEx writer(PlatformOutputStream out) {
return marsh.writer(out);
}
@@ -199,7 +198,7 @@ public class PlatformContextImpl implements PlatformContext {
try (PlatformMemory mem0 = mem.allocate()) {
PlatformOutputStream out = mem0.output();
- PortableRawWriterEx w = writer(out);
+ BinaryRawWriterEx w = writer(out);
w.writeUuid(node.id());
@@ -234,7 +233,7 @@ public class PlatformContextImpl implements PlatformContext {
}
/** {@inheritDoc} */
- @Override public void writeNode(PortableRawWriterEx writer, ClusterNode node) {
+ @Override public void writeNode(BinaryRawWriterEx writer, ClusterNode node) {
if (node == null) {
writer.writeUuid(null);
@@ -247,7 +246,7 @@ public class PlatformContextImpl implements PlatformContext {
}
/** {@inheritDoc} */
- @Override public void writeNodes(PortableRawWriterEx writer, Collection<ClusterNode> nodes) {
+ @Override public void writeNodes(BinaryRawWriterEx writer, Collection<ClusterNode> nodes) {
if (nodes == null) {
writer.writeInt(-1);
@@ -264,7 +263,7 @@ public class PlatformContextImpl implements PlatformContext {
}
/** {@inheritDoc} */
- @Override public void writeClusterMetrics(PortableRawWriterEx writer, @Nullable ClusterMetrics metrics) {
+ @Override public void writeClusterMetrics(BinaryRawWriterEx writer, @Nullable ClusterMetrics metrics) {
if (metrics == null)
writer.writeBoolean(false);
else {
@@ -340,17 +339,17 @@ public class PlatformContextImpl implements PlatformContext {
/** {@inheritDoc} */
@SuppressWarnings("ConstantConditions")
- @Override public void processMetadata(PortableRawReaderEx reader) {
+ @Override public void processMetadata(BinaryRawReaderEx reader) {
Collection<T4<Integer, String, String, Map<String, Integer>>> metas = PlatformUtils.readCollection(reader,
new PlatformReaderClosure<T4<Integer, String, String, Map<String, Integer>>>() {
- @Override public T4<Integer, String, String, Map<String, Integer>> read(PortableRawReaderEx reader) {
+ @Override public T4<Integer, String, String, Map<String, Integer>> read(BinaryRawReaderEx reader) {
int typeId = reader.readInt();
String typeName = reader.readString();
String affKey = reader.readString();
Map<String, Integer> fields = PlatformUtils.readMap(reader,
new PlatformReaderBiClosure<String, Integer>() {
- @Override public IgniteBiTuple<String, Integer> read(PortableRawReaderEx reader) {
+ @Override public IgniteBiTuple<String, Integer> read(BinaryRawReaderEx reader) {
return F.t(reader.readString(), reader.readInt());
}
});
@@ -365,17 +364,17 @@ public class PlatformContextImpl implements PlatformContext {
}
/** {@inheritDoc} */
- @Override public void writeMetadata(PortableRawWriterEx writer, int typeId) {
+ @Override public void writeMetadata(BinaryRawWriterEx writer, int typeId) {
writeMetadata0(writer, typeId, cacheObjProc.metadata(typeId));
}
/** {@inheritDoc} */
- @Override public void writeAllMetadata(PortableRawWriterEx writer) {
- Collection<PortableMetadata> metas = cacheObjProc.metadata();
+ @Override public void writeAllMetadata(BinaryRawWriterEx writer) {
+ Collection<BinaryType> metas = cacheObjProc.metadata();
writer.writeInt(metas.size());
- for (org.apache.ignite.portable.PortableMetadata m : metas)
+ for (BinaryType m : metas)
writeMetadata0(writer, cacheObjProc.typeId(m.typeName()), m);
}
@@ -386,18 +385,18 @@ public class PlatformContextImpl implements PlatformContext {
* @param typeId Type id.
* @param meta Metadata.
*/
- private void writeMetadata0(PortableRawWriterEx writer, int typeId, PortableMetadata meta) {
+ private void writeMetadata0(BinaryRawWriterEx writer, int typeId, BinaryType meta) {
if (meta == null)
writer.writeBoolean(false);
else {
writer.writeBoolean(true);
- Map<String, String> metaFields = ((PortableMetaDataImpl)meta).fields0();
+ Map<String, String> metaFields = ((BinaryMetaDataImpl)meta).fields0();
Map<String, Integer> fields = U.newHashMap(metaFields.size());
for (Map.Entry<String, String> metaField : metaFields.entrySet())
- fields.put(metaField.getKey(), CacheObjectPortableProcessorImpl.fieldTypeId(metaField.getValue()));
+ fields.put(metaField.getKey(), CacheObjectBinaryProcessorImpl.fieldTypeId(metaField.getValue()));
writer.writeInt(typeId);
writer.writeString(meta.typeName());
@@ -428,7 +427,7 @@ public class PlatformContextImpl implements PlatformContext {
}
/** {@inheritDoc} */
- @Override public void writeEvent(PortableRawWriterEx writer, Event evt) {
+ @Override public void writeEvent(BinaryRawWriterEx writer, Event evt) {
assert writer != null;
if (evt == null)
@@ -566,7 +565,7 @@ public class PlatformContextImpl implements PlatformContext {
* @param writer Writer.
* @param evt Event.
*/
- private void writeCommonEventData(PortableRawWriterEx writer, EventAdapter evt) {
+ private void writeCommonEventData(BinaryRawWriterEx writer, EventAdapter evt) {
PlatformUtils.writeIgniteUuid(writer, evt.id());
writer.writeLong(evt.localOrder());
writeNode(writer, evt.node());
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformExtendedException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformExtendedException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformExtendedException.java
index 825db6c..e8e7b9b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformExtendedException.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformExtendedException.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.processors.platform;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
/**
* Denotes an exception which has some data to be written in a special manner.
@@ -53,5 +53,5 @@ public abstract class PlatformExtendedException extends PlatformException {
*
* @param writer Writer.
*/
- public abstract void writeData(PortableRawWriterEx writer);
+ public abstract void writeData(BinaryRawWriterEx writer);
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
index d783928..27d7da3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
@@ -26,7 +26,7 @@ import org.apache.ignite.configuration.PlatformConfiguration;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteComputeImpl;
import org.apache.ignite.internal.cluster.ClusterGroupAdapter;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.GridProcessorAdapter;
import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
import org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl;
@@ -122,7 +122,7 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
try (PlatformMemory mem = platformCtx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = platformCtx.writer(out);
+ BinaryRawWriterEx writer = platformCtx.writer(out);
writer.writeString(ctx.gridName());
@@ -253,6 +253,8 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
throws IgniteCheckedException {
IgniteDataStreamer ldr = ctx.dataStream().dataStreamer(cacheName);
+ ldr.keepBinary(true);
+
return new PlatformDataStreamer(platformCtx, cacheName, (DataStreamerImpl)ldr, keepPortable);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
index ecdfc2c..6ec52d6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
@@ -28,8 +28,8 @@ import org.apache.ignite.cache.query.ScanQuery;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.cache.query.TextQuery;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.cache.CacheOperationContext;
import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException;
import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
@@ -44,6 +44,7 @@ import org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils;
import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
import org.apache.ignite.internal.util.GridConcurrentFactory;
import org.apache.ignite.internal.util.typedef.C1;
+import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteFuture;
import org.jetbrains.annotations.Nullable;
@@ -179,7 +180,7 @@ public class PlatformCache extends PlatformAbstractTarget {
/** Underlying JCache. */
private final IgniteCacheProxy cache;
- /** Whether this cache is created with "keepPortable" flag on the other side. */
+ /** Whether this cache is created with "keepBinary" flag on the other side. */
private final boolean keepPortable;
/** */
@@ -232,7 +233,7 @@ public class PlatformCache extends PlatformAbstractTarget {
if (keepPortable)
return this;
- return new PlatformCache(platformCtx, cache.withSkipStore(), true);
+ return new PlatformCache(platformCtx, cache.withKeepBinary(), true);
}
/**
@@ -276,7 +277,7 @@ public class PlatformCache extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected long processInStreamOutLong(int type, PortableRawReaderEx reader) throws IgniteCheckedException {
+ @Override protected long processInStreamOutLong(int type, BinaryRawReaderEx reader) throws IgniteCheckedException {
switch (type) {
case OP_PUT:
cache.put(reader.readObjectDetached(), reader.readObjectDetached());
@@ -372,7 +373,7 @@ public class PlatformCache extends PlatformAbstractTarget {
/**
* Loads cache via localLoadCache or loadCache.
*/
- private void loadCache0(PortableRawReaderEx reader, boolean loc) throws IgniteCheckedException {
+ private void loadCache0(BinaryRawReaderEx reader, boolean loc) throws IgniteCheckedException {
PlatformCacheEntryFilter filter = null;
Object pred = reader.readObjectDetached();
@@ -389,7 +390,7 @@ public class PlatformCache extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected Object processInStreamOutObject(int type, PortableRawReaderEx reader)
+ @Override protected Object processInStreamOutObject(int type, BinaryRawReaderEx reader)
throws IgniteCheckedException {
switch (type) {
case OP_QRY_SQL:
@@ -432,7 +433,7 @@ public class PlatformCache extends PlatformAbstractTarget {
* @param reader Reader.
* @return Arguments.
*/
- @Nullable private Object[] readQueryArgs(PortableRawReaderEx reader) {
+ @Nullable private Object[] readQueryArgs(BinaryRawReaderEx reader) {
int cnt = reader.readInt();
if (cnt > 0) {
@@ -448,7 +449,7 @@ public class PlatformCache extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected void processOutStream(int type, PortableRawWriterEx writer) throws IgniteCheckedException {
+ @Override protected void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
switch (type) {
case OP_GET_NAME:
writer.writeObject(cache.getName());
@@ -521,7 +522,7 @@ public class PlatformCache extends PlatformAbstractTarget {
/** {@inheritDoc} */
@SuppressWarnings({"IfMayBeConditional", "ConstantConditions"})
- @Override protected void processInStreamOutStream(int type, PortableRawReaderEx reader, PortableRawWriterEx writer)
+ @Override protected void processInStreamOutStream(int type, BinaryRawReaderEx reader, BinaryRawWriterEx writer)
throws IgniteCheckedException {
switch (type) {
case OP_GET: {
@@ -640,7 +641,7 @@ public class PlatformCache extends PlatformAbstractTarget {
* @param writer Writer.
* @param results Results.
*/
- private static void writeInvokeAllResult(PortableRawWriterEx writer, Map<Object, EntryProcessorResult> results) {
+ private static void writeInvokeAllResult(BinaryRawWriterEx writer, Map<Object, EntryProcessorResult> results) {
if (results == null) {
writer.writeInt(-1);
@@ -674,7 +675,7 @@ public class PlatformCache extends PlatformAbstractTarget {
* @param writer Writer.
* @param ex Exception.
*/
- private static void writeError(PortableRawWriterEx writer, Exception ex) {
+ private static void writeError(BinaryRawWriterEx writer, Exception ex) {
if (ex.getCause() instanceof PlatformNativeException)
writer.writeObjectDetached(((PlatformNativeException)ex.getCause()).cause());
else {
@@ -845,7 +846,7 @@ public class PlatformCache extends PlatformAbstractTarget {
/**
* Runs specified query.
*/
- private PlatformQueryCursor runQuery(PortableRawReaderEx reader, Query qry) throws IgniteCheckedException {
+ private PlatformQueryCursor runQuery(BinaryRawReaderEx reader, Query qry) throws IgniteCheckedException {
try {
QueryCursorEx cursor = (QueryCursorEx) cache.query(qry);
@@ -861,7 +862,7 @@ public class PlatformCache extends PlatformAbstractTarget {
/**
* Runs specified fields query.
*/
- private PlatformFieldsQueryCursor runFieldsQuery(PortableRawReaderEx reader, Query qry)
+ private PlatformFieldsQueryCursor runFieldsQuery(BinaryRawReaderEx reader, Query qry)
throws IgniteCheckedException {
try {
QueryCursorEx cursor = (QueryCursorEx) cache.query(qry);
@@ -877,7 +878,7 @@ public class PlatformCache extends PlatformAbstractTarget {
/**
* Reads the query of specified type.
*/
- private Query readInitialQuery(PortableRawReaderEx reader) throws IgniteCheckedException {
+ private Query readInitialQuery(BinaryRawReaderEx reader) throws IgniteCheckedException {
int typ = reader.readInt();
switch (typ) {
@@ -900,7 +901,7 @@ public class PlatformCache extends PlatformAbstractTarget {
/**
* Reads sql query.
*/
- private Query readSqlQuery(PortableRawReaderEx reader) {
+ private Query readSqlQuery(BinaryRawReaderEx reader) {
boolean loc = reader.readBoolean();
String sql = reader.readString();
String typ = reader.readString();
@@ -914,7 +915,7 @@ public class PlatformCache extends PlatformAbstractTarget {
/**
* Reads fields query.
*/
- private Query readFieldsQuery(PortableRawReaderEx reader) {
+ private Query readFieldsQuery(BinaryRawReaderEx reader) {
boolean loc = reader.readBoolean();
String sql = reader.readString();
final int pageSize = reader.readInt();
@@ -927,7 +928,7 @@ public class PlatformCache extends PlatformAbstractTarget {
/**
* Reads text query.
*/
- private Query readTextQuery(PortableRawReaderEx reader) {
+ private Query readTextQuery(BinaryRawReaderEx reader) {
boolean loc = reader.readBoolean();
String txt = reader.readString();
String typ = reader.readString();
@@ -939,7 +940,7 @@ public class PlatformCache extends PlatformAbstractTarget {
/**
* Reads scan query.
*/
- private Query readScanQuery(PortableRawReaderEx reader) {
+ private Query readScanQuery(BinaryRawReaderEx reader) {
boolean loc = reader.readBoolean();
final int pageSize = reader.readInt();
@@ -966,7 +967,7 @@ public class PlatformCache extends PlatformAbstractTarget {
*/
private static class GetAllWriter implements PlatformFutureUtils.Writer {
/** <inheritDoc /> */
- @Override public void write(PortableRawWriterEx writer, Object obj, Throwable err) {
+ @Override public void write(BinaryRawWriterEx writer, Object obj, Throwable err) {
assert obj instanceof Map;
PlatformUtils.writeNullableMap(writer, (Map) obj);
@@ -983,7 +984,7 @@ public class PlatformCache extends PlatformAbstractTarget {
*/
private static class EntryProcessorInvokeWriter implements PlatformFutureUtils.Writer {
/** <inheritDoc /> */
- @Override public void write(PortableRawWriterEx writer, Object obj, Throwable err) {
+ @Override public void write(BinaryRawWriterEx writer, Object obj, Throwable err) {
if (err == null) {
writer.writeBoolean(false); // No error.
@@ -1007,7 +1008,7 @@ public class PlatformCache extends PlatformAbstractTarget {
*/
private static class EntryProcessorInvokeAllWriter implements PlatformFutureUtils.Writer {
/** <inheritDoc /> */
- @Override public void write(PortableRawWriterEx writer, Object obj, Throwable err) {
+ @Override public void write(BinaryRawWriterEx writer, Object obj, Throwable err) {
writeInvokeAllResult(writer, (Map)obj);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryFilterImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryFilterImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryFilterImpl.java
index 5f8ec8f..6998451 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryFilterImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryFilterImpl.java
@@ -18,7 +18,7 @@
package org.apache.ignite.internal.processors.platform.cache;
import org.apache.ignite.Ignite;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractPredicate;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -58,7 +58,7 @@ public class PlatformCacheEntryFilterImpl extends PlatformAbstractPredicate impl
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(k);
writer.writeObject(v);
@@ -94,7 +94,7 @@ public class PlatformCacheEntryFilterImpl extends PlatformAbstractPredicate impl
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(pred);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryProcessorImpl.java
index f59a63f..ce06ec1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryProcessorImpl.java
@@ -26,8 +26,8 @@ import javax.cache.processor.MutableEntry;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.portable.PortableRawReaderEx;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.PlatformProcessor;
import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
@@ -119,7 +119,7 @@ public class PlatformCacheEntryProcessorImpl implements PlatformCacheEntryProces
try (PlatformMemory outMem = ctx.memory().allocate()) {
PlatformOutputStream out = outMem.output();
- PortableRawWriterEx writer = ctx.writer(out);
+ BinaryRawWriterEx writer = ctx.writer(out);
writeEntryAndProcessor(entry, writer);
@@ -132,7 +132,7 @@ public class PlatformCacheEntryProcessorImpl implements PlatformCacheEntryProces
in.synchronize();
- PortableRawReaderEx reader = ctx.reader(in);
+ BinaryRawReaderEx reader = ctx.reader(in);
return readResultAndUpdateEntry(ctx, entry, reader);
}
@@ -145,7 +145,7 @@ public class PlatformCacheEntryProcessorImpl implements PlatformCacheEntryProces
* @param entry Entry to process.
* @param writer Writer.
*/
- private void writeEntryAndProcessor(MutableEntry entry, PortableRawWriterEx writer) {
+ private void writeEntryAndProcessor(MutableEntry entry, BinaryRawWriterEx writer) {
writer.writeObject(entry.getKey());
writer.writeObject(entry.getValue());
@@ -170,7 +170,7 @@ public class PlatformCacheEntryProcessorImpl implements PlatformCacheEntryProces
* @throws javax.cache.processor.EntryProcessorException If processing has failed in user code.
*/
@SuppressWarnings("unchecked")
- private Object readResultAndUpdateEntry(PlatformContext ctx, MutableEntry entry, PortableRawReaderEx reader) {
+ private Object readResultAndUpdateEntry(PlatformContext ctx, MutableEntry entry, BinaryRawReaderEx reader) {
byte state = reader.readByte();
switch (state) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheIterator.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheIterator.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheIterator.java
index 78ca683..a5659af 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheIterator.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheIterator.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.platform.cache;
import java.util.Iterator;
import javax.cache.Cache;
import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
import org.apache.ignite.internal.processors.platform.PlatformContext;
@@ -47,7 +47,7 @@ public class PlatformCacheIterator extends PlatformAbstractTarget {
}
/** {@inheritDoc} */
- @Override protected void processOutStream(int type, PortableRawWriterEx writer) throws IgniteCheckedException {
+ @Override protected void processOutStream(int type, BinaryRawWriterEx writer) throws IgniteCheckedException {
switch (type) {
case OP_NEXT:
if (iter.hasNext()) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCachePartialUpdateException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCachePartialUpdateException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCachePartialUpdateException.java
index ef17a06..8314e3a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCachePartialUpdateException.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCachePartialUpdateException.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.processors.platform.cache;
-import org.apache.ignite.internal.portable.PortableRawWriterEx;
+import org.apache.ignite.internal.portable.BinaryRawWriterEx;
import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException;
import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.processors.platform.PlatformExtendedException;
@@ -49,7 +49,7 @@ public class PlatformCachePartialUpdateException extends PlatformExtendedExcepti
}
/** {@inheritDoc} */
- @Override public void writeData(PortableRawWriterEx writer) {
+ @Override public void writeData(BinaryRawWriterEx writer) {
Collection keys = ((CachePartialUpdateCheckedException)getCause()).failedKeys();
writer.writeBoolean(keepPortable);
[15/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index 1f4852c..e244aa5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -1710,7 +1710,7 @@ public class GridCacheContext<K, V> implements Externalizable {
public boolean keepPortable() {
CacheOperationContext opCtx = operationContextPerCall();
- return opCtx != null && opCtx.isKeepPortable();
+ return opCtx != null && opCtx.isKeepBinary();
}
/**
@@ -1752,7 +1752,7 @@ public class GridCacheContext<K, V> implements Externalizable {
}
/**
- * Unwraps object for portables.
+ * Unwraps object for binary.
*
* @param o Object to unwrap.
* @param keepPortable Keep portable flag.
@@ -1855,15 +1855,9 @@ public class GridCacheContext<K, V> implements Externalizable {
assert val != null || skipVals;
if (!keepCacheObjects) {
- Object key0 = key.value(cacheObjCtx, false);
- Object val0 = skipVals ? true : val.value(cacheObjCtx, cpy);
+ Object key0 = unwrapPortableIfNeeded(key, !deserializePortable);
- if (deserializePortable) {
- key0 = unwrapPortableIfNeeded(key0, false);
-
- if (!skipVals)
- val0 = unwrapPortableIfNeeded(val0, false);
- }
+ Object val0 = skipVals ? true : unwrapPortableIfNeeded(val, !deserializePortable);
assert key0 != null : key;
assert val0 != null : val;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
index 50b01c8..81914bb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryEx.java
@@ -303,7 +303,8 @@ public interface GridCacheEntryEx {
UUID subjId,
Object transformClo,
String taskName,
- @Nullable IgniteCacheExpiryPolicy expiryPlc)
+ @Nullable IgniteCacheExpiryPolicy expiryPlc,
+ boolean keepBinary)
throws IgniteCheckedException, GridCacheEntryRemovedException;
/**
@@ -329,7 +330,8 @@ public interface GridCacheEntryEx {
UUID subjId,
Object transformClo,
String taskName,
- @Nullable IgniteCacheExpiryPolicy expiryPlc)
+ @Nullable IgniteCacheExpiryPolicy expiryPlc,
+ boolean keepBinary)
throws IgniteCheckedException, GridCacheEntryRemovedException;
/**
@@ -375,6 +377,7 @@ public interface GridCacheEntryEx {
long ttl,
boolean evt,
boolean metrics,
+ boolean keepPortable,
AffinityTopologyVersion topVer,
CacheEntryPredicate[] filter,
GridDrType drType,
@@ -413,6 +416,7 @@ public interface GridCacheEntryEx {
boolean retval,
boolean evt,
boolean metrics,
+ boolean keepPortable,
AffinityTopologyVersion topVer,
CacheEntryPredicate[] filter,
GridDrType drType,
@@ -466,6 +470,7 @@ public interface GridCacheEntryEx {
boolean writeThrough,
boolean readThrough,
boolean retval,
+ boolean keepPortable,
@Nullable IgniteCacheExpiryPolicy expiryPlc,
boolean evt,
boolean metrics,
@@ -512,6 +517,7 @@ public interface GridCacheEntryEx {
boolean writeThrough,
boolean readThrough,
boolean retval,
+ boolean keepPortable,
@Nullable ExpiryPolicy expiryPlc,
boolean evt,
boolean metrics,
@@ -549,8 +555,9 @@ public interface GridCacheEntryEx {
public boolean tmLock(IgniteInternalTx tx,
long timeout,
@Nullable GridCacheVersion serOrder,
- @Nullable GridCacheVersion serReadVer)
- throws GridCacheEntryRemovedException, GridDistributedLockCancelledException;
+ @Nullable GridCacheVersion serReadVer,
+ boolean keepBinary
+ ) throws GridCacheEntryRemovedException, GridDistributedLockCancelledException;
/**
* Unlocks acquired lock.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
index 751c316..afca43b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
@@ -26,7 +26,6 @@ import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener;
import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.X;
-import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.LT;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteUuid;
@@ -84,7 +83,8 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
boolean hasOldVal,
UUID subjId,
String cloClsName,
- String taskName)
+ String taskName,
+ boolean keepBinary)
{
addEvent(part,
key,
@@ -98,7 +98,8 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
hasOldVal,
subjId,
cloClsName,
- taskName);
+ taskName,
+ keepBinary);
}
/**
@@ -118,7 +119,8 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
false,
null,
null,
- null);
+ null,
+ false);
}
/**
@@ -148,7 +150,8 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
boolean hasOldVal,
UUID subjId,
String cloClsName,
- String taskName)
+ String taskName,
+ boolean keepPortable)
{
addEvent(part,
key,
@@ -161,7 +164,8 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
hasOldVal,
subjId,
cloClsName,
- taskName);
+ taskName,
+ keepPortable);
}
/**
@@ -189,7 +193,8 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
boolean hasOldVal,
UUID subjId,
String cloClsName,
- String taskName)
+ String taskName,
+ boolean keepBinary)
{
IgniteInternalTx tx = owner == null ? null : cctx.tm().tx(owner.version());
@@ -205,7 +210,8 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
hasOldVal,
subjId,
cloClsName,
- taskName);
+ taskName,
+ keepBinary);
}
/**
@@ -236,7 +242,8 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
boolean hasOldVal,
UUID subjId,
@Nullable String cloClsName,
- @Nullable String taskName
+ @Nullable String taskName,
+ boolean keepPortable
) {
assert key != null || type == EVT_CACHE_STARTED || type == EVT_CACHE_STOPPED;
@@ -262,12 +269,12 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
type,
part,
cctx.isNear(),
- key == null ? null : key.value(cctx.cacheObjectContext(), false),
+ cctx.cacheObjectContext().unwrapPortableIfNeeded(key, keepPortable, false),
xid,
lockId,
- CU.value(newVal, cctx, false),
+ cctx.cacheObjectContext().unwrapPortableIfNeeded(newVal, keepPortable, false),
hasNewVal,
- CU.value(oldVal, cctx, false),
+ cctx.cacheObjectContext().unwrapPortableIfNeeded(oldVal, keepPortable, false),
hasOldVal,
subjId,
cloClsName,
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
index 9a89fee..845e204 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
@@ -723,7 +723,7 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter {
if (recordable)
cctx.events().addEvent(entry.partition(), entry.key(), cctx.nodeId(), (IgniteUuid)null, null,
- EVT_CACHE_ENTRY_EVICTED, null, false, oldVal, hasVal, null, null, null);
+ EVT_CACHE_ENTRY_EVICTED, null, false, oldVal, hasVal, null, null, null, false);
if (log.isDebugEnabled())
log.debug("Entry was evicted [entry=" + entry + ", localNode=" + cctx.nodeId() + ']');
@@ -1043,7 +1043,8 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter {
if (recordable)
cctx.events().addEvent(entry.partition(), entry.key(), cctx.nodeId(), (IgniteUuid)null, null,
- EVT_CACHE_ENTRY_EVICTED, null, false, entry.rawGet(), entry.hasValue(), null, null, null);
+ EVT_CACHE_ENTRY_EVICTED, null, false, entry.rawGet(), entry.hasValue(), null, null, null,
+ false);
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index 2111594..a5762ad 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -234,7 +234,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (cctx.kernalContext().config().isPeerClassLoadingEnabled()) {
Object val0 = null;
- if (val != null && val.type() != CacheObject.TYPE_BYTE_ARR) {
+ if (val != null && val.cacheObjectType() != CacheObject.TYPE_BYTE_ARR) {
val0 = cctx.cacheObjects().unmarshal(cctx.cacheObjectContext(),
val.valueBytes(cctx.cacheObjectContext()), cctx.deploy().globalLoader());
@@ -253,7 +253,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
assert mem != null;
if (val != null) {
- byte type = val.type();
+ byte type = val.cacheObjectType();
offHeapPointer(mem.putOffHeap(offHeapPointer(), val.valueBytes(cctx.cacheObjectContext()), type));
}
@@ -625,7 +625,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
try {
byte[] bytes = val.valueBytes(cctx.cacheObjectContext());
- return new IgniteBiTuple<>(bytes, val.type());
+ return new IgniteBiTuple<>(bytes, val.cacheObjectType());
}
catch (IgniteCheckedException e) {
throw new IgniteException(e);
@@ -674,7 +674,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
UUID subjId,
Object transformClo,
String taskName,
- @Nullable IgniteCacheExpiryPolicy expirePlc)
+ @Nullable IgniteCacheExpiryPolicy expirePlc,
+ boolean keepBinary)
throws IgniteCheckedException, GridCacheEntryRemovedException {
return (CacheObject)innerGet0(tx,
readSwap,
@@ -687,7 +688,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
transformClo,
taskName,
expirePlc,
- false);
+ false,
+ keepBinary);
}
/** {@inheritDoc} */
@@ -700,7 +702,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
UUID subjId,
Object transformClo,
String taskName,
- @Nullable IgniteCacheExpiryPolicy expiryPlc)
+ @Nullable IgniteCacheExpiryPolicy expiryPlc,
+ boolean keepBinary)
throws IgniteCheckedException, GridCacheEntryRemovedException {
return (T2<CacheObject, GridCacheVersion>)innerGet0(tx,
readSwap,
@@ -713,7 +716,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
transformClo,
taskName,
expiryPlc,
- true);
+ true,
+ keepBinary);
}
/** {@inheritDoc} */
@@ -729,8 +733,9 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
Object transformClo,
String taskName,
@Nullable IgniteCacheExpiryPolicy expiryPlc,
- boolean retVer)
- throws IgniteCheckedException, GridCacheEntryRemovedException {
+ boolean retVer,
+ boolean keepBinary
+ ) throws IgniteCheckedException, GridCacheEntryRemovedException {
assert !(retVer && readThrough);
// Disable read-through if there is no store.
@@ -854,7 +859,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
expiredVal != null || hasOldBytes,
subjId,
null,
- taskName);
+ taskName,
+ keepBinary);
}
cctx.continuousQueries().onEntryExpired(this, key, expiredVal);
@@ -864,9 +870,20 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
}
if (evt && !expired && cctx.events().isRecordable(EVT_CACHE_OBJECT_READ)) {
- cctx.events().addEvent(partition(), key, tx, owner, EVT_CACHE_OBJECT_READ, ret, ret != null, old,
- hasOldBytes || old != null, subjId,
- transformClo != null ? transformClo.getClass().getName() : null, taskName);
+ cctx.events().addEvent(
+ partition(),
+ key,
+ tx,
+ owner,
+ EVT_CACHE_OBJECT_READ,
+ ret,
+ ret != null,
+ old,
+ hasOldBytes || old != null,
+ subjId,
+ transformClo != null ? transformClo.getClass().getName() : null,
+ taskName,
+ keepBinary);
// No more notifications.
evt = false;
@@ -941,9 +958,20 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
}
if (evt && cctx.events().isRecordable(EVT_CACHE_OBJECT_READ))
- cctx.events().addEvent(partition(), key, tx, owner, EVT_CACHE_OBJECT_READ, ret, ret != null,
- old, hasOldBytes, subjId, transformClo != null ? transformClo.getClass().getName() : null,
- taskName);
+ cctx.events().addEvent(
+ partition(),
+ key,
+ tx,
+ owner,
+ EVT_CACHE_OBJECT_READ,
+ ret,
+ ret != null,
+ old,
+ hasOldBytes,
+ subjId,
+ transformClo != null ? transformClo.getClass().getName() : null,
+ taskName,
+ keepBinary);
}
}
@@ -1052,6 +1080,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
long ttl,
boolean evt,
boolean metrics,
+ boolean keepPortable,
AffinityTopologyVersion topVer,
CacheEntryPredicate[] filter,
GridDrType drType,
@@ -1106,9 +1135,9 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (intercept) {
val0 = CU.value(val, cctx, false);
- CacheLazyEntry e = new CacheLazyEntry(cctx, key, old);
+ CacheLazyEntry e = new CacheLazyEntry(cctx, key, old, keepPortable);
- Object interceptorVal = cctx.config().getInterceptor().onBeforePut(new CacheLazyEntry(cctx, key, old),
+ Object interceptorVal = cctx.config().getInterceptor().onBeforePut(new CacheLazyEntry(cctx, key, old, keepPortable),
val0);
key0 = e.key();
@@ -1175,13 +1204,14 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
val != null,
evtOld,
evtOld != null || hasValueUnlocked(),
- subjId, null, taskName);
+ subjId, null, taskName,
+ keepPortable);
}
if (cctx.isLocal() || cctx.isReplicated() || (tx != null && tx.local() && !isNear()))
cctx.continuousQueries().onEntryUpdated(this, key, val, old, false);
- cctx.dataStructures().onEntryUpdated(key, false);
+ cctx.dataStructures().onEntryUpdated(key, false, keepPortable);
}
if (log.isDebugEnabled())
@@ -1193,7 +1223,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
cctx.store().put(tx, keyValue(false), CU.value(val, cctx, false), newVer);
if (intercept)
- cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(cctx, key, key0, val, val0));
+ cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(cctx, key, key0, val, val0, keepPortable));
return valid ? new GridCacheUpdateTxResult(true, retval ? old : null) :
new GridCacheUpdateTxResult(false, null);
@@ -1216,6 +1246,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
boolean retval,
boolean evt,
boolean metrics,
+ boolean keepPortable,
AffinityTopologyVersion topVer,
CacheEntryPredicate[] filter,
GridDrType drType,
@@ -1270,7 +1301,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
old = (retval || intercept) ? rawGetOrUnmarshalUnlocked(!retval) : val;
if (intercept) {
- entry0 = new CacheLazyEntry(cctx, key, old);
+ entry0 = new CacheLazyEntry(cctx, key, old, keepPortable);
interceptRes = cctx.config().getInterceptor().onBeforeRemove(entry0);
@@ -1342,13 +1373,14 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
evtOld != null || hasValueUnlocked(),
subjId,
null,
- taskName);
+ taskName,
+ keepPortable);
}
if (cctx.isLocal() || cctx.isReplicated() || (tx != null && tx.local() && !isNear()))
cctx.continuousQueries().onEntryUpdated(this, key, null, old, false);
- cctx.dataStructures().onEntryUpdated(key, true);
+ cctx.dataStructures().onEntryUpdated(key, true, keepPortable);
}
// Persist outside of synchronization. The correctness of the
@@ -1412,6 +1444,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
boolean writeThrough,
boolean readThrough,
boolean retval,
+ boolean keepBinary,
@Nullable ExpiryPolicy expiryPlc,
boolean evt,
boolean metrics,
@@ -1513,7 +1546,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
assert entryProcessor != null;
- CacheInvokeEntry<Object, Object> entry = new CacheInvokeEntry<>(cctx, key, old, version());
+ CacheInvokeEntry<Object, Object> entry = new CacheInvokeEntry<>(cctx, key, old, version(), keepBinary);
try {
Object computed = entryProcessor.process(entry, invokeArgs);
@@ -1554,7 +1587,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (op == GridCacheOperation.UPDATE) {
updated0 = value(updated0, updated, false);
- e = new CacheLazyEntry(cctx, key, key0, old, old0);
+ e = new CacheLazyEntry(cctx, key, key0, old, old0, keepBinary);
Object interceptorVal = cctx.config().getInterceptor().onBeforePut(e, updated0);
@@ -1567,7 +1600,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
}
}
else {
- e = new CacheLazyEntry(cctx, key, key0, old, old0);
+ e = new CacheLazyEntry(cctx, key, key0, old, old0, keepBinary);
interceptorRes = cctx.config().getInterceptor().onBeforeRemove(e);
@@ -1629,7 +1662,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
cctx.events().addEvent(partition(), key, cctx.localNodeId(), null,
(GridCacheVersion)null, EVT_CACHE_OBJECT_READ, evtOld, evtOld != null || hadVal, evtOld,
- evtOld != null || hadVal, subjId, transformCloClsName, taskName);
+ evtOld != null || hadVal, subjId, transformCloClsName, taskName, keepBinary);
}
if (cctx.events().isRecordable(EVT_CACHE_OBJECT_PUT)) {
@@ -1638,7 +1671,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
cctx.events().addEvent(partition(), key, cctx.localNodeId(), null,
(GridCacheVersion)null, EVT_CACHE_OBJECT_PUT, updated, updated != null, evtOld,
- evtOld != null || hadVal, subjId, null, taskName);
+ evtOld != null || hadVal, subjId, null, taskName, keepBinary);
}
}
}
@@ -1670,7 +1703,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (transformCloClsName != null && cctx.events().isRecordable(EVT_CACHE_OBJECT_READ))
cctx.events().addEvent(partition(), key, cctx.localNodeId(), null,
(GridCacheVersion)null, EVT_CACHE_OBJECT_READ, evtOld, evtOld != null || hadVal, evtOld,
- evtOld != null || hadVal, subjId, transformCloClsName, taskName);
+ evtOld != null || hadVal, subjId, transformCloClsName, taskName, keepBinary);
if (cctx.events().isRecordable(EVT_CACHE_OBJECT_REMOVED)) {
if (evtOld == null)
@@ -1678,7 +1711,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
cctx.events().addEvent(partition(), key, cctx.localNodeId(), null, (GridCacheVersion)null,
EVT_CACHE_OBJECT_REMOVED, null, false, evtOld, evtOld != null || hadVal, subjId, null,
- taskName);
+ taskName, keepBinary);
}
}
@@ -1690,18 +1723,20 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
cctx.continuousQueries().onEntryUpdated(this, key, val, old, false);
- cctx.dataStructures().onEntryUpdated(key, op == GridCacheOperation.DELETE);
+ cctx.dataStructures().onEntryUpdated(key, op == GridCacheOperation.DELETE, keepBinary);
if (intercept) {
if (op == GridCacheOperation.UPDATE)
- cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(cctx, key, key0, updated, updated0));
+ cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(cctx, key, key0, updated, updated0, keepBinary));
else
- cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(cctx, key, key0, old, old0));
+ cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(cctx, key, key0, old, old0, keepBinary));
}
}
return new GridTuple3<>(res,
- cctx.unwrapTemporary(interceptorRes != null ? interceptorRes.get2() : CU.value(old, cctx, false)),
+ cctx.unwrapTemporary(interceptorRes != null ?
+ interceptorRes.get2() :
+ cctx.cacheObjectContext().unwrapPortableIfNeeded(old, keepBinary, false)),
invokeRes);
}
@@ -1717,6 +1752,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
boolean writeThrough,
boolean readThrough,
boolean retval,
+ boolean keepPortable,
@Nullable IgniteCacheExpiryPolicy expiryPlc,
boolean evt,
boolean metrics,
@@ -1784,7 +1820,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
oldVal = rawGetOrUnmarshalUnlocked(true);
- CacheInvokeEntry<Object, Object> entry = new CacheInvokeEntry(cctx, key, oldVal, version());
+ CacheInvokeEntry<Object, Object> entry = new CacheInvokeEntry(cctx, key, oldVal, version(), keepPortable);
try {
Object computed = entryProcessor.process(entry, invokeArgs);
@@ -2009,7 +2045,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
EntryProcessor<Object, Object, ?> entryProcessor = (EntryProcessor<Object, Object, ?>)writeObj;
- CacheInvokeEntry<Object, Object> entry = new CacheInvokeEntry(cctx, key, oldVal, version());
+ CacheInvokeEntry<Object, Object> entry = new CacheInvokeEntry(cctx, key, oldVal, version(), keepPortable);
try {
Object computed = entryProcessor.process(entry, invokeArgs);
@@ -2133,7 +2169,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
updated0 = value(updated0, updated, false);
Object interceptorVal = cctx.config().getInterceptor()
- .onBeforePut(new CacheLazyEntry(cctx, key, key0, oldVal, old0), updated0);
+ .onBeforePut(new CacheLazyEntry(cctx, key, key0, oldVal, old0, keepPortable), updated0);
if (interceptorVal == null)
return new GridCacheUpdateAtomicResult(false,
@@ -2155,7 +2191,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
// Try write-through.
if (writeThrough)
// Must persist inside synchronization in non-tx mode.
- cctx.store().put(null, keyValue(false), CU.value(updated, cctx, false), newVer);
+ cctx.store().put(null, key, updated, newVer);
if (!hadVal) {
boolean new0 = isNew();
@@ -2193,7 +2229,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
cctx.events().addEvent(partition(), key, evtNodeId, null,
newVer, EVT_CACHE_OBJECT_READ, evtOld, evtOld != null || hadVal, evtOld,
- evtOld != null || hadVal, subjId, transformClo.getClass().getName(), taskName);
+ evtOld != null || hadVal, subjId, transformClo.getClass().getName(), taskName,
+ keepPortable);
}
if (newVer != null && cctx.events().isRecordable(EVT_CACHE_OBJECT_PUT)) {
@@ -2202,14 +2239,14 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
cctx.events().addEvent(partition(), key, evtNodeId, null,
newVer, EVT_CACHE_OBJECT_PUT, updated, updated != null, evtOld,
- evtOld != null || hadVal, subjId, null, taskName);
+ evtOld != null || hadVal, subjId, null, taskName, keepPortable);
}
}
}
else {
if (intercept) {
interceptRes = cctx.config().getInterceptor().onBeforeRemove(new CacheLazyEntry(cctx, key, key0,
- oldVal, old0));
+ oldVal, old0, keepPortable));
if (cctx.cancelRemove(interceptRes))
return new GridCacheUpdateAtomicResult(false,
@@ -2225,7 +2262,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (writeThrough)
// Must persist inside synchronization in non-tx mode.
- cctx.store().remove(null, keyValue(false));
+ cctx.store().remove(null, key);
if (oldVal == null)
oldVal = saveValueForIndexUnlocked();
@@ -2282,7 +2319,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
cctx.events().addEvent(partition(), key, evtNodeId, null,
newVer, EVT_CACHE_OBJECT_READ, evtOld, evtOld != null || hadVal, evtOld,
- evtOld != null || hadVal, subjId, transformClo.getClass().getName(), taskName);
+ evtOld != null || hadVal, subjId, transformClo.getClass().getName(), taskName,
+ keepPortable);
}
if (newVer != null && cctx.events().isRecordable(EVT_CACHE_OBJECT_REMOVED)) {
@@ -2291,7 +2329,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
cctx.events().addEvent(partition(), key, evtNodeId, null, newVer,
EVT_CACHE_OBJECT_REMOVED, null, false, evtOld, evtOld != null || hadVal,
- subjId, null, taskName);
+ subjId, null, taskName, keepPortable);
}
}
@@ -2304,13 +2342,13 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (cctx.isReplicated() || primary)
cctx.continuousQueries().onEntryUpdated(this, key, val, oldVal, false);
- cctx.dataStructures().onEntryUpdated(key, op == GridCacheOperation.DELETE);
+ cctx.dataStructures().onEntryUpdated(key, op == GridCacheOperation.DELETE, keepPortable);
if (intercept) {
if (op == GridCacheOperation.UPDATE)
- cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(cctx, key, key0, updated, updated0));
+ cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(cctx, key, key0, updated, updated0, keepPortable));
else
- cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(cctx, key, key0, oldVal, old0));
+ cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(cctx, key, key0, oldVal, old0, keepPortable));
if (interceptRes != null)
oldVal = cctx.toCacheObject(cctx.unwrapTemporary(interceptRes.get2()));
@@ -3153,7 +3191,7 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
if (cctx.isLocal() || cctx.isReplicated() || cctx.affinity().primary(cctx.localNode(), key, topVer))
cctx.continuousQueries().onEntryUpdated(this, key, val, null, preload);
- cctx.dataStructures().onEntryUpdated(key, false);
+ cctx.dataStructures().onEntryUpdated(key, false, true);
}
if (cctx.store().isLocal()) {
@@ -3486,7 +3524,8 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
expiredVal != null || hasOldBytes,
null,
null,
- null);
+ null,
+ true);
}
cctx.continuousQueries().onEntryExpired(this, key, expiredVal);
@@ -3715,7 +3754,9 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
/** {@inheritDoc} */
@Override public <K, V> Cache.Entry<K, V> wrapLazyValue() {
- return new LazyValueEntry<>(key);
+ CacheOperationContext opCtx = cctx.operationContextPerCall();
+
+ return new LazyValueEntry<>(key, opCtx != null && opCtx.isKeepBinary());
}
/** {@inheritDoc} */
@@ -4196,22 +4237,26 @@ public abstract class GridCacheMapEntry extends GridMetadataAwareAdapter impleme
/** */
private final KeyCacheObject key;
+ /** */
+ private boolean keepBinary;
+
/**
* @param key Key.
*/
- private LazyValueEntry(KeyCacheObject key) {
+ private LazyValueEntry(KeyCacheObject key, boolean keepBinary) {
this.key = key;
+ this.keepBinary = keepBinary;
}
/** {@inheritDoc} */
@Override public K getKey() {
- return key.value(cctx.cacheObjectContext(), false);
+ return (K)cctx.cacheObjectContext().unwrapPortableIfNeeded(key, keepBinary);
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public V getValue() {
- return CU.value(peekVisibleValue(), cctx, true);
+ return (V)cctx.cacheObjectContext().unwrapPortableIfNeeded(peekVisibleValue(), keepBinary);
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
index cd779f2..cca6d6a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
@@ -229,12 +229,12 @@ public class GridCacheProxyImpl<K, V> implements IgniteInternalCache<K, V>, Exte
/** {@inheritDoc} */
@Override public <K1, V1> GridCacheProxyImpl<K1, V1> keepPortable() {
- if (opCtx != null && opCtx.isKeepPortable())
+ if (opCtx != null && opCtx.isKeepBinary())
return (GridCacheProxyImpl<K1, V1>)this;
return new GridCacheProxyImpl<>((GridCacheContext<K1, V1>)ctx,
(GridCacheAdapter<K1, V1>)delegate,
- opCtx != null ? opCtx.keepPortable() : new CacheOperationContext(false, null, true, null, false));
+ opCtx != null ? opCtx.keepBinary() : new CacheOperationContext(false, null, true, null, false));
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java
index 22b9f8d..2d179fa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java
@@ -101,13 +101,13 @@ public class GridCacheReturn implements Externalizable, Message {
* @param v Value.
* @param success Success flag.
*/
- public GridCacheReturn(GridCacheContext cctx, boolean loc, Object v, boolean success) {
+ public GridCacheReturn(GridCacheContext cctx, boolean loc, boolean keepBinary, Object v, boolean success) {
this.loc = loc;
this.success = success;
if (v != null) {
if (v instanceof CacheObject)
- initValue(cctx, (CacheObject)v);
+ initValue(cctx, (CacheObject)v, keepBinary);
else {
assert loc;
@@ -152,8 +152,8 @@ public class GridCacheReturn implements Externalizable, Message {
* @param v Value.
* @return This instance for chaining.
*/
- public GridCacheReturn value(GridCacheContext cctx, CacheObject v) {
- initValue(cctx, v);
+ public GridCacheReturn value(GridCacheContext cctx, CacheObject v, boolean keepBinary) {
+ initValue(cctx, v, keepBinary);
return this;
}
@@ -171,10 +171,15 @@ public class GridCacheReturn implements Externalizable, Message {
* @param success Success flag to set.
* @return This instance for chaining.
*/
- public GridCacheReturn set(GridCacheContext cctx, @Nullable CacheObject cacheObj, boolean success) {
+ public GridCacheReturn set(
+ GridCacheContext cctx,
+ @Nullable CacheObject cacheObj,
+ boolean success,
+ boolean keepBinary
+ ) {
this.success = success;
- initValue(cctx, cacheObj);
+ initValue(cctx, cacheObj, keepBinary);
return this;
}
@@ -183,9 +188,9 @@ public class GridCacheReturn implements Externalizable, Message {
* @param cctx Cache context.
* @param cacheObj Cache object.
*/
- private void initValue(GridCacheContext cctx, @Nullable CacheObject cacheObj) {
+ private void initValue(GridCacheContext cctx, @Nullable CacheObject cacheObj, boolean keepBinary) {
if (loc)
- v = CU.value(cacheObj, cctx, true);
+ v = cctx.cacheObjectContext().unwrapPortableIfNeeded(cacheObj, keepBinary, true);
else {
assert cacheId == 0 || cacheId == cctx.cacheId();
@@ -313,7 +318,7 @@ public class GridCacheReturn implements Externalizable, Message {
if (cacheObj != null) {
cacheObj.finishUnmarshal(ctx.cacheObjectContext(), ldr);
- v = cacheObj.value(ctx.cacheObjectContext(), false);
+ v = ctx.cacheObjectContext().unwrapPortableIfNeeded(cacheObj, true, false);
}
if (invokeRes && invokeResCol != null) {
@@ -324,10 +329,10 @@ public class GridCacheReturn implements Externalizable, Message {
for (CacheInvokeDirectResult res : invokeResCol) {
CacheInvokeResult<?> res0 = res.error() == null ?
- CacheInvokeResult.fromResult(CU.value(res.result(), ctx, false)) :
+ CacheInvokeResult.fromResult(ctx.cacheObjectContext().unwrapPortableIfNeeded(res.result(), true, false)) :
CacheInvokeResult.fromError(res.error());
- map0.put(res.key().value(ctx.cacheObjectContext(), false), res0);
+ map0.put(ctx.cacheObjectContext().unwrapPortableIfNeeded(res.key(), true, false), res0);
}
v = map0;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index b9b7a30..37b5e15 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -550,7 +550,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
assert key != null;
byte[] valBytes = swapMgr.read(spaceName,
- new SwapKey(key.value(cctx.cacheObjectContext(), false), part, key.valueBytes(cctx.cacheObjectContext())),
+ new SwapKey(key, part, key.valueBytes(cctx.cacheObjectContext())),
cctx.deploy().globalLoader());
if (cctx.config().isStatisticsEnabled())
@@ -616,7 +616,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
assert key != null;
byte[] bytes = swapMgr.read(spaceName,
- new SwapKey(key.value(cctx.cacheObjectContext(), false), part, keyBytes),
+ new SwapKey(key, part, keyBytes),
cctx.deploy().globalLoader());
if (bytes == null && lsnr != null)
@@ -667,7 +667,8 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
true,
null,
null,
- null);
+ null,
+ false);
return entry;
}
@@ -690,7 +691,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
final GridTuple<GridCacheSwapEntry> t = F.t1();
final GridTuple<IgniteCheckedException> err = F.t1();
- SwapKey swapKey = new SwapKey(key.value(cctx.cacheObjectContext(), false),
+ SwapKey swapKey = new SwapKey(key,
part,
key.valueBytes(cctx.cacheObjectContext()));
@@ -731,7 +732,8 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
true,
null,
null,
- null);
+ null,
+ false);
}
if (cctx.config().isStatisticsEnabled())
@@ -916,7 +918,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
if (cctx.events().isRecordable(EVT_CACHE_OBJECT_FROM_OFFHEAP))
cctx.events().addEvent(part, key, cctx.nodeId(), (IgniteUuid)null, null,
- EVT_CACHE_OBJECT_FROM_OFFHEAP, null, false, null, true, null, null, null);
+ EVT_CACHE_OBJECT_FROM_OFFHEAP, null, false, null, true, null, null, null, false);
GridCacheBatchSwapEntry unswapped = new GridCacheBatchSwapEntry(key,
part,
@@ -938,7 +940,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
if (unprocessedKeys == null)
unprocessedKeys = new ArrayList<>(keys.size());
- SwapKey swapKey = new SwapKey(key.value(cctx.cacheObjectContext(), false),
+ SwapKey swapKey = new SwapKey(key,
cctx.affinity().partition(key),
key.valueBytes(cctx.cacheObjectContext()));
@@ -953,7 +955,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
unprocessedKeys = new ArrayList<>(keys.size());
for (KeyCacheObject key : keys) {
- SwapKey swapKey = new SwapKey(key.value(cctx.cacheObjectContext(), false),
+ SwapKey swapKey = new SwapKey(key,
cctx.affinity().partition(key),
key.valueBytes(cctx.cacheObjectContext()));
@@ -1021,7 +1023,8 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
true,
null,
null,
- null);
+ null,
+ false);
}
if (cctx.config().isStatisticsEnabled())
@@ -1220,7 +1223,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
}
if (swapEnabled) {
- SwapKey swapKey = new SwapKey(key.value(cctx.cacheObjectContext(), false),
+ SwapKey swapKey = new SwapKey(key,
part,
key.valueBytes(cctx.cacheObjectContext()));
@@ -1286,7 +1289,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
if (cctx.events().isRecordable(EVT_CACHE_OBJECT_TO_OFFHEAP))
cctx.events().addEvent(part, key, cctx.nodeId(), (IgniteUuid)null, null,
- EVT_CACHE_OBJECT_TO_OFFHEAP, null, false, null, true, null, null, null);
+ EVT_CACHE_OBJECT_TO_OFFHEAP, null, false, null, true, null, null, null, false);
}
else if (swapEnabled)
writeToSwap(part, key, entry.marshal());
@@ -1320,7 +1323,8 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
if (cctx.events().isRecordable(EVT_CACHE_OBJECT_TO_OFFHEAP))
cctx.events().addEvent(swapEntry.partition(), swapEntry.key(), cctx.nodeId(),
- (IgniteUuid)null, null, EVT_CACHE_OBJECT_TO_OFFHEAP, null, false, null, true, null, null, null);
+ (IgniteUuid)null, null, EVT_CACHE_OBJECT_TO_OFFHEAP, null, false, null, true, null, null, null,
+ false);
if (qryMgr.enabled())
qryMgr.onSwap(swapEntry.key());
@@ -1330,7 +1334,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
Map<SwapKey, byte[]> batch = new LinkedHashMap<>();
for (GridCacheBatchSwapEntry entry : swapped) {
- SwapKey swapKey = new SwapKey(entry.key().value(cctx.cacheObjectContext(), false),
+ SwapKey swapKey = new SwapKey(entry.key(),
entry.partition(),
entry.key().valueBytes(cctx.cacheObjectContext()));
@@ -1342,7 +1346,8 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
if (cctx.events().isRecordable(EVT_CACHE_OBJECT_SWAPPED)) {
for (GridCacheBatchSwapEntry batchSwapEntry : swapped) {
cctx.events().addEvent(batchSwapEntry.partition(), batchSwapEntry.key(), cctx.nodeId(),
- (IgniteUuid)null, null, EVT_CACHE_OBJECT_SWAPPED, null, false, null, true, null, null, null);
+ (IgniteUuid)null, null, EVT_CACHE_OBJECT_SWAPPED, null, false, null, true, null, null, null,
+ false);
if (qryMgr.enabled())
qryMgr.onSwap(batchSwapEntry.key());
@@ -1368,7 +1373,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
checkIteratorQueue();
swapMgr.write(spaceName,
- new SwapKey(key.value(cctx.cacheObjectContext(), false), part, key.valueBytes(cctx.cacheObjectContext())),
+ new SwapKey(key, part, key.valueBytes(cctx.cacheObjectContext())),
entry, cctx.deploy().globalLoader());
if (cctx.config().isStatisticsEnabled())
@@ -1376,7 +1381,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
if (cctx.events().isRecordable(EVT_CACHE_OBJECT_SWAPPED))
cctx.events().addEvent(part, key, cctx.nodeId(), (IgniteUuid) null, null,
- EVT_CACHE_OBJECT_SWAPPED, null, false, null, true, null, null, null);
+ EVT_CACHE_OBJECT_SWAPPED, null, false, null, true, null, null, null, false);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index f7d115f..09ae714 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -148,6 +148,9 @@ public class GridCacheUtils {
/** Skip store flag bit mask. */
public static final int SKIP_STORE_FLAG_MASK = 0x1;
+ /** Keep serialized flag. */
+ public static final int KEEP_BINARY_FLAG_MASK = 0x2;
+
/** Empty predicate array. */
private static final IgnitePredicate[] EMPTY = new IgnitePredicate[0];
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index f39084e..b64ad9a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -311,7 +311,7 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V
}
/** {@inheritDoc} */
- @Override public <K1, V1> IgniteCache<K1, V1> withKeepPortable() {
+ @Override public <K1, V1> IgniteCache<K1, V1> withKeepBinary() {
return keepPortable();
}
@@ -445,7 +445,7 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V
final CacheQuery<Map.Entry<K,V>> qry;
final CacheQueryFuture<Map.Entry<K,V>> fut;
- boolean isKeepPortable = opCtx != null && opCtx.isKeepPortable();
+ boolean isKeepPortable = opCtx != null && opCtx.isKeepBinary();
if (filter instanceof ScanQuery) {
IgniteBiPredicate<K, V> p = ((ScanQuery)filter).getFilter();
@@ -1672,7 +1672,7 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V
* </ul> <p> For example, if you use {@link Integer} as a key and {@code Value} class as a value (which will be
* stored in portable format), you should acquire following projection to avoid deserialization:
* <pre>
- * IgniteInternalCache<Integer, GridPortableObject> prj = cache.keepPortable();
+ * IgniteInternalCache<Integer, GridPortableObject> prj = cache.keepBinary();
*
* // Value is not deserialized and returned in portable format.
* GridPortableObject po = prj.get(1);
@@ -1726,7 +1726,7 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V
CacheOperationContext opCtx0 =
new CacheOperationContext(true,
opCtx != null ? opCtx.subjectId() : null,
- opCtx != null && opCtx.isKeepPortable(),
+ opCtx != null && opCtx.isKeepBinary(),
opCtx != null ? opCtx.expiry() : null,
opCtx != null && opCtx.noRetries());
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
index 167cc8e..4155706 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
@@ -188,7 +188,7 @@ import org.jetbrains.annotations.Nullable;
* needed for performance reasons. To work with portable format directly you should create special projection
* using {@link #keepPortable()} method:
* <pre>
- * IgniteInternalCache<Integer, GridPortableObject> prj = Ignition.grid().cache(null).keepPortable();
+ * IgniteInternalCache<Integer, GridPortableObject> prj = Ignition.grid().cache(null).keepBinary();
*
* // Value is not deserialized and returned in portable format.
* GridPortableObject po = prj.get(1);
@@ -231,7 +231,7 @@ public interface IgniteInternalCache<K, V> extends Iterable<Cache.Entry<K, V>> {
* so keys and values will be returned from cache API methods without changes. Therefore,
* signature of the projection can contain only following types:
* <ul>
- * <li><code>org.gridgain.grid.portables.PortableObject</code> for portable classes</li>
+ * <li><code>org.gridgain.grid.binary.PortableObject</code> for portable classes</li>
* <li>All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)</li>
* <li>Arrays of primitives (byte[], int[], ...)</li>
* <li>{@link String} and array of {@link String}s</li>
@@ -249,7 +249,7 @@ public interface IgniteInternalCache<K, V> extends Iterable<Cache.Entry<K, V>> {
* (which will be stored in portable format), you should acquire following projection
* to avoid deserialization:
* <pre>
- * IgniteInternalCache<Integer, GridPortableObject> prj = cache.keepPortable();
+ * IgniteInternalCache<Integer, GridPortableObject> prj = cache.keepBinary();
*
* // Value is not deserialized and returned in portable format.
* GridPortableObject po = prj.get(1);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
index 6958c87..4db7ec1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
@@ -61,6 +61,11 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
}
/** {@inheritDoc} */
+ @Override public boolean isPlatformType() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
assert val != null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java
index 1ff4575..edad586 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java
@@ -312,8 +312,8 @@ public class CacheDataStructuresManager extends GridCacheManagerAdapter {
* @param key Key.
* @param rmv {@code True} if entry was removed.
*/
- public void onEntryUpdated(KeyCacheObject key, boolean rmv) {
- Object key0 = key.value(cctx.cacheObjectContext(), false);
+ public void onEntryUpdated(KeyCacheObject key, boolean rmv, boolean keepPortable) {
+ Object key0 = cctx.cacheObjectContext().unwrapPortableIfNeeded(key, keepPortable, false);
if (key0 instanceof GridCacheSetItemKey)
onSetItemUpdated((GridCacheSetItemKey)key0, rmv);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
index 637e51b..1709b0f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheAdapter.java
@@ -169,6 +169,8 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
boolean skipStore = opCtx != null && opCtx.skipStore();
+ boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
+
do {
retry = false;
@@ -181,7 +183,7 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
retry = !ctx.kernalContext().task().execute(
- new RemoveAllTask(ctx.name(), topVer, skipStore), null).get();
+ new RemoveAllTask(ctx.name(), topVer, skipStore, keepBinary), null).get();
}
}
while (ctx.affinity().affinityTopologyVersion().compareTo(topVer) != 0 || retry);
@@ -200,9 +202,7 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
CacheOperationContext opCtx = ctx.operationContextPerCall();
- boolean skipStore = opCtx != null && opCtx.skipStore();
-
- removeAllAsync(opFut, topVer, skipStore);
+ removeAllAsync(opFut, topVer, opCtx != null && opCtx.skipStore(), opCtx != null && opCtx.isKeepBinary());
return opFut;
}
@@ -212,15 +212,19 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
* @param topVer Topology version.
* @param skipStore Skip store flag.
*/
- private void removeAllAsync(final GridFutureAdapter<Void> opFut, final AffinityTopologyVersion topVer,
- final boolean skipStore) {
+ private void removeAllAsync(
+ final GridFutureAdapter<Void> opFut,
+ final AffinityTopologyVersion topVer,
+ final boolean skipStore,
+ final boolean keepBinary
+ ) {
Collection<ClusterNode> nodes = ctx.grid().cluster().forDataNodes(name()).nodes();
if (!nodes.isEmpty()) {
ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
IgniteInternalFuture<Boolean> rmvAll = ctx.kernalContext().task().execute(
- new RemoveAllTask(ctx.name(), topVer, skipStore), null);
+ new RemoveAllTask(ctx.name(), topVer, skipStore, keepBinary), null);
rmvAll.listen(new IgniteInClosure<IgniteInternalFuture<Boolean>>() {
@Override public void apply(IgniteInternalFuture<Boolean> fut) {
@@ -232,7 +236,7 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
if (topVer0.equals(topVer) && !retry)
opFut.onDone();
else
- removeAllAsync(opFut, topVer0, skipStore);
+ removeAllAsync(opFut, topVer0, skipStore, keepBinary);
}
catch (ClusterGroupEmptyCheckedException ignore) {
if (log.isDebugEnabled())
@@ -277,15 +281,19 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
/** Skip store flag. */
private final boolean skipStore;
+ /** Keep binary flag. */
+ private final boolean keepBinary;
+
/**
* @param cacheName Cache name.
* @param topVer Affinity topology version.
* @param skipStore Skip store flag.
*/
- public RemoveAllTask(String cacheName, AffinityTopologyVersion topVer, boolean skipStore) {
+ public RemoveAllTask(String cacheName, AffinityTopologyVersion topVer, boolean skipStore, boolean keepBinary) {
this.cacheName = cacheName;
this.topVer = topVer;
this.skipStore = skipStore;
+ this.keepBinary = keepBinary;
}
/** {@inheritDoc} */
@@ -294,7 +302,7 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
Map<ComputeJob, ClusterNode> jobs = new HashMap();
for (ClusterNode node : subgrid)
- jobs.put(new GlobalRemoveAllJob(cacheName, topVer, skipStore), node);
+ jobs.put(new GlobalRemoveAllJob(cacheName, topVer, skipStore, keepBinary), node);
return jobs;
}
@@ -335,15 +343,24 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
/** Skip store flag. */
private final boolean skipStore;
+ /** Keep binary flag. */
+ private final boolean keepBinary;
+
/**
* @param cacheName Cache name.
* @param topVer Topology version.
* @param skipStore Skip store flag.
*/
- private GlobalRemoveAllJob(String cacheName, @NotNull AffinityTopologyVersion topVer, boolean skipStore) {
+ private GlobalRemoveAllJob(
+ String cacheName,
+ @NotNull AffinityTopologyVersion topVer,
+ boolean skipStore,
+ boolean keepBinary
+ ) {
super(cacheName, topVer);
this.skipStore = skipStore;
+ this.keepBinary = keepBinary;
}
/** {@inheritDoc} */
@@ -376,6 +393,7 @@ public abstract class GridDistributedCacheAdapter<K, V> extends GridCacheAdapter
((DataStreamerImpl) dataLdr).maxRemapCount(0);
dataLdr.skipStore(skipStore);
+ dataLdr.keepBinary(keepBinary);
dataLdr.receiver(DataStreamerCacheUpdaters.<KeyCacheObject, Object>batched());
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheEntry.java
index a138d30..eaf6a7d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedCacheEntry.java
@@ -746,8 +746,9 @@ public class GridDistributedCacheEntry extends GridCacheMapEntry {
@Override public boolean tmLock(IgniteInternalTx tx,
long timeout,
@Nullable GridCacheVersion serOrder,
- GridCacheVersion serReadVer)
- throws GridCacheEntryRemovedException, GridDistributedLockCancelledException {
+ GridCacheVersion serReadVer,
+ boolean keepBinary
+ ) throws GridCacheEntryRemovedException, GridDistributedLockCancelledException {
if (tx.local())
// Null is returned if timeout is negative and there is other lock owner.
return addLocal(
@@ -821,7 +822,7 @@ public class GridDistributedCacheEntry extends GridCacheMapEntry {
// Event notification.
cctx.events().addEvent(partition(), key, prev.nodeId(), prev, EVT_CACHE_OBJECT_UNLOCKED, val, hasVal,
- val, hasVal, null, null, null);
+ val, hasVal, null, null, null, true);
}
if (owner != null && cctx.events().isRecordable(EVT_CACHE_OBJECT_LOCKED)) {
@@ -829,7 +830,7 @@ public class GridDistributedCacheEntry extends GridCacheMapEntry {
// Event notification.
cctx.events().addEvent(partition(), key, owner.nodeId(), owner, EVT_CACHE_OBJECT_LOCKED, val, hasVal,
- val, hasVal, null, null, null);
+ val, hasVal, null, null, null, true);
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
index 2899e25..4c504ec 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
@@ -39,6 +39,7 @@ import org.apache.ignite.plugin.extensions.communication.MessageWriter;
import org.apache.ignite.transactions.TransactionIsolation;
import org.jetbrains.annotations.Nullable;
+import static org.apache.ignite.internal.processors.cache.GridCacheUtils.KEEP_BINARY_FLAG_MASK;
import static org.apache.ignite.internal.processors.cache.GridCacheUtils.SKIP_STORE_FLAG_MASK;
/**
@@ -135,6 +136,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
int keyCnt,
int txSize,
boolean skipStore,
+ boolean keepBinary,
boolean addDepInfo
) {
super(lockVer, keyCnt, addDepInfo);
@@ -158,6 +160,7 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
retVals = new boolean[keyCnt];
skipStore(skipStore);
+ keepBinary(keepBinary);
}
/**
@@ -243,6 +246,20 @@ public class GridDistributedLockRequest extends GridDistributedBaseMessage {
}
/**
+ * @param keepBinary Keep binary flag.
+ */
+ public void keepBinary(boolean keepBinary) {
+ flags = keepBinary ? (byte)(flags | KEEP_BINARY_FLAG_MASK) : (byte)(flags & ~KEEP_BINARY_FLAG_MASK);
+ }
+
+ /**
+ * @return Keep portable.
+ */
+ public boolean keepBinary() {
+ return (flags & KEEP_BINARY_FLAG_MASK) != 0;
+ }
+
+ /**
* @return Transaction isolation or <tt>null</tt> if not in transaction.
*/
public TransactionIsolation isolation() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
index fcbf58d..3aa7e1c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxRemoteAdapter.java
@@ -586,6 +586,7 @@ public class GridDistributedTxRemoteAdapter extends IgniteTxAdapter
false,
true,
true,
+ txEntry.keepBinary(),
topVer,
null,
replicate ? DR_BACKUP : DR_NONE,
@@ -602,6 +603,7 @@ public class GridDistributedTxRemoteAdapter extends IgniteTxAdapter
txEntry.ttl(),
true,
true,
+ txEntry.keepBinary(),
topVer,
null,
replicate ? DR_BACKUP : DR_NONE,
@@ -632,6 +634,7 @@ public class GridDistributedTxRemoteAdapter extends IgniteTxAdapter
false,
true,
true,
+ txEntry.keepBinary(),
topVer,
null,
replicate ? DR_BACKUP : DR_NONE,
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
index 1b2d834..60410c4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheEntry.java
@@ -263,8 +263,9 @@ public class GridDhtCacheEntry extends GridDistributedCacheEntry {
@Override public boolean tmLock(IgniteInternalTx tx,
long timeout,
@Nullable GridCacheVersion serOrder,
- GridCacheVersion serReadVer)
- throws GridCacheEntryRemovedException, GridDistributedLockCancelledException {
+ GridCacheVersion serReadVer,
+ boolean keepBinary
+ ) throws GridCacheEntryRemovedException, GridDistributedLockCancelledException {
if (tx.local()) {
GridDhtTxLocalAdapter dhtTx = (GridDhtTxLocalAdapter)tx;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
index 749d06a..c83e78c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java
@@ -666,7 +666,8 @@ public class GridDhtLocalPartition implements Comparable<GridDhtLocalPartition>,
cached.hasValue(),
null,
null,
- null);
+ null,
+ false);
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java
index c175b0b..6ed8261 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockFuture.java
@@ -165,6 +165,9 @@ public final class GridDhtLockFuture extends GridCompoundIdentityFuture<Boolean>
/** Skip store flag. */
private final boolean skipStore;
+ /** Keep binary. */
+ private final boolean keepBinary;
+
/**
* @param cctx Cache context.
* @param nearNodeId Near node ID.
@@ -193,7 +196,8 @@ public final class GridDhtLockFuture extends GridCompoundIdentityFuture<Boolean>
long threadId,
long accessTtl,
CacheEntryPredicate[] filter,
- boolean skipStore) {
+ boolean skipStore,
+ boolean keepBinary) {
super(cctx.kernalContext(), CU.boolReducer());
assert nearNodeId != null;
@@ -211,6 +215,7 @@ public final class GridDhtLockFuture extends GridCompoundIdentityFuture<Boolean>
this.tx = tx;
this.accessTtl = accessTtl;
this.skipStore = skipStore;
+ this.keepBinary = keepBinary;
if (tx != null)
tx.topologyVersion(topVer);
@@ -870,6 +875,7 @@ public final class GridDhtLockFuture extends GridCompoundIdentityFuture<Boolean>
inTx() ? tx.taskNameHash() : 0,
read ? accessTtl : -1L,
skipStore,
+ keepBinary,
cctx.deploymentEnabled());
try {
@@ -1177,7 +1183,7 @@ public final class GridDhtLockFuture extends GridCompoundIdentityFuture<Boolean>
if (rec && !entry.isInternal())
cctx.events().addEvent(entry.partition(), entry.key(), cctx.localNodeId(),
(IgniteUuid)null, null, EVT_CACHE_REBALANCE_OBJECT_LOADED, info.value(), true, null,
- false, null, null, null);
+ false, null, null, null, false);
}
}
catch (IgniteCheckedException e) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
index 91ab1ca..efcbdc6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java
@@ -120,6 +120,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
* @param taskNameHash Task name hash code.
* @param accessTtl TTL for read operation.
* @param skipStore Skip store flag.
+ * @param keepBinary Keep binary flag.
* @param addDepInfo Deployment info flag.
*/
public GridDhtLockRequest(
@@ -143,6 +144,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
int taskNameHash,
long accessTtl,
boolean skipStore,
+ boolean keepBinary,
boolean addDepInfo
) {
super(cacheId,
@@ -159,6 +161,7 @@ public class GridDhtLockRequest extends GridDistributedLockRequest {
dhtCnt == 0 ? nearCnt : dhtCnt,
txSize,
skipStore,
+ keepBinary,
addDepInfo);
this.topVer = topVer;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
index 4ce4759..732ff43 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
@@ -39,7 +39,6 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo;
import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
-import org.apache.ignite.internal.processors.cache.GridCacheFilterFailedException;
import org.apache.ignite.internal.processors.cache.GridCacheLockTimeoutException;
import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate;
import org.apache.ignite.internal.processors.cache.GridCacheReturn;
@@ -62,7 +61,6 @@ import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
import org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException;
import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridLeanSet;
-import org.apache.ignite.internal.util.future.GridEmbeddedFuture;
import org.apache.ignite.internal.util.future.GridFinishedFuture;
import org.apache.ignite.internal.util.lang.GridClosureException;
import org.apache.ignite.internal.util.typedef.C1;
@@ -256,7 +254,8 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
null,
null,
req.accessTtl(),
- req.skipStore());
+ req.skipStore(),
+ req.keepBinary());
}
entry = entryExx(key, req.topologyVersion());
@@ -604,7 +603,8 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
isolation,
accessTtl,
CU.empty0(),
- opCtx != null && opCtx.skipStore());
+ opCtx != null && opCtx.skipStore(),
+ opCtx != null && opCtx.isKeepBinary());
}
/**
@@ -631,7 +631,8 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
TransactionIsolation isolation,
long accessTtl,
CacheEntryPredicate[] filter,
- boolean skipStore) {
+ boolean skipStore,
+ boolean keepBinary) {
if (keys == null || keys.isEmpty())
return new GridDhtFinishedFuture<>(true);
@@ -652,7 +653,8 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
tx.threadId(),
accessTtl,
filter,
- skipStore);
+ skipStore,
+ keepBinary);
for (KeyCacheObject key : keys) {
try {
@@ -772,7 +774,8 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
req.threadId(),
req.accessTtl(),
filter,
- req.skipStore());
+ req.skipStore(),
+ req.keepBinary());
// Add before mapping.
if (!ctx.mvcc().addFuture(fut))
@@ -916,7 +919,8 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
req.txRead(),
req.needReturnValue(),
req.accessTtl(),
- req.skipStore());
+ req.skipStore(),
+ req.keepBinary());
final GridDhtTxLocal t = tx;
@@ -1124,7 +1128,8 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
CU.subjectId(tx, ctx.shared()),
null,
tx != null ? tx.resolveTaskName() : null,
- null);
+ null,
+ req.keepBinary());
assert e.lockedBy(mappedVer) ||
(ctx.mvcc().isRemoved(e.context(), mappedVer) && req.timeout() > 0) :
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
index 8c7d985..0cb5853 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
@@ -153,7 +153,7 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter {
invalidate,
storeEnabled,
onePhaseCommit,
- txSize,
+ txSize,
subjId,
taskNameHash
);
@@ -613,7 +613,8 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter {
final boolean read,
final boolean needRetVal,
long accessTtl,
- boolean skipStore
+ boolean skipStore,
+ boolean keepBinary
) {
try {
checkValid();
@@ -681,7 +682,8 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter {
-1L,
-1L,
null,
- skipStore);
+ skipStore,
+ keepBinary);
if (read)
txEntry.ttl(accessTtl);
@@ -719,7 +721,8 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter {
skipped,
accessTtl,
null,
- skipStore);
+ skipStore,
+ keepBinary);
}
catch (IgniteCheckedException e) {
setRollbackOnly();
@@ -749,7 +752,8 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter {
final Set<KeyCacheObject> skipped,
final long accessTtl,
@Nullable final CacheEntryPredicate[] filter,
- boolean skipStore) {
+ boolean skipStore,
+ boolean keepBinary) {
if (log.isDebugEnabled())
log.debug("Before acquiring transaction lock on keys [passedKeys=" + passedKeys + ", skipped=" +
skipped + ']');
@@ -768,7 +772,8 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter {
isolation,
accessTtl,
CU.empty0(),
- skipStore);
+ skipStore,
+ keepBinary);
return new GridEmbeddedFuture<>(
fut,
[16/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
deleted file mode 100644
index 89bb3ff..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
+++ /dev/null
@@ -1,570 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableContext;
-import org.apache.ignite.internal.portable.PortableObjectImpl;
-import org.apache.ignite.internal.portable.PortableObjectOffheapImpl;
-import org.apache.ignite.internal.portable.PortableUtils;
-import org.apache.ignite.internal.portable.PortableWriterExImpl;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
-import org.apache.ignite.internal.util.GridArgumentCheck;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableInvalidClassException;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DFLT_HDR_LEN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLAGS_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.HASH_CODE_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.PROTO_VER_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TYPE_ID_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-
-/**
- *
- */
-public class PortableBuilderImpl implements PortableBuilder {
- /** */
- private static final Object REMOVED_FIELD_MARKER = new Object();
-
- /** */
- private final PortableContext ctx;
-
- /** */
- private final int typeId;
-
- /** May be null. */
- private String typeName;
-
- /** May be null. */
- private String clsNameToWrite;
-
- /** */
- private boolean registeredType = true;
-
- /** */
- private Map<String, Object> assignedVals;
-
- /** */
- private Map<Integer, Object> readCache;
-
- /** Position of object in source array, or -1 if object is not created from PortableObject. */
- private final int start;
-
- /** Flags. */
- private final short flags;
-
- /** Total header length */
- private final int hdrLen;
-
- /** Context of PortableObject reading process. Or {@code null} if object is not created from PortableObject. */
- private final PortableBuilderReader reader;
-
- /** */
- private int hashCode;
-
- /**
- * @param clsName Class name.
- * @param ctx Portable context.
- */
- public PortableBuilderImpl(PortableContext ctx, String clsName) {
- this(ctx, ctx.typeId(clsName), PortableContext.typeName(clsName));
- }
-
- /**
- * @param typeId Type ID.
- * @param ctx Portable context.
- */
- public PortableBuilderImpl(PortableContext ctx, int typeId) {
- this(ctx, typeId, null);
- }
-
- /**
- * @param typeName Type name.
- * @param ctx Context.
- * @param typeId Type id.
- */
- public PortableBuilderImpl(PortableContext ctx, int typeId, String typeName) {
- this.typeId = typeId;
- this.typeName = typeName;
- this.ctx = ctx;
-
- start = -1;
- flags = -1;
- reader = null;
- hdrLen = DFLT_HDR_LEN;
-
- readCache = Collections.emptyMap();
- }
-
- /**
- * @param obj Object to wrap.
- */
- public PortableBuilderImpl(PortableObjectImpl obj) {
- this(new PortableBuilderReader(obj), obj.start());
-
- reader.registerObject(this);
- }
-
- /**
- * @param reader ctx
- * @param start Start.
- */
- PortableBuilderImpl(PortableBuilderReader reader, int start) {
- this.reader = reader;
- this.start = start;
- this.flags = reader.readShortPositioned(start + FLAGS_POS);
-
- byte ver = reader.readBytePositioned(start + PROTO_VER_POS);
-
- PortableUtils.checkProtocolVersion(ver);
-
- int typeId = reader.readIntPositioned(start + TYPE_ID_POS);
- ctx = reader.portableContext();
- hashCode = reader.readIntPositioned(start + HASH_CODE_POS);
-
- if (typeId == UNREGISTERED_TYPE_ID) {
- int mark = reader.position();
-
- reader.position(start + DFLT_HDR_LEN);
-
- clsNameToWrite = reader.readString();
-
- Class cls;
-
- try {
- // TODO: IGNITE-1272 - Is class loader needed here?
- cls = U.forName(clsNameToWrite, null);
- }
- catch (ClassNotFoundException e) {
- throw new PortableInvalidClassException("Failed to load the class: " + clsNameToWrite, e);
- }
-
- this.typeId = ctx.descriptorForClass(cls).typeId();
-
- registeredType = false;
-
- hdrLen = reader.position() - mark;
-
- reader.position(mark);
- }
- else {
- this.typeId = typeId;
- hdrLen = DFLT_HDR_LEN;
- }
- }
-
- /** {@inheritDoc} */
- @Override public PortableObject build() {
- try (PortableWriterExImpl writer = new PortableWriterExImpl(ctx, typeId, false)) {
-
- PortableBuilderSerializer serializationCtx = new PortableBuilderSerializer();
-
- serializationCtx.registerObjectWriting(this, 0);
-
- serializeTo(writer, serializationCtx);
-
- byte[] arr = writer.array();
-
- return new PortableObjectImpl(ctx, arr, 0);
- }
- }
-
- /**
- * @param writer Writer.
- * @param serializer Serializer.
- */
- void serializeTo(PortableWriterExImpl writer, PortableBuilderSerializer serializer) {
- try {
- PortableUtils.writeHeader(writer,
- true,
- registeredType ? typeId : UNREGISTERED_TYPE_ID,
- hashCode,
- registeredType ? null : clsNameToWrite);
-
- Set<Integer> remainsFlds = null;
-
- if (reader != null) {
- Map<Integer, Object> assignedFldsById;
-
- if (assignedVals != null) {
- assignedFldsById = U.newHashMap(assignedVals.size());
-
- for (Map.Entry<String, Object> entry : assignedVals.entrySet()) {
- int fldId = ctx.fieldId(typeId, entry.getKey());
-
- assignedFldsById.put(fldId, entry.getValue());
- }
-
- remainsFlds = assignedFldsById.keySet();
- } else
- assignedFldsById = Collections.emptyMap();
-
- // Get footer details.
- int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
-
- IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start, fieldOffsetSize);
-
- int footerPos = footer.get1();
- int footerEnd = footer.get2();
-
- // Get raw position.
- int rawPos = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize);
-
- // Position reader on data.
- reader.position(start + hdrLen);
-
- while (reader.position() + 4 < rawPos) {
- int fieldId = reader.readIntPositioned(footerPos);
- int fieldLen = fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldOffsetSize).get2();
-
- int postPos = reader.position() + fieldLen; // Position where reader will be placed afterwards.
-
- footerPos += 4 + fieldOffsetSize;
-
- if (assignedFldsById.containsKey(fieldId)) {
- Object assignedVal = assignedFldsById.remove(fieldId);
-
- if (assignedVal != REMOVED_FIELD_MARKER) {
- writer.writeFieldId(fieldId);
-
- serializer.writeValue(writer, assignedVal);
- }
- }
- else {
- int type = fieldLen != 0 ? reader.readByte(0) : 0;
-
- if (fieldLen != 0 && !PortableUtils.isPlainArrayType(type) && PortableUtils.isPlainType(type)) {
- writer.writeFieldId(fieldId);
-
- writer.write(reader.array(), reader.position(), fieldLen);
- }
- else {
- writer.writeFieldId(fieldId);
-
- Object val;
-
- if (fieldLen == 0)
- val = null;
- else if (readCache == null) {
- val = reader.parseValue();
-
- assert reader.position() == postPos;
- }
- else
- val = readCache.get(fieldId);
-
- serializer.writeValue(writer, val);
- }
- }
-
- reader.position(postPos);
- }
- }
-
- if (assignedVals != null && (remainsFlds == null || !remainsFlds.isEmpty())) {
- boolean metadataEnabled = ctx.isMetaDataEnabled(typeId);
-
- PortableMetadata metadata = null;
-
- if (metadataEnabled)
- metadata = ctx.metaData(typeId);
-
- Map<String, String> newFldsMetadata = null;
-
- for (Map.Entry<String, Object> entry : assignedVals.entrySet()) {
- Object val = entry.getValue();
-
- if (val == REMOVED_FIELD_MARKER)
- continue;
-
- String name = entry.getKey();
-
- int fldId = ctx.fieldId(typeId, name);
-
- if (remainsFlds != null && !remainsFlds.contains(fldId))
- continue;
-
- writer.writeFieldId(fldId);
-
- serializer.writeValue(writer, val);
-
- if (metadataEnabled) {
- String oldFldTypeName = metadata == null ? null : metadata.fieldTypeName(name);
-
- String newFldTypeName;
-
- if (val instanceof PortableValueWithType)
- newFldTypeName = ((PortableValueWithType) val).typeName();
- else {
- byte type = PortableUtils.typeByClass(val.getClass());
-
- newFldTypeName = CacheObjectPortableProcessorImpl.fieldTypeName(type);
- }
-
- if (oldFldTypeName == null) {
- // It's a new field, we have to add it to metadata.
-
- if (newFldsMetadata == null)
- newFldsMetadata = new HashMap<>();
-
- newFldsMetadata.put(name, newFldTypeName);
- }
- else {
- String objTypeName =
- CacheObjectPortableProcessorImpl.FIELD_TYPE_NAMES[GridPortableMarshaller.OBJ];
-
- if (!objTypeName.equals(oldFldTypeName) && !oldFldTypeName.equals(newFldTypeName)) {
- throw new PortableException(
- "Wrong value has been set [" +
- "typeName=" + (typeName == null ? metadata.typeName() : typeName) +
- ", fieldName=" + name +
- ", fieldType=" + oldFldTypeName +
- ", assignedValueType=" + newFldTypeName + ']'
- );
- }
- }
- }
- }
-
- if (newFldsMetadata != null) {
- String typeName = this.typeName;
-
- if (typeName == null)
- typeName = metadata.typeName();
-
- ctx.updateMetaData(typeId, typeName, newFldsMetadata);
- }
- }
-
- if (reader != null) {
- // Write raw data if any.
- int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
-
- int rawOff = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize);
- int footerStart = PortableUtils.footerStartAbsolute(reader, start);
-
- if (rawOff < footerStart) {
- writer.rawWriter();
-
- writer.write(reader.array(), rawOff, footerStart - rawOff);
- }
-
- // Shift reader to the end of the object.
- reader.position(start + PortableUtils.length(reader, start));
- }
-
- writer.postWrite(true);
- }
- finally {
- writer.popSchema();
- }
- }
-
- /** {@inheritDoc} */
- @Override public PortableBuilderImpl hashCode(int hashCode) {
- this.hashCode = hashCode;
-
- return this;
- }
-
- /**
- * Get field position and length.
- *
- * @param footerPos Field position inside the footer (absolute).
- * @param footerEnd Footer end (absolute).
- * @param rawPos Raw data position (absolute).
- * @param fieldOffsetSize Size of field's offset.
- * @return Tuple with field position and length.
- */
- private IgniteBiTuple<Integer, Integer> fieldPositionAndLength(int footerPos, int footerEnd, int rawPos,
- int fieldOffsetSize) {
- // Get field offset first.
- int fieldOffset = PortableUtils.fieldOffsetRelative(reader, footerPos + 4, fieldOffsetSize);
- int fieldPos = start + fieldOffset;
-
- // Get field length.
- int fieldLen;
-
- if (footerPos + 4 + fieldOffsetSize == footerEnd)
- // This is the last field, compare to raw offset.
- fieldLen = rawPos - fieldPos;
- else {
- // Field is somewhere in the middle, get difference with the next offset.
- int nextFieldOffset = PortableUtils.fieldOffsetRelative(reader, footerPos + 4 + fieldOffsetSize + 4,
- fieldOffsetSize);
-
- fieldLen = nextFieldOffset - fieldOffset;
- }
-
- return F.t(fieldPos, fieldLen);
- }
-
- /**
- * Initialize read cache if needed.
- */
- private void ensureReadCacheInit() {
- if (readCache == null) {
- int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
-
- Map<Integer, Object> readCache = new HashMap<>();
-
- IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start, fieldOffsetSize);
-
- int footerPos = footer.get1();
- int footerEnd = footer.get2();
-
- int rawPos = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize);
-
- while (footerPos + 4 < footerEnd) {
- int fieldId = reader.readIntPositioned(footerPos);
-
- IgniteBiTuple<Integer, Integer> posAndLen =
- fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldOffsetSize);
-
- Object val = reader.getValueQuickly(posAndLen.get1(), posAndLen.get2());
-
- readCache.put(fieldId, val);
-
- // Shift current footer position.
- footerPos += 4 + fieldOffsetSize;
- }
-
- this.readCache = readCache;
- }
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override public <T> T getField(String name) {
- Object val;
-
- if (assignedVals != null && assignedVals.containsKey(name)) {
- val = assignedVals.get(name);
-
- if (val == REMOVED_FIELD_MARKER)
- return null;
- }
- else {
- ensureReadCacheInit();
-
- int fldId = ctx.fieldId(typeId, name);
-
- val = readCache.get(fldId);
- }
-
- return (T)PortableUtils.unwrapLazy(val);
- }
-
- /** {@inheritDoc} */
- @Override public PortableBuilder setField(String name, Object val) {
- GridArgumentCheck.notNull(val, name);
-
- if (assignedVals == null)
- assignedVals = new LinkedHashMap<>();
-
- Object oldVal = assignedVals.put(name, val);
-
- if (oldVal instanceof PortableValueWithType) {
- ((PortableValueWithType)oldVal).value(val);
-
- assignedVals.put(name, oldVal);
- }
-
- return this;
- }
-
- /** {@inheritDoc} */
- @Override public <T> PortableBuilder setField(String name, @Nullable T val, Class<? super T> type) {
- if (assignedVals == null)
- assignedVals = new LinkedHashMap<>();
-
- //int fldId = ctx.fieldId(typeId, fldName);
-
- assignedVals.put(name, new PortableValueWithType(PortableUtils.typeByClass(type), val));
-
- return this;
- }
-
- /** {@inheritDoc} */
- @Override public PortableBuilder setField(String name, @Nullable PortableBuilder builder) {
- if (builder == null)
- return setField(name, null, Object.class);
- else
- return setField(name, (Object)builder);
- }
-
- /**
- * Removes field from portable object.
- *
- * @param name Field name.
- * @return {@code this} instance for chaining.
- */
- @Override public PortableBuilderImpl removeField(String name) {
- if (assignedVals == null)
- assignedVals = new LinkedHashMap<>();
-
- assignedVals.put(name, REMOVED_FIELD_MARKER);
-
- return this;
- }
-
- /**
- * Creates builder initialized by specified portable object.
- *
- * @param obj Portable object to initialize builder.
- * @return New builder.
- */
- public static PortableBuilderImpl wrap(PortableObject obj) {
- PortableObjectImpl heapObj;
-
- if (obj instanceof PortableObjectOffheapImpl)
- heapObj = (PortableObjectImpl)((PortableObjectOffheapImpl)obj).heapCopy();
- else
- heapObj = (PortableObjectImpl)obj;
-
- return new PortableBuilderImpl(heapObj);
- }
-
- /**
- * @return Object start position in source array.
- */
- int start() {
- return start;
- }
-
- /**
- * @return Object type id.
- */
- public int typeId() {
- return typeId;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
index 9645ced..d2a3ac2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
@@ -23,13 +23,13 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.ignite.internal.portable.GridPortableMarshaller;
import org.apache.ignite.internal.portable.PortableContext;
-import org.apache.ignite.internal.portable.PortableObjectImpl;
import org.apache.ignite.internal.portable.PortablePositionReadable;
+import org.apache.ignite.internal.portable.BinaryObjectImpl;
import org.apache.ignite.internal.portable.PortablePrimitives;
-import org.apache.ignite.internal.portable.PortableReaderExImpl;
+import org.apache.ignite.internal.portable.BinaryReaderExImpl;
import org.apache.ignite.internal.portable.PortableUtils;
-import org.apache.ignite.internal.portable.PortableWriterExImpl;
-import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.internal.portable.BinaryWriterExImpl;
+import org.apache.ignite.binary.BinaryObjectException;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
@@ -40,13 +40,13 @@ import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
*/
public class PortableBuilderReader implements PortablePositionReadable {
/** */
- private final Map<Integer, PortableBuilderImpl> objMap = new HashMap<>();
+ private final Map<Integer, BinaryObjectBuilderImpl> objMap = new HashMap<>();
/** */
private final PortableContext ctx;
/** */
- private final PortableReaderExImpl reader;
+ private final BinaryReaderExImpl reader;
/** */
private byte[] arr;
@@ -57,13 +57,13 @@ public class PortableBuilderReader implements PortablePositionReadable {
/**
* @param objImpl Portable object
*/
- PortableBuilderReader(PortableObjectImpl objImpl) {
+ PortableBuilderReader(BinaryObjectImpl objImpl) {
ctx = objImpl.context();
arr = objImpl.array();
pos = objImpl.start();
// TODO: IGNITE-1272 - Is class loader needed here?
- reader = new PortableReaderExImpl(portableContext(), arr, pos, null);
+ reader = new BinaryReaderExImpl(portableContext(), arr, pos, null);
}
/**
@@ -76,7 +76,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
/**
* @param obj Mutable portable object.
*/
- public void registerObject(PortableBuilderImpl obj) {
+ public void registerObject(BinaryObjectBuilderImpl obj) {
objMap.put(obj.start(), obj);
}
@@ -170,7 +170,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
return null;
if (flag != STRING)
- throw new PortableException("Failed to deserialize String.");
+ throw new BinaryObjectException("Failed to deserialize String.");
boolean convert = readBoolean();
int len = readInt();
@@ -338,7 +338,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
break;
default:
- throw new PortableException("Invalid flag value: " + type);
+ throw new BinaryObjectException("Invalid flag value: " + type);
}
pos += len;
@@ -359,10 +359,10 @@ public class PortableBuilderReader implements PortablePositionReadable {
case GridPortableMarshaller.HANDLE: {
int objStart = pos - readIntPositioned(pos + 1);
- PortableBuilderImpl res = objMap.get(objStart);
+ BinaryObjectBuilderImpl res = objMap.get(objStart);
if (res == null) {
- res = new PortableBuilderImpl(this, objStart);
+ res = new BinaryObjectBuilderImpl(this, objStart);
objMap.put(objStart, res);
}
@@ -371,10 +371,10 @@ public class PortableBuilderReader implements PortablePositionReadable {
}
case GridPortableMarshaller.OBJ: {
- PortableBuilderImpl res = objMap.get(pos);
+ BinaryObjectBuilderImpl res = objMap.get(pos);
if (res == null) {
- res = new PortableBuilderImpl(this, pos);
+ res = new BinaryObjectBuilderImpl(this, pos);
objMap.put(pos, res);
}
@@ -455,13 +455,13 @@ public class PortableBuilderReader implements PortablePositionReadable {
int start = readIntPositioned(pos + 4 + size);
- PortableObjectImpl portableObj = new PortableObjectImpl(ctx, arr, pos + 4 + start);
+ BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr, pos + 4 + start);
return new PortablePlainPortableObject(portableObj);
}
default:
- throw new PortableException("Invalid flag value: " + type);
+ throw new BinaryObjectException("Invalid flag value: " + type);
}
}
@@ -484,10 +484,10 @@ public class PortableBuilderReader implements PortablePositionReadable {
case GridPortableMarshaller.HANDLE: {
int objStart = pos - 1 - readInt();
- PortableBuilderImpl res = objMap.get(objStart);
+ BinaryObjectBuilderImpl res = objMap.get(objStart);
if (res == null) {
- res = new PortableBuilderImpl(this, objStart);
+ res = new BinaryObjectBuilderImpl(this, objStart);
objMap.put(objStart, res);
}
@@ -498,10 +498,10 @@ public class PortableBuilderReader implements PortablePositionReadable {
case GridPortableMarshaller.OBJ: {
pos--;
- PortableBuilderImpl res = objMap.get(pos);
+ BinaryObjectBuilderImpl res = objMap.get(pos);
if (res == null) {
- res = new PortableBuilderImpl(this, pos);
+ res = new BinaryObjectBuilderImpl(this, pos);
objMap.put(pos, res);
}
@@ -633,7 +633,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
if (flag == GridPortableMarshaller.NULL) continue;
if (flag != GridPortableMarshaller.DATE)
- throw new PortableException("Invalid flag value: " + flag);
+ throw new BinaryObjectException("Invalid flag value: " + flag);
long time = PortablePrimitives.readLong(arr, pos);
@@ -657,7 +657,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
continue;
if (flag != GridPortableMarshaller.TIMESTAMP)
- throw new PortableException("Invalid flag value: " + flag);
+ throw new BinaryObjectException("Invalid flag value: " + flag);
long time = PortablePrimitives.readLong(arr, pos);
@@ -719,7 +719,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
return new PortableLazySet(this, size);
}
- throw new PortableException("Unknown collection type: " + colType);
+ throw new BinaryObjectException("Unknown collection type: " + colType);
}
case GridPortableMarshaller.MAP:
@@ -741,14 +741,14 @@ public class PortableBuilderReader implements PortablePositionReadable {
int start = readInt();
- PortableObjectImpl portableObj = new PortableObjectImpl(ctx, arr,
+ BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr,
pos - 4 - size + start);
return new PortablePlainPortableObject(portableObj);
}
default:
- throw new PortableException("Invalid flag value: " + type);
+ throw new BinaryObjectException("Invalid flag value: " + type);
}
PortableAbstractLazyValue res;
@@ -794,7 +794,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
/**
* @return Reader.
*/
- PortableReaderExImpl reader() {
+ BinaryReaderExImpl reader() {
return reader;
}
@@ -829,7 +829,7 @@ public class PortableBuilderReader implements PortablePositionReadable {
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
ctx.writeValue(writer, wrappedCollection());
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializationAware.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializationAware.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializationAware.java
index 976059a..a750f6c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializationAware.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializationAware.java
@@ -27,5 +27,5 @@ interface PortableBuilderSerializationAware {
* @param writer Writer.
* @param ctx Context.
*/
- public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx);
+ public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
index fa08d79..0e8eaa4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
@@ -17,12 +17,12 @@
package org.apache.ignite.internal.portable.builder;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableObjectEx;
+import org.apache.ignite.internal.portable.BinaryObjectEx;
import org.apache.ignite.internal.portable.PortableUtils;
-import org.apache.ignite.internal.portable.PortableWriterExImpl;
+import org.apache.ignite.internal.portable.BinaryWriterExImpl;
import org.apache.ignite.internal.util.*;
-import org.apache.ignite.portable.*;
import java.util.*;
@@ -31,16 +31,16 @@ import java.util.*;
*/
class PortableBuilderSerializer {
/** */
- private final Map<PortableBuilderImpl, Integer> objToPos = new IdentityHashMap<>();
+ private final Map<BinaryObjectBuilderImpl, Integer> objToPos = new IdentityHashMap<>();
/** */
- private Map<PortableObject, PortableBuilderImpl> portableObjToWrapper;
+ private Map<BinaryObject, BinaryObjectBuilderImpl> portableObjToWrapper;
/**
* @param obj Mutable object.
* @param posInResArr Object position in the array.
*/
- public void registerObjectWriting(PortableBuilderImpl obj, int posInResArr) {
+ public void registerObjectWriting(BinaryObjectBuilderImpl obj, int posInResArr) {
objToPos.put(obj, posInResArr);
}
@@ -48,7 +48,7 @@ class PortableBuilderSerializer {
* @param writer Writer.
* @param val Value.
*/
- public void writeValue(PortableWriterExImpl writer, Object val) {
+ public void writeValue(BinaryWriterExImpl writer, Object val) {
if (val == null) {
writer.writeByte(GridPortableMarshaller.NULL);
@@ -61,23 +61,23 @@ class PortableBuilderSerializer {
return;
}
- if (val instanceof PortableObjectEx) {
+ if (val instanceof BinaryObjectEx) {
if (portableObjToWrapper == null)
portableObjToWrapper = new IdentityHashMap<>();
- PortableBuilderImpl wrapper = portableObjToWrapper.get(val);
+ BinaryObjectBuilderImpl wrapper = portableObjToWrapper.get(val);
if (wrapper == null) {
- wrapper = PortableBuilderImpl.wrap((PortableObject)val);
+ wrapper = BinaryObjectBuilderImpl.wrap((BinaryObject)val);
- portableObjToWrapper.put((PortableObject)val, wrapper);
+ portableObjToWrapper.put((BinaryObject)val, wrapper);
}
val = wrapper;
}
- if (val instanceof PortableBuilderImpl) {
- PortableBuilderImpl obj = (PortableBuilderImpl)val;
+ if (val instanceof BinaryObjectBuilderImpl) {
+ BinaryObjectBuilderImpl obj = (BinaryObjectBuilderImpl)val;
Integer posInResArr = objToPos.get(obj);
@@ -186,7 +186,7 @@ class PortableBuilderSerializer {
* @param arr The array.
* @param compTypeId Component type ID.
*/
- public void writeArray(PortableWriterExImpl writer, byte elementType, Object[] arr, int compTypeId) {
+ public void writeArray(BinaryWriterExImpl writer, byte elementType, Object[] arr, int compTypeId) {
writer.writeByte(elementType);
writer.writeInt(compTypeId);
writer.writeInt(arr.length);
@@ -201,7 +201,7 @@ class PortableBuilderSerializer {
* @param arr The array.
* @param clsName Component class name.
*/
- public void writeArray(PortableWriterExImpl writer, byte elementType, Object[] arr, String clsName) {
+ public void writeArray(BinaryWriterExImpl writer, byte elementType, Object[] arr, String clsName) {
writer.writeByte(elementType);
writer.writeInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
writer.writeString(clsName);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java
index d864a6e..1e2ebc9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java
@@ -18,10 +18,10 @@
package org.apache.ignite.internal.portable.builder;
import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableWriterExImpl;
+import org.apache.ignite.internal.portable.BinaryWriterExImpl;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableInvalidClassException;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
/**
*
@@ -54,7 +54,7 @@ class PortableEnumArrayLazyValue extends PortableAbstractLazyValue {
cls = U.forName(reader.readString(), null);
}
catch (ClassNotFoundException e) {
- throw new PortableInvalidClassException("Failed to load the class: " + clsName, e);
+ throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
}
compTypeId = reader.portableContext().descriptorForClass(cls).typeId();
@@ -90,7 +90,7 @@ class PortableEnumArrayLazyValue extends PortableAbstractLazyValue {
continue;
if (flag != GridPortableMarshaller.ENUM)
- throw new PortableException("Invalid flag value: " + flag);
+ throw new BinaryObjectException("Invalid flag value: " + flag);
res[i] = new PortableBuilderEnum(reader);
}
@@ -99,7 +99,7 @@ class PortableEnumArrayLazyValue extends PortableAbstractLazyValue {
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
if (val != null) {
if (clsName != null)
ctx.writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, clsName);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyArrayList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyArrayList.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyArrayList.java
index f29872e..29bbe85 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyArrayList.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyArrayList.java
@@ -131,7 +131,7 @@ class PortableLazyArrayList extends AbstractList<Object> implements PortableBuil
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
if (delegate == null) {
int size = reader.readIntPositioned(off + 1);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyLinkedList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyLinkedList.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyLinkedList.java
index 4940311..3271aaa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyLinkedList.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyLinkedList.java
@@ -188,7 +188,7 @@ class PortableLazyLinkedList extends AbstractList<Object> implements PortableBui
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
if (delegate == null) {
int size = reader.readIntPositioned(off + 1);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMap.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMap.java
index 74bd4c4..32d4f44 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMap.java
@@ -85,7 +85,7 @@ class PortableLazyMap extends AbstractMap<Object, Object> implements PortableBui
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
if (delegate == null) {
int size = reader.readIntPositioned(off + 1);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMapEntry.java
index bd027f5..5ebb223 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMapEntry.java
@@ -59,7 +59,7 @@ class PortableLazyMapEntry implements Map.Entry<Object, Object>, PortableBuilder
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
writer.writeByte(GridPortableMarshaller.MAP_ENTRY);
ctx.writeValue(writer, key);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazySet.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazySet.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazySet.java
index c1099eb..7e62aa4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazySet.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazySet.java
@@ -21,7 +21,7 @@ import java.util.Collection;
import java.util.Set;
import org.apache.ignite.internal.portable.GridPortableMarshaller;
import org.apache.ignite.internal.portable.PortableUtils;
-import org.apache.ignite.internal.portable.PortableWriterExImpl;
+import org.apache.ignite.internal.portable.BinaryWriterExImpl;
import org.apache.ignite.internal.util.typedef.internal.U;
/**
@@ -47,7 +47,7 @@ class PortableLazySet extends PortableAbstractLazyValue {
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
if (val == null) {
int size = reader.readIntPositioned(off + 1);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableModifiableLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableModifiableLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableModifiableLazyValue.java
index 09fb844..2b439c8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableModifiableLazyValue.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableModifiableLazyValue.java
@@ -43,7 +43,7 @@ public class PortableModifiableLazyValue extends PortableAbstractLazyValue {
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
if (val == null)
writer.write(reader.array(), valOff, len);
else
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java
index 1126a3c..6634eea 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java
@@ -18,9 +18,9 @@
package org.apache.ignite.internal.portable.builder;
import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableWriterExImpl;
+import org.apache.ignite.internal.portable.BinaryWriterExImpl;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.portable.PortableInvalidClassException;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
/**
*
@@ -53,7 +53,7 @@ class PortableObjectArrayLazyValue extends PortableAbstractLazyValue {
cls = U.forName(reader.readString(), null);
}
catch (ClassNotFoundException e) {
- throw new PortableInvalidClassException("Failed to load the class: " + clsName, e);
+ throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
}
compTypeId = reader.portableContext().descriptorForClass(cls).typeId();
@@ -82,7 +82,7 @@ class PortableObjectArrayLazyValue extends PortableAbstractLazyValue {
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
if (clsName == null)
ctx.writeArray(writer, GridPortableMarshaller.OBJ_ARR, lazyValsArr, compTypeId);
else
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainLazyValue.java
index 136958a..14c182b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainLazyValue.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainLazyValue.java
@@ -43,7 +43,7 @@ class PortablePlainLazyValue extends PortableAbstractLazyValue {
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
writer.write(reader.array(), valOff, len);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java
index 8743fbe..1512b44 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java
@@ -17,22 +17,22 @@
package org.apache.ignite.internal.portable.builder;
-import org.apache.ignite.internal.portable.PortableObjectImpl;
-import org.apache.ignite.internal.portable.PortableObjectOffheapImpl;
-import org.apache.ignite.internal.portable.PortableWriterExImpl;
-import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.internal.portable.BinaryObjectImpl;
+import org.apache.ignite.internal.portable.BinaryObjectOffheapImpl;
+import org.apache.ignite.internal.portable.BinaryWriterExImpl;
+import org.apache.ignite.binary.BinaryObject;
/**
*
*/
public class PortablePlainPortableObject implements PortableLazyValue {
/** */
- private final PortableObject portableObj;
+ private final BinaryObject portableObj;
/**
* @param portableObj Portable object.
*/
- public PortablePlainPortableObject(PortableObject portableObj) {
+ public PortablePlainPortableObject(BinaryObject portableObj) {
this.portableObj = portableObj;
}
@@ -42,12 +42,12 @@ public class PortablePlainPortableObject implements PortableLazyValue {
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
- PortableObject val = portableObj;
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+ BinaryObject val = portableObj;
- if (val instanceof PortableObjectOffheapImpl)
- val = ((PortableObjectOffheapImpl)val).heapCopy();
+ if (val instanceof BinaryObjectOffheapImpl)
+ val = ((BinaryObjectOffheapImpl)val).heapCopy();
- writer.doWritePortableObject((PortableObjectImpl)val);
+ writer.doWritePortableObject((BinaryObjectImpl)val);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableValueWithType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableValueWithType.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableValueWithType.java
index 2e031f0..5ea8e62 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableValueWithType.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableValueWithType.java
@@ -17,8 +17,8 @@
package org.apache.ignite.internal.portable.builder;
-import org.apache.ignite.internal.portable.PortableWriterExImpl;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
+import org.apache.ignite.internal.portable.BinaryWriterExImpl;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
import org.apache.ignite.internal.util.typedef.internal.S;
/**
@@ -41,7 +41,7 @@ class PortableValueWithType implements PortableLazyValue {
}
/** {@inheritDoc} */
- @Override public void writeTo(PortableWriterExImpl writer, PortableBuilderSerializer ctx) {
+ @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
if (val instanceof PortableBuilderSerializationAware)
((PortableBuilderSerializationAware)val).writeTo(writer, ctx);
else
@@ -50,7 +50,7 @@ class PortableValueWithType implements PortableLazyValue {
/** {@inheritDoc} */
public String typeName() {
- return CacheObjectPortableProcessorImpl.fieldTypeName(type);
+ return CacheObjectBinaryProcessorImpl.fieldTypeName(type);
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
index d7f66c9..2c4864e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.portable.streams;
-import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.binary.BinaryObjectException;
/**
* Portable abstract input stream.
@@ -288,7 +288,7 @@ public abstract class PortableAbstractInputStream extends PortableAbstractStream
/** {@inheritDoc} */
@Override public void position(int pos) {
if (remaining() + this.pos < pos)
- throw new PortableException("Position is out of bounds: " + pos);
+ throw new BinaryObjectException("Position is out of bounds: " + pos);
else
this.pos = pos;
}
@@ -305,7 +305,7 @@ public abstract class PortableAbstractInputStream extends PortableAbstractStream
*/
protected void ensureEnoughData(int cnt) {
if (remaining() < cnt)
- throw new PortableException("Not enough data to read the value [position=" + pos +
+ throw new BinaryObjectException("Not enough data to read the value [position=" + pos +
", requiredBytes=" + cnt + ", remainingBytes=" + remaining() + ']');
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
index 8bc40cd..d728927 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
@@ -33,6 +33,7 @@ import org.apache.ignite.cache.affinity.AffinityFunction;
import org.apache.ignite.cache.affinity.AffinityKeyMapper;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.events.DiscoveryEvent;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.internal.GridNodeOrderComparator;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.processors.cache.CacheObject;
@@ -369,7 +370,7 @@ public class GridAffinityAssignmentCache {
* @return Affinity key.
*/
private Object affinityKey(Object key) {
- if (key instanceof CacheObject)
+ if (key instanceof CacheObject && !(key instanceof BinaryObject))
key = ((CacheObject)key).value(ctx.cacheObjectContext(), false);
return (key instanceof GridCacheInternal ? ctx.defaultAffMapper() : affMapper).affinityKey(key);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
index 8f66dc1..90306b0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
@@ -38,6 +38,7 @@ import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.events.DiscoveryEvent;
import org.apache.ignite.events.Event;
+import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener;
@@ -497,7 +498,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
* @throws IgniteCheckedException In case of error.
*/
private <K> ClusterNode primary(AffinityInfo aff, K key) throws IgniteCheckedException {
- if (key instanceof CacheObject)
+ if (key instanceof CacheObject && !(key instanceof BinaryObject))
key = ((CacheObject)key).value(aff.cacheObjCtx, false);
int part = aff.affFunc.partition(aff.mapper.affinityKey(key));
@@ -516,7 +517,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
* @return Primary and backup nodes.
*/
private <K> List<ClusterNode> primaryAndBackups(AffinityInfo aff, K key) {
- if (key instanceof CacheObject)
+ if (key instanceof CacheObject && !(key instanceof BinaryObject))
key = ((CacheObject) key).value(aff.cacheObjCtx, false);
int part = aff.affFunc.partition(aff.mapper.affinityKey(key));
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeEntry.java
index f87dadd..2de26fc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeEntry.java
@@ -49,9 +49,10 @@ public class CacheInvokeEntry<K, V> extends CacheLazyEntry<K, V> implements Muta
public CacheInvokeEntry(GridCacheContext cctx,
KeyCacheObject keyObj,
@Nullable CacheObject valObj,
- GridCacheVersion ver
+ GridCacheVersion ver,
+ boolean keepPortable
) {
- super(cctx, keyObj, valObj);
+ super(cctx, keyObj, valObj, keepPortable);
this.hadVal = valObj != null;
this.ver = ver;
@@ -70,8 +71,10 @@ public class CacheInvokeEntry<K, V> extends CacheLazyEntry<K, V> implements Muta
@Nullable K key,
@Nullable CacheObject valObj,
@Nullable V val,
- GridCacheVersion ver) {
- super(ctx, keyObj, key, valObj, val);
+ GridCacheVersion ver,
+ boolean keepPortable
+ ) {
+ super(ctx, keyObj, key, valObj, val, keepPortable);
this.hadVal = valObj != null || val != null;
this.ver = ver;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLazyEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLazyEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLazyEntry.java
index 1301f1a..47ad30c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLazyEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheLazyEntry.java
@@ -20,7 +20,6 @@ package org.apache.ignite.internal.processors.cache;
import javax.cache.Cache;
import org.apache.ignite.Ignite;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
-import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.S;
/**
@@ -44,15 +43,19 @@ public class CacheLazyEntry<K, V> implements Cache.Entry<K, V> {
@GridToStringInclude
protected V val;
+ /** Keep portable flag. */
+ private boolean keepPortable;
+
/**
* @param cctx Cache context.
* @param keyObj Key cache object.
* @param valObj Cache object value.
*/
- public CacheLazyEntry(GridCacheContext cctx, KeyCacheObject keyObj, CacheObject valObj) {
+ public CacheLazyEntry(GridCacheContext cctx, KeyCacheObject keyObj, CacheObject valObj, boolean keepPortable) {
+ this.cctx = cctx;
this.keyObj = keyObj;
this.valObj = valObj;
- this.cctx = cctx;
+ this.keepPortable = keepPortable;
}
/**
@@ -60,10 +63,11 @@ public class CacheLazyEntry<K, V> implements Cache.Entry<K, V> {
* @param val Value.
* @param cctx Cache context.
*/
- public CacheLazyEntry(GridCacheContext cctx, KeyCacheObject keyObj, V val) {
+ public CacheLazyEntry(GridCacheContext cctx, KeyCacheObject keyObj, V val, boolean keepPortable) {
+ this.cctx = cctx;
this.keyObj = keyObj;
this.val = val;
- this.cctx = cctx;
+ this.keepPortable = keepPortable;
}
/**
@@ -77,18 +81,21 @@ public class CacheLazyEntry<K, V> implements Cache.Entry<K, V> {
KeyCacheObject keyObj,
K key,
CacheObject valObj,
- V val) {
+ V val,
+ boolean keepPortable
+ ) {
this.cctx = ctx;
this.keyObj = keyObj;
this.key = key;
this.valObj = valObj;
this.val = val;
+ this.keepPortable = keepPortable;
}
/** {@inheritDoc} */
@Override public K getKey() {
if (key == null)
- key = CU.value(keyObj, cctx, true);
+ key = (K)cctx.unwrapPortableIfNeeded(keyObj, keepPortable);
return key;
}
@@ -96,7 +103,7 @@ public class CacheLazyEntry<K, V> implements Cache.Entry<K, V> {
/** {@inheritDoc} */
@Override public V getValue() {
if (val == null)
- val = CU.value(valObj, cctx, true);
+ val = (V)cctx.unwrapPortableIfNeeded(valObj, keepPortable);
return val;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
index d870a6c..81129bd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
@@ -48,7 +48,16 @@ public interface CacheObject extends Message {
/**
* @return Object type.
*/
- public byte type();
+ public byte cacheObjectType();
+
+ /**
+ * Gets flag indicating whether object value is a platform type. Platform types will be automatically
+ * deserialized on public API cache operations regardless whether
+ * {@link org.apache.ignite.IgniteCache#withKeepBinary()} is used or not.
+ *
+ * @return Platform type flag.
+ */
+ public boolean isPlatformType();
/**
* Prepares cache object for cache (e.g. copies user-provided object if needed).
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
index a3f37f6..df20646 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
@@ -49,7 +49,7 @@ public abstract class CacheObjectAdapter implements CacheObject, Externalizable
}
/** {@inheritDoc} */
- @Override public byte type() {
+ @Override public byte cacheObjectType() {
return TYPE_REGULAR;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
index 32f5f88..e961d84 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectByteArrayImpl.java
@@ -75,11 +75,16 @@ public class CacheObjectByteArrayImpl implements CacheObject, Externalizable {
}
/** {@inheritDoc} */
- @Override public byte type() {
+ @Override public byte cacheObjectType() {
return TYPE_BYTE_ARR;
}
/** {@inheritDoc} */
+ @Override public boolean isPlatformType() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
@Override public CacheObject prepareForCache(CacheObjectContext ctx) {
return this;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
index 44b91a5..d49a029 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
@@ -17,15 +17,20 @@
package org.apache.ignite.internal.processors.cache;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
import org.apache.ignite.cache.affinity.AffinityKeyMapper;
import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.portable.PortableUtils;
import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
+import org.apache.ignite.internal.util.typedef.F;
/**
*
*/
-public class CacheObjectContext {
+@SuppressWarnings("TypeMayBeWeakened") public class CacheObjectContext {
/** */
private GridKernalContext kernalCtx;
@@ -60,12 +65,12 @@ public class CacheObjectContext {
boolean storeVal,
boolean addDepInfo) {
this.kernalCtx = kernalCtx;
- this.p2pEnabled = kernalCtx.config().isPeerClassLoadingEnabled();
this.dfltAffMapper = dfltAffMapper;
this.cpyOnGet = cpyOnGet;
this.storeVal = storeVal;
this.addDepInfo = addDepInfo;
+ p2pEnabled = kernalCtx.config().isPeerClassLoadingEnabled();
proc = kernalCtx.cacheObjects();
}
@@ -118,25 +123,124 @@ public class CacheObjectContext {
return proc;
}
+ /** {@inheritDoc} */
+ public Object unwrapPortableIfNeeded(Object o, boolean keepPortable) {
+ return unwrapPortableIfNeeded(o, keepPortable, true);
+ }
+
+ /** {@inheritDoc} */
+ public Object unwrapPortableIfNeeded(Object o, boolean keepPortable, boolean cpy) {
+ if (o == null)
+ return null;
+
+ return unwrapPortable(o, keepPortable, cpy);
+ }
+
+ /** {@inheritDoc} */
+ public Collection<Object> unwrapPortablesIfNeeded(Collection<Object> col, boolean keepPortable) {
+ return unwrapPortablesIfNeeded(col, keepPortable, true);
+ }
+
+ /** {@inheritDoc} */
+ public Collection<Object> unwrapPortablesIfNeeded(Collection<Object> col, boolean keepPortable, boolean cpy) {
+ if (col instanceof ArrayList)
+ return unwrapPortables((ArrayList<Object>)col, keepPortable, cpy);
+
+ if (col instanceof Set)
+ return unwrapPortables((Set<Object>)col, keepPortable, cpy);
+
+ Collection<Object> col0 = new ArrayList<>(col.size());
+
+ for (Object obj : col)
+ col0.add(unwrapPortable(obj, keepPortable, cpy));
+
+ return col0;
+ }
+
/**
- * Unwraps object.
+ * Unwraps map.
*
- * @param o Object to unwrap.
+ * @param map Map to unwrap.
* @param keepPortable Keep portable flag.
- * @return Unwrapped object.
+ * @return Unwrapped collection.
*/
- public Object unwrapPortableIfNeeded(Object o, boolean keepPortable) {
- return o;
+ private Map<Object, Object> unwrapPortablesIfNeeded(Map<Object, Object> map, boolean keepPortable, boolean cpy) {
+ if (keepPortable)
+ return map;
+
+ Map<Object, Object> map0 = PortableUtils.newMap(map);
+
+ for (Map.Entry<Object, Object> e : map.entrySet())
+ map0.put(unwrapPortable(e.getKey(), keepPortable, cpy), unwrapPortable(e.getValue(), keepPortable, cpy));
+
+ return map0;
}
/**
- * Unwraps collection.
+ * Unwraps array list.
*
- * @param col Collection to unwrap.
- * @param keepPortable Keep portable flag.
- * @return Unwrapped collection.
+ * @param col List to unwrap.
+ * @return Unwrapped list.
*/
- public Collection<Object> unwrapPortablesIfNeeded(Collection<Object> col, boolean keepPortable) {
+ private Collection<Object> unwrapPortables(ArrayList<Object> col, boolean keepPortable, boolean cpy) {
+ int size = col.size();
+
+ for (int i = 0; i < size; i++) {
+ Object o = col.get(i);
+
+ Object unwrapped = unwrapPortable(o, keepPortable, cpy);
+
+ if (o != unwrapped)
+ col.set(i, unwrapped);
+ }
+
return col;
}
+
+ /**
+ * Unwraps set with binary.
+ *
+ * @param set Set to unwrap.
+ * @return Unwrapped set.
+ */
+ private Set<Object> unwrapPortables(Set<Object> set, boolean keepPortable, boolean cpy) {
+ Set<Object> set0 = PortableUtils.newSet(set);
+
+ for (Object obj : set)
+ set0.add(unwrapPortable(obj, keepPortable, cpy));
+
+ return set0;
+ }
+
+ /**
+ * @param o Object to unwrap.
+ * @return Unwrapped object.
+ */
+ private Object unwrapPortable(Object o, boolean keepPortable, boolean cpy) {
+ if (o instanceof Map.Entry) {
+ Map.Entry entry = (Map.Entry)o;
+
+ Object key = entry.getKey();
+
+ Object uKey = unwrapPortable(key, keepPortable, cpy);
+
+ Object val = entry.getValue();
+
+ Object uVal = unwrapPortable(val, keepPortable, cpy);
+
+ return (key != uKey || val != uVal) ? F.t(uKey, uVal) : o;
+ }
+ else if (o instanceof Collection)
+ return unwrapPortablesIfNeeded((Collection<Object>)o, keepPortable, cpy);
+ else if (o instanceof Map)
+ return unwrapPortablesIfNeeded((Map<Object, Object>)o, keepPortable, cpy);
+ else if (o instanceof CacheObject) {
+ CacheObject co = (CacheObject)o;
+
+ if (!keepPortable || co.isPlatformType())
+ return unwrapPortable(co.value(this, true), keepPortable, cpy);
+ }
+
+ return o;
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
index 83a80b3..694027f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
@@ -47,6 +47,11 @@ public class CacheObjectImpl extends CacheObjectAdapter {
}
/** {@inheritDoc} */
+ @Override public boolean isPlatformType() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
cpy = cpy && needCopy(ctx);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationContext.java
index d551258..3993146 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationContext.java
@@ -43,7 +43,7 @@ public class CacheOperationContext implements Serializable {
private final UUID subjId;
/** Keep portable flag. */
- private final boolean keepPortable;
+ private final boolean keepBinary;
/** Expiry policy. */
private final ExpiryPolicy expiryPlc;
@@ -56,7 +56,7 @@ public class CacheOperationContext implements Serializable {
subjId = null;
- keepPortable = false;
+ keepBinary = false;
expiryPlc = null;
@@ -66,20 +66,20 @@ public class CacheOperationContext implements Serializable {
/**
* @param skipStore Skip store flag.
* @param subjId Subject ID.
- * @param keepPortable Keep portable flag.
+ * @param keepBinary Keep portable flag.
* @param expiryPlc Expiry policy.
*/
public CacheOperationContext(
boolean skipStore,
@Nullable UUID subjId,
- boolean keepPortable,
+ boolean keepBinary,
@Nullable ExpiryPolicy expiryPlc,
boolean noRetries) {
this.skipStore = skipStore;
this.subjId = subjId;
- this.keepPortable = keepPortable;
+ this.keepBinary = keepBinary;
this.expiryPlc = expiryPlc;
@@ -89,8 +89,8 @@ public class CacheOperationContext implements Serializable {
/**
* @return Keep portable flag.
*/
- public boolean isKeepPortable() {
- return keepPortable;
+ public boolean isKeepBinary() {
+ return keepBinary;
}
/**
@@ -98,7 +98,7 @@ public class CacheOperationContext implements Serializable {
*
* @return New instance of CacheOperationContext with keep portable flag.
*/
- public CacheOperationContext keepPortable() {
+ public CacheOperationContext keepBinary() {
return new CacheOperationContext(
skipStore,
subjId,
@@ -126,7 +126,7 @@ public class CacheOperationContext implements Serializable {
return new CacheOperationContext(
skipStore,
subjId,
- keepPortable,
+ keepBinary,
expiryPlc,
noRetries);
}
@@ -148,7 +148,7 @@ public class CacheOperationContext implements Serializable {
return new CacheOperationContext(
skipStore,
subjId,
- keepPortable,
+ keepBinary,
expiryPlc,
noRetries);
}
@@ -183,7 +183,7 @@ public class CacheOperationContext implements Serializable {
return new CacheOperationContext(
skipStore,
subjId,
- keepPortable,
+ keepBinary,
expiryPlc,
noRetries
);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 74951b5..0d0d3ff 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -809,9 +809,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
else
cacheVal = localCachePeek0(cacheKey, modes.heap, modes.offheap, modes.swap, plc);
- Object val = CU.value(cacheVal, ctx, true);
-
- val = ctx.unwrapPortableIfNeeded(val, ctx.keepPortable());
+ Object val = ctx.unwrapPortableIfNeeded(cacheVal, ctx.keepPortable());
return (V)val;
}
@@ -945,13 +943,13 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
if (doomed != null && ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED))
// Event notification.
ctx.events().addEvent(doomed.partition(), doomed.key(), locNodeId, (IgniteUuid)null, null,
- EVT_CACHE_ENTRY_DESTROYED, null, false, null, false, null, null, null);
+ EVT_CACHE_ENTRY_DESTROYED, null, false, null, false, null, null, null, true);
if (created != null) {
// Event notification.
if (ctx.events().isRecordable(EVT_CACHE_ENTRY_CREATED))
ctx.events().addEvent(created.partition(), created.key(), locNodeId, (IgniteUuid)null, null,
- EVT_CACHE_ENTRY_CREATED, null, false, null, false, null, null, null);
+ EVT_CACHE_ENTRY_CREATED, null, false, null, false, null, null, null, true);
if (touch)
ctx.evicts().touch(cur, topVer);
@@ -1046,7 +1044,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
if (ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED))
// Event notification.
ctx.events().addEvent(entry.partition(), entry.key(), locNodeId, (IgniteUuid)null, null,
- EVT_CACHE_ENTRY_DESTROYED, null, false, null, false, null, null, null);
+ EVT_CACHE_ENTRY_DESTROYED, null, false, null, false, null, null, null, false);
}
else if (log.isDebugEnabled())
log.debug("Remove will not be done for key (obsolete entry got replaced or removed): " + key);
@@ -1622,7 +1620,8 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
subjId,
null,
taskName,
- expiry);
+ expiry,
+ !deserializePortable);
if (res == null) {
if (storeEnabled) {
@@ -1824,7 +1823,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
@Override public IgniteInternalFuture<Map<K1, V1>> op(IgniteTxLocalAdapter tx) {
return tx.getAllAsync(ctx, keys, deserializePortable, skipVals, false, !readThrough);
}
- });
+ }, ctx.operationContextPerCall());
}
}
@@ -3988,11 +3987,11 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
IgniteTxLocalAdapter tx = ctx.tm().threadLocalTx(ctx);
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
if (tx == null || tx.implicit()) {
boolean skipStore = ctx.skipStore(); // Save value of thread-local flag.
- CacheOperationContext opCtx = ctx.operationContextPerCall();
-
int retries = opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES;
if (retries == 1) {
@@ -4006,10 +4005,10 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
!skipStore,
0);
- return asyncOp(tx, op);
+ return asyncOp(tx, op, opCtx);
}
else {
- AsyncOpRetryFuture<T> fut = new AsyncOpRetryFuture<>(op, skipStore, retries);
+ AsyncOpRetryFuture<T> fut = new AsyncOpRetryFuture<>(op, retries, opCtx);
fut.execute();
@@ -4017,7 +4016,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
}
}
else
- return asyncOp(tx, op);
+ return asyncOp(tx, op, opCtx);
}
/**
@@ -4027,7 +4026,11 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
* @return Future.
*/
@SuppressWarnings("unchecked")
- protected <T> IgniteInternalFuture<T> asyncOp(IgniteTxLocalAdapter tx, final AsyncOp<T> op) {
+ protected <T> IgniteInternalFuture<T> asyncOp(
+ IgniteTxLocalAdapter tx,
+ final AsyncOp<T> op,
+ final CacheOperationContext opCtx
+ ) {
IgniteInternalFuture<T> fail = asyncOpAcquire();
if (fail != null)
@@ -4050,24 +4053,31 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
return new GridFinishedFuture<>(
new IgniteCheckedException("Operation has been cancelled (node is stopping)."));
- return op.op(tx0).chain(new CX1<IgniteInternalFuture<T>, T>() {
- @Override public T applyx(IgniteInternalFuture<T> tFut) throws IgniteCheckedException {
- try {
- return tFut.get();
- }
- catch (IgniteTxRollbackCheckedException e) {
- throw e;
- }
- catch (IgniteCheckedException e1) {
- tx0.rollbackAsync();
+ ctx.operationContextPerCall(opCtx);
- throw e1;
- }
- finally {
- ctx.shared().txContextReset();
+ try {
+ return op.op(tx0).chain(new CX1<IgniteInternalFuture<T>, T>() {
+ @Override public T applyx(IgniteInternalFuture<T> tFut) throws IgniteCheckedException {
+ try {
+ return tFut.get();
+ }
+ catch (IgniteTxRollbackCheckedException e) {
+ throw e;
+ }
+ catch (IgniteCheckedException e1) {
+ tx0.rollbackAsync();
+
+ throw e1;
+ }
+ finally {
+ ctx.shared().txContextReset();
+ }
}
- }
- });
+ });
+ }
+ finally {
+ ctx.operationContextPerCall(null);
+ }
}
});
@@ -4605,7 +4615,8 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
null,
null,
null,
- null);
+ null,
+ !deserializePortable);
if (val == null)
return null;
@@ -4631,28 +4642,31 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
private AsyncOp<T> op;
/** */
- private boolean skipStore;
-
- /** */
private int retries;
/** */
private IgniteTxLocalAdapter tx;
+ /** */
+ private CacheOperationContext opCtx;
+
/**
* @param op Operation.
- * @param skipStore Skip store flag.
* @param retries Number of retries.
+ * @param opCtx Operation context per call to save.
*/
- public AsyncOpRetryFuture(AsyncOp<T> op,
- boolean skipStore,
- int retries) {
+ public AsyncOpRetryFuture(
+ AsyncOp<T> op,
+ int retries,
+ CacheOperationContext opCtx
+ ) {
assert retries > 1 : retries;
+ tx = null;
+
this.op = op;
- this.tx = null;
- this.skipStore = skipStore;
this.retries = retries;
+ this.opCtx = opCtx;
}
/**
@@ -4666,10 +4680,10 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
OPTIMISTIC,
READ_COMMITTED,
ctx.kernalContext().config().getTransactionConfiguration().getDefaultTxTimeout(),
- !skipStore,
+ opCtx == null || !opCtx.skipStore(),
0);
- IgniteInternalFuture<T> fut = asyncOp(tx, op);
+ IgniteInternalFuture<T> fut = asyncOp(tx, op, opCtx);
fut.listen(new IgniteInClosure<IgniteInternalFuture<T>>() {
@Override public void apply(IgniteInternalFuture<T> fut) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
index 1be7c07..fac704b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
@@ -1878,7 +1878,7 @@ public class GridCacheConcurrentMap {
* @return Key iterator.
*/
Iterator<K> keyIterator() {
- return new KeyIterator<>(map, filter);
+ return new KeyIterator<>(map, opCtxPerCall != null && opCtxPerCall.isKeepBinary(), filter);
}
/**
@@ -2156,6 +2156,9 @@ public class GridCacheConcurrentMap {
/** Hash table iterator. */
private Iterator0<K, V> it;
+ /** Keep binary flag. */
+ private boolean keepBinary;
+
/**
* Empty constructor required for {@link Externalizable}.
*/
@@ -2167,8 +2170,9 @@ public class GridCacheConcurrentMap {
* @param map Cache map.
* @param filter Filter.
*/
- private KeyIterator(GridCacheConcurrentMap map, CacheEntryPredicate[] filter) {
+ private KeyIterator(GridCacheConcurrentMap map, boolean keepBinary, CacheEntryPredicate[] filter) {
it = new Iterator0<>(map, false, filter, -1, -1);
+ this.keepBinary = keepBinary;
}
/** {@inheritDoc} */
@@ -2178,7 +2182,7 @@ public class GridCacheConcurrentMap {
/** {@inheritDoc} */
@Override public K next() {
- return it.next().key().value(it.ctx.cacheObjectContext(), true);
+ return (K)it.ctx.cacheObjectContext().unwrapPortableIfNeeded(it.next().key(), keepBinary, true);
}
/** {@inheritDoc} */
[13/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
index 8446665..0afd6bc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
@@ -49,7 +49,6 @@ import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException;
-import org.apache.ignite.internal.processors.cache.GridCacheFilterFailedException;
import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
import org.apache.ignite.internal.processors.cache.GridCacheMapEntryFactory;
import org.apache.ignite.internal.processors.cache.GridCacheOperation;
@@ -144,6 +143,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
@Override public V getAndPut(K key, V val, @Nullable CacheEntryPredicate[] filter) throws IgniteCheckedException {
A.notNull(key, "key", val, "val");
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
return (V)updateAllInternal(UPDATE,
Collections.singleton(key),
Collections.singleton(val),
@@ -153,7 +154,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
false,
filter,
ctx.writeThrough(),
- ctx.readThrough());
+ ctx.readThrough(),
+ opCtx != null && opCtx.isKeepBinary());
}
/** {@inheritDoc} */
@@ -164,6 +166,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
long start = statsEnabled ? System.nanoTime() : 0L;
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
boolean res = (Boolean)updateAllInternal(UPDATE,
Collections.singleton(key),
Collections.singleton(val),
@@ -173,7 +177,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
false,
filter,
ctx.writeThrough(),
- ctx.readThrough());
+ ctx.readThrough(),
+ opCtx != null && opCtx.isKeepBinary());
if (statsEnabled)
metrics0().addPutTimeNanos(System.nanoTime() - start);
@@ -275,7 +280,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
true,
ctx.equalsValArray(oldVal),
ctx.writeThrough(),
- ctx.readThrough());
+ ctx.readThrough(),
+ ctx.operationContextPerCall().isKeepBinary());
}
/** {@inheritDoc} */
@@ -292,7 +298,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
true,
ctx.equalsValArray(val),
ctx.writeThrough(),
- ctx.readThrough());
+ ctx.readThrough(),
+ ctx.operationContextPerCall().isKeepBinary());
}
/** {@inheritDoc} */
@@ -322,6 +329,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
long start = statsEnabled ? System.nanoTime() : 0L;
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
updateAllInternal(UPDATE,
m.keySet(),
m.values(),
@@ -331,7 +340,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
false,
CU.empty0(),
ctx.writeThrough(),
- ctx.readThrough());
+ ctx.readThrough(),
+ opCtx != null && opCtx.isKeepBinary());
if (statsEnabled)
metrics0().addPutTimeNanos(System.nanoTime() - start);
@@ -350,6 +360,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public V getAndRemove(K key) throws IgniteCheckedException {
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
return (V)updateAllInternal(DELETE,
Collections.singleton(key),
null,
@@ -359,7 +371,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
false,
CU.empty0(),
ctx.writeThrough(),
- ctx.readThrough());
+ ctx.readThrough(),
+ opCtx != null && opCtx.isKeepBinary());
}
/** {@inheritDoc} */
@@ -371,6 +384,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public void removeAll(Collection<? extends K> keys) throws IgniteCheckedException {
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
updateAllInternal(DELETE,
keys,
null,
@@ -380,7 +395,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
false,
CU.empty0(),
ctx.writeThrough(),
- ctx.readThrough());
+ ctx.readThrough(),
+ opCtx != null && opCtx.isKeepBinary());
}
/** {@inheritDoc} */
@@ -397,6 +413,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
A.notNull(key, "key");
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
Boolean rmv = (Boolean)updateAllInternal(DELETE,
Collections.singleton(key),
null,
@@ -406,7 +424,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
false,
CU.empty0(),
ctx.writeThrough(),
- ctx.readThrough());
+ ctx.readThrough(),
+ opCtx != null && opCtx.isKeepBinary());
if (statsEnabled && rmv)
metrics0().addRemoveTimeNanos(System.nanoTime() - start);
@@ -426,6 +445,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
@Override public boolean remove(K key, V val) throws IgniteCheckedException {
A.notNull(key, "key", val, "val");
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
return (Boolean)updateAllInternal(DELETE,
Collections.singleton(key),
null,
@@ -435,7 +456,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
false,
ctx.equalsValArray(val),
ctx.writeThrough(),
- ctx.readThrough());
+ ctx.readThrough(),
+ opCtx != null && opCtx.isKeepBinary());
}
/** {@inheritDoc} */
@@ -575,7 +597,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
subjId,
null,
taskName,
- expiry);
+ expiry,
+ !deserializePortable);
if (v != null)
ctx.addResult(vals, cacheKey, v, skipVals, false, deserializePortable, true);
@@ -644,6 +667,10 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
}
});
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
+ final boolean keepPortable = opCtx != null && opCtx.isKeepBinary();
+
return (Map<K, EntryProcessorResult<T>>)updateAllInternal(TRANSFORM,
invokeMap.keySet(),
invokeMap.values(),
@@ -653,7 +680,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
false,
null,
ctx.writeThrough(),
- ctx.readThrough());
+ ctx.readThrough(),
+ keepPortable);
}
/** {@inheritDoc} */
@@ -727,6 +755,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
if (keyCheck)
validateCacheKeys(map.keySet());
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
return (Map<K, EntryProcessorResult<T>>)updateAllInternal(TRANSFORM,
map.keySet(),
map.values(),
@@ -736,7 +766,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
false,
null,
ctx.writeThrough(),
- ctx.readThrough());
+ ctx.readThrough(),
+ opCtx != null && opCtx.isKeepBinary());
}
/** {@inheritDoc} */
@@ -787,8 +818,12 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
final boolean readThrough = ctx.readThrough();
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
final ExpiryPolicy expiry = expiryPerCall();
+ final boolean keepPortable = opCtx != null && opCtx.isKeepBinary();
+
IgniteInternalFuture fut = asyncOp(new Callable<Object>() {
@Override public Object call() throws Exception {
return updateAllInternal(op,
@@ -800,7 +835,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
rawRetval,
filter,
writeThrough,
- readThrough);
+ readThrough,
+ keepPortable);
}
});
@@ -835,6 +871,10 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
final ExpiryPolicy expiryPlc = expiryPerCall();
+ CacheOperationContext opCtx = ctx.operationContextPerCall();
+
+ final boolean keepPortable = opCtx != null && opCtx.isKeepBinary();
+
IgniteInternalFuture fut = asyncOp(new Callable<Object>() {
@Override public Object call() throws Exception {
return updateAllInternal(DELETE,
@@ -846,7 +886,8 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
rawRetval,
filter,
writeThrough,
- readThrough);
+ readThrough,
+ keepPortable);
}
});
@@ -882,7 +923,9 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
boolean rawRetval,
CacheEntryPredicate[] filter,
boolean writeThrough,
- boolean readThrough) throws IgniteCheckedException {
+ boolean readThrough,
+ boolean keepPortable
+ ) throws IgniteCheckedException {
if (keyCheck)
validateCacheKeys(keys);
@@ -905,6 +948,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
expiryPlc,
ver,
filter,
+ keepPortable,
subjId,
taskName);
}
@@ -945,6 +989,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
writeThrough,
readThrough,
retval,
+ keepPortable,
expiryPlc,
true,
true,
@@ -999,7 +1044,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
if (err != null)
throw err;
- Object ret = res == null ? null : rawRetval ? new GridCacheReturn(ctx, true, res.get2(), res.get1()) :
+ Object ret = res == null ? null : rawRetval ? new GridCacheReturn(ctx, true, keepPortable, res.get2(), res.get1()) :
(retval || op == TRANSFORM) ? res.get2() : res.get1();
if (op == TRANSFORM && ret == null)
@@ -1032,6 +1077,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
@Nullable ExpiryPolicy expiryPlc,
GridCacheVersion ver,
@Nullable CacheEntryPredicate[] filter,
+ boolean keepPortable,
UUID subjId,
String taskName
) throws IgniteCheckedException {
@@ -1099,12 +1145,13 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
subjId,
entryProcessor,
taskName,
- null);
+ null,
+ keepPortable);
Object oldVal = null;
CacheInvokeEntry<Object, Object> invokeEntry = new CacheInvokeEntry<>(ctx, entry.key(), old,
- entry.version());
+ entry.version(), keepPortable);
CacheObject updated;
Object updatedVal = null;
@@ -1133,7 +1180,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
if (intercept) {
IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor()
.onBeforeRemove(new CacheLazyEntry(ctx, entry.key(), invokeEntry.key(),
- old, oldVal));
+ old, oldVal, keepPortable));
if (ctx.cancelRemove(interceptorRes))
continue;
@@ -1148,6 +1195,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
putMap,
null,
expiryPlc,
+ keepPortable,
err,
subjId,
taskName);
@@ -1168,7 +1216,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
if (intercept) {
Object interceptorVal = ctx.config().getInterceptor()
.onBeforePut(new CacheLazyEntry(ctx, entry.key(), invokeEntry.getKey(),
- old, oldVal), updatedVal);
+ old, oldVal, keepPortable), updatedVal);
if (interceptorVal == null)
continue;
@@ -1185,6 +1233,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
null,
rmvKeys,
expiryPlc,
+ keepPortable,
err,
subjId,
taskName);
@@ -1218,10 +1267,11 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
subjId,
null,
taskName,
- null);
+ null,
+ keepPortable);
Object interceptorVal = ctx.config().getInterceptor().onBeforePut(new CacheLazyEntry(
- ctx, entry.key(), old), val);
+ ctx, entry.key(), old, keepPortable), val);
if (interceptorVal == null)
continue;
@@ -1252,10 +1302,11 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
subjId,
null,
taskName,
- null);
+ null,
+ keepPortable);
IgniteBiTuple<Boolean, ?> interceptorRes = ctx.config().getInterceptor()
- .onBeforeRemove(new CacheLazyEntry(ctx, entry.key(), old));
+ .onBeforeRemove(new CacheLazyEntry(ctx, entry.key(), old, keepPortable));
if (ctx.cancelRemove(interceptorRes))
continue;
@@ -1289,6 +1340,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
putMap,
rmvKeys,
expiryPlc,
+ keepPortable,
err,
subjId,
taskName);
@@ -1326,6 +1378,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
@Nullable Map<Object, Object> putMap,
@Nullable Collection<Object> rmvKeys,
@Nullable ExpiryPolicy expiryPlc,
+ boolean keepPortable,
@Nullable CachePartialUpdateCheckedException err,
UUID subjId,
String taskName
@@ -1395,6 +1448,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
false,
false,
false,
+ keepPortable,
expiryPlc,
true,
true,
@@ -1405,9 +1459,9 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
if (intercept) {
if (op == UPDATE)
- ctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(ctx, entry.key(), writeVal));
+ ctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(ctx, entry.key(), writeVal, keepPortable));
else
- ctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(ctx, entry.key(), t.get2()));
+ ctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(ctx, entry.key(), t.get2(), keepPortable));
}
}
catch (GridCacheEntryRemovedException ignore) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java
index 23edd9e..1a2ef7b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java
@@ -21,7 +21,7 @@ import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.IgniteKernal;
import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.binary.BinaryObject;
/**
*
@@ -34,7 +34,7 @@ public class CacheDefaultPortableAffinityKeyMapper extends GridCacheDefaultAffin
@Override public Object affinityKey(Object key) {
IgniteKernal kernal = (IgniteKernal)ignite;
- CacheObjectPortableProcessorImpl proc = (CacheObjectPortableProcessorImpl)kernal.context().cacheObjects();
+ CacheObjectBinaryProcessorImpl proc = (CacheObjectBinaryProcessorImpl)kernal.context().cacheObjects();
try {
key = proc.toPortable(key);
@@ -43,8 +43,8 @@ public class CacheDefaultPortableAffinityKeyMapper extends GridCacheDefaultAffin
U.error(log, "Failed to marshal key to portable: " + key, e);
}
- if (key instanceof PortableObject)
- return proc.affinityKey((PortableObject)key);
+ if (key instanceof BinaryObject)
+ return proc.affinityKey((BinaryObject)key);
else
return super.affinityKey(key);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessor.java
new file mode 100644
index 0000000..7178a94
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessor.java
@@ -0,0 +1,103 @@
+/*
+ * 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.cache.portable;
+
+import java.util.Collection;
+import java.util.Map;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Extended cache object processor interface with additional methods for binary.
+ */
+public interface CacheObjectBinaryProcessor extends IgniteCacheObjectProcessor {
+ /**
+ * @param typeId Type ID.
+ * @return Builder.
+ */
+ public BinaryObjectBuilder builder(int typeId);
+
+ /**
+ * @param clsName Class name.
+ * @return Builder.
+ */
+ public BinaryObjectBuilder builder(String clsName);
+
+ /**
+ * Creates builder initialized by existing portable object.
+ *
+ * @param portableObj Portable object to edit.
+ * @return Portable builder.
+ */
+ public BinaryObjectBuilder builder(BinaryObject portableObj);
+
+ /**
+ * @param typeId Type ID.
+ * @param newMeta New meta data.
+ * @throws IgniteException In case of error.
+ */
+ public void addMeta(int typeId, final BinaryType newMeta) throws IgniteException;
+
+ /**
+ * @param typeId Type ID.
+ * @param typeName Type name.
+ * @param affKeyFieldName Affinity key field name.
+ * @param fieldTypeIds Fields map.
+ * @throws IgniteException In case of error.
+ */
+ public void updateMetaData(int typeId, String typeName, @Nullable String affKeyFieldName,
+ Map<String, Integer> fieldTypeIds) throws IgniteException;
+
+ /**
+ * @param typeId Type ID.
+ * @return Meta data.
+ * @throws IgniteException In case of error.
+ */
+ @Nullable public BinaryType metadata(int typeId) throws IgniteException;
+
+ /**
+ * @param typeIds Type ID.
+ * @return Meta data.
+ * @throws IgniteException In case of error.
+ */
+ public Map<Integer, BinaryType> metadata(Collection<Integer> typeIds) throws IgniteException;
+
+ /**
+ * @return Metadata for all types.
+ * @throws IgniteException In case of error.
+ */
+ public Collection<BinaryType> metadata() throws IgniteException;
+
+ /**
+ * @return Portables interface.
+ * @throws IgniteException If failed.
+ */
+ public IgniteBinary binary() throws IgniteException;
+
+ /**
+ * @param obj Original object.
+ * @return Portable object (in case portable marshaller is used).
+ * @throws IgniteException If failed.
+ */
+ public Object marshalToPortable(Object obj) throws IgniteException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessorImpl.java
new file mode 100644
index 0000000..df8e7f9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessorImpl.java
@@ -0,0 +1,1046 @@
+/*
+ * 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.cache.portable;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import javax.cache.Cache;
+import javax.cache.CacheException;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryListenerException;
+import javax.cache.event.CacheEntryUpdatedListener;
+import javax.cache.event.EventType;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterTopologyException;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.portable.GridPortableMarshaller;
+import org.apache.ignite.internal.portable.PortableContext;
+import org.apache.ignite.internal.portable.PortableMetaDataHandler;
+import org.apache.ignite.internal.portable.BinaryMetaDataImpl;
+import org.apache.ignite.internal.portable.BinaryObjectImpl;
+import org.apache.ignite.internal.portable.BinaryObjectOffheapImpl;
+import org.apache.ignite.internal.portable.PortableUtils;
+import org.apache.ignite.internal.portable.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.portable.streams.PortableInputStream;
+import org.apache.ignite.internal.portable.streams.PortableOffheapInputStream;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
+import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapter;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.GridCacheUtils;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.query.CacheQuery;
+import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture;
+import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessorImpl;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.C1;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+import sun.misc.Unsafe;
+
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.CLASS;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.COL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP_ENTRY;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.PORTABLE_OBJ;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP_ARR;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID_ARR;
+
+/**
+ * Portable processor implementation.
+ */
+public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorImpl implements
+ CacheObjectBinaryProcessor {
+ /** */
+ public static final String[] FIELD_TYPE_NAMES;
+
+ /** */
+ private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+ /** */
+ private final CountDownLatch startLatch = new CountDownLatch(1);
+
+ /** */
+ private final boolean clientNode;
+
+ /** */
+ private volatile IgniteCacheProxy<PortableMetaDataKey, BinaryType> metaDataCache;
+
+ /** */
+ private final ConcurrentHashMap8<PortableMetaDataKey, BinaryType> clientMetaDataCache;
+
+ /** Predicate to filter portable meta data in utility cache. */
+ private final CacheEntryPredicate metaPred = new CacheEntryPredicateAdapter() {
+ private static final long serialVersionUID = 0L;
+
+ @Override public boolean apply(GridCacheEntryEx e) {
+ return e.key().value(e.context().cacheObjectContext(), false) instanceof PortableMetaDataKey;
+ }
+ };
+
+ /** */
+ private PortableContext portableCtx;
+
+ /** */
+ private Marshaller marsh;
+
+ /** */
+ private GridPortableMarshaller portableMarsh;
+
+ /** */
+ @GridToStringExclude
+ private IgniteBinary portables;
+
+ /** Metadata updates collected before metadata cache is initialized. */
+ private final Map<Integer, BinaryType> metaBuf = new ConcurrentHashMap<>();
+
+ /** */
+ private UUID metaCacheQryId;
+
+ /**
+ *
+ */
+ static {
+ FIELD_TYPE_NAMES = new String[104];
+
+ FIELD_TYPE_NAMES[BYTE] = "byte";
+ FIELD_TYPE_NAMES[SHORT] = "short";
+ FIELD_TYPE_NAMES[INT] = "int";
+ FIELD_TYPE_NAMES[LONG] = "long";
+ FIELD_TYPE_NAMES[BOOLEAN] = "boolean";
+ FIELD_TYPE_NAMES[FLOAT] = "float";
+ FIELD_TYPE_NAMES[DOUBLE] = "double";
+ FIELD_TYPE_NAMES[CHAR] = "char";
+ FIELD_TYPE_NAMES[UUID] = "UUID";
+ FIELD_TYPE_NAMES[DECIMAL] = "decimal";
+ FIELD_TYPE_NAMES[STRING] = "String";
+ FIELD_TYPE_NAMES[DATE] = "Date";
+ FIELD_TYPE_NAMES[TIMESTAMP] = "Timestamp";
+ FIELD_TYPE_NAMES[ENUM] = "Enum";
+ FIELD_TYPE_NAMES[OBJ] = "Object";
+ FIELD_TYPE_NAMES[PORTABLE_OBJ] = "Object";
+ FIELD_TYPE_NAMES[COL] = "Collection";
+ FIELD_TYPE_NAMES[MAP] = "Map";
+ FIELD_TYPE_NAMES[MAP_ENTRY] = "Entry";
+ FIELD_TYPE_NAMES[CLASS] = "Class";
+ FIELD_TYPE_NAMES[BYTE_ARR] = "byte[]";
+ FIELD_TYPE_NAMES[SHORT_ARR] = "short[]";
+ FIELD_TYPE_NAMES[INT_ARR] = "int[]";
+ FIELD_TYPE_NAMES[LONG_ARR] = "long[]";
+ FIELD_TYPE_NAMES[BOOLEAN_ARR] = "boolean[]";
+ FIELD_TYPE_NAMES[FLOAT_ARR] = "float[]";
+ FIELD_TYPE_NAMES[DOUBLE_ARR] = "double[]";
+ FIELD_TYPE_NAMES[CHAR_ARR] = "char[]";
+ FIELD_TYPE_NAMES[UUID_ARR] = "UUID[]";
+ FIELD_TYPE_NAMES[DECIMAL_ARR] = "decimal[]";
+ FIELD_TYPE_NAMES[STRING_ARR] = "String[]";
+ FIELD_TYPE_NAMES[DATE_ARR] = "Date[]";
+ FIELD_TYPE_NAMES[TIMESTAMP_ARR] = "Timestamp[]";
+ FIELD_TYPE_NAMES[OBJ_ARR] = "Object[]";
+ FIELD_TYPE_NAMES[ENUM_ARR] = "Enum[]";
+ }
+
+ /**
+ * @param typeName Field type name.
+ * @return Field type ID;
+ */
+ @SuppressWarnings("StringEquality")
+ public static int fieldTypeId(String typeName) {
+ for (int i = 0; i < FIELD_TYPE_NAMES.length; i++) {
+ String typeName0 = FIELD_TYPE_NAMES[i];
+
+ if (typeName.equals(typeName0))
+ return i;
+ }
+
+ throw new IllegalArgumentException("Invalid metadata type name: " + typeName);
+ }
+
+ /**
+ * @param typeId Field type ID.
+ * @return Field type name.
+ */
+ public static String fieldTypeName(int typeId) {
+ assert typeId >= 0 && typeId < FIELD_TYPE_NAMES.length : typeId;
+
+ String typeName = FIELD_TYPE_NAMES[typeId];
+
+ assert typeName != null : typeId;
+
+ return typeName;
+ }
+
+ /**
+ * @param typeIds Field type IDs.
+ * @return Field type names.
+ */
+ public static Map<String, String> fieldTypeNames(Map<String, Integer> typeIds) {
+ Map<String, String> names = U.newHashMap(typeIds.size());
+
+ for (Map.Entry<String, Integer> e : typeIds.entrySet())
+ names.put(e.getKey(), fieldTypeName(e.getValue()));
+
+ return names;
+ }
+
+ /**
+ * @param ctx Kernal context.
+ */
+ public CacheObjectBinaryProcessorImpl(GridKernalContext ctx) {
+ super(ctx);
+
+ marsh = ctx.grid().configuration().getMarshaller();
+
+ clientNode = this.ctx.clientNode();
+
+ clientMetaDataCache = clientNode ? new ConcurrentHashMap8<PortableMetaDataKey, BinaryType>() : null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void start() throws IgniteCheckedException {
+ if (marsh instanceof PortableMarshaller) {
+ PortableMetaDataHandler metaHnd = new PortableMetaDataHandler() {
+ @Override public void addMeta(int typeId, BinaryType newMeta)
+ throws BinaryObjectException {
+ if (metaDataCache == null) {
+ BinaryType oldMeta = metaBuf.get(typeId);
+
+ if (oldMeta == null || checkMeta(typeId, oldMeta, newMeta, null)) {
+ synchronized (this) {
+ Map<String, String> fields = new HashMap<>();
+
+ if (checkMeta(typeId, oldMeta, newMeta, fields)) {
+ newMeta = new BinaryMetaDataImpl(newMeta.typeName(),
+ fields,
+ newMeta.affinityKeyFieldName());
+
+ metaBuf.put(typeId, newMeta);
+ }
+ else
+ return;
+ }
+
+ if (metaDataCache == null)
+ return;
+ else
+ metaBuf.remove(typeId);
+ }
+ else
+ return;
+ }
+
+ CacheObjectBinaryProcessorImpl.this.addMeta(typeId, newMeta);
+ }
+
+ @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
+ if (metaDataCache == null)
+ U.awaitQuiet(startLatch);
+
+ return CacheObjectBinaryProcessorImpl.this.metadata(typeId);
+ }
+ };
+
+ PortableMarshaller pMarh0 = (PortableMarshaller)marsh;
+
+ portableCtx = new PortableContext(metaHnd, ctx.config());
+
+ IgniteUtils.invoke(PortableMarshaller.class, pMarh0, "setPortableContext", portableCtx);
+
+ portableMarsh = new GridPortableMarshaller(portableCtx);
+
+ portables = new IgniteBinaryImpl(ctx, this);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override public void onUtilityCacheStarted() throws IgniteCheckedException {
+ metaDataCache = ctx.cache().jcache(CU.UTILITY_CACHE_NAME);
+
+ if (clientNode) {
+ assert !metaDataCache.context().affinityNode();
+
+ metaCacheQryId = metaDataCache.context().continuousQueries().executeInternalQuery(
+ new MetaDataEntryListener(),
+ new MetaDataEntryFilter(),
+ false,
+ true);
+
+ while (true) {
+ ClusterNode oldestSrvNode =
+ CU.oldestAliveCacheServerNode(ctx.cache().context(), AffinityTopologyVersion.NONE);
+
+ if (oldestSrvNode == null)
+ break;
+
+ GridCacheQueryManager qryMgr = metaDataCache.context().queries();
+
+ CacheQuery<Map.Entry<PortableMetaDataKey, BinaryType>> qry =
+ qryMgr.createScanQuery(new MetaDataPredicate(), null, false);
+
+ qry.keepAll(false);
+
+ qry.projection(ctx.cluster().get().forNode(oldestSrvNode));
+
+ try {
+ CacheQueryFuture<Map.Entry<PortableMetaDataKey, BinaryType>> fut = qry.execute();
+
+ Map.Entry<PortableMetaDataKey, BinaryType> next;
+
+ while ((next = fut.next()) != null) {
+ assert next.getKey() != null : next;
+ assert next.getValue() != null : next;
+
+ addClientCacheMetaData(next.getKey(), next.getValue());
+ }
+ }
+ catch (IgniteCheckedException e) {
+ if (!ctx.discovery().alive(oldestSrvNode) || !ctx.discovery().pingNode(oldestSrvNode.id()))
+ continue;
+ else
+ throw e;
+ }
+ catch (CacheException e) {
+ if (X.hasCause(e, ClusterTopologyCheckedException.class, ClusterTopologyException.class))
+ continue;
+ else
+ throw e;
+ }
+
+ break;
+ }
+ }
+
+ startLatch.countDown();
+
+ for (Map.Entry<Integer, BinaryType> e : metaBuf.entrySet())
+ addMeta(e.getKey(), e.getValue());
+
+ metaBuf.clear();
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onKernalStop(boolean cancel) {
+ super.onKernalStop(cancel);
+
+ if (metaCacheQryId != null)
+ metaDataCache.context().continuousQueries().cancelInternalQuery(metaCacheQryId);
+ }
+
+ /**
+ * @param key Metadata key.
+ * @param newMeta Metadata.
+ */
+ private void addClientCacheMetaData(PortableMetaDataKey key, final BinaryType newMeta) {
+ clientMetaDataCache.compute(key,
+ new ConcurrentHashMap8.BiFun<PortableMetaDataKey, BinaryType, BinaryType>() {
+ @Override public BinaryType apply(PortableMetaDataKey key, BinaryType oldMeta) {
+ BinaryType res;
+
+ try {
+ res = checkMeta(key.typeId(), oldMeta, newMeta, null) ? newMeta : oldMeta;
+ }
+ catch (BinaryObjectException e) {
+ res = oldMeta;
+ }
+
+ return res;
+ }
+ }
+ );
+ }
+
+ /** {@inheritDoc} */
+ @Override public int typeId(String typeName) {
+ if (portableCtx == null)
+ return super.typeId(typeName);
+
+ return portableCtx.typeId(typeName);
+ }
+
+ /**
+ * @param obj Object.
+ * @return Bytes.
+ * @throws org.apache.ignite.binary.BinaryObjectException If failed.
+ */
+ public byte[] marshal(@Nullable Object obj) throws BinaryObjectException {
+ byte[] arr = portableMarsh.marshal(obj);
+
+ assert arr.length > 0;
+
+ return arr;
+ }
+
+ /**
+ * @param ptr Off-heap pointer.
+ * @param forceHeap If {@code true} creates heap-based object.
+ * @return Object.
+ * @throws org.apache.ignite.binary.BinaryObjectException If failed.
+ */
+ public Object unmarshal(long ptr, boolean forceHeap) throws BinaryObjectException {
+ assert ptr > 0 : ptr;
+
+ int size = UNSAFE.getInt(ptr);
+
+ ptr += 4;
+
+ byte type = UNSAFE.getByte(ptr++);
+
+ if (type != CacheObject.TYPE_BYTE_ARR) {
+ assert size > 0 : size;
+
+ PortableInputStream in = new PortableOffheapInputStream(ptr, size, forceHeap);
+
+ return portableMarsh.unmarshal(in);
+ }
+ else
+ return U.copyMemory(ptr, size);
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object marshalToPortable(@Nullable Object obj) throws BinaryObjectException {
+ if (obj == null)
+ return null;
+
+ if (PortableUtils.isPortableType(obj.getClass()))
+ return obj;
+
+ if (obj instanceof Object[]) {
+ Object[] arr = (Object[])obj;
+
+ Object[] pArr = new Object[arr.length];
+
+ for (int i = 0; i < arr.length; i++)
+ pArr[i] = marshalToPortable(arr[i]);
+
+ return pArr;
+ }
+
+ if (obj instanceof Collection) {
+ Collection<Object> col = (Collection<Object>)obj;
+
+ Collection<Object> pCol;
+
+ if (col instanceof Set)
+ pCol = (Collection<Object>)PortableUtils.newSet((Set<?>)col);
+ else
+ pCol = new ArrayList<>(col.size());
+
+ for (Object item : col)
+ pCol.add(marshalToPortable(item));
+
+ return pCol;
+ }
+
+ if (obj instanceof Map) {
+ Map<?, ?> map = (Map<?, ?>)obj;
+
+ Map<Object, Object> pMap = PortableUtils.newMap((Map<Object, Object>)obj);
+
+ for (Map.Entry<?, ?> e : map.entrySet())
+ pMap.put(marshalToPortable(e.getKey()), marshalToPortable(e.getValue()));
+
+ return pMap;
+ }
+
+ if (obj instanceof Map.Entry) {
+ Map.Entry<?, ?> e = (Map.Entry<?, ?>)obj;
+
+ return new GridMapEntry<>(marshalToPortable(e.getKey()), marshalToPortable(e.getValue()));
+ }
+
+ byte[] arr = portableMarsh.marshal(obj);
+
+ assert arr.length > 0;
+
+ Object obj0 = portableMarsh.unmarshal(arr, null);
+
+ assert obj0 instanceof BinaryObject;
+
+ ((BinaryObjectImpl)obj0).detachAllowed(true);
+
+ return obj0;
+ }
+
+ /**
+ * @return Marshaller.
+ */
+ public GridPortableMarshaller marshaller() {
+ return portableMarsh;
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilder builder(int typeId) {
+ return new BinaryObjectBuilderImpl(portableCtx, typeId);
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilder builder(String clsName) {
+ return new BinaryObjectBuilderImpl(portableCtx, clsName);
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilder builder(BinaryObject portableObj) {
+ return BinaryObjectBuilderImpl.wrap(portableObj);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void updateMetaData(int typeId, String typeName, @Nullable String affKeyFieldName,
+ Map<String, Integer> fieldTypeIds) throws BinaryObjectException {
+ portableCtx.updateMetaData(typeId,
+ new BinaryMetaDataImpl(typeName, fieldTypeNames(fieldTypeIds), affKeyFieldName));
+ }
+
+ /** {@inheritDoc} */
+ @Override public void addMeta(final int typeId, final BinaryType newMeta) throws BinaryObjectException {
+ assert newMeta != null;
+
+ final PortableMetaDataKey key = new PortableMetaDataKey(typeId);
+
+ try {
+ BinaryType oldMeta = metaDataCache.localPeek(key);
+
+ if (oldMeta == null || checkMeta(typeId, oldMeta, newMeta, null)) {
+ BinaryObjectException err = metaDataCache.invoke(key, new MetaDataProcessor(typeId, newMeta));
+
+ if (err != null)
+ throw err;
+ }
+ }
+ catch (CacheException e) {
+ throw new BinaryObjectException("Failed to update meta data for type: " + newMeta.typeName(), e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public BinaryType metadata(final int typeId) throws BinaryObjectException {
+ try {
+ if (clientNode)
+ return clientMetaDataCache.get(new PortableMetaDataKey(typeId));
+
+ return metaDataCache.localPeek(new PortableMetaDataKey(typeId));
+ }
+ catch (CacheException e) {
+ throw new BinaryObjectException(e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public Map<Integer, BinaryType> metadata(Collection<Integer> typeIds)
+ throws BinaryObjectException {
+ try {
+ Collection<PortableMetaDataKey> keys = new ArrayList<>(typeIds.size());
+
+ for (Integer typeId : typeIds)
+ keys.add(new PortableMetaDataKey(typeId));
+
+ Map<PortableMetaDataKey, BinaryType> meta = metaDataCache.getAll(keys);
+
+ Map<Integer, BinaryType> res = U.newHashMap(meta.size());
+
+ for (Map.Entry<PortableMetaDataKey, BinaryType> e : meta.entrySet())
+ res.put(e.getKey().typeId(), e.getValue());
+
+ return res;
+ }
+ catch (CacheException e) {
+ throw new BinaryObjectException(e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override public Collection<BinaryType> metadata() throws BinaryObjectException {
+ if (clientNode)
+ return new ArrayList<>(clientMetaDataCache.values());
+
+ return F.viewReadOnly(metaDataCache.entrySetx(metaPred),
+ new C1<Cache.Entry<PortableMetaDataKey, BinaryType>, BinaryType>() {
+ private static final long serialVersionUID = 0L;
+
+ @Override public BinaryType apply(
+ Cache.Entry<PortableMetaDataKey, BinaryType> e) {
+ return e.getValue();
+ }
+ });
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteBinary binary() throws IgniteException {
+ return portables;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isPortableObject(Object obj) {
+ return obj instanceof BinaryObject;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isPortableEnabled(CacheConfiguration<?, ?> ccfg) {
+ return marsh instanceof PortableMarshaller;
+ }
+
+ /**
+ * @param po Portable object.
+ * @return Affinity key.
+ */
+ public Object affinityKey(BinaryObject po) {
+ try {
+ BinaryType meta = po.type();
+
+ if (meta != null) {
+ String affKeyFieldName = meta.affinityKeyFieldName();
+
+ if (affKeyFieldName != null)
+ return po.field(affKeyFieldName);
+ }
+ }
+ catch (BinaryObjectException e) {
+ U.error(log, "Failed to get affinity field from portable object: " + po, e);
+ }
+
+ return po;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int typeId(Object obj) {
+ if (obj == null)
+ return 0;
+
+ return isPortableObject(obj) ? ((BinaryObject)obj).typeId() : typeId(obj.getClass().getSimpleName());
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object field(Object obj, String fieldName) {
+ if (obj == null)
+ return null;
+
+ return isPortableObject(obj) ? ((BinaryObject)obj).field(fieldName) : super.field(obj, fieldName);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean hasField(Object obj, String fieldName) {
+ return obj != null && ((BinaryObject)obj).hasField(fieldName);
+ }
+
+ /**
+ * @return Portable context.
+ */
+ public PortableContext portableContext() {
+ return portableCtx;
+ }
+
+ /** {@inheritDoc} */
+ @Override public CacheObjectContext contextForCache(CacheConfiguration cfg) throws IgniteCheckedException {
+ assert cfg != null;
+
+ boolean portableEnabled = marsh instanceof PortableMarshaller && !GridCacheUtils.isSystemCache(cfg.getName()) &&
+ !GridCacheUtils.isIgfsCache(ctx.config(), cfg.getName());
+
+ CacheObjectContext ctx0 = super.contextForCache(cfg);
+
+ CacheObjectContext res = new CacheObjectPortableContext(ctx,
+ ctx0.copyOnGet(),
+ ctx0.storeValue(),
+ portableEnabled,
+ ctx0.addDeploymentInfo());
+
+ ctx.resource().injectGeneric(res.defaultAffMapper());
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte[] marshal(CacheObjectContext ctx, Object val) throws IgniteCheckedException {
+ if (!((CacheObjectPortableContext)ctx).portableEnabled() || portableMarsh == null)
+ return super.marshal(ctx, val);
+
+ byte[] arr = portableMarsh.marshal(val);
+
+ assert arr.length > 0;
+
+ return arr;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object unmarshal(CacheObjectContext ctx, byte[] bytes, ClassLoader clsLdr)
+ throws IgniteCheckedException {
+ if (!((CacheObjectPortableContext)ctx).portableEnabled() || portableMarsh == null)
+ return super.unmarshal(ctx, bytes, clsLdr);
+
+ return portableMarsh.unmarshal(bytes, clsLdr);
+ }
+
+ /** {@inheritDoc} */
+ @Override public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj) {
+ if (!((CacheObjectPortableContext)ctx).portableEnabled())
+ return super.toCacheKeyObject(ctx, obj, userObj);
+
+ if (obj instanceof KeyCacheObject)
+ return (KeyCacheObject)obj;
+
+ if (((CacheObjectPortableContext)ctx).portableEnabled()) {
+ obj = toPortable(obj);
+
+ if (obj instanceof BinaryObject)
+ return (BinaryObjectImpl)obj;
+ }
+
+ return toCacheKeyObject0(obj, userObj);
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public CacheObject toCacheObject(CacheObjectContext ctx, @Nullable Object obj,
+ boolean userObj) {
+ if (!((CacheObjectPortableContext)ctx).portableEnabled())
+ return super.toCacheObject(ctx, obj, userObj);
+
+ if (obj == null || obj instanceof CacheObject)
+ return (CacheObject)obj;
+
+ obj = toPortable(obj);
+
+ if (obj instanceof BinaryObject)
+ return (BinaryObjectImpl)obj;
+
+ return toCacheObject0(obj, userObj);
+ }
+
+ /** {@inheritDoc} */
+ @Override public CacheObject toCacheObject(CacheObjectContext ctx, byte type, byte[] bytes) {
+ if (type == BinaryObjectImpl.TYPE_BINARY)
+ return new BinaryObjectImpl(portableContext(), bytes, 0);
+
+ return super.toCacheObject(ctx, type, bytes);
+ }
+
+ /** {@inheritDoc} */
+ @Override public CacheObject toCacheObject(GridCacheContext ctx, long valPtr, boolean tmp)
+ throws IgniteCheckedException {
+ if (!((CacheObjectPortableContext)ctx.cacheObjectContext()).portableEnabled())
+ return super.toCacheObject(ctx, valPtr, tmp);
+
+ Object val = unmarshal(valPtr, !tmp);
+
+ if (val instanceof BinaryObjectOffheapImpl)
+ return (BinaryObjectOffheapImpl)val;
+
+ return new CacheObjectImpl(val, null);
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object unwrapTemporary(GridCacheContext ctx, Object obj) throws BinaryObjectException {
+ if (!((CacheObjectPortableContext)ctx.cacheObjectContext()).portableEnabled())
+ return obj;
+
+ if (obj instanceof BinaryObjectOffheapImpl)
+ return ((BinaryObjectOffheapImpl)obj).heapCopy();
+
+ return obj;
+ }
+
+ /**
+ * @param obj Object.
+ * @return Portable object.
+ * @throws IgniteException In case of error.
+ */
+ @Nullable public Object toPortable(@Nullable Object obj) throws IgniteException {
+ if (obj == null)
+ return null;
+
+ if (isPortableObject(obj))
+ return obj;
+
+ return marshalToPortable(obj);
+ }
+
+ /**
+ * @param typeId Type ID.
+ * @param oldMeta Old meta.
+ * @param newMeta New meta.
+ * @param fields Fields map.
+ * @return Whether meta is changed.
+ * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+ */
+ private static boolean checkMeta(int typeId, @Nullable BinaryType oldMeta,
+ BinaryType newMeta, @Nullable Map<String, String> fields) throws BinaryObjectException {
+ assert newMeta != null;
+
+ Map<String, String> oldFields = oldMeta != null ? ((BinaryMetaDataImpl)oldMeta).fieldsMeta() : null;
+ Map<String, String> newFields = ((BinaryMetaDataImpl)newMeta).fieldsMeta();
+
+ boolean changed = false;
+
+ if (oldMeta != null) {
+ if (!oldMeta.typeName().equals(newMeta.typeName())) {
+ throw new BinaryObjectException(
+ "Two portable types have duplicate type ID [" +
+ "typeId=" + typeId +
+ ", typeName1=" + oldMeta.typeName() +
+ ", typeName2=" + newMeta.typeName() +
+ ']'
+ );
+ }
+
+ if (!F.eq(oldMeta.affinityKeyFieldName(), newMeta.affinityKeyFieldName())) {
+ throw new BinaryObjectException(
+ "Portable type has different affinity key fields on different clients [" +
+ "typeName=" + newMeta.typeName() +
+ ", affKeyFieldName1=" + oldMeta.affinityKeyFieldName() +
+ ", affKeyFieldName2=" + newMeta.affinityKeyFieldName() +
+ ']'
+ );
+ }
+
+ if (fields != null)
+ fields.putAll(oldFields);
+ }
+ else
+ changed = true;
+
+ for (Map.Entry<String, String> e : newFields.entrySet()) {
+ String typeName = oldFields != null ? oldFields.get(e.getKey()) : null;
+
+ if (typeName != null) {
+ if (!typeName.equals(e.getValue())) {
+ throw new BinaryObjectException(
+ "Portable field has different types on different clients [" +
+ "typeName=" + newMeta.typeName() +
+ ", fieldName=" + e.getKey() +
+ ", fieldTypeName1=" + typeName +
+ ", fieldTypeName2=" + e.getValue() +
+ ']'
+ );
+ }
+ }
+ else {
+ if (fields != null)
+ fields.put(e.getKey(), e.getValue());
+
+ changed = true;
+ }
+ }
+
+ return changed;
+ }
+
+ /**
+ */
+ private static class MetaDataProcessor implements
+ EntryProcessor<PortableMetaDataKey, BinaryType, BinaryObjectException>, Externalizable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** */
+ private int typeId;
+
+ /** */
+ private BinaryType newMeta;
+
+ /**
+ * For {@link Externalizable}.
+ */
+ public MetaDataProcessor() {
+ // No-op.
+ }
+
+ /**
+ * @param typeId Type ID.
+ * @param newMeta New metadata.
+ */
+ private MetaDataProcessor(int typeId, BinaryType newMeta) {
+ assert newMeta != null;
+
+ this.typeId = typeId;
+ this.newMeta = newMeta;
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectException process(
+ MutableEntry<PortableMetaDataKey, BinaryType> entry,
+ Object... args) {
+ try {
+ BinaryType oldMeta = entry.getValue();
+
+ Map<String, String> fields = new HashMap<>();
+
+ if (checkMeta(typeId, oldMeta, newMeta, fields)) {
+ BinaryType res = new BinaryMetaDataImpl(newMeta.typeName(),
+ fields,
+ newMeta.affinityKeyFieldName());
+
+ entry.setValue(res);
+
+ return null;
+ }
+ else
+ return null;
+ }
+ catch (BinaryObjectException e) {
+ return e;
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeInt(typeId);
+ out.writeObject(newMeta);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ typeId = in.readInt();
+ newMeta = (BinaryType)in.readObject();
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(MetaDataProcessor.class, this);
+ }
+ }
+
+ /**
+ *
+ */
+ class MetaDataEntryListener implements CacheEntryUpdatedListener<PortableMetaDataKey, BinaryType> {
+ /** {@inheritDoc} */
+ @Override public void onUpdated(
+ Iterable<CacheEntryEvent<? extends PortableMetaDataKey, ? extends BinaryType>> evts)
+ throws CacheEntryListenerException {
+ for (CacheEntryEvent<? extends PortableMetaDataKey, ? extends BinaryType> evt : evts) {
+ assert evt.getEventType() == EventType.CREATED || evt.getEventType() == EventType.UPDATED : evt;
+
+ PortableMetaDataKey key = evt.getKey();
+
+ final BinaryType newMeta = evt.getValue();
+
+ assert newMeta != null : evt;
+
+ addClientCacheMetaData(key, newMeta);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(MetaDataEntryListener.class, this);
+ }
+ }
+
+ /**
+ *
+ */
+ static class MetaDataEntryFilter implements CacheEntryEventSerializableFilter<Object, Object> {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** {@inheritDoc} */
+ @Override public boolean evaluate(CacheEntryEvent<?, ?> evt) throws CacheEntryListenerException {
+ return evt.getKey() instanceof PortableMetaDataKey;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(MetaDataEntryFilter.class, this);
+ }
+ }
+
+ /**
+ *
+ */
+ static class MetaDataPredicate implements IgniteBiPredicate<Object, Object> {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** {@inheritDoc} */
+ @Override public boolean apply(Object key, Object val) {
+ return key instanceof PortableMetaDataKey;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(MetaDataPredicate.class, this);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java
index 41a5a7a..c83c9af 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java
@@ -17,17 +17,9 @@
package org.apache.ignite.internal.processors.cache.portable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.PortableUtils;
import org.apache.ignite.internal.processors.cache.CacheObjectContext;
import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.portable.PortableObject;
/**
*
@@ -60,129 +52,4 @@ public class CacheObjectPortableContext extends CacheObjectContext {
public boolean portableEnabled() {
return portableEnabled;
}
-
- /** {@inheritDoc} */
- @Override public Object unwrapPortableIfNeeded(Object o, boolean keepPortable) {
- if (o == null)
- return null;
-
- if (keepPortable || !portableEnabled() || !PortableUtils.isPortableOrCollectionType(o.getClass()))
- return o;
-
- return unwrapPortable(o);
- }
-
- /** {@inheritDoc} */
- @Override public Collection<Object> unwrapPortablesIfNeeded(Collection<Object> col, boolean keepPortable) {
- if (keepPortable || !portableEnabled())
- return col;
-
- if (col instanceof ArrayList)
- return unwrapPortables((ArrayList<Object>)col);
-
- if (col instanceof Set)
- return unwrapPortables((Set<Object>)col);
-
- Collection<Object> col0 = new ArrayList<>(col.size());
-
- for (Object obj : col)
- col0.add(unwrapPortable(obj));
-
- return col0;
- }
-
- /**
- * Unwraps map.
- *
- * @param map Map to unwrap.
- * @param keepPortable Keep portable flag.
- * @return Unwrapped collection.
- */
- public Map<Object, Object> unwrapPortablesIfNeeded(Map<Object, Object> map, boolean keepPortable) {
- if (keepPortable || !portableEnabled())
- return map;
-
- Map<Object, Object> map0 = PortableUtils.newMap(map);
-
- for (Map.Entry<Object, Object> e : map.entrySet())
- map0.put(unwrapPortable(e.getKey()), unwrapPortable(e.getValue()));
-
- return map0;
- }
-
- /**
- * Unwraps array list.
- *
- * @param col List to unwrap.
- * @return Unwrapped list.
- */
- private Collection<Object> unwrapPortables(ArrayList<Object> col) {
- int size = col.size();
-
- for (int i = 0; i < size; i++) {
- Object o = col.get(i);
-
- Object unwrapped = unwrapPortable(o);
-
- if (o != unwrapped)
- col.set(i, unwrapped);
- }
-
- return col;
- }
-
- /**
- * Unwraps set with portables.
- *
- * @param set Set to unwrap.
- * @return Unwrapped set.
- */
- private Set<Object> unwrapPortables(Set<Object> set) {
- Set<Object> set0 = PortableUtils.newSet(set);
-
- Iterator<Object> iter = set.iterator();
-
- while (iter.hasNext())
- set0.add(unwrapPortable(iter.next()));
-
- return set0;
- }
-
- /**
- * @param o Object to unwrap.
- * @return Unwrapped object.
- */
- private Object unwrapPortable(Object o) {
- if (o instanceof Map.Entry) {
- Map.Entry entry = (Map.Entry)o;
-
- Object key = entry.getKey();
-
- boolean unwrapped = false;
-
- if (key instanceof PortableObject) {
- key = ((PortableObject)key).deserialize();
-
- unwrapped = true;
- }
-
- Object val = entry.getValue();
-
- if (val instanceof PortableObject) {
- val = ((PortableObject)val).deserialize();
-
- unwrapped = true;
- }
-
- return unwrapped ? F.t(key, val) : o;
- }
- else if (o instanceof Collection)
- return unwrapPortablesIfNeeded((Collection<Object>)o, false);
- else if (o instanceof Map)
- return unwrapPortablesIfNeeded((Map<Object, Object>)o, false);
- else if (o instanceof PortableObject)
- return ((PortableObject)o).deserialize();
-
- return o;
- }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessor.java
deleted file mode 100644
index fcd73d2..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessor.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.cache.portable;
-
-import java.util.Collection;
-import java.util.Map;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgnitePortables;
-import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Extended cache object processor interface with additional methods for portables.
- */
-public interface CacheObjectPortableProcessor extends IgniteCacheObjectProcessor {
- /**
- * @param typeId Type ID.
- * @return Builder.
- */
- public PortableBuilder builder(int typeId);
-
- /**
- * @param clsName Class name.
- * @return Builder.
- */
- public PortableBuilder builder(String clsName);
-
- /**
- * Creates builder initialized by existing portable object.
- *
- * @param portableObj Portable object to edit.
- * @return Portable builder.
- */
- public PortableBuilder builder(PortableObject portableObj);
-
- /**
- * @param typeId Type ID.
- * @param newMeta New meta data.
- * @throws IgniteException In case of error.
- */
- public void addMeta(int typeId, final PortableMetadata newMeta) throws IgniteException;
-
- /**
- * @param typeId Type ID.
- * @param typeName Type name.
- * @param affKeyFieldName Affinity key field name.
- * @param fieldTypeIds Fields map.
- * @throws IgniteException In case of error.
- */
- public void updateMetaData(int typeId, String typeName, @Nullable String affKeyFieldName,
- Map<String, Integer> fieldTypeIds) throws IgniteException;
-
- /**
- * @param typeId Type ID.
- * @return Meta data.
- * @throws IgniteException In case of error.
- */
- @Nullable public PortableMetadata metadata(int typeId) throws IgniteException;
-
- /**
- * @param typeIds Type ID.
- * @return Meta data.
- * @throws IgniteException In case of error.
- */
- public Map<Integer, PortableMetadata> metadata(Collection<Integer> typeIds) throws IgniteException;
-
- /**
- * @return Metadata for all types.
- * @throws IgniteException In case of error.
- */
- public Collection<PortableMetadata> metadata() throws IgniteException;
-
- /**
- * @return Portables interface.
- * @throws IgniteException If failed.
- */
- public IgnitePortables portables() throws IgniteException;
-
- /**
- * @param obj Original object.
- * @return Portable object (in case portable marshaller is used).
- * @throws IgniteException If failed.
- */
- public Object marshalToPortable(Object obj) throws IgniteException;
-}
\ No newline at end of file
[03/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractSelfTest.java
new file mode 100644
index 0000000..0892750
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractSelfTest.java
@@ -0,0 +1,981 @@
+/*
+ * 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.cache.portable;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import javax.cache.Cache;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.portable.BinaryObjectImpl;
+import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.util.typedef.P2;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiInClosure;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public abstract class GridCacheBinaryObjectsAbstractSelfTest extends GridCommonAbstractTest {
+ /** */
+ public static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static final int ENTRY_CNT = 100;
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+ disco.setIpFinder(IP_FINDER);
+
+ cfg.setDiscoverySpi(disco);
+
+ CacheConfiguration cacheCfg = new CacheConfiguration();
+
+ cacheCfg.setCacheMode(cacheMode());
+ cacheCfg.setAtomicityMode(atomicityMode());
+ cacheCfg.setNearConfiguration(nearConfiguration());
+ cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
+ cacheCfg.setCacheStoreFactory(singletonFactory(new TestStore()));
+ cacheCfg.setReadThrough(true);
+ cacheCfg.setWriteThrough(true);
+ cacheCfg.setLoadPreviousValue(true);
+ cacheCfg.setBackups(1);
+
+ if (offheapTiered()) {
+ cacheCfg.setMemoryMode(OFFHEAP_TIERED);
+ cacheCfg.setOffHeapMaxMemory(0);
+ }
+
+ cfg.setCacheConfiguration(cacheCfg);
+
+ cfg.setMarshaller(new PortableMarshaller());
+
+ return cfg;
+ }
+
+ /**
+ * @return {@code True} if should use OFFHEAP_TIERED mode.
+ */
+ protected boolean offheapTiered() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGridsMultiThreaded(gridCount());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ for (int i = 0; i < gridCount(); i++) {
+ GridCacheAdapter<Object, Object> c = ((IgniteKernal)grid(i)).internalCache();
+
+ for (GridCacheEntryEx e : c.map().entries0()) {
+ Object key = e.key().value(c.context().cacheObjectContext(), false);
+ Object val = CU.value(e.rawGet(), c.context(), false);
+
+ if (key instanceof BinaryObject)
+ assert ((BinaryObjectImpl)key).detached() : val;
+
+ if (val instanceof BinaryObject)
+ assert ((BinaryObjectImpl)val).detached() : val;
+ }
+ }
+
+ IgniteCache<Object, Object> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.remove(i);
+
+ if (offheapTiered()) {
+ for (int k = 0; k < 100; k++)
+ c.remove(k);
+ }
+
+ assertEquals(0, c.size());
+ }
+
+ /**
+ * @return Cache mode.
+ */
+ protected abstract CacheMode cacheMode();
+
+ /**
+ * @return Atomicity mode.
+ */
+ protected abstract CacheAtomicityMode atomicityMode();
+
+ /**
+ * @return Distribution mode.
+ */
+ protected abstract NearCacheConfiguration nearConfiguration();
+
+ /**
+ * @return Grid count.
+ */
+ protected abstract int gridCount();
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("unchecked")
+ public void testCircularReference() throws Exception {
+ IgniteCache c = keepPortableCache();
+
+ TestReferenceObject obj1 = new TestReferenceObject();
+
+ obj1.obj = new TestReferenceObject(obj1);
+
+ c.put(1, obj1);
+
+ BinaryObject po = (BinaryObject)c.get(1);
+
+ String str = po.toString();
+
+ log.info("toString: " + str);
+
+ assertNotNull(str);
+
+ assertTrue("Unexpected toString: " + str,
+ str.startsWith("TestReferenceObject") && str.contains("obj=TestReferenceObject ["));
+
+ TestReferenceObject obj1_r = po.deserialize();
+
+ assertNotNull(obj1_r);
+
+ TestReferenceObject obj2_r = obj1_r.obj;
+
+ assertNotNull(obj2_r);
+
+ assertSame(obj1_r, obj2_r.obj);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGet() throws Exception {
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ TestObject obj = c.get(i);
+
+ assertEquals(i, obj.val);
+ }
+
+ IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ BinaryObject po = kpc.get(i);
+
+ assertEquals(i, (int)po.field("val"));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testIterator() throws Exception {
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ Map<Integer, TestObject> entries = new HashMap<>();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ TestObject val = new TestObject(i);
+
+ c.put(i, val);
+
+ entries.put(i, val);
+ }
+
+ IgniteCache<Integer, BinaryObject> prj = ((IgniteCacheProxy)c).keepPortable();
+
+ Iterator<Cache.Entry<Integer, BinaryObject>> it = prj.iterator();
+
+ assertTrue(it.hasNext());
+
+ while (it.hasNext()) {
+ Cache.Entry<Integer, BinaryObject> entry = it.next();
+
+ assertTrue(entries.containsKey(entry.getKey()));
+
+ TestObject o = entries.get(entry.getKey());
+
+ BinaryObject po = entry.getValue();
+
+ assertEquals(o.val, (int)po.field("val"));
+
+ entries.remove(entry.getKey());
+ }
+
+ assertEquals(0, entries.size());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCollection() throws Exception {
+ IgniteCache<Integer, Collection<TestObject>> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Collection<TestObject> col = new ArrayList<>(3);
+
+ for (int j = 0; j < 3; j++)
+ col.add(new TestObject(i * 10 + j));
+
+ c.put(i, col);
+ }
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Collection<TestObject> col = c.get(i);
+
+ assertEquals(3, col.size());
+
+ Iterator<TestObject> it = col.iterator();
+
+ for (int j = 0; j < 3; j++) {
+ assertTrue(it.hasNext());
+
+ assertEquals(i * 10 + j, it.next().val);
+ }
+ }
+
+ IgniteCache<Integer, Collection<BinaryObject>> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Collection<BinaryObject> col = kpc.get(i);
+
+ assertEquals(3, col.size());
+
+ Iterator<BinaryObject> it = col.iterator();
+
+ for (int j = 0; j < 3; j++) {
+ assertTrue(it.hasNext());
+
+ assertEquals(i * 10 + j, (int)it.next().field("val"));
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMap() throws Exception {
+ IgniteCache<Integer, Map<Integer, TestObject>> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Map<Integer, TestObject> map = U.newHashMap(3);
+
+ for (int j = 0; j < 3; j++) {
+ int idx = i * 10 + j;
+
+ map.put(idx, new TestObject(idx));
+ }
+
+ c.put(i, map);
+ }
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Map<Integer, TestObject> map = c.get(i);
+
+ assertEquals(3, map.size());
+
+ for (int j = 0; j < 3; j++) {
+ int idx = i * 10 + j;
+
+ assertEquals(idx, map.get(idx).val);
+ }
+ }
+
+ IgniteCache<Integer, Map<Integer, BinaryObject>> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Map<Integer, BinaryObject> map = kpc.get(i);
+
+ assertEquals(3, map.size());
+
+ for (int j = 0; j < 3; j++) {
+ int idx = i * 10 + j;
+
+ assertEquals(idx, (int)map.get(idx).field("val"));
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAsync() throws Exception {
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ cacheAsync.get(i);
+
+ TestObject obj = cacheAsync.<TestObject>future().get();
+
+ assertNotNull(obj);
+
+ assertEquals(i, obj.val);
+ }
+
+ IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+
+ IgniteCache<Integer, BinaryObject> cachePortableAsync = kpc.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ cachePortableAsync.get(i);
+
+ BinaryObject po = cachePortableAsync.<BinaryObject>future().get();
+
+ assertEquals(i, (int)po.field("val"));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetTx() throws Exception {
+ if (atomicityMode() != TRANSACTIONAL)
+ return;
+
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ TestObject obj = c.get(i);
+
+ assertEquals(i, obj.val);
+
+ tx.commit();
+ }
+ }
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+ TestObject obj = c.get(i);
+
+ assertEquals(i, obj.val);
+
+ tx.commit();
+ }
+ }
+
+ IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ BinaryObject po = kpc.get(i);
+
+ assertEquals(i, (int)po.field("val"));
+
+ tx.commit();
+ }
+ }
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+ BinaryObject po = kpc.get(i);
+
+ assertEquals(i, (int)po.field("val"));
+
+ tx.commit();
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAsyncTx() throws Exception {
+ if (atomicityMode() != TRANSACTIONAL)
+ return;
+
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ cacheAsync.get(i);
+
+ TestObject obj = cacheAsync.<TestObject>future().get();
+
+ assertEquals(i, obj.val);
+
+ tx.commit();
+ }
+ }
+
+ IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+ IgniteCache<Integer, BinaryObject> cachePortableAsync = kpc.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ cachePortableAsync.get(i);
+
+ BinaryObject po = cachePortableAsync.<BinaryObject>future().get();
+
+ assertEquals(i, (int)po.field("val"));
+
+ tx.commit();
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAll() throws Exception {
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ Map<Integer, TestObject> objs = c.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+ assertEquals(e.getKey().intValue(), e.getValue().val);
+ }
+
+ IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ Map<Integer, BinaryObject> objs = kpc.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
+ assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAllAsync() throws Exception {
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ cacheAsync.getAll(keys);
+
+ Map<Integer, TestObject> objs = cacheAsync.<Map<Integer, TestObject>>future().get();
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+ assertEquals(e.getKey().intValue(), e.getValue().val);
+ }
+
+ IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+ IgniteCache<Integer, BinaryObject> cachePortableAsync = kpc.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+
+ cachePortableAsync.getAll(keys);
+
+ Map<Integer, BinaryObject> objs = cachePortableAsync.<Map<Integer, BinaryObject>>future().get();
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
+ assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAllTx() throws Exception {
+ if (atomicityMode() != TRANSACTIONAL)
+ return;
+
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ Map<Integer, TestObject> objs = c.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+ assertEquals(e.getKey().intValue(), e.getValue().val);
+
+ tx.commit();
+ }
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+ Map<Integer, TestObject> objs = c.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+ assertEquals(e.getKey().intValue(), e.getValue().val);
+
+ tx.commit();
+ }
+ }
+
+ IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ Map<Integer, BinaryObject> objs = kpc.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
+ assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+
+ tx.commit();
+ }
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+ Map<Integer, BinaryObject> objs = kpc.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
+ assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+
+ tx.commit();
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAllAsyncTx() throws Exception {
+ if (atomicityMode() != TRANSACTIONAL)
+ return;
+
+ IgniteCache<Integer, TestObject> c = jcache(0);
+ IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ cacheAsync.getAll(keys);
+
+ Map<Integer, TestObject> objs = cacheAsync.<Map<Integer, TestObject>>future().get();
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+ assertEquals(e.getKey().intValue(), e.getValue().val);
+
+ tx.commit();
+ }
+ }
+
+ IgniteCache<Integer, BinaryObject> cache = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ IgniteCache<Integer, BinaryObject> asyncCache = cache.withAsync();
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ asyncCache.getAll(keys);
+
+ Map<Integer, BinaryObject> objs = asyncCache.<Map<Integer, BinaryObject>>future().get();
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
+ assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+
+ tx.commit();
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLoadCache() throws Exception {
+ for (int i = 0; i < gridCount(); i++)
+ jcache(i).localLoadCache(null);
+
+ IgniteCache<Integer, TestObject> cache = jcache(0);
+
+ assertEquals(3, cache.size(CachePeekMode.PRIMARY));
+
+ assertEquals(1, cache.get(1).val);
+ assertEquals(2, cache.get(2).val);
+ assertEquals(3, cache.get(3).val);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLoadCacheAsync() throws Exception {
+ for (int i = 0; i < gridCount(); i++) {
+ IgniteCache<Object, Object> jcache = jcache(i).withAsync();
+
+ jcache.loadCache(null);
+
+ jcache.future().get();
+ }
+
+ IgniteCache<Integer, TestObject> cache = jcache(0);
+
+ assertEquals(3, cache.size(CachePeekMode.PRIMARY));
+
+ assertEquals(1, cache.get(1).val);
+ assertEquals(2, cache.get(2).val);
+ assertEquals(3, cache.get(3).val);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLoadCacheFilteredAsync() throws Exception {
+ for (int i = 0; i < gridCount(); i++) {
+ IgniteCache<Integer, TestObject> c = this.<Integer, TestObject>jcache(i).withAsync();
+
+ c.loadCache(new P2<Integer, TestObject>() {
+ @Override public boolean apply(Integer key, TestObject val) {
+ return val.val < 3;
+ }
+ });
+
+ c.future().get();
+ }
+
+ IgniteCache<Integer, TestObject> cache = jcache(0);
+
+ assertEquals(2, cache.size(CachePeekMode.PRIMARY));
+
+ assertEquals(1, cache.get(1).val);
+ assertEquals(2, cache.get(2).val);
+
+ assertNull(cache.get(3));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTransform() throws Exception {
+ IgniteCache<Integer, BinaryObject> c = keepPortableCache();
+
+ checkTransform(primaryKey(c));
+
+ if (cacheMode() != CacheMode.LOCAL) {
+ checkTransform(backupKey(c));
+
+ if (nearConfiguration() != null)
+ checkTransform(nearKey(c));
+ }
+ }
+
+ /**
+ * @return Cache with keep portable flag.
+ */
+ private <K, V> IgniteCache<K, V> keepPortableCache() {
+ return ignite(0).cache(null).withKeepBinary();
+ }
+
+ /**
+ * @param key Key.
+ * @throws Exception If failed.
+ */
+ private void checkTransform(Integer key) throws Exception {
+ log.info("Transform: " + key);
+
+ IgniteCache<Integer, BinaryObject> c = keepPortableCache();
+
+ try {
+ c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
+ @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
+ BinaryObject val = e.getValue();
+
+ assertNull("Unexpected value: " + val, val);
+
+ return null;
+ }
+ });
+
+ jcache(0).put(key, new TestObject(1));
+
+ c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
+ @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
+ BinaryObject val = e.getValue();
+
+ assertNotNull("Unexpected value: " + val, val);
+
+ assertEquals(new Integer(1), val.field("val"));
+
+ Ignite ignite = e.unwrap(Ignite.class);
+
+ IgniteBinary portables = ignite.binary();
+
+ BinaryObjectBuilder builder = portables.builder(val);
+
+ builder.setField("val", 2);
+
+ e.setValue(builder.build());
+
+ return null;
+ }
+ });
+
+ BinaryObject obj = c.get(key);
+
+ assertEquals(new Integer(2), obj.field("val"));
+
+ c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
+ @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
+ BinaryObject val = e.getValue();
+
+ assertNotNull("Unexpected value: " + val, val);
+
+ assertEquals(new Integer(2), val.field("val"));
+
+ e.setValue(val);
+
+ return null;
+ }
+ });
+
+ obj = c.get(key);
+
+ assertEquals(new Integer(2), obj.field("val"));
+
+ c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
+ @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
+ BinaryObject val = e.getValue();
+
+ assertNotNull("Unexpected value: " + val, val);
+
+ assertEquals(new Integer(2), val.field("val"));
+
+ e.remove();
+
+ return null;
+ }
+ });
+
+ assertNull(c.get(key));
+ }
+ finally {
+ c.remove(key);
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestObject implements Binarylizable {
+ /** */
+ private int val;
+
+ /**
+ */
+ private TestObject() {
+ // No-op.
+ }
+
+ /**
+ * @param val Value.
+ */
+ private TestObject(int val) {
+ this.val = val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+ writer.writeInt("val", val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+ val = reader.readInt("val");
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestReferenceObject implements Binarylizable {
+ /** */
+ private TestReferenceObject obj;
+
+ /**
+ */
+ private TestReferenceObject() {
+ // No-op.
+ }
+
+ /**
+ * @param obj Object.
+ */
+ private TestReferenceObject(TestReferenceObject obj) {
+ this.obj = obj;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+ writer.writeObject("obj", obj);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+ obj = reader.readObject("obj");
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestStore extends CacheStoreAdapter<Integer, Object> {
+ /** {@inheritDoc} */
+ @Override public void loadCache(IgniteBiInClosure<Integer, Object> clo, Object... args) {
+ for (int i = 1; i <= 3; i++)
+ clo.apply(i, new TestObject(i));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Object load(Integer key) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(Cache.Entry<? extends Integer, ?> e) {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void delete(Object key) {
+ // No-op.
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java
new file mode 100644
index 0000000..a33eb7b
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java
@@ -0,0 +1,295 @@
+/*
+ * 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.cache.portable;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.lang.GridAbsPredicate;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.eclipse.jetty.util.ConcurrentHashSet;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class GridCacheClientNodeBinaryObjectMetadataMultinodeTest extends GridCommonAbstractTest {
+ /** */
+ protected static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private boolean client;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setPeerClassLoadingEnabled(false);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder).setForceServerMode(true);
+
+ cfg.setMarshaller(new PortableMarshaller());
+
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+ cfg.setCacheConfiguration(ccfg);
+
+ cfg.setClientMode(client);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClientMetadataInitialization() throws Exception {
+ startGrids(2);
+
+ final AtomicBoolean stop = new AtomicBoolean();
+
+ final ConcurrentHashSet<String> allTypes = new ConcurrentHashSet<>();
+
+ IgniteInternalFuture<?> fut;
+
+ try {
+ // Update portable metadata concurrently with client nodes start.
+ fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ IgniteBinary portables = ignite(0).binary();
+
+ IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepBinary();
+
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ for (int i = 0; i < 1000; i++) {
+ log.info("Iteration: " + i);
+
+ String type = "portable-type-" + i;
+
+ allTypes.add(type);
+
+ for (int f = 0; f < 10; f++) {
+ BinaryObjectBuilder builder = portables.builder(type);
+
+ String fieldName = "f" + f;
+
+ builder.setField(fieldName, i);
+
+ cache.put(rnd.nextInt(0, 100_000), builder.build());
+
+ if (f % 100 == 0)
+ log.info("Put iteration: " + f);
+ }
+
+ if (stop.get())
+ break;
+ }
+
+ return null;
+ }
+ }, 5, "update-thread");
+ }
+ finally {
+ stop.set(true);
+ }
+
+ client = true;
+
+ startGridsMultiThreaded(2, 5);
+
+ fut.get();
+
+ assertFalse(allTypes.isEmpty());
+
+ log.info("Expected portable types: " + allTypes.size());
+
+ assertEquals(7, ignite(0).cluster().nodes().size());
+
+ for (int i = 0; i < 7; i++) {
+ log.info("Check metadata on node: " + i);
+
+ boolean client = i > 1;
+
+ assertEquals((Object)client, ignite(i).configuration().isClientMode());
+
+ IgniteBinary portables = ignite(i).binary();
+
+ Collection<BinaryType> metaCol = portables.metadata();
+
+ assertEquals(allTypes.size(), metaCol.size());
+
+ Set<String> names = new HashSet<>();
+
+ for (BinaryType meta : metaCol) {
+ assertTrue(names.add(meta.typeName()));
+
+ assertNull(meta.affinityKeyFieldName());
+
+ assertEquals(10, meta.fields().size());
+ }
+
+ assertEquals(allTypes.size(), names.size());
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFailoverOnStart() throws Exception {
+ startGrids(4);
+
+ IgniteBinary portables = ignite(0).binary();
+
+ IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepBinary();
+
+ for (int i = 0; i < 1000; i++) {
+ BinaryObjectBuilder builder = portables.builder("type-" + i);
+
+ builder.setField("f0", i);
+
+ cache.put(i, builder.build());
+ }
+
+ client = true;
+
+ final CyclicBarrier barrier = new CyclicBarrier(6);
+
+ final AtomicInteger startIdx = new AtomicInteger(4);
+
+ IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ barrier.await();
+
+ Ignite ignite = startGrid(startIdx.getAndIncrement());
+
+ assertTrue(ignite.configuration().isClientMode());
+
+ log.info("Started node: " + ignite.name());
+
+ return null;
+ }
+ }, 5, "start-thread");
+
+ barrier.await();
+
+ U.sleep(ThreadLocalRandom.current().nextInt(10, 100));
+
+ for (int i = 0; i < 3; i++)
+ stopGrid(i);
+
+ fut.get();
+
+ assertEquals(6, ignite(3).cluster().nodes().size());
+
+ for (int i = 3; i < 7; i++) {
+ log.info("Check metadata on node: " + i);
+
+ boolean client = i > 3;
+
+ assertEquals((Object) client, ignite(i).configuration().isClientMode());
+
+ portables = ignite(i).binary();
+
+ final IgniteBinary p0 = portables;
+
+ GridTestUtils.waitForCondition(new GridAbsPredicate() {
+ @Override public boolean apply() {
+ Collection<BinaryType> metaCol = p0.metadata();
+
+ return metaCol.size() == 1000;
+ }
+ }, getTestTimeout());
+
+ Collection<BinaryType> metaCol = portables.metadata();
+
+ assertEquals(1000, metaCol.size());
+
+ Set<String> names = new HashSet<>();
+
+ for (BinaryType meta : metaCol) {
+ assertTrue(names.add(meta.typeName()));
+
+ assertNull(meta.affinityKeyFieldName());
+
+ assertEquals(1, meta.fields().size());
+ }
+
+ assertEquals(1000, names.size());
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClientStartsFirst() throws Exception {
+ client = true;
+
+ Ignite ignite0 = startGrid(0);
+
+ assertTrue(ignite0.configuration().isClientMode());
+
+ client = false;
+
+ Ignite ignite1 = startGrid(1);
+
+ assertFalse(ignite1.configuration().isClientMode());
+
+ IgniteBinary portables = ignite(1).binary();
+
+ IgniteCache<Object, Object> cache = ignite(1).cache(null).withKeepBinary();
+
+ for (int i = 0; i < 100; i++) {
+ BinaryObjectBuilder builder = portables.builder("type-" + i);
+
+ builder.setField("f0", i);
+
+ cache.put(i, builder.build());
+ }
+
+ assertEquals(100, ignite(0).binary().metadata().size());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataTest.java
new file mode 100644
index 0000000..c2d0197
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataTest.java
@@ -0,0 +1,290 @@
+/*
+ * 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.cache.portable;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheKeyConfiguration;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+
+/**
+ *
+ */
+public class GridCacheClientNodeBinaryObjectMetadataTest extends GridCacheAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 4;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return CacheMode.PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return ATOMIC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(TestObject1.class.getName(), TestObject2.class.getName()));
+
+ BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
+
+ typeCfg.setClassName(TestObject1.class.getName());
+
+ CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestObject1.class.getName(), "val2");
+
+ cfg.setCacheKeyCfg(keyCfg);
+
+ marsh.setTypeConfigurations(Arrays.asList(typeCfg));
+
+ if (gridName.equals(getTestGridName(gridCount() - 1)))
+ cfg.setClientMode(true);
+
+ cfg.setMarshaller(marsh);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setForceServerMode(true);
+
+ return cfg;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableMetadataOnClient() throws Exception {
+ Ignite ignite0 = ignite(gridCount() - 1);
+
+ assertTrue(ignite0.configuration().isClientMode());
+
+ Ignite ignite1 = ignite(0);
+
+ assertFalse(ignite1.configuration().isClientMode());
+
+ Affinity<Object> aff0 = ignite0.affinity(null);
+ Affinity<Object> aff1 = ignite1.affinity(null);
+
+ for (int i = 0 ; i < 100; i++) {
+ TestObject1 obj1 = new TestObject1(i, i + 1);
+
+ assertEquals(aff1.mapKeyToPrimaryAndBackups(obj1),
+ aff0.mapKeyToPrimaryAndBackups(obj1));
+
+ TestObject2 obj2 = new TestObject2(i, i + 1);
+
+ assertEquals(aff1.mapKeyToPrimaryAndBackups(obj2),
+ aff0.mapKeyToPrimaryAndBackups(obj2));
+ }
+
+ {
+ BinaryObjectBuilder builder = ignite0.binary().builder("TestObject3");
+
+ builder.setField("f1", 1);
+
+ ignite0.cache(null).put(0, builder.build());
+
+ IgniteCache<Integer, BinaryObject> cache = ignite0.cache(null).withKeepBinary();
+
+ BinaryObject obj = cache.get(0);
+
+ BinaryType meta = obj.type();
+
+ assertNotNull(meta);
+ assertEquals(1, meta.fields().size());
+
+ meta = ignite0.binary().metadata(TestObject1.class);
+
+ assertNotNull(meta);
+ assertEquals("val2", meta.affinityKeyFieldName());
+
+ meta = ignite0.binary().metadata(TestObject2.class);
+
+ assertNotNull(meta);
+ assertNull(meta.affinityKeyFieldName());
+ }
+
+ {
+ BinaryObjectBuilder builder = ignite1.binary().builder("TestObject3");
+
+ builder.setField("f2", 2);
+
+ ignite1.cache(null).put(1, builder.build());
+
+ IgniteCache<Integer, BinaryObject> cache = ignite1.cache(null).withKeepBinary();
+
+ BinaryObject obj = cache.get(0);
+
+ BinaryType meta = obj.type();
+
+ assertNotNull(meta);
+ assertEquals(2, meta.fields().size());
+
+ meta = ignite1.binary().metadata(TestObject1.class);
+
+ assertNotNull(meta);
+ assertEquals("val2", meta.affinityKeyFieldName());
+
+ meta = ignite1.binary().metadata(TestObject2.class);
+
+ assertNotNull(meta);
+ assertNull(meta.affinityKeyFieldName());
+ }
+
+ BinaryType meta = ignite0.binary().metadata("TestObject3");
+
+ assertNotNull(meta);
+ assertEquals(2, meta.fields().size());
+
+ IgniteCache<Integer, BinaryObject> cache = ignite0.cache(null).withKeepBinary();
+
+ BinaryObject obj = cache.get(1);
+
+ assertEquals(Integer.valueOf(2), obj.field("f2"));
+ assertNull(obj.field("f1"));
+
+ meta = obj.type();
+
+ assertNotNull(meta);
+ assertEquals(2, meta.fields().size());
+
+ Collection<BinaryType> meta1 = ignite1.binary().metadata();
+ Collection<BinaryType> meta2 = ignite1.binary().metadata();
+
+ assertEquals(meta1.size(), meta2.size());
+
+ for (BinaryType m1 : meta1) {
+ boolean found = false;
+
+ for (BinaryType m2 : meta1) {
+ if (m1.typeName().equals(m2.typeName())) {
+ assertEquals(m1.affinityKeyFieldName(), m2.affinityKeyFieldName());
+ assertEquals(m1.fields(), m2.fields());
+
+ found = true;
+
+ break;
+ }
+ }
+
+ assertTrue(found);
+ }
+ }
+
+ /**
+ *
+ */
+ static class TestObject1 {
+ /** */
+ private int val1;
+
+ /** */
+ private int val2;
+
+ /**
+ * @param val1 Value 1.
+ * @param val2 Value 2.
+ */
+ public TestObject1(int val1, int val2) {
+ this.val1 = val1;
+ this.val2 = val2;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestObject1 that = (TestObject1)o;
+
+ return val1 == that.val1;
+
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val1;
+ }
+ }
+
+ /**
+ *
+ */
+ static class TestObject2 {
+ /** */
+ private int val1;
+
+ /** */
+ private int val2;
+
+ /**
+ * @param val1 Value 1.
+ * @param val2 Value 2.
+ */
+ public TestObject2(int val1, int val2) {
+ this.val1 = val1;
+ this.val2 = val2;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestObject2 that = (TestObject2)o;
+
+ return val2 == that.val2;
+
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val2;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataMultinodeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataMultinodeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataMultinodeTest.java
deleted file mode 100644
index 1ba3d4d..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataMultinodeTest.java
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * 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.cache.portable;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CyclicBarrier;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgnitePortables;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.util.lang.GridAbsPredicate;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.eclipse.jetty.util.ConcurrentHashSet;
-
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-
-/**
- *
- */
-public class GridCacheClientNodePortableMetadataMultinodeTest extends GridCommonAbstractTest {
- /** */
- protected static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
-
- /** */
- private boolean client;
-
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- cfg.setPeerClassLoadingEnabled(false);
-
- ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder).setForceServerMode(true);
-
- cfg.setMarshaller(new PortableMarshaller());
-
- CacheConfiguration ccfg = new CacheConfiguration();
-
- ccfg.setWriteSynchronizationMode(FULL_SYNC);
-
- cfg.setCacheConfiguration(ccfg);
-
- cfg.setClientMode(client);
-
- return cfg;
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTest() throws Exception {
- super.afterTest();
-
- stopAllGrids();
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testClientMetadataInitialization() throws Exception {
- startGrids(2);
-
- final AtomicBoolean stop = new AtomicBoolean();
-
- final ConcurrentHashSet<String> allTypes = new ConcurrentHashSet<>();
-
- IgniteInternalFuture<?> fut;
-
- try {
- // Update portable metadata concurrently with client nodes start.
- fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
- @Override public Object call() throws Exception {
- IgnitePortables portables = ignite(0).portables();
-
- IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepPortable();
-
- ThreadLocalRandom rnd = ThreadLocalRandom.current();
-
- for (int i = 0; i < 1000; i++) {
- log.info("Iteration: " + i);
-
- String type = "portable-type-" + i;
-
- allTypes.add(type);
-
- for (int f = 0; f < 10; f++) {
- PortableBuilder builder = portables.builder(type);
-
- String fieldName = "f" + f;
-
- builder.setField(fieldName, i);
-
- cache.put(rnd.nextInt(0, 100_000), builder.build());
-
- if (f % 100 == 0)
- log.info("Put iteration: " + f);
- }
-
- if (stop.get())
- break;
- }
-
- return null;
- }
- }, 5, "update-thread");
- }
- finally {
- stop.set(true);
- }
-
- client = true;
-
- startGridsMultiThreaded(2, 5);
-
- fut.get();
-
- assertFalse(allTypes.isEmpty());
-
- log.info("Expected portable types: " + allTypes.size());
-
- assertEquals(7, ignite(0).cluster().nodes().size());
-
- for (int i = 0; i < 7; i++) {
- log.info("Check metadata on node: " + i);
-
- boolean client = i > 1;
-
- assertEquals((Object)client, ignite(i).configuration().isClientMode());
-
- IgnitePortables portables = ignite(i).portables();
-
- Collection<PortableMetadata> metaCol = portables.metadata();
-
- assertEquals(allTypes.size(), metaCol.size());
-
- Set<String> names = new HashSet<>();
-
- for (PortableMetadata meta : metaCol) {
- assertTrue(names.add(meta.typeName()));
-
- assertNull(meta.affinityKeyFieldName());
-
- assertEquals(10, meta.fields().size());
- }
-
- assertEquals(allTypes.size(), names.size());
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testFailoverOnStart() throws Exception {
- startGrids(4);
-
- IgnitePortables portables = ignite(0).portables();
-
- IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepPortable();
-
- for (int i = 0; i < 1000; i++) {
- PortableBuilder builder = portables.builder("type-" + i);
-
- builder.setField("f0", i);
-
- cache.put(i, builder.build());
- }
-
- client = true;
-
- final CyclicBarrier barrier = new CyclicBarrier(6);
-
- final AtomicInteger startIdx = new AtomicInteger(4);
-
- IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
- @Override public Object call() throws Exception {
- barrier.await();
-
- Ignite ignite = startGrid(startIdx.getAndIncrement());
-
- assertTrue(ignite.configuration().isClientMode());
-
- log.info("Started node: " + ignite.name());
-
- return null;
- }
- }, 5, "start-thread");
-
- barrier.await();
-
- U.sleep(ThreadLocalRandom.current().nextInt(10, 100));
-
- for (int i = 0; i < 3; i++)
- stopGrid(i);
-
- fut.get();
-
- assertEquals(6, ignite(3).cluster().nodes().size());
-
- for (int i = 3; i < 7; i++) {
- log.info("Check metadata on node: " + i);
-
- boolean client = i > 3;
-
- assertEquals((Object) client, ignite(i).configuration().isClientMode());
-
- portables = ignite(i).portables();
-
- final IgnitePortables p0 = portables;
-
- GridTestUtils.waitForCondition(new GridAbsPredicate() {
- @Override public boolean apply() {
- Collection<PortableMetadata> metaCol = p0.metadata();
-
- return metaCol.size() == 1000;
- }
- }, getTestTimeout());
-
- Collection<PortableMetadata> metaCol = portables.metadata();
-
- assertEquals(1000, metaCol.size());
-
- Set<String> names = new HashSet<>();
-
- for (PortableMetadata meta : metaCol) {
- assertTrue(names.add(meta.typeName()));
-
- assertNull(meta.affinityKeyFieldName());
-
- assertEquals(1, meta.fields().size());
- }
-
- assertEquals(1000, names.size());
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testClientStartsFirst() throws Exception {
- client = true;
-
- Ignite ignite0 = startGrid(0);
-
- assertTrue(ignite0.configuration().isClientMode());
-
- client = false;
-
- Ignite ignite1 = startGrid(1);
-
- assertFalse(ignite1.configuration().isClientMode());
-
- IgnitePortables portables = ignite(1).portables();
-
- IgniteCache<Object, Object> cache = ignite(1).cache(null).withKeepPortable();
-
- for (int i = 0; i < 100; i++) {
- PortableBuilder builder = portables.builder("type-" + i);
-
- builder.setField("f0", i);
-
- cache.put(i, builder.build());
- }
-
- assertEquals(100, ignite(0).portables().metadata().size());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataTest.java
deleted file mode 100644
index a66d940..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataTest.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * 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.cache.portable;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.affinity.Affinity;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableTypeConfiguration;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-
-/**
- *
- */
-public class GridCacheClientNodePortableMetadataTest extends GridCacheAbstractSelfTest {
- /** {@inheritDoc} */
- @Override protected int gridCount() {
- return 4;
- }
-
- /** {@inheritDoc} */
- @Override protected CacheMode cacheMode() {
- return CacheMode.PARTITIONED;
- }
-
- /** {@inheritDoc} */
- @Override protected CacheAtomicityMode atomicityMode() {
- return ATOMIC;
- }
-
- /** {@inheritDoc} */
- @Override protected NearCacheConfiguration nearConfiguration() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- PortableMarshaller marsh = new PortableMarshaller();
-
- marsh.setClassNames(Arrays.asList(TestObject1.class.getName(), TestObject2.class.getName()));
-
- PortableTypeConfiguration typeCfg = new PortableTypeConfiguration();
-
- typeCfg.setClassName(TestObject1.class.getName());
- typeCfg.setAffinityKeyFieldName("val2");
-
- marsh.setTypeConfigurations(Arrays.asList(typeCfg));
-
- if (gridName.equals(getTestGridName(gridCount() - 1)))
- cfg.setClientMode(true);
-
- cfg.setMarshaller(marsh);
-
- ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setForceServerMode(true);
-
- return cfg;
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testPortableMetadataOnClient() throws Exception {
- Ignite ignite0 = ignite(gridCount() - 1);
-
- assertTrue(ignite0.configuration().isClientMode());
-
- Ignite ignite1 = ignite(0);
-
- assertFalse(ignite1.configuration().isClientMode());
-
- Affinity<Object> aff0 = ignite0.affinity(null);
- Affinity<Object> aff1 = ignite1.affinity(null);
-
- for (int i = 0 ; i < 100; i++) {
- TestObject1 obj1 = new TestObject1(i, i + 1);
-
- assertEquals(aff1.mapKeyToPrimaryAndBackups(obj1),
- aff0.mapKeyToPrimaryAndBackups(obj1));
-
- TestObject2 obj2 = new TestObject2(i, i + 1);
-
- assertEquals(aff1.mapKeyToPrimaryAndBackups(obj2),
- aff0.mapKeyToPrimaryAndBackups(obj2));
- }
-
- {
- PortableBuilder builder = ignite0.portables().builder("TestObject3");
-
- builder.setField("f1", 1);
-
- ignite0.cache(null).put(0, builder.build());
-
- IgniteCache<Integer, PortableObject> cache = ignite0.cache(null).withKeepPortable();
-
- PortableObject obj = cache.get(0);
-
- PortableMetadata meta = obj.metaData();
-
- assertNotNull(meta);
- assertEquals(1, meta.fields().size());
-
- meta = ignite0.portables().metadata(TestObject1.class);
-
- assertNotNull(meta);
- assertEquals("val2", meta.affinityKeyFieldName());
-
- meta = ignite0.portables().metadata(TestObject2.class);
-
- assertNotNull(meta);
- assertNull(meta.affinityKeyFieldName());
- }
-
- {
- PortableBuilder builder = ignite1.portables().builder("TestObject3");
-
- builder.setField("f2", 2);
-
- ignite1.cache(null).put(1, builder.build());
-
- IgniteCache<Integer, PortableObject> cache = ignite1.cache(null).withKeepPortable();
-
- PortableObject obj = cache.get(0);
-
- PortableMetadata meta = obj.metaData();
-
- assertNotNull(meta);
- assertEquals(2, meta.fields().size());
-
- meta = ignite1.portables().metadata(TestObject1.class);
-
- assertNotNull(meta);
- assertEquals("val2", meta.affinityKeyFieldName());
-
- meta = ignite1.portables().metadata(TestObject2.class);
-
- assertNotNull(meta);
- assertNull(meta.affinityKeyFieldName());
- }
-
- PortableMetadata meta = ignite0.portables().metadata("TestObject3");
-
- assertNotNull(meta);
- assertEquals(2, meta.fields().size());
-
- IgniteCache<Integer, PortableObject> cache = ignite0.cache(null).withKeepPortable();
-
- PortableObject obj = cache.get(1);
-
- assertEquals(Integer.valueOf(2), obj.field("f2"));
- assertNull(obj.field("f1"));
-
- meta = obj.metaData();
-
- assertNotNull(meta);
- assertEquals(2, meta.fields().size());
-
- Collection<PortableMetadata> meta1 = ignite1.portables().metadata();
- Collection<PortableMetadata> meta2 = ignite1.portables().metadata();
-
- assertEquals(meta1.size(), meta2.size());
-
- for (PortableMetadata m1 : meta1) {
- boolean found = false;
-
- for (PortableMetadata m2 : meta1) {
- if (m1.typeName().equals(m2.typeName())) {
- assertEquals(m1.affinityKeyFieldName(), m2.affinityKeyFieldName());
- assertEquals(m1.fields(), m2.fields());
-
- found = true;
-
- break;
- }
- }
-
- assertTrue(found);
- }
- }
-
- /**
- *
- */
- static class TestObject1 {
- /** */
- private int val1;
-
- /** */
- private int val2;
-
- /**
- * @param val1 Value 1.
- * @param val2 Value 2.
- */
- public TestObject1(int val1, int val2) {
- this.val1 = val1;
- this.val2 = val2;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- TestObject1 that = (TestObject1)o;
-
- return val1 == that.val1;
-
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return val1;
- }
- }
-
- /**
- *
- */
- static class TestObject2 {
- /** */
- private int val1;
-
- /** */
- private int val2;
-
- /**
- * @param val1 Value 1.
- * @param val2 Value 2.
- */
- public TestObject2(int val1, int val2) {
- this.val1 = val1;
- this.val2 = val2;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- TestObject2 that = (TestObject2)o;
-
- return val2 == that.val2;
-
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return val2;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractDataStreamerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractDataStreamerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractDataStreamerSelfTest.java
deleted file mode 100644
index 9ba38d9..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractDataStreamerSelfTest.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * 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.cache.portable;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.ignite.IgniteDataStreamer;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CacheWriteSynchronizationMode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableTypeConfiguration;
-import org.apache.ignite.portable.PortableWriter;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.jsr166.LongAdder8;
-
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
-
-/**
- * Test for portable objects stored in cache.
- */
-public abstract class GridCachePortableObjectsAbstractDataStreamerSelfTest extends GridCommonAbstractTest {
- /** */
- private static final int THREAD_CNT = 64;
-
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- CacheConfiguration cacheCfg = new CacheConfiguration();
-
- cacheCfg.setCacheMode(cacheMode());
- cacheCfg.setAtomicityMode(atomicityMode());
- cacheCfg.setNearConfiguration(nearConfiguration());
- cacheCfg.setWriteSynchronizationMode(writeSynchronizationMode());
-
- cfg.setCacheConfiguration(cacheCfg);
-
- PortableMarshaller marsh = new PortableMarshaller();
-
- marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(TestObject.class.getName())));
-
- cfg.setMarshaller(marsh);
-
- return cfg;
- }
-
- /**
- * @return Sync mode.
- */
- protected CacheWriteSynchronizationMode writeSynchronizationMode() {
- return PRIMARY_SYNC;
- }
-
- /** {@inheritDoc} */
- @Override protected void beforeTestsStarted() throws Exception {
- startGridsMultiThreaded(gridCount());
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTestsStopped() throws Exception {
- stopAllGrids();
- }
-
- /**
- * @return Cache mode.
- */
- protected abstract CacheMode cacheMode();
-
- /**
- * @return Atomicity mode.
- */
- protected abstract CacheAtomicityMode atomicityMode();
-
- /**
- * @return Near configuration.
- */
- protected abstract NearCacheConfiguration nearConfiguration();
-
- /**
- * @return Grid count.
- */
- protected int gridCount() {
- return 1;
- }
-
- /**
- * @throws Exception If failed.
- */
- @SuppressWarnings("BusyWait")
- public void testGetPut() throws Exception {
- final AtomicBoolean flag = new AtomicBoolean();
-
- final LongAdder8 cnt = new LongAdder8();
-
- try (IgniteDataStreamer<Object, Object> ldr = grid(0).dataStreamer(null)) {
- IgniteInternalFuture<?> f = multithreadedAsync(
- new Callable<Object>() {
- @Override public Object call() throws Exception {
- ThreadLocalRandom rnd = ThreadLocalRandom.current();
-
- while (!flag.get()) {
- ldr.addData(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
-
- cnt.add(1);
- }
-
- return null;
- }
- },
- THREAD_CNT
- );
-
- for (int i = 0; i < 30 && !f.isDone(); i++)
- Thread.sleep(1000);
-
- flag.set(true);
-
- f.get();
- }
-
- info("Operations in 30 sec: " + cnt.sum());
- }
-
- /**
- */
- private static class TestObject implements PortableMarshalAware, Serializable {
- /** */
- private int val;
-
- /**
- */
- private TestObject() {
- // No-op.
- }
-
- /**
- * @param val Value.
- */
- private TestObject(int val) {
- this.val = val;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return val;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object obj) {
- return obj instanceof TestObject && ((TestObject)obj).val == val;
- }
-
- /** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
- writer.writeInt("val", val);
- }
-
- /** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
- val = reader.readInt("val");
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractMultiThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractMultiThreadedSelfTest.java
deleted file mode 100644
index 67f0e52..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractMultiThreadedSelfTest.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * 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.cache.portable;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CacheWriteSynchronizationMode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableTypeConfiguration;
-import org.apache.ignite.portable.PortableWriter;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.jsr166.LongAdder8;
-
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
-
-/**
- * Test for portable objects stored in cache.
- */
-public abstract class GridCachePortableObjectsAbstractMultiThreadedSelfTest extends GridCommonAbstractTest {
- /** */
- private static final int THREAD_CNT = 64;
-
- /** */
- private static final AtomicInteger idxGen = new AtomicInteger();
-
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- CacheConfiguration cacheCfg = new CacheConfiguration();
-
- cacheCfg.setCacheMode(cacheMode());
- cacheCfg.setAtomicityMode(atomicityMode());
- cacheCfg.setNearConfiguration(nearConfiguration());
- cacheCfg.setWriteSynchronizationMode(writeSynchronizationMode());
-
- cfg.setCacheConfiguration(cacheCfg);
-
- PortableMarshaller marsh = new PortableMarshaller();
-
- marsh.setTypeConfigurations(Arrays.asList(
- new PortableTypeConfiguration(TestObject.class.getName())));
-
- cfg.setMarshaller(marsh);
-
- return cfg;
- }
-
- /**
- * @return Sync mode.
- */
- protected CacheWriteSynchronizationMode writeSynchronizationMode() {
- return PRIMARY_SYNC;
- }
-
- /** {@inheritDoc} */
- @Override protected void beforeTestsStarted() throws Exception {
- startGridsMultiThreaded(gridCount());
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTestsStopped() throws Exception {
- stopAllGrids();
- }
-
- /**
- * @return Cache mode.
- */
- protected abstract CacheMode cacheMode();
-
- /**
- * @return Atomicity mode.
- */
- protected abstract CacheAtomicityMode atomicityMode();
-
- /**
- * @return Distribution mode.
- */
- protected abstract NearCacheConfiguration nearConfiguration();
-
- /**
- * @return Grid count.
- */
- protected int gridCount() {
- return 1;
- }
-
- /**
- * @throws Exception If failed.
- */
- @SuppressWarnings("BusyWait") public void testGetPut() throws Exception {
- final AtomicBoolean flag = new AtomicBoolean();
-
- final LongAdder8 cnt = new LongAdder8();
-
- IgniteInternalFuture<?> f = multithreadedAsync(
- new Callable<Object>() {
- @Override public Object call() throws Exception {
- int threadId = idxGen.getAndIncrement() % 2;
-
- ThreadLocalRandom rnd = ThreadLocalRandom.current();
-
- while (!flag.get()) {
- IgniteCache<Object, Object> c = jcache(rnd.nextInt(gridCount()));
-
- switch (threadId) {
- case 0:
- // Put/get/remove portable -> portable.
-
- c.put(new TestObject(rnd.nextInt(10000)), new TestObject(rnd.nextInt(10000)));
-
- IgniteCache<Object, Object> p2 = ((IgniteCacheProxy<Object, Object>)c).keepPortable();
-
- PortableObject v = (PortableObject)p2.get(new TestObject(rnd.nextInt(10000)));
-
- if (v != null)
- v.deserialize();
-
- c.remove(new TestObject(rnd.nextInt(10000)));
-
- break;
-
- case 1:
- // Put/get int -> portable.
- c.put(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
-
- IgniteCache<Integer, PortableObject> p4 = ((IgniteCacheProxy<Object, Object>)c).keepPortable();
-
- PortableObject v1 = p4.get(rnd.nextInt(10000));
-
- if (v1 != null)
- v1.deserialize();
-
- p4.remove(rnd.nextInt(10000));
-
- break;
-
- default:
- assert false;
- }
-
- cnt.add(3);
- }
-
- return null;
- }
- },
- THREAD_CNT
- );
-
- for (int i = 0; i < 30 && !f.isDone(); i++)
- Thread.sleep(1000);
-
- flag.set(true);
-
- f.get();
-
- info("Operations in 30 sec: " + cnt.sum());
- }
-
- /**
- */
- private static class TestObject implements PortableMarshalAware, Serializable {
- /** */
- private int val;
-
- /**
- */
- private TestObject() {
- // No-op.
- }
-
- /**
- * @param val Value.
- */
- private TestObject(int val) {
- this.val = val;
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return val;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object obj) {
- return obj instanceof TestObject && ((TestObject)obj).val == val;
- }
-
- /** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
- writer.writeInt("val", val);
- }
-
- /** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
- val = reader.readInt("val");
- }
- }
-}
\ No newline at end of file
[12/26] ignite git commit: Merged IGNITE-950-new into IGNITE-1282
Posted by ag...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java
deleted file mode 100644
index b687666..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java
+++ /dev/null
@@ -1,1043 +0,0 @@
-/*
- * 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.cache.portable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CountDownLatch;
-import javax.cache.Cache;
-import javax.cache.CacheException;
-import javax.cache.event.CacheEntryEvent;
-import javax.cache.event.CacheEntryListenerException;
-import javax.cache.event.CacheEntryUpdatedListener;
-import javax.cache.event.EventType;
-import javax.cache.processor.EntryProcessor;
-import javax.cache.processor.MutableEntry;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgnitePortables;
-import org.apache.ignite.cluster.ClusterTopologyException;
-import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
-import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
-import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableContext;
-import org.apache.ignite.internal.portable.PortableMetaDataHandler;
-import org.apache.ignite.internal.portable.PortableMetaDataImpl;
-import org.apache.ignite.internal.portable.PortableObjectImpl;
-import org.apache.ignite.internal.portable.PortableObjectOffheapImpl;
-import org.apache.ignite.internal.portable.PortableUtils;
-import org.apache.ignite.internal.portable.builder.PortableBuilderImpl;
-import org.apache.ignite.internal.portable.streams.PortableInputStream;
-import org.apache.ignite.internal.portable.streams.PortableOffheapInputStream;
-import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
-import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapter;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
-import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
-import org.apache.ignite.internal.processors.cache.GridCacheUtils;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
-import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.processors.cache.query.CacheQuery;
-import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture;
-import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager;
-import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessorImpl;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.C1;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.X;
-import org.apache.ignite.internal.util.typedef.internal.CU;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiPredicate;
-import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-import sun.misc.Unsafe;
-
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CLASS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.COL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP_ENTRY;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.PORTABLE_OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID_ARR;
-
-/**
- * Portable processor implementation.
- */
-public class CacheObjectPortableProcessorImpl extends IgniteCacheObjectProcessorImpl implements
- CacheObjectPortableProcessor {
- /** */
- public static final String[] FIELD_TYPE_NAMES;
-
- /** */
- private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
- /** */
- private final CountDownLatch startLatch = new CountDownLatch(1);
-
- /** */
- private final boolean clientNode;
-
- /** */
- private volatile IgniteCacheProxy<PortableMetaDataKey, PortableMetadata> metaDataCache;
-
- /** */
- private final ConcurrentHashMap8<PortableMetaDataKey, PortableMetadata> clientMetaDataCache;
-
- /** Predicate to filter portable meta data in utility cache. */
- private final CacheEntryPredicate metaPred = new CacheEntryPredicateAdapter() {
- private static final long serialVersionUID = 0L;
-
- @Override public boolean apply(GridCacheEntryEx e) {
- return e.key().value(e.context().cacheObjectContext(), false) instanceof PortableMetaDataKey;
- }
- };
-
- /** */
- private PortableContext portableCtx;
-
- /** */
- private Marshaller marsh;
-
- /** */
- private GridPortableMarshaller portableMarsh;
-
- /** */
- @GridToStringExclude
- private IgnitePortables portables;
-
- /** Metadata updates collected before metadata cache is initialized. */
- private final Map<Integer, PortableMetadata> metaBuf = new ConcurrentHashMap<>();
-
- /** */
- private UUID metaCacheQryId;
-
- /**
- *
- */
- static {
- FIELD_TYPE_NAMES = new String[104];
-
- FIELD_TYPE_NAMES[BYTE] = "byte";
- FIELD_TYPE_NAMES[SHORT] = "short";
- FIELD_TYPE_NAMES[INT] = "int";
- FIELD_TYPE_NAMES[LONG] = "long";
- FIELD_TYPE_NAMES[BOOLEAN] = "boolean";
- FIELD_TYPE_NAMES[FLOAT] = "float";
- FIELD_TYPE_NAMES[DOUBLE] = "double";
- FIELD_TYPE_NAMES[CHAR] = "char";
- FIELD_TYPE_NAMES[UUID] = "UUID";
- FIELD_TYPE_NAMES[DECIMAL] = "decimal";
- FIELD_TYPE_NAMES[STRING] = "String";
- FIELD_TYPE_NAMES[DATE] = "Date";
- FIELD_TYPE_NAMES[TIMESTAMP] = "Timestamp";
- FIELD_TYPE_NAMES[ENUM] = "Enum";
- FIELD_TYPE_NAMES[OBJ] = "Object";
- FIELD_TYPE_NAMES[PORTABLE_OBJ] = "Object";
- FIELD_TYPE_NAMES[COL] = "Collection";
- FIELD_TYPE_NAMES[MAP] = "Map";
- FIELD_TYPE_NAMES[MAP_ENTRY] = "Entry";
- FIELD_TYPE_NAMES[CLASS] = "Class";
- FIELD_TYPE_NAMES[BYTE_ARR] = "byte[]";
- FIELD_TYPE_NAMES[SHORT_ARR] = "short[]";
- FIELD_TYPE_NAMES[INT_ARR] = "int[]";
- FIELD_TYPE_NAMES[LONG_ARR] = "long[]";
- FIELD_TYPE_NAMES[BOOLEAN_ARR] = "boolean[]";
- FIELD_TYPE_NAMES[FLOAT_ARR] = "float[]";
- FIELD_TYPE_NAMES[DOUBLE_ARR] = "double[]";
- FIELD_TYPE_NAMES[CHAR_ARR] = "char[]";
- FIELD_TYPE_NAMES[UUID_ARR] = "UUID[]";
- FIELD_TYPE_NAMES[DECIMAL_ARR] = "decimal[]";
- FIELD_TYPE_NAMES[STRING_ARR] = "String[]";
- FIELD_TYPE_NAMES[DATE_ARR] = "Date[]";
- FIELD_TYPE_NAMES[TIMESTAMP_ARR] = "Timestamp[]";
- FIELD_TYPE_NAMES[OBJ_ARR] = "Object[]";
- FIELD_TYPE_NAMES[ENUM_ARR] = "Enum[]";
- }
-
- /**
- * @param typeName Field type name.
- * @return Field type ID;
- */
- @SuppressWarnings("StringEquality")
- public static int fieldTypeId(String typeName) {
- for (int i = 0; i < FIELD_TYPE_NAMES.length; i++) {
- String typeName0 = FIELD_TYPE_NAMES[i];
-
- if (typeName.equals(typeName0))
- return i;
- }
-
- throw new IllegalArgumentException("Invalid metadata type name: " + typeName);
- }
-
- /**
- * @param typeId Field type ID.
- * @return Field type name.
- */
- public static String fieldTypeName(int typeId) {
- assert typeId >= 0 && typeId < FIELD_TYPE_NAMES.length : typeId;
-
- String typeName = FIELD_TYPE_NAMES[typeId];
-
- assert typeName != null : typeId;
-
- return typeName;
- }
-
- /**
- * @param typeIds Field type IDs.
- * @return Field type names.
- */
- public static Map<String, String> fieldTypeNames(Map<String, Integer> typeIds) {
- Map<String, String> names = U.newHashMap(typeIds.size());
-
- for (Map.Entry<String, Integer> e : typeIds.entrySet())
- names.put(e.getKey(), fieldTypeName(e.getValue()));
-
- return names;
- }
-
- /**
- * @param ctx Kernal context.
- */
- public CacheObjectPortableProcessorImpl(GridKernalContext ctx) {
- super(ctx);
-
- marsh = ctx.grid().configuration().getMarshaller();
-
- clientNode = this.ctx.clientNode();
-
- clientMetaDataCache = clientNode ? new ConcurrentHashMap8<PortableMetaDataKey, PortableMetadata>() : null;
- }
-
- /** {@inheritDoc} */
- @Override public void start() throws IgniteCheckedException {
- if (marsh instanceof PortableMarshaller) {
- PortableMetaDataHandler metaHnd = new PortableMetaDataHandler() {
- @Override public void addMeta(int typeId, PortableMetadata newMeta)
- throws PortableException {
- if (metaDataCache == null) {
- PortableMetadata oldMeta = metaBuf.get(typeId);
-
- if (oldMeta == null || checkMeta(typeId, oldMeta, newMeta, null)) {
- synchronized (this) {
- Map<String, String> fields = new HashMap<>();
-
- if (checkMeta(typeId, oldMeta, newMeta, fields)) {
- newMeta = new PortableMetaDataImpl(newMeta.typeName(),
- fields,
- newMeta.affinityKeyFieldName());
-
- metaBuf.put(typeId, newMeta);
- }
- else
- return;
- }
-
- if (metaDataCache == null)
- return;
- else
- metaBuf.remove(typeId);
- }
- else
- return;
- }
-
- CacheObjectPortableProcessorImpl.this.addMeta(typeId, newMeta);
- }
-
- @Override public PortableMetadata metadata(int typeId) throws PortableException {
- if (metaDataCache == null)
- U.awaitQuiet(startLatch);
-
- return CacheObjectPortableProcessorImpl.this.metadata(typeId);
- }
- };
-
- PortableMarshaller pMarh0 = (PortableMarshaller)marsh;
-
- portableCtx = new PortableContext(metaHnd, ctx.gridName());
-
- IgniteUtils.invoke(PortableMarshaller.class, pMarh0, "setPortableContext", portableCtx);
-
- portableMarsh = new GridPortableMarshaller(portableCtx);
-
- portables = new IgnitePortablesImpl(ctx, this);
- }
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override public void onUtilityCacheStarted() throws IgniteCheckedException {
- metaDataCache = ctx.cache().jcache(CU.UTILITY_CACHE_NAME);
-
- if (clientNode) {
- assert !metaDataCache.context().affinityNode();
-
- metaCacheQryId = metaDataCache.context().continuousQueries().executeInternalQuery(
- new MetaDataEntryListener(),
- new MetaDataEntryFilter(),
- false,
- true);
-
- while (true) {
- ClusterNode oldestSrvNode =
- CU.oldestAliveCacheServerNode(ctx.cache().context(), AffinityTopologyVersion.NONE);
-
- if (oldestSrvNode == null)
- break;
-
- GridCacheQueryManager qryMgr = metaDataCache.context().queries();
-
- CacheQuery<Map.Entry<PortableMetaDataKey, PortableMetadata>> qry =
- qryMgr.createScanQuery(new MetaDataPredicate(), null, false);
-
- qry.keepAll(false);
-
- qry.projection(ctx.cluster().get().forNode(oldestSrvNode));
-
- try {
- CacheQueryFuture<Map.Entry<PortableMetaDataKey, PortableMetadata>> fut = qry.execute();
-
- Map.Entry<PortableMetaDataKey, PortableMetadata> next;
-
- while ((next = fut.next()) != null) {
- assert next.getKey() != null : next;
- assert next.getValue() != null : next;
-
- addClientCacheMetaData(next.getKey(), next.getValue());
- }
- }
- catch (IgniteCheckedException e) {
- if (!ctx.discovery().alive(oldestSrvNode) || !ctx.discovery().pingNode(oldestSrvNode.id()))
- continue;
- else
- throw e;
- }
- catch (CacheException e) {
- if (X.hasCause(e, ClusterTopologyCheckedException.class, ClusterTopologyException.class))
- continue;
- else
- throw e;
- }
-
- break;
- }
- }
-
- startLatch.countDown();
-
- for (Map.Entry<Integer, PortableMetadata> e : metaBuf.entrySet())
- addMeta(e.getKey(), e.getValue());
-
- metaBuf.clear();
- }
-
- /** {@inheritDoc} */
- @Override public void onKernalStop(boolean cancel) {
- super.onKernalStop(cancel);
-
- if (metaCacheQryId != null)
- metaDataCache.context().continuousQueries().cancelInternalQuery(metaCacheQryId);
- }
-
- /**
- * @param key Metadata key.
- * @param newMeta Metadata.
- */
- private void addClientCacheMetaData(PortableMetaDataKey key, final PortableMetadata newMeta) {
- clientMetaDataCache.compute(key,
- new ConcurrentHashMap8.BiFun<PortableMetaDataKey, PortableMetadata, PortableMetadata>() {
- @Override public PortableMetadata apply(PortableMetaDataKey key, PortableMetadata oldMeta) {
- PortableMetadata res;
-
- try {
- res = checkMeta(key.typeId(), oldMeta, newMeta, null) ? newMeta : oldMeta;
- }
- catch (PortableException e) {
- res = oldMeta;
- }
-
- return res;
- }
- }
- );
- }
-
- /** {@inheritDoc} */
- @Override public int typeId(String typeName) {
- return portableCtx.typeId(typeName);
- }
-
- /**
- * @param obj Object.
- * @return Bytes.
- * @throws PortableException If failed.
- */
- public byte[] marshal(@Nullable Object obj) throws PortableException {
- byte[] arr = portableMarsh.marshal(obj);
-
- assert arr.length > 0;
-
- return arr;
- }
-
- /**
- * @param ptr Off-heap pointer.
- * @param forceHeap If {@code true} creates heap-based object.
- * @return Object.
- * @throws PortableException If failed.
- */
- public Object unmarshal(long ptr, boolean forceHeap) throws PortableException {
- assert ptr > 0 : ptr;
-
- int size = UNSAFE.getInt(ptr);
-
- ptr += 4;
-
- byte type = UNSAFE.getByte(ptr++);
-
- if (type != CacheObject.TYPE_BYTE_ARR) {
- assert size > 0 : size;
-
- PortableInputStream in = new PortableOffheapInputStream(ptr, size, forceHeap);
-
- return portableMarsh.unmarshal(in);
- }
- else
- return U.copyMemory(ptr, size);
- }
-
- /** {@inheritDoc} */
- @Override public Object marshalToPortable(@Nullable Object obj) throws PortableException {
- if (obj == null)
- return null;
-
- if (PortableUtils.isPortableType(obj.getClass()))
- return obj;
-
- if (obj instanceof Object[]) {
- Object[] arr = (Object[])obj;
-
- Object[] pArr = new Object[arr.length];
-
- for (int i = 0; i < arr.length; i++)
- pArr[i] = marshalToPortable(arr[i]);
-
- return pArr;
- }
-
- if (obj instanceof Collection) {
- Collection<Object> col = (Collection<Object>)obj;
-
- Collection<Object> pCol;
-
- if (col instanceof Set)
- pCol = (Collection<Object>)PortableUtils.newSet((Set<?>)col);
- else
- pCol = new ArrayList<>(col.size());
-
- for (Object item : col)
- pCol.add(marshalToPortable(item));
-
- return pCol;
- }
-
- if (obj instanceof Map) {
- Map<?, ?> map = (Map<?, ?>)obj;
-
- Map<Object, Object> pMap = PortableUtils.newMap((Map<Object, Object>)obj);
-
- for (Map.Entry<?, ?> e : map.entrySet())
- pMap.put(marshalToPortable(e.getKey()), marshalToPortable(e.getValue()));
-
- return pMap;
- }
-
- if (obj instanceof Map.Entry) {
- Map.Entry<?, ?> e = (Map.Entry<?, ?>)obj;
-
- return new GridMapEntry<>(marshalToPortable(e.getKey()), marshalToPortable(e.getValue()));
- }
-
- byte[] arr = portableMarsh.marshal(obj);
-
- assert arr.length > 0;
-
- Object obj0 = portableMarsh.unmarshal(arr, null);
-
- assert obj0 instanceof PortableObject;
-
- ((PortableObjectImpl)obj0).detachAllowed(true);
-
- return obj0;
- }
-
- /**
- * @return Marshaller.
- */
- public GridPortableMarshaller marshaller() {
- return portableMarsh;
- }
-
- /** {@inheritDoc} */
- @Override public PortableBuilder builder(int typeId) {
- return new PortableBuilderImpl(portableCtx, typeId);
- }
-
- /** {@inheritDoc} */
- @Override public PortableBuilder builder(String clsName) {
- return new PortableBuilderImpl(portableCtx, clsName);
- }
-
- /** {@inheritDoc} */
- @Override public PortableBuilder builder(PortableObject portableObj) {
- return PortableBuilderImpl.wrap(portableObj);
- }
-
- /** {@inheritDoc} */
- @Override public void updateMetaData(int typeId, String typeName, @Nullable String affKeyFieldName,
- Map<String, Integer> fieldTypeIds) throws PortableException {
- portableCtx.updateMetaData(typeId,
- new PortableMetaDataImpl(typeName, fieldTypeNames(fieldTypeIds), affKeyFieldName));
- }
-
- /** {@inheritDoc} */
- @Override public void addMeta(final int typeId, final PortableMetadata newMeta) throws PortableException {
- assert newMeta != null;
-
- final PortableMetaDataKey key = new PortableMetaDataKey(typeId);
-
- try {
- PortableMetadata oldMeta = metaDataCache.localPeek(key);
-
- if (oldMeta == null || checkMeta(typeId, oldMeta, newMeta, null)) {
- PortableException err = metaDataCache.invoke(key, new MetaDataProcessor(typeId, newMeta));
-
- if (err != null)
- throw err;
- }
- }
- catch (CacheException e) {
- throw new PortableException("Failed to update meta data for type: " + newMeta.typeName(), e);
- }
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public PortableMetadata metadata(final int typeId) throws PortableException {
- try {
- if (clientNode)
- return clientMetaDataCache.get(new PortableMetaDataKey(typeId));
-
- return metaDataCache.localPeek(new PortableMetaDataKey(typeId));
- }
- catch (CacheException e) {
- throw new PortableException(e);
- }
- }
-
- /** {@inheritDoc} */
- @Override public Map<Integer, PortableMetadata> metadata(Collection<Integer> typeIds)
- throws PortableException {
- try {
- Collection<PortableMetaDataKey> keys = new ArrayList<>(typeIds.size());
-
- for (Integer typeId : typeIds)
- keys.add(new PortableMetaDataKey(typeId));
-
- Map<PortableMetaDataKey, PortableMetadata> meta = metaDataCache.getAll(keys);
-
- Map<Integer, PortableMetadata> res = U.newHashMap(meta.size());
-
- for (Map.Entry<PortableMetaDataKey, PortableMetadata> e : meta.entrySet())
- res.put(e.getKey().typeId(), e.getValue());
-
- return res;
- }
- catch (CacheException e) {
- throw new PortableException(e);
- }
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("unchecked")
- @Override public Collection<PortableMetadata> metadata() throws PortableException {
- if (clientNode)
- return new ArrayList<>(clientMetaDataCache.values());
-
- return F.viewReadOnly(metaDataCache.entrySetx(metaPred),
- new C1<Cache.Entry<PortableMetaDataKey, PortableMetadata>, PortableMetadata>() {
- private static final long serialVersionUID = 0L;
-
- @Override public PortableMetadata apply(
- Cache.Entry<PortableMetaDataKey, PortableMetadata> e) {
- return e.getValue();
- }
- });
- }
-
- /** {@inheritDoc} */
- @Override public IgnitePortables portables() throws IgniteException {
- return portables;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isPortableObject(Object obj) {
- return obj instanceof PortableObject;
- }
-
- /** {@inheritDoc} */
- @Override public boolean isPortableEnabled(CacheConfiguration<?, ?> ccfg) {
- return marsh instanceof PortableMarshaller;
- }
-
- /**
- * @param po Portable object.
- * @return Affinity key.
- */
- public Object affinityKey(PortableObject po) {
- try {
- PortableMetadata meta = po.metaData();
-
- if (meta != null) {
- String affKeyFieldName = meta.affinityKeyFieldName();
-
- if (affKeyFieldName != null)
- return po.field(affKeyFieldName);
- }
- }
- catch (PortableException e) {
- U.error(log, "Failed to get affinity field from portable object: " + po, e);
- }
-
- return po;
- }
-
- /** {@inheritDoc} */
- @Override public int typeId(Object obj) {
- if (obj == null)
- return 0;
-
- return isPortableObject(obj) ? ((PortableObject)obj).typeId() : typeId(obj.getClass().getSimpleName());
- }
-
- /** {@inheritDoc} */
- @Override public Object field(Object obj, String fieldName) {
- if (obj == null)
- return null;
-
- return isPortableObject(obj) ? ((PortableObject)obj).field(fieldName) : super.field(obj, fieldName);
- }
-
- /** {@inheritDoc} */
- @Override public boolean hasField(Object obj, String fieldName) {
- return obj != null && ((PortableObject)obj).hasField(fieldName);
- }
-
- /**
- * @return Portable context.
- */
- public PortableContext portableContext() {
- return portableCtx;
- }
-
- /** {@inheritDoc} */
- @Override public CacheObjectContext contextForCache(CacheConfiguration cfg) throws IgniteCheckedException {
- assert cfg != null;
-
- boolean portableEnabled = marsh instanceof PortableMarshaller && !GridCacheUtils.isSystemCache(cfg.getName()) &&
- !GridCacheUtils.isIgfsCache(ctx.config(), cfg.getName());
-
- CacheObjectContext ctx0 = super.contextForCache(cfg);
-
- CacheObjectContext res = new CacheObjectPortableContext(ctx,
- ctx0.copyOnGet(),
- ctx0.storeValue(),
- portableEnabled,
- ctx0.addDeploymentInfo());
-
- ctx.resource().injectGeneric(res.defaultAffMapper());
-
- return res;
- }
-
- /** {@inheritDoc} */
- @Override public byte[] marshal(CacheObjectContext ctx, Object val) throws IgniteCheckedException {
- if (!((CacheObjectPortableContext)ctx).portableEnabled() || portableMarsh == null)
- return super.marshal(ctx, val);
-
- byte[] arr = portableMarsh.marshal(val);
-
- assert arr.length > 0;
-
- return arr;
- }
-
- /** {@inheritDoc} */
- @Override public Object unmarshal(CacheObjectContext ctx, byte[] bytes, ClassLoader clsLdr)
- throws IgniteCheckedException {
- if (!((CacheObjectPortableContext)ctx).portableEnabled() || portableMarsh == null)
- return super.unmarshal(ctx, bytes, clsLdr);
-
- return portableMarsh.unmarshal(bytes, clsLdr);
- }
-
- /** {@inheritDoc} */
- @Override public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj) {
- if (!((CacheObjectPortableContext)ctx).portableEnabled())
- return super.toCacheKeyObject(ctx, obj, userObj);
-
- if (obj instanceof KeyCacheObject)
- return (KeyCacheObject)obj;
-
- if (((CacheObjectPortableContext)ctx).portableEnabled()) {
- obj = toPortable(obj);
-
- if (obj instanceof PortableObject)
- return (PortableObjectImpl)obj;
- }
-
- return toCacheKeyObject0(obj, userObj);
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public CacheObject toCacheObject(CacheObjectContext ctx, @Nullable Object obj,
- boolean userObj) {
- if (!((CacheObjectPortableContext)ctx).portableEnabled())
- return super.toCacheObject(ctx, obj, userObj);
-
- if (obj == null || obj instanceof CacheObject)
- return (CacheObject)obj;
-
- obj = toPortable(obj);
-
- if (obj instanceof PortableObject)
- return (PortableObjectImpl)obj;
-
- return toCacheObject0(obj, userObj);
- }
-
- /** {@inheritDoc} */
- @Override public CacheObject toCacheObject(CacheObjectContext ctx, byte type, byte[] bytes) {
- if (type == PortableObjectImpl.TYPE_PORTABLE)
- return new PortableObjectImpl(portableContext(), bytes, 0);
-
- return super.toCacheObject(ctx, type, bytes);
- }
-
- /** {@inheritDoc} */
- @Override public CacheObject toCacheObject(GridCacheContext ctx, long valPtr, boolean tmp)
- throws IgniteCheckedException {
- if (!((CacheObjectPortableContext)ctx.cacheObjectContext()).portableEnabled())
- return super.toCacheObject(ctx, valPtr, tmp);
-
- Object val = unmarshal(valPtr, !tmp);
-
- if (val instanceof PortableObjectOffheapImpl)
- return (PortableObjectOffheapImpl)val;
-
- return new CacheObjectImpl(val, null);
- }
-
- /** {@inheritDoc} */
- @Override public Object unwrapTemporary(GridCacheContext ctx, Object obj) throws PortableException {
- if (!((CacheObjectPortableContext)ctx.cacheObjectContext()).portableEnabled())
- return obj;
-
- if (obj instanceof PortableObjectOffheapImpl)
- return ((PortableObjectOffheapImpl)obj).heapCopy();
-
- return obj;
- }
-
- /**
- * @param obj Object.
- * @return Portable object.
- * @throws IgniteException In case of error.
- */
- @Nullable public Object toPortable(@Nullable Object obj) throws IgniteException {
- if (obj == null)
- return null;
-
- if (isPortableObject(obj))
- return obj;
-
- return marshalToPortable(obj);
- }
-
- /**
- * @param typeId Type ID.
- * @param oldMeta Old meta.
- * @param newMeta New meta.
- * @param fields Fields map.
- * @return Whether meta is changed.
- * @throws PortableException In case of error.
- */
- private static boolean checkMeta(int typeId, @Nullable PortableMetadata oldMeta,
- PortableMetadata newMeta, @Nullable Map<String, String> fields) throws PortableException {
- assert newMeta != null;
-
- Map<String, String> oldFields = oldMeta != null ? ((PortableMetaDataImpl)oldMeta).fieldsMeta() : null;
- Map<String, String> newFields = ((PortableMetaDataImpl)newMeta).fieldsMeta();
-
- boolean changed = false;
-
- if (oldMeta != null) {
- if (!oldMeta.typeName().equals(newMeta.typeName())) {
- throw new PortableException(
- "Two portable types have duplicate type ID [" +
- "typeId=" + typeId +
- ", typeName1=" + oldMeta.typeName() +
- ", typeName2=" + newMeta.typeName() +
- ']'
- );
- }
-
- if (!F.eq(oldMeta.affinityKeyFieldName(), newMeta.affinityKeyFieldName())) {
- throw new PortableException(
- "Portable type has different affinity key fields on different clients [" +
- "typeName=" + newMeta.typeName() +
- ", affKeyFieldName1=" + oldMeta.affinityKeyFieldName() +
- ", affKeyFieldName2=" + newMeta.affinityKeyFieldName() +
- ']'
- );
- }
-
- if (fields != null)
- fields.putAll(oldFields);
- }
- else
- changed = true;
-
- for (Map.Entry<String, String> e : newFields.entrySet()) {
- String typeName = oldFields != null ? oldFields.get(e.getKey()) : null;
-
- if (typeName != null) {
- if (!typeName.equals(e.getValue())) {
- throw new PortableException(
- "Portable field has different types on different clients [" +
- "typeName=" + newMeta.typeName() +
- ", fieldName=" + e.getKey() +
- ", fieldTypeName1=" + typeName +
- ", fieldTypeName2=" + e.getValue() +
- ']'
- );
- }
- }
- else {
- if (fields != null)
- fields.put(e.getKey(), e.getValue());
-
- changed = true;
- }
- }
-
- return changed;
- }
-
- /**
- */
- private static class MetaDataProcessor implements
- EntryProcessor<PortableMetaDataKey, PortableMetadata, PortableException>, Externalizable {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** */
- private int typeId;
-
- /** */
- private PortableMetadata newMeta;
-
- /**
- * For {@link Externalizable}.
- */
- public MetaDataProcessor() {
- // No-op.
- }
-
- /**
- * @param typeId Type ID.
- * @param newMeta New metadata.
- */
- private MetaDataProcessor(int typeId, PortableMetadata newMeta) {
- assert newMeta != null;
-
- this.typeId = typeId;
- this.newMeta = newMeta;
- }
-
- /** {@inheritDoc} */
- @Override public PortableException process(
- MutableEntry<PortableMetaDataKey, PortableMetadata> entry,
- Object... args) {
- try {
- PortableMetadata oldMeta = entry.getValue();
-
- Map<String, String> fields = new HashMap<>();
-
- if (checkMeta(typeId, oldMeta, newMeta, fields)) {
- PortableMetadata res = new PortableMetaDataImpl(newMeta.typeName(),
- fields,
- newMeta.affinityKeyFieldName());
-
- entry.setValue(res);
-
- return null;
- }
- else
- return null;
- }
- catch (PortableException e) {
- return e;
- }
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- out.writeInt(typeId);
- out.writeObject(newMeta);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- typeId = in.readInt();
- newMeta = (PortableMetadata)in.readObject();
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(MetaDataProcessor.class, this);
- }
- }
-
- /**
- *
- */
- class MetaDataEntryListener implements CacheEntryUpdatedListener<PortableMetaDataKey, PortableMetadata> {
- /** {@inheritDoc} */
- @Override public void onUpdated(
- Iterable<CacheEntryEvent<? extends PortableMetaDataKey, ? extends PortableMetadata>> evts)
- throws CacheEntryListenerException {
- for (CacheEntryEvent<? extends PortableMetaDataKey, ? extends PortableMetadata> evt : evts) {
- assert evt.getEventType() == EventType.CREATED || evt.getEventType() == EventType.UPDATED : evt;
-
- PortableMetaDataKey key = evt.getKey();
-
- final PortableMetadata newMeta = evt.getValue();
-
- assert newMeta != null : evt;
-
- addClientCacheMetaData(key, newMeta);
- }
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(MetaDataEntryListener.class, this);
- }
- }
-
- /**
- *
- */
- static class MetaDataEntryFilter implements CacheEntryEventSerializableFilter<Object, Object> {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** {@inheritDoc} */
- @Override public boolean evaluate(CacheEntryEvent<?, ?> evt) throws CacheEntryListenerException {
- return evt.getKey() instanceof PortableMetaDataKey;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(MetaDataEntryFilter.class, this);
- }
- }
-
- /**
- *
- */
- static class MetaDataPredicate implements IgniteBiPredicate<Object, Object> {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** {@inheritDoc} */
- @Override public boolean apply(Object key, Object val) {
- return key instanceof PortableMetaDataKey;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(MetaDataPredicate.class, this);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgniteBinaryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgniteBinaryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgniteBinaryImpl.java
new file mode 100644
index 0000000..6a93a53
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgniteBinaryImpl.java
@@ -0,0 +1,177 @@
+/*
+ * 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.cache.portable;
+
+import java.util.Collection;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * {@link org.apache.ignite.IgniteBinary} implementation.
+ */
+public class IgniteBinaryImpl implements IgniteBinary {
+ /** */
+ private GridKernalContext ctx;
+
+ /** */
+ private CacheObjectBinaryProcessor proc;
+
+ /**
+ * @param ctx Context.
+ */
+ public IgniteBinaryImpl(GridKernalContext ctx, CacheObjectBinaryProcessor proc) {
+ this.ctx = ctx;
+
+ this.proc = proc;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int typeId(String typeName) {
+ guard();
+
+ try {
+ return proc.typeId(typeName);
+ }
+ finally {
+ unguard();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> T toBinary(@Nullable Object obj) throws BinaryObjectException {
+ guard();
+
+ try {
+ return (T)proc.marshalToPortable(obj);
+ }
+ finally {
+ unguard();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilder builder(int typeId) {
+ guard();
+
+ try {
+ return proc.builder(typeId);
+ }
+ finally {
+ unguard();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilder builder(String typeName) {
+ guard();
+
+ try {
+ return proc.builder(typeName);
+ }
+ finally {
+ unguard();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public BinaryObjectBuilder builder(BinaryObject portableObj) {
+ guard();
+
+ try {
+ return proc.builder(portableObj);
+ }
+ finally {
+ unguard();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public BinaryType metadata(Class<?> cls) throws BinaryObjectException {
+ guard();
+
+ try {
+ return proc.metadata(proc.typeId(cls.getName()));
+ }
+ finally {
+ unguard();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public BinaryType metadata(String typeName) throws BinaryObjectException {
+ guard();
+
+ try {
+ return proc.metadata(proc.typeId(typeName));
+ }
+ finally {
+ unguard();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
+ guard();
+
+ try {
+ return proc.metadata(typeId);
+ }
+ finally {
+ unguard();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<BinaryType> metadata() throws BinaryObjectException {
+ guard();
+
+ try {
+ return proc.metadata();
+ }
+ finally {
+ unguard();
+ }
+ }
+
+ /**
+ * @return Portable processor.
+ */
+ public IgniteCacheObjectProcessor processor() {
+ return proc;
+ }
+
+ /**
+ * <tt>ctx.gateway().readLock()</tt>
+ */
+ private void guard() {
+ ctx.gateway().readLock();
+ }
+
+ /**
+ * <tt>ctx.gateway().readUnlock()</tt>
+ */
+ private void unguard() {
+ ctx.gateway().readUnlock();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgnitePortablesImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgnitePortablesImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgnitePortablesImpl.java
deleted file mode 100644
index 5ed6505..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgnitePortablesImpl.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * 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.cache.portable;
-
-import java.util.Collection;
-import org.apache.ignite.IgnitePortables;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * {@link IgnitePortables} implementation.
- */
-public class IgnitePortablesImpl implements IgnitePortables {
- /** */
- private GridKernalContext ctx;
-
- /** */
- private CacheObjectPortableProcessor proc;
-
- /**
- * @param ctx Context.
- */
- public IgnitePortablesImpl(GridKernalContext ctx, CacheObjectPortableProcessor proc) {
- this.ctx = ctx;
-
- this.proc = proc;
- }
-
- /** {@inheritDoc} */
- @Override public int typeId(String typeName) {
- guard();
-
- try {
- return proc.typeId(typeName);
- }
- finally {
- unguard();
- }
- }
-
- /** {@inheritDoc} */
- @Override public <T> T toPortable(@Nullable Object obj) throws PortableException {
- guard();
-
- try {
- return (T)proc.marshalToPortable(obj);
- }
- finally {
- unguard();
- }
- }
-
- /** {@inheritDoc} */
- @Override public PortableBuilder builder(int typeId) {
- guard();
-
- try {
- return proc.builder(typeId);
- }
- finally {
- unguard();
- }
- }
-
- /** {@inheritDoc} */
- @Override public PortableBuilder builder(String typeName) {
- guard();
-
- try {
- return proc.builder(typeName);
- }
- finally {
- unguard();
- }
- }
-
- /** {@inheritDoc} */
- @Override public PortableBuilder builder(PortableObject portableObj) {
- guard();
-
- try {
- return proc.builder(portableObj);
- }
- finally {
- unguard();
- }
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public PortableMetadata metadata(Class<?> cls) throws PortableException {
- guard();
-
- try {
- return proc.metadata(proc.typeId(cls.getName()));
- }
- finally {
- unguard();
- }
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public PortableMetadata metadata(String typeName) throws PortableException {
- guard();
-
- try {
- return proc.metadata(proc.typeId(typeName));
- }
- finally {
- unguard();
- }
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public PortableMetadata metadata(int typeId) throws PortableException {
- guard();
-
- try {
- return proc.metadata(typeId);
- }
- finally {
- unguard();
- }
- }
-
- /** {@inheritDoc} */
- @Override public Collection<PortableMetadata> metadata() throws PortableException {
- guard();
-
- try {
- return proc.metadata();
- }
- finally {
- unguard();
- }
- }
-
- /**
- * @return Portable processor.
- */
- public IgniteCacheObjectProcessor processor() {
- return proc;
- }
-
- /**
- * <tt>ctx.gateway().readLock()</tt>
- */
- private void guard() {
- ctx.gateway().readLock();
- }
-
- /**
- * <tt>ctx.gateway().readUnlock()</tt>
- */
- private void unguard() {
- ctx.gateway().readUnlock();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
index 1c8107e..58a8424 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
@@ -907,7 +907,8 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
CacheObject cacheVal =
entry != null ? entry.peek(true, false, false, topVer, expiryPlc) : null;
- val = cacheVal != null ? (V)cacheVal.value(cctx.cacheObjectContext(), false) : null;
+ // TODO 950 nocopy
+ val = (V)cctx.cacheObjectContext().unwrapPortableIfNeeded(cacheVal, qry.keepPortable());
}
catch (GridCacheEntryRemovedException e) {
val = null;
@@ -1093,7 +1094,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
next = null;
while (it.hasNext()) {
- final LazySwapEntry e = new LazySwapEntry(it.next());
+ final LazySwapEntry e = new LazySwapEntry(it.next(), keepPortable);
if (filter != null) {
K key = (K)cctx.unwrapPortableIfNeeded(e.key(), keepPortable);
@@ -2510,11 +2511,15 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
/** */
private final Map.Entry<byte[], byte[]> e;
+ /** */
+ private boolean keepBinary;
+
/**
* @param e Entry with
*/
- LazySwapEntry(Map.Entry<byte[], byte[]> e) {
+ LazySwapEntry(Map.Entry<byte[], byte[]> e, boolean keepBinary) {
this.e = e;
+ this.keepBinary = keepBinary;
}
/** {@inheritDoc} */
@@ -2529,7 +2534,7 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
CacheObject obj = cctx.cacheObjects().toCacheObject(cctx.cacheObjectContext(), t.get2(), t.get1());
- return obj.value(cctx.cacheObjectContext(), false);
+ return (V)cctx.cacheObjectContext().unwrapPortableIfNeeded(obj, keepBinary);
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java
index c7feda4..fa2d6b1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java
@@ -165,7 +165,7 @@ public class GridCacheQueryRequest extends GridCacheMessage implements GridCache
* @param incBackups {@code true} if need to include backups.
* @param fields Fields query flag.
* @param all Whether to load all pages.
- * @param keepPortable Whether to keep portables.
+ * @param keepPortable Whether to keep binary.
* @param subjId Subject ID.
* @param taskHash Task name hash code.
* @param topVer Topology version.
@@ -452,7 +452,7 @@ public class GridCacheQueryRequest extends GridCacheMessage implements GridCache
}
/**
- * @return Whether to keep portables.
+ * @return Whether to keep binary.
*/
public boolean keepPortable() {
return keepPortable;
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEvent.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEvent.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEvent.java
index 7417138..d26be5f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEvent.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEvent.java
@@ -21,7 +21,6 @@ import javax.cache.Cache;
import javax.cache.event.CacheEntryEvent;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.S;
/**
@@ -60,18 +59,18 @@ class CacheContinuousQueryEvent<K, V> extends CacheEntryEvent<K, V> {
/** {@inheritDoc} */
@Override
public K getKey() {
- return e.key().value(cctx.cacheObjectContext(), false);
+ return (K)cctx.cacheObjectContext().unwrapPortableIfNeeded(e.key(), true, false);
}
/** {@inheritDoc} */
@Override public V getValue() {
- return CU.value(e.value(), cctx, false);
+ return (V)cctx.cacheObjectContext().unwrapPortableIfNeeded(e.value(), true, false);
}
/** {@inheritDoc} */
@Override
public V getOldValue() {
- return CU.value(e.oldValue(), cctx, false);
+ return (V)cctx.cacheObjectContext().unwrapPortableIfNeeded(e.oldValue(), true, false);
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
index 174e1ce..f48ff38 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/GridCacheStoreManagerAdapter.java
@@ -60,6 +60,7 @@ import org.apache.ignite.internal.util.typedef.internal.SB;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiInClosure;
import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.lang.IgniteClosure;
import org.apache.ignite.lifecycle.LifecycleAware;
import org.apache.ignite.transactions.Transaction;
import org.jetbrains.annotations.NotNull;
@@ -269,10 +270,7 @@ public abstract class GridCacheStoreManagerAdapter extends GridCacheManagerAdapt
// Never load internal keys from store as they are never persisted.
return null;
- Object storeKey = key.value(cctx.cacheObjectContext(), false);
-
- if (convertPortable())
- storeKey = cctx.unwrapPortableIfNeeded(storeKey, false);
+ Object storeKey = cctx.unwrapPortableIfNeeded(key, !convertPortable());
if (log.isDebugEnabled())
log.debug("Loading value from store for key: " + storeKey);
@@ -396,22 +394,12 @@ public abstract class GridCacheStoreManagerAdapter extends GridCacheManagerAdapt
return;
}
- Collection<Object> keys0;
-
- if (convertPortable()) {
- keys0 = F.viewReadOnly(keys, new C1<KeyCacheObject, Object>() {
- @Override public Object apply(KeyCacheObject key) {
- return cctx.unwrapPortableIfNeeded(key.value(cctx.cacheObjectContext(), false), false);
- }
- });
- }
- else {
- keys0 = F.viewReadOnly(keys, new C1<KeyCacheObject, Object>() {
+ Collection<Object> keys0 = F.viewReadOnly(keys,
+ new C1<KeyCacheObject, Object>() {
@Override public Object apply(KeyCacheObject key) {
- return key.value(cctx.cacheObjectContext(), false);
+ return cctx.unwrapPortableIfNeeded(key, !convertPortable());
}
});
- }
if (log.isDebugEnabled())
log.debug("Loading values from store for keys: " + keys0);
@@ -532,10 +520,8 @@ public abstract class GridCacheStoreManagerAdapter extends GridCacheManagerAdapt
if (key instanceof GridCacheInternal)
return true;
- if (convertPortable()) {
- key = cctx.unwrapPortableIfNeeded(key, false);
- val = cctx.unwrapPortableIfNeeded(val, false);
- }
+ key = cctx.unwrapPortableIfNeeded(key, !convertPortable());
+ val = cctx.unwrapPortableIfNeeded(val, !convertPortable());
if (log.isDebugEnabled())
log.debug("Storing value in cache store [key=" + key + ", val=" + val + ']');
@@ -637,8 +623,7 @@ public abstract class GridCacheStoreManagerAdapter extends GridCacheManagerAdapt
if (key instanceof GridCacheInternal)
return false;
- if (convertPortable())
- key = cctx.unwrapPortableIfNeeded(key, false);
+ key = cctx.unwrapPortableIfNeeded(key, !convertPortable());
if (log.isDebugEnabled())
log.debug("Removing value from cache store [key=" + key + ']');
@@ -686,7 +671,7 @@ public abstract class GridCacheStoreManagerAdapter extends GridCacheManagerAdapt
}
if (store != null) {
- Collection<Object> keys0 = convertPortable() ? cctx.unwrapPortablesIfNeeded(keys, false) : keys;
+ Collection<Object> keys0 = cctx.unwrapPortablesIfNeeded(keys, !convertPortable());
if (log.isDebugEnabled())
log.debug("Removing values from cache store [keys=" + keys0 + ']');
@@ -773,7 +758,7 @@ public abstract class GridCacheStoreManagerAdapter extends GridCacheManagerAdapt
assert e != null;
if (e.getMessage() != null) {
- throw new IgniteCheckedException("Cache store must work with portable objects if portables are " +
+ throw new IgniteCheckedException("Cache store must work with portable objects if binary are " +
"enabled for cache [cacheName=" + cctx.namex() + ']', e);
}
else
@@ -1093,15 +1078,13 @@ public abstract class GridCacheStoreManagerAdapter extends GridCacheManagerAdapt
Object k = e.getKey();
- if (rmvd != null && rmvd.contains(k))
- continue;
-
Object v = locStore ? e.getValue() : e.getValue().get1();
- if (convertPortable()) {
- k = cctx.unwrapPortableIfNeeded(k, false);
- v = cctx.unwrapPortableIfNeeded(v, false);
- }
+ k = cctx.unwrapPortableIfNeeded(k, !convertPortable());
+ v = cctx.unwrapPortableIfNeeded(v, !convertPortable());
+
+ if (rmvd != null && rmvd.contains(k))
+ continue;
next = new CacheEntryImpl<>(k, v);
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
index 716676f..76f2f77 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
@@ -142,8 +142,13 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx {
* @return Transaction.
*/
@SuppressWarnings("unchecked")
- private IgniteInternalTx txStart0(TransactionConcurrency concurrency, TransactionIsolation isolation,
- long timeout, int txSize, @Nullable GridCacheContext sysCacheCtx) {
+ private IgniteInternalTx txStart0(
+ TransactionConcurrency concurrency,
+ TransactionIsolation isolation,
+ long timeout,
+ int txSize,
+ @Nullable GridCacheContext sysCacheCtx
+ ) {
cctx.kernalContext().gateway().readLock();
try {
@@ -152,7 +157,6 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx {
if (tx != null)
throw new IllegalStateException("Failed to start new transaction " +
"(current thread already has a transaction): " + tx);
-
tx = cctx.tm().newTx(
false,
false,
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
index 1c82636..4103af2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxAdapter.java
@@ -1286,7 +1286,8 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
/*subjId*/subjId,
/**closure name */recordEvt ? F.first(txEntry.entryProcessors()).get1() : null,
resolveTaskName(),
- null);
+ null,
+ txEntry.keepBinary());
boolean modified = false;
@@ -1310,7 +1311,7 @@ public abstract class IgniteTxAdapter extends GridMetadataAwareAdapter
for (T2<EntryProcessor<Object, Object, Object>, Object[]> t : txEntry.entryProcessors()) {
CacheInvokeEntry<Object, Object> invokeEntry = new CacheInvokeEntry(txEntry.context(),
- txEntry.key(), key, cacheVal, val, ver);
+ txEntry.key(), key, cacheVal, val, ver, txEntry.keepBinary());
try {
EntryProcessor<Object, Object, Object> processor = t.get1();
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
index 9eb2808..60ff33c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java
@@ -54,6 +54,7 @@ import org.jetbrains.annotations.Nullable;
import static org.apache.ignite.internal.processors.cache.GridCacheOperation.READ;
import static org.apache.ignite.internal.processors.cache.GridCacheOperation.TRANSFORM;
+import static org.apache.ignite.internal.processors.cache.GridCacheUtils.KEEP_BINARY_FLAG_MASK;
import static org.apache.ignite.internal.processors.cache.GridCacheUtils.SKIP_STORE_FLAG_MASK;
/**
@@ -178,6 +179,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
/**
* Additional flags.
* GridCacheUtils.SKIP_STORE_FLAG_MASK - for skipStore flag value.
+ * GridCacheUtils.KEEP_BINARY_FLAG_MASK - for withKeepBinary flag.
*/
private byte flags;
@@ -212,7 +214,9 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
long conflictExpireTime,
GridCacheEntryEx entry,
@Nullable GridCacheVersion conflictVer,
- boolean skipStore) {
+ boolean skipStore,
+ boolean keepBinary
+ ) {
assert ctx != null;
assert tx != null;
assert op != null;
@@ -227,6 +231,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
this.conflictVer = conflictVer;
skipStore(skipStore);
+ keepBinary(keepBinary);
key = entry.key();
@@ -258,7 +263,9 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
GridCacheEntryEx entry,
CacheEntryPredicate[] filters,
GridCacheVersion conflictVer,
- boolean skipStore) {
+ boolean skipStore,
+ boolean keepBinary
+ ) {
assert ctx != null;
assert tx != null;
assert op != null;
@@ -273,6 +280,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
this.conflictVer = conflictVer;
skipStore(skipStore);
+ keepBinary(keepBinary);
if (entryProcessor != null)
addEntryProcessor(entryProcessor, invokeArgs);
@@ -436,14 +444,50 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
* @param skipStore Skip store flag.
*/
public void skipStore(boolean skipStore){
- flags = skipStore ? (byte)(flags | SKIP_STORE_FLAG_MASK) : (byte)(flags & ~SKIP_STORE_FLAG_MASK);
+ setFlag(skipStore, SKIP_STORE_FLAG_MASK);
}
/**
* @return Skip store flag.
*/
public boolean skipStore() {
- return (flags & SKIP_STORE_FLAG_MASK) == 1;
+ return isFlag(SKIP_STORE_FLAG_MASK);
+ }
+
+ /**
+ * Sets keep binary flag value.
+ *
+ * @param keepBinary Keep binary flag value.
+ */
+ public void keepBinary(boolean keepBinary) {
+ setFlag(keepBinary, KEEP_BINARY_FLAG_MASK);
+ }
+
+ /**
+ * @return Keep binary flag value.
+ */
+ public boolean keepBinary() {
+ return isFlag(KEEP_BINARY_FLAG_MASK);
+ }
+
+ /**
+ * Sets flag mask.
+ *
+ * @param flag Set or clear.
+ * @param mask Mask.
+ */
+ private void setFlag(boolean flag, int mask) {
+ flags = flag ? (byte)(flags | mask) : (byte)(flags & ~mask);
+ }
+
+ /**
+ * Reads flag mask.
+ *
+ * @param mask Mask to read.
+ * @return Flag value.
+ */
+ private boolean isFlag(int mask) {
+ return (flags & mask) != 0;
}
/**
@@ -616,7 +660,7 @@ public class IgniteTxEntry implements GridPeerDeployAware, Message {
for (T2<EntryProcessor<Object, Object, Object>, Object[]> t : entryProcessors()) {
try {
CacheInvokeEntry<Object, Object> invokeEntry = new CacheInvokeEntry(ctx, key, keyVal, cacheVal, val,
- ver);
+ ver, keepBinary());
EntryProcessor processor = t.get1();