Search in sources :

Example 6 with ServerInvokerImpl

use of io.fabric8.dosgi.tcp.ServerInvokerImpl in project fabric8 by jboss-fuse.

the class InvocationTest method testNoOverflow.

@Test(timeout = 30 * 1000)
public void testNoOverflow() throws Exception {
    DispatchQueue queue = Dispatch.createQueue();
    HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
    map.put("protobuf", new ProtobufSerializationStrategy());
    ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
    server.start();
    ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
    client.start();
    try {
        server.registerService("service-id", new ServerInvoker.ServiceFactory() {

            public Object get() {
                return new HelloImpl();
            }

            public void unget() {
            }
        }, HelloImpl.class.getClassLoader());
        InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
        Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
        char[] chars = new char[65 * 1024];
        String payload = new String(chars);
        for (int i = 0; i < 100; i++) {
            hello.hello(payload);
        }
    } finally {
        server.stop();
        client.stop();
    }
}
Also used : ServerInvoker(io.fabric8.dosgi.io.ServerInvoker) HashMap(java.util.HashMap) InvocationHandler(java.lang.reflect.InvocationHandler) ClientInvokerImpl(io.fabric8.dosgi.tcp.ClientInvokerImpl) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

Example 7 with ServerInvokerImpl

use of io.fabric8.dosgi.tcp.ServerInvokerImpl in project fabric8 by jboss-fuse.

the class TransportFailureTest method testInvoke.

@Test
public void testInvoke() throws Exception {
    DispatchQueue queue = Dispatch.createQueue();
    HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
    map.put("protobuf", new ProtobufSerializationStrategy());
    ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
    server.start();
    ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
    client.start();
    try {
        server.registerService("service-id", new ServerInvoker.ServiceFactory() {

            public Object get() {
                return new HelloImpl();
            }

            public void unget() {
            }
        }, HelloImpl.class.getClassLoader());
        InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
        Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
        AsyncCallbackFuture<String> future1 = new AsyncCallbackFuture<String>();
        hello.hello("Guillaume", future1);
        long t0 = System.currentTimeMillis();
        try {
            assertEquals("Hello Guillaume!", future1.get(MAX_DELAY, TimeUnit.MILLISECONDS));
            fail("Should have thrown an exception");
        } catch (Exception e) {
            // Expected
            long t1 = System.currentTimeMillis();
            assertTrue(t1 - t0 > SLEEP_TIME / 2);
            assertTrue(t1 - t0 < MAX_DELAY / 2);
        }
    } finally {
        server.stop();
        client.stop();
    }
}
Also used : ServerInvoker(io.fabric8.dosgi.io.ServerInvoker) HashMap(java.util.HashMap) InvocationHandler(java.lang.reflect.InvocationHandler) AsyncCallbackFuture(io.fabric8.dosgi.api.AsyncCallbackFuture) ClientInvokerImpl(io.fabric8.dosgi.tcp.ClientInvokerImpl) ProtobufSerializationStrategy(io.fabric8.dosgi.api.ProtobufSerializationStrategy) SerializationStrategy(io.fabric8.dosgi.api.SerializationStrategy) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) ProtobufSerializationStrategy(io.fabric8.dosgi.api.ProtobufSerializationStrategy) DispatchQueue(org.fusesource.hawtdispatch.DispatchQueue) Test(org.junit.Test)

Example 8 with ServerInvokerImpl

use of io.fabric8.dosgi.tcp.ServerInvokerImpl in project fabric8 by jboss-fuse.

the class Manager method init.

public void init() throws Exception {
    // Create client and server
    this.client = new ClientInvokerImpl(queue, timeout, serializationStrategies);
    this.server = new ServerInvokerImpl(uri, queue, serializationStrategies);
    this.client.start();
    this.server.start();
    // ZooKeeper tracking
    try {
        create(curator, DOSGI_REGISTRY, CreateMode.PERSISTENT);
    } catch (KeeperException.NodeExistsException e) {
    // The node already exists, that's fine
    }
    this.tree = new TreeCacheExtended(curator, DOSGI_REGISTRY, true);
    this.tree.getListenable().addListener(this);
    this.tree.start();
    // UUID
    this.uuid = Utils.getUUID(this.bundleContext);
    // Service listener filter
    String filter = "(" + RemoteConstants.SERVICE_EXPORTED_INTERFACES + "=*)";
    // Initialization
    this.bundleContext.addServiceListener(this, filter);
    // Service registration
    this.registration = this.bundleContext.registerService(new String[] { ListenerHook.class.getName(), EventHook.class.getName(), FindHook.class.getName() }, this, null);
    // Check existing services
    ServiceReference[] references = this.bundleContext.getServiceReferences((String) null, filter);
    if (references != null) {
        for (ServiceReference reference : references) {
            exportService(reference);
        }
    }
}
Also used : ClientInvokerImpl(io.fabric8.dosgi.tcp.ClientInvokerImpl) ServerInvokerImpl(io.fabric8.dosgi.tcp.ServerInvokerImpl) TreeCacheExtended(org.apache.curator.framework.recipes.cache.TreeCacheExtended) KeeperException(org.apache.zookeeper.KeeperException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

ClientInvokerImpl (io.fabric8.dosgi.tcp.ClientInvokerImpl)8 ServerInvokerImpl (io.fabric8.dosgi.tcp.ServerInvokerImpl)8 ServerInvoker (io.fabric8.dosgi.io.ServerInvoker)7 InvocationHandler (java.lang.reflect.InvocationHandler)7 HashMap (java.util.HashMap)7 DispatchQueue (org.fusesource.hawtdispatch.DispatchQueue)7 Test (org.junit.Test)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 AsyncCallbackFuture (io.fabric8.dosgi.api.AsyncCallbackFuture)1 ProtobufSerializationStrategy (io.fabric8.dosgi.api.ProtobufSerializationStrategy)1 SerializationStrategy (io.fabric8.dosgi.api.SerializationStrategy)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 ArrayList (java.util.ArrayList)1 TreeCacheExtended (org.apache.curator.framework.recipes.cache.TreeCacheExtended)1 KeeperException (org.apache.zookeeper.KeeperException)1 ServiceReference (org.osgi.framework.ServiceReference)1