Package org.apache.mina.api

Examples of org.apache.mina.api.MinaRuntimeException


            datagramChannel = DatagramChannel.open();
            datagramChannel.socket().setReuseAddress(isReuseAddress());
            datagramChannel.socket().bind(address);
            datagramChannel.configureBlocking(false);
        } catch (IOException e) {
            throw new MinaRuntimeException("can't open the address " + address, e);
        }

        readSelectorLoop.register(false, false, true, false, this, datagramChannel, null);

        // it's the first address bound, let's fire the event
View Full Code Here


        readSelectorLoop.unregister(this, datagramChannel);
        datagramChannel.socket().close();
        try {
            datagramChannel.close();
        } catch (IOException e) {
            throw new MinaRuntimeException("can't close the datagram socket", e);
        }

        this.address = null;
        this.fireServiceInactivated();
    }
View Full Code Here

        SocketChannel clientSocket;
        try {
            clientSocket = SocketChannel.open();
        } catch (IOException e) {
            throw new MinaRuntimeException("can't create a new socket, out of file descriptors ?", e);
        }

        try {
            clientSocket.socket().setSoTimeout(getConnectTimeoutMillis());
        } catch (SocketException e) {
            throw new MinaRuntimeException("can't set socket timeout", e);
        }

        // non blocking
        try {
            clientSocket.configureBlocking(false);
        } catch (IOException e) {
            throw new MinaRuntimeException("can't configure socket as non-blocking", e);
        }

        // apply idle configuration
        // Has to be final, as it's used in a inner class...
        final NioTcpSession session = new NioTcpSession(this, clientSocket, readWriteSelectorPool.getSelectorLoop(),
                idleChecker);
        TcpSessionConfig config = getSessionConfig();

        session.getConfig().setIdleTimeInMillis(IdleStatus.READ_IDLE, config.getIdleTimeInMillis(IdleStatus.READ_IDLE));
        session.getConfig().setIdleTimeInMillis(IdleStatus.WRITE_IDLE,
                config.getIdleTimeInMillis(IdleStatus.WRITE_IDLE));

        // apply the default service socket configuration
        Boolean keepAlive = config.isKeepAlive();

        if (keepAlive != null) {
            session.getConfig().setKeepAlive(keepAlive);
        }

        Boolean oobInline = config.isOobInline();

        if (oobInline != null) {
            session.getConfig().setOobInline(oobInline);
        }

        Boolean reuseAddress = config.isReuseAddress();

        if (reuseAddress != null) {
            session.getConfig().setReuseAddress(reuseAddress);
        }

        Boolean tcpNoDelay = config.isTcpNoDelay();

        if (tcpNoDelay != null) {
            session.getConfig().setTcpNoDelay(tcpNoDelay);
        }

        Integer receiveBufferSize = config.getReadBufferSize();

        if (receiveBufferSize != null) {
            session.getConfig().setReadBufferSize(receiveBufferSize);
        } else {
            int rcvBufferSize;
            try {
                rcvBufferSize = clientSocket.socket().getReceiveBufferSize();
            } catch (SocketException e) {
                throw new MinaRuntimeException("can't configure socket receive buffer size", e);
            }
            session.getConfig().setReadBufferSize(rcvBufferSize);
        }

        Integer sendBufferSize = config.getSendBufferSize();

        if (sendBufferSize != null) {
            session.getConfig().setSendBufferSize(sendBufferSize);
        } else {
            int sndBufferSize;
            try {
                sndBufferSize = clientSocket.socket().getSendBufferSize();
            } catch (SocketException e) {
                throw new MinaRuntimeException("can't configure socket send buffe size", e);
            }
            session.getConfig().setSendBufferSize(sndBufferSize);
        }

        Integer trafficClass = config.getTrafficClass();
View Full Code Here

            if (trafficClass != null) {
                channel.socket().setTrafficClass(trafficClass);
            }
        } catch (IOException e) {
            throw new MinaRuntimeException("Can't open and configure a new udp socket", e);
        }

        worker = new Worker();
        bound = true;
        worker.start();
View Full Code Here

        bound = false;
        try {
            try {
                channel.close();
            } catch (IOException e) {
                throw new MinaRuntimeException("can't unbind the udp channel", e);
            }
            boundAddress = null;
            idleChecker.destroy();
            worker.join();
        } catch (InterruptedException e) {
View Full Code Here

            serverChannel = ServerSocketChannel.open();
            serverChannel.socket().setReuseAddress(isReuseAddress());
            serverChannel.socket().bind(address);
            serverChannel.configureBlocking(false);
        } catch (IOException e) {
            throw new MinaRuntimeException("can't bind address" + address, e);
        }

        acceptSelectorLoop.register(true, false, false, false, this, serverChannel, null);

        idleChecker = new IndexedIdleChecker();
View Full Code Here

        }
        try {
            serverChannel.socket().close();
            serverChannel.close();
        } catch (IOException e) {
            throw new MinaRuntimeException("can't unbind server", e);
        }

        acceptSelectorLoop.unregister(this, serverChannel);

        this.address = null;
View Full Code Here

        DatagramChannel ch;
        try {
            ch = DatagramChannel.open();
        } catch (IOException e) {
            throw new MinaRuntimeException("can't create a new socket, out of file descriptors ?", e);
        }
        try {
            ch.configureBlocking(false);
        } catch (IOException e) {
            throw new MinaRuntimeException("can't configure socket as non-blocking", e);
        }

        UdpSessionConfig config = getSessionConfig();

        NioSelectorLoop loop = (NioSelectorLoop) readWriteSelectorPool.getSelectorLoop();

        NioUdpSession session = new NioUdpSession(this, idleChecker, ch, null, remoteAddress, loop);

        session.setConnected();

        // apply idle configuration
        session.getConfig().setIdleTimeInMillis(IdleStatus.READ_IDLE, config.getIdleTimeInMillis(IdleStatus.READ_IDLE));
        session.getConfig().setIdleTimeInMillis(IdleStatus.WRITE_IDLE,
                config.getIdleTimeInMillis(IdleStatus.WRITE_IDLE));

        // Manage the Idle status
        idleChecker.sessionRead(session, System.currentTimeMillis());
        idleChecker.sessionWritten(session, System.currentTimeMillis());

        // apply the default service socket configuration

        Boolean reuseAddress = config.isReuseAddress();

        if (reuseAddress != null) {
            session.getConfig().setReuseAddress(reuseAddress);
        }

        Integer readBufferSize = config.getReadBufferSize();

        if (readBufferSize != null) {
            session.getConfig().setReadBufferSize(readBufferSize);
        } else {
            int rcvBufferSize;
            try {
                rcvBufferSize = ch.socket().getReceiveBufferSize();
                session.getConfig().setReadBufferSize(rcvBufferSize);

            } catch (SocketException e) {
                throw new MinaRuntimeException("can't configure socket receive buffer size", e);
            }
        }

        Integer sendBufferSize = config.getSendBufferSize();

        if (sendBufferSize != null) {
            session.getConfig().setSendBufferSize(sendBufferSize);
        } else {
            int sndBufferSize;
            try {
                sndBufferSize = ch.socket().getSendBufferSize();
                session.getConfig().setSendBufferSize(sndBufferSize);
            } catch (SocketException e) {
                throw new MinaRuntimeException("can't configure socket send buffe size", e);
            }
        }

        Integer trafficClass = config.getTrafficClass();
View Full Code Here

            if (trafficClass != null) {
                channel.socket().setTrafficClass(trafficClass);
            }
        } catch (IOException e) {
            throw new MinaRuntimeException("Can't open and configure a new udp socket", e);
        }

        worker = new Worker();
        bound = true;
        worker.start();
View Full Code Here

        bound = false;
        try {
            try {
                channel.close();
            } catch (IOException e) {
                throw new MinaRuntimeException("can't unbind the udp channel", e);
            }
            boundAddress = null;
            idleChecker.destroy();
            worker.join();
        } catch (InterruptedException e) {
View Full Code Here

TOP

Related Classes of org.apache.mina.api.MinaRuntimeException

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.