All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jppf.serialization.DeserializationCaches Maven / Gradle / Ivy

There is a newer version: 6.3-alpha
Show newest version
/*
 * JPPF.
 * Copyright (C) 2005-2015 JPPF Team.
 * http://www.jppf.org
 *
 * Licensed 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.jppf.serialization;

import java.lang.reflect.Array;
import java.util.*;

import org.slf4j.*;

/**
 * Instances of this class handle the caching and lookup of class descriptors and objects during deserialization.
 * @author Laurent Cohen
 * @exclude
 */
class DeserializationCaches {
  /**
   * Logger for this class.
   */
  private static Logger log = LoggerFactory.getLogger(DeserializationCaches.class);
  /**
   * Mapping of handles to corresponding class descriptors.
   */
  Map handleToDescriptorMap = new HashMap<>();
  /**
   * Mapping of handles to corresponding objects.
   */
  Map handleToObjectMap = new HashMap<>();

  /**
   * Default constructor.
   */
  DeserializationCaches() {
    Set, ClassDescriptor>> entries = SerializationCaches.globalTypesMap.entrySet();
    List list = new ArrayList<>(entries.size());
    for (Map.Entry, ClassDescriptor> entry: entries) {
      ClassDescriptor cd = entry.getValue();
      ClassDescriptor cd2 = new ClassDescriptor();
      cd2.signature = cd.signature;
      cd2.primitive = cd.primitive;
      cd2.array = cd.array;
      cd2.externalizable = cd.externalizable;
      cd2.hasWriteObject = cd.hasWriteObject;
      cd2.enumType = cd.enumType;
      cd2.handle = cd.handle;
      if (cd.superClass != null) cd2.superClassHandle = cd.superClass.handle;
      if (cd.componentType != null) cd2.componentTypeHandle = cd.componentType.handle;
      if (cd.fields.length > 0) {
        cd2.fields = new FieldDescriptor[cd.fields.length];
        for (int i=0; i list, final ClassLoader classloader) throws Exception {
    for (ClassDescriptor cd: list) {
      if (cd.clazz != null) continue;
      if (cd.array) {
        List types = new ArrayList<>();
        ClassDescriptor tmp = cd;
        while (tmp != null) {
          types.add(tmp);
          tmp = tmp.array ? getDescriptor(tmp.componentTypeHandle) : null;
        }
        for (int i=types.size()-1; i>=0; i--) {
          tmp = types.get(i);
          if (tmp.clazz != null) continue;
          if (!tmp.array) tmp.clazz = SerializationReflectionHelper.getNonArrayTypeFromSignature(tmp.signature, classloader);
          else {
            Class clazz = types.get(i+1).clazz;
            Object array = Array.newInstance(clazz, 0);
            tmp.clazz = array.getClass();
          }
        }
      }
      else cd.clazz = SerializationReflectionHelper.getNonArrayTypeFromSignature(cd.signature, classloader);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy