Search in sources :

Example 11 with Marshaller

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

the class CommandDispatcherMarshaller method marshal.

@Override
public <R> byte[] marshal(Command<R, ? super C> command) throws IOException {
    int version = this.context.getCurrentVersion();
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    try (DataOutputStream output = new DataOutputStream(bytes)) {
        IndexExternalizer.VARIABLE.writeData(output, version);
        try (Marshaller marshaller = this.context.createMarshaller(version)) {
            marshaller.start(Marshalling.createByteOutput(output));
            marshaller.writeObject(this.id);
            marshaller.writeObject(command);
            marshaller.flush();
        }
        return bytes.toByteArray();
    }
}
Also used : Marshaller(org.jboss.marshalling.Marshaller) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 12 with Marshaller

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

the class CommandResponseMarshaller method objectToBuffer.

@Override
public Buffer objectToBuffer(Object object) throws Exception {
    int version = this.context.getCurrentVersion();
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    try (DataOutputStream output = new DataOutputStream(bytes)) {
        IndexExternalizer.VARIABLE.writeData(output, version);
        try (Marshaller marshaller = this.context.createMarshaller(version)) {
            marshaller.start(Marshalling.createByteOutput(output));
            marshaller.writeObject(object);
            marshaller.flush();
        }
    }
    return new Buffer(bytes.toByteArray());
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(org.jgroups.util.Buffer) Marshaller(org.jboss.marshalling.Marshaller) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 13 with Marshaller

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

the class EjbTimerXmlPersister method writeTimer.

private void writeTimer(XMLExtendedStreamWriter writer, TimerImpl timer) throws XMLStreamException {
    String info = null;
    String primaryKey = null;
    if (timer.getInfo() != null) {
        try {
            Marshaller marshaller = factory.createMarshaller(configuration);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            marshaller.start(new OutputStreamByteOutput(out));
            marshaller.writeObject(timer.getInfo());
            marshaller.finish();
            marshaller.flush();
            info = Base64.getEncoder().encodeToString(out.toByteArray());
        } catch (Exception e) {
            EjbLogger.EJB3_TIMER_LOGGER.failedToPersistTimer(timer, e);
            return;
        }
    }
    if (timer.getPrimaryKey() != null) {
        try {
            Marshaller marshaller = factory.createMarshaller(configuration);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            marshaller.start(new OutputStreamByteOutput(out));
            marshaller.writeObject(timer.getPrimaryKey());
            marshaller.finish();
            marshaller.flush();
            primaryKey = Base64.getEncoder().encodeToString(out.toByteArray());
        } catch (Exception e) {
            EjbLogger.EJB3_TIMER_LOGGER.failedToPersistTimer(timer, e);
            return;
        }
    }
    writer.writeStartElement(TIMER);
    writer.writeAttribute(TIMED_OBJECT_ID, timer.getTimedObjectId());
    writer.writeAttribute(TIMER_ID, timer.getId());
    writer.writeAttribute(INITIAL_DATE, Long.toString(timer.getInitialExpiration().getTime()));
    writer.writeAttribute(REPEAT_INTERVAL, Long.toString(timer.getInterval()));
    if (timer.getNextExpiration() != null) {
        writer.writeAttribute(NEXT_DATE, Long.toString(timer.getNextExpiration().getTime()));
    }
    writer.writeAttribute(TIMER_STATE, timer.getState().name());
    if (info != null) {
        writer.writeStartElement(INFO);
        writer.writeCharacters(info);
        writer.writeEndElement();
    }
    if (primaryKey != null) {
        writer.writeStartElement(PRIMARY_KEY);
        writer.writeCharacters(primaryKey);
        writer.writeEndElement();
    }
    writer.writeEndElement();
}
Also used : Marshaller(org.jboss.marshalling.Marshaller) OutputStreamByteOutput(org.jboss.marshalling.OutputStreamByteOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 14 with Marshaller

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

the class DatabaseTimerPersistence method serialize.

private String serialize(final Serializable serializable) {
    if (serializable == null) {
        return null;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        final Marshaller marshaller = factory.createMarshaller(configuration);
        marshaller.start(new OutputStreamByteOutput(out));
        marshaller.writeObject(serializable);
        marshaller.finish();
        out.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return Base64.getEncoder().encodeToString(out.toByteArray());
}
Also used : Marshaller(org.jboss.marshalling.Marshaller) OutputStreamByteOutput(org.jboss.marshalling.OutputStreamByteOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 15 with Marshaller

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

the class SimpleMarshalledValue method getBytes.

byte[] getBytes() throws IOException {
    byte[] bytes = this.bytes;
    if (bytes != null)
        return bytes;
    if (this.object == null)
        return null;
    int version = this.context.getCurrentVersion();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ClassLoader loader = setThreadContextClassLoader(this.context.getClassLoader());
    try (SimpleDataOutput data = new SimpleDataOutput(Marshalling.createByteOutput(output))) {
        IndexExternalizer.VARIABLE.writeData(data, version);
        try (Marshaller marshaller = this.context.createMarshaller(version)) {
            marshaller.start(data);
            marshaller.writeObject(this.object);
            marshaller.finish();
            return output.toByteArray();
        }
    } finally {
        setThreadContextClassLoader(loader);
    }
}
Also used : Marshaller(org.jboss.marshalling.Marshaller) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleDataOutput(org.jboss.marshalling.SimpleDataOutput)

Aggregations

Marshaller (org.jboss.marshalling.Marshaller)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 OutputStreamByteOutput (org.jboss.marshalling.OutputStreamByteOutput)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)3 MarshallerFactory (org.jboss.marshalling.MarshallerFactory)3 MarshallingConfiguration (org.jboss.marshalling.MarshallingConfiguration)3 Test (org.junit.Test)3 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 StartException (org.jboss.msc.service.StartException)2 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandler (io.netty.channel.ChannelHandler)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PortableRemoteObject (javax.rmi.PortableRemoteObject)1 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)1