Search in sources :

Example 11 with IConnection

use of backtype.storm.messaging.IConnection in project jstorm by alibaba.

the class NettyUnitTest method test_client_reboot.

@Test
public void test_client_reboot() {
    System.out.println("!!!!!!!!!!Start client reboot test!!!!!!!!");
    final String req_msg = setupLargMsg();
    final IContext context = TransportFactory.makeContext(storm_conf);
    new Thread(new Runnable() {

        @Override
        public void run() {
            IConnection client = context.connect(null, "localhost", port);
            lock.lock();
            List<TaskMessage> list = new ArrayList<TaskMessage>();
            TaskMessage message = new TaskMessage(task, req_msg.getBytes());
            list.add(message);
            client.send(message);
            System.out.println("Send first");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            client.close();
            IConnection client2 = context.connect(null, "localhost", port);
            System.out.println("!!!!!!! restart client !!!!!!!!!!");
            client2.send(message);
            System.out.println("Send second");
            JStormUtils.sleepMs(1000);
            try {
                clientClose.await();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            client2.close();
            contextClose.signal();
            lock.unlock();
        }
    }).start();
    IConnection server = initNettyServer();
    byte[] recv = (byte[]) server.recv(task, 0);
    System.out.println("Sever receive first");
    Assert.assertEquals(req_msg, new String(recv));
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    byte[] recv2 = (byte[]) server.recv(task, 0);
    System.out.println("Sever receive second");
    Assert.assertEquals(req_msg, new String(recv2));
    lock.lock();
    try {
        clientClose.signal();
        server.close();
        try {
            contextClose.await();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        context.term();
    } finally {
        lock.unlock();
    }
    System.out.println("!!!!!!!!!!End client reboot test!!!!!!!!");
}
Also used : IContext(backtype.storm.messaging.IContext) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 12 with IConnection

use of backtype.storm.messaging.IConnection in project jstorm by alibaba.

the class NettyUnitTest method test_slow_receive.

@Test
public void test_slow_receive() {
    System.out.println("!!!!!!!!!!Start test_slow_receive message test!!!!!!!!");
    final int base = 100000;
    final IContext context = TransportFactory.makeContext(storm_conf);
    final IConnection server = initNettyServer();
    new Thread(new Runnable() {

        @Override
        public void run() {
            lock.lock();
            IConnection client = null;
            client = context.connect(null, "localhost", port);
            List<TaskMessage> list = new ArrayList<TaskMessage>();
            for (int i = 1; i < Short.MAX_VALUE; i++) {
                String req_msg = String.valueOf(i + base);
                TaskMessage message = new TaskMessage(task, req_msg.getBytes());
                list.add(message);
                if (i % 1000 == 0) {
                    System.out.println("send " + req_msg);
                    client.send(list);
                    list = new ArrayList<TaskMessage>();
                }
            }
            client.send(list);
            System.out.println("Finish Send ");
            JStormUtils.sleepMs(1000);
            try {
                clientClose.await();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            client.close();
            contextClose.signal();
            lock.unlock();
        }
    }).start();
    for (int i = 1; i < Short.MAX_VALUE; i++) {
        byte[] message = (byte[]) server.recv(task, 0);
        JStormUtils.sleepMs(1);
        if (i % 1000 == 0) {
            Assert.assertEquals(String.valueOf(i + base), new String(message));
            System.out.println("Receive " + new String(message));
        }
    }
    System.out.println("Finish Receive ");
    lock.lock();
    try {
        clientClose.signal();
        server.close();
        try {
            contextClose.await();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        context.term();
    } finally {
        lock.unlock();
    }
    System.out.println("!!!!!!!!!!End test_slow_receive message test!!!!!!!!");
}
Also used : IContext(backtype.storm.messaging.IContext) IConnection(backtype.storm.messaging.IConnection) TaskMessage(backtype.storm.messaging.TaskMessage) Test(org.junit.Test)

Example 13 with IConnection

use of backtype.storm.messaging.IConnection in project storm by nathanmarz.

the class Context method connect.

/**
 * establish a connection to a remote server
 */
public IConnection connect(String storm_id, String host, int port) {
    IConnection client = new Client(storm_conf, host, port);
    connections.add(client);
    return client;
}
Also used : IConnection(backtype.storm.messaging.IConnection)

Example 14 with IConnection

use of backtype.storm.messaging.IConnection in project storm by nathanmarz.

the class Context method bind.

/**
 * establish a server with a binding port
 */
public IConnection bind(String storm_id, int port) {
    IConnection server = new Server(storm_conf, port);
    connections.add(server);
    return server;
}
Also used : IConnection(backtype.storm.messaging.IConnection)

Example 15 with IConnection

use of backtype.storm.messaging.IConnection in project jstorm by alibaba.

the class Worker method startDispatchThread.

private AsyncLoopThread startDispatchThread() {
    // send tuple directly from netty server
    // send control tuple to dispatch thread
    // startDispatchDisruptor();
    IContext context = workerData.getContext();
    String topologyId = workerData.getTopologyId();
    // create recv connection
    Map stormConf = workerData.getStormConf();
    long timeout = JStormUtils.parseLong(stormConf.get(Config.TOPOLOGY_DISRUPTOR_WAIT_TIMEOUT), 10);
    WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS);
    int queueSize = JStormUtils.parseInt(stormConf.get(Config.TOPOLOGY_CTRL_BUFFER_SIZE), 256);
    DisruptorQueue recvControlQueue = DisruptorQueue.mkInstance("Dispatch-control", ProducerType.MULTI, queueSize, waitStrategy, false, 0, 0);
    // metric for recvControlQueue
    QueueGauge revCtrlGauge = new QueueGauge(recvControlQueue, MetricDef.RECV_CTRL_QUEUE);
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.RECV_CTRL_QUEUE, MetricType.GAUGE), new AsmGauge(revCtrlGauge));
    IConnection recvConnection = context.bind(topologyId, workerData.getPort(), workerData.getDeserializeQueues(), recvControlQueue, false, workerData.getTaskIds());
    workerData.setRecvConnection(recvConnection);
    // create recvice control messages's thread
    RunnableCallback recvControlDispather = new VirtualPortCtrlDispatch(workerData, recvConnection, recvControlQueue, MetricDef.RECV_THREAD);
    return new AsyncLoopThread(recvControlDispather, false, Thread.MAX_PRIORITY, true);
}
Also used : IContext(backtype.storm.messaging.IContext) DisruptorQueue(backtype.storm.utils.DisruptorQueue) IConnection(backtype.storm.messaging.IConnection) RunnableCallback(com.alibaba.jstorm.callback.RunnableCallback) QueueGauge(com.alibaba.jstorm.common.metric.QueueGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) AsyncLoopThread(com.alibaba.jstorm.callback.AsyncLoopThread) AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) WaitStrategy(com.lmax.disruptor.WaitStrategy)

Aggregations

IConnection (backtype.storm.messaging.IConnection)25 TaskMessage (backtype.storm.messaging.TaskMessage)15 Test (org.junit.Test)12 IContext (backtype.storm.messaging.IContext)8 WorkerSlot (backtype.storm.scheduler.WorkerSlot)6 DisruptorQueue (backtype.storm.utils.DisruptorQueue)3 ITupleExt (backtype.storm.tuple.ITupleExt)2 AsyncLoopThread (com.alibaba.jstorm.callback.AsyncLoopThread)2 TimeoutBlockingWaitStrategy (com.lmax.disruptor.TimeoutBlockingWaitStrategy)2 WaitStrategy (com.lmax.disruptor.WaitStrategy)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 RunnableCallback (com.alibaba.jstorm.callback.RunnableCallback)1 AsmGauge (com.alibaba.jstorm.common.metric.AsmGauge)1 QueueGauge (com.alibaba.jstorm.common.metric.QueueGauge)1 Assignment (com.alibaba.jstorm.schedule.Assignment)1 ResourceWorkerSlot (com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)1 TaskShutdownDameon (com.alibaba.jstorm.task.TaskShutdownDameon)1 KryoException (com.esotericsoftware.kryo.KryoException)1 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)1