Search in sources :

Example 11 with Buffer

use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.

the class LengthPrefixedCodecTest method testWrite$Twice.

@Test
public void testWrite$Twice() throws Exception {
    final Buffer value1 = Buffer.ascii("TESTDATA");
    final Buffer value2 = Buffer.ascii("TESTDATA");
    codec.write(value1);
    final BufferState state = codec.write(value2);
    assertEquals(BufferState.NOT_EMPTY, state);
    assertEquals(false, codec.full());
    assertEquals(false, codec.empty());
    assertEquals(0l, codec.getWriteCounter());
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteBuffer(java.nio.ByteBuffer) BufferState(io.fabric8.dosgi.io.ProtocolCodec.BufferState) Test(org.junit.Test)

Example 12 with Buffer

use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.

the class LengthPrefixedCodecTest method testWrite.

@Test
public void testWrite() throws Exception {
    final Buffer value = Buffer.ascii("TESTDATA");
    final BufferState state = codec.write(value);
    assertEquals(BufferState.WAS_EMPTY, state);
    assertEquals(false, codec.full());
    assertEquals(false, codec.empty());
    assertEquals(0l, codec.getWriteCounter());
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteBuffer(java.nio.ByteBuffer) BufferState(io.fabric8.dosgi.io.ProtocolCodec.BufferState) Test(org.junit.Test)

Example 13 with Buffer

use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.

the class LengthPrefixedCodecTest method testFlush$Partially.

@Test
public void testFlush$Partially() throws Exception {
    final Buffer value = Buffer.ascii("TESTDATA");
    codec.write(value);
    final int bytesThatWillBeWritten = value.length() / 2;
    expect(writableByteChannel.write((ByteBuffer) anyObject())).andAnswer(createWriteAnswer(bytesThatWillBeWritten));
    replay(writableByteChannel);
    final BufferState state = codec.flush();
    assertEquals(BufferState.NOT_EMPTY, state);
    assertEquals(false, codec.full());
    assertEquals(false, codec.empty());
    assertEquals(bytesThatWillBeWritten, codec.getWriteCounter());
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteBuffer(java.nio.ByteBuffer) BufferState(io.fabric8.dosgi.io.ProtocolCodec.BufferState) Test(org.junit.Test)

Example 14 with Buffer

use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.

the class LengthPrefixedCodecTest method testFlush.

@Test
public void testFlush() throws Exception {
    final Buffer value = Buffer.ascii("TESTDATA");
    codec.write(value);
    final int bytesThatWillBeWritten = value.length();
    expect(writableByteChannel.write((ByteBuffer) anyObject())).andAnswer(createWriteAnswer(bytesThatWillBeWritten));
    replay(writableByteChannel);
    final BufferState state = codec.flush();
    assertEquals(BufferState.EMPTY, state);
    assertEquals(false, codec.full());
    assertEquals(true, codec.empty());
    assertEquals(bytesThatWillBeWritten, codec.getWriteCounter());
    assertEquals(BufferState.WAS_EMPTY, codec.flush());
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) ByteBuffer(java.nio.ByteBuffer) BufferState(io.fabric8.dosgi.io.ProtocolCodec.BufferState) Test(org.junit.Test)

Example 15 with Buffer

use of org.fusesource.hawtbuf.Buffer in project fabric8 by jboss-fuse.

the class ClientInvokerImpl method getMethodData.

private MethodData getMethodData(Method method) throws IOException {
    MethodData rc = null;
    synchronized (method_cache) {
        rc = method_cache.get(method);
    }
    if (rc == null) {
        StringBuilder sb = new StringBuilder();
        sb.append(method.getName());
        sb.append(",");
        Class<?>[] types = method.getParameterTypes();
        for (int i = 0; i < types.length; i++) {
            if (i != 0) {
                sb.append(",");
            }
            sb.append(encodeClassName(types[i]));
        }
        Buffer signature = new UTF8Buffer(sb.toString()).buffer();
        Serialization annotation = method.getAnnotation(Serialization.class);
        SerializationStrategy serializationStrategy;
        if (annotation != null) {
            serializationStrategy = serializationStrategies.get(annotation.value());
            if (serializationStrategy == null) {
                throw new RuntimeException("Could not find the serialization strategy named: " + annotation.value());
            }
        } else {
            serializationStrategy = ObjectSerializationStrategy.INSTANCE;
        }
        final InvocationStrategy strategy;
        if (AsyncInvocationStrategy.isAsyncMethod(method)) {
            strategy = AsyncInvocationStrategy.INSTANCE;
        } else {
            strategy = BlockingInvocationStrategy.INSTANCE;
        }
        rc = new MethodData(strategy, serializationStrategy, signature);
        synchronized (method_cache) {
            method_cache.put(method, rc);
        }
    }
    return rc;
}
Also used : Buffer(org.fusesource.hawtbuf.Buffer) UTF8Buffer(org.fusesource.hawtbuf.UTF8Buffer) Serialization(io.fabric8.dosgi.api.Serialization) UTF8Buffer(org.fusesource.hawtbuf.UTF8Buffer) SerializationStrategy(io.fabric8.dosgi.api.SerializationStrategy) ObjectSerializationStrategy(io.fabric8.dosgi.api.ObjectSerializationStrategy)

Aggregations

Buffer (org.fusesource.hawtbuf.Buffer)45 IOException (java.io.IOException)17 ByteBuffer (java.nio.ByteBuffer)10 Exchange (org.apache.camel.Exchange)9 Test (org.junit.Test)9 Transaction (org.fusesource.hawtdb.api.Transaction)8 UTF8Buffer (org.fusesource.hawtbuf.UTF8Buffer)6 SortedIndex (org.fusesource.hawtdb.api.SortedIndex)6 InflaterInputStream (java.util.zip.InflaterInputStream)5 ByteArrayInputStream (org.fusesource.hawtbuf.ByteArrayInputStream)5 BufferState (io.fabric8.dosgi.io.ProtocolCodec.BufferState)4 OpenwireException (io.fabric8.gateway.handlers.detecting.protocol.openwire.support.OpenwireException)3 DataStructure (io.fabric8.gateway.handlers.detecting.protocol.openwire.command.DataStructure)2 RandomAccessFile (java.io.RandomAccessFile)2 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)2 BufferEditor (org.fusesource.hawtbuf.BufferEditor)2 ByteArrayOutputStream (org.fusesource.hawtbuf.ByteArrayOutputStream)2 DataByteArrayOutputStream (org.fusesource.hawtbuf.DataByteArrayOutputStream)2 Index (org.fusesource.hawtdb.api.Index)2 ObjectSerializationStrategy (io.fabric8.dosgi.api.ObjectSerializationStrategy)1