@Override public Object objectFromStream(DataInput stream) throws Exception { int size = IndexSerializer.VARIABLE.readInt(stream); byte[] buffer = new byte[size]; stream.readFully(buffer); if (this.factory.isUnknownForkResponse(ByteBuffer.wrap(buffer))) return NoSuchService.INSTANCE; try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(buffer))) { int version = this.versionSerializer.readInt(input); try (Unmarshaller unmarshaller = this.context.createUnmarshaller(version)) { unmarshaller.start(Marshalling.createByteInput(input)); return unmarshaller.readObject(); } } } }
private Callable<Object> read(Message message) throws Exception { try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(message.getRawBuffer(), message.getOffset(), message.getLength()))) { int version = IndexSerializer.VARIABLE.readInt(input); try (Unmarshaller unmarshaller = this.marshallingContext.createUnmarshaller(version)) { unmarshaller.start(Marshalling.createByteInput(input)); Object clientId = unmarshaller.readObject(); Optional<Object> context = this.contexts.get(clientId); if (context == null) return () -> NoSuchService.INSTANCE; @SuppressWarnings("unchecked") Command<Object, Object> command = (Command<Object, Object>) unmarshaller.readObject(); // Wrap execution result in an Optional, since command execution might return null ExceptionSupplier<Optional<Object>, Exception> task = () -> Optional.ofNullable(command.execute(context.orElse(null))); return () -> this.executor.execute(task).orElse(Optional.of(NoSuchService.INSTANCE)).orElse(null); } } }
/** * {@inheritDoc} * @see org.wildfly.clustering.marshalling.spi.MarshalledValue#get(java.lang.Object) */ @SuppressWarnings("unchecked") @Override public synchronized T get(MarshallingContext context) throws IOException, ClassNotFoundException { if (this.object == null) { this.context = context; if (this.bytes != null) { ByteArrayInputStream input = new ByteArrayInputStream(this.bytes); ClassLoader loader = setThreadContextClassLoader(this.context.getClassLoader()); try (SimpleDataInput data = new SimpleDataInput(Marshalling.createByteInput(input))) { int version = IndexSerializer.VARIABLE.readInt(data); try (Unmarshaller unmarshaller = context.createUnmarshaller(version)) { unmarshaller.start(data); this.object = (T) unmarshaller.readObject(); unmarshaller.finish(); this.bytes = null; // Free up memory } } finally { setThreadContextClassLoader(loader); } } } return this.object; }
@Override public Object objectFromStream(DataInput stream) throws Exception { int size = IndexSerializer.VARIABLE.readInt(stream); byte[] buffer = new byte[size]; stream.readFully(buffer); if (this.factory.isUnknownForkResponse(ByteBuffer.wrap(buffer))) return NoSuchService.INSTANCE; try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(buffer))) { int version = this.versionSerializer.readInt(input); try (Unmarshaller unmarshaller = this.context.createUnmarshaller(version)) { unmarshaller.start(Marshalling.createByteInput(input)); return unmarshaller.readObject(); } } } }
private Callable<Object> read(Message message) throws Exception { try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(message.getRawBuffer(), message.getOffset(), message.getLength()))) { int version = IndexSerializer.VARIABLE.readInt(input); try (Unmarshaller unmarshaller = this.marshallingContext.createUnmarshaller(version)) { unmarshaller.start(Marshalling.createByteInput(input)); Object clientId = unmarshaller.readObject(); Optional<Object> context = this.contexts.get(clientId); if (context == null) return () -> NoSuchService.INSTANCE; @SuppressWarnings("unchecked") Command<Object, Object> command = (Command<Object, Object>) unmarshaller.readObject(); // Wrap execution result in an Optional, since command execution might return null ExceptionSupplier<Optional<Object>, Exception> task = () -> Optional.ofNullable(command.execute(context.orElse(null))); return () -> this.executor.execute(task).orElse(Optional.of(NoSuchService.INSTANCE)).orElse(null); } } }
/** * {@inheritDoc} * @see org.wildfly.clustering.marshalling.spi.MarshalledValue#get(java.lang.Object) */ @SuppressWarnings("unchecked") @Override public synchronized T get(MarshallingContext context) throws IOException, ClassNotFoundException { if (this.object == null) { this.context = context; if (this.bytes != null) { ByteArrayInputStream input = new ByteArrayInputStream(this.bytes); ClassLoader loader = setThreadContextClassLoader(this.context.getClassLoader()); try (SimpleDataInput data = new SimpleDataInput(Marshalling.createByteInput(input))) { int version = IndexSerializer.VARIABLE.readInt(data); try (Unmarshaller unmarshaller = context.createUnmarshaller(version)) { unmarshaller.start(data); this.object = (T) unmarshaller.readObject(); unmarshaller.finish(); this.bytes = null; // Free up memory } } finally { setThreadContextClassLoader(loader); } } } return this.object; }