/** * Constructs an optionally locked clusterable serialization strategy. * <p> * Non-locked instances can be used to provider tighter over lock scoping, and * associated transaction scoping when serialization strategies are being used * within operations that are intended to be atomic. * * @param internalLocking {@code true} if internal locking should be applied */ public DsoSerializationStrategy(boolean internalLocking) { oscSerializer = new ObjectStreamClassSerializer(internalLocking); }
void forceSlowLookup() { this.oscSerializer.forceSlowLookup(); }
@Override protected void writeClassDescriptor(final ObjectStreamClass desc) throws IOException { int code = oscSerializer.getMappingFor(desc); encodeInt(this, code); } }
ObjectStreamClassSerializer(boolean locked) { this.locked = locked; if (locked) { mappings = new ConcurrentDistributedMap<Object, Object>(); } else { mappings = new ConcurrentDistributedMap<Object, Object>(LockType.WRITE, new NullLockStrategy<Object>()); } initialize(); }
private Integer addMapping(ObjectStreamClass desc) throws IOException { SerializableDataKey key = new SerializableDataKey(desc); Integer value = Integer.valueOf(nextMapping++); put(value, key.getSerializedOsc()); put(key, value); /* * We could populate the local cache of ObjectStreamClass descriptors here, it will only help performance on the * first deserialization of the associated class though, and forcing the ObjectStreamClass to go through a * serialization pass helps provide some insurance that everything is working correctly. */ return value; }
@Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { int code = decodeInt(this); if (localOnly) { ObjectStreamClass osc = oscSerializer.localGetObjectStreamClassFor(code); if (osc == null) { throw new ObjectStreamClassNotLocalException(); } return osc; } else { return oscSerializer.getObjectStreamClassFor(code, loader); } }
@Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { int code = decodeInt(this); return oscSerializer.getObjectStreamClassFor(code, loader); }
public int getMappingFor(ObjectStreamClass desc) throws IOException { desc = prune(desc); ComparisonSerializableDataKey key = new ComparisonSerializableDataKey(desc); Integer value = (Integer) mappings.unsafeGet(key); if (value != null) { return value.intValue(); } if (locked) ManagerUtil.monitorEnter(writeLock, Manager.LOCK_TYPE_WRITE); try { value = (Integer) mappings.get(key); if (value != null) { return value.intValue(); } value = addMapping(desc); } finally { if (locked) ManagerUtil.monitorExit(writeLock, Manager.LOCK_TYPE_WRITE); } return value.intValue(); }
@Override protected void writeClassDescriptor(final ObjectStreamClass desc) throws IOException { int code = oscSerializer.getMappingFor(desc); encodeInt(this, code); } }
ObjectStreamClassSerializer(boolean locked) { this.locked = locked; if (locked) { mappings = new ConcurrentDistributedMap<String, Object>(); } else { mappings = new ConcurrentDistributedMap<String, Object>(LockType.WRITE, new NullLockStrategy<String>()); } initialize(); }
private Integer addMapping(ObjectStreamClass desc) throws IOException { SerializableDataKey key = new SerializableDataKey(desc); Integer value = Integer.valueOf(nextMapping++); put(key, value); put(value, key.getSerializedOsc()); /* * We could populate the local cache of ObjectStreamClass descriptors here, * it will only help performance on the first deserialization of the * associated class though, and forcing the ObjectStreamClass to go through * a serialization pass helps provide some insurance that everything is * working correctly. */ return value; }
@Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { int code = decodeInt(this); return oscSerializer.getObjectStreamClassFor(code, loader); }
public int getMappingFor(ObjectStreamClass desc) throws IOException { desc = prune(desc); ComparisonSerializableDataKey key = new ComparisonSerializableDataKey(desc); Integer value = (Integer) mappings.unsafeGet(key); if (value != null) { return value.intValue(); } if (locked) ManagerUtil.monitorEnter(writeLock, Manager.LOCK_TYPE_WRITE); try { value = (Integer) mappings.get(key); if (value != null) { return value.intValue(); } value = addMapping(desc); } finally { if (locked) ManagerUtil.monitorExit(writeLock, Manager.LOCK_TYPE_WRITE); } return value.intValue(); }
@Override protected void writeClassDescriptor(final ObjectStreamClass desc) throws IOException { String name = desc.getName(); int code = oscSerializer.getMappingFor(name); encodeInt(this, code); } }
ObjectStreamClassSerializer(boolean locked) { this.locked = locked; if (locked) { mappings = new ConcurrentDistributedMap<Object, Object>(); } else { mappings = new ConcurrentDistributedMap<Object, Object>(LockType.WRITE, new NullLockStrategy<Object>()); } initialize(); }
public int getMappingFor(String className) { Integer value = (Integer) mappings.unsafeGet(className); if (value != null) { return value.intValue(); } if (locked) ManagerUtil.monitorEnter(writeLock, Manager.LOCK_TYPE_WRITE); try { value = (Integer) mappings.get(className); if (value != null) { return value.intValue(); } value = Integer.valueOf(nextMapping++); // insert two-way mapping exploiting the fact that className can never start with a digit put(className, value); put(value.toString(), className); } finally { if (locked) ManagerUtil.monitorExit(writeLock, Manager.LOCK_TYPE_WRITE); } return value.intValue(); }
/** * Constructs an optionally locked clusterable serialization strategy. * <p> * Non-locked instances can be used to provider tighter over lock scoping, and associated transaction scoping when * serialization strategies are being used within operations that are intended to be atomic. * * @param internalLocking * {@code true} if internal locking should be applied */ public DsoSerializationStrategy(boolean internalLocking) { oscSerializer = new ObjectStreamClassSerializer(internalLocking); }
@Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { int code = decodeInt(this); return oscSerializer.getObjectStreamClassFor(code, loader); }
void forceSlowLookup() { this.oscSerializer.forceSlowLookup(); }
@Override protected void writeClassDescriptor(final ObjectStreamClass desc) throws IOException { String name = desc.getName(); int code = oscSerializer.getMappingFor(name); encodeInt(this, code); } }