http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java deleted file mode 100644 index ce7063a..0000000 --- a/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portable; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.TreeMap; -import org.apache.ignite.IgnitePortables; -import org.apache.ignite.cache.IgniteObject; -import org.apache.ignite.marshaller.portable.PortableMarshaller; -import org.jetbrains.annotations.Nullable; - -/** - * Wrapper for portable object in portable binary format. Once an object is defined as portable, - * Ignite will always store it in memory in the portable (i.e. binary) format. - * User can choose to work either with the portable format or with the deserialized form - * (assuming that class definitions are present in the classpath). - * <p> - * <b>NOTE:</b> user does not need to (and should not) implement this interface directly. - * <p> - * To work with the portable format directly, user should create a cache projection - * over {@code PortableObject} class and then retrieve individual fields as needed: - * <pre name=code class=java> - * IgniteCache<PortableObject, PortableObject> prj = cache.withKeepPortable(); - * - * // Convert instance of MyKey to portable format. - * // We could also use GridPortableBuilder to create the key in portable format directly. - * PortableObject key = grid.portables().toPortable(new MyKey()); - * - * PortableObject val = prj.get(key); - * - * String field = val.field("myFieldName"); - * </pre> - * Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized - * typed objects at all times. In this case we do incur the deserialization cost. However, if - * {@link PortableMarshaller#isKeepDeserialized()} is {@code true} then Ignite will only deserialize on the first access - * and will cache the deserialized object, so it does not have to be deserialized again: - * <pre name=code class=java> - * IgniteCache<MyKey.class, MyValue.class> cache = grid.cache(null); - * - * MyValue val = cache.get(new MyKey()); - * - * // Normal java getter. - * String fieldVal = val.getMyFieldName(); - * </pre> - * <h1 class="header">Working With Maps and Collections</h1> - * All maps and collections in the portable objects are serialized automatically. When working - * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most - * adequate collection or map in either language. For example, {@link ArrayList} in Java will become - * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap} - * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary} - * in C#, etc. - * <h1 class="header">Dynamic Structure Changes</h1> - * Since objects are always cached in the portable binary format, server does not need to - * be aware of the class definitions. Moreover, if class definitions are not present or not - * used on the server, then clients can continuously change the structure of the portable - * objects without having to restart the cluster. For example, if one client stores a - * certain class with fields A and B, and another client stores the same class with - * fields B and C, then the server-side portable object will have the fields A, B, and C. - * As the structure of a portable object changes, the new fields become available for SQL queries - * automatically. - * <h1 class="header">Building Portable Objects</h1> - * Ignite comes with {@link PortableBuilder} which allows to build portable objects dynamically: - * <pre name=code class=java> - * PortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject"); - * - * builder.setField("fieldA", "A"); - * builder.setField("fieldB", "B"); - * - * PortableObject portableObj = builder.build(); - * </pre> - * For the cases when class definition is present - * in the class path, it is also possible to populate a standard POJO and then - * convert it to portable format, like so: - * <pre name=code class=java> - * MyObject obj = new MyObject(); - * - * obj.setFieldA("A"); - * obj.setFieldB(123); - * - * PortableObject portableObj = Ignition.ignite().portables().toPortable(obj); - * </pre> - * <h1 class="header">Portable Metadata</h1> - * Even though Ignite portable protocol only works with hash codes for type and field names - * to achieve better performance, Ignite provides metadata for all portable types which - * can be queried ar runtime via any of the {@link IgnitePortables#metadata(Class)} - * methods. Having metadata also allows for proper formatting of {@code PortableObject.toString()} method, - * even when portable objects are kept in binary format only, which may be necessary for audit reasons. - */ -public interface PortableObject extends IgniteObject, Cloneable { - /** - * Gets portable object type ID. - * - * @return Type ID. - */ - @Override public int typeId(); - - /** - * Gets meta data for this portable object. - * - * @return Meta data. - * @throws PortableException In case of error. - */ - @Nullable public PortableMetadata metaData() throws PortableException; - - /** - * Gets field value. - * - * @param fieldName Field name. - * @return Field value. - * @throws PortableException In case of any other error. - */ - @Override @Nullable public <F> F field(String fieldName) throws PortableException; - - /** - * Checks whether field is set. - * - * @param fieldName Field name. - * @return {@code true} if field is set. - */ - @Override public boolean hasField(String fieldName); - - /** - * Gets field descriptor. - * - * @param fieldName Field name. - * @return Field descriptor. - * @throws PortableException If failed. - */ - public PortableField fieldDescriptor(String fieldName) throws PortableException; - - /** - * Gets fully deserialized instance of portable object. - * - * @return Fully deserialized instance of portable object. - * @throws PortableInvalidClassException If class doesn't exist. - * @throws PortableException In case of any other error. - */ - @Override @Nullable public <T> T deserialize() throws PortableException; - - /** - * Copies this portable object. - * - * @return Copy of this portable object. - */ - public PortableObject clone() throws CloneNotSupportedException; -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java deleted file mode 100644 index 4b3dc4c..0000000 --- a/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portable; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Collection; -import java.util.Date; -import java.util.Map; -import java.util.UUID; -import org.jetbrains.annotations.Nullable; - -/** - * Raw reader for portable objects. Raw reader does not use field name hash codes, therefore, - * making the format even more compact. However, if the raw reader is used, - * dynamic structure changes to the portable objects are not supported. - */ -public interface PortableRawReader { - /** - * @return Byte value. - * @throws PortableException In case of error. - */ - public byte readByte() throws PortableException; - - /** - * @return Short value. - * @throws PortableException In case of error. - */ - public short readShort() throws PortableException; - - /** - * @return Integer value. - * @throws PortableException In case of error. - */ - public int readInt() throws PortableException; - - /** - * @return Long value. - * @throws PortableException In case of error. - */ - public long readLong() throws PortableException; - - /** - * @return Float value. - * @throws PortableException In case of error. - */ - public float readFloat() throws PortableException; - - /** - * @return Double value. - * @throws PortableException In case of error. - */ - public double readDouble() throws PortableException; - - /** - * @return Char value. - * @throws PortableException In case of error. - */ - public char readChar() throws PortableException; - - /** - * @return Boolean value. - * @throws PortableException In case of error. - */ - public boolean readBoolean() throws PortableException; - - /** - * @return Decimal value. - * @throws PortableException In case of error. - */ - @Nullable public BigDecimal readDecimal() throws PortableException; - - /** - * @return String value. - * @throws PortableException In case of error. - */ - @Nullable public String readString() throws PortableException; - - /** - * @return UUID. - * @throws PortableException In case of error. - */ - @Nullable public UUID readUuid() throws PortableException; - - /** - * @return Date. - * @throws PortableException In case of error. - */ - @Nullable public Date readDate() throws PortableException; - - /** - * @return Timestamp. - * @throws PortableException In case of error. - */ - @Nullable public Timestamp readTimestamp() throws PortableException; - - /** - * @return Object. - * @throws PortableException In case of error. - */ - @Nullable public <T> T readObject() throws PortableException; - - /** - * @return Byte array. - * @throws PortableException In case of error. - */ - @Nullable public byte[] readByteArray() throws PortableException; - - /** - * @return Short array. - * @throws PortableException In case of error. - */ - @Nullable public short[] readShortArray() throws PortableException; - - /** - * @return Integer array. - * @throws PortableException In case of error. - */ - @Nullable public int[] readIntArray() throws PortableException; - - /** - * @return Long array. - * @throws PortableException In case of error. - */ - @Nullable public long[] readLongArray() throws PortableException; - - /** - * @return Float array. - * @throws PortableException In case of error. - */ - @Nullable public float[] readFloatArray() throws PortableException; - - /** - * @return Byte array. - * @throws PortableException In case of error. - */ - @Nullable public double[] readDoubleArray() throws PortableException; - - /** - * @return Char array. - * @throws PortableException In case of error. - */ - @Nullable public char[] readCharArray() throws PortableException; - - /** - * @return Boolean array. - * @throws PortableException In case of error. - */ - @Nullable public boolean[] readBooleanArray() throws PortableException; - - /** - * @return Decimal array. - * @throws PortableException In case of error. - */ - @Nullable public BigDecimal[] readDecimalArray() throws PortableException; - - /** - * @return String array. - * @throws PortableException In case of error. - */ - @Nullable public String[] readStringArray() throws PortableException; - - /** - * @return UUID array. - * @throws PortableException In case of error. - */ - @Nullable public UUID[] readUuidArray() throws PortableException; - - /** - * @return Date array. - * @throws PortableException In case of error. - */ - @Nullable public Date[] readDateArray() throws PortableException; - - /** - * @return Timestamp array. - * @throws PortableException In case of error. - */ - @Nullable public Timestamp[] readTimestampArray() throws PortableException; - - /** - * @return Object array. - * @throws PortableException In case of error. - */ - @Nullable public Object[] readObjectArray() throws PortableException; - - /** - * @return Collection. - * @throws PortableException In case of error. - */ - @Nullable public <T> Collection<T> readCollection() throws PortableException; - - /** - * @param colCls Collection class. - * @return Collection. - * @throws PortableException In case of error. - */ - @Nullable public <T> Collection<T> readCollection(Class<? extends Collection<T>> colCls) - throws PortableException; - - /** - * @return Map. - * @throws PortableException In case of error. - */ - @Nullable public <K, V> Map<K, V> readMap() throws PortableException; - - /** - * @param mapCls Map class. - * @return Map. - * @throws PortableException In case of error. - */ - @Nullable public <K, V> Map<K, V> readMap(Class<? extends Map<K, V>> mapCls) throws PortableException; - - /** - * @return Value. - * @throws PortableException In case of error. - */ - @Nullable public <T extends Enum<?>> T readEnum() throws PortableException; - - /** - * @return Value. - * @throws PortableException In case of error. - */ - @Nullable public <T extends Enum<?>> T[] readEnumArray() throws PortableException; -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java deleted file mode 100644 index 245f755..0000000 --- a/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portable; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Collection; -import java.util.Date; -import java.util.Map; -import java.util.UUID; -import org.jetbrains.annotations.Nullable; - -/** - * Raw writer for portable object. Raw writer does not write field name hash codes, therefore, - * making the format even more compact. However, if the raw writer is used, - * dynamic structure changes to the portable objects are not supported. - */ -public interface PortableRawWriter { - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeByte(byte val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeShort(short val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeInt(int val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeLong(long val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeFloat(float val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDouble(double val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeChar(char val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeBoolean(boolean val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDecimal(@Nullable BigDecimal val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeString(@Nullable String val) throws PortableException; - - /** - * @param val UUID to write. - * @throws PortableException In case of error. - */ - public void writeUuid(@Nullable UUID val) throws PortableException; - - /** - * @param val Date to write. - * @throws PortableException In case of error. - */ - public void writeDate(@Nullable Date val) throws PortableException; - - /** - * @param val Timestamp to write. - * @throws PortableException In case of error. - */ - public void writeTimestamp(@Nullable Timestamp val) throws PortableException; - - /** - * @param obj Value to write. - * @throws PortableException In case of error. - */ - public void writeObject(@Nullable Object obj) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeByteArray(@Nullable byte[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeShortArray(@Nullable short[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeIntArray(@Nullable int[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeLongArray(@Nullable long[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeFloatArray(@Nullable float[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDoubleArray(@Nullable double[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeCharArray(@Nullable char[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeBooleanArray(@Nullable boolean[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDecimalArray(@Nullable BigDecimal[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeStringArray(@Nullable String[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeUuidArray(@Nullable UUID[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDateArray(@Nullable Date[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeTimestampArray(@Nullable Timestamp[] val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeObjectArray(@Nullable Object[] val) throws PortableException; - - /** - * @param col Collection to write. - * @throws PortableException In case of error. - */ - public <T> void writeCollection(@Nullable Collection<T> col) throws PortableException; - - /** - * @param map Map to write. - * @throws PortableException In case of error. - */ - public <K, V> void writeMap(@Nullable Map<K, V> map) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public <T extends Enum<?>> void writeEnum(T val) throws PortableException; - - /** - * @param val Value to write. - * @throws PortableException In case of error. - */ - public <T extends Enum<?>> void writeEnumArray(T[] val) throws PortableException; -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java deleted file mode 100644 index f2b1cda..0000000 --- a/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java +++ /dev/null @@ -1,291 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portable; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Collection; -import java.util.Date; -import java.util.Map; -import java.util.UUID; -import org.jetbrains.annotations.Nullable; - -/** - * Reader for portable objects used in {@link PortableMarshalAware} implementations. - * Useful for the cases when user wants a fine-grained control over serialization. - * <p> - * Note that Ignite never writes full strings for field or type names. Instead, - * for performance reasons, Ignite writes integer hash codes for type and field names. - * It has been tested that hash code conflicts for the type names or the field names - * within the same type are virtually non-existent and, to gain performance, it is safe - * to work with hash codes. For the cases when hash codes for different types or fields - * actually do collide, Ignite provides {@link PortableIdMapper} which - * allows to override the automatically generated hash code IDs for the type and field names. - */ -public interface PortableReader { - /** - * @param fieldName Field name. - * @return Byte value. - * @throws PortableException In case of error. - */ - public byte readByte(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Short value. - * @throws PortableException In case of error. - */ - public short readShort(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Integer value. - * @throws PortableException In case of error. - */ - public int readInt(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Long value. - * @throws PortableException In case of error. - */ - public long readLong(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @throws PortableException In case of error. - * @return Float value. - */ - public float readFloat(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Double value. - * @throws PortableException In case of error. - */ - public double readDouble(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Char value. - * @throws PortableException In case of error. - */ - public char readChar(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Boolean value. - * @throws PortableException In case of error. - */ - public boolean readBoolean(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Decimal value. - * @throws PortableException In case of error. - */ - @Nullable public BigDecimal readDecimal(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return String value. - * @throws PortableException In case of error. - */ - @Nullable public String readString(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return UUID. - * @throws PortableException In case of error. - */ - @Nullable public UUID readUuid(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Date. - * @throws PortableException In case of error. - */ - @Nullable public Date readDate(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Timestamp. - * @throws PortableException In case of error. - */ - @Nullable public Timestamp readTimestamp(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Object. - * @throws PortableException In case of error. - */ - @Nullable public <T> T readObject(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Byte array. - * @throws PortableException In case of error. - */ - @Nullable public byte[] readByteArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Short array. - * @throws PortableException In case of error. - */ - @Nullable public short[] readShortArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Integer array. - * @throws PortableException In case of error. - */ - @Nullable public int[] readIntArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Long array. - * @throws PortableException In case of error. - */ - @Nullable public long[] readLongArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Float array. - * @throws PortableException In case of error. - */ - @Nullable public float[] readFloatArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Byte array. - * @throws PortableException In case of error. - */ - @Nullable public double[] readDoubleArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Char array. - * @throws PortableException In case of error. - */ - @Nullable public char[] readCharArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Boolean array. - * @throws PortableException In case of error. - */ - @Nullable public boolean[] readBooleanArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Decimal array. - * @throws PortableException In case of error. - */ - @Nullable public BigDecimal[] readDecimalArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return String array. - * @throws PortableException In case of error. - */ - @Nullable public String[] readStringArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return UUID array. - * @throws PortableException In case of error. - */ - @Nullable public UUID[] readUuidArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Date array. - * @throws PortableException In case of error. - */ - @Nullable public Date[] readDateArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Timestamp array. - * @throws PortableException In case of error. - */ - @Nullable public Timestamp[] readTimestampArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Object array. - * @throws PortableException In case of error. - */ - @Nullable public Object[] readObjectArray(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Collection. - * @throws PortableException In case of error. - */ - @Nullable public <T> Collection<T> readCollection(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @param colCls Collection class. - * @return Collection. - * @throws PortableException In case of error. - */ - @Nullable public <T> Collection<T> readCollection(String fieldName, Class<? extends Collection<T>> colCls) - throws PortableException; - - /** - * @param fieldName Field name. - * @return Map. - * @throws PortableException In case of error. - */ - @Nullable public <K, V> Map<K, V> readMap(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @param mapCls Map class. - * @return Map. - * @throws PortableException In case of error. - */ - @Nullable public <K, V> Map<K, V> readMap(String fieldName, Class<? extends Map<K, V>> mapCls) - throws PortableException; - - /** - * @param fieldName Field name. - * @return Value. - * @throws PortableException In case of error. - */ - @Nullable public <T extends Enum<?>> T readEnum(String fieldName) throws PortableException; - - /** - * @param fieldName Field name. - * @return Value. - * @throws PortableException In case of error. - */ - @Nullable public <T extends Enum<?>> T[] readEnumArray(String fieldName) throws PortableException; - - /** - * Gets raw reader. Raw reader does not use field name hash codes, therefore, - * making the format even more compact. However, if the raw reader is used, - * dynamic structure changes to the portable objects are not supported. - * - * @return Raw reader. - */ - public PortableRawReader rawReader(); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java deleted file mode 100644 index 90ee562..0000000 --- a/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portable; - -import org.apache.ignite.marshaller.portable.PortableMarshaller; - -/** - * Interface that allows to implement custom serialization logic for portable objects. - * Can be used instead of {@link PortableMarshalAware} in case if the class - * cannot be changed directly. - * <p> - * Portable serializer can be configured for all portable objects via - * {@link PortableMarshaller#getSerializer()} method, or for a specific - * portable type via {@link PortableTypeConfiguration#getSerializer()} method. - */ -public interface PortableSerializer { - /** - * Writes fields to provided writer. - * - * @param obj Empty object. - * @param writer Portable object writer. - * @throws PortableException In case of error. - */ - public void writePortable(Object obj, PortableWriter writer) throws PortableException; - - /** - * Reads fields from provided reader. - * - * @param obj Empty object - * @param reader Portable object reader. - * @throws PortableException In case of error. - */ - public void readPortable(Object obj, PortableReader reader) throws PortableException; -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java deleted file mode 100644 index 68f0514..0000000 --- a/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portable; - -import java.sql.Timestamp; -import java.util.Collection; -import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.marshaller.portable.PortableMarshaller; - -/** - * Defines configuration properties for a specific portable type. Providing per-type - * configuration is optional, as it is generally enough, and also optional, to provide global portable - * configuration using {@link PortableMarshaller#setClassNames(Collection)}. - * However, this class allows you to change configuration properties for a specific - * portable type without affecting configuration for other portable types. - * <p> - * Per-type portable configuration can be specified in {@link PortableMarshaller#getTypeConfigurations()} method. - */ -public class PortableTypeConfiguration { - /** Class name. */ - private String clsName; - - /** ID mapper. */ - private PortableIdMapper idMapper; - - /** Serializer. */ - private PortableSerializer serializer; - - /** Meta data enabled flag. */ - private Boolean metaDataEnabled; - - /** Keep deserialized flag. */ - private Boolean keepDeserialized; - - /** Affinity key field name. */ - private String affKeyFieldName; - - /** - */ - public PortableTypeConfiguration() { - // No-op. - } - - /** - * @param clsName Class name. - */ - public PortableTypeConfiguration(String clsName) { - this.clsName = clsName; - } - - /** - * Gets type name. - * - * @return Type name. - */ - public String getClassName() { - return clsName; - } - - /** - * Sets type name. - * - * @param clsName Type name. - */ - public void setClassName(String clsName) { - this.clsName = clsName; - } - - /** - * Gets ID mapper. - * - * @return ID mapper. - */ - public PortableIdMapper getIdMapper() { - return idMapper; - } - - /** - * Sets ID mapper. - * - * @param idMapper ID mapper. - */ - public void setIdMapper(PortableIdMapper idMapper) { - this.idMapper = idMapper; - } - - /** - * Gets serializer. - * - * @return Serializer. - */ - public PortableSerializer getSerializer() { - return serializer; - } - - /** - * Sets serializer. - * - * @param serializer Serializer. - */ - public void setSerializer(PortableSerializer serializer) { - this.serializer = serializer; - } - - /** - * Defines whether meta data is collected for this type. If provided, this value will override - * {@link PortableMarshaller#isMetaDataEnabled()} property. - * - * @return Whether meta data is collected. - */ - public Boolean isMetaDataEnabled() { - return metaDataEnabled; - } - - /** - * @param metaDataEnabled Whether meta data is collected. - */ - public void setMetaDataEnabled(Boolean metaDataEnabled) { - this.metaDataEnabled = metaDataEnabled; - } - - /** - * Defines whether {@link PortableObject} should cache deserialized instance. If provided, - * this value will override {@link PortableMarshaller#isKeepDeserialized()} - * property. - * - * @return Whether deserialized value is kept. - */ - public Boolean isKeepDeserialized() { - return keepDeserialized; - } - - /** - * @param keepDeserialized Whether deserialized value is kept. - */ - public void setKeepDeserialized(Boolean keepDeserialized) { - this.keepDeserialized = keepDeserialized; - } - - /** - * Gets affinity key field name. - * - * @return Affinity key field name. - */ - public String getAffinityKeyFieldName() { - return affKeyFieldName; - } - - /** - * Sets affinity key field name. - * - * @param affKeyFieldName Affinity key field name. - */ - public void setAffinityKeyFieldName(String affKeyFieldName) { - this.affKeyFieldName = affKeyFieldName; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(PortableTypeConfiguration.class, this, super.toString()); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java deleted file mode 100644 index 99bd5c6..0000000 --- a/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.portable; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Collection; -import java.util.Date; -import java.util.Map; -import java.util.UUID; -import org.jetbrains.annotations.Nullable; - -/** - * Writer for portable object used in {@link PortableMarshalAware} implementations. - * Useful for the cases when user wants a fine-grained control over serialization. - * <p> - * Note that Ignite never writes full strings for field or type names. Instead, - * for performance reasons, Ignite writes integer hash codes for type and field names. - * It has been tested that hash code conflicts for the type names or the field names - * within the same type are virtually non-existent and, to gain performance, it is safe - * to work with hash codes. For the cases when hash codes for different types or fields - * actually do collide, Ignite provides {@link PortableIdMapper} which - * allows to override the automatically generated hash code IDs for the type and field names. - */ -public interface PortableWriter { - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeByte(String fieldName, byte val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeShort(String fieldName, short val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeInt(String fieldName, int val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeLong(String fieldName, long val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeFloat(String fieldName, float val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDouble(String fieldName, double val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeChar(String fieldName, char val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeBoolean(String fieldName, boolean val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeString(String fieldName, @Nullable String val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val UUID to write. - * @throws PortableException In case of error. - */ - public void writeUuid(String fieldName, @Nullable UUID val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Date to write. - * @throws PortableException In case of error. - */ - public void writeDate(String fieldName, @Nullable Date val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Timestamp to write. - * @throws PortableException In case of error. - */ - public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws PortableException; - - /** - * @param fieldName Field name. - * @param obj Value to write. - * @throws PortableException In case of error. - */ - public void writeObject(String fieldName, @Nullable Object obj) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeByteArray(String fieldName, @Nullable byte[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeShortArray(String fieldName, @Nullable short[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeIntArray(String fieldName, @Nullable int[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeLongArray(String fieldName, @Nullable long[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeFloatArray(String fieldName, @Nullable float[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDoubleArray(String fieldName, @Nullable double[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeCharArray(String fieldName, @Nullable char[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeBooleanArray(String fieldName, @Nullable boolean[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeStringArray(String fieldName, @Nullable String[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeDateArray(String fieldName, @Nullable Date[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public void writeObjectArray(String fieldName, @Nullable Object[] val) throws PortableException; - - /** - * @param fieldName Field name. - * @param col Collection to write. - * @throws PortableException In case of error. - */ - public <T> void writeCollection(String fieldName, @Nullable Collection<T> col) throws PortableException; - - /** - * @param fieldName Field name. - * @param map Map to write. - * @throws PortableException In case of error. - */ - public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws PortableException; - - /** - * @param fieldName Field name. - * @param val Value to write. - * @throws PortableException In case of error. - */ - public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws PortableException; - - /** - * Gets raw writer. Raw writer does not write field name hash codes, therefore, - * making the format even more compact. However, if the raw writer is used, - * dynamic structure changes to the portable objects are not supported. - * - * @return Raw writer. - */ - public PortableRawWriter rawWriter(); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/portable/package-info.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/portable/package-info.java b/modules/core/src/main/java/org/apache/ignite/portable/package-info.java deleted file mode 100644 index 0105b15..0000000 --- a/modules/core/src/main/java/org/apache/ignite/portable/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * <!-- Package description. --> - * Contains portable objects API classes. - */ -package org.apache.ignite.portable; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java index 6254605..e3a02cb 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java @@ -44,6 +44,7 @@ import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLSocketFactory; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteAuthenticationException; +import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; @@ -59,6 +60,7 @@ import org.apache.ignite.internal.util.typedef.internal.LT; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiTuple; +import org.apache.ignite.lang.IgniteCallable; import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.lang.IgniteProductVersion; import org.apache.ignite.lang.IgniteUuid; http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapKey.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapKey.java b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapKey.java index fb22be2..fb028b4 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapKey.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/SwapKey.java @@ -17,6 +17,7 @@ package org.apache.ignite.spi.swapspace; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; @@ -44,7 +45,8 @@ public class SwapKey { * @param key Key. */ public SwapKey(Object key) { - this(key, Integer.MAX_VALUE, null); + this.key = key; + part = Integer.MAX_VALUE; } /** @@ -52,7 +54,8 @@ public class SwapKey { * @param part Partition. */ public SwapKey(Object key, int part) { - this(key, part, null); + this.key = key; + this.part = part; } /** @@ -60,7 +63,7 @@ public class SwapKey { * @param part Part. * @param keyBytes Key bytes. */ - public SwapKey(Object key, int part, @Nullable byte[] keyBytes) { + public SwapKey(KeyCacheObject key, int part, @Nullable byte[] keyBytes) { assert key != null; assert part >= 0; http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java b/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java index e7d224c..48559a9 100644 --- a/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/stream/StreamAdapter.java @@ -33,11 +33,10 @@ import org.apache.ignite.IgniteDataStreamer; * <li>A single tuple extractor, which extracts either no or 1 tuple out of a message. See * see {@link #setTupleExtractor(StreamTupleExtractor)}.</li> * <li>A multiple tuple extractor, which is capable of extracting multiple tuples out of a single message, in the - * form of a {@link Map<K, V>}. See {@link #setMultipleTupleExtractor(StreamMultipleTupleExtractor)}.</li> + * form of a {@link Map}. See {@link #setMultipleTupleExtractor(StreamMultipleTupleExtractor)}.</li> * </ol> */ public abstract class StreamAdapter<T, K, V> { - /** Tuple extractor extracting a single tuple from an event */ private StreamSingleTupleExtractor<T, K, V> singleTupleExtractor; http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java new file mode 100644 index 0000000..1db3f0b --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java @@ -0,0 +1,730 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.portable; + +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.IgniteUtils; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.MarshallerContextTestImpl; +import org.apache.ignite.marshaller.portable.PortableMarshaller; +import org.apache.ignite.binary.BinaryField; +import org.apache.ignite.binary.BinaryType; +import org.apache.ignite.binary.BinaryObject; +import org.apache.ignite.binary.BinaryTypeConfiguration; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.util.Arrays; +import java.util.Date; +import java.util.UUID; + +/** + * Contains tests for portable object fields. + */ +public abstract class BinaryFieldsAbstractSelfTest extends GridCommonAbstractTest { + /** Dummy metadata handler. */ + protected static final PortableMetaDataHandler META_HND = new PortableMetaDataHandler() { + @Override public void addMeta(int typeId, BinaryType meta) { + // No-op. + } + + @Override public BinaryType metadata(int typeId) { + return null; + } + }; + + /** Marshaller. */ + protected PortableMarshaller dfltMarsh; + + /** + * Create marshaller. + * + * @param stringAsBytes Whether to marshal strings as bytes (UTF8). + * @return Portable marshaller. + * @throws Exception If failed. + */ + protected static PortableMarshaller createMarshaller(boolean stringAsBytes) throws Exception { + PortableContext ctx = new PortableContext(META_HND, new IgniteConfiguration()); + + PortableMarshaller marsh = new PortableMarshaller(); + + marsh.setConvertStringToBytes(stringAsBytes); + + marsh.setTypeConfigurations(Arrays.asList( + new BinaryTypeConfiguration(TestObject.class.getName()), + new BinaryTypeConfiguration(TestOuterObject.class.getName()), + new BinaryTypeConfiguration(TestInnerObject.class.getName()) + )); + + marsh.setContext(new MarshallerContextTestImpl(null)); + + IgniteUtils.invoke(PortableMarshaller.class, marsh, "setPortableContext", ctx); + + return marsh; + } + + /** + * Get portable context for the current marshaller. + * + * @param marsh Marshaller. + * @return Portable context. + */ + protected static PortableContext portableContext(PortableMarshaller marsh) { + GridPortableMarshaller impl = U.field(marsh, "impl"); + + return impl.context(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + dfltMarsh = createMarshaller(true); + } + + /** + * Test byte field. + * + * @throws Exception If failed. + */ + public void testByte() throws Exception { + check("fByte"); + } + + /** + * Test byte array field. + * + * @throws Exception If failed. + */ + public void testByteArray() throws Exception { + check("fByteArr"); + } + + /** + * Test boolean field. + * + * @throws Exception If failed. + */ + public void testBoolean() throws Exception { + check("fBool"); + } + + /** + * Test boolean array field. + * + * @throws Exception If failed. + */ + public void testBooleanArray() throws Exception { + check("fBoolArr"); + } + + /** + * Test short field. + * + * @throws Exception If failed. + */ + public void testShort() throws Exception { + check("fShort"); + } + + /** + * Test short array field. + * + * @throws Exception If failed. + */ + public void testShortArray() throws Exception { + check("fShortArr"); + } + + /** + * Test char field. + * + * @throws Exception If failed. + */ + public void testChar() throws Exception { + check("fChar"); + } + + /** + * Test char array field. + * + * @throws Exception If failed. + */ + public void testCharArray() throws Exception { + check("fCharArr"); + } + + /** + * Test int field. + * + * @throws Exception If failed. + */ + public void testInt() throws Exception { + check("fInt"); + } + + /** + * Test int array field. + * + * @throws Exception If failed. + */ + public void testIntArray() throws Exception { + check("fIntArr"); + } + + /** + * Test long field. + * + * @throws Exception If failed. + */ + public void testLong() throws Exception { + check("fLong"); + } + + /** + * Test long array field. + * + * @throws Exception If failed. + */ + public void testLongArray() throws Exception { + check("fLongArr"); + } + + /** + * Test float field. + * + * @throws Exception If failed. + */ + public void testFloat() throws Exception { + check("fFloat"); + } + + /** + * Test float array field. + * + * @throws Exception If failed. + */ + public void testFloatArray() throws Exception { + check("fFloatArr"); + } + + /** + * Test double field. + * + * @throws Exception If failed. + */ + public void testDouble() throws Exception { + check("fDouble"); + } + + /** + * Test double array field. + * + * @throws Exception If failed. + */ + public void testDoubleArray() throws Exception { + check("fDoubleArr"); + } + + /** + * Test string field. + * + * @throws Exception If failed. + */ + public void testString() throws Exception { + check("fString"); + } + + /** + * Test string field. + * + * @throws Exception If failed. + */ + public void testStringAsChars() throws Exception { + PortableMarshaller marsh = createMarshaller(false); + + checkNormal(marsh, "fString", true); + checkNested(marsh, "fString", true); + } + + /** + * Test string array field. + * + * @throws Exception If failed. + */ + public void testStringArray() throws Exception { + check("fStringArr"); + } + + /** + * Test date field. + * + * @throws Exception If failed. + */ + public void testDate() throws Exception { + check("fDate"); + } + + /** + * Test date array field. + * + * @throws Exception If failed. + */ + public void testDateArray() throws Exception { + check("fDateArr"); + } + + /** + * Test timestamp field. + * + * @throws Exception If failed. + */ + public void testTimestamp() throws Exception { + check("fTimestamp"); + } + + /** + * Test timestamp array field. + * + * @throws Exception If failed. + */ + public void testTimestampArray() throws Exception { + check("fTimestampArr"); + } + + /** + * Test UUID field. + * + * @throws Exception If failed. + */ + public void testUuid() throws Exception { + check("fUuid"); + } + + /** + * Test UUID array field. + * + * @throws Exception If failed. + */ + public void testUuidArray() throws Exception { + check("fUuidArr"); + } + + /** + * Test decimal field. + * + * @throws Exception If failed. + */ + public void testDecimal() throws Exception { + check("fDecimal"); + } + + /** + * Test decimal array field. + * + * @throws Exception If failed. + */ + public void testDecimalArray() throws Exception { + check("fDecimalArr"); + } + + /** + * Test object field. + * + * @throws Exception If failed. + */ + public void testObject() throws Exception { + check("fObj"); + } + + /** + * Test object array field. + * + * @throws Exception If failed. + */ + public void testObjectArray() throws Exception { + check("fObjArr"); + } + + /** + * Test null field. + * + * @throws Exception If failed. + */ + public void testNull() throws Exception { + check("fNull"); + } + + /** + * Test missing field. + * + * @throws Exception If failed. + */ + public void testMissing() throws Exception { + String fieldName = "fMissing"; + + checkNormal(dfltMarsh, fieldName, false); + checkNested(dfltMarsh, fieldName, false); + } + + /** + * Check field resolution in both normal and nested modes. + * + * @param fieldName Field name. + * @throws Exception If failed. + */ + public void check(String fieldName) throws Exception { + checkNormal(dfltMarsh, fieldName, true); + checkNested(dfltMarsh, fieldName, true); + } + + /** + * Check field. + * + * @param marsh Marshaller. + * @param fieldName Field name. + * @param exists Whether field should exist. + * @throws Exception If failed. + */ + private void checkNormal(PortableMarshaller marsh, String fieldName, boolean exists) throws Exception { + TestContext testCtx = context(marsh, fieldName); + + check0(fieldName, testCtx, exists); + } + + /** + * Check nested field. + * + * @param marsh Marshaller. + * @param fieldName Field name. + * @param exists Whether field should exist. + * @throws Exception If failed. + */ + private void checkNested(PortableMarshaller marsh, String fieldName, boolean exists) throws Exception { + TestContext testCtx = nestedContext(marsh, fieldName); + + check0(fieldName, testCtx, exists); + } + + /** + * Internal check routine. + * + * @param fieldName Field name. + * @param ctx Context. + * @param exists Whether field should exist. + * @throws Exception If failed. + */ + private void check0(String fieldName, TestContext ctx, boolean exists) throws Exception { + Object val = ctx.field.value(ctx.portObj); + + if (exists) { + assertTrue(ctx.field.exists(ctx.portObj)); + + Object expVal = U.field(ctx.obj, fieldName); + + if (val instanceof BinaryObject) + val = ((BinaryObject) val).deserialize(); + + if (val != null && val.getClass().isArray()) { + assertNotNull(expVal); + + if (val instanceof byte[]) + assertTrue(Arrays.equals((byte[]) expVal, (byte[]) val)); + else if (val instanceof boolean[]) + assertTrue(Arrays.equals((boolean[]) expVal, (boolean[]) val)); + else if (val instanceof short[]) + assertTrue(Arrays.equals((short[]) expVal, (short[]) val)); + else if (val instanceof char[]) + assertTrue(Arrays.equals((char[]) expVal, (char[]) val)); + else if (val instanceof int[]) + assertTrue(Arrays.equals((int[]) expVal, (int[]) val)); + else if (val instanceof long[]) + assertTrue(Arrays.equals((long[]) expVal, (long[]) val)); + else if (val instanceof float[]) + assertTrue(Arrays.equals((float[]) expVal, (float[]) val)); + else if (val instanceof double[]) + assertTrue(Arrays.equals((double[]) expVal, (double[]) val)); + else { + Object[] expVal0 = (Object[])expVal; + Object[] val0 = (Object[])val; + + assertEquals(expVal0.length, val0.length); + + for (int i = 0; i < expVal0.length; i++) { + Object expItem = expVal0[i]; + Object item = val0[i]; + + if (item instanceof BinaryObject) + item = ((BinaryObject)item).deserialize(); + + assertEquals(expItem, item); + } + } + } + else + assertEquals(expVal, val); + } + else { + assertFalse(ctx.field.exists(ctx.portObj)); + + assert val == null; + } + } + + /** + * Get test context. + * + * @param marsh Portable marshaller. + * @param fieldName Field name. + * @return Test context. + * @throws Exception If failed. + */ + private TestContext context(PortableMarshaller marsh, String fieldName) throws Exception { + TestObject obj = createObject(); + + BinaryObjectEx portObj = toPortable(marsh, obj); + + BinaryField field = portObj.fieldDescriptor(fieldName); + + return new TestContext(obj, portObj, field); + } + + /** + * Get test context with nested test object. + * + * @param marsh Portable marshaller. + * @param fieldName Field name. + * @return Test context. + * @throws Exception If failed. + */ + private TestContext nestedContext(PortableMarshaller marsh, String fieldName) + throws Exception { + TestObject obj = createObject(); + TestOuterObject outObj = new TestOuterObject(obj); + + BinaryObjectEx portOutObj = toPortable(marsh, outObj); + BinaryObjectEx portObj = portOutObj.field("fInner"); + + assert portObj != null; + + BinaryField field = portObj.fieldDescriptor(fieldName); + + return new TestContext(obj, portObj, field); + } + + /** + * Create test object. + * + * @return Test object. + */ + private TestObject createObject() { + return new TestObject(0); + } + + /** + * Convert object to portable object. + * + * @param marsh Marshaller. + * @param obj Object. + * @return Portable object. + * @throws Exception If failed. + */ + protected abstract BinaryObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception; + + /** + * Outer test object. + */ + @SuppressWarnings("UnusedDeclaration") + public static class TestOuterObject { + /** Inner object. */ + public TestObject fInner; + + /** + * Default constructor. + */ + public TestOuterObject() { + // No-op. + } + + /** + * Constructor. + * + * @param fInner Inner object. + */ + public TestOuterObject(TestObject fInner) { + this.fInner = fInner; + } + } + + /** + * Test object class, c + */ + @SuppressWarnings("UnusedDeclaration") + public static class TestObject { + /** Primitive fields. */ + public byte fByte; + public boolean fBool; + public short fShort; + public char fChar; + public int fInt; + public long fLong; + public float fFloat; + public double fDouble; + + public byte[] fByteArr; + public boolean[] fBoolArr; + public short[] fShortArr; + public char[] fCharArr; + public int[] fIntArr; + public long[] fLongArr; + public float[] fFloatArr; + public double[] fDoubleArr; + + /** Special fields. */ + public String fString; + public Date fDate; + public Timestamp fTimestamp; + public UUID fUuid; + public BigDecimal fDecimal; + + public String[] fStringArr; + public Date[] fDateArr; + public Timestamp[] fTimestampArr; + public UUID[] fUuidArr; + public BigDecimal[] fDecimalArr; + + /** Nested object. */ + public TestInnerObject fObj; + + public TestInnerObject[] fObjArr; + + /** Field which is always set to null. */ + public Object fNull; + + /** + * Default constructor. + */ + public TestObject() { + // No-op. + } + + /** + * Non-default constructor. + * + * @param ignore Ignored. + */ + public TestObject(int ignore) { + fByte = 1; + fBool = true; + fShort = 2; + fChar = 3; + fInt = 4; + fLong = 5; + fFloat = 6.6f; + fDouble = 7.7; + + fByteArr = new byte[] { 1, 2 }; + fBoolArr = new boolean[] { true, false }; + fShortArr = new short[] { 2, 3 }; + fCharArr = new char[] { 3, 4 }; + fIntArr = new int[] { 4, 5 }; + fLongArr = new long[] { 5, 6 }; + fFloatArr = new float[] { 6.6f, 7.7f }; + fDoubleArr = new double[] { 7.7, 8.8 }; + + fString = "8"; + fDate = new Date(); + fTimestamp = new Timestamp(new Date().getTime() + 1); + fUuid = UUID.randomUUID(); + fDecimal = new BigDecimal(9); + + fStringArr = new String[] { "8", "9" }; + fDateArr = new Date[] { new Date(), new Date(new Date().getTime() + 1) }; + fTimestampArr = + new Timestamp[] { new Timestamp(new Date().getTime() + 1), new Timestamp(new Date().getTime() + 2) }; + fUuidArr = new UUID[] { UUID.randomUUID(), UUID.randomUUID() }; + fDecimalArr = new BigDecimal[] { new BigDecimal(9), new BigDecimal(10) }; + + fObj = new TestInnerObject(10); + fObjArr = new TestInnerObject[] { new TestInnerObject(10), new TestInnerObject(11) }; + } + } + + /** + * Inner test object. + */ + @SuppressWarnings("UnusedDeclaration") + public static class TestInnerObject { + /** Value. */ + private int val; + + /** + * Default constructor. + */ + public TestInnerObject() { + // No-op. + } + + /** + * Constructor. + * + * @param val Value. + */ + public TestInnerObject(int val) { + this.val = val; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return val; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object other) { + return other != null && other instanceof TestInnerObject && val == ((TestInnerObject)(other)).val; + } + } + + /** + * Test context. + */ + public static class TestContext { + /** Object. */ + public final TestObject obj; + + /** Portable object. */ + public final BinaryObjectEx portObj; + + /** Field. */ + public final BinaryField field; + + /** + * Constructor. + * + * @param obj Object. + * @param portObj Portable object. + * @param field Field. + */ + public TestContext(TestObject obj, BinaryObjectEx portObj, BinaryField field) { + this.obj = obj; + this.portObj = portObj; + this.field = field; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java new file mode 100644 index 0000000..0140c53 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.portable; + +import org.apache.ignite.marshaller.portable.PortableMarshaller; + +/** + * Field tests for heap-based portables. + */ +public class BinaryFieldsHeapSelfTest extends BinaryFieldsAbstractSelfTest { + /** {@inheritDoc} */ + @Override protected BinaryObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception { + byte[] bytes = marsh.marshal(obj); + + return new BinaryObjectImpl(portableContext(marsh), bytes, 0); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/b783d2b7/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java new file mode 100644 index 0000000..1bd0f72 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.portable; + +import org.apache.ignite.internal.util.GridUnsafe; +import org.apache.ignite.marshaller.portable.PortableMarshaller; +import org.eclipse.jetty.util.ConcurrentHashSet; +import sun.misc.Unsafe; + +/** + * Field tests for heap-based portables. + */ +public class BinaryFieldsOffheapSelfTest extends BinaryFieldsAbstractSelfTest { + /** Unsafe instance. */ + private static final Unsafe UNSAFE = GridUnsafe.unsafe(); + + /** Byte array offset for unsafe mechanics. */ + protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class); + + /** Allocated unsafe pointer. */ + private final ConcurrentHashSet<Long> ptrs = new ConcurrentHashSet<>(); + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + // Cleanup allocated objects. + for (Long ptr : ptrs) + UNSAFE.freeMemory(ptr); + + ptrs.clear(); + } + + /** {@inheritDoc} */ + @Override protected BinaryObjectEx toPortable(PortableMarshaller marsh, Object obj) throws Exception { + byte[] arr = marsh.marshal(obj); + + long ptr = UNSAFE.allocateMemory(arr.length); + + ptrs.add(ptr); + + UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length); + + return new BinaryObjectOffheapImpl(portableContext(marsh), ptr, 0, arr.length); + } +}