Search in sources :

Example 1 with Instantiator

use of org.apache.geode.Instantiator in project geode by apache.

the class InternalInstantiator method logInstantiators.

public static void logInstantiators() {
    for (Iterator itr = dsMap.values().iterator(); itr.hasNext(); ) {
        Instantiator instantiator = (Instantiator) itr.next();
        logger.info(LocalizedMessage.create(LocalizedStrings.InternalInstantiator_REGISTERED, new Object[] { Integer.valueOf(instantiator.getId()), instantiator.getInstantiatedClass().getName() }));
    }
    for (Iterator itr = idsToHolders.values().iterator(); itr.hasNext(); ) {
        InstantiatorAttributesHolder holder = (InstantiatorAttributesHolder) itr.next();
        logger.info(LocalizedMessage.create(LocalizedStrings.InternalInstantiator_REGISTERED_HOLDER, new Object[] { Integer.valueOf(holder.getId()), holder.getInstantiatedClassName() }));
    }
}
Also used : Iterator(java.util.Iterator) Instantiator(org.apache.geode.Instantiator)

Example 2 with Instantiator

use of org.apache.geode.Instantiator in project geode by apache.

the class InternalInstantiator method getInstantiators.

/**
   * Returns all of the currently registered instantiators
   */
public static Instantiator[] getInstantiators() {
    Collection coll = new ArrayList();
    if (!classNamesToHolders.isEmpty()) {
        Iterator it = classNamesToHolders.values().iterator();
        while (it.hasNext()) {
            try {
                InstantiatorAttributesHolder holder = (InstantiatorAttributesHolder) it.next();
                Class instantiatorClass = InternalDataSerializer.getCachedClass(holder.getInstantiatorClassName());
                Class instantiatedClass = InternalDataSerializer.getCachedClass(holder.getInstantiatedClassName());
                synchronized (InternalInstantiator.class) {
                    if (!idsToInstantiators.containsKey(holder.getId())) {
                        register(instantiatorClass, instantiatedClass, holder.getId(), false, holder.getEventId(), holder.getContext());
                    }
                    classNamesToHolders.remove(holder.getInstantiatedClassName());
                    idsToHolders.remove(holder.getId());
                }
            } catch (ClassNotFoundException cnfe) {
                InternalCache cache = GemFireCacheImpl.getInstance();
                if (cache != null && cache.getLoggerI18n() != null && cache.getLoggerI18n().infoEnabled()) {
                    cache.getLoggerI18n().info(LocalizedStrings.InternalInstantiator_COULD_NOT_LOAD_INSTANTIATOR_CLASS_0, new Object[] { cnfe.getMessage() });
                }
            }
        }
    }
    // Don't move it before the if block above.
    coll.addAll(dsMap.values());
    return (Instantiator[]) coll.toArray(new Instantiator[coll.size()]);
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) InternalCache(org.apache.geode.internal.cache.InternalCache) Instantiator(org.apache.geode.Instantiator)

Example 3 with Instantiator

use of org.apache.geode.Instantiator in project geode by apache.

the class InternalInstantiator method unregister.

/**
   * Unregisters the given class with the given class id with the {@code Instantiator}.
   *
   * @throws IllegalArgumentException If {@code c} was not previously registered with id
   *         {@code classId}.
   * @throws NullPointerException If {@code c} is {@code null}
   */
public static synchronized void unregister(Class c, int classId) {
    if (c == null) {
        throw new NullPointerException(LocalizedStrings.InternalInstantiator_CANNOT_UNREGISTER_A_NULL_CLASS.toLocalizedString());
    }
    final Integer idx = Integer.valueOf(classId);
    final Instantiator i = (Instantiator) idsToInstantiators.remove(idx);
    if (i == null) {
        throw new IllegalArgumentException(LocalizedStrings.InternalInstantiator_CLASS_0_WAS_NOT_REGISTERED_WITH_ID_1.toLocalizedString(new Object[] { c.getName(), Integer.valueOf(classId) }));
    } else {
        dsMap.remove(c.getName(), i);
    }
    idsToHolders.remove(idx);
    classNamesToHolders.remove(i.getInstantiatedClass().getName());
}
Also used : Instantiator(org.apache.geode.Instantiator)

Example 4 with Instantiator

use of org.apache.geode.Instantiator in project geode by apache.

the class DataType method getDataType.

public static String getDataType(byte[] bytes) {
    final DataInput in = getDataInput(bytes);
    byte header = 0;
    try {
        header = in.readByte();
    } catch (IOException e) {
        return "IOException: " + e.getMessage();
    }
    try {
        switch(header) {
            case DS_FIXED_ID_BYTE:
                {
                    return "org.apache.geode.internal.DataSerializableFixedID:" + DSFIDFactory.create(in.readByte(), in).getClass().getName();
                }
            case DS_FIXED_ID_SHORT:
                {
                    return "org.apache.geode.internal.DataSerializableFixedID:" + DSFIDFactory.create(in.readShort(), in).getClass().getName();
                }
            case DS_FIXED_ID_INT:
                {
                    return "org.apache.geode.internal.DataSerializableFixedID:" + DSFIDFactory.create(in.readInt(), in).getClass().getName();
                }
            case DS_NO_FIXED_ID:
                return "org.apache.geode.internal.DataSerializableFixedID:" + DataSerializer.readClass(in).getName();
            case NULL:
                return "null";
            case NULL_STRING:
            case STRING:
            case HUGE_STRING:
            case STRING_BYTES:
            case HUGE_STRING_BYTES:
                return "java.lang.String";
            case CLASS:
                return "java.lang.Class";
            case DATE:
                return "java.util.Date";
            case FILE:
                return "java.io.File";
            case INET_ADDRESS:
                return "java.net.InetAddress";
            case BOOLEAN:
                return "java.lang.Boolean";
            case CHARACTER:
                return "java.lang.Character";
            case BYTE:
                return "java.lang.Byte";
            case SHORT:
                return "java.lang.Short";
            case INTEGER:
                return "java.lang.Integer";
            case LONG:
                return "java.lang.Long";
            case FLOAT:
                return "java.lang.Float";
            case DOUBLE:
                return "java.lang.Double";
            case BYTE_ARRAY:
                return "byte[]";
            case ARRAY_OF_BYTE_ARRAYS:
                return "byte[][]";
            case SHORT_ARRAY:
                return "short[]";
            case STRING_ARRAY:
                return "java.lang.String[]";
            case INT_ARRAY:
                return "int[]";
            case LONG_ARRAY:
                return "long[]";
            case FLOAT_ARRAY:
                return "float[]";
            case DOUBLE_ARRAY:
                return "double[]";
            case BOOLEAN_ARRAY:
                return "boolean[]";
            case CHAR_ARRAY:
                return "char[]";
            case OBJECT_ARRAY:
                return "java.lang.Object[]";
            case ARRAY_LIST:
                return "java.util.ArrayList";
            case LINKED_LIST:
                return "java.util.LinkedList";
            case HASH_SET:
                return "java.util.HashSet";
            case LINKED_HASH_SET:
                return "java.util.LinkedHashSet";
            case HASH_MAP:
                return "java.util.HashMap";
            case IDENTITY_HASH_MAP:
                return "java.util.IdentityHashMap";
            case HASH_TABLE:
                return "java.util.Hashtable";
            // return "java.util.concurrent.ConcurrentHashMap";
            case PROPERTIES:
                return "java.util.Properties";
            case TIME_UNIT:
                return "java.util.concurrent.TimeUnit";
            case USER_CLASS:
                byte userClassDSId = in.readByte();
                return "DataSerializer: with Id:" + userClassDSId;
            case USER_CLASS_2:
                short userClass2DSId = in.readShort();
                return "DataSerializer: with Id:" + userClass2DSId;
            case USER_CLASS_4:
                int userClass4DSId = in.readInt();
                return "DataSerializer: with Id:" + userClass4DSId;
            case VECTOR:
                return "java.util.Vector";
            case STACK:
                return "java.util.Stack";
            case TREE_MAP:
                return "java.util.TreeMap";
            case TREE_SET:
                return "java.util.TreeSet";
            case BOOLEAN_TYPE:
                return "java.lang.Boolean.class";
            case CHARACTER_TYPE:
                return "java.lang.Character.class";
            case BYTE_TYPE:
                return "java.lang.Byte.class";
            case SHORT_TYPE:
                return "java.lang.Short.class";
            case INTEGER_TYPE:
                return "java.lang.Integer.class";
            case LONG_TYPE:
                return "java.lang.Long.class";
            case FLOAT_TYPE:
                return "java.lang.Float.class";
            case DOUBLE_TYPE:
                return "java.lang.Double.class";
            case VOID_TYPE:
                return "java.lang.Void.class";
            case USER_DATA_SERIALIZABLE:
                {
                    Instantiator instantiator = InternalInstantiator.getInstantiator(in.readByte());
                    return "org.apache.geode.Instantiator:" + instantiator.getInstantiatedClass().getName();
                }
            case USER_DATA_SERIALIZABLE_2:
                {
                    Instantiator instantiator = InternalInstantiator.getInstantiator(in.readShort());
                    return "org.apache.geode.Instantiator:" + instantiator.getInstantiatedClass().getName();
                }
            case USER_DATA_SERIALIZABLE_4:
                {
                    Instantiator instantiator = InternalInstantiator.getInstantiator(in.readInt());
                    return "org.apache.geode.Instantiator:" + instantiator.getInstantiatedClass().getName();
                }
            case DATA_SERIALIZABLE:
                return "org.apache.geode.DataSerializable:" + DataSerializer.readClass(in).getName();
            case SERIALIZABLE:
                {
                    String name = null;
                    try {
                        Object obj = InternalDataSerializer.basicReadObject(getDataInput(bytes));
                        name = obj.getClass().getName();
                    } catch (ClassNotFoundException e) {
                        name = e.getMessage();
                    }
                    return "java.io.Serializable:" + name;
                }
            case PDX:
                {
                    int typeId = in.readInt();
                    try {
                        InternalCache gfc = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.");
                        PdxType pdxType = gfc.getPdxRegistry().getType(typeId);
                        if (pdxType == null) {
                            // fix 52164
                            return "org.apache.geode.pdx.PdxInstance: unknown id=" + typeId;
                        }
                        return "org.apache.geode.pdx.PdxInstance:" + pdxType.getClassName();
                    } catch (CacheClosedException e) {
                        return "org.apache.geode.pdx.PdxInstance:PdxRegistryClosed";
                    }
                }
            case PDX_ENUM:
                {
                    int dsId = in.readByte();
                    int tmp = InternalDataSerializer.readArrayLength(in);
                    int enumId = (dsId << 24) | (tmp & 0xFFFFFF);
                    try {
                        InternalCache gfc = GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.");
                        EnumInfo enumInfo = gfc.getPdxRegistry().getEnumInfoById(enumId);
                        return "PdxRegistry/java.lang.Enum:" + enumInfo.getClassName();
                    } catch (CacheClosedException e) {
                        return "PdxRegistry/java.lang.Enum:PdxRegistryClosed";
                    }
                }
            case GEMFIRE_ENUM:
                {
                    String name = DataSerializer.readString(in);
                    return "java.lang.Enum:" + name;
                }
            case PDX_INLINE_ENUM:
                {
                    String name = DataSerializer.readString(in);
                    return "java.lang.Enum:" + name;
                }
            case BIG_INTEGER:
                return "java.math.BigInteger";
            case BIG_DECIMAL:
                return "java.math.BigDecimal";
            case UUID:
                return "java.util.UUID";
            case TIMESTAMP:
                return "java.sql.Timestamp";
            default:
        }
        return "Unknown header byte: " + header;
    } catch (IOException e) {
        throw new Error(e);
    } catch (ClassNotFoundException e) {
        throw new Error(e);
    }
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) InternalCache(org.apache.geode.internal.cache.InternalCache) InternalInstantiator(org.apache.geode.internal.InternalInstantiator) Instantiator(org.apache.geode.Instantiator) IOException(java.io.IOException) CacheClosedException(org.apache.geode.cache.CacheClosedException) DataInput(java.io.DataInput)

Example 5 with Instantiator

use of org.apache.geode.Instantiator in project geode by apache.

the class DiskInitFile method saveInstantiators.

private void saveInstantiators() {
    Object[] objects = InternalInstantiator.getInstantiatorsForSerialization();
    for (Object obj : objects) {
        if (obj instanceof Instantiator) {
            saveInstantiator((Instantiator) obj);
        } else {
            InstantiatorAttributesHolder iah = (InstantiatorAttributesHolder) obj;
            saveInstantiator(iah.getId(), iah.getInstantiatorClassName(), iah.getInstantiatedClassName());
        }
    }
}
Also used : InstantiatorAttributesHolder(org.apache.geode.internal.InternalInstantiator.InstantiatorAttributesHolder) InternalInstantiator(org.apache.geode.internal.InternalInstantiator) Instantiator(org.apache.geode.Instantiator)

Aggregations

Instantiator (org.apache.geode.Instantiator)24 UnitTest (org.apache.geode.test.junit.categories.UnitTest)9 Test (org.junit.Test)9 CanonicalInstantiator (org.apache.geode.CanonicalInstantiator)7 InternalInstantiator (org.apache.geode.internal.InternalInstantiator)7 DataSerializable (org.apache.geode.DataSerializable)5 InternalCache (org.apache.geode.internal.cache.InternalCache)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 IOException (java.io.IOException)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 DataSerializer (org.apache.geode.DataSerializer)2 CacheClosedException (org.apache.geode.cache.CacheClosedException)2 DataInput (java.io.DataInput)1 EOFException (java.io.EOFException)1 NotSerializableException (java.io.NotSerializableException)1 UTFDataFormatException (java.io.UTFDataFormatException)1