Search in sources :

Example 1 with NetException

use of org.apache.hyracks.api.exceptions.NetException 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 2 with NetException

use of org.apache.hyracks.api.exceptions.NetException in project asterixdb by apache.

the class ChannelSet method createChannel.

private ChannelControlBlock createChannel(int idx) throws NetException {
    if (idx > MuxDemuxCommand.MAX_CHANNEL_ID) {
        throw new NetException("Channel Id > " + MuxDemuxCommand.MAX_CHANNEL_ID + " being opened");
    }
    if (idx >= ccbArray.length) {
        expand(idx);
    }
    if (ccbArray[idx] != null) {
        assert ccbArray[idx].completelyClosed() : ccbArray[idx].toString();
        if (ccbArray[idx].completelyClosed()) {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine("Cleaning free channel: " + ccbArray[idx]);
            }
            freeChannel(ccbArray[idx]);
        }
    }
    assert idx < ccbArray.length;
    assert !allocationBitmap.get(idx);
    IChannelInterfaceFactory channelInterfaceFactory = mConn.getChannelInterfaceFactory();
    ChannelControlBlock channel = new ChannelControlBlock(this, idx, channelInterfaceFactory);
    ccbArray[idx] = channel;
    allocationBitmap.set(idx);
    ++openChannelCount;
    return channel;
}
Also used : IChannelInterfaceFactory(org.apache.hyracks.api.comm.IChannelInterfaceFactory) NetException(org.apache.hyracks.api.exceptions.NetException)

Example 3 with NetException

use of org.apache.hyracks.api.exceptions.NetException in project asterixdb by apache.

the class MultiplexedConnection method driveReaderStateMachine.

void driveReaderStateMachine() throws IOException, NetException {
    SocketChannel sc = tcpConnection.getSocketChannel();
    int chunksRead = 0;
    while (chunksRead < MAX_CHUNKS_READ_PER_CYCLE) {
        if (readerState.readBuffer.remaining() > 0) {
            int read = sc.read(readerState.readBuffer);
            if (read < 0) {
                throw new NetException("Socket Closed");
            }
            muxDemux.getPerformanceCounters().addSignalingBytesRead(read);
            if (readerState.readBuffer.remaining() > 0) {
                return;
            }
            readerState.readBuffer.flip();
            readerState.command.read(readerState.readBuffer);
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine("Received command: " + readerState.command);
            }
            ChannelControlBlock ccb = null;
            switch(readerState.command.getCommandType()) {
                case ADD_CREDITS:
                    {
                        ccb = readerState.getCCBInCommand();
                        ccb.addWriteCredits(readerState.command.getData());
                        break;
                    }
                case CLOSE_CHANNEL:
                    {
                        ccb = readerState.getCCBInCommand();
                        ccb.reportRemoteEOS();
                        int channelId = ccb.getChannelId();
                        cSet.markEOSAck(channelId);
                        cSet.unmarkPendingCredits(channelId);
                        break;
                    }
                case CLOSE_CHANNEL_ACK:
                    {
                        ccb = readerState.getCCBInCommand();
                        ccb.reportLocalEOSAck();
                        break;
                    }
                case DATA:
                    {
                        ccb = readerState.getCCBInCommand();
                        readerState.pendingReadSize = readerState.command.getData();
                        readerState.ccb = ccb;
                        break;
                    }
                case ERROR:
                    {
                        ccb = readerState.getCCBInCommand();
                        ccb.reportRemoteError(readerState.command.getData());
                        int channelId = ccb.getChannelId();
                        cSet.markEOSAck(channelId);
                        cSet.unmarkPendingCredits(channelId);
                        break;
                    }
                case OPEN_CHANNEL:
                    {
                        int channelId = readerState.command.getChannelId();
                        ccb = cSet.registerChannel(channelId);
                        muxDemux.getChannelOpenListener().channelOpened(ccb);
                    }
            }
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine("Applied command: " + readerState.command + " on " + ccb);
            }
        }
        if (readerState.pendingReadSize > 0) {
            ++chunksRead;
            int newPendingReadSize = readerState.ccb.read(sc, readerState.pendingReadSize);
            muxDemux.getPerformanceCounters().addPayloadBytesRead(readerState.pendingReadSize - newPendingReadSize);
            readerState.pendingReadSize = newPendingReadSize;
            if (readerState.pendingReadSize > 0) {
                return;
            }
        }
        readerState.reset();
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) IChannelControlBlock(org.apache.hyracks.api.comm.IChannelControlBlock) NetException(org.apache.hyracks.api.exceptions.NetException)

Example 4 with NetException

use of org.apache.hyracks.api.exceptions.NetException in project asterixdb by apache.

the class MultiplexedConnection method openChannel.

/**
     * Open a channel to the other side.
     *
     * @return
     * @throws NetException
     *             - A network failure occurred.
     */
public ChannelControlBlock openChannel() throws NetException {
    synchronized (this) {
        if (connectionFailure) {
            throw new NetException(error);
        }
    }
    ChannelControlBlock channel = cSet.allocateChannel();
    int channelId = channel.getChannelId();
    cSet.initiateChannelSyn(channelId);
    return channel;
}
Also used : IChannelControlBlock(org.apache.hyracks.api.comm.IChannelControlBlock) NetException(org.apache.hyracks.api.exceptions.NetException)

Aggregations

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