Search in sources :

Example 36 with DataStructure

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure in project fabric8 by jboss-fuse.

the class ConsumerControlMarshaller method looseMarshal.

/**
 * Write the booleans that this object uses to a BooleanStream
 */
public void looseMarshal(OpenWireFormat wireFormat, Object o, DataByteArrayOutputStream dataOut) throws IOException {
    ConsumerControl info = (ConsumerControl) o;
    super.looseMarshal(wireFormat, o, dataOut);
    dataOut.writeBoolean(info.isClose());
    looseMarshalNestedObject(wireFormat, (DataStructure) info.getConsumerId(), dataOut);
    dataOut.writeInt(info.getPrefetch());
}
Also used : ConsumerControl(io.fabric8.gateway.handlers.detecting.protocol.openwire.command.ConsumerControl)

Example 37 with DataStructure

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure in project fabric8 by jboss-fuse.

the class OpenWireFormat method looseUnmarshalNestedObject.

public DataStructure looseUnmarshalNestedObject(DataByteArrayInputStream dis) throws IOException {
    if (dis.readBoolean()) {
        byte dataType = dis.readByte();
        DataStreamMarshaller dsm = (DataStreamMarshaller) dataMarshallers[dataType & 0xFF];
        if (dsm == null) {
            throw new IOException("Unknown data type: " + dataType);
        }
        DataStructure data = dsm.createObject();
        dsm.looseUnmarshal(this, data, dis);
        return data;
    } else {
        return null;
    }
}
Also used : DataStructure(io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure) IOException(java.io.IOException)

Example 38 with DataStructure

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure in project fabric8 by jboss-fuse.

the class OpenWireFormat method marshal.

public synchronized Buffer marshal(Object command) throws IOException {
    if (cacheEnabled) {
        runMarshallCacheEvictionSweep();
    }
    // MarshallAware ma = null;
    // // If not using value caching, then the marshaled form is always the
    // // same
    // if (!cacheEnabled && ((DataStructure)command).isMarshallAware()) {
    // ma = (MarshallAware)command;
    // }
    Buffer sequence = null;
    if (sequence == null) {
        int size = 1;
        if (command != null) {
            DataStructure c = (DataStructure) command;
            byte type = c.getDataStructureType();
            DataStreamMarshaller dsm = (DataStreamMarshaller) dataMarshallers[type & 0xFF];
            if (dsm == null) {
                throw new IOException("Unknown data type: " + type);
            }
            if (tightEncodingEnabled) {
                BooleanStream bs = new BooleanStream();
                size += dsm.tightMarshal1(this, c, bs);
                size += bs.marshalledSize();
                bytesOut.restart(size);
                if (!sizePrefixDisabled) {
                    bytesOut.writeInt(size);
                }
                bytesOut.writeByte(type);
                bs.marshal(bytesOut);
                dsm.tightMarshal2(this, c, bytesOut, bs);
                sequence = bytesOut.toBuffer();
            } else {
                bytesOut.restart();
                if (!sizePrefixDisabled) {
                    // we don't know the final size
                    bytesOut.writeInt(0);
                // yet but write this here for
                // now.
                }
                bytesOut.writeByte(type);
                dsm.looseMarshal(this, c, bytesOut);
                sequence = bytesOut.toBuffer();
                if (!sizePrefixDisabled) {
                    size = sequence.getLength() - 4;
                    int pos = sequence.offset;
                    sequence.offset = 0;
                    BufferEditor.big(sequence).writeInt(size);
                    sequence.offset = pos;
                }
            }
        } else {
            bytesOut.restart(5);
            bytesOut.writeInt(size);
            bytesOut.writeByte(NULL_TYPE);
            sequence = bytesOut.toBuffer();
        }
    // if( ma!=null ) {
    // ma.setCachedMarshalledForm(this, sequence);
    // }
    }
    return sequence;
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) DataStructure(io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure) IOException(java.io.IOException)

Example 39 with DataStructure

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure in project fabric8 by jboss-fuse.

the class OpenWireFormat method marshal.

public synchronized void marshal(Object o, DataByteArrayOutputStream dataOut) throws IOException {
    if (cacheEnabled) {
        runMarshallCacheEvictionSweep();
    }
    int size = 1;
    if (o != null) {
        DataStructure c = (DataStructure) o;
        byte type = c.getDataStructureType();
        DataStreamMarshaller dsm = (DataStreamMarshaller) dataMarshallers[type & 0xFF];
        if (dsm == null) {
            throw new IOException("Unknown data type: " + type);
        }
        if (tightEncodingEnabled) {
            BooleanStream bs = new BooleanStream();
            size += dsm.tightMarshal1(this, c, bs);
            size += bs.marshalledSize();
            if (!sizePrefixDisabled) {
                dataOut.writeInt(size);
            }
            dataOut.writeByte(type);
            bs.marshal(dataOut);
            dsm.tightMarshal2(this, c, dataOut, bs);
        } else {
            DataByteArrayOutputStream looseOut = dataOut;
            if (!sizePrefixDisabled) {
                bytesOut.restart();
                looseOut = bytesOut;
            }
            looseOut.writeByte(type);
            dsm.looseMarshal(this, c, looseOut);
            if (!sizePrefixDisabled) {
                Buffer sequence = bytesOut.toBuffer();
                dataOut.writeInt(sequence.getLength());
                dataOut.write(sequence.getData(), sequence.getOffset(), sequence.getLength());
            }
        }
    } else {
        if (!sizePrefixDisabled) {
            dataOut.writeInt(size);
        }
        dataOut.writeByte(NULL_TYPE);
    }
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) DataByteArrayOutputStream(org.fusesource.hawtbuf.DataByteArrayOutputStream) DataStructure(io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure) IOException(java.io.IOException)

Example 40 with DataStructure

use of io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure in project fabric8 by jboss-fuse.

the class OpenWireFormat method tightMarshal2.

/**
 * Used by NIO or AIO transports; note that the size is not written as part
 * of this method.
 */
public void tightMarshal2(Object o, DataByteArrayOutputStream ds, BooleanStream bs) throws IOException {
    if (cacheEnabled) {
        runMarshallCacheEvictionSweep();
    }
    if (o != null) {
        DataStructure c = (DataStructure) o;
        byte type = c.getDataStructureType();
        DataStreamMarshaller dsm = (DataStreamMarshaller) dataMarshallers[type & 0xFF];
        if (dsm == null) {
            throw new IOException("Unknown data type: " + type);
        }
        ds.writeByte(type);
        bs.marshal(ds);
        dsm.tightMarshal2(this, c, ds, bs);
    }
}
Also used : DataStructure(io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure) IOException(java.io.IOException)

Aggregations

DataStructure (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure)30 IOException (java.io.IOException)7 Message (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.Message)6 DataResponse (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataResponse)5 RemoveInfo (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.RemoveInfo)5 BrokerInfo (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.BrokerInfo)3 ConnectionError (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.ConnectionError)3 ConnectionInfo (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.ConnectionInfo)3 ConsumerControl (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.ConsumerControl)3 ConsumerInfo (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.ConsumerInfo)3 DestinationInfo (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DestinationInfo)3 LocalTransactionId (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.LocalTransactionId)3 MessageAck (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.MessageAck)3 MessageDispatch (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.MessageDispatch)3 MessageDispatchNotification (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.MessageDispatchNotification)3 MessageId (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.MessageId)3 NetworkBridgeFilter (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.NetworkBridgeFilter)3 ProducerInfo (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.ProducerInfo)3 RemoveSubscriptionInfo (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.RemoveSubscriptionInfo)3 SessionInfo (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.SessionInfo)3