/** * {@inhericDoc} * @see org.jboss.ha.framework.server.HAServiceImpl#getReplicant() */ protected Serializable getReplicant() { return new SimpleCachableMarshalledValue(this.drmEntry); }
@Override public synchronized byte[] toByteArray() throws IOException { if (serializedForm == null) { serializedForm = serialize(); } raw = null; return serializedForm; }
/** * {@inheritDoc} * @see org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller#unmarshal(java.lang.Object) */ @Override public Object unmarshal(Object object) throws IOException, ClassNotFoundException { if ((object == null) || !(object instanceof SimpleCachableMarshalledValue)) return object; SimpleCachableMarshalledValue value = (SimpleCachableMarshalledValue) object; // Swap in/out the class loader for this web app. Needed only for unmarshalling. ContextClassLoaderSwitcher.SwitchContext switchContext = this.switcher.getSwitchContext(this.manager.getApplicationClassLoader()); try { value.setObjectStreamSource(this.source); return value.get(); } finally { switchContext.reset(); } } }
SimpleCachableMarshalledValue mv = (SimpleCachableMarshalledValue) attributes_ois.readObject(); attributes = uncheckedCast(mv.get());
@Override public synchronized Serializable get() throws IOException, ClassNotFoundException { if (raw == null) { if (serializedForm != null) { ByteArrayInputStream bais = new ByteArrayInputStream(serializedForm); ObjectInput mvis = getObjectStreamSource().getObjectInput(bais); try { raw = (Serializable) mvis.readObject(); serializedForm = null; } finally { mvis.close(); } } } return raw; }
private byte[] serialize() throws IOException { byte[] result = serializedForm; if (result == null) { if (raw != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutput mvos = getObjectStreamSource().getObjectOutput(baos); mvos.writeObject(raw); mvos.flush(); try { result = baos.toByteArray(); } finally { mvos.close(); } } } return result; } }
private Serializable createReplicant(ModClusterServiceDRMEntry entry) { return new SimpleCachableMarshalledValue(entry); }
/** * The object implements the writeExternal method to save its contents * by calling the methods of DataOutput for its primitive values or * calling the writeObject method of ObjectOutput for objects, strings, * and arrays. * * @serialData Overriding methods should use this tag to describe * the data layout of this Externalizable object. * List the sequence of element types and, if possible, * relate the element to a public/protected field and/or * method of this Externalizable class. * * @param out the stream to write the object to * * @throws IOException Includes any I/O exceptions that may occur */ @Override public synchronized void writeExternal(ObjectOutput out) throws IOException { byte[] bytes = serialize(); int length = bytes != null ? bytes.length : 0; out.writeInt(length); if( length > 0 ) { out.write(bytes); } out.writeInt(hashCode); }
/** * {@inheritDoc} * @see org.jboss.web.tomcat.service.session.distributedcache.spi.SessionAttributeMarshaller#marshal(java.lang.Object) */ @Override public Object marshal(Object value) { if ((value == null) || MarshalledValueHelper.isTypeExcluded(value.getClass())) return value; if (!(value instanceof Serializable)) { throw new IllegalArgumentException(String.format("%s does not implement %s", value, Serializable.class.getName())); } return new SimpleCachableMarshalledValue((Serializable) value, this.source, true); }
protected RDBMSStoreBase() { try { Object empty = new SimpleCachableMarshalledValue(new HashMap<String, Object>()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(empty); oos.close(); emptyAttributes = baos.toByteArray(); } catch (IOException e) { throw new RuntimeException("Cannot serialize simple HashMap"); } }
private byte[] writeSessionAttributes(OutgoingSessionGranularitySessionData session) throws IOException { Map<String, Object> attrs = session.getSessionAttributes(); if (attrs == null) { return null; } ObjectOutputStream oos = null; ByteArrayOutputStream bos = null; try { bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(new BufferedOutputStream(bos)); oos.writeObject(new SimpleCachableMarshalledValue((Serializable) attrs)); oos.close(); return bos.toByteArray(); } finally { if (oos != null) { oos.close(); } if (bos != null) { bos.close(); } } }