Search in sources :

Example 1 with IChannelControlBlock

use of org.apache.hyracks.api.comm.IChannelControlBlock in project asterixdb by apache.

the class NCMessageBroker method sendMessageToNC.

@Override
public void sendMessageToNC(String nodeId, INcAddressedMessage message) throws Exception {
    IChannelControlBlock messagingChannel = ncs.getMessagingNetworkManager().getMessagingChannel(nodeId);
    sendMessageToChannel(messagingChannel, message);
}
Also used : IChannelControlBlock(org.apache.hyracks.api.comm.IChannelControlBlock)

Example 2 with IChannelControlBlock

use of org.apache.hyracks.api.comm.IChannelControlBlock in project asterixdb by apache.

the class MessagingNetworkManager method establishNewConnection.

private IChannelControlBlock establishNewConnection(String nodeId) throws Exception {
    Map<String, NodeControllerInfo> nodeControllers = ncs.getNodeControllersInfo();
    // Get the node messaging address from its info
    NodeControllerInfo nodeControllerInfo = nodeControllers.get(nodeId);
    if (nodeControllerInfo == null) {
        throw new NetException("Could not find node: " + nodeId);
    }
    NetworkAddress nodeMessagingNeAddress = nodeControllerInfo.getMessagingNetworkAddress();
    SocketAddress nodeAddress = new InetSocketAddress(InetAddress.getByName(nodeMessagingNeAddress.getAddress()), nodeMessagingNeAddress.getPort());
    // Open the channel
    IChannelControlBlock ccb = connect(nodeAddress);
    try {
        // Prepare the initial message buffer
        ByteBuffer initialBuffer = ccb.getReadInterface().getBufferFactory().createBuffer();
        prepareMessagingInitialMessage(ncs.getId(), initialBuffer);
        // Send the initial messaging channel handshake message to register the opened channel on both nodes
        ccb.getWriteInterface().getFullBufferAcceptor().accept(initialBuffer);
        return ccb;
    } catch (NetException e) {
        closeChannel(ccb);
        throw e;
    }
}
Also used : NetworkAddress(org.apache.hyracks.api.comm.NetworkAddress) NodeControllerInfo(org.apache.hyracks.api.client.NodeControllerInfo) NetException(org.apache.hyracks.api.exceptions.NetException) InetSocketAddress(java.net.InetSocketAddress) IChannelControlBlock(org.apache.hyracks.api.comm.IChannelControlBlock) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ByteBuffer(java.nio.ByteBuffer)

Example 3 with IChannelControlBlock

use of org.apache.hyracks.api.comm.IChannelControlBlock in project asterixdb by apache.

the class MessagingNetworkManager method getMessagingChannel.

public IChannelControlBlock getMessagingChannel(String nodeId) throws Exception {
    synchronized (ncChannels) {
        IChannelControlBlock ccb = ncChannels.get(nodeId);
        if (ccb == null) {
            // Establish new connection
            ccb = establishNewConnection(nodeId);
            addOpenChannel(nodeId, ccb);
        }
        return ccb;
    }
}
Also used : IChannelControlBlock(org.apache.hyracks.api.comm.IChannelControlBlock)

Aggregations

IChannelControlBlock (org.apache.hyracks.api.comm.IChannelControlBlock)3 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 NodeControllerInfo (org.apache.hyracks.api.client.NodeControllerInfo)1 NetworkAddress (org.apache.hyracks.api.comm.NetworkAddress)1 NetException (org.apache.hyracks.api.exceptions.NetException)1