, IgniteAsyncS
* so keys and values will be returned from cache API methods without changes. Therefore,
* signature of the projection can contain only following types:
*
- * {@link org.apache.ignite.portables.PortableObject} for portable classes
+ * {@link org.gridgain.grid.portables.PortableObject} for portable classes
* All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)
* Arrays of primitives (byte[], int[], ...)
* {@link String} and array of {@link String}s
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 68579616ff43e..0000000000000
--- a/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java
+++ /dev/null
@@ -1,364 +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 org.apache.ignite.portables.*;
-import org.jetbrains.annotations.*;
-
-import java.sql.*;
-import java.util.*;
-import java.util.Date;
-
-/**
- * Defines portable objects functionality. With portable objects you are able to:
- *
- * Seamlessly interoperate between Java, .NET, and C++.
- * Make any object portable with zero code change to your existing code.
- * Nest portable objects within each other.
- * Automatically handle {@code circular} or {@code null} references.
- * Automatically convert collections and maps between Java, .NET, and C++.
- *
- * Optionally avoid deserialization of objects on the server side
- * (objects are stored in {@link org.apache.ignite.portables.PortableObject} format).
- *
- * Avoid need to have concrete class definitions on the server side.
- * Dynamically change structure of the classes without having to restart the cluster.
- * Index into portable objects for querying purposes.
- *
- *
- * 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).
- *
- * To work with the portable format directly, user should create a special cache projection
- * using {@link org.apache.ignite.cache.CacheProjection#keepPortable()} method and then retrieve individual fields as needed:
- *
- * CacheProjection<GridPortableObject.class, GridPortableObject.class> prj = cache.keepPortable();
- *
- * // Convert instance of MyKey to portable format.
- * // We could also use GridPortableBuilder to create
- * // the key in portable format directly.
- * GridPortableObject key = grid.portables().toPortable(new MyKey());
- *
- * GridPortableObject val = prj.get(key);
- *
- * String field = val.field("myFieldName");
- *
- * 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,
- * Ignite will only deserialize on the first access and will cache the deserialized object,
- * so it does not have to be deserialized again:
- *
- * CacheProjection<MyKey.class, MyValue.class> prj =
- * cache.projection(MyKey.class, MyValue.class);
- *
- * MyValue val = prj.get(new MyKey());
- *
- * // Normal java getter.
- * String fieldVal = val.getMyFieldName();
- *
- * 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:
- *
- * CacheProjection<Integer.class, GridPortableObject.class> prj = cache.keepPortable();
- *
- *
- * Note that only portable classes are converted to {@link org.apache.ignite.portables.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):
- *
- * All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)
- * Arrays of primitives (byte[], int[], ...)
- * {@link String} and array of {@link String}s
- * {@link UUID} and array of {@link UUID}s
- * {@link Date} and array of {@link Date}s
- * {@link Timestamp} and array of {@link Timestamp}s
- * Enums and array of enums
- *
- * Maps, collections and array of objects (but objects inside
- * them will still be converted if they are portable)
- *
- *
- *
- * 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.
- *
- * Ignite comes with {@link org.apache.ignite.portables.PortableBuilder} which allows to build portable objects dynamically:
- *
- * GridPortableBuilder builder = Ignition.ignite().portables().builder();
- *
- * builder.typeId("MyObject");
- *
- * builder.stringField("fieldA", "A");
- * build.intField("fieldB", "B");
- *
- * GridPortableObject portableObj = builder.build();
- *
- * 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:
- *
- * MyObject obj = new MyObject();
- *
- * obj.setFieldA("A");
- * obj.setFieldB(123);
- *
- * GridPortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
- *
- * NOTE: you don't need to convert typed objects to portable format before storing
- * them in cache, Ignite will do that automatically.
- *
- * 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) GridPortables.metadata(...)}
- * methods. Having metadata also allows for proper formatting of {@code GridPortableObject.toString()} method,
- * even when portable objects are kept in binary format only, which may be necessary for audit reasons.
- *
- * 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.
- *
- * To make any object portable, you have to specify it in {@link org.apache.ignite.portables.PortableConfiguration}
- * at startup. 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.
- *
- * Here is an example of portable configuration (note that star (*) notation is supported):
- *
- * ...
- * <!-- Portable objects configuration. -->
- * <property name="portableConfiguration">
- * <bean class="org.apache.ignite.portables.PortableConfiguration">
- * <property name="classNames">
- * <list>
- * <value>my.package.for.portable.objects.*</value>
- * <value>org.apache.ignite.examples.client.portable.Employee</value>
- * </list>
- * </property>
- * </bean>
- * </property>
- * ...
- *
- * or from code:
- *
- * GridConfiguration gridCfg = new GridConfiguration();
- *
- * GridPortableConfiguration portCfg = new GridPortableConfiguration();
- *
- * portCfg.setClassNames(Arrays.asList(
- * Employee.class.getName(),
- * Address.class.getName())
- * );
- *
- * gridCfg.setPortableConfiguration(portCfg);
- *
- * You can also specify class name for a portable object via {@link org.apache.ignite.portables.PortableTypeConfiguration}.
- * Do it in case if you need to override other configuration properties on per-type level, like
- * ID-mapper, or serializer.
- *
- * 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:
- *
- * <property name="portableConfiguration">
- * <bean class="org.apache.ignite.portables.PortableConfiguration">
- * ...
- * <property name="typeConfigurations">
- * <list>
- * <bean class="org.apache.ignite.portables.PortableTypeConfiguration">
- * <property name="className" value="org.apache.ignite.examples.client.portable.EmployeeKey"/>
- * <property name="affinityKeyFieldName" value="organizationId"/>
- * </bean>
- * </list>
- * </property>
- * ...
- * </bean>
- * </property>
- *
- *
- * Once portable object is specified in {@link org.apache.ignite.portables.PortableConfiguration}, Ignite will
- * be able to serialize and deserialize it. However, you can provide your own custom
- * serialization logic by optionally implementing {@link org.apache.ignite.portables.PortableMarshalAware} interface, like so:
- *
- * public class Address implements GridPortableMarshalAware {
- * private String street;
- * private int zip;
- *
- * // Empty constructor required for portable deserialization.
- * public Address() {}
- *
- * @Override public void writePortable(GridPortableWriter writer) throws GridPortableException {
- * writer.writeString("street", street);
- * writer.writeInt("zip", zip);
- * }
- *
- * @Override public void readPortable(GridPortableReader reader) throws GridPortableException {
- * street = reader.readString("street");
- * zip = reader.readInt("zip");
- * }
- * }
- *
- * Alternatively, if you cannot change class definitions, you can provide custom serialization
- * logic in {@link org.apache.ignite.portables.PortableSerializer} either globally in {@link org.apache.ignite.portables.PortableConfiguration} or
- * for a specific type via {@link org.apache.ignite.portables.PortableTypeConfiguration} instance.
- *
- * Similar to java serialization you can use {@code writeReplace()} and {@code readResolve()} methods.
- *
- *
- * {@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.
- *
- *
- * {@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.
- *
- *
- *
- *
- * 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.portables.PortableIdMapper} implementation.
- *
- * ID-mapper may be provided either globally in {@link org.apache.ignite.portables.PortableConfiguration},
- * or for a specific type via {@link org.apache.ignite.portables.PortableTypeConfiguration} instance.
- *
- * 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:
- *
- * ...
- * <bean class="org.apache.ignite.cache.CacheConfiguration">
- * ...
- * <property name="queryConfiguration">
- * <bean class="CacheQueryConfiguration">
- * <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>
- * </property>
- * </bean>
- *
- */
-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 org.apache.ignite.portables.PortableObject}.
- *
- * Note that object's type needs to be configured in {@link org.apache.ignite.portables.PortableConfiguration}.
- *
- * @param obj Object to convert.
- * @return Converted object.
- * @throws org.apache.ignite.portables.PortableException In case of error.
- */
- public 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 org.apache.ignite.portables.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 org.apache.ignite.portables.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 org.apache.ignite.portables.PortableException In case of error.
- */
- @Nullable public PortableMetadata metadata(int typeId) throws PortableException;
-
- /**
- * Gets metadata for all known types.
- *
- * @return Metadata.
- * @throws org.apache.ignite.portables.PortableException In case of error.
- */
- public Collection metadata() throws PortableException;
-}
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java b/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
index fd378d4103b56..b6e4dc1546022 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheProjection.java
@@ -290,7 +290,7 @@ public interface CacheProjection extends Iterable> {
* so keys and values will be returned from cache API methods without changes. Therefore,
* signature of the projection can contain only following types:
*
- * {@link org.apache.ignite.portables.PortableObject} for portable classes
+ * {@link org.gridgain.grid.portables.PortableObject} for portable classes
* All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)
* Arrays of primitives (byte[], int[], ...)
* {@link String} and array of {@link String}s
@@ -477,9 +477,17 @@ public interface CacheProjection extends Iterable> {
* @param key Key.
* @param peekModes Peek modes.
* @return Value.
+ * @throws IgniteCheckedException If failed.
*/
@Nullable public V localPeek(K key, CachePeekMode[] peekModes) throws IgniteCheckedException;
+ /**
+ * @param peekModes Peek modes.
+ * @return Entries iterable.
+ * @throws IgniteCheckedException If failed.
+ */
+ public Iterable> localEntries(CachePeekMode[] peekModes) throws IgniteCheckedException;
+
/**
* Peeks at cached value using optional set of peek modes. This method will sequentially
* iterate over given peek modes in the order passed in, and try to peek at value using
@@ -1408,6 +1416,11 @@ public IgniteTx txStartPartition(int partId, IgniteTxConcurrency concurrency,
*/
public void clear() throws IgniteCheckedException;
+ /**
+ * @return Clear future.
+ */
+ public IgniteInternalFuture> clearAsync();
+
/**
* Clears cache on all nodes that store it's data. That is, caches are cleared on remote
* nodes and local node, as opposed to {@link CacheProjection#clearLocally()} method which only
@@ -1669,6 +1682,11 @@ public IgniteInternalFuture> removeAllAsync(@Nullable Collection extends K>
*/
public void removeAll() throws IgniteCheckedException;
+ /**
+ * @return Remove future.
+ */
+ public IgniteInternalFuture> removeAllAsync();
+
/**
* Asynchronously removes mappings from cache for entries for which the optionally passed in filters do
* pass. If passed in filters are {@code null}, then all entries in cache will be enrolled
@@ -1874,6 +1892,26 @@ public void unlockAll(@Nullable Collection extends K> keys,
*/
public int size();
+ /**
+ * @param peekModes Peek modes.
+ * @return Local cache size.
+ * @throws IgniteCheckedException If failed.
+ */
+ public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException;
+
+ /**
+ * @param peekModes Peek modes.
+ * @return Global cache size.
+ * @throws IgniteCheckedException If failed.
+ */
+ public int size(CachePeekMode[] peekModes) throws IgniteCheckedException;
+
+ /**
+ * @param peekModes Peek modes.
+ * @return Future.
+ */
+ public IgniteInternalFuture sizeAsync(CachePeekMode[] peekModes);
+
/**
* Gets the number of all entries cached across all nodes.
*
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStore.java
index 367773fe6d33e..114b56e77eb66 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/CacheStore.java
@@ -20,7 +20,6 @@
import org.apache.ignite.*;
import org.apache.ignite.cache.store.jdbc.*;
import org.apache.ignite.lang.*;
-import org.apache.ignite.portables.*;
import org.apache.ignite.resources.*;
import org.apache.ignite.transactions.*;
import org.jetbrains.annotations.*;
@@ -69,8 +68,8 @@
* }
*
*
- * When portables are enabled for cache by setting {@link org.apache.ignite.configuration.CacheConfiguration#isPortableEnabled()} to
- * {@code true}), all portable keys and values are converted to instances of {@link PortableObject}.
+ * When portables are enabled for cache by setting {@code org.apache.ignite.configuration.CacheConfiguration#isPortableEnabled()} to
+ * {@code true}), all portable keys and values are converted to instances of {@code PortableObject}.
* Therefore, all cache store methods will take parameters in portable format. To avoid class
* cast exceptions, store must have signature compatible with portables. E.g., if you use {@link Integer}
* as a key and {@code Value} class as a value (which will be converted to portable format), cache store
@@ -84,7 +83,7 @@
* ...
* }
*
- * This behavior can be overridden by setting {@link org.apache.ignite.configuration.CacheConfiguration#setKeepPortableInStore(boolean)}
+ * This behavior can be overridden by setting {@code org.apache.ignite.configuration.CacheConfiguration#setKeepPortableInStore(boolean)}
* flag value to {@code false}. In this case, Ignite will deserialize keys and values stored in portable
* format before they are passed to cache store, so that you can use the following cache store signature instead:
*
@@ -100,7 +99,7 @@
* 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 store is invoked.
*
- * Note that only portable classes are converted to {@link PortableObject} format. Following
+ * Note that only portable classes are converted to {@code PortableObject} format. Following
* types are stored in cache without changes and therefore should not affect cache store signature:
*
* All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)
@@ -116,7 +115,6 @@
*
*
*
- * @see IgnitePortables
* @see CacheStoreSession
*/
public abstract class CacheStore implements CacheLoader, CacheWriter {
diff --git a/modules/core/src/main/java/org/apache/ignite/client/GridClientCacheFlag.java b/modules/core/src/main/java/org/apache/ignite/client/GridClientCacheFlag.java
index 9cf307ed54d39..eeba6583dc84e 100644
--- a/modules/core/src/main/java/org/apache/ignite/client/GridClientCacheFlag.java
+++ b/modules/core/src/main/java/org/apache/ignite/client/GridClientCacheFlag.java
@@ -43,7 +43,7 @@ public enum GridClientCacheFlag {
* Disable deserialization of portable objects on get operations.
* If set and portable marshaller is used, {@link GridClientData#get(Object)}
* and {@link GridClientData#getAll(Collection)} methods will return
- * instances of {@link org.apache.ignite.portables.PortableObject} class instead of user objects.
+ * instances of {@link org.gridgain.grid.portables.PortableObject} class instead of user objects.
* Use this flag if you don't have corresponding class on your client of
* if you want to get access to some individual fields, but do not want to
* fully deserialize the object.
diff --git a/modules/core/src/main/java/org/apache/ignite/client/GridClientConfiguration.java b/modules/core/src/main/java/org/apache/ignite/client/GridClientConfiguration.java
index d571f470a6ea3..bf3a01374dc94 100644
--- a/modules/core/src/main/java/org/apache/ignite/client/GridClientConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/client/GridClientConfiguration.java
@@ -25,7 +25,6 @@
import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.plugin.security.*;
-import org.apache.ignite.portables.*;
import org.jetbrains.annotations.*;
import java.net.*;
@@ -117,9 +116,6 @@ public class GridClientConfiguration {
/** Daemon flag. */
private boolean daemon;
- /** Portable configuration. */
- private PortableConfiguration portableCfg;
-
/**
* Creates default configuration.
*/
@@ -154,7 +150,6 @@ public GridClientConfiguration(GridClientConfiguration cfg) {
topRefreshFreq = cfg.getTopologyRefreshFrequency();
daemon = cfg.isDaemon();
marshaller = cfg.getMarshaller();
- portableCfg = cfg.getPortableConfiguration();
setDataConfigurations(cfg.getDataConfigurations());
}
@@ -631,24 +626,6 @@ public void setMarshaller(GridClientMarshaller marshaller) {
this.marshaller = marshaller;
}
- /**
- * Gets portable configuration.
- *
- * @return Portable configuration.
- */
- public PortableConfiguration getPortableConfiguration() {
- return portableCfg;
- }
-
- /**
- * Sets portable configuration.
- *
- * @param portableCfg Portable configuration.
- */
- public void setPortableConfiguration(@Nullable PortableConfiguration portableCfg) {
- this.portableCfg = portableCfg;
- }
-
/**
* Load client configuration from the properties map.
*
diff --git a/modules/core/src/main/java/org/apache/ignite/client/GridClientFactory.java b/modules/core/src/main/java/org/apache/ignite/client/GridClientFactory.java
index 647155e018d8c..339a9f7a97a36 100644
--- a/modules/core/src/main/java/org/apache/ignite/client/GridClientFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/client/GridClientFactory.java
@@ -54,7 +54,7 @@ public static GridClient start(GridClientConfiguration cfg) throws GridClientExc
try {
UUID clientId = UUID.randomUUID();
- GridClientImpl client = new GridClientImpl(clientId, cfg);
+ GridClientImpl client = new GridClientImpl(clientId, cfg, false);
GridClientImpl old = openClients.putIfAbsent(clientId, client);
diff --git a/modules/core/src/main/java/org/apache/ignite/client/impl/GridClientImpl.java b/modules/core/src/main/java/org/apache/ignite/client/impl/GridClientImpl.java
index 8f64a79188228..43b8d2004744c 100644
--- a/modules/core/src/main/java/org/apache/ignite/client/impl/GridClientImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/client/impl/GridClientImpl.java
@@ -103,12 +103,13 @@ public class GridClientImpl implements GridClient {
*
* @param id Client identifier.
* @param cfg0 Client configuration.
+ * @param routerClient Router client flag.
* @throws GridClientException If client configuration is incorrect.
* @throws GridServerUnreachableException If none of the servers specified in configuration can
* be reached.
*/
@SuppressWarnings("CallToThreadStartDuringObjectConstruction")
- public GridClientImpl(UUID id, GridClientConfiguration cfg0) throws GridClientException {
+ public GridClientImpl(UUID id, GridClientConfiguration cfg0, boolean routerClient) throws GridClientException {
this.id = id;
cfg = new GridClientConfiguration(cfg0);
@@ -158,7 +159,7 @@ public GridClientImpl(UUID id, GridClientConfiguration cfg0) throws GridClientEx
throw new GridClientException("Servers addresses and routers addresses cannot both be provided " +
"for client (please fix configuration and restart): " + this);
- connMgr = createConnectionManager(id, sslCtx, cfg, routers, top, null);
+ connMgr = createConnectionManager(id, sslCtx, cfg, routers, top, null, routerClient);
try {
// Init connection manager, it should cause topology update.
@@ -385,8 +386,9 @@ private static Collection parseAddresses(Collection c
* @return New connection manager based on current client settings.
* @throws GridClientException If failed to start connection server.
*/
- public GridClientConnectionManager newConnectionManager(@Nullable Byte marshId) throws GridClientException {
- return createConnectionManager(id, sslCtx, cfg, routers, top, marshId);
+ public GridClientConnectionManager newConnectionManager(@Nullable Byte marshId, boolean routerClient)
+ throws GridClientException {
+ return createConnectionManager(id, sslCtx, cfg, routers, top, marshId, routerClient);
}
/**
@@ -399,7 +401,7 @@ public GridClientConnectionManager newConnectionManager(@Nullable Byte marshId)
*/
private GridClientConnectionManager createConnectionManager(UUID clientId, SSLContext sslCtx,
GridClientConfiguration cfg, Collection routers, GridClientTopology top,
- @Nullable Byte marshId)
+ @Nullable Byte marshId, boolean routerClient)
throws GridClientException {
GridClientConnectionManager mgr;
@@ -409,10 +411,11 @@ private GridClientConnectionManager createConnectionManager(UUID clientId, SSLCo
Constructor> cons = cls.getConstructor(UUID.class, SSLContext.class, GridClientConfiguration.class,
Collection.class, GridClientTopology.class, Byte.class);
- mgr = (GridClientConnectionManager)cons.newInstance(clientId, sslCtx, cfg, routers, top, marshId);
+ mgr = (GridClientConnectionManager)cons.newInstance(clientId, sslCtx, cfg, routers, top, marshId,
+ routerClient);
}
catch (ClassNotFoundException ignored) {
- mgr = new GridClientConnectionManagerOsImpl(clientId, sslCtx, cfg, routers, top, marshId);
+ mgr = new GridClientConnectionManagerOsImpl(clientId, sslCtx, cfg, routers, top, marshId, routerClient);
}
catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new GridClientException("Failed to create client connection manager.", e);
diff --git a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java
index fbc90879dae22..b689b9b6cfb0c 100644
--- a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java
@@ -22,7 +22,7 @@
import org.apache.ignite.client.impl.*;
import org.apache.ignite.client.util.*;
import org.apache.ignite.internal.processors.rest.client.message.*;
-import org.apache.ignite.internal.util.direct.*;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.*;
import org.apache.ignite.internal.util.nio.*;
import org.apache.ignite.internal.util.nio.ssl.*;
import org.apache.ignite.internal.util.typedef.*;
@@ -95,44 +95,6 @@ abstract class GridClientConnectionManagerAdapter implements GridClientConnectio
/** Marshaller ID. */
private final Byte marshId;
- /** Message writer. */
- @SuppressWarnings("FieldCanBeLocal")
- private final GridNioMessageWriter msgWriter = new GridNioMessageWriter() {
- @Override public boolean write(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, ByteBuffer buf) {
- assert msg != null;
- assert buf != null;
-
- msg.messageWriter(this, nodeId);
-
- return msg.writeTo(buf);
- }
-
- @Override public int writeFully(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg, OutputStream out,
- ByteBuffer buf) throws IOException {
- assert msg != null;
- assert out != null;
- assert buf != null;
- assert buf.hasArray();
-
- msg.messageWriter(this, nodeId);
-
- boolean finished = false;
- int cnt = 0;
-
- while (!finished) {
- finished = msg.writeTo(buf);
-
- out.write(buf.array(), 0, buf.position());
-
- cnt += buf.position();
-
- buf.clear();
- }
-
- return cnt;
- }
- };
-
/**
* @param clientId Client ID.
* @param sslCtx SSL context to enable secured connection or {@code null} to use unsecured one.
@@ -148,7 +110,8 @@ protected GridClientConnectionManagerAdapter(UUID clientId,
GridClientConfiguration cfg,
Collection routers,
GridClientTopology top,
- @Nullable Byte marshId)
+ @Nullable Byte marshId,
+ boolean routerClient)
throws GridClientException {
assert clientId != null : "clientId != null";
assert cfg != null : "cfg != null";
@@ -180,28 +143,12 @@ protected GridClientConnectionManagerAdapter(UUID clientId,
GridNioFilter[] filters;
- GridNioMessageReader msgReader = new GridNioMessageReader() {
- @Override public boolean read(@Nullable UUID nodeId, GridTcpCommunicationMessageAdapter msg,
- ByteBuffer buf) {
- assert msg != null;
- assert buf != null;
-
- msg.messageReader(this, nodeId);
-
- return msg.readFrom(buf);
- }
-
- @Nullable @Override public GridTcpMessageFactory messageFactory() {
- return null;
- }
- };
-
- GridNioFilter codecFilter = new GridNioCodecFilter(new NioParser(msgReader), gridLog, true);
+ GridNioFilter codecFilter = new GridNioCodecFilter(new GridTcpRestParser(routerClient), gridLog, false);
if (sslCtx != null) {
GridNioSslFilter sslFilter = new GridNioSslFilter(sslCtx, gridLog);
- sslFilter.directMode(true);
+ sslFilter.directMode(false);
sslFilter.clientMode(true);
filters = new GridNioFilter[]{codecFilter, sslFilter};
@@ -219,12 +166,11 @@ protected GridClientConnectionManagerAdapter(UUID clientId,
.byteOrder(ByteOrder.nativeOrder())
.tcpNoDelay(cfg.isTcpNoDelay())
.directBuffer(true)
- .directMode(true)
+ .directMode(false)
.socketReceiveBufferSize(0)
.socketSendBufferSize(0)
.idleTimeout(Long.MAX_VALUE)
- .gridName("gridClient")
- .messageWriter(msgWriter)
+ .gridName(routerClient ? "routerClient" : "gridClient")
.daemon(cfg.isDaemon())
.build();
@@ -648,21 +594,15 @@ private NioListener(Logger log) {
assert conn != null;
- if (msg instanceof GridClientMessageWrapper) {
- GridClientMessageWrapper req = (GridClientMessageWrapper)msg;
-
- if (req.messageSize() != 0) {
- assert req.message() != null;
-
- conn.handleResponse(req);
- }
- else
- conn.handlePingResponse();
- }
- else {
- assert msg instanceof GridClientPingPacket : msg;
-
+ if (msg instanceof GridClientPingPacket)
conn.handlePingResponse();
+ else {
+ try {
+ conn.handleResponse((GridClientMessage)msg);
+ }
+ catch (IOException e) {
+ log.log(Level.SEVERE, "Failed to parse response.", e);
+ }
}
}
}
@@ -701,63 +641,4 @@ private void handleHandshakeResponse(GridClientFutureAdapter handshakeF
ses.close();
}
}
-
- /**
- *
- */
- private static class NioParser implements GridNioParser {
- /** Message metadata key. */
- private static final int MSG_META_KEY = GridNioSessionMetaKey.nextUniqueKey();
-
- /** Message reader. */
- private final GridNioMessageReader msgReader;
-
- /**
- * @param msgReader Message reader.
- */
- NioParser(GridNioMessageReader msgReader) {
- this.msgReader = msgReader;
- }
-
- /** {@inheritDoc} */
- @Nullable @Override public Object decode(GridNioSession ses, ByteBuffer buf) throws IOException, IgniteCheckedException {
- GridClientFutureAdapter> handshakeFut = ses.meta(GridClientNioTcpConnection.SES_META_HANDSHAKE);
-
- if (handshakeFut != null) {
- byte code = buf.get();
-
- return new GridClientHandshakeResponse(code);
- }
-
- GridTcpCommunicationMessageAdapter msg = ses.removeMeta(MSG_META_KEY);
-
- if (msg == null && buf.hasRemaining()) {
- byte type = buf.get();
-
- if (type == GridClientMessageWrapper.REQ_HEADER)
- msg = new GridClientMessageWrapper();
- else
- throw new IOException("Invalid message type: " + type);
- }
-
- boolean finished = false;
-
- if (buf.hasRemaining())
- finished = msgReader.read(null, msg, buf);
-
- if (finished)
- return msg;
- else {
- ses.addMeta(MSG_META_KEY, msg);
-
- return null;
- }
- }
-
- /** {@inheritDoc} */
- @Override public ByteBuffer encode(GridNioSession ses, Object msg) throws IOException, IgniteCheckedException {
- // No encoding needed for direct messages.
- throw new UnsupportedEncodingException();
- }
- }
}
diff --git a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerOsImpl.java b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerOsImpl.java
index f2d4506321585..a9bd80e5c61a2 100644
--- a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerOsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerOsImpl.java
@@ -36,8 +36,9 @@ public class GridClientConnectionManagerOsImpl extends GridClientConnectionManag
* @throws GridClientException In case of error.
*/
public GridClientConnectionManagerOsImpl(UUID clientId, SSLContext sslCtx, GridClientConfiguration cfg,
- Collection routers, GridClientTopology top, Byte marshId) throws GridClientException {
- super(clientId, sslCtx, cfg, routers, top, marshId);
+ Collection routers, GridClientTopology top, Byte marshId, boolean routerClient)
+ throws GridClientException {
+ super(clientId, sslCtx, cfg, routers, top, marshId, routerClient);
}
/** {@inheritDoc} */
diff --git a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java
index 51da3d7571015..03fa95d8ba76e 100644
--- a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java
+++ b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientNioTcpConnection.java
@@ -33,7 +33,6 @@
import javax.net.ssl.*;
import java.io.*;
import java.net.*;
-import java.nio.*;
import java.nio.channels.*;
import java.util.*;
import java.util.concurrent.*;
@@ -43,6 +42,7 @@
import static org.apache.ignite.client.GridClientCacheFlag.*;
import static org.apache.ignite.client.impl.connection.GridClientConnectionCloseReason.*;
import static org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.*;
+import static org.apache.ignite.internal.util.nio.GridNioSessionMetaKey.*;
/**
* This class performs request to grid over tcp protocol. Serialization is performed with marshaller
@@ -194,9 +194,9 @@ else if (marsh instanceof GridClientOptimizedMarshaller)
else if (marsh instanceof GridClientJdkMarshaller)
req.marshallerId(GridClientJdkMarshaller.ID);
- GridClientHandshakeRequestWrapper wrapper = new GridClientHandshakeRequestWrapper(req);
+ ses.addMeta(MARSHALLER.ordinal(), marsh);
- ses.send(wrapper);
+ ses.send(req);
handshakeFut.get();
@@ -392,7 +392,7 @@ private GridClientFutureAdapter makeRequest(GridClientMessage msg, final
else if (now - lastPingSndTime > pingInterval && lastPingRcvTime != Long.MAX_VALUE) {
lastPingRcvTime = Long.MAX_VALUE;
- ses.send(new GridClientPingPacketWrapper());
+ ses.send(GridClientPingPacket.PING_MESSAGE);
lastPingSndTime = now;
}
@@ -415,22 +415,7 @@ else if (now - lastPingSndTime > pingInterval && lastPingRcvTime != Long.MAX_VAL
assert old == null;
- GridClientMessageWrapper wrapper;
-
- try {
- wrapper = messageWrapper(msg);
- }
- catch (IOException e) {
- log.log(Level.SEVERE, "Failed to marshal message: " + msg, e);
-
- removePending(reqId);
-
- fut.onDone(e);
-
- return fut;
- }
-
- GridNioFuture> sndFut = ses.send(wrapper);
+ GridNioFuture> sndFut = ses.send(msg);
lastMsgSndTime = U.currentTimeMillis();
@@ -473,59 +458,41 @@ void handlePingResponse() {
* Handles incoming response message. If this connection is closed this method would signal empty event
* if there is no more pending requests.
*
- * @param req Incoming response data.
+ * @param res Incoming response data.
*/
@SuppressWarnings({"unchecked", "TooBroadScope"})
- void handleResponse(GridClientMessageWrapper req) {
+ void handleResponse(GridClientMessage res) throws IOException {
lastMsgRcvTime = U.currentTimeMillis();
- TcpClientFuture fut = pendingReqs.get(req.requestId());
+ TcpClientFuture fut = pendingReqs.get(res.requestId());
if (fut == null) {
log.warning("Response for an unknown request is received, ignoring. " +
- "[req=" + req + ", ses=" + ses + ']');
+ "[res=" + res + ", ses=" + ses + ']');
return;
}
if (fut.forward()) {
- GridRouterResponse msg = new GridRouterResponse(
- req.messageArray(),
- req.requestId(),
- clientId,
- req.destinationId());
-
- removePending(msg.requestId());
+ removePending(res.requestId());
- fut.onDone(msg);
+ fut.onDone(res);
}
else {
- GridClientMessage msg;
+ GridClientMessage res0 = res;
- if (keepPortablesMode != null)
- keepPortablesMode.set(fut.keepPortables());
+ if (res instanceof GridRouterResponse) {
+ res0 = marsh.unmarshal(((GridRouterResponse)res).body());
- try {
- msg = marsh.unmarshal(req.messageArray());
+ res0.requestId(res.requestId());
+ res0.clientId(res.clientId());
+ res0.destinationId(res.destinationId());
}
- catch (IOException e) {
- fut.onDone(new GridClientException("Failed to unmarshal message.", e));
- return;
- }
-
- finally {
- if (keepPortablesMode != null)
- keepPortablesMode.set(true);
- }
- msg.requestId(req.requestId());
- msg.clientId(req.clientId());
- msg.destinationId(req.destinationId());
-
- if (msg instanceof GridClientResponse)
- handleClientResponse(fut, (GridClientResponse)msg);
+ if (res0 instanceof GridClientResponse)
+ handleClientResponse(fut, (GridClientResponse)res0);
else
- log.warning("Unsupported response type received: " + msg);
+ log.warning("Unsupported response type received: " + res0);
}
}
@@ -559,22 +526,7 @@ private void handleClientResponse(TcpClientFuture fut, GridClientResponse resp)
req.requestId(resp.requestId());
- GridClientMessageWrapper wrapper;
-
- try {
- wrapper = messageWrapper(req);
- }
- catch (IOException e) {
- log.log(Level.SEVERE, "Failed to marshal message: " + req, e);
-
- removePending(resp.requestId());
-
- fut.onDone(e);
-
- return;
- }
-
- ses.send(wrapper);
+ ses.send(req);
return;
}
@@ -588,22 +540,7 @@ private void handleClientResponse(TcpClientFuture fut, GridClientResponse resp)
src.sessionToken(sesTok);
- GridClientMessageWrapper wrapper;
-
- try {
- wrapper = messageWrapper(src);
- }
- catch (IOException e) {
- log.log(Level.SEVERE, "Failed to marshal message: " + src, e);
-
- removePending(resp.requestId());
-
- fut.onDone(e);
-
- return;
- }
-
- ses.send(wrapper);
+ ses.send(src);
return;
}
@@ -623,27 +560,6 @@ else if (resp.errorMessage() != null)
fut.onDone(resp.result());
}
- /**
- * @param msg Client message.
- * @return Message wrapper for direct marshalling.
- * @throws IOException If failed to marshal message.
- */
- private GridClientMessageWrapper messageWrapper(GridClientMessage msg) throws IOException {
- GridClientMessageWrapper wrapper = new GridClientMessageWrapper();
-
- wrapper.requestId(msg.requestId());
- wrapper.clientId(clientId);
- wrapper.destinationId(msg.destinationId());
-
- ByteBuffer data = (msg instanceof GridRouterRequest) ? ByteBuffer.wrap(((GridRouterRequest)msg).body()) :
- marsh.marshal(msg, 0);
-
- wrapper.message(data);
- wrapper.messageSize(data.remaining() + 40);
-
- return wrapper;
- }
-
/**
* Removes pending request and signals to {@link #closedLatch} if necessary.
*
diff --git a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridRouterClientImpl.java b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridRouterClientImpl.java
index 0d7f74d751f7f..1b3434612e79c 100644
--- a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridRouterClientImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridRouterClientImpl.java
@@ -60,7 +60,7 @@ class GridRouterClientImpl implements GridClient {
this.cliCfg = cliCfg;
- clientImpl = new GridClientImpl(id, cliCfg);
+ clientImpl = new GridClientImpl(id, cliCfg, true);
if (cliCfg.getProtocol() != GridClientProtocol.TCP)
throw new AssertionError("Unknown protocol: " + cliCfg.getProtocol());
@@ -136,7 +136,7 @@ private GridClientConnectionManager connectionManager(byte marshId) throws GridC
if (mgr == null) {
GridClientConnectionManager old = connMgrMap.putIfAbsent(marshId, mgr =
- clientImpl.newConnectionManager(marshId));
+ clientImpl.newConnectionManager(marshId, true));
if (old != null)
mgr = old;
diff --git a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java
index 231b0f52f48d0..129406dc332be 100644
--- a/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java
+++ b/modules/core/src/main/java/org/apache/ignite/client/router/impl/GridTcpRouterNioParser.java
@@ -39,6 +39,12 @@ class GridTcpRouterNioParser extends GridTcpRestParser {
/** Number of sent messages. */
private volatile long sndCnt;
+ /**
+ */
+ public GridTcpRouterNioParser() {
+ super(false);
+ }
+
/** {@inheritDoc} */
@Override protected GridClientMessage parseClientMessage(GridNioSession ses, ParserState state) {
rcvCnt++;
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 212782c51a446..599059e93f0c2 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
@@ -25,7 +25,6 @@
import org.apache.ignite.cache.query.*;
import org.apache.ignite.cache.store.*;
import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.portables.*;
import org.apache.ignite.spi.indexing.*;
import org.jetbrains.annotations.*;
@@ -312,12 +311,6 @@ public class CacheConfiguration extends MutableConfiguration {
/** */
private CacheInterceptor, ?> interceptor;
- /** */
- private boolean portableEnabled;
-
- /** */
- private boolean keepPortableInStore = true;
-
/** Query configuration. */
private CacheQueryConfiguration qryCfg;
@@ -379,7 +372,6 @@ public CacheConfiguration(CompleteConfiguration cfg) {
invalidate = cc.isInvalidate();
isReadThrough = cc.isReadThrough();
isWriteThrough = cc.isWriteThrough();
- keepPortableInStore = cc.isKeepPortableInStore();
listenerConfigurations = cc.listenerConfigurations;
loadPrevVal = cc.isLoadPreviousValue();
offHeapMaxMem = cc.getOffHeapMaxMemory();
@@ -389,7 +381,6 @@ public CacheConfiguration(CompleteConfiguration cfg) {
name = cc.getName();
nearStartSize = cc.getNearStartSize();
nearEvictPlc = cc.getNearEvictionPolicy();
- portableEnabled = cc.isPortableEnabled();
preloadMode = cc.getPreloadMode();
preloadBatchSize = cc.getPreloadBatchSize();
preloadDelay = cc.getPreloadPartitionedDelay();
@@ -1603,61 +1594,6 @@ public void setInterceptor(CacheInterceptor interceptor) {
this.interceptor = interceptor;
}
- /**
- * Flag indicating whether Ignite should store portable keys and values
- * as instances of {@link PortableObject}.
- *
- * @return Portable enabled flag.
- */
- public boolean isPortableEnabled() {
- return portableEnabled;
- }
-
- /**
- * Gets portable enabled flag value.
- *
- * @param portableEnabled Portable enabled flag value.
- */
- public void setPortableEnabled(boolean portableEnabled) {
- this.portableEnabled = portableEnabled;
- }
-
- /**
- * Flag indicating that {@link CacheStore} implementation
- * is working with portable objects instead of Java objects
- * if portable mode for this cache is enabled ({@link #isPortableEnabled()}
- * flag is {@code true}). Default value of this flag is {@code true},
- * because this is recommended behavior from performance standpoint.
- *
- * If set to {@code false}, Ignite will deserialize keys and
- * values stored in portable format before they are passed
- * to cache store.
- *
- * Note that setting this flag to {@code false} can simplify
- * 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
- * store is called.
- *
- * This flag is ignored if portable mode is disabled for this
- * cache ({@link #isPortableEnabled()} flag is {@code false}).
- *
- * @return Keep portables in store flag.
- */
- public boolean isKeepPortableInStore() {
- return keepPortableInStore;
- }
-
- /**
- * Sets keep portables in store flag.
- *
- * @param keepPortableInStore Keep portables in store flag.
- */
- public void setKeepPortableInStore(boolean keepPortableInStore) {
- this.keepPortableInStore = keepPortableInStore;
- }
-
/**
* Gets collection of type metadata objects.
*
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 2c3b8c07d8aa4..954ff86a3d6c4 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
@@ -29,7 +29,6 @@
import org.apache.ignite.services.*;
import org.apache.ignite.marshaller.*;
import org.apache.ignite.plugin.*;
-import org.apache.ignite.portables.*;
import org.apache.ignite.spi.authentication.*;
import org.apache.ignite.spi.indexing.*;
import org.apache.ignite.streamer.*;
@@ -482,9 +481,6 @@ public class IgniteConfiguration {
/** Client access configuration. */
private ClientConnectionConfiguration clientCfg;
- /** Portable configuration. */
- private PortableConfiguration portableCfg;
-
/** Warmup closure. Will be invoked before actual grid start. */
private IgniteInClosure warmupClos;
@@ -572,7 +568,6 @@ public IgniteConfiguration(IgniteConfiguration cfg) {
p2pMissedCacheSize = cfg.getPeerClassLoadingMissedResourcesCacheSize();
p2pPoolSize = cfg.getPeerClassLoadingThreadPoolSize();
pluginCfgs = cfg.getPluginConfigurations();
- portableCfg = cfg.getPortableConfiguration();
qryCfg = cfg.getQueryConfiguration();
restAccessibleFolders = cfg.getRestAccessibleFolders();
restIdleTimeout = cfg.getRestIdleTimeout();
@@ -2775,20 +2770,6 @@ public void setClientConnectionConfiguration(ClientConnectionConfiguration clien
this.clientCfg = clientCfg;
}
- /**
- * @return Portable configuration.
- */
- public PortableConfiguration getPortableConfiguration() {
- return portableCfg;
- }
-
- /**
- * @param portableCfg Portable configuration.
- */
- public void setPortableConfiguration(PortableConfiguration portableCfg) {
- this.portableCfg = portableCfg;
- }
-
/**
* Gets configurations for services to be deployed on the grid.
*
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java
index d966434f35669..eb747125da775 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupAdapter.java
@@ -555,6 +555,12 @@ private ClusterGroup forOthers(Collection excludeIds) {
return forPredicate(new StreamersFilter(streamerName, streamerNames));
}
+ /** {@inheritDoc} */
+ @Override public ClusterGroup forCacheNodes(@Nullable String cacheName,
+ Set distributionModes) {
+ return forPredicate(new CachesFilter(cacheName, distributionModes));
+ }
+
/** {@inheritDoc} */
@Override public final ClusterGroup forHost(ClusterNode node) {
A.notNull(node, "node");
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java
index ac1fffabfb869..faaab85523f36 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/ClusterGroupEx.java
@@ -17,7 +17,9 @@
package org.apache.ignite.internal;
+import org.apache.ignite.cache.*;
import org.apache.ignite.cluster.*;
+import org.jetbrains.annotations.*;
import java.util.*;
@@ -32,4 +34,11 @@ public interface ClusterGroupEx extends ClusterGroup {
* @return Internal projection.
*/
public ClusterGroupEx forSubjectId(UUID subjId);
+
+ /**
+ * @param cacheName Cache name.
+ * @param distributionModes Cache distribution modes.
+ * @return Cluster group.
+ */
+ public ClusterGroup forCacheNodes(@Nullable String cacheName, Set distributionModes);
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridDirectVersion.java b/modules/core/src/main/java/org/apache/ignite/internal/GridDirectVersion.java
deleted file mode 100644
index b9566c54d8c0d..0000000000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridDirectVersion.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;
-
-import java.lang.annotation.*;
-
-/**
- * Assigns version to a field.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface GridDirectVersion {
- /**
- * @return Version index (must be above zero).
- */
- int value();
-}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridJobCancelRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/GridJobCancelRequest.java
index 74019c19220aa..5cb6a27b1f77d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridJobCancelRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridJobCancelRequest.java
@@ -17,9 +17,9 @@
package org.apache.ignite.internal;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import org.jetbrains.annotations.*;
import java.io.*;
@@ -28,7 +28,7 @@
/**
* Job cancellation request.
*/
-public class GridJobCancelRequest extends GridTcpCommunicationMessageAdapter {
+public class GridJobCancelRequest extends MessageAdapter {
/** */
private static final long serialVersionUID = 0L;
@@ -111,7 +111,7 @@ public boolean system() {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridJobCancelRequest _clone = new GridJobCancelRequest();
clone0(_clone);
@@ -120,7 +120,7 @@ public boolean system() {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridJobCancelRequest _clone = (GridJobCancelRequest)_msg;
_clone.sesId = sesId;
@@ -131,33 +131,33 @@ public boolean system() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putGridUuid(jobId))
+ if (!writer.writeIgniteUuid("jobId", jobId))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putGridUuid(sesId))
+ if (!writer.writeIgniteUuid("sesId", sesId))
return false;
- commState.idx++;
+ state++;
case 2:
- if (!commState.putBoolean(sys))
+ if (!writer.writeBoolean("sys", sys))
return false;
- commState.idx++;
+ state++;
}
@@ -167,36 +167,32 @@ public boolean system() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- IgniteUuid jobId0 = commState.getGridUuid();
+ jobId = reader.readIgniteUuid("jobId");
- if (jobId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- jobId = jobId0;
-
- commState.idx++;
+ state++;
case 1:
- IgniteUuid sesId0 = commState.getGridUuid();
+ sesId = reader.readIgniteUuid("sesId");
- if (sesId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- sesId = sesId0;
-
- commState.idx++;
+ state++;
case 2:
- if (buf.remaining() < 1)
- return false;
+ sys = reader.readBoolean("sys");
- sys = commState.getBoolean();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteRequest.java
index 4bf76a164b702..004b9955f00b5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteRequest.java
@@ -19,10 +19,10 @@
import org.apache.ignite.compute.*;
import org.apache.ignite.configuration.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import org.jetbrains.annotations.*;
import java.io.*;
@@ -32,7 +32,7 @@
/**
* Job execution request.
*/
-public class GridJobExecuteRequest extends GridTcpCommunicationMessageAdapter implements GridTaskMessage {
+public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMessage {
/** */
private static final long serialVersionUID = 0L;
@@ -413,7 +413,7 @@ public UUID getSubjectId() {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridJobExecuteRequest _clone = new GridJobExecuteRequest();
clone0(_clone);
@@ -422,7 +422,7 @@ public UUID getSubjectId() {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridJobExecuteRequest _clone = (GridJobExecuteRequest)_msg;
_clone.subjId = subjId;
@@ -456,194 +456,141 @@ public UUID getSubjectId() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putGridUuid(clsLdrId))
+ if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putString(cpSpi))
+ if (!writer.writeString("cpSpi", cpSpi))
return false;
- commState.idx++;
+ state++;
case 2:
- if (!commState.putEnum(depMode))
+ if (!writer.writeEnum("depMode", depMode))
return false;
- commState.idx++;
+ state++;
case 3:
- if (!commState.putBoolean(dynamicSiblings))
+ if (!writer.writeBoolean("dynamicSiblings", dynamicSiblings))
return false;
- commState.idx++;
+ state++;
case 4:
- if (!commState.putBoolean(forceLocDep))
+ if (!writer.writeBoolean("forceLocDep", forceLocDep))
return false;
- commState.idx++;
+ state++;
case 5:
- if (!commState.putBoolean(internal))
+ if (!writer.writeBoolean("internal", internal))
return false;
- commState.idx++;
+ state++;
case 6:
- if (!commState.putByteArray(jobAttrsBytes))
+ if (!writer.writeByteArray("jobAttrsBytes", jobAttrsBytes))
return false;
- commState.idx++;
+ state++;
case 7:
- if (!commState.putByteArray(jobBytes))
+ if (!writer.writeByteArray("jobBytes", jobBytes))
return false;
- commState.idx++;
+ state++;
case 8:
- if (!commState.putGridUuid(jobId))
+ if (!writer.writeIgniteUuid("jobId", jobId))
return false;
- commState.idx++;
+ state++;
case 9:
- if (ldrParticipants != null) {
- if (commState.it == null) {
- if (!commState.putInt(ldrParticipants.size()))
- return false;
-
- commState.it = ldrParticipants.entrySet().iterator();
- }
-
- while (commState.it.hasNext() || commState.cur != NULL) {
- if (commState.cur == NULL)
- commState.cur = commState.it.next();
-
- Map.Entry e = (Map.Entry)commState.cur;
-
- if (!commState.keyDone) {
- if (!commState.putUuid(e.getKey()))
- return false;
-
- commState.keyDone = true;
- }
-
- if (!commState.putGridUuid(e.getValue()))
- return false;
-
- commState.keyDone = false;
-
- commState.cur = NULL;
- }
-
- commState.it = null;
- } else {
- if (!commState.putInt(-1))
- return false;
- }
+ if (!writer.writeMap("ldrParticipants", ldrParticipants, UUID.class, IgniteUuid.class))
+ return false;
- commState.idx++;
+ state++;
case 10:
- if (!commState.putByteArray(sesAttrsBytes))
+ if (!writer.writeByteArray("sesAttrsBytes", sesAttrsBytes))
return false;
- commState.idx++;
+ state++;
case 11:
- if (!commState.putBoolean(sesFullSup))
+ if (!writer.writeBoolean("sesFullSup", sesFullSup))
return false;
- commState.idx++;
+ state++;
case 12:
- if (!commState.putGridUuid(sesId))
+ if (!writer.writeIgniteUuid("sesId", sesId))
return false;
- commState.idx++;
+ state++;
case 13:
- if (!commState.putByteArray(siblingsBytes))
+ if (!writer.writeByteArray("siblingsBytes", siblingsBytes))
return false;
- commState.idx++;
+ state++;
case 14:
- if (!commState.putLong(startTaskTime))
+ if (!writer.writeLong("startTaskTime", startTaskTime))
return false;
- commState.idx++;
+ state++;
case 15:
- if (!commState.putUuid(subjId))
+ if (!writer.writeUuid("subjId", subjId))
return false;
- commState.idx++;
+ state++;
case 16:
- if (!commState.putString(taskClsName))
+ if (!writer.writeString("taskClsName", taskClsName))
return false;
- commState.idx++;
+ state++;
case 17:
- if (!commState.putString(taskName))
+ if (!writer.writeString("taskName", taskName))
return false;
- commState.idx++;
+ state++;
case 18:
- if (!commState.putLong(timeout))
+ if (!writer.writeLong("timeout", timeout))
return false;
- commState.idx++;
+ state++;
case 19:
- if (top != null) {
- if (commState.it == null) {
- if (!commState.putInt(top.size()))
- return false;
-
- commState.it = top.iterator();
- }
-
- while (commState.it.hasNext() || commState.cur != NULL) {
- if (commState.cur == NULL)
- commState.cur = commState.it.next();
-
- if (!commState.putUuid((UUID)commState.cur))
- return false;
-
- commState.cur = NULL;
- }
-
- commState.it = null;
- } else {
- if (!commState.putInt(-1))
- return false;
- }
+ if (!writer.writeCollection("top", top, UUID.class))
+ return false;
- commState.idx++;
+ state++;
case 20:
- if (!commState.putString(userVer))
+ if (!writer.writeString("userVer", userVer))
return false;
- commState.idx++;
+ state++;
}
@@ -653,257 +600,176 @@ public UUID getSubjectId() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- IgniteUuid clsLdrId0 = commState.getGridUuid();
+ clsLdrId = reader.readIgniteUuid("clsLdrId");
- if (clsLdrId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- clsLdrId = clsLdrId0;
-
- commState.idx++;
+ state++;
case 1:
- String cpSpi0 = commState.getString();
+ cpSpi = reader.readString("cpSpi");
- if (cpSpi0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- cpSpi = cpSpi0;
-
- commState.idx++;
+ state++;
case 2:
- if (buf.remaining() < 1)
- return false;
-
- byte depMode0 = commState.getByte();
+ depMode = reader.readEnum("depMode", DeploymentMode.class);
- depMode = DeploymentMode.fromOrdinal(depMode0);
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 3:
- if (buf.remaining() < 1)
- return false;
+ dynamicSiblings = reader.readBoolean("dynamicSiblings");
- dynamicSiblings = commState.getBoolean();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 4:
- if (buf.remaining() < 1)
- return false;
+ forceLocDep = reader.readBoolean("forceLocDep");
- forceLocDep = commState.getBoolean();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 5:
- if (buf.remaining() < 1)
- return false;
+ internal = reader.readBoolean("internal");
- internal = commState.getBoolean();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 6:
- byte[] jobAttrsBytes0 = commState.getByteArray();
+ jobAttrsBytes = reader.readByteArray("jobAttrsBytes");
- if (jobAttrsBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- jobAttrsBytes = jobAttrsBytes0;
-
- commState.idx++;
+ state++;
case 7:
- byte[] jobBytes0 = commState.getByteArray();
+ jobBytes = reader.readByteArray("jobBytes");
- if (jobBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- jobBytes = jobBytes0;
-
- commState.idx++;
+ state++;
case 8:
- IgniteUuid jobId0 = commState.getGridUuid();
+ jobId = reader.readIgniteUuid("jobId");
- if (jobId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- jobId = jobId0;
-
- commState.idx++;
+ state++;
case 9:
- if (commState.readSize == -1) {
- if (buf.remaining() < 4)
- return false;
-
- commState.readSize = commState.getInt();
- }
+ ldrParticipants = reader.readMap("ldrParticipants", UUID.class, IgniteUuid.class, false);
- if (commState.readSize >= 0) {
- if (ldrParticipants == null)
- ldrParticipants = new HashMap<>(commState.readSize, 1.0f);
-
- for (int i = commState.readItems; i < commState.readSize; i++) {
- if (!commState.keyDone) {
- UUID _val = commState.getUuid();
-
- if (_val == UUID_NOT_READ)
- return false;
-
- commState.cur = _val;
- commState.keyDone = true;
- }
-
- IgniteUuid _val = commState.getGridUuid();
-
- if (_val == GRID_UUID_NOT_READ)
- return false;
-
- ldrParticipants.put((UUID)commState.cur, _val);
-
- commState.keyDone = false;
-
- commState.readItems++;
- }
- }
-
- commState.readSize = -1;
- commState.readItems = 0;
- commState.cur = null;
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 10:
- byte[] sesAttrsBytes0 = commState.getByteArray();
+ sesAttrsBytes = reader.readByteArray("sesAttrsBytes");
- if (sesAttrsBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- sesAttrsBytes = sesAttrsBytes0;
-
- commState.idx++;
+ state++;
case 11:
- if (buf.remaining() < 1)
- return false;
+ sesFullSup = reader.readBoolean("sesFullSup");
- sesFullSup = commState.getBoolean();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 12:
- IgniteUuid sesId0 = commState.getGridUuid();
+ sesId = reader.readIgniteUuid("sesId");
- if (sesId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- sesId = sesId0;
-
- commState.idx++;
+ state++;
case 13:
- byte[] siblingsBytes0 = commState.getByteArray();
+ siblingsBytes = reader.readByteArray("siblingsBytes");
- if (siblingsBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- siblingsBytes = siblingsBytes0;
-
- commState.idx++;
+ state++;
case 14:
- if (buf.remaining() < 8)
- return false;
+ startTaskTime = reader.readLong("startTaskTime");
- startTaskTime = commState.getLong();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 15:
- UUID subjId0 = commState.getUuid();
+ subjId = reader.readUuid("subjId");
- if (subjId0 == UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- subjId = subjId0;
-
- commState.idx++;
+ state++;
case 16:
- String taskClsName0 = commState.getString();
+ taskClsName = reader.readString("taskClsName");
- if (taskClsName0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- taskClsName = taskClsName0;
-
- commState.idx++;
+ state++;
case 17:
- String taskName0 = commState.getString();
+ taskName = reader.readString("taskName");
- if (taskName0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- taskName = taskName0;
-
- commState.idx++;
+ state++;
case 18:
- if (buf.remaining() < 8)
- return false;
+ timeout = reader.readLong("timeout");
- timeout = commState.getLong();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 19:
- if (commState.readSize == -1) {
- if (buf.remaining() < 4)
- return false;
-
- commState.readSize = commState.getInt();
- }
+ top = reader.readCollection("top", UUID.class);
- if (commState.readSize >= 0) {
- if (top == null)
- top = new ArrayList<>(commState.readSize);
-
- for (int i = commState.readItems; i < commState.readSize; i++) {
- UUID _val = commState.getUuid();
-
- if (_val == UUID_NOT_READ)
- return false;
-
- top.add((UUID)_val);
-
- commState.readItems++;
- }
- }
-
- commState.readSize = -1;
- commState.readItems = 0;
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 20:
- String userVer0 = commState.getString();
+ userVer = reader.readString("userVer");
- if (userVer0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- userVer = userVer0;
-
- commState.idx++;
+ state++;
}
@@ -912,7 +778,7 @@ public UUID getSubjectId() {
/** {@inheritDoc} */
@Override public byte directType() {
- return 81;
+ return 1;
}
/** {@inheritDoc} */
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteResponse.java
index dec23989b6afd..3c3352a72b469 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteResponse.java
@@ -18,10 +18,10 @@
package org.apache.ignite.internal;
import org.apache.ignite.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import org.jetbrains.annotations.*;
import java.io.*;
@@ -31,7 +31,7 @@
/**
* Job execution response.
*/
-public class GridJobExecuteResponse extends GridTcpCommunicationMessageAdapter implements GridTaskMessage {
+public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMessage {
/** */
private static final long serialVersionUID = 0L;
@@ -206,7 +206,7 @@ public void setFakeException(IgniteException fakeEx) {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridJobExecuteResponse _clone = new GridJobExecuteResponse();
clone0(_clone);
@@ -215,7 +215,7 @@ public void setFakeException(IgniteException fakeEx) {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridJobExecuteResponse _clone = (GridJobExecuteResponse)_msg;
_clone.nodeId = nodeId;
@@ -234,57 +234,57 @@ public void setFakeException(IgniteException fakeEx) {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putByteArray(gridExBytes))
+ if (!writer.writeByteArray("gridExBytes", gridExBytes))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putBoolean(isCancelled))
+ if (!writer.writeBoolean("isCancelled", isCancelled))
return false;
- commState.idx++;
+ state++;
case 2:
- if (!commState.putByteArray(jobAttrsBytes))
+ if (!writer.writeByteArray("jobAttrsBytes", jobAttrsBytes))
return false;
- commState.idx++;
+ state++;
case 3:
- if (!commState.putGridUuid(jobId))
+ if (!writer.writeIgniteUuid("jobId", jobId))
return false;
- commState.idx++;
+ state++;
case 4:
- if (!commState.putUuid(nodeId))
+ if (!writer.writeUuid("nodeId", nodeId))
return false;
- commState.idx++;
+ state++;
case 5:
- if (!commState.putByteArray(resBytes))
+ if (!writer.writeByteArray("resBytes", resBytes))
return false;
- commState.idx++;
+ state++;
case 6:
- if (!commState.putGridUuid(sesId))
+ if (!writer.writeIgniteUuid("sesId", sesId))
return false;
- commState.idx++;
+ state++;
}
@@ -294,76 +294,64 @@ public void setFakeException(IgniteException fakeEx) {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- byte[] gridExBytes0 = commState.getByteArray();
+ gridExBytes = reader.readByteArray("gridExBytes");
- if (gridExBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- gridExBytes = gridExBytes0;
-
- commState.idx++;
+ state++;
case 1:
- if (buf.remaining() < 1)
- return false;
+ isCancelled = reader.readBoolean("isCancelled");
- isCancelled = commState.getBoolean();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 2:
- byte[] jobAttrsBytes0 = commState.getByteArray();
+ jobAttrsBytes = reader.readByteArray("jobAttrsBytes");
- if (jobAttrsBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- jobAttrsBytes = jobAttrsBytes0;
-
- commState.idx++;
+ state++;
case 3:
- IgniteUuid jobId0 = commState.getGridUuid();
+ jobId = reader.readIgniteUuid("jobId");
- if (jobId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- jobId = jobId0;
-
- commState.idx++;
+ state++;
case 4:
- UUID nodeId0 = commState.getUuid();
+ nodeId = reader.readUuid("nodeId");
- if (nodeId0 == UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- nodeId = nodeId0;
-
- commState.idx++;
+ state++;
case 5:
- byte[] resBytes0 = commState.getByteArray();
+ resBytes = reader.readByteArray("resBytes");
- if (resBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- resBytes = resBytes0;
-
- commState.idx++;
+ state++;
case 6:
- IgniteUuid sesId0 = commState.getGridUuid();
+ sesId = reader.readIgniteUuid("sesId");
- if (sesId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- sesId = sesId0;
-
- commState.idx++;
+ state++;
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsRequest.java
index bced3666b39be..2fc71d9912c6c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsRequest.java
@@ -17,9 +17,9 @@
package org.apache.ignite.internal;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import java.io.*;
import java.nio.*;
@@ -27,7 +27,7 @@
/**
* Job siblings request.
*/
-public class GridJobSiblingsRequest extends GridTcpCommunicationMessageAdapter {
+public class GridJobSiblingsRequest extends MessageAdapter {
/** */
private static final long serialVersionUID = 0L;
@@ -85,7 +85,7 @@ public byte[] topicBytes() {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridJobSiblingsRequest _clone = new GridJobSiblingsRequest();
clone0(_clone);
@@ -94,7 +94,7 @@ public byte[] topicBytes() {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridJobSiblingsRequest _clone = (GridJobSiblingsRequest)_msg;
_clone.sesId = sesId;
@@ -105,27 +105,27 @@ public byte[] topicBytes() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putGridUuid(sesId))
+ if (!writer.writeIgniteUuid("sesId", sesId))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putByteArray(topicBytes))
+ if (!writer.writeByteArray("topicBytes", topicBytes))
return false;
- commState.idx++;
+ state++;
}
@@ -135,28 +135,24 @@ public byte[] topicBytes() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- IgniteUuid sesId0 = commState.getGridUuid();
+ sesId = reader.readIgniteUuid("sesId");
- if (sesId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- sesId = sesId0;
-
- commState.idx++;
+ state++;
case 1:
- byte[] topicBytes0 = commState.getByteArray();
+ topicBytes = reader.readByteArray("topicBytes");
- if (topicBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- topicBytes = topicBytes0;
-
- commState.idx++;
+ state++;
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsResponse.java
index 4d52bd5ee37fd..ffaaa1ef8cd10 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsResponse.java
@@ -19,9 +19,9 @@
import org.apache.ignite.*;
import org.apache.ignite.compute.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.marshaller.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import org.jetbrains.annotations.*;
import java.io.*;
@@ -31,7 +31,7 @@
/**
* Job siblings response.
*/
-public class GridJobSiblingsResponse extends GridTcpCommunicationMessageAdapter {
+public class GridJobSiblingsResponse extends MessageAdapter {
/** */
private static final long serialVersionUID = 0L;
@@ -78,7 +78,7 @@ public void unmarshalSiblings(Marshaller marsh) throws IgniteCheckedException {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridJobSiblingsResponse _clone = new GridJobSiblingsResponse();
clone0(_clone);
@@ -87,7 +87,7 @@ public void unmarshalSiblings(Marshaller marsh) throws IgniteCheckedException {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridJobSiblingsResponse _clone = (GridJobSiblingsResponse)_msg;
_clone.siblings = siblings;
@@ -97,21 +97,21 @@ public void unmarshalSiblings(Marshaller marsh) throws IgniteCheckedException {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putByteArray(siblingsBytes))
+ if (!writer.writeByteArray("siblingsBytes", siblingsBytes))
return false;
- commState.idx++;
+ state++;
}
@@ -121,18 +121,16 @@ public void unmarshalSiblings(Marshaller marsh) throws IgniteCheckedException {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- byte[] siblingsBytes0 = commState.getByteArray();
+ siblingsBytes = reader.readByteArray("siblingsBytes");
- if (siblingsBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- siblingsBytes = siblingsBytes0;
-
- commState.idx++;
+ state++;
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
index eea69ae2807d7..152cfa67003af 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
@@ -59,7 +59,6 @@
import org.apache.ignite.internal.processors.task.*;
import org.apache.ignite.internal.processors.timeout.*;
import org.apache.ignite.internal.product.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.plugin.*;
@@ -502,17 +501,6 @@ public interface GridKernalContext extends Iterable {
*/
public T createComponent(Class cls);
- /**
- * @return Message factory.
- */
- public GridTcpMessageFactory messageFactory();
-
- /**
- * @param producer Message producer.
- * @return Message type code.
- */
- public byte registerMessageProducer(GridTcpCommunicationMessageProducer producer);
-
/**
* @return Thread pool implementation to be used in grid to process job execution
* requests and user messages sent to the node.
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 c9604de056675..3bd3f7cd06978 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
@@ -35,6 +35,7 @@
import org.apache.ignite.internal.processors.cache.*;
import org.apache.ignite.internal.processors.cache.dr.*;
import org.apache.ignite.internal.processors.cache.dr.os.*;
+import org.apache.ignite.internal.processors.cache.serialization.*;
import org.apache.ignite.internal.processors.clock.*;
import org.apache.ignite.internal.processors.closure.*;
import org.apache.ignite.internal.processors.continuous.*;
@@ -50,6 +51,7 @@
import org.apache.ignite.internal.processors.plugin.*;
import org.apache.ignite.internal.processors.port.*;
import org.apache.ignite.internal.processors.portable.*;
+import org.apache.ignite.internal.processors.portable.os.*;
import org.apache.ignite.internal.processors.query.*;
import org.apache.ignite.internal.processors.resource.*;
import org.apache.ignite.internal.processors.rest.*;
@@ -62,7 +64,6 @@
import org.apache.ignite.internal.processors.task.*;
import org.apache.ignite.internal.processors.timeout.*;
import org.apache.ignite.internal.product.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.internal.util.typedef.internal.*;
@@ -317,15 +318,6 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
/** Enterprise release flag. */
private boolean ent;
- /** */
- private GridTcpMessageFactory msgFactory;
-
- /** */
- private int pluginMsg = GridTcpCommunicationMessageFactory.MAX_COMMON_TYPE;
-
- /** */
- private Map pluginMsgs;
-
/**
* No-arg constructor is required by externalization.
*/
@@ -844,69 +836,14 @@ public void timeSource(GridClockSource clockSrc) {
if (cls.equals(GridCacheDrManager.class))
return (T)new GridOsCacheDrManager();
+ else if (cls.equals(GridPortableProcessor.class))
+ return (T)new GridOsPortableProcessor(this);
+ else if (cls.equals(IgniteCacheSerializationManager.class))
+ return (T)new IgniteCacheOsSerializationManager();
throw new IgniteException("Unsupported component type: " + cls);
}
- /** {@inheritDoc} */
- @Override public GridTcpMessageFactory messageFactory() {
- assert msgFactory != null;
-
- return msgFactory;
- }
-
- /** {@inheritDoc} */
- @Override public byte registerMessageProducer(GridTcpCommunicationMessageProducer producer) {
- int nextMsg = ++pluginMsg;
-
- if (nextMsg > Byte.MAX_VALUE)
- throw new IgniteException();
-
- if (pluginMsgs == null)
- pluginMsgs = new HashMap<>();
-
- pluginMsgs.put((byte)nextMsg, producer);
-
- return (byte)nextMsg;
- }
-
- /**
- * Creates message factory.
- */
- void createMessageFactory() {
- final GridTcpCommunicationMessageProducer[] common = GridTcpCommunicationMessageFactory.commonProducers();
-
- final GridTcpCommunicationMessageProducer[] producers;
-
- if (pluginMsgs != null) {
- producers = Arrays.copyOf(common, pluginMsg + 1);
-
- for (Map.Entry e : pluginMsgs.entrySet()) {
- assert producers[e.getKey()] == null : e.getKey();
-
- producers[e.getKey()] = e.getValue();
- }
-
- pluginMsgs = null;
- }
- else
- producers = common;
-
- msgFactory = new GridTcpMessageFactory() {
- @Override public GridTcpCommunicationMessageAdapter create(byte type) {
- if (type < 0 || type >= producers.length)
- return GridTcpCommunicationMessageFactory.create(type);
-
- GridTcpCommunicationMessageProducer producer = producers[type];
-
- if (producer != null)
- return producer.create(type);
- else
- throw new IllegalStateException("Common message type producer is not registered: " + type);
- }
- };
- }
-
/**
* @return Plugin manager.
*/
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridPluginContext.java b/modules/core/src/main/java/org/apache/ignite/internal/GridPluginContext.java
index b9f7e2d573cf0..31a4246bf5ef7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridPluginContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridPluginContext.java
@@ -20,7 +20,6 @@
import org.apache.ignite.*;
import org.apache.ignite.cluster.*;
import org.apache.ignite.configuration.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.plugin.*;
import org.apache.ignite.spi.*;
@@ -93,9 +92,4 @@ public GridPluginContext(GridKernalContext ctx, PluginConfiguration cfg, IgniteC
@Override public void deregisterPorts(Class> cls) {
ctx.ports().deregisterPorts(cls);
}
-
- /** {@inheritDoc} */
- @Override public byte registerMessageProducer(GridTcpCommunicationMessageProducer producer) {
- return ctx.registerMessageProducer(producer);
- }
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridPortablesImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/GridPortablesImpl.java
deleted file mode 100644
index 8dedc4dadf1eb..0000000000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridPortablesImpl.java
+++ /dev/null
@@ -1,174 +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;
-
-import org.apache.ignite.*;
-import org.apache.ignite.internal.processors.portable.*;
-import org.apache.ignite.portables.*;
-import org.jetbrains.annotations.*;
-
-import java.util.*;
-
-/**
- * {@link org.apache.ignite.IgnitePortables} implementation.
- */
-public class GridPortablesImpl implements IgnitePortables {
- /** */
- private GridKernalContext ctx;
-
- /** */
- private GridPortableProcessor proc;
-
- /**
- * @param ctx Context.
- */
- public GridPortablesImpl(GridKernalContext ctx) {
- this.ctx = ctx;
-
- proc = ctx.portable();
- }
-
- /** {@inheritDoc} */
- @Override public int typeId(String typeName) {
- guard();
-
- try {
- return proc.typeId(typeName);
- }
- finally {
- unguard();
- }
- }
-
- /** {@inheritDoc} */
- @Override public 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 metadata() throws PortableException {
- guard();
-
- try {
- return proc.metadata();
- }
- finally {
- unguard();
- }
- }
-
- /**
- * @return Portable processor.
- */
- public GridPortableProcessor processor() {
- return proc;
- }
-
- /**
- * ctx.gateway().readLock()
- */
- private void guard() {
- ctx.gateway().readLock();
- }
-
- /**
- * ctx.gateway().readUnlock()
- */
- private void unguard() {
- ctx.gateway().readUnlock();
- }
-}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridTaskCancelRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/GridTaskCancelRequest.java
index 40ce0f623362e..75ff8eabec6a7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridTaskCancelRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridTaskCancelRequest.java
@@ -17,9 +17,9 @@
package org.apache.ignite.internal;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import java.io.*;
import java.nio.*;
@@ -27,7 +27,7 @@
/**
* Request for cancelling tasks.
*/
-public class GridTaskCancelRequest extends GridTcpCommunicationMessageAdapter {
+public class GridTaskCancelRequest extends MessageAdapter {
/** */
private static final long serialVersionUID = 0L;
@@ -62,7 +62,7 @@ public IgniteUuid sessionId() {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridTaskCancelRequest _clone = new GridTaskCancelRequest();
clone0(_clone);
@@ -71,7 +71,7 @@ public IgniteUuid sessionId() {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridTaskCancelRequest _clone = (GridTaskCancelRequest)_msg;
_clone.sesId = sesId;
@@ -80,21 +80,21 @@ public IgniteUuid sessionId() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putGridUuid(sesId))
+ if (!writer.writeIgniteUuid("sesId", sesId))
return false;
- commState.idx++;
+ state++;
}
@@ -104,18 +104,16 @@ public IgniteUuid sessionId() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- IgniteUuid sesId0 = commState.getGridUuid();
+ sesId = reader.readIgniteUuid("sesId");
- if (sesId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- sesId = sesId0;
-
- commState.idx++;
+ state++;
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionRequest.java
index c219679d81861..1f75ee2bfe3af 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionRequest.java
@@ -17,9 +17,9 @@
package org.apache.ignite.internal;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import java.io.*;
import java.nio.*;
@@ -28,7 +28,7 @@
/**
* Task session request.
*/
-public class GridTaskSessionRequest extends GridTcpCommunicationMessageAdapter implements GridTaskMessage {
+public class GridTaskSessionRequest extends MessageAdapter implements GridTaskMessage {
/** */
private static final long serialVersionUID = 0L;
@@ -99,7 +99,7 @@ public IgniteUuid getJobId() {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridTaskSessionRequest _clone = new GridTaskSessionRequest();
clone0(_clone);
@@ -108,7 +108,7 @@ public IgniteUuid getJobId() {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridTaskSessionRequest _clone = (GridTaskSessionRequest)_msg;
_clone.sesId = sesId;
@@ -120,33 +120,33 @@ public IgniteUuid getJobId() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putByteArray(attrsBytes))
+ if (!writer.writeByteArray("attrsBytes", attrsBytes))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putGridUuid(jobId))
+ if (!writer.writeIgniteUuid("jobId", jobId))
return false;
- commState.idx++;
+ state++;
case 2:
- if (!commState.putGridUuid(sesId))
+ if (!writer.writeIgniteUuid("sesId", sesId))
return false;
- commState.idx++;
+ state++;
}
@@ -156,38 +156,32 @@ public IgniteUuid getJobId() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- byte[] attrsBytes0 = commState.getByteArray();
+ attrsBytes = reader.readByteArray("attrsBytes");
- if (attrsBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- attrsBytes = attrsBytes0;
-
- commState.idx++;
+ state++;
case 1:
- IgniteUuid jobId0 = commState.getGridUuid();
+ jobId = reader.readIgniteUuid("jobId");
- if (jobId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- jobId = jobId0;
-
- commState.idx++;
+ state++;
case 2:
- IgniteUuid sesId0 = commState.getGridUuid();
+ sesId = reader.readIgniteUuid("sesId");
- if (sesId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- sesId = sesId0;
-
- commState.idx++;
+ state++;
}
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 917032f9ffe49..d2dced156afaf 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
@@ -212,10 +212,6 @@ public class IgniteKernal extends ClusterGroupAdapter implements IgniteEx, Ignit
@GridToStringExclude
private GridSecurity security;
- /** Portables instance. */
- @GridToStringExclude
- private IgnitePortables portables;
-
/** Kernal gateway. */
@GridToStringExclude
private final AtomicReference gw = new AtomicReference<>();
@@ -750,13 +746,13 @@ public void start(final IgniteConfiguration cfg, ExecutorService utilityCachePoo
startProcessor(ctx, createComponent(GridLicenseProcessor.class, ctx), attrs);
startProcessor(ctx, new GridAffinityProcessor(ctx), attrs);
startProcessor(ctx, createComponent(GridSegmentationProcessor.class, ctx), attrs);
+ startProcessor(ctx, createComponent(GridPortableProcessor.class, ctx), attrs);
startProcessor(ctx, new GridQueryProcessor(ctx), attrs);
startProcessor(ctx, new GridCacheProcessor(ctx), attrs);
startProcessor(ctx, new GridTaskSessionProcessor(ctx), attrs);
startProcessor(ctx, new GridJobProcessor(ctx), attrs);
startProcessor(ctx, new GridTaskProcessor(ctx), attrs);
startProcessor(ctx, (GridProcessor)SCHEDULE.createOptional(ctx), attrs);
- startProcessor(ctx, createComponent(GridPortableProcessor.class, ctx), attrs);
startProcessor(ctx, new GridRestProcessor(ctx), attrs);
startProcessor(ctx, new GridDataLoaderProcessor(ctx), attrs);
startProcessor(ctx, new GridStreamProcessor(ctx), attrs);
@@ -775,11 +771,8 @@ public void start(final IgniteConfiguration cfg, ExecutorService utilityCachePoo
provider.start(ctx.plugins().pluginContextForProvider(provider), attrs);
}
- ctx.createMessageFactory();
-
if (ctx.isEnterprise()) {
security = new GridSecurityImpl(ctx);
- portables = new GridPortablesImpl(ctx);
}
gw.writeLock();
@@ -3249,14 +3242,6 @@ private boolean runNextNodeCallable(final ConcurrentLinkedQueue compatibleVersions() {
return compatibleVers;
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index 7ef3c15a3f256..8040f2c4ea0a3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -1678,9 +1678,6 @@ else if (marsh instanceof OptimizedMarshaller && !U.isHotSpot()) {
// REST configuration.
myCfg.setClientConnectionConfiguration(clientCfg);
- // Portable configuration.
- myCfg.setPortableConfiguration(cfg.getPortableConfiguration());
-
// Hadoop configuration.
myCfg.setHadoopConfiguration(cfg.getHadoopConfiguration());
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
new file mode 100644
index 0000000000000..f74da650856d6
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
@@ -0,0 +1,1613 @@
+/*
+ * 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.direct;
+
+import org.apache.ignite.internal.util.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.jetbrains.annotations.*;
+import sun.misc.*;
+import sun.nio.ch.*;
+
+import java.lang.reflect.*;
+import java.nio.*;
+import java.util.*;
+
+/**
+ * Portable stream based on {@link ByteBuffer}.
+ */
+public class DirectByteBufferStream {
+ /** */
+ private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+ /** */
+ private static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+ /** */
+ private static final long SHORT_ARR_OFF = UNSAFE.arrayBaseOffset(short[].class);
+
+ /** */
+ private static final long INT_ARR_OFF = UNSAFE.arrayBaseOffset(int[].class);
+
+ /** */
+ private static final long LONG_ARR_OFF = UNSAFE.arrayBaseOffset(long[].class);
+
+ /** */
+ private static final long FLOAT_ARR_OFF = UNSAFE.arrayBaseOffset(float[].class);
+
+ /** */
+ private static final long DOUBLE_ARR_OFF = UNSAFE.arrayBaseOffset(double[].class);
+
+ /** */
+ private static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
+
+ /** */
+ private static final long BOOLEAN_ARR_OFF = UNSAFE.arrayBaseOffset(boolean[].class);
+
+ /** */
+ private static final byte[] BYTE_ARR_EMPTY = new byte[0];
+
+ /** */
+ private static final short[] SHORT_ARR_EMPTY = new short[0];
+
+ /** */
+ private static final int[] INT_ARR_EMPTY = new int[0];
+
+ /** */
+ private static final long[] LONG_ARR_EMPTY = new long[0];
+
+ /** */
+ private static final float[] FLOAT_ARR_EMPTY = new float[0];
+
+ /** */
+ private static final double[] DOUBLE_ARR_EMPTY = new double[0];
+
+ /** */
+ private static final char[] CHAR_ARR_EMPTY = new char[0];
+
+ /** */
+ private static final boolean[] BOOLEAN_ARR_EMPTY = new boolean[0];
+
+ /** */
+ private static final ArrayCreator BYTE_ARR_CREATOR = new ArrayCreator() {
+ @Override public byte[] create(int len) {
+ assert len >= 0;
+
+ switch (len) {
+ case 0:
+ return BYTE_ARR_EMPTY;
+
+ default:
+ return new byte[len];
+ }
+ }
+ };
+
+ /** */
+ private static final ArrayCreator SHORT_ARR_CREATOR = new ArrayCreator() {
+ @Override public short[] create(int len) {
+ assert len >= 0;
+
+ switch (len) {
+ case 0:
+ return SHORT_ARR_EMPTY;
+
+ default:
+ return new short[len];
+ }
+ }
+ };
+
+ /** */
+ private static final ArrayCreator INT_ARR_CREATOR = new ArrayCreator() {
+ @Override public int[] create(int len) {
+ assert len >= 0;
+
+ switch (len) {
+ case 0:
+ return INT_ARR_EMPTY;
+
+ default:
+ return new int[len];
+ }
+ }
+ };
+
+ /** */
+ private static final ArrayCreator LONG_ARR_CREATOR = new ArrayCreator() {
+ @Override public long[] create(int len) {
+ assert len >= 0;
+
+ switch (len) {
+ case 0:
+ return LONG_ARR_EMPTY;
+
+ default:
+ return new long[len];
+ }
+ }
+ };
+
+ /** */
+ private static final ArrayCreator FLOAT_ARR_CREATOR = new ArrayCreator() {
+ @Override public float[] create(int len) {
+ assert len >= 0;
+
+ switch (len) {
+ case 0:
+ return FLOAT_ARR_EMPTY;
+
+ default:
+ return new float[len];
+ }
+ }
+ };
+
+ /** */
+ private static final ArrayCreator DOUBLE_ARR_CREATOR = new ArrayCreator() {
+ @Override public double[] create(int len) {
+ assert len >= 0;
+
+ switch (len) {
+ case 0:
+ return DOUBLE_ARR_EMPTY;
+
+ default:
+ return new double[len];
+ }
+ }
+ };
+
+ /** */
+ private static final ArrayCreator CHAR_ARR_CREATOR = new ArrayCreator() {
+ @Override public char[] create(int len) {
+ assert len >= 0;
+
+ switch (len) {
+ case 0:
+ return CHAR_ARR_EMPTY;
+
+ default:
+ return new char[len];
+ }
+ }
+ };
+
+ /** */
+ private static final ArrayCreator BOOLEAN_ARR_CREATOR = new ArrayCreator() {
+ @Override public boolean[] create(int len) {
+ assert len >= 0;
+
+ switch (len) {
+ case 0:
+ return BOOLEAN_ARR_EMPTY;
+
+ default:
+ return new boolean[len];
+ }
+ }
+ };
+
+ /** */
+ private static final Object NULL = new Object();
+
+ /** */
+ private static final Map, Type> TYPES = U.newHashMap(30);
+
+ static {
+ TYPES.put(byte.class, Type.BYTE);
+ TYPES.put(Byte.class, Type.BYTE);
+ TYPES.put(short.class, Type.SHORT);
+ TYPES.put(Short.class, Type.SHORT);
+ TYPES.put(int.class, Type.INT);
+ TYPES.put(Integer.class, Type.INT);
+ TYPES.put(long.class, Type.LONG);
+ TYPES.put(Long.class, Type.LONG);
+ TYPES.put(float.class, Type.FLOAT);
+ TYPES.put(Float.class, Type.FLOAT);
+ TYPES.put(double.class, Type.DOUBLE);
+ TYPES.put(Double.class, Type.DOUBLE);
+ TYPES.put(char.class, Type.CHAR);
+ TYPES.put(Character.class, Type.CHAR);
+ TYPES.put(boolean.class, Type.BOOLEAN);
+ TYPES.put(Boolean.class, Type.BOOLEAN);
+ TYPES.put(byte[].class, Type.BYTE_ARR);
+ TYPES.put(short[].class, Type.SHORT_ARR);
+ TYPES.put(int[].class, Type.INT_ARR);
+ TYPES.put(long[].class, Type.LONG_ARR);
+ TYPES.put(float[].class, Type.FLOAT_ARR);
+ TYPES.put(double[].class, Type.DOUBLE_ARR);
+ TYPES.put(char[].class, Type.CHAR_ARR);
+ TYPES.put(boolean[].class, Type.BOOLEAN_ARR);
+ TYPES.put(String.class, Type.STRING);
+ TYPES.put(BitSet.class, Type.BIT_SET);
+ TYPES.put(UUID.class, Type.UUID);
+ TYPES.put(IgniteUuid.class, Type.IGNITE_UUID);
+ }
+
+ /**
+ * @param cls Class.
+ * @return Type enum value.
+ */
+ private static Type type(Class> cls) {
+ Type type = TYPES.get(cls);
+
+ if (type == null) {
+ assert MessageAdapter.class.isAssignableFrom(cls) : cls;
+
+ type = Type.MSG;
+ }
+
+ return type;
+ }
+
+ /** */
+ private final MessageFactory msgFactory;
+
+ /** */
+ private ByteBuffer buf;
+
+ /** */
+ private byte[] heapArr;
+
+ /** */
+ private long baseOff;
+
+ /** */
+ private int arrOff = -1;
+
+ /** */
+ private Object tmpArr;
+
+ /** */
+ private int tmpArrOff;
+
+ /** */
+ private int tmpArrBytes;
+
+ /** */
+ private boolean msgTypeDone;
+
+ /** */
+ private MessageAdapter msg;
+
+ /** */
+ private Iterator> it;
+
+ /** */
+ private Object cur = NULL;
+
+ /** */
+ private boolean keyDone;
+
+ /** */
+ private int readSize = -1;
+
+ /** */
+ private int readItems;
+
+ /** */
+ private Object[] objArr;
+
+ /** */
+ private Collection col;
+
+ /** */
+ private Map map;
+
+ /** */
+ private boolean lastFinished;
+
+ /**
+ * @param msgFactory Message factory.
+ */
+ public DirectByteBufferStream(@Nullable MessageFactory msgFactory) {
+ this.msgFactory = msgFactory;
+ }
+
+ /**
+ * @param buf Buffer.
+ */
+ public void setBuffer(ByteBuffer buf) {
+ assert buf != null;
+
+ if (this.buf != buf) {
+ this.buf = buf;
+
+ heapArr = buf.isDirect() ? null : buf.array();
+ baseOff = buf.isDirect() ? ((DirectBuffer)buf).address() : BYTE_ARR_OFF;
+ }
+ }
+
+ /**
+ * @return Number of remaining bytes.
+ */
+ public int remaining() {
+ return buf.remaining();
+ }
+
+ /**
+ * @return Whether last object was fully written or read.
+ */
+ public boolean lastFinished() {
+ return lastFinished;
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void writeByte(byte val) {
+ lastFinished = buf.remaining() >= 1;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ UNSAFE.putByte(heapArr, baseOff + pos, val);
+
+ buf.position(pos + 1);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void writeShort(short val) {
+ lastFinished = buf.remaining() >= 2;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ UNSAFE.putShort(heapArr, baseOff + pos, val);
+
+ buf.position(pos + 2);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void writeInt(int val) {
+ lastFinished = buf.remaining() >= 4;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ UNSAFE.putInt(heapArr, baseOff + pos, val);
+
+ buf.position(pos + 4);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void writeLong(long val) {
+ lastFinished = buf.remaining() >= 8;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ UNSAFE.putLong(heapArr, baseOff + pos, val);
+
+ buf.position(pos + 8);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void writeFloat(float val) {
+ lastFinished = buf.remaining() >= 4;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ UNSAFE.putFloat(heapArr, baseOff + pos, val);
+
+ buf.position(pos + 4);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void writeDouble(double val) {
+ lastFinished = buf.remaining() >= 8;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ UNSAFE.putDouble(heapArr, baseOff + pos, val);
+
+ buf.position(pos + 8);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void writeChar(char val) {
+ lastFinished = buf.remaining() >= 2;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ UNSAFE.putChar(heapArr, baseOff + pos, val);
+
+ buf.position(pos + 2);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void writeBoolean(boolean val) {
+ lastFinished = buf.remaining() >= 1;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ UNSAFE.putBoolean(heapArr, baseOff + pos, val);
+
+ buf.position(pos + 1);
+ }
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void writeByteArray(byte[] val) {
+ if (val != null)
+ lastFinished = writeArray(val, BYTE_ARR_OFF, val.length, val.length);
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @param val Value.
+ */
+ public void writeByteArray(byte[] val, int off, int len) {
+ if (val != null)
+ lastFinished = writeArray(val, BYTE_ARR_OFF + off, len, len, true);
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeShortArray(short[] val) {
+ if (val != null)
+ lastFinished = writeArray(val, SHORT_ARR_OFF, val.length, val.length << 1);
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeIntArray(int[] val) {
+ if (val != null)
+ lastFinished = writeArray(val, INT_ARR_OFF, val.length, val.length << 2);
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeLongArray(long[] val) {
+ if (val != null)
+ lastFinished = writeArray(val, LONG_ARR_OFF, val.length, val.length << 3);
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeFloatArray(float[] val) {
+ if (val != null)
+ lastFinished = writeArray(val, FLOAT_ARR_OFF, val.length, val.length << 2);
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeDoubleArray(double[] val) {
+ if (val != null)
+ lastFinished = writeArray(val, DOUBLE_ARR_OFF, val.length, val.length << 3);
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeCharArray(char[] val) {
+ if (val != null)
+ lastFinished = writeArray(val, CHAR_ARR_OFF, val.length, val.length << 1);
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeBooleanArray(boolean[] val) {
+ if (val != null)
+ lastFinished = writeArray(val, BOOLEAN_ARR_OFF, val.length, val.length);
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeString(String val) {
+ writeByteArray(val != null ? val.getBytes() : null);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeBitSet(BitSet val) {
+ writeLongArray(val != null ? val.toLongArray() : null);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeUuid(UUID val) {
+ writeByteArray(val != null ? U.uuidToBytes(val) : null);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeIgniteUuid(IgniteUuid val) {
+ writeByteArray(val != null ? U.igniteUuidToBytes(val) : null);
+ }
+
+ /**
+ * @param val Value
+ */
+ public void writeEnum(Enum> val) {
+ writeByte(val != null ? (byte)val.ordinal() : -1);
+ }
+
+ /**
+ * @param msg Message.
+ */
+ public void writeMessage(MessageAdapter msg) {
+ if (msg != null)
+ lastFinished = buf.hasRemaining() && msg.writeTo(buf);
+ else
+ writeByte(Byte.MIN_VALUE);
+ }
+
+ /**
+ * @param arr Array.
+ * @param itemCls Component type.
+ * @param writer Writer.
+ */
+ public void writeObjectArray(T[] arr, Class itemCls, MessageWriter writer) {
+ if (arr != null) {
+ if (it == null) {
+ writeInt(arr.length);
+
+ if (!lastFinished)
+ return;
+
+ it = arrayIterator(arr);
+ }
+
+ Type itemType = type(itemCls);
+
+ while (it.hasNext() || cur != NULL) {
+ if (cur == NULL) {
+ cur = it.next();
+
+ if (cur != null && itemType == Type.MSG) {
+ cur = ((MessageAdapter)cur).clone();
+
+ ((MessageAdapter)cur).setWriter(writer);
+ }
+ }
+
+ write(itemType, cur);
+
+ if (!lastFinished)
+ return;
+
+ cur = NULL;
+ }
+
+ it = null;
+ }
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @param col Collection.
+ * @param itemCls Item type.
+ * @param writer Writer.
+ */
+ public void writeCollection(Collection col, Class itemCls, MessageWriter writer) {
+ if (col != null) {
+ if (it == null) {
+ writeInt(col.size());
+
+ if (!lastFinished)
+ return;
+
+ it = col.iterator();
+ }
+
+ Type itemType = type(itemCls);
+
+ while (it.hasNext() || cur != NULL) {
+ if (cur == NULL) {
+ cur = it.next();
+
+ if (cur != null && itemType == Type.MSG) {
+ cur = ((MessageAdapter)cur).clone();
+
+ ((MessageAdapter)cur).setWriter(writer);
+ }
+ }
+
+ write(itemType, cur);
+
+ if (!lastFinished)
+ return;
+
+ cur = NULL;
+ }
+
+ it = null;
+ }
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @param map Map.
+ * @param keyCls Key type.
+ * @param valCls Value type.
+ * @param writer Writer.
+ */
+ @SuppressWarnings("unchecked")
+ public void writeMap(Map map, Class keyCls, Class valCls, MessageWriter writer) {
+ if (map != null) {
+ if (it == null) {
+ writeInt(map.size());
+
+ if (!lastFinished)
+ return;
+
+ it = map.entrySet().iterator();
+ }
+
+ Type keyType = type(keyCls);
+ Type valType = type(valCls);
+
+ while (it.hasNext() || cur != NULL) {
+ Map.Entry e;
+
+ if (cur == NULL) {
+ cur = it.next();
+
+ e = (Map.Entry)cur;
+
+ if (keyType == Type.MSG || valType == Type.MSG) {
+ K k = e.getKey();
+ V v = e.getValue();
+
+ if (k != null && keyType == Type.MSG) {
+ k = (K)((MessageAdapter)k).clone();
+
+ ((MessageAdapter)k).setWriter(writer);
+ }
+
+ if (v != null && valType == Type.MSG) {
+ v = (V)((MessageAdapter)v).clone();
+
+ ((MessageAdapter)v).setWriter(writer);
+ }
+
+ cur = e = F.t(k, v);
+ }
+ }
+ else
+ e = (Map.Entry)cur;
+
+ if (!keyDone) {
+ write(keyType, e.getKey());
+
+ if (!lastFinished)
+ return;
+
+ keyDone = true;
+ }
+
+ write(valType, e.getValue());
+
+ if (!lastFinished)
+ return;
+
+ cur = NULL;
+ keyDone = false;
+ }
+
+ it = null;
+ }
+ else
+ writeInt(-1);
+ }
+
+ /**
+ * @return Value.
+ */
+ public byte readByte() {
+ lastFinished = buf.remaining() >= 1;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ buf.position(pos + 1);
+
+ return UNSAFE.getByte(heapArr, baseOff + pos);
+ }
+ else
+ return 0;
+ }
+
+ /**
+ * @return Value.
+ */
+ public short readShort() {
+ lastFinished = buf.remaining() >= 2;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ buf.position(pos + 2);
+
+ return UNSAFE.getShort(heapArr, baseOff + pos);
+ }
+ else
+ return 0;
+ }
+
+ /**
+ * @return Value.
+ */
+ public int readInt() {
+ lastFinished = buf.remaining() >= 4;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ buf.position(pos + 4);
+
+ return UNSAFE.getInt(heapArr, baseOff + pos);
+ }
+ else
+ return 0;
+ }
+
+ /**
+ * @return Value.
+ */
+ public long readLong() {
+ lastFinished = buf.remaining() >= 8;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ buf.position(pos + 8);
+
+ return UNSAFE.getLong(heapArr, baseOff + pos);
+ }
+ else
+ return 0;
+ }
+
+ /**
+ * @return Value.
+ */
+ public float readFloat() {
+ lastFinished = buf.remaining() >= 4;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ buf.position(pos + 4);
+
+ return UNSAFE.getFloat(heapArr, baseOff + pos);
+ }
+ else
+ return 0;
+ }
+
+ /**
+ * @return Value.
+ */
+ public double readDouble() {
+ lastFinished = buf.remaining() >= 8;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ buf.position(pos + 8);
+
+ return UNSAFE.getDouble(heapArr, baseOff + pos);
+ }
+ else
+ return 0;
+ }
+
+ /**
+ * @return Value.
+ */
+ public char readChar() {
+ lastFinished = buf.remaining() >= 2;
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ buf.position(pos + 2);
+
+ return UNSAFE.getChar(heapArr, baseOff + pos);
+ }
+ else
+ return 0;
+ }
+
+ /**
+ * @return Value.
+ */
+ public boolean readBoolean() {
+ lastFinished = buf.hasRemaining();
+
+ if (lastFinished) {
+ int pos = buf.position();
+
+ buf.position(pos + 1);
+
+ return UNSAFE.getBoolean(heapArr, baseOff + pos);
+ }
+ else
+ return false;
+ }
+
+ /**
+ * @return Value.
+ */
+ public byte[] readByteArray() {
+ return readArray(BYTE_ARR_CREATOR, 0, BYTE_ARR_OFF);
+ }
+
+ /**
+ * @param len Length.
+ * @return Value.
+ */
+ public byte[] readByteArray(int len) {
+ return readArray(BYTE_ARR_CREATOR, 0, BYTE_ARR_OFF, len);
+ }
+
+ /**
+ /**
+ * @return Value.
+ */
+ public short[] readShortArray() {
+ return readArray(SHORT_ARR_CREATOR, 1, SHORT_ARR_OFF);
+ }
+
+ /**
+ * @return Value.
+ */
+ public int[] readIntArray() {
+ return readArray(INT_ARR_CREATOR, 2, INT_ARR_OFF);
+ }
+
+ /**
+ * @return Value.
+ */
+ public long[] readLongArray() {
+ return readArray(LONG_ARR_CREATOR, 3, LONG_ARR_OFF);
+ }
+
+ /**
+ * @return Value.
+ */
+ public float[] readFloatArray() {
+ return readArray(FLOAT_ARR_CREATOR, 2, FLOAT_ARR_OFF);
+ }
+
+ /**
+ * @return Value.
+ */
+ public double[] readDoubleArray() {
+ return readArray(DOUBLE_ARR_CREATOR, 3, DOUBLE_ARR_OFF);
+ }
+
+ /**
+ * @return Value.
+ */
+ public char[] readCharArray() {
+ return readArray(CHAR_ARR_CREATOR, 1, CHAR_ARR_OFF);
+ }
+
+ /**
+ * @return Value.
+ */
+ public boolean[] readBooleanArray() {
+ return readArray(BOOLEAN_ARR_CREATOR, 0, BOOLEAN_ARR_OFF);
+ }
+
+ /**
+ * @return Value.
+ */
+ public String readString() {
+ byte[] arr = readByteArray();
+
+ return arr != null ? new String(arr) : null;
+ }
+
+ /**
+ * @return Value.
+ */
+ public BitSet readBitSet() {
+ long[] arr = readLongArray();
+
+ return arr != null ? BitSet.valueOf(arr) : null;
+ }
+
+ /**
+ * @return Value.
+ */
+ public UUID readUuid() {
+ byte[] arr = readByteArray();
+
+ return arr != null ? U.bytesToUuid(arr, 0) : null;
+ }
+
+ /**
+ * @return Value.
+ */
+ public IgniteUuid readIgniteUuid() {
+ byte[] arr = readByteArray();
+
+ return arr != null ? U.bytesToIgniteUuid(arr, 0) : null;
+ }
+
+ /**
+ * @param enumCls Enum type.
+ * @return Value.
+ */
+ @SuppressWarnings("unchecked")
+ public > T readEnum(Class enumCls) {
+ byte ord = readByte();
+
+ return ord >= 0 ? (T)GridEnumCache.get(enumCls)[ord] : null;
+ }
+
+ /**
+ * @return Message.
+ */
+ @SuppressWarnings("unchecked")
+ public T readMessage() {
+ if (!msgTypeDone) {
+ if (!buf.hasRemaining()) {
+ lastFinished = false;
+
+ return null;
+ }
+
+ byte type = readByte();
+
+ msg = type == Byte.MIN_VALUE ? null : msgFactory.create(type);
+
+ msgTypeDone = true;
+ }
+
+ lastFinished = msg == null || msg.readFrom(buf);
+
+ if (lastFinished) {
+ MessageAdapter msg0 = msg;
+
+ msgTypeDone = false;
+ msg = null;
+
+ return (T)msg0;
+ }
+ else
+ return null;
+ }
+
+ /**
+ * @param itemCls Component type.
+ * @return Array.
+ */
+ @SuppressWarnings("unchecked")
+ public T[] readObjectArray(Class> itemCls) {
+ if (readSize == -1) {
+ int size = readInt();
+
+ if (!lastFinished)
+ return null;
+
+ readSize = size;
+ }
+
+ if (readSize >= 0) {
+ if (objArr == null)
+ objArr = (Object[])Array.newInstance(itemCls, readSize);
+
+ Type itemType = type(itemCls);
+
+ for (int i = readItems; i < readSize; i++) {
+ Object item = read(itemType);
+
+ if (!lastFinished)
+ return null;
+
+ objArr[i] = item;
+
+ readItems++;
+ }
+ }
+
+ readSize = -1;
+ readItems = 0;
+ cur = null;
+
+ T[] objArr0 = (T[])objArr;
+
+ objArr = null;
+
+ return objArr0;
+ }
+
+ /**
+ * @param itemCls Item type.
+ * @return Collection.
+ */
+ @SuppressWarnings("unchecked")
+ public , T> C readCollection(Class itemCls) {
+ if (readSize == -1) {
+ int size = readInt();
+
+ if (!lastFinished)
+ return null;
+
+ readSize = size;
+ }
+
+ if (readSize >= 0) {
+ if (col == null)
+ col = new ArrayList<>(readSize);
+
+ Type itemType = type(itemCls);
+
+ for (int i = readItems; i < readSize; i++) {
+ Object item = read(itemType);
+
+ if (!lastFinished)
+ return null;
+
+ col.add(item);
+
+ readItems++;
+ }
+ }
+
+ readSize = -1;
+ readItems = 0;
+ cur = null;
+
+ Collection col0 = (Collection)col;
+
+ col = null;
+
+ return (C)col0;
+ }
+
+ /**
+ * @param keyCls Key type.
+ * @param valCls Value type.
+ * @param linked Whether linked map should be created.
+ * @return Map.
+ */
+ @SuppressWarnings("unchecked")
+ public , K, V> M readMap(Class keyCls, Class valCls, boolean linked) {
+ if (readSize == -1) {
+ int size = readInt();
+
+ if (!lastFinished)
+ return null;
+
+ readSize = size;
+ }
+
+ if (readSize >= 0) {
+ if (map == null)
+ map = linked ? U.newLinkedHashMap(readSize) : U.newHashMap(readSize);
+
+ Type keyType = type(keyCls);
+ Type valType = type(valCls);
+
+ for (int i = readItems; i < readSize; i++) {
+ if (!keyDone) {
+ Object key = read(keyType);
+
+ if (!lastFinished)
+ return null;
+
+ cur = key;
+ keyDone = true;
+ }
+
+ Object val = read(valType);
+
+ if (!lastFinished)
+ return null;
+
+ map.put(cur, val);
+
+ keyDone = false;
+
+ readItems++;
+ }
+ }
+
+ readSize = -1;
+ readItems = 0;
+ cur = null;
+
+ Map map0 = (Map)map;
+
+ map = null;
+
+ return (M)map0;
+ }
+
+ /**
+ * @param arr Array.
+ * @param off Offset.
+ * @param len Length.
+ * @param bytes Length in bytes.
+ * @return Whether array was fully written
+ */
+ private boolean writeArray(Object arr, long off, int len, int bytes) {
+ return writeArray(arr, off, len, bytes, false);
+ }
+
+ /**
+ * @param arr Array.
+ * @param off Offset.
+ * @param len Length.
+ * @param bytes Length in bytes.
+ * @param skipLen {@code true} if length should not be written.
+ * @return Whether array was fully written
+ */
+ private boolean writeArray(Object arr, long off, int len, int bytes, boolean skipLen) {
+ assert arr != null;
+ assert arr.getClass().isArray() && arr.getClass().getComponentType().isPrimitive();
+ assert off > 0;
+ assert len >= 0;
+ assert bytes >= 0;
+ assert bytes >= arrOff;
+
+ if (arrOff == -1) {
+ if (!skipLen) {
+ if (buf.remaining() < 4)
+ return false;
+
+ writeInt(len);
+ }
+
+ arrOff = 0;
+ }
+
+ int toWrite = bytes - arrOff;
+ int pos = buf.position();
+ int remaining = buf.remaining();
+
+ if (toWrite <= remaining) {
+ UNSAFE.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, toWrite);
+
+ pos += toWrite;
+
+ buf.position(pos);
+
+ arrOff = -1;
+
+ return true;
+ }
+ else {
+ UNSAFE.copyMemory(arr, off + arrOff, heapArr, baseOff + pos, remaining);
+
+ pos += remaining;
+
+ buf.position(pos);
+
+ arrOff += remaining;
+
+ return false;
+ }
+ }
+
+ /**
+ * @param creator Array creator.
+ * @param lenShift Array length shift size.
+ * @param off Base offset.
+ * @return Array or special value if it was not fully read.
+ */
+ private T readArray(ArrayCreator creator, int lenShift, long off) {
+ return readArray(creator, lenShift, off, -1);
+ }
+
+ /**
+ * @param creator Array creator.
+ * @param lenShift Array length shift size.
+ * @param off Base offset.
+ * @param len Length.
+ * @return Array or special value if it was not fully read.
+ */
+ @SuppressWarnings("unchecked")
+ private T readArray(ArrayCreator creator, int lenShift, long off, int len) {
+ assert creator != null;
+
+ if (tmpArr == null) {
+ if (len == -1) {
+ if (buf.remaining() < 4) {
+ lastFinished = false;
+
+ return null;
+ }
+
+ len = readInt();
+ }
+
+ switch (len) {
+ case -1:
+ lastFinished = true;
+
+ return null;
+
+ case 0:
+ lastFinished = true;
+
+ return creator.create(0);
+
+ default:
+ tmpArr = creator.create(len);
+ tmpArrBytes = len << lenShift;
+ }
+ }
+
+ int toRead = tmpArrBytes - tmpArrOff;
+ int remaining = buf.remaining();
+ int pos = buf.position();
+
+ lastFinished = toRead <= remaining;
+
+ if (lastFinished) {
+ UNSAFE.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, toRead);
+
+ buf.position(pos + toRead);
+
+ T arr = (T)tmpArr;
+
+ tmpArr = null;
+ tmpArrBytes = 0;
+ tmpArrOff = 0;
+
+ return arr;
+ }
+ else {
+ UNSAFE.copyMemory(heapArr, baseOff + pos, tmpArr, off + tmpArrOff, remaining);
+
+ buf.position(pos + remaining);
+
+ tmpArrOff += remaining;
+
+ return null;
+ }
+ }
+
+ /**
+ * @param type Type.
+ * @param val Value.
+ */
+ private void write(Type type, Object val) {
+ switch (type) {
+ case BYTE:
+ writeByte((Byte)val);
+
+ break;
+
+ case SHORT:
+ writeShort((Short)val);
+
+ break;
+
+ case INT:
+ writeInt((Integer)val);
+
+ break;
+
+ case LONG:
+ writeLong((Long)val);
+
+ break;
+
+ case FLOAT:
+ writeFloat((Float)val);
+
+ break;
+
+ case DOUBLE:
+ writeDouble((Double)val);
+
+ break;
+
+ case CHAR:
+ writeChar((Character)val);
+
+ break;
+
+ case BOOLEAN:
+ writeBoolean((Boolean)val);
+
+ break;
+
+ case BYTE_ARR:
+ writeByteArray((byte[])val);
+
+ break;
+
+ case SHORT_ARR:
+ writeShortArray((short[])val);
+
+ break;
+
+ case INT_ARR:
+ writeIntArray((int[])val);
+
+ break;
+
+ case LONG_ARR:
+ writeLongArray((long[])val);
+
+ break;
+
+ case FLOAT_ARR:
+ writeFloatArray((float[])val);
+
+ break;
+
+ case DOUBLE_ARR:
+ writeDoubleArray((double[])val);
+
+ break;
+
+ case CHAR_ARR:
+ writeCharArray((char[])val);
+
+ break;
+
+ case BOOLEAN_ARR:
+ writeBooleanArray((boolean[])val);
+
+ break;
+
+ case STRING:
+ writeString((String)val);
+
+ break;
+
+ case BIT_SET:
+ writeBitSet((BitSet)val);
+
+ break;
+
+ case UUID:
+ writeUuid((UUID)val);
+
+ break;
+
+ case IGNITE_UUID:
+ writeIgniteUuid((IgniteUuid)val);
+
+ break;
+
+ case MSG:
+ writeMessage((MessageAdapter)val);
+
+ break;
+
+ default:
+ throw new IllegalArgumentException("Unknown type: " + type);
+ }
+ }
+
+ /**
+ * @param type Type.
+ * @return Value.
+ */
+ private Object read(Type type) {
+ switch (type) {
+ case BYTE:
+ return readByte();
+
+ case SHORT:
+ return readShort();
+
+ case INT:
+ return readInt();
+
+ case LONG:
+ return readLong();
+
+ case FLOAT:
+ return readFloat();
+
+ case DOUBLE:
+ return readDouble();
+
+ case CHAR:
+ return readChar();
+
+ case BOOLEAN:
+ return readBoolean();
+
+ case BYTE_ARR:
+ return readByteArray();
+
+ case SHORT_ARR:
+ return readShortArray();
+
+ case INT_ARR:
+ return readIntArray();
+
+ case LONG_ARR:
+ return readLongArray();
+
+ case FLOAT_ARR:
+ return readFloatArray();
+
+ case DOUBLE_ARR:
+ return readDoubleArray();
+
+ case CHAR_ARR:
+ return readCharArray();
+
+ case BOOLEAN_ARR:
+ return readBooleanArray();
+
+ case STRING:
+ return readString();
+
+ case BIT_SET:
+ return readBitSet();
+
+ case UUID:
+ return readUuid();
+
+ case IGNITE_UUID:
+ return readIgniteUuid();
+
+ case MSG:
+ return readMessage();
+
+ default:
+ throw new IllegalArgumentException("Unknown type: " + type);
+ }
+ }
+
+ /**
+ * @param arr Array.
+ * @return Array iterator.
+ */
+ private Iterator> arrayIterator(final Object[] arr) {
+ return new Iterator() {
+ private int idx;
+
+ @Override public boolean hasNext() {
+ return idx < arr.length;
+ }
+
+ @Override public Object next() {
+ if (!hasNext())
+ throw new NoSuchElementException();
+
+ return arr[idx++];
+ }
+
+ @Override public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ /**
+ * Array creator.
+ */
+ private static interface ArrayCreator {
+ /**
+ * @param len Array length or {@code -1} if array was not fully read.
+ * @return New array.
+ */
+ public T create(int len);
+ }
+
+ /**
+ */
+ private enum Type {
+ BYTE,
+
+ SHORT,
+
+ INT,
+
+ LONG,
+
+ FLOAT,
+
+ DOUBLE,
+
+ CHAR,
+
+ BOOLEAN,
+
+ BYTE_ARR,
+
+ SHORT_ARR,
+
+ INT_ARR,
+
+ LONG_ARR,
+
+ FLOAT_ARR,
+
+ DOUBLE_ARR,
+
+ CHAR_ARR,
+
+ BOOLEAN_ARR,
+
+ STRING,
+
+ BIT_SET,
+
+ UUID,
+
+ IGNITE_UUID,
+
+ MSG
+ }
+}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
new file mode 100644
index 0000000000000..48c79ce4f08bf
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
@@ -0,0 +1,279 @@
+/*
+ * 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.direct;
+
+import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.jetbrains.annotations.*;
+
+import java.nio.*;
+import java.util.*;
+
+/**
+ * Message reader implementation.
+ */
+public class DirectMessageReader implements MessageReader {
+ /** Stream. */
+ private final DirectByteBufferStream stream;
+
+ /** Whether last field was fully read. */
+ private boolean lastRead;
+
+ /**
+ * @param msgFactory Message factory.
+ */
+ public DirectMessageReader(MessageFactory msgFactory) {
+ this.stream = new DirectByteBufferStream(msgFactory);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void setBuffer(ByteBuffer buf) {
+ stream.setBuffer(buf);
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte readByte(String name) {
+ byte val = stream.readByte();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public short readShort(String name) {
+ short val = stream.readShort();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int readInt(String name) {
+ int val = stream.readInt();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long readLong(String name) {
+ long val = stream.readLong();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public float readFloat(String name) {
+ float val = stream.readFloat();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public double readDouble(String name) {
+ double val = stream.readDouble();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public char readChar(String name) {
+ char val = stream.readChar();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean readBoolean(String name) {
+ boolean val = stream.readBoolean();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public byte[] readByteArray(String name) {
+ byte[] arr = stream.readByteArray();
+
+ lastRead = stream.lastFinished();
+
+ return arr;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public short[] readShortArray(String name) {
+ short[] arr = stream.readShortArray();
+
+ lastRead = stream.lastFinished();
+
+ return arr;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public int[] readIntArray(String name) {
+ int[] arr = stream.readIntArray();
+
+ lastRead = stream.lastFinished();
+
+ return arr;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public long[] readLongArray(String name) {
+ long[] arr = stream.readLongArray();
+
+ lastRead = stream.lastFinished();
+
+ return arr;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public float[] readFloatArray(String name) {
+ float[] arr = stream.readFloatArray();
+
+ lastRead = stream.lastFinished();
+
+ return arr;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public double[] readDoubleArray(String name) {
+ double[] arr = stream.readDoubleArray();
+
+ lastRead = stream.lastFinished();
+
+ return arr;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public char[] readCharArray(String name) {
+ char[] arr = stream.readCharArray();
+
+ lastRead = stream.lastFinished();
+
+ return arr;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public boolean[] readBooleanArray(String name) {
+ boolean[] arr = stream.readBooleanArray();
+
+ lastRead = stream.lastFinished();
+
+ return arr;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String readString(String name) {
+ String val = stream.readString();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public BitSet readBitSet(String name) {
+ BitSet val = stream.readBitSet();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public UUID readUuid(String name) {
+ UUID val = stream.readUuid();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteUuid readIgniteUuid(String name) {
+ IgniteUuid val = stream.readIgniteUuid();
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public > T readEnum(String name, Class enumCls) {
+ T val = stream.readEnum(enumCls);
+
+ lastRead = stream.lastFinished();
+
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public T readMessage(String name) {
+ T msg = stream.readMessage();
+
+ lastRead = stream.lastFinished();
+
+ return msg;
+ }
+
+ /** {@inheritDoc} */
+ @Override public T[] readObjectArray(String name, Class itemCls) {
+ T[] msg = stream.readObjectArray(itemCls);
+
+ lastRead = stream.lastFinished();
+
+ return msg;
+ }
+
+ /** {@inheritDoc} */
+ @Override public , T> C readCollection(String name, Class itemCls) {
+ C col = stream.readCollection(itemCls);
+
+ lastRead = stream.lastFinished();
+
+ return col;
+ }
+
+ /** {@inheritDoc} */
+ @Override public , K, V> M readMap(String name, Class keyCls, Class valCls,
+ boolean linked) {
+ M map = stream.readMap(keyCls, valCls, linked);
+
+ lastRead = stream.lastFinished();
+
+ return map;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean isLastRead() {
+ return lastRead;
+ }
+}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
new file mode 100644
index 0000000000000..7526facf7e5a2
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
@@ -0,0 +1,216 @@
+/*
+ * 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.direct;
+
+import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.jetbrains.annotations.*;
+
+import java.nio.*;
+import java.util.*;
+
+/**
+ * Message writer implementation.
+ */
+public class DirectMessageWriter implements MessageWriter {
+ /** Stream. */
+ private final DirectByteBufferStream stream = new DirectByteBufferStream(null);
+
+ /** {@inheritDoc} */
+ @Override public void setBuffer(ByteBuffer buf) {
+ stream.setBuffer(buf);
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeByte(String name, byte val) {
+ stream.writeByte(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeShort(String name, short val) {
+ stream.writeShort(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeInt(String name, int val) {
+ stream.writeInt(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeLong(String name, long val) {
+ stream.writeLong(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeFloat(String name, float val) {
+ stream.writeFloat(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeDouble(String name, double val) {
+ stream.writeDouble(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeChar(String name, char val) {
+ stream.writeChar(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeBoolean(String name, boolean val) {
+ stream.writeBoolean(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeByteArray(String name, @Nullable byte[] val) {
+ stream.writeByteArray(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeShortArray(String name, @Nullable short[] val) {
+ stream.writeShortArray(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeIntArray(String name, @Nullable int[] val) {
+ stream.writeIntArray(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeLongArray(String name, @Nullable long[] val) {
+ stream.writeLongArray(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeFloatArray(String name, @Nullable float[] val) {
+ stream.writeFloatArray(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeDoubleArray(String name, @Nullable double[] val) {
+ stream.writeDoubleArray(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeCharArray(String name, @Nullable char[] val) {
+ stream.writeCharArray(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeBooleanArray(String name, @Nullable boolean[] val) {
+ stream.writeBooleanArray(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeString(String name, String val) {
+ stream.writeString(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeBitSet(String name, BitSet val) {
+ stream.writeBitSet(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeUuid(String name, UUID val) {
+ stream.writeUuid(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeIgniteUuid(String name, IgniteUuid val) {
+ stream.writeIgniteUuid(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeEnum(String name, Enum> val) {
+ stream.writeEnum(val);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeMessage(String name, @Nullable MessageAdapter msg) {
+ if (msg != null)
+ msg.setWriter(this);
+
+ stream.writeMessage(msg);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeObjectArray(String name, T[] arr, Class itemCls) {
+ stream.writeObjectArray(arr, itemCls, this);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeCollection(String name, Collection col, Class itemCls) {
+ stream.writeCollection(col, itemCls, this);
+
+ return stream.lastFinished();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean writeMap(String name, Map map, Class keyCls, Class valCls) {
+ stream.writeMap(map, keyCls, valCls, this);
+
+ return stream.lastFinished();
+ }
+}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
index 6be401fe1bb90..771b352f4ecfb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
@@ -25,7 +25,6 @@
import org.apache.ignite.internal.managers.communication.*;
import org.apache.ignite.internal.managers.eventstorage.*;
import org.apache.ignite.internal.processors.cache.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.internal.util.typedef.internal.*;
@@ -38,7 +37,6 @@
import javax.cache.expiry.*;
import java.io.*;
-import java.nio.*;
import java.util.*;
import static java.util.Arrays.*;
@@ -318,8 +316,8 @@ protected final String stopInfo() {
A.notNull(topic, "topic");
try {
- if (msg instanceof GridTcpCommunicationMessageAdapter)
- ctx.io().send(node, topic, (GridTcpCommunicationMessageAdapter)msg, SYSTEM_POOL);
+ if (msg instanceof MessageAdapter)
+ ctx.io().send(node, topic, (MessageAdapter)msg, SYSTEM_POOL);
else
ctx.io().sendUserMessage(asList(node), msg, topic, false, 0);
}
@@ -501,24 +499,6 @@ protected final String stopInfo() {
return null;
}
- @Override public boolean writeDelta(UUID nodeId, Object msg, ByteBuffer buf) {
- for (MessageCallback patcher : ctx.plugins().extensions(MessageCallback.class)) {
- if (!patcher.onSend(nodeId, msg, buf))
- return false;
- }
-
- return true;
- }
-
- @Override public boolean readDelta(UUID nodeId, Class> msgCls, ByteBuffer buf) {
- for (MessageCallback patcher : ctx.plugins().extensions(MessageCallback.class)) {
- if (!patcher.onReceive(nodeId, msgCls, buf))
- return false;
- }
-
- return true;
- }
-
@Override public Collection authenticatedSubjects() {
return ctx.grid().security().authenticatedSubjects();
}
@@ -547,8 +527,12 @@ protected final String stopInfo() {
}
}
- @Override public GridTcpMessageFactory messageFactory() {
- return ctx.messageFactory();
+ @Override public MessageFormatter messageFormatter() {
+ return ctx.io().formatter();
+ }
+
+ @Override public MessageFactory messageFactory() {
+ return ctx.io().messageFactory();
}
/**
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointRequest.java
index edbc944a78d97..5085a9cdae501 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointRequest.java
@@ -17,9 +17,9 @@
package org.apache.ignite.internal.managers.checkpoint;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import java.io.*;
import java.nio.*;
@@ -27,7 +27,7 @@
/**
* This class defines checkpoint request.
*/
-public class GridCheckpointRequest extends GridTcpCommunicationMessageAdapter {
+public class GridCheckpointRequest extends MessageAdapter {
/** */
private static final long serialVersionUID = 0L;
@@ -85,7 +85,7 @@ public String getCheckpointSpi() {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridCheckpointRequest _clone = new GridCheckpointRequest();
clone0(_clone);
@@ -94,7 +94,7 @@ public String getCheckpointSpi() {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridCheckpointRequest _clone = (GridCheckpointRequest)_msg;
_clone.sesId = sesId;
@@ -105,33 +105,33 @@ public String getCheckpointSpi() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putString(cpSpi))
+ if (!writer.writeString("cpSpi", cpSpi))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putString(key))
+ if (!writer.writeString("key", key))
return false;
- commState.idx++;
+ state++;
case 2:
- if (!commState.putGridUuid(sesId))
+ if (!writer.writeIgniteUuid("sesId", sesId))
return false;
- commState.idx++;
+ state++;
}
@@ -141,38 +141,32 @@ public String getCheckpointSpi() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- String cpSpi0 = commState.getString();
+ cpSpi = reader.readString("cpSpi");
- if (cpSpi0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- cpSpi = cpSpi0;
-
- commState.idx++;
+ state++;
case 1:
- String key0 = commState.getString();
+ key = reader.readString("key");
- if (key0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- key = key0;
-
- commState.idx++;
+ state++;
case 2:
- IgniteUuid sesId0 = commState.getGridUuid();
+ sesId = reader.readIgniteUuid("sesId");
- if (sesId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- sesId = sesId0;
-
- commState.idx++;
+ state++;
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
index ad4d3fe0d1dd5..e53691df3b186 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
@@ -21,18 +21,19 @@
import org.apache.ignite.cluster.*;
import org.apache.ignite.events.*;
import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.direct.*;
import org.apache.ignite.internal.managers.*;
import org.apache.ignite.internal.managers.deployment.*;
import org.apache.ignite.internal.managers.eventstorage.*;
import org.apache.ignite.internal.processors.timeout.*;
import org.apache.ignite.internal.util.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.internal.util.worker.*;
import org.apache.ignite.lang.*;
import org.apache.ignite.marshaller.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import org.apache.ignite.spi.*;
import org.apache.ignite.spi.communication.*;
import org.jdk8.backport.*;
@@ -130,6 +131,12 @@ public class GridIoManager extends GridManagerAdapter 0) {
+ if (formatterExt.length > 1)
+ throw new IgniteCheckedException("More than one MessageFormatter extension is defined. Check your " +
+ "plugins configuration and make sure that only one of them provides custom message format.");
+
+ formatter = formatterExt[0];
+ }
+ else {
+ formatter = new MessageFormatter() {
+ @Override public MessageWriter writer() {
+ return new DirectMessageWriter();
+ }
+
+ @Override public MessageReader reader() {
+ return new DirectMessageReader(msgFactory);
+ }
+ };
+ }
+
+ msgFactory = new GridIoMessageFactory(formatter, ctx.plugins().extensions(MessageFactory.class));
+
if (log.isDebugEnabled())
log.debug(startInfo());
}
@@ -841,7 +889,7 @@ private void send(
ClusterNode node,
Object topic,
int topicOrd,
- GridTcpCommunicationMessageAdapter msg,
+ MessageAdapter msg,
GridIoPolicy plc,
boolean ordered,
long timeout,
@@ -852,8 +900,6 @@ private void send(
assert msg != null;
assert plc != null;
- GridIoMessage ioMsg = new GridIoMessage(plc, topic, topicOrd, msg, ordered, timeout, skipOnTimeout);
-
if (locNodeId.equals(node.id())) {
assert plc != P2P_POOL;
@@ -862,12 +908,16 @@ private void send(
if (commLsnr == null)
throw new IgniteCheckedException("Trying to send message when grid is not fully started.");
+ GridIoMessage ioMsg = new GridIoMessage(plc, topic, topicOrd, msg, ordered, timeout, skipOnTimeout);
+
if (ordered)
processOrderedMessage(locNodeId, ioMsg, plc, null);
else
processRegularMessage0(ioMsg, locNodeId);
}
else {
+ GridIoMessage ioMsg = new GridIoMessage(plc, topic, topicOrd, msg.clone(), ordered, timeout, skipOnTimeout);
+
if (topicOrd < 0)
ioMsg.topicBytes(marsh.marshal(topic));
@@ -890,7 +940,7 @@ private void send(
* @param plc Type of processing.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
- public void send(UUID nodeId, Object topic, GridTcpCommunicationMessageAdapter msg, GridIoPolicy plc)
+ public void send(UUID nodeId, Object topic, MessageAdapter msg, GridIoPolicy plc)
throws IgniteCheckedException {
ClusterNode node = ctx.discovery().node(nodeId);
@@ -908,7 +958,7 @@ public void send(UUID nodeId, Object topic, GridTcpCommunicationMessageAdapter m
* @throws IgniteCheckedException Thrown in case of any errors.
*/
@SuppressWarnings("TypeMayBeWeakened")
- public void send(UUID nodeId, GridTopic topic, GridTcpCommunicationMessageAdapter msg, GridIoPolicy plc)
+ public void send(UUID nodeId, GridTopic topic, MessageAdapter msg, GridIoPolicy plc)
throws IgniteCheckedException {
ClusterNode node = ctx.discovery().node(nodeId);
@@ -925,7 +975,7 @@ public void send(UUID nodeId, GridTopic topic, GridTcpCommunicationMessageAdapte
* @param plc Type of processing.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
- public void send(ClusterNode node, Object topic, GridTcpCommunicationMessageAdapter msg, GridIoPolicy plc)
+ public void send(ClusterNode node, Object topic, MessageAdapter msg, GridIoPolicy plc)
throws IgniteCheckedException {
send(node, topic, -1, msg, plc, false, 0, false);
}
@@ -937,7 +987,7 @@ public void send(ClusterNode node, Object topic, GridTcpCommunicationMessageAdap
* @param plc Type of processing.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
- public void send(ClusterNode node, GridTopic topic, GridTcpCommunicationMessageAdapter msg, GridIoPolicy plc)
+ public void send(ClusterNode node, GridTopic topic, MessageAdapter msg, GridIoPolicy plc)
throws IgniteCheckedException {
send(node, topic, topic.ordinal(), msg, plc, false, 0, false);
}
@@ -954,7 +1004,7 @@ public void send(ClusterNode node, GridTopic topic, GridTcpCommunicationMessageA
public void sendOrderedMessage(
ClusterNode node,
Object topic,
- GridTcpCommunicationMessageAdapter msg,
+ MessageAdapter msg,
GridIoPolicy plc,
long timeout,
boolean skipOnTimeout
@@ -976,7 +1026,7 @@ public void sendOrderedMessage(
public void sendOrderedMessage(
UUID nodeId,
Object topic,
- GridTcpCommunicationMessageAdapter msg,
+ MessageAdapter msg,
GridIoPolicy plc,
long timeout,
boolean skipOnTimeout
@@ -1003,7 +1053,7 @@ public void sendOrderedMessage(
public void sendOrderedMessage(
Collection extends ClusterNode> nodes,
Object topic,
- GridTcpCommunicationMessageAdapter msg,
+ MessageAdapter msg,
GridIoPolicy plc,
long timeout,
boolean skipOnTimeout
@@ -1024,7 +1074,7 @@ public void sendOrderedMessage(
public void send(
Collection extends ClusterNode> nodes,
Object topic,
- GridTcpCommunicationMessageAdapter msg,
+ MessageAdapter msg,
GridIoPolicy plc
) throws IgniteCheckedException {
send(nodes, topic, -1, msg, plc, false, 0, false);
@@ -1040,7 +1090,7 @@ public void send(
public void send(
Collection extends ClusterNode> nodes,
GridTopic topic,
- GridTcpCommunicationMessageAdapter msg,
+ MessageAdapter msg,
GridIoPolicy plc
) throws IgniteCheckedException {
send(nodes, topic, topic.ordinal(), msg, plc, false, 0, false);
@@ -1100,7 +1150,7 @@ public void sendUserMessage(Collection extends ClusterNode> nodes, Object msg,
depClsName = cls0.getName();
}
- GridTcpCommunicationMessageAdapter ioMsg = new GridIoUserMessage(
+ MessageAdapter ioMsg = new GridIoUserMessage(
msg,
serMsg,
depClsName,
@@ -1173,7 +1223,7 @@ private void send(
Collection extends ClusterNode> nodes,
Object topic,
int topicOrd,
- GridTcpCommunicationMessageAdapter msg,
+ MessageAdapter msg,
GridIoPolicy plc,
boolean ordered,
long timeout,
@@ -1192,15 +1242,8 @@ private void send(
// Small optimization, as communication SPIs may have lighter implementation for sending
// messages to one node vs. many.
if (!nodes.isEmpty()) {
- boolean first = true;
-
- for (ClusterNode node : nodes) {
- GridTcpCommunicationMessageAdapter msg0 = first ? msg : msg.clone();
-
- first = false;
-
- send(node, topic, topicOrd, msg0, plc, ordered, timeout, skipOnTimeout);
- }
+ for (ClusterNode node : nodes)
+ send(node, topic, topicOrd, msg, plc, ordered, timeout, skipOnTimeout);
}
else if (log.isDebugEnabled())
log.debug("Failed to send message to empty nodes collection [topic=" + topic + ", msg=" +
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
index 67766a1db7d38..c77f1745f7b97 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
@@ -18,9 +18,9 @@
package org.apache.ignite.internal.managers.communication;
import org.apache.ignite.internal.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import java.io.*;
import java.nio.*;
@@ -28,7 +28,7 @@
/**
* Wrapper for all grid messages.
*/
-public class GridIoMessage extends GridTcpCommunicationMessageAdapter {
+public class GridIoMessage extends MessageAdapter {
/** */
private static final long serialVersionUID = 0L;
@@ -56,7 +56,7 @@ public class GridIoMessage extends GridTcpCommunicationMessageAdapter {
private boolean skipOnTimeout;
/** Message. */
- private GridTcpCommunicationMessageAdapter msg;
+ private MessageAdapter msg;
/**
* No-op constructor to support {@link Externalizable} interface.
@@ -79,7 +79,7 @@ public GridIoMessage(
GridIoPolicy plc,
Object topic,
int topicOrd,
- GridTcpCommunicationMessageAdapter msg,
+ MessageAdapter msg,
boolean ordered,
long timeout,
boolean skipOnTimeout
@@ -180,7 +180,7 @@ boolean isOrdered() {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridIoMessage _clone = new GridIoMessage();
clone0(_clone);
@@ -190,7 +190,7 @@ boolean isOrdered() {
/** {@inheritDoc} */
@SuppressWarnings("RedundantCast")
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridIoMessage _clone = (GridIoMessage)_msg;
_clone.plc = plc;
@@ -200,63 +200,63 @@ boolean isOrdered() {
_clone.ordered = ordered;
_clone.timeout = timeout;
_clone.skipOnTimeout = skipOnTimeout;
- _clone.msg = msg != null ? (GridTcpCommunicationMessageAdapter)msg.clone() : null;
+ _clone.msg = msg != null ? (MessageAdapter)msg.clone() : null;
}
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putMessage(msg))
+ if (!writer.writeMessage("msg", msg))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putBoolean(ordered))
+ if (!writer.writeBoolean("ordered", ordered))
return false;
- commState.idx++;
+ state++;
case 2:
- if (!commState.putEnum(plc))
+ if (!writer.writeEnum("plc", plc))
return false;
- commState.idx++;
+ state++;
case 3:
- if (!commState.putBoolean(skipOnTimeout))
+ if (!writer.writeBoolean("skipOnTimeout", skipOnTimeout))
return false;
- commState.idx++;
+ state++;
case 4:
- if (!commState.putLong(timeout))
+ if (!writer.writeLong("timeout", timeout))
return false;
- commState.idx++;
+ state++;
case 5:
- if (!commState.putByteArray(topicBytes))
+ if (!writer.writeByteArray("topicBytes", topicBytes))
return false;
- commState.idx++;
+ state++;
case 6:
- if (!commState.putInt(topicOrd))
+ if (!writer.writeInt("topicOrd", topicOrd))
return false;
- commState.idx++;
+ state++;
}
@@ -266,70 +266,64 @@ boolean isOrdered() {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- Object msg0 = commState.getMessage();
+ msg = reader.readMessage("msg");
- if (msg0 == MSG_NOT_READ)
+ if (!reader.isLastRead())
return false;
- msg = (GridTcpCommunicationMessageAdapter)msg0;
-
- commState.idx++;
+ state++;
case 1:
- if (buf.remaining() < 1)
- return false;
+ ordered = reader.readBoolean("ordered");
- ordered = commState.getBoolean();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 2:
- if (buf.remaining() < 1)
- return false;
+ plc = reader.readEnum("plc", GridIoPolicy.class);
- byte plc0 = commState.getByte();
-
- plc = GridIoPolicy.fromOrdinal(plc0);
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 3:
- if (buf.remaining() < 1)
- return false;
+ skipOnTimeout = reader.readBoolean("skipOnTimeout");
- skipOnTimeout = commState.getBoolean();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 4:
- if (buf.remaining() < 8)
- return false;
+ timeout = reader.readLong("timeout");
- timeout = commState.getLong();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 5:
- byte[] topicBytes0 = commState.getByteArray();
+ topicBytes = reader.readByteArray("topicBytes");
- if (topicBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- topicBytes = topicBytes0;
-
- commState.idx++;
+ state++;
case 6:
- if (buf.remaining() < 4)
- return false;
+ topicOrd = reader.readInt("topicOrd");
- topicOrd = commState.getInt();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
}
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
new file mode 100644
index 0000000000000..e8481f1688ca9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -0,0 +1,543 @@
+/*
+ * 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.managers.communication;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.managers.checkpoint.*;
+import org.apache.ignite.internal.managers.deployment.*;
+import org.apache.ignite.internal.managers.eventstorage.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.cache.distributed.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.*;
+import org.apache.ignite.internal.processors.cache.distributed.near.*;
+import org.apache.ignite.internal.processors.cache.query.*;
+import org.apache.ignite.internal.processors.cache.version.*;
+import org.apache.ignite.internal.processors.clock.*;
+import org.apache.ignite.internal.processors.continuous.*;
+import org.apache.ignite.internal.processors.dataload.*;
+import org.apache.ignite.internal.processors.fs.*;
+import org.apache.ignite.internal.processors.rest.handlers.task.*;
+import org.apache.ignite.internal.processors.streamer.*;
+import org.apache.ignite.internal.util.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
+import org.apache.ignite.spi.collision.jobstealing.*;
+import org.apache.ignite.spi.communication.tcp.*;
+import org.jdk8.backport.*;
+
+import java.util.*;
+
+/**
+ * Message factory implementation.
+ */
+public class GridIoMessageFactory implements MessageFactory {
+ /** Custom messages registry. Used for test purposes. */
+ private static final Map> CUSTOM = new ConcurrentHashMap8<>();
+
+ /** Message reader factory. */
+ private final MessageFormatter formatter;
+
+ /** Extensions. */
+ private final MessageFactory[] ext;
+
+ /**
+ * @param formatter Message formatter.
+ * @param ext Extensions.
+ */
+ public GridIoMessageFactory(MessageFormatter formatter, MessageFactory[] ext) {
+ assert formatter != null;
+
+ this.formatter = formatter;
+ this.ext = ext;
+ }
+
+ /** {@inheritDoc} */
+ @Override public MessageAdapter create(byte type) {
+ MessageAdapter msg = null;
+
+ switch (type) {
+ case TcpCommunicationSpi.NODE_ID_MSG_TYPE:
+ return new TcpCommunicationSpi.NodeIdMessage();
+
+ case TcpCommunicationSpi.RECOVERY_LAST_ID_MSG_TYPE:
+ return new TcpCommunicationSpi.RecoveryLastReceivedMessage();
+
+ case TcpCommunicationSpi.HANDSHAKE_MSG_TYPE:
+ return new TcpCommunicationSpi.HandshakeMessage();
+
+ case 0:
+ msg = new GridJobCancelRequest();
+
+ break;
+
+ case 1:
+ msg = new GridJobExecuteRequest();
+
+ break;
+
+ case 2:
+ msg = new GridJobExecuteResponse();
+
+ break;
+
+ case 3:
+ msg = new GridJobSiblingsRequest();
+
+ break;
+
+ case 4:
+ msg = new GridJobSiblingsResponse();
+
+ break;
+
+ case 5:
+ msg = new GridTaskCancelRequest();
+
+ break;
+
+ case 6:
+ msg = new GridTaskSessionRequest();
+
+ break;
+
+ case 7:
+ msg = new GridCheckpointRequest();
+
+ break;
+
+ case 8:
+ msg = new GridIoMessage();
+
+ break;
+
+ case 9:
+ msg = new GridIoUserMessage();
+
+ break;
+
+ case 10:
+ msg = new GridDeploymentInfoBean();
+
+ break;
+
+ case 11:
+ msg = new GridDeploymentRequest();
+
+ break;
+
+ case 12:
+ msg = new GridDeploymentResponse();
+
+ break;
+
+ case 13:
+ msg = new GridEventStorageMessage();
+
+ break;
+
+ case 14:
+ msg = new GridCacheEvictionRequest();
+
+ break;
+
+ case 15:
+ msg = new GridCacheEvictionResponse();
+
+ break;
+
+ case 16:
+ msg = new GridCacheOptimisticCheckPreparedTxRequest();
+
+ break;
+
+ case 17:
+ msg = new GridCacheOptimisticCheckPreparedTxResponse();
+
+ break;
+
+ case 18:
+ msg = new GridCachePessimisticCheckCommittedTxRequest();
+
+ break;
+
+ case 19:
+ msg = new GridCachePessimisticCheckCommittedTxResponse();
+
+ break;
+
+ case 20:
+ msg = new GridCacheTtlUpdateRequest();
+
+ break;
+
+ case 21:
+ msg = new GridDistributedLockRequest();
+
+ break;
+
+ case 22:
+ msg = new GridDistributedLockResponse();
+
+ break;
+
+ case 23:
+ msg = new GridDistributedTxFinishRequest();
+
+ break;
+
+ case 24:
+ msg = new GridDistributedTxFinishResponse();
+
+ break;
+
+ case 25:
+ msg = new GridDistributedTxPrepareRequest();
+
+ break;
+
+ case 26:
+ msg = new GridDistributedTxPrepareResponse();
+
+ break;
+
+ case 27:
+ msg = new GridDistributedUnlockRequest();
+
+ break;
+
+ case 28:
+ msg = new GridDhtAffinityAssignmentRequest();
+
+ break;
+
+ case 29:
+ msg = new GridDhtAffinityAssignmentResponse();
+
+ break;
+
+ case 30:
+ msg = new GridDhtLockRequest();
+
+ break;
+
+ case 31:
+ msg = new GridDhtLockResponse();
+
+ break;
+
+ case 32:
+ msg = new GridDhtTxFinishRequest();
+
+ break;
+
+ case 33:
+ msg = new GridDhtTxFinishResponse();
+
+ break;
+
+ case 34:
+ msg = new GridDhtTxPrepareRequest();
+
+ break;
+
+ case 35:
+ msg = new GridDhtTxPrepareResponse();
+
+ break;
+
+ case 36:
+ msg = new GridDhtUnlockRequest();
+
+ break;
+
+ case 37:
+ msg = new GridDhtAtomicDeferredUpdateResponse();
+
+ break;
+
+ case 38:
+ msg = new GridDhtAtomicUpdateRequest();
+
+ break;
+
+ case 39:
+ msg = new GridDhtAtomicUpdateResponse();
+
+ break;
+
+ case 40:
+ msg = new GridNearAtomicUpdateRequest();
+
+ break;
+
+ case 41:
+ msg = new GridNearAtomicUpdateResponse();
+
+ break;
+
+ case 42:
+ msg = new GridDhtForceKeysRequest();
+
+ break;
+
+ case 43:
+ msg = new GridDhtForceKeysResponse();
+
+ break;
+
+ case 44:
+ msg = new GridDhtPartitionDemandMessage();
+
+ break;
+
+ case 45:
+ msg = new GridDhtPartitionSupplyMessage();
+
+ break;
+
+ case 46:
+ msg = new GridDhtPartitionsFullMessage();
+
+ break;
+
+ case 47:
+ msg = new GridDhtPartitionsSingleMessage();
+
+ break;
+
+ case 48:
+ msg = new GridDhtPartitionsSingleRequest();
+
+ break;
+
+ case 49:
+ msg = new GridNearGetRequest();
+
+ break;
+
+ case 50:
+ msg = new GridNearGetResponse();
+
+ break;
+
+ case 51:
+ msg = new GridNearLockRequest();
+
+ break;
+
+ case 52:
+ msg = new GridNearLockResponse();
+
+ break;
+
+ case 53:
+ msg = new GridNearTxFinishRequest();
+
+ break;
+
+ case 54:
+ msg = new GridNearTxFinishResponse();
+
+ break;
+
+ case 55:
+ msg = new GridNearTxPrepareRequest();
+
+ break;
+
+ case 56:
+ msg = new GridNearTxPrepareResponse();
+
+ break;
+
+ case 57:
+ msg = new GridNearUnlockRequest();
+
+ break;
+
+ case 58:
+ msg = new GridCacheQueryRequest();
+
+ break;
+
+ case 59:
+ msg = new GridCacheQueryResponse();
+
+ break;
+
+ case 60:
+ msg = new GridClockDeltaSnapshotMessage();
+
+ break;
+
+ case 61:
+ msg = new GridContinuousMessage();
+
+ break;
+
+ case 62:
+ msg = new GridDataLoadRequest();
+
+ break;
+
+ case 63:
+ msg = new GridDataLoadResponse();
+
+ break;
+
+ case 64:
+ msg = new GridGgfsAckMessage();
+
+ break;
+
+ case 65:
+ msg = new GridGgfsBlockKey();
+
+ break;
+
+ case 66:
+ msg = new GridGgfsBlocksMessage();
+
+ break;
+
+ case 67:
+ msg = new GridGgfsDeleteMessage();
+
+ break;
+
+ case 68:
+ msg = new GridGgfsFileAffinityRange();
+
+ break;
+
+ case 69:
+ msg = new GridGgfsFragmentizerRequest();
+
+ break;
+
+ case 70:
+ msg = new GridGgfsFragmentizerResponse();
+
+ break;
+
+ case 71:
+ msg = new GridGgfsSyncMessage();
+
+ break;
+
+ case 76:
+ msg = new GridTaskResultRequest();
+
+ break;
+
+ case 77:
+ msg = new GridTaskResultResponse();
+
+ break;
+
+ case 79:
+ msg = new GridStreamerCancelRequest();
+
+ break;
+
+ case 80:
+ msg = new GridStreamerExecutionRequest();
+
+ break;
+
+ case 81:
+ msg = new GridStreamerResponse();
+
+ break;
+
+ case 82:
+ msg = new JobStealingRequest();
+
+ break;
+
+ case 83:
+ msg = new GridClockDeltaVersion();
+
+ break;
+
+ case 84:
+ msg = new GridByteArrayList();
+
+ break;
+
+ case 85:
+ msg = new GridLongList();
+
+ break;
+
+ case 86:
+ msg = new GridCacheVersion();
+
+ break;
+
+ case 87:
+ msg = new GridDhtPartitionExchangeId();
+
+ break;
+
+ case 88:
+ msg = new GridCacheValueBytes();
+
+ break;
+
+ default:
+ if (ext != null) {
+ for (MessageFactory factory : ext) {
+ msg = factory.create(type);
+
+ if (msg != null)
+ break;
+ }
+ }
+
+ if (msg == null) {
+ IgniteOutClosure c = CUSTOM.get(type);
+
+ if (c != null)
+ msg = c.apply();
+ }
+ }
+
+ if (msg == null)
+ throw new IgniteException("Invalid message type: " + type);
+
+ msg.setReader(formatter.reader());
+
+ return msg;
+ }
+
+ /**
+ * Registers factory for custom message. Used for test purposes.
+ *
+ * @param type Message type.
+ * @param c Message producer.
+ */
+ public static void registerCustom(byte type, IgniteOutClosure c) {
+ assert c != null;
+
+ CUSTOM.put(type, c);
+ }
+}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoUserMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoUserMessage.java
index 481456d76ffbf..05ff2dfa2ff5a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoUserMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoUserMessage.java
@@ -20,10 +20,10 @@
import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.*;
import org.apache.ignite.internal.managers.deployment.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import org.jetbrains.annotations.*;
import java.io.*;
@@ -33,7 +33,7 @@
/**
* User message wrapper.
*/
-public class GridIoUserMessage extends GridTcpCommunicationMessageAdapter {
+public class GridIoUserMessage extends MessageAdapter {
/** */
private static final long serialVersionUID = 0L;
@@ -204,7 +204,7 @@ public void deployment(GridDeployment dep) {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridIoUserMessage _clone = new GridIoUserMessage();
clone0(_clone);
@@ -213,7 +213,7 @@ public void deployment(GridDeployment dep) {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridIoUserMessage _clone = (GridIoUserMessage)_msg;
_clone.body = body;
@@ -231,89 +231,57 @@ public void deployment(GridDeployment dep) {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putByteArray(bodyBytes))
+ if (!writer.writeByteArray("bodyBytes", bodyBytes))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putGridUuid(clsLdrId))
+ if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
return false;
- commState.idx++;
+ state++;
case 2:
- if (!commState.putString(depClsName))
+ if (!writer.writeString("depClsName", depClsName))
return false;
- commState.idx++;
+ state++;
case 3:
- if (!commState.putEnum(depMode))
+ if (!writer.writeEnum("depMode", depMode))
return false;
- commState.idx++;
+ state++;
case 4:
- if (ldrParties != null) {
- if (commState.it == null) {
- if (!commState.putInt(ldrParties.size()))
- return false;
-
- commState.it = ldrParties.entrySet().iterator();
- }
-
- while (commState.it.hasNext() || commState.cur != NULL) {
- if (commState.cur == NULL)
- commState.cur = commState.it.next();
-
- Map.Entry e = (Map.Entry)commState.cur;
-
- if (!commState.keyDone) {
- if (!commState.putUuid(e.getKey()))
- return false;
-
- commState.keyDone = true;
- }
-
- if (!commState.putGridUuid(e.getValue()))
- return false;
-
- commState.keyDone = false;
-
- commState.cur = NULL;
- }
-
- commState.it = null;
- } else {
- if (!commState.putInt(-1))
- return false;
- }
+ if (!writer.writeMap("ldrParties", ldrParties, UUID.class, IgniteUuid.class))
+ return false;
- commState.idx++;
+ state++;
case 5:
- if (!commState.putByteArray(topicBytes))
+ if (!writer.writeByteArray("topicBytes", topicBytes))
return false;
- commState.idx++;
+ state++;
case 6:
- if (!commState.putString(userVer))
+ if (!writer.writeString("userVer", userVer))
return false;
- commState.idx++;
+ state++;
}
@@ -323,110 +291,64 @@ public void deployment(GridDeployment dep) {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- byte[] bodyBytes0 = commState.getByteArray();
+ bodyBytes = reader.readByteArray("bodyBytes");
- if (bodyBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- bodyBytes = bodyBytes0;
-
- commState.idx++;
+ state++;
case 1:
- IgniteUuid clsLdrId0 = commState.getGridUuid();
+ clsLdrId = reader.readIgniteUuid("clsLdrId");
- if (clsLdrId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- clsLdrId = clsLdrId0;
-
- commState.idx++;
+ state++;
case 2:
- String depClsName0 = commState.getString();
+ depClsName = reader.readString("depClsName");
- if (depClsName0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- depClsName = depClsName0;
-
- commState.idx++;
+ state++;
case 3:
- if (buf.remaining() < 1)
- return false;
-
- byte depMode0 = commState.getByte();
+ depMode = reader.readEnum("depMode", DeploymentMode.class);
- depMode = DeploymentMode.fromOrdinal(depMode0);
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 4:
- if (commState.readSize == -1) {
- if (buf.remaining() < 4)
- return false;
-
- commState.readSize = commState.getInt();
- }
-
- if (commState.readSize >= 0) {
- if (ldrParties == null)
- ldrParties = U.newHashMap(commState.readSize);
-
- for (int i = commState.readItems; i < commState.readSize; i++) {
- if (!commState.keyDone) {
- UUID _val = commState.getUuid();
-
- if (_val == UUID_NOT_READ)
- return false;
-
- commState.cur = _val;
- commState.keyDone = true;
- }
-
- IgniteUuid _val = commState.getGridUuid();
+ ldrParties = reader.readMap("ldrParties", UUID.class, IgniteUuid.class, false);
- if (_val == GRID_UUID_NOT_READ)
- return false;
-
- ldrParties.put((UUID)commState.cur, _val);
-
- commState.keyDone = false;
-
- commState.readItems++;
- }
- }
-
- commState.readSize = -1;
- commState.readItems = 0;
- commState.cur = null;
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 5:
- byte[] topicBytes0 = commState.getByteArray();
+ topicBytes = reader.readByteArray("topicBytes");
- if (topicBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- topicBytes = topicBytes0;
-
- commState.idx++;
+ state++;
case 6:
- String userVer0 = commState.getString();
+ userVer = reader.readString("userVer");
- if (userVer0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- userVer = userVer0;
-
- commState.idx++;
+ state++;
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java
index aa1b288b3424a..d9a7d9bdb71a7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java
@@ -24,13 +24,13 @@
import org.apache.ignite.internal.managers.communication.*;
import org.apache.ignite.internal.managers.eventstorage.*;
import org.apache.ignite.internal.util.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.lang.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
import org.apache.ignite.marshaller.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import java.io.*;
import java.util.*;
@@ -282,7 +282,7 @@ private void processResourceRequest(UUID nodeId, GridDeploymentRequest req) {
* @param topic Response topic.
* @param res Response.
*/
- private void sendResponse(UUID nodeId, Object topic, GridTcpCommunicationMessageAdapter res) {
+ private void sendResponse(UUID nodeId, Object topic, MessageAdapter res) {
ClusterNode node = ctx.discovery().node(nodeId);
if (node != null) {
@@ -314,7 +314,7 @@ else if (log.isDebugEnabled())
void sendUndeployRequest(String rsrcName, Collection rmtNodes) throws IgniteCheckedException {
assert !rmtNodes.contains(ctx.discovery().localNode());
- GridTcpCommunicationMessageAdapter req = new GridDeploymentRequest(null, null, rsrcName, true);
+ MessageAdapter req = new GridDeploymentRequest(null, null, rsrcName, true);
if (!rmtNodes.isEmpty()) {
ctx.io().send(
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentInfoBean.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentInfoBean.java
index e93c3c972a9e7..a84d0493a4358 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentInfoBean.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentInfoBean.java
@@ -19,10 +19,10 @@
import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import java.io.*;
import java.nio.*;
@@ -31,7 +31,7 @@
/**
* Deployment info bean.
*/
-public class GridDeploymentInfoBean extends GridTcpCommunicationMessageAdapter implements GridDeploymentInfo,
+public class GridDeploymentInfoBean extends MessageAdapter implements GridDeploymentInfo,
Externalizable {
/** */
private static final long serialVersionUID = 0L;
@@ -139,7 +139,7 @@ public void localDeploymentOwner(boolean locDepOwner) {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridDeploymentInfoBean _clone = new GridDeploymentInfoBean();
clone0(_clone);
@@ -148,7 +148,7 @@ public void localDeploymentOwner(boolean locDepOwner) {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridDeploymentInfoBean _clone = (GridDeploymentInfoBean)_msg;
_clone.clsLdrId = clsLdrId;
@@ -161,77 +161,45 @@ public void localDeploymentOwner(boolean locDepOwner) {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putGridUuid(clsLdrId))
+ if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putEnum(depMode))
+ if (!writer.writeEnum("depMode", depMode))
return false;
- commState.idx++;
+ state++;
case 2:
- if (!commState.putBoolean(locDepOwner))
+ if (!writer.writeBoolean("locDepOwner", locDepOwner))
return false;
- commState.idx++;
+ state++;
case 3:
- if (participants != null) {
- if (commState.it == null) {
- if (!commState.putInt(participants.size()))
- return false;
-
- commState.it = participants.entrySet().iterator();
- }
-
- while (commState.it.hasNext() || commState.cur != NULL) {
- if (commState.cur == NULL)
- commState.cur = commState.it.next();
-
- Map.Entry e = (Map.Entry)commState.cur;
-
- if (!commState.keyDone) {
- if (!commState.putUuid(e.getKey()))
- return false;
-
- commState.keyDone = true;
- }
-
- if (!commState.putGridUuid(e.getValue()))
- return false;
-
- commState.keyDone = false;
-
- commState.cur = NULL;
- }
-
- commState.it = null;
- } else {
- if (!commState.putInt(-1))
- return false;
- }
+ if (!writer.writeMap("participants", participants, UUID.class, IgniteUuid.class))
+ return false;
- commState.idx++;
+ state++;
case 4:
- if (!commState.putString(userVer))
+ if (!writer.writeString("userVer", userVer))
return false;
- commState.idx++;
+ state++;
}
@@ -241,88 +209,48 @@ public void localDeploymentOwner(boolean locDepOwner) {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- IgniteUuid clsLdrId0 = commState.getGridUuid();
+ clsLdrId = reader.readIgniteUuid("clsLdrId");
- if (clsLdrId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- clsLdrId = clsLdrId0;
-
- commState.idx++;
+ state++;
case 1:
- if (buf.remaining() < 1)
- return false;
-
- byte depMode0 = commState.getByte();
+ depMode = reader.readEnum("depMode", DeploymentMode.class);
- depMode = DeploymentMode.fromOrdinal(depMode0);
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 2:
- if (buf.remaining() < 1)
- return false;
+ locDepOwner = reader.readBoolean("locDepOwner");
- locDepOwner = commState.getBoolean();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 3:
- if (commState.readSize == -1) {
- if (buf.remaining() < 4)
- return false;
-
- commState.readSize = commState.getInt();
- }
-
- if (commState.readSize >= 0) {
- if (participants == null)
- participants = U.newHashMap(commState.readSize);
-
- for (int i = commState.readItems; i < commState.readSize; i++) {
- if (!commState.keyDone) {
- UUID _val = commState.getUuid();
-
- if (_val == UUID_NOT_READ)
- return false;
-
- commState.cur = _val;
- commState.keyDone = true;
- }
+ participants = reader.readMap("participants", UUID.class, IgniteUuid.class, false);
- IgniteUuid _val = commState.getGridUuid();
-
- if (_val == GRID_UUID_NOT_READ)
- return false;
-
- participants.put((UUID)commState.cur, _val);
-
- commState.keyDone = false;
-
- commState.readItems++;
- }
- }
-
- commState.readSize = -1;
- commState.readItems = 0;
- commState.cur = null;
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 4:
- String userVer0 = commState.getString();
+ userVer = reader.readString("userVer");
- if (userVer0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- userVer = userVer0;
-
- commState.idx++;
+ state++;
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java
index aa35a7e897733..50d9b24fd62ff 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java
@@ -18,10 +18,10 @@
package org.apache.ignite.internal.managers.deployment;
import org.apache.ignite.internal.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import java.io.*;
import java.nio.*;
@@ -30,7 +30,7 @@
/**
* Deployment request.
*/
-public class GridDeploymentRequest extends GridTcpCommunicationMessageAdapter {
+public class GridDeploymentRequest extends MessageAdapter {
/** */
private static final long serialVersionUID = 0L;
@@ -157,7 +157,7 @@ public void nodeIds(Collection nodeIds) {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridDeploymentRequest _clone = new GridDeploymentRequest();
clone0(_clone);
@@ -166,7 +166,7 @@ public void nodeIds(Collection nodeIds) {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridDeploymentRequest _clone = (GridDeploymentRequest)_msg;
_clone.resTopic = resTopic;
@@ -180,66 +180,45 @@ public void nodeIds(Collection nodeIds) {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putBoolean(isUndeploy))
+ if (!writer.writeBoolean("isUndeploy", isUndeploy))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putGridUuid(ldrId))
+ if (!writer.writeIgniteUuid("ldrId", ldrId))
return false;
- commState.idx++;
+ state++;
case 2:
- if (nodeIds != null) {
- if (commState.it == null) {
- if (!commState.putInt(nodeIds.size()))
- return false;
-
- commState.it = nodeIds.iterator();
- }
-
- while (commState.it.hasNext() || commState.cur != NULL) {
- if (commState.cur == NULL)
- commState.cur = commState.it.next();
-
- if (!commState.putUuid((UUID)commState.cur))
- return false;
-
- commState.cur = NULL;
- }
-
- commState.it = null;
- } else {
- if (!commState.putInt(-1))
- return false;
- }
+ if (!writer.writeCollection("nodeIds", nodeIds, UUID.class))
+ return false;
- commState.idx++;
+ state++;
case 3:
- if (!commState.putByteArray(resTopicBytes))
+ if (!writer.writeByteArray("resTopicBytes", resTopicBytes))
return false;
- commState.idx++;
+ state++;
case 4:
- if (!commState.putString(rsrcName))
+ if (!writer.writeString("rsrcName", rsrcName))
return false;
- commState.idx++;
+ state++;
}
@@ -249,75 +228,48 @@ public void nodeIds(Collection nodeIds) {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (buf.remaining() < 1)
- return false;
+ isUndeploy = reader.readBoolean("isUndeploy");
- isUndeploy = commState.getBoolean();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 1:
- IgniteUuid ldrId0 = commState.getGridUuid();
+ ldrId = reader.readIgniteUuid("ldrId");
- if (ldrId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- ldrId = ldrId0;
-
- commState.idx++;
+ state++;
case 2:
- if (commState.readSize == -1) {
- if (buf.remaining() < 4)
- return false;
+ nodeIds = reader.readCollection("nodeIds", UUID.class);
- commState.readSize = commState.getInt();
- }
-
- if (commState.readSize >= 0) {
- if (nodeIds == null)
- nodeIds = new ArrayList<>(commState.readSize);
-
- for (int i = commState.readItems; i < commState.readSize; i++) {
- UUID _val = commState.getUuid();
-
- if (_val == UUID_NOT_READ)
- return false;
-
- nodeIds.add((UUID)_val);
-
- commState.readItems++;
- }
- }
-
- commState.readSize = -1;
- commState.readItems = 0;
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 3:
- byte[] resTopicBytes0 = commState.getByteArray();
+ resTopicBytes = reader.readByteArray("resTopicBytes");
- if (resTopicBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- resTopicBytes = resTopicBytes0;
-
- commState.idx++;
+ state++;
case 4:
- String rsrcName0 = commState.getString();
+ rsrcName = reader.readString("rsrcName");
- if (rsrcName0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- rsrcName = rsrcName0;
-
- commState.idx++;
+ state++;
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentResponse.java
index 24bd8e0a22c67..9c54b844d5a65 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentResponse.java
@@ -18,8 +18,8 @@
package org.apache.ignite.internal.managers.deployment;
import org.apache.ignite.internal.util.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import java.io.*;
import java.nio.*;
@@ -27,7 +27,7 @@
/**
* Grid deployment response containing requested resource bytes.
*/
-public class GridDeploymentResponse extends GridTcpCommunicationMessageAdapter {
+public class GridDeploymentResponse extends MessageAdapter {
/** */
private static final long serialVersionUID = 0L;
@@ -107,7 +107,7 @@ void errorMessage(String errMsg) {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridDeploymentResponse _clone = new GridDeploymentResponse();
clone0(_clone);
@@ -116,44 +116,44 @@ void errorMessage(String errMsg) {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridDeploymentResponse _clone = (GridDeploymentResponse)_msg;
_clone.success = success;
_clone.errMsg = errMsg;
- _clone.byteSrc = byteSrc;
+ _clone.byteSrc = byteSrc != null ? (GridByteArrayList)byteSrc.clone() : null;
}
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putByteArrayList(byteSrc))
+ if (!writer.writeMessage("byteSrc", byteSrc))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putString(errMsg))
+ if (!writer.writeString("errMsg", errMsg))
return false;
- commState.idx++;
+ state++;
case 2:
- if (!commState.putBoolean(success))
+ if (!writer.writeBoolean("success", success))
return false;
- commState.idx++;
+ state++;
}
@@ -163,36 +163,32 @@ void errorMessage(String errMsg) {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- GridByteArrayList byteSrc0 = commState.getByteArrayList();
+ byteSrc = reader.readMessage("byteSrc");
- if (byteSrc0 == BYTE_ARR_LIST_NOT_READ)
+ if (!reader.isLastRead())
return false;
- byteSrc = byteSrc0;
-
- commState.idx++;
+ state++;
case 1:
- String errMsg0 = commState.getString();
+ errMsg = reader.readString("errMsg");
- if (errMsg0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- errMsg = errMsg0;
-
- commState.idx++;
+ state++;
case 2:
- if (buf.remaining() < 1)
- return false;
+ success = reader.readBoolean("success");
- success = commState.getBoolean();
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
index 834e6498fe320..39df697ce83f0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
@@ -34,7 +34,6 @@
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.internal.util.worker.*;
import org.apache.ignite.lang.*;
-import org.apache.ignite.plugin.extensions.discovery.*;
import org.apache.ignite.plugin.security.*;
import org.apache.ignite.plugin.segmentation.*;
import org.apache.ignite.spi.*;
@@ -266,11 +265,6 @@ public void setNodeAttributes(Map attrs, IgniteProductVersion ve
c.updateAlives(node);
}
- if (type == EVT_NODE_JOINED) {
- for (DiscoveryCallback listener : ctx.plugins().extensions(DiscoveryCallback.class))
- listener.beforeNodeJoined(node);
- }
-
// Put topology snapshot into discovery history.
// There is no race possible between history maintenance and concurrent discovery
// event notifications, since SPI notifies manager about all events from this listener.
@@ -369,11 +363,6 @@ public void setNodeAttributes(Map attrs, IgniteProductVersion ve
topVer.setIfGreater(locNode.order());
- for (DiscoveryCallback listener : ctx.plugins().extensions(DiscoveryCallback.class)) {
- listener.onStart(discoCache().remoteNodes());
- listener.onStart(discoCache().daemonNodes());
- }
-
// Start discovery worker.
new IgniteThread(discoWrk).start();
@@ -1416,9 +1405,6 @@ else if (log.isDebugEnabled())
if (hasRslvrs)
segChkWrk.scheduleSegmentCheck();
- for (DiscoveryCallback listener : ctx.plugins().extensions(DiscoveryCallback.class))
- listener.onNodeLeft(node);
-
if (!isDaemon) {
if (!isLocDaemon) {
if (log.isInfoEnabled())
@@ -1440,9 +1426,6 @@ else if (log.isDebugEnabled())
if (hasRslvrs)
segChkWrk.scheduleSegmentCheck();
- for (DiscoveryCallback listener : ctx.plugins().extensions(DiscoveryCallback.class))
- listener.onNodeLeft(node);
-
if (!isDaemon) {
if (!isLocDaemon) {
U.warn(log, "Node FAILED: " + node);
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageMessage.java
index 37d1f19882edb..058ac8ee6d31a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageMessage.java
@@ -20,10 +20,10 @@
import org.apache.ignite.configuration.*;
import org.apache.ignite.events.*;
import org.apache.ignite.internal.*;
-import org.apache.ignite.internal.util.direct.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.lang.*;
+import org.apache.ignite.plugin.extensions.communication.*;
import org.jetbrains.annotations.*;
import java.nio.*;
@@ -32,7 +32,7 @@
/**
* Event storage message.
*/
-public class GridEventStorageMessage extends GridTcpCommunicationMessageAdapter {
+public class GridEventStorageMessage extends MessageAdapter {
/** */
private static final long serialVersionUID = 0L;
@@ -262,7 +262,7 @@ void exceptionBytes(byte[] exBytes) {
/** {@inheritDoc} */
@SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
- @Override public GridTcpCommunicationMessageAdapter clone() {
+ @Override public MessageAdapter clone() {
GridEventStorageMessage _clone = new GridEventStorageMessage();
clone0(_clone);
@@ -271,7 +271,7 @@ void exceptionBytes(byte[] exBytes) {
}
/** {@inheritDoc} */
- @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) {
+ @Override protected void clone0(MessageAdapter _msg) {
GridEventStorageMessage _clone = (GridEventStorageMessage)_msg;
_clone.resTopic = resTopic;
@@ -291,101 +291,69 @@ void exceptionBytes(byte[] exBytes) {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean writeTo(ByteBuffer buf) {
- commState.setBuffer(buf);
+ writer.setBuffer(buf);
- if (!commState.typeWritten) {
- if (!commState.putByte(directType()))
+ if (!typeWritten) {
+ if (!writer.writeByte(null, directType()))
return false;
- commState.typeWritten = true;
+ typeWritten = true;
}
- switch (commState.idx) {
+ switch (state) {
case 0:
- if (!commState.putGridUuid(clsLdrId))
+ if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
return false;
- commState.idx++;
+ state++;
case 1:
- if (!commState.putEnum(depMode))
+ if (!writer.writeEnum("depMode", depMode))
return false;
- commState.idx++;
+ state++;
case 2:
- if (!commState.putByteArray(evtsBytes))
+ if (!writer.writeByteArray("evtsBytes", evtsBytes))
return false;
- commState.idx++;
+ state++;
case 3:
- if (!commState.putByteArray(exBytes))
+ if (!writer.writeByteArray("exBytes", exBytes))
return false;
- commState.idx++;
+ state++;
case 4:
- if (!commState.putByteArray(filter))
+ if (!writer.writeByteArray("filter", filter))
return false;
- commState.idx++;
+ state++;
case 5:
- if (!commState.putString(filterClsName))
+ if (!writer.writeString("filterClsName", filterClsName))
return false;
- commState.idx++;
+ state++;
case 6:
- if (ldrParties != null) {
- if (commState.it == null) {
- if (!commState.putInt(ldrParties.size()))
- return false;
-
- commState.it = ldrParties.entrySet().iterator();
- }
-
- while (commState.it.hasNext() || commState.cur != NULL) {
- if (commState.cur == NULL)
- commState.cur = commState.it.next();
-
- Map.Entry e = (Map.Entry)commState.cur;
-
- if (!commState.keyDone) {
- if (!commState.putUuid(e.getKey()))
- return false;
-
- commState.keyDone = true;
- }
-
- if (!commState.putGridUuid(e.getValue()))
- return false;
-
- commState.keyDone = false;
-
- commState.cur = NULL;
- }
-
- commState.it = null;
- } else {
- if (!commState.putInt(-1))
- return false;
- }
+ if (!writer.writeMap("ldrParties", ldrParties, UUID.class, IgniteUuid.class))
+ return false;
- commState.idx++;
+ state++;
case 7:
- if (!commState.putByteArray(resTopicBytes))
+ if (!writer.writeByteArray("resTopicBytes", resTopicBytes))
return false;
- commState.idx++;
+ state++;
case 8:
- if (!commState.putString(userVer))
+ if (!writer.writeString("userVer", userVer))
return false;
- commState.idx++;
+ state++;
}
@@ -395,130 +363,80 @@ void exceptionBytes(byte[] exBytes) {
/** {@inheritDoc} */
@SuppressWarnings("all")
@Override public boolean readFrom(ByteBuffer buf) {
- commState.setBuffer(buf);
+ reader.setBuffer(buf);
- switch (commState.idx) {
+ switch (state) {
case 0:
- IgniteUuid clsLdrId0 = commState.getGridUuid();
+ clsLdrId = reader.readIgniteUuid("clsLdrId");
- if (clsLdrId0 == GRID_UUID_NOT_READ)
+ if (!reader.isLastRead())
return false;
- clsLdrId = clsLdrId0;
-
- commState.idx++;
+ state++;
case 1:
- if (buf.remaining() < 1)
- return false;
+ depMode = reader.readEnum("depMode", DeploymentMode.class);
- byte depMode0 = commState.getByte();
-
- depMode = DeploymentMode.fromOrdinal(depMode0);
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 2:
- byte[] evtsBytes0 = commState.getByteArray();
+ evtsBytes = reader.readByteArray("evtsBytes");
- if (evtsBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- evtsBytes = evtsBytes0;
-
- commState.idx++;
+ state++;
case 3:
- byte[] exBytes0 = commState.getByteArray();
+ exBytes = reader.readByteArray("exBytes");
- if (exBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- exBytes = exBytes0;
-
- commState.idx++;
+ state++;
case 4:
- byte[] filter0 = commState.getByteArray();
+ filter = reader.readByteArray("filter");
- if (filter0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- filter = filter0;
-
- commState.idx++;
+ state++;
case 5:
- String filterClsName0 = commState.getString();
+ filterClsName = reader.readString("filterClsName");
- if (filterClsName0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- filterClsName = filterClsName0;
-
- commState.idx++;
+ state++;
case 6:
- if (commState.readSize == -1) {
- if (buf.remaining() < 4)
- return false;
-
- commState.readSize = commState.getInt();
- }
-
- if (commState.readSize >= 0) {
- if (ldrParties == null)
- ldrParties = U.newHashMap(commState.readSize);
-
- for (int i = commState.readItems; i < commState.readSize; i++) {
- if (!commState.keyDone) {
- UUID _val = commState.getUuid();
-
- if (_val == UUID_NOT_READ)
- return false;
-
- commState.cur = _val;
- commState.keyDone = true;
- }
-
- IgniteUuid _val = commState.getGridUuid();
+ ldrParties = reader.readMap("ldrParties", UUID.class, IgniteUuid.class, false);
- if (_val == GRID_UUID_NOT_READ)
- return false;
-
- ldrParties.put((UUID)commState.cur, _val);
-
- commState.keyDone = false;
-
- commState.readItems++;
- }
- }
-
- commState.readSize = -1;
- commState.readItems = 0;
- commState.cur = null;
+ if (!reader.isLastRead())
+ return false;
- commState.idx++;
+ state++;
case 7:
- byte[] resTopicBytes0 = commState.getByteArray();
+ resTopicBytes = reader.readByteArray("resTopicBytes");
- if (resTopicBytes0 == BYTE_ARR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- resTopicBytes = resTopicBytes0;
-
- commState.idx++;
+ state++;
case 8:
- String userVer0 = commState.getString();
+ userVer = reader.readString("userVer");
- if (userVer0 == STR_NOT_READ)
+ if (!reader.isLastRead())
return false;
- userVer = userVer0;
-
- commState.idx++;
+ state++;
}
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 f00b33fd0bcbf..ef999d76ab4a6 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
@@ -321,6 +321,23 @@ public long swapKeys(@Nullable String spaceName) throws IgniteCheckedException {
}
}
+ /**
+ * Gets number of swap entries for given partitions.
+ *
+ * @param spaceName Space name.
+ * @param parts Partitions.
+ * @return Number of swap entries for given partitions.
+ * @throws IgniteCheckedException If failed.
+ */
+ public long swapKeys(@Nullable String spaceName, Set parts) throws IgniteCheckedException {
+ try {
+ return getSpi().count(spaceName, parts);
+ }
+ catch (IgniteSpiException e) {
+ throw new IgniteCheckedException("Failed to get swap keys count for space: " + spaceName, e);
+ }
+ }
+
/**
* @param spaceName Space name.
* @throws IgniteCheckedException If failed.
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 ff44528819921..a5261e03ace69 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
@@ -27,7 +27,6 @@
import org.apache.ignite.internal.util.future.*;
import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.portables.*;
import org.jdk8.backport.*;
import org.jetbrains.annotations.*;
@@ -277,7 +276,7 @@ public int partition(Object key) {
try {
key = ctx.marshalToPortable(key);
}
- catch (PortableException e) {
+ catch (IgniteException e) {
U.error(log, "Failed to marshal key to portable: " + key, e);
}
}
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 5ee9826714eda..cf268fd0b76f9 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
@@ -397,7 +397,7 @@ private AffinityInfo affinityInfoFromNode(@Nullable String cacheName, long topVe
f.reset();
m.reset();
- Boolean portableEnabled = U.portableEnabled(n, cacheName);
+ Boolean portableEnabled = ctx.portable().portableEnabled(n, cacheName);
return new AffinityInfo(f, m, t.get3(), portableEnabled != null && portableEnabled);
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryImpl0.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryImpl0.java
new file mode 100644
index 0000000000000..05c30c35edd92
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryImpl0.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.processors.cache;
+
+import javax.cache.*;
+import java.util.*;
+
+/**
+ *
+ */
+public class CacheEntryImpl0 implements Cache.Entry {
+ /** */
+ private final Map.Entry e;
+
+ /**
+ * @param e Entry.
+ */
+ public CacheEntryImpl0(Map.Entry e) {
+ this.e = e;
+ }
+
+ /** {@inheritDoc} */
+ @Override public K getKey() {
+ return e.getKey();
+ }
+
+ /** {@inheritDoc} */
+ @Override public V getValue() {
+ return e.getValue();
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override public T unwrap(Class cls) {
+ if (!cls.equals(getClass()))
+ throw new IllegalArgumentException("Unwrapping to class is not supported: " + cls);
+
+ return (T)this;
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return "CacheEntry [key=" + getKey() + ", val=" + getValue() + ']';
+ }
+}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheWeakQueryIteratorsHolder.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheWeakQueryIteratorsHolder.java
index 245528c3010d0..0dbe9179239be 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheWeakQueryIteratorsHolder.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheWeakQueryIteratorsHolder.java
@@ -126,7 +126,8 @@ public class WeakQueryFutureIterator extends GridCloseableIteratorAdapter
/** Weak reference. */
private final WeakReference> weakRef;
- CacheIteratorConverter convert;
+ /** */
+ private final CacheIteratorConverter convert;
/** Init flag. */
private boolean init;
@@ -139,6 +140,7 @@ public class WeakQueryFutureIterator extends GridCloseableIteratorAdapter
/**
* @param fut GridCacheQueryFuture to iterate.
+ * @param convert Converter.
*/
WeakQueryFutureIterator(CacheQueryFuture fut, CacheIteratorConverter convert) {
this.fut = fut;
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 a4e01fa91a8e5..b10e4ceeea1b7 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
@@ -45,7 +45,6 @@
import org.apache.ignite.lang.*;
import org.apache.ignite.mxbean.*;
import org.apache.ignite.plugin.security.*;
-import org.apache.ignite.portables.*;
import org.apache.ignite.resources.*;
import org.apache.ignite.transactions.*;
import org.jdk8.backport.*;
@@ -82,6 +81,12 @@ public abstract class GridCacheAdapter implements GridCache,
/** clearLocally() split threshold. */
public static final int CLEAR_ALL_SPLIT_THRESHOLD = 10000;
+ /** Distribution modes to include into global size calculation. */
+ private static final Set SIZE_NODES = EnumSet.of(
+ CacheDistributionMode.NEAR_PARTITIONED,
+ CacheDistributionMode.PARTITIONED_ONLY,
+ CacheDistributionMode.NEAR_ONLY);
+
/** Deserialization stash. */
private static final ThreadLocal> stash = new ThreadLocal>() {
@@ -458,10 +463,6 @@ public GridCacheProjectionImpl keepPortable0() {
Class super K1> keyType,
Class super V1> valType
) {
- if (PortableObject.class.isAssignableFrom(keyType) || PortableObject.class.isAssignableFrom(valType))
- throw new IllegalStateException("Failed to create cache projection for portable objects. " +
- "Use keepPortable() method instead.");
-
if (ctx.deploymentEnabled()) {
try {
ctx.deploy().registerClasses(keyType, valType);
@@ -655,102 +656,70 @@ public IgniteInternalFuture containsKeyAsync(K key, @Nullable IgnitePre
}
/** {@inheritDoc} */
- @SuppressWarnings("ForLoopReplaceableByForEach")
- @Nullable @Override public V localPeek(K key, CachePeekMode[] peekModes) throws IgniteCheckedException {
- A.notNull(key, "key");
-
+ @Override public Iterable> localEntries(CachePeekMode[] peekModes) throws IgniteCheckedException {
assert peekModes != null;
- if (keyCheck)
- validateCacheKey(key);
-
ctx.checkSecurity(GridSecurityPermission.CACHE_READ);
- boolean near = false;
- boolean primary = false;
- boolean backup = false;
+ PeekModes modes = parsePeekModes(peekModes);
- boolean heap = false;
- boolean offheap = false;
- boolean swap = false;
+ List>> its = new ArrayList<>();
- if (peekModes.length == 0) {
- near = true;
- primary = true;
- backup = true;
+ if (ctx.isLocal()) {
+ modes.primary = true;
+ modes.backup = true;
- heap = true;
- offheap = true;
- swap = true;
+ if (modes.heap)
+ its.add(iterator(map.entries0().iterator(), !ctx.keepPortable()));
}
- else {
- for (int i = 0; i < peekModes.length; i++) {
- CachePeekMode peekMode = peekModes[i];
-
- A.notNull(peekMode, "peekMode");
+ else if (modes.heap) {
+ if (modes.near && ctx.isNear())
+ its.add(ctx.near().nearEntriesIterator());
- switch (peekMode) {
- case ALL:
- near = true;
- primary = true;
- backup = true;
-
- heap = true;
- offheap = true;
- swap = true;
-
- break;
+ if (modes.primary || modes.backup) {
+ GridDhtCacheAdapter cache = ctx.isNear() ? ctx.near().dht() : ctx.dht();
- case BACKUP:
- backup = true;
-
- break;
-
- case PRIMARY:
- primary = true;
-
- break;
-
- case NEAR:
- near = true;
-
- break;
+ its.add(cache.localEntriesIterator(modes.primary, modes.backup));
+ }
+ }
- case ONHEAP:
- heap = true;
+ // Swap and offheap are disabled for near cache.
+ if (modes.primary || modes.backup) {
+ long topVer = ctx.affinity().affinityTopologyVersion();
- break;
+ GridCacheSwapManager swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap();
- case OFFHEAP:
- offheap = true;
+ if (modes.swap)
+ its.add(swapMgr.swapIterator(modes.primary, modes.backup, topVer));
- break;
+ if (modes.offheap)
+ its.add(swapMgr.offheapIterator(modes.primary, modes.backup, topVer));
+ }
- case SWAP:
- swap = true;
+ final Iterator> it = F.flatIterators(its);
- break;
+ return new Iterable>() {
+ @Override public Iterator> iterator() {
+ return it;
+ }
- default:
- assert false : peekMode;
- }
+ public String toString() {
+ return "CacheLocalEntries []";
}
- }
+ };
+ }
- if (!(heap || offheap || swap)) {
- heap = true;
- offheap = true;
- swap = true;
- }
+ /** {@inheritDoc} */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ @Nullable @Override public V localPeek(K key, CachePeekMode[] peekModes) throws IgniteCheckedException {
+ A.notNull(key, "key");
- if (!(primary || backup || near)) {
- primary = true;
- backup = true;
- near = true;
- }
+ if (keyCheck)
+ validateCacheKey(key);
- assert heap || offheap || swap;
- assert primary || backup || near;
+ ctx.checkSecurity(GridSecurityPermission.CACHE_READ);
+
+ PeekModes modes = parsePeekModes(peekModes);
try {
if (ctx.portableEnabled())
@@ -765,11 +734,11 @@ public IgniteInternalFuture containsKeyAsync(K key, @Nullable IgnitePre
boolean nearKey;
- if (!(near && primary && backup)) {
+ if (!(modes.near && modes.primary && modes.backup)) {
boolean keyPrimary = ctx.affinity().primary(ctx.localNode(), part, topVer);
if (keyPrimary) {
- if (!primary)
+ if (!modes.primary)
return null;
nearKey = false;
@@ -778,20 +747,20 @@ public IgniteInternalFuture containsKeyAsync(K key, @Nullable IgnitePre
boolean keyBackup = ctx.affinity().belongs(ctx.localNode(), part, topVer);
if (keyBackup) {
- if (!backup)
+ if (!modes.backup)
return null;
nearKey = false;
}
else {
- if (!near)
+ if (!modes.near)
return null;
nearKey = true;
// Swap and offheap are disabled for near cache.
- offheap = false;
- swap = false;
+ modes.offheap = false;
+ modes.swap = false;
}
}
}
@@ -800,36 +769,36 @@ public IgniteInternalFuture containsKeyAsync(K key, @Nullable IgnitePre
if (nearKey) {
// Swap and offheap are disabled for near cache.
- offheap = false;
- swap = false;
+ modes.offheap = false;
+ modes.swap = false;
}
}
if (nearKey && !ctx.isNear())
return null;
- if (heap) {
+ if (modes.heap) {
GridCacheEntryEx e = nearKey ? peekEx(key) :
(ctx.isNear() ? ctx.near().dht().peekEx(key) : peekEx(key));
if (e != null) {
- val = e.peek(heap, offheap, swap, topVer);
+ val = e.peek(modes.heap, modes.offheap, modes.swap, topVer);
- offheap = false;
- swap = false;
+ modes.offheap = false;
+ modes.swap = false;
}
}
- if (offheap || swap) {
+ if (modes.offheap || modes.swap) {
GridCacheSwapManager swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap();
- GridCacheSwapEntry swapEntry = swapMgr.read(key, offheap, swap);
+ GridCacheSwapEntry swapEntry = swapMgr.read(key, modes.offheap, modes.swap);
val = swapEntry != null ? swapEntry.value() : null;
}
}
else
- val = localCachePeek0(key, heap, offheap, swap);
+ val = localCachePeek0(key, modes.heap, modes.offheap, modes.swap);
if (ctx.portableEnabled())
val = (V)ctx.unwrapPortableIfNeeded(val, ctx.keepPortable());
@@ -1526,6 +1495,32 @@ private boolean clearLocally(GridCacheVersion obsoleteVer, K key,
}
}
+ /** {@inheritDoc} */
+ @Override public IgniteInternalFuture> clearAsync() {
+ Collection nodes = ctx.grid().forCacheNodes(name()).nodes();
+
+ if (!nodes.isEmpty()) {
+ IgniteInternalFuture fut =
+ ctx.closures().callAsyncNoFailover(BROADCAST, new GlobalClearAllCallable(name()), nodes, true);
+
+ return fut.chain(new CX1, Object>() {
+ @Override public Object applyx(IgniteInternalFuture fut) throws IgniteCheckedException {
+ try {
+ return fut.get();
+ }
+ catch (ClusterGroupEmptyCheckedException ignore) {
+ if (log.isDebugEnabled())
+ log.debug("All remote nodes left while cache clearLocally [cacheName=" + name() + "]");
+
+ return null;
+ }
+ }
+ });
+ }
+ else
+ return new GridFinishedFuture<>(ctx.kernalContext());
+ }
+
/** {@inheritDoc} */
@Override public boolean compact(K key) throws IgniteCheckedException {
return compact(key, (IgnitePredicate>[])null);
@@ -1557,7 +1552,7 @@ private boolean evictx(K key, GridCacheVersion ver,
try {
key = (K)ctx.marshalToPortable(key);
}
- catch (PortableException e) {
+ catch (IgniteException e) {
throw new IgniteException(e);
}
}
@@ -3568,7 +3563,7 @@ public String toString() {
try {
key0 = (K)ctx.marshalToPortable(key);
}
- catch (PortableException e) {
+ catch (IgniteException e) {
return new GridFinishedFuture<>(ctx.kernalContext(), e);
}
}
@@ -3851,7 +3846,7 @@ protected void checkJta() throws IgniteCheckedException {
ctx.store().loadCache(new CIX3() {
@Override public void applyx(K key, V val, @Nullable GridCacheVersion ver)
- throws PortableException {
+ throws IgniteException {
assert ver == null;
loadEntry(key, val, ver0, p, topVer, replicate, ttl);
@@ -4065,6 +4060,99 @@ IgniteInternalFuture> globalLoadCacheAsync(@Nullable IgniteBiPredicate p
return e == null || e.obsolete() ? null : e.wrap();
}
+ /** {@inheritDoc} */
+ @Override public int size(CachePeekMode[] peekModes) throws IgniteCheckedException {
+ if (isLocal())
+ return localSize(peekModes);
+
+ return sizeAsync(peekModes).get();
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgniteInternalFuture sizeAsync(CachePeekMode[] peekModes) {
+ assert peekModes != null;
+
+ PeekModes modes = parsePeekModes(peekModes);
+
+ ClusterGroup grp;
+
+ if (modes.near)
+ grp = ctx.grid().forCacheNodes(name(), SIZE_NODES);
+ else
+ grp = ctx.grid().forDataNodes(name());
+
+ Collection nodes = grp.nodes();
+
+ if (nodes.isEmpty())
+ return new GridFinishedFuture<>(ctx.kernalContext(), 0);
+
+ IgniteInternalFuture> fut =
+ ctx.closures().broadcastNoFailover(new SizeCallable(ctx.name(), peekModes), null, nodes);
+
+ return fut.chain(new CX1>, Integer>() {
+ @Override public Integer applyx(IgniteInternalFuture> fut)
+ throws IgniteCheckedException {
+ Collection res = fut.get();
+
+ int totalSize = 0;
+
+ for (Integer size : res)
+ totalSize += size;
+
+ return totalSize;
+ }
+ });
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ @Override public int localSize(CachePeekMode[] peekModes) throws IgniteCheckedException {
+ PeekModes modes = parsePeekModes(peekModes);
+
+ int size = 0;
+
+ if (ctx.isLocal()) {
+ modes.primary = true;
+ modes.backup = true;
+
+ if (modes.heap)
+ size += size();
+ }
+ else {
+ if (modes.heap) {
+ if (modes.near)
+ size += nearSize();
+
+ GridCacheAdapter cache = ctx.isNear() ? ctx.near().dht() : ctx.cache();
+
+ if (!(modes.primary && modes.backup)) {
+ if (modes.primary)
+ size += cache.primarySize();
+
+ if (modes.backup)
+ size += (cache.size() - cache.primarySize());
+ }
+ else
+ size += cache.size();
+ }
+ }
+
+ // Swap and offheap are disabled for near cache.
+ if (modes.primary || modes.backup) {
+ long topVer = ctx.affinity().affinityTopologyVersion();
+
+ GridCacheSwapManager swapMgr = ctx.isNear() ? ctx.near().dht().context().swap() : ctx.swap();
+
+ if (modes.swap)
+ size += swapMgr.swapEntriesCount(modes.primary, modes.backup, topVer);
+
+ if (modes.offheap)
+ size += swapMgr.offheapEntriesCount(modes.primary, modes.backup, topVer);
+ }
+
+ return size;
+ }
+
/** {@inheritDoc} */
@Override public int size() {
return map.publicSize();
@@ -4782,14 +4870,8 @@ public boolean containsKey(K key, @Nullable IgnitePredicate> f
if (keyCheck)
validateCacheKey(key);
- if (ctx.portableEnabled()) {
- try {
- key = (K)ctx.marshalToPortable(key);
- }
- catch (PortableException e) {
- throw new IgniteException(e);
- }
- }
+ if (ctx.portableEnabled())
+ key = (K)ctx.marshalToPortable(key);
GridCacheEntryEx e = peekEx(key);
@@ -5249,6 +5331,232 @@ protected void validateCacheKeys(Iterable> keys) {
}
}
+ /**
+ * @param it Internal entry iterator.
+ * @param deserializePortable Deserialize portable flag.
+ * @return Public API iterator.
+ */
+ protected Iterator> iterator(final Iterator> it,
+ final boolean deserializePortable) {
+ return new Iterator>() {
+ {
+ advance();
+ }
+
+ /** */
+ private Cache.Entry next;
+
+ @Override public boolean hasNext() {
+ return next != null;
+ }
+
+ @Override public Cache.Entry next() {
+ if (next == null)
+ throw new NoSuchElementException();
+
+ Cache.Entry e = next;
+
+ advance();
+
+ return e;
+ }
+
+ @Override public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Switch to next entry.
+ */
+ private void advance() {
+ next = null;
+
+ while (it.hasNext()) {
+ GridCacheEntryEx entry = it.next();
+
+ try {
+ next = toCacheEntry(entry, deserializePortable);
+
+ if (next == null)
+ continue;
+
+ break;
+ }
+ catch (IgniteCheckedException e) {
+ throw U.convertToCacheException(e);
+ }
+ catch (GridCacheEntryRemovedException ignore) {
+ // No-op.
+ }
+ }
+ }
+ };
+ }
+
+ /**
+ * @param entry Internal entry.
+ * @param deserializePortable Deserialize portable flag.
+ * @return Public API entry.
+ * @throws IgniteCheckedException If failed.
+ * @throws GridCacheEntryRemovedException If entry removed.
+ */
+ @Nullable private Cache.Entry toCacheEntry(GridCacheEntryEx entry,
+ boolean deserializePortable)
+ throws IgniteCheckedException, GridCacheEntryRemovedException
+ {
+ try {
+ V val = entry.innerGet(
+ null,
+ false,
+ false,
+ false,
+ true,
+ false,
+ false,
+ false,
+ null,
+ null,
+ null,
+ null,
+ null);
+
+ if (val == null)
+ return null;
+
+ K key = entry.key();
+
+ if (deserializePortable && ctx.portableEnabled()) {
+ key = (K)ctx.unwrapPortableIfNeeded(key, true);
+ val = (V)ctx.unwrapPortableIfNeeded(val, true);
+ }
+
+ return new CacheEntryImpl<>(key, val);
+ }
+ catch (GridCacheFilterFailedException ignore) {
+ assert false;
+
+ return null;
+ }
+ }
+
+ /**
+ *
+ */
+ private static class PeekModes {
+ /** */
+ boolean near;
+
+ /** */
+ boolean primary;
+
+ /** */
+ boolean backup;
+
+ /** */
+ boolean heap;
+
+ /** */
+ boolean offheap;
+
+ /** */
+ boolean swap;
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(PeekModes.class, this);
+ }
+ }
+
+ /**
+ * @param peekModes Cache peek modes array.
+ * @return Peek modes flags.
+ */
+ private static PeekModes parsePeekModes(CachePeekMode[] peekModes) {
+ assert peekModes != null;
+
+ PeekModes modes = new PeekModes();
+
+ if (peekModes.length == 0) {
+ modes.near = true;
+ modes.primary = true;
+ modes.backup = true;
+
+ modes.heap = true;
+ modes.offheap = true;
+ modes.swap = true;
+ }
+ else {
+ for (int i = 0; i < peekModes.length; i++) {
+ CachePeekMode peekMode = peekModes[i];
+
+ A.notNull(peekMode, "peekMode");
+
+ switch (peekMode) {
+ case ALL:
+ modes.near = true;
+ modes.primary = true;
+ modes.backup = true;
+
+ modes.heap = true;
+ modes.offheap = true;
+ modes.swap = true;
+
+ break;
+
+ case BACKUP:
+ modes.backup = true;
+
+ break;
+
+ case PRIMARY:
+ modes.primary = true;
+
+ break;
+
+ case NEAR:
+ modes.near = true;
+
+ break;
+
+ case ONHEAP:
+ modes.heap = true;
+
+ break;
+
+ case OFFHEAP:
+ modes.offheap = true;
+
+ break;
+
+ case SWAP:
+ modes.swap = true;
+
+ break;
+
+ default:
+ assert false : peekMode;
+ }
+ }
+ }
+
+ if (!(modes.heap || modes.offheap || modes.swap)) {
+ modes.heap = true;
+ modes.offheap = true;
+ modes.swap = true;
+ }
+
+ if (!(modes.primary || modes.backup || modes.near)) {
+ modes.primary = true;
+ modes.backup = true;
+ modes.near = true;
+ }
+
+ assert modes.heap || modes.offheap || modes.swap;
+ assert modes.primary || modes.backup || modes.near;
+
+ return modes;
+ }
+
/**
* @param plc Explicitly specified expiry policy for cache operation.
* @return Expiry policy wrapper.
@@ -5443,7 +5751,79 @@ private GlobalClearAllCallable(String cacheName) {
}
/**
- * Internal callable which performs {@link org.apache.ignite.cache.CacheProjection#size()} or {@link org.apache.ignite.cache.CacheProjection#primarySize()}
+ * Internal callable for global size calculation.
+ */
+ @GridInternal
+ private static class SizeCallable extends IgniteClosureX implements Externalizable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Cache name. */
+ private String cacheName;
+
+ /** Peek modes. */
+ private CachePeekMode[] peekModes;
+
+ /** Injected grid instance. */
+ @IgniteInstanceResource
+ private Ignite ignite;
+
+ /**
+ * Required by {@link Externalizable}.
+ */
+ public SizeCallable() {
+ // No-op.
+ }
+
+ /**
+ * @param cacheName Cache name.
+ * @param peekModes Cache peek modes.
+ */
+ private SizeCallable(String cacheName, CachePeekMode[] peekModes) {
+ this.cacheName = cacheName;
+ this.peekModes = peekModes;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Integer applyx(Object o) throws IgniteCheckedException {
+ GridCache cache = ((IgniteEx)ignite).cachex(cacheName);
+
+ assert cache != null : cacheName;
+
+ return cache.localSize(peekModes);
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("ForLoopReplaceableByForEach")
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ U.writeString(out, cacheName);
+
+ out.writeInt(peekModes.length);
+
+ for (int i = 0; i < peekModes.length; i++)
+ U.writeEnum(out, peekModes[i]);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ cacheName = U.readString(in);
+
+ int len = in.readInt();
+
+ peekModes = new CachePeekMode[len];
+
+ for (int i = 0; i < len; i++)
+ peekModes[i] = CachePeekMode.fromOrdinal(in.readByte());
+ }
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return S.toString(SizeCallable.class, this);
+ }
+ }
+
+ /**
+ * Internal callable which performs {@link CacheProjection#size()} or {@link CacheProjection#primarySize()}
* operation on a cache with the given name.
*/
@GridInternal
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
index 999ad66df80ba..b0cfb6b0db212 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAttributes.java
@@ -157,9 +157,6 @@ public class GridCacheAttributes implements Externalizable {
/** Store load previous value flag. */
private boolean loadPrevVal;
- /** Portable enabled flag. */
- private boolean portableEnabled;
-
/**
* @param cfg Cache configuration.
* @param store Cache store.
@@ -176,7 +173,6 @@ public GridCacheAttributes(CacheConfiguration cfg, @Nullable CacheStore, ?> st
loadPrevVal = cfg.isLoadPreviousValue();
name = cfg.getName();
partDistro = GridCacheUtils.distributionMode(cfg);
- portableEnabled = cfg.isPortableEnabled();
preloadBatchSize = cfg.getPreloadBatchSize();
preloadMode = cfg.getPreloadMode();
qryIdxEnabled = cfg.isQueryIndexEnabled();
@@ -521,13 +517,6 @@ public String indexingSpiName() {
return indexingSpiName;
}
- /**
- * @return Portable enabled flag.
- */
- public boolean portableEnabled() {
- return portableEnabled;
- }
-
/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
U.writeEnum(out, atomicityMode);
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 e8192b985ec96..492b90d2d65d3 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
@@ -37,6 +37,7 @@
import org.apache.ignite.internal.processors.cache.local.*;
import org.apache.ignite.internal.processors.cache.query.*;
import org.apache.ignite.internal.processors.cache.query.continuous.*;
+import org.apache.ignite.internal.processors.cache.serialization.*;
import org.apache.ignite.internal.processors.cache.transactions.*;
import org.apache.ignite.internal.processors.cache.version.*;
import org.apache.ignite.internal.processors.closure.*;
@@ -52,7 +53,6 @@
import org.apache.ignite.lang.*;
import org.apache.ignite.marshaller.*;
import org.apache.ignite.plugin.security.*;
-import org.apache.ignite.portables.*;
import org.jetbrains.annotations.*;
import javax.cache.*;
@@ -131,6 +131,9 @@ public class GridCacheContext implements Externalizable {
/** Replication manager. */
private GridCacheDrManager drMgr;
+ /** Serialization manager. */
+ private IgniteCacheSerializationManager serMgr;
+
/** JTA manager. */
private CacheJtaManagerAdapter jtaMgr;
@@ -238,6 +241,7 @@ public GridCacheContext(
CacheDataStructuresManager dataStructuresMgr,
GridCacheTtlManager ttlMgr,
GridCacheDrManager drMgr,
+ IgniteCacheSerializationManager serMgr,
CacheJtaManagerAdapter jtaMgr) {
assert ctx != null;
assert sharedCtx != null;
@@ -271,6 +275,7 @@ public GridCacheContext(
this.dataStructuresMgr = add(dataStructuresMgr);
this.ttlMgr = add(ttlMgr);
this.drMgr = add(drMgr);
+ this.serMgr = add(serMgr);
this.jtaMgr = add(jtaMgr);
log = ctx.log(getClass());
@@ -1578,11 +1583,11 @@ public boolean conflictNeedResolve(GridCacheVersion oldVer, GridCacheVersion new
* @return Conflict resolution result.
* @throws IgniteCheckedException In case of exception.
*/
- public GridCacheVersionConflictContextImpl conflictResolve(GridCacheVersionedEntryEx oldEntry,
+ public GridCacheVersionConflictContext conflictResolve(GridCacheVersionedEntryEx oldEntry,
GridCacheVersionedEntryEx newEntry, boolean atomicVerComparator) throws IgniteCheckedException {
assert conflictRslvr != null : "Should not reach this place.";
- GridCacheVersionConflictContextImpl ctx = conflictRslvr.resolve(oldEntry, newEntry, atomicVerComparator);
+ GridCacheVersionConflictContext ctx = conflictRslvr.resolve(oldEntry, newEntry, atomicVerComparator);
if (ctx.isManualResolve())
drMgr.onReceiveCacheConflictResolved(ctx.isUseNew(), ctx.isUseOld(), ctx.isMerge());
@@ -1611,7 +1616,7 @@ public void onDeferredDelete(GridCacheEntryEx entry, GridCacheVersion ver)
}
/**
- * @param interceptorRes Result of {@link org.apache.ignite.cache.CacheInterceptor#onBeforeRemove} callback.
+ * @param interceptorRes Result of {@link CacheInterceptor#onBeforeRemove} callback.
* @return {@code True} if interceptor cancels remove.
*/
public boolean cancelRemove(@Nullable IgniteBiTuple interceptorRes) {
@@ -1643,7 +1648,14 @@ public GridPortableProcessor portable() {
* @return Portable enabled flag.
*/
public boolean portableEnabled() {
- return cacheCfg.isPortableEnabled();
+ return serMgr.portableEnabled();
+ }
+
+ /**
+ * @return Keep portable in store flag.
+ */
+ public boolean keepPortableInStore() {
+ return serMgr.keepPortableInStore();
}
/**
@@ -1689,15 +1701,15 @@ public byte[] convertPortableBytes(byte[] bytes) throws IgniteCheckedException {
/**
* @param obj Object.
* @return Portable object.
- * @throws PortableException In case of error.
+ * @throws IgniteException In case of error.
*/
- @Nullable public Object marshalToPortable(@Nullable Object obj) throws PortableException {
+ @Nullable public Object marshalToPortable(@Nullable Object obj) throws IgniteException {
assert portableEnabled();
if (obj == null)
return null;
- if (obj instanceof PortableObject || obj instanceof GridCacheInternal)
+ if (ctx.portable().isPortableObject(obj) || obj instanceof GridCacheInternal)
return obj;
GridPortableProcessor proc = kernalContext().portable();
@@ -1715,58 +1727,7 @@ public byte[] convertPortableBytes(byte[] bytes) throws IgniteCheckedException {
* @return Unwrapped collection.
*/
public Collection unwrapPortablesIfNeeded(Collection col, boolean keepPortable) {
- if (keepPortable || !config().isPortableEnabled())
- return col;
-
- if (col instanceof ArrayList)
- return unwrapPortables((ArrayList)col);
-
- Collection