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();
}
}
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());
}
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();
}
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());
}
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);
}
}
Aggregations