Package org.apache.s4.comm.topology

Examples of org.apache.s4.comm.topology.ClusterNode


        this.assignment = assignment;
    }

    @Inject
    private void resolveLocalPartitionId() {
        ClusterNode node = assignment.assignClusterNode();
        if (node != null) {
            localPartitionId = node.getPartition();
        }
    }
View Full Code Here


        bind(RemoteSenders.class).toInstance(Mockito.mock(RemoteSenders.class));
        bind(RemoteEmitters.class).toInstance(Mockito.mock(RemoteEmitters.class));
        bind(RemoteEmitterFactory.class).toInstance(Mockito.mock(RemoteEmitterFactory.class));
        bind(Clusters.class).toInstance(Mockito.mock(Clusters.class));
        Assignment mockedAssignment = Mockito.mock(Assignment.class);
        Mockito.when(mockedAssignment.assignClusterNode()).thenReturn(new ClusterNode(0, 0, "machine", "Task-0"));
        bind(Assignment.class).toInstance(mockedAssignment);
        Names.bindProperties(binder(), ImmutableMap.of("s4.cluster.name", "testCluster"));
    }
View Full Code Here

    @Override
    public boolean send(int partitionId, EventMessage eventMessage) {
        try {
            byte[] message = serDeser.serialize(eventMessage);
            ClusterNode node = nodes.get(partitionId);
            if (node == null) {
                LoggerFactory.getLogger(getClass()).error(
                        "Cannot send message to partition {} because this partition is not visible to this emitter",
                        partitionId);
                return false;
            }
            byte[] byteBuffer = new byte[message.length];
            System.arraycopy(message, 0, byteBuffer, 0, message.length);
            InetAddress inetAddress = inetCache.get(partitionId);
            if (inetAddress == null) {
                inetAddress = InetAddress.getByName(node.getMachineName());
                inetCache.put(partitionId, inetAddress);
            }
            DatagramPacket dp = new DatagramPacket(byteBuffer, byteBuffer.length, inetAddress, node.getPort());
            socket.send(dp);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
View Full Code Here

                if (process != null) {
                    int partition = Integer.parseInt(process.getSimpleField("partition"));
                    String host = process.getSimpleField("host");
                    int port = Integer.parseInt(process.getSimpleField("port"));
                    String taskId = process.getSimpleField("taskId");
                    ClusterNode node = new ClusterNode(partition, port, host, taskId);
                    nodes.add(node);
                }
            }

            app = new App();
View Full Code Here

        bootstrap.setOption("tcpNoDelay", true);
        bootstrap.setOption("keepAlive", true);
    }

    private boolean connectTo(Integer partitionId) {
        ClusterNode clusterNode = partitionNodeMap.get(partitionId);

        if (clusterNode == null) {
            clusterNode = topology.getTopology().getNodes().get(partitionId);
            partitionNodeMap.forcePut(partitionId, clusterNode);
        }

        if (clusterNode == null) {
            logger.error("No ClusterNode exists for partitionId " + partitionId);
            return false;
        }

        for (int retries = 0; retries < NUM_RETRIES; retries++) {
            ChannelFuture f = this.bootstrap.connect(new InetSocketAddress(clusterNode.getMachineName(), clusterNode
                    .getPort()));
            f.awaitUninterruptibly();
            if (f.isSuccess()) {
                partitionChannelMap.forcePut(partitionId, f.getChannel());
                return true;
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException ie) {
                logger.error(String.format("Interrupted while connecting to %s:%d", clusterNode.getMachineName(),
                        clusterNode.getPort()));
            }
        }

        return false;
    }
View Full Code Here

        /*
         * Close the channels that correspond to changed partitions and update partitionNodeMap
         */
        for (ClusterNode clusterNode : topology.getTopology().getNodes()) {
            Integer partition = clusterNode.getPartition();
            ClusterNode oldNode = partitionNodeMap.get(partition);

            if (oldNode != null && !oldNode.equals(clusterNode)) {
                partitionChannelMap.remove(partition).close();
            }

            partitionNodeMap.forcePut(partition, clusterNode);
        }
View Full Code Here

    private SerializerDeserializer serDeser;

    @Inject
    public TestListener(Assignment assignment, @Named("s4.comm.timeout") int timeout, SerializerDeserializer serDeser) {
        // wait for an assignment
        ClusterNode node = assignment.assignClusterNode();
        this.serDeser = serDeser;

        ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
                Executors.newCachedThreadPool());

        bootstrap = new ServerBootstrap(factory);

        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            @Override
            public ChannelPipeline getPipeline() {
                ChannelPipeline p = Channels.pipeline();
                p.addLast("1", new LengthFieldBasedFrameDecoder(999999, 0, 4, 0, 4));
                p.addLast("2", new MyChannelHandler());

                return p;
            }
        });

        bootstrap.setOption("child.tcpNoDelay", true);
        bootstrap.setOption("child.keepAlive", true);
        bootstrap.setOption("child.reuseAddress", true);
        bootstrap.setOption("child.connectTimeoutMillis", timeout);
        bootstrap.setOption("readWriteFair", true);

        Channel c = bootstrap.bind(new InetSocketAddress(node.getPort()));
        channels.add(c);

        zkClient = new ZkClient("localhost:2181");
    }
View Full Code Here

                if (process != null) {
                    int partition = Integer.parseInt(process.getSimpleField("partition"));
                    String host = process.getSimpleField("host");
                    int port = Integer.parseInt(process.getSimpleField("port"));
                    String taskId = process.getSimpleField("taskId");
                    ClusterNode node = new ClusterNode(partition, port, host, taskId);
                    nodes.add(node);
                }
            }

            app = new App();
View Full Code Here

    }

    @Override
    public boolean send(int partitionId, byte[] message) {
        try {
            ClusterNode node = nodes.get(partitionId);
            if (node == null) {
                throw new RuntimeException(String.format("Bad partition id %d", partitionId));
            }
            byte[] byteBuffer = new byte[message.length];
            System.arraycopy(message, 0, byteBuffer, 0, message.length);
            InetAddress inetAddress = inetCache.get(partitionId);
            if (inetAddress == null) {
                inetAddress = InetAddress.getByName(node.getMachineName());
                inetCache.put(partitionId, inetAddress);
            }
            DatagramPacket dp = new DatagramPacket(byteBuffer, byteBuffer.length, inetAddress, node.getPort());
            socket.send(dp);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
View Full Code Here

        taskSetup.setup(clusterName, 10);
        String zookeeperAddress = "localhost:2181";
        for (int i = 0; i < 10; i++) {
            AssignmentFromZK assignmentFromZK = new AssignmentFromZK(
                    clusterName, zookeeperAddress, 30000, 30000);
            ClusterNode assignClusterNode = assignmentFromZK
                    .assignClusterNode();
            System.out.println(i+"-->"+assignClusterNode);
        }
        TopologyFromZK topologyFromZK=new TopologyFromZK(clusterName, zookeeperAddress, 30000, 30000);
        Thread.sleep(3000);
View Full Code Here

TOP

Related Classes of org.apache.s4.comm.topology.ClusterNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.