Package java.nio.channels

Examples of java.nio.channels.SelectableChannel


             */
            @Override
            public boolean onAcceptInterest(SelectionKey key, Context ctx)
                    throws IOException {
                try {
                    SelectableChannel channel = acceptWithoutRegistration(key);

                    if (channel != null) {
                        configureChannel(channel);

                        SelectionKey readKey = channel.register(selector,
                                SelectionKey.OP_READ);

                        // Cache the connection.
                        TargetTuple tt = connectionManager.add(readKey, this);

View Full Code Here


                //
                // have to register keys with selector thread
                //
                while ((newLink = _registerConnections.poll()) != null) {
                    try {
                        SelectableChannel sc = newLink.getSelectableChannel();

                        if (sc.isOpen()) {
                            if (_log.isLoggable(Level.INFO)) {
                                _log.log(Level.INFO,
                                    "Adding new open channel : " +
                                    newLink.getInfo() +
                                    ", current number of keys in selector = " +
                                    _selector.keys().size());
                            }

                            sc.register(_selector, SelectionKey.OP_READ, newLink);
                        }
                    } catch (Exception e) {
                        _log.log(Level.WARNING, "Failed to register link.", e);
                    }
                }
View Full Code Here

        private int bufferSize = DEFAULT_RECEIVE_BB_SIZE;

        @Override
        public boolean execute(Context ctx) throws IOException {
            SelectableChannel channel = ctx.getSelectionKey().channel();

            // Make sure we remove that attribute in case the

            // ProtocolChain is not the default one.
            ctx.removeAttribute(ProtocolFilter.SUCCESSFUL_READ);

            /*
             * Read filter should be executed only for READ or READ_WRITE
             * operations and never for WRITE. Printing a fine message.
             */
            if (ctx.getCurrentOpType() == Context.OpType.OP_WRITE) {
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE,
                            "sip.network.grizzly.filter.write.warning");
                }

                return false;
            }

            if (!channel.isOpen()) {
                ctx.setKeyRegistrationState(KeyRegistrationState.CANCEL);

                return false;
            }

View Full Code Here

        public boolean execute(Context ctx) throws IOException {
            // Make sure we remove that attribute in case the
            // ProtocolChain is not the default one.
            ctx.removeAttribute(ProtocolFilter.SUCCESSFUL_READ);

            SelectableChannel channel = ctx.getSelectionKey().channel();

            if (ctx.getCurrentOpType() == Context.OpType.OP_WRITE) {
                if (logger.isLoggable(Level.FINER)) {
                    logger.log(Level.FINER,
                            "sip.network.grizzly.filter.write.warning");
                }

                return false;
            }

            if (!channel.isOpen()) {
                ctx.setKeyRegistrationState(KeyRegistrationState.CANCEL);

                return false;
            }
            WorkerThread workerThread = (WorkerThread) Thread.currentThread();
View Full Code Here

                } else if (handler == null) {
                    handler = createHandlerUDP(tt);
                }

                if (handler != null) {
                    SelectableChannel channel = handler.getUnderlyingChannel();

                    if ((channel != null) && channel.isOpen() && (handler.getSelectorHandler() != null) && (handler.getSelectorHandler().getAsyncQueueWriter() != null)) {
                        streams.putIfAbsent(tt, handler);
                    } else {
                      if (handler.getUnderlyingChannel() == null) {
                            if (logger.isLoggable(Level.FINEST)){
                                logger.log(
View Full Code Here

            if ((key != null) && (key.channel() != null) && (byteBuffer != null)) {
                StringBuffer sb = new StringBuffer();
                for (int i = 0; i < byteBuffer.position(); i++) {
                    sb.append((char) byteBuffer.get(i));
                }
                SelectableChannel channel = key.channel();
                if (channel instanceof DatagramChannel) {
                    DatagramSocket sock = ((DatagramChannel) channel).socket();
                    if (sock != null) {
                      if (ex == null) {
                            if (logger.isLoggable(Level.FINEST)){
View Full Code Here

                        null)) {
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < byteBuffer.position(); i++) {
                        sb.append((char) byteBuffer.get(i));
                    }
                    SelectableChannel channel = key.channel();
                    if (channel instanceof DatagramChannel) {
                        DatagramSocket sock =
                                ((DatagramChannel) channel).socket();
                        if (sock != null) {
                            logger.log(Level.FINEST, "STUN OUT ",
View Full Code Here

                        null)) {
                    StringBuffer sb = new StringBuffer();
                    for (int i = 0; i < byteBuffer.position(); i++) {
                        sb.append((char) byteBuffer.get(i));
                    }
                    SelectableChannel channel = key.channel();
                    if (channel instanceof DatagramChannel) {
                        DatagramSocket sock =
                                ((DatagramChannel) channel).socket();
                        if (sock != null) {
                            logger.log(Level.FINEST, "STUN ERROR  ",
View Full Code Here

                EventHandler eventHandler =
                    (EventHandler)deferredRegistrations.get(i);
                if (orb.transportDebugFlag) {
                    dprint(".handleDeferredRegistrations: " + eventHandler);
                }
                SelectableChannel channel = eventHandler.getChannel();
                SelectionKey selectionKey = null;
                try {
                    selectionKey =
                        channel.register(selector,
                                         eventHandler.getInterestOps(),
                                         (Object)eventHandler);
                } catch (ClosedChannelException e) {
                    if (orb.transportDebugFlag) {
                        dprint(".handleDeferredRegistrations: " + e);
View Full Code Here

        return new IoSessionIterator(selector.selectedKeys());
    }

    @Override
    protected void init(NioSession session) throws Exception {
        SelectableChannel ch = (SelectableChannel) session.getChannel();
        ch.configureBlocking(false);
        session.setSelectionKey(ch.register(selector, SelectionKey.OP_READ,
                session));
    }
View Full Code Here

TOP

Related Classes of java.nio.channels.SelectableChannel

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.