Search in sources :

Example 11 with Unmarshaller

use of org.jboss.marshalling.Unmarshaller in project wildfly by wildfly.

the class ChannelCommandDispatcherFactory method handle.

@Override
public Object handle(Message message) throws Exception {
    try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(message.getRawBuffer(), message.getOffset(), message.getLength()))) {
        int version = IndexExternalizer.VARIABLE.readData(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();
            Callable<Optional<Object>> task = new Callable<Optional<Object>>() {

                @Override
                public Optional<Object> call() throws Exception {
                    // Wrap in an Optional, since command execution might return null
                    return Optional.ofNullable(command.execute(context.orElse(null)));
                }
            };
            return this.executor.execute(task).orElse(Optional.of(NoSuchService.INSTANCE)).orElse(null);
        }
    }
}
Also used : Optional(java.util.Optional) ByteArrayInputStream(java.io.ByteArrayInputStream) Command(org.wildfly.clustering.dispatcher.Command) DataInputStream(java.io.DataInputStream) Unmarshaller(org.jboss.marshalling.Unmarshaller) Callable(java.util.concurrent.Callable)

Example 12 with Unmarshaller

use of org.jboss.marshalling.Unmarshaller in project wildfly by wildfly.

the class DiskBasedModularPersistentSessionManager method loadSerializedSessions.

@Override
protected Map<String, SessionEntry> loadSerializedSessions(String deploymentName) throws IOException {
    File file = new File(baseDir, deploymentName);
    if (!file.exists()) {
        return null;
    }
    FileInputStream in = new FileInputStream(file);
    try {
        Unmarshaller unMarshaller = createUnmarshaller();
        try {
            try {
                unMarshaller.start(new InputStreamByteInput(in));
                return (Map<String, SessionEntry>) unMarshaller.readObject();
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            } finally {
                unMarshaller.finish();
            }
        } finally {
            unMarshaller.close();
        }
    } finally {
        IoUtils.safeClose(in);
    }
}
Also used : InputStreamByteInput(org.jboss.marshalling.InputStreamByteInput) Unmarshaller(org.jboss.marshalling.Unmarshaller) File(java.io.File) Map(java.util.Map) FileInputStream(java.io.FileInputStream)

Example 13 with Unmarshaller

use of org.jboss.marshalling.Unmarshaller in project wildfly by wildfly.

the class EjbCorbaServant method unmarshalIdentifier.

private Object unmarshalIdentifier() throws IOException, ClassNotFoundException {
    final Object id;
    try {
        final byte[] idData = poaCurrent.get_object_id();
        final Unmarshaller unmarshaller = factory.createUnmarshaller(configuration);
        unmarshaller.start(new InputStreamByteInput(new ByteArrayInputStream(idData)));
        id = unmarshaller.readObject();
        unmarshaller.finish();
    } catch (NoContext noContext) {
        throw new RuntimeException(noContext);
    }
    return id;
}
Also used : NoContext(org.omg.PortableServer.CurrentPackage.NoContext) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStreamByteInput(org.jboss.marshalling.InputStreamByteInput) Unmarshaller(org.jboss.marshalling.Unmarshaller)

Aggregations

Unmarshaller (org.jboss.marshalling.Unmarshaller)13 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStreamByteInput (org.jboss.marshalling.InputStreamByteInput)4 IOException (java.io.IOException)3 ByteBuf (io.netty.buffer.ByteBuf)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ByteBufferInput (org.jboss.marshalling.ByteBufferInput)2 ByteInput (org.jboss.marshalling.ByteInput)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)1 DataInputStream (java.io.DataInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 Optional (java.util.Optional)1 Callable (java.util.concurrent.Callable)1 TimerImpl (org.jboss.as.ejb3.timerservice.TimerImpl)1