com.caucho.hessian.io.Deserializer Java Examples

The following examples show how to use com.caucho.hessian.io.Deserializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultipleClassLoaderSofaSerializerFactory.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
protected void putDeserializerToCachedType(String type, Deserializer deserializer) {

    ConcurrentMap<ClassLoader, Deserializer> concurrentMap = cachedTypeDeserializerMap
        .get(type);

    if (concurrentMap == null) {
        ConcurrentMap<ClassLoader, Deserializer> newMap = new ConcurrentHashMap<ClassLoader, Deserializer>();
        concurrentMap = cachedTypeDeserializerMap.putIfAbsent(type, newMap);
        if (concurrentMap == null) {
            concurrentMap = newMap;
        }
    }

    concurrentMap.put(Thread.currentThread().getContextClassLoader(), deserializer);
}
 
Example #2
Source File: HessionBigDecimalSerializerFactory.java    From AutoLoadCache with Apache License 2.0 5 votes vote down vote up
@Override
public Deserializer getDeserializer(@SuppressWarnings("rawtypes") Class cl) throws HessianProtocolException {
    if (BigDecimal.class.isAssignableFrom(cl)) {
        return BIG_DECIMAL_DESERIALIZER;
    }
    return null;
}
 
Example #3
Source File: CougarSerializerFactoryTest.java    From cougar with Apache License 2.0 5 votes vote down vote up
@Test
public void testMissingTypeCacheHit() throws Exception {
    String presentType = getClass().getName();
    CougarSerializerFactory factory = new CougarSerializerFactory(Collections.EMPTY_SET);
    Deserializer deserializer = factory.getDeserializer(presentType);
    assertNotNull(deserializer);

    Set<String> missingTypes = factory.getMissingTypes();
    missingTypes.add(presentType);
    deserializer = factory.getDeserializer(presentType);
    assertNull(deserializer);
}
 
Example #4
Source File: CougarSerializerFactoryTest.java    From cougar with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoDeserializerFound() throws Exception {
    CougarSerializerFactory factory = new CougarSerializerFactory(Collections.EMPTY_SET);
    Deserializer deserializer = factory.getDeserializer(MISSING_TYPE_NAME);
    assertNull(deserializer);
    Set<String> missingTypes = factory.getMissingTypes();
    assertEquals(1, missingTypes.size());
    assertTrue(missingTypes.contains(MISSING_TYPE_NAME));
}
 
Example #5
Source File: CougarSerializerFactoryTest.java    From cougar with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeserializerFound() throws Exception {
    CougarSerializerFactory factory = new CougarSerializerFactory(Collections.EMPTY_SET);
    Deserializer deserializer = factory.getDeserializer(Integer.class.getName());
    assertNotNull(deserializer);
    Set<String> missingTypes = factory.getMissingTypes();
    assertEquals(0, missingTypes.size());
}
 
Example #6
Source File: EnumSerialiserFactory.java    From cougar with Apache License 2.0 5 votes vote down vote up
@Override
public Deserializer getDeserializer(Class cls) throws HessianProtocolException {

	Deserializer deserializer = null;
       if (cls != null && TranscribableEnum.class.isAssignableFrom(cls)) {
           deserializer = new TranscribableEnumDeserializer(cls, transcriptionParams);
       }


	return deserializer;
}
 
Example #7
Source File: CougarSerializerFactory.java    From cougar with Apache License 2.0 5 votes vote down vote up
/**
 * If a Cougar server response contains a class the client doesn't know about (which is legal and backwards compatible
 * in cases) then the default behavior of Hessian is to perform a lookup, fail, throw an exception and log it.
 * This has been measured at about 25 times slower than the happy path, and Hessian does not negatively cache 'misses',
 * so this is a per-response slowdown. This implementation caches type lookup misses, and so eradicates the problem.
 */
private Deserializer optimizedGetDeserializer(String type)
        throws HessianProtocolException {
    if (missingTypes.contains(type)) {
        return null;
    }
    Deserializer answer = super.getDeserializer(type);
    if (answer == null) {
        missingTypes.add(type);
    }
    return answer;
}
 
Example #8
Source File: CougarSerializerFactory.java    From cougar with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a deserializer based on a string type.
 */
public Deserializer getDeserializer(String type)
        throws HessianProtocolException
{
    if (type == null || type.equals("")) {
        return null;
    }

    if (!transcriptionParams.contains(TranscribableParams.MajorOnlyPackageNaming)) {
        // look for vMajor
        type = ClassnameCompatibilityMapper.toMajorOnlyPackaging(type);
    }

    return optimizedGetDeserializer(type);
}
 
Example #9
Source File: FaultDetailSerialiserFactory.java    From cougar with Apache License 2.0 5 votes vote down vote up
@Override
public Deserializer getDeserializer(Class cls) throws HessianProtocolException {

	Deserializer deserializer = null;
       if (FaultDetail.class.isAssignableFrom(cls)) {
           deserializer = new FaultDetailDeserialiser(cls, transcriptionParams);
       }

	return deserializer;
}
 
Example #10
Source File: HessionSoftReferenceSerializerFactory.java    From AutoLoadCache with Apache License 2.0 5 votes vote down vote up
@Override
public Deserializer getDeserializer(@SuppressWarnings("rawtypes") Class cl) throws HessianProtocolException {
    if (SoftReference.class.isAssignableFrom(cl)) {
        return beanDeserializer;
    }
    return null;
}
 
Example #11
Source File: WeakReferenceSerializerFactory.java    From AutoLoadCache with Apache License 2.0 5 votes vote down vote up
@Override
public Deserializer getDeserializer(@SuppressWarnings("rawtypes") Class cl) throws HessianProtocolException {
    if (WeakReference.class.isAssignableFrom(cl)) {
        return beanDeserializer;
    }
    return null;
}
 
Example #12
Source File: JMXSerializerFactory.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the deserializer for a class.
 *
 * @param cl the class of the object that needs to be deserialized.
 *
 * @return a deserializer object for the serialization.
 */
public Deserializer getDeserializer(Class cl)
    throws HessianProtocolException
{
    if (ObjectName.class.equals(cl)) {
        return new StringValueDeserializer(cl);
    }
    else if (ObjectInstance.class.equals(cl)) {
        return new ObjectInstanceDeserializer();
    }
    else if (MBeanAttributeInfo.class.isAssignableFrom(cl)) {
        return new MBeanAttributeInfoDeserializer();
    }
    else if (MBeanConstructorInfo.class.isAssignableFrom(cl)) {
        return new MBeanConstructorInfoDeserializer();
    }
    else if (MBeanOperationInfo.class.isAssignableFrom(cl)) {
        return new MBeanOperationInfoDeserializer();
    }
    else if (MBeanParameterInfo.class.isAssignableFrom(cl)) {
        return new MBeanParameterInfoDeserializer();
    }
    else if (MBeanNotificationInfo.class.isAssignableFrom(cl)) {
        return new MBeanNotificationInfoDeserializer();
    }
    /*
    else if (MBeanInfo.class.equals(cl)) {
      return new MBeanInfoDeserializer();
    }
    */

    return null;
}
 
Example #13
Source File: GenericMultipleClassLoaderSofaSerializerFactory.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public Deserializer getDeserializer(String type) throws HessianProtocolException {

    // 如果类型在过滤列表, 说明是jdk自带类, 直接委托父类处理
    if (StringUtils.isEmpty(type) || ClassFilter.filterExcludeClass(type)) {
        return super.getDeserializer(type);
    }

    // 如果是数组类型, 且在name过滤列表, 说明jdk类, 直接委托父类处理
    if (type.charAt(0) == ARRAY_PREFIX && ClassFilter.arrayFilter(type)) {
        return super.getDeserializer(type);
    }

    // 查看是否已经包含反序列化器
    Deserializer deserializer = DESERIALIZER_MAP.get(type);
    if (deserializer != null) {
        return deserializer;
    }

    // 新建反序列化器, 如果是java.lang.Class使用GenericClassDeserializer,否则使用GenericDeserializer
    if (ClassFilter.CLASS_NAME.equals(type)) {
        deserializer = GenericClassDeserializer.getInstance();
    } else {
        deserializer = new GenericDeserializer(type);
    }

    DESERIALIZER_MAP.putIfAbsent(type, deserializer);
    return deserializer;
}
 
Example #14
Source File: GenericSingleClassLoaderSofaSerializerFactory.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
public Deserializer getDeserializer(String type) throws HessianProtocolException {

    // 如果类型在过滤列表, 说明是jdk自带类, 直接委托父类处理
    if (StringUtils.isEmpty(type) || ClassFilter.filterExcludeClass(type)) {
        return super.getDeserializer(type);
    }

    // 如果是数组类型, 且在name过滤列表, 说明jdk类, 直接委托父类处理
    if (type.charAt(0) == ARRAY_PREFIX && ClassFilter.arrayFilter(type)) {
        return super.getDeserializer(type);
    }

    // 查看是否已经包含反序列化器
    Deserializer deserializer = DESERIALIZER_MAP.get(type);
    if (deserializer != null) {
        return deserializer;
    }

    // 新建反序列化器, 如果是java.lang.Class使用GenericClassDeserializer,否则使用GenericDeserializer
    if (ClassFilter.CLASS_NAME.equals(type)) {
        deserializer = GenericClassDeserializer.getInstance();
    } else {
        deserializer = new GenericDeserializer(type);
    }

    DESERIALIZER_MAP.putIfAbsent(type, deserializer);
    return deserializer;
}
 
Example #15
Source File: MultipleClassLoaderSofaSerializerFactory.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Override
protected Deserializer getDeserializerFromCachedType(String type) {
    Map<ClassLoader, Deserializer> map = cachedTypeDeserializerMap.get(type);
    if (map == null) {
        return null;
    }

    return map.get(Thread.currentThread().getContextClassLoader());
}
 
Example #16
Source File: MyListSerializeFactory.java    From sofa-hessian with Apache License 2.0 5 votes vote down vote up
@Override
public Deserializer getDeserializer(Class cl) throws HessianProtocolException {
    if (MyList.class.isAssignableFrom(cl)) {
        return new MyListDeserializer(cl);
    }
    return null;
}
 
Example #17
Source File: SingleClassLoaderSofaSerializerFactory.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
protected void putDeserializerToCachedType(String type, Deserializer deserializer) {
    _cachedTypeDeserializerMap.put(type, deserializer);
}
 
Example #18
Source File: SingleClassLoaderSofaSerializerFactory.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
protected Deserializer getDeserializerFromCachedType(String type) {
    return (Deserializer) _cachedTypeDeserializerMap.get(type);
}
 
Example #19
Source File: MyListSerializeFactory.java    From sofa-hessian with Apache License 2.0 4 votes vote down vote up
@Override
public Deserializer getDeserializer(String type) throws HessianProtocolException {
    return null;
}
 
Example #20
Source File: AbstractGenericSerializerFactory.java    From sofa-hessian with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the deserializer for type.
 *
 * @param type the name of the object that needs to be deserialized.
 *
 * @return a deserializer object for the serialization.
 */
abstract public Deserializer getDeserializer(String type) throws HessianProtocolException;