Search in sources :

Example 1 with Unmarshaller

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

the class EjbTimerXmlParser_1_0 method deserialize.

private Object deserialize(final String info) throws IOException, ClassNotFoundException {
    byte[] data = Base64.getDecoder().decode(info.trim());
    Unmarshaller unmarshaller = factory.createUnmarshaller(configuration);
    unmarshaller.start(new ByteBufferInput(ByteBuffer.wrap(data)));
    try {
        return unmarshaller.readObject();
    } finally {
        unmarshaller.close();
    }
}
Also used : ByteBufferInput(org.jboss.marshalling.ByteBufferInput) Unmarshaller(org.jboss.marshalling.Unmarshaller)

Example 2 with Unmarshaller

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

the class SimpleMarshalledValue method get.

/**
     * {@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 = IndexExternalizer.VARIABLE.readData(data);
                try (Unmarshaller unmarshaller = context.createUnmarshaller(version)) {
                    unmarshaller.start(data);
                    this.object = (T) unmarshaller.readObject();
                    unmarshaller.finish();
                    // Free up memory
                    this.bytes = null;
                }
            } finally {
                setThreadContextClassLoader(loader);
            }
        }
    }
    return this.object;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Unmarshaller(org.jboss.marshalling.Unmarshaller) SimpleDataInput(org.jboss.marshalling.SimpleDataInput)

Example 3 with Unmarshaller

use of org.jboss.marshalling.Unmarshaller in project workflow-cps-plugin by jenkinsci.

the class CpsFlowExecution method loadProgramAsync.

/**
 * Deserializes {@link CpsThreadGroup} from {@link #getProgramDataFile()} if necessary.
 *
 * This moves us into the PREPARING state.
 * @param programDataFile
 */
public void loadProgramAsync(File programDataFile) {
    final SettableFuture<CpsThreadGroup> result = SettableFuture.create();
    programPromise = result;
    try {
        scriptClass = parseScript().getClass();
        final RiverReader r = new RiverReader(programDataFile, scriptClass.getClassLoader(), owner);
        Futures.addCallback(r.restorePickles(pickleFutures = new ArrayList<>()), new FutureCallback<Unmarshaller>() {

            public void onSuccess(Unmarshaller u) {
                pickleFutures = null;
                try {
                    CpsFlowExecution old = PROGRAM_STATE_SERIALIZATION.get();
                    PROGRAM_STATE_SERIALIZATION.set(CpsFlowExecution.this);
                    try {
                        CpsThreadGroup g = (CpsThreadGroup) u.readObject();
                        result.set(g);
                        try {
                            if (g.isPaused()) {
                                owner.getListener().getLogger().println("Still paused");
                            } else {
                                owner.getListener().getLogger().println("Ready to run at " + new Date());
                                // In case we last paused execution due to Jenkins.isQuietingDown, make sure we do something after we restart.
                                g.scheduleRun();
                            }
                        } catch (IOException x) {
                            LOGGER.log(Level.WARNING, null, x);
                        }
                    } catch (Throwable t) {
                        onFailure(t);
                    } finally {
                        PROGRAM_STATE_SERIALIZATION.set(old);
                    }
                } finally {
                    r.close();
                }
            }

            public void onFailure(Throwable t) {
                // Note: not calling result.setException(t) since loadProgramFailed in fact sets a result
                try {
                    loadProgramFailed(t, result);
                } finally {
                    r.close();
                }
            }
        });
    } catch (Exception | GroovyBugError e) {
        loadProgramFailed(e, result);
    }
}
Also used : GroovyBugError(org.codehaus.groovy.GroovyBugError) IOException(java.io.IOException) Date(java.util.Date) UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) AbortException(hudson.AbortException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) FlowInterruptedException(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException) RiverReader(org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverReader) Unmarshaller(org.jboss.marshalling.Unmarshaller)

Example 4 with Unmarshaller

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

the class CompatibleMarshallingDecoder method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
    if (discardingTooLongFrame) {
        buffer.skipBytes(actualReadableBytes());
        checkpoint();
        return;
    }
    Unmarshaller unmarshaller = provider.getUnmarshaller(ctx);
    ByteInput input = new ChannelBufferByteInput(buffer);
    if (maxObjectSize != Integer.MAX_VALUE) {
        input = new LimitingByteInput(input, maxObjectSize);
    }
    try {
        unmarshaller.start(input);
        Object obj = unmarshaller.readObject();
        unmarshaller.finish();
        out.add(obj);
    } catch (LimitingByteInput.TooBigObjectException ignored) {
        discardingTooLongFrame = true;
        throw new TooLongFrameException();
    } 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 : TooLongFrameException(io.netty.handler.codec.TooLongFrameException) ByteInput(org.jboss.marshalling.ByteInput) Unmarshaller(org.jboss.marshalling.Unmarshaller)

Example 5 with Unmarshaller

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

the class ThreadLocalUnmarshallerProvider method getUnmarshaller.

@Override
public Unmarshaller getUnmarshaller(ChannelHandlerContext ctx) throws Exception {
    Unmarshaller unmarshaller = unmarshallers.get();
    if (unmarshaller == null) {
        unmarshaller = factory.createUnmarshaller(config);
        unmarshallers.set(unmarshaller);
    }
    return unmarshaller;
}
Also used : Unmarshaller(org.jboss.marshalling.Unmarshaller)

Aggregations

Unmarshaller (org.jboss.marshalling.Unmarshaller)15 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 InputStreamByteInput (org.jboss.marshalling.InputStreamByteInput)4 ByteBuf (io.netty.buffer.ByteBuf)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ByteBufferInput (org.jboss.marshalling.ByteBufferInput)2 ByteInput (org.jboss.marshalling.ByteInput)2 SimpleDataInput (org.jboss.marshalling.SimpleDataInput)2 AbortException (hudson.AbortException)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)1 DataInputStream (java.io.DataInputStream)1 InputStream (java.io.InputStream)1 InvalidClassException (java.io.InvalidClassException)1 Optional (java.util.Optional)1