Search in sources :

Example 6 with Unmarshaller

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

the class AbstractPersistentSessionManager method loadSessionAttributes.

@Override
public Map<String, PersistentSession> loadSessionAttributes(String deploymentName, final ClassLoader classLoader) {
    try {
        Unmarshaller unmarshaller = createUnmarshaller();
        try {
            long time = System.currentTimeMillis();
            Map<String, SessionEntry> data = loadSerializedSessions(deploymentName);
            if (data != null) {
                Map<String, PersistentSession> ret = new HashMap<String, PersistentSession>();
                for (Map.Entry<String, SessionEntry> sessionEntry : data.entrySet()) {
                    if (sessionEntry.getValue().expiry.getTime() > time) {
                        Map<String, Object> session = new HashMap<String, Object>();
                        for (Map.Entry<String, byte[]> sessionAttribute : sessionEntry.getValue().data.entrySet()) {
                            unmarshaller.start(new ByteBufferInput(ByteBuffer.wrap(sessionAttribute.getValue())));
                            session.put(sessionAttribute.getKey(), unmarshaller.readObject());
                            unmarshaller.finish();
                        }
                        ret.put(sessionEntry.getKey(), new PersistentSession(sessionEntry.getValue().expiry, session));
                    }
                }
                return ret;
            }
        } finally {
            unmarshaller.close();
        }
    } catch (Exception e) {
        UndertowServletLogger.ROOT_LOGGER.failedtoLoadPersistentSessions(e);
    }
    return null;
}
Also used : HashMap(java.util.HashMap) StartException(org.jboss.msc.service.StartException) IOException(java.io.IOException) ByteBufferInput(org.jboss.marshalling.ByteBufferInput) Unmarshaller(org.jboss.marshalling.Unmarshaller) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with Unmarshaller

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

the class ContextBoundUnmarshallerProvider method getUnmarshaller.

@Override
public Unmarshaller getUnmarshaller(ChannelHandlerContext ctx) throws Exception {
    Attribute<Unmarshaller> attr = ctx.attr(UNMARSHALLER);
    Unmarshaller unmarshaller = attr.get();
    if (unmarshaller == null) {
        unmarshaller = super.getUnmarshaller(ctx);
        attr.set(unmarshaller);
    }
    return unmarshaller;
}
Also used : Unmarshaller(org.jboss.marshalling.Unmarshaller)

Example 8 with Unmarshaller

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

the class MarshallingDecoder method decode.

@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    ByteBuf frame = (ByteBuf) super.decode(ctx, in);
    if (frame == null) {
        return null;
    }
    Unmarshaller unmarshaller = provider.getUnmarshaller(ctx);
    ByteInput input = new ChannelBufferByteInput(frame);
    try {
        unmarshaller.start(input);
        Object obj = unmarshaller.readObject();
        unmarshaller.finish();
        return obj;
    } finally {
        // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are
        // readable. This helps to be sure that we do not leak resource
        unmarshaller.close();
    }
}
Also used : ByteInput(org.jboss.marshalling.ByteInput) ByteBuf(io.netty.buffer.ByteBuf) Unmarshaller(org.jboss.marshalling.Unmarshaller)

Example 9 with Unmarshaller

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

the class AbstractCompatibleMarshallingEncoderTest method testMarshalling.

@Test
public void testMarshalling() throws Exception {
    @SuppressWarnings("RedundantStringConstructorCall") String testObject = new String("test");
    final MarshallerFactory marshallerFactory = createMarshallerFactory();
    final MarshallingConfiguration configuration = createMarshallingConfig();
    EmbeddedChannel ch = new EmbeddedChannel(createEncoder());
    ch.writeOutbound(testObject);
    assertTrue(ch.finish());
    ByteBuf buffer = ch.readOutbound();
    Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
    unmarshaller.start(Marshalling.createByteInput(truncate(buffer).nioBuffer()));
    String read = (String) unmarshaller.readObject();
    assertEquals(testObject, read);
    assertEquals(-1, unmarshaller.read());
    assertNull(ch.readOutbound());
    unmarshaller.finish();
    unmarshaller.close();
    buffer.release();
}
Also used : MarshallerFactory(org.jboss.marshalling.MarshallerFactory) MarshallingConfiguration(org.jboss.marshalling.MarshallingConfiguration) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) Unmarshaller(org.jboss.marshalling.Unmarshaller) Test(org.junit.Test)

Example 10 with Unmarshaller

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

the class DatabaseTimerPersistence method deSerialize.

public Object deSerialize(final String data) throws SQLException {
    if (data == null) {
        return null;
    }
    InputStream in = new ByteArrayInputStream(Base64.getDecoder().decode(data));
    try {
        final Unmarshaller unmarshaller = factory.createUnmarshaller(configuration);
        unmarshaller.start(new InputStreamByteInput(in));
        Object ret = unmarshaller.readObject();
        unmarshaller.finish();
        return ret;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    } finally {
        safeClose(in);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamByteInput(org.jboss.marshalling.InputStreamByteInput) IOException(java.io.IOException) 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