Examples of WriteRequest


Examples of org.apache.mina.common.IoFilter.WriteRequest

     */
    class DataMatcher extends AbstractMatcher {
        protected boolean argumentMatches(Object arg0, Object arg1) {
            // we need to only verify the ByteBuffer output
            if (arg0 instanceof WriteRequest) {
                WriteRequest expected = (WriteRequest) arg0;
                WriteRequest actual = (WriteRequest) arg1;
                ByteBuffer bExpected = (ByteBuffer) expected.getMessage();
                ByteBuffer bActual = (ByteBuffer) actual.getMessage();
                return bExpected.equals(bActual);
            }
            return true;
        }
View Full Code Here

Examples of org.apache.mina.common.IoFilter.WriteRequest

                return DefaultWriteFuture.newNotWrittenFuture( this );
            }
        }

        WriteFuture future = new DefaultWriteFuture( this );
        write0( new WriteRequest( message, future, remoteAddress ) );
       
        return future;
    }
View Full Code Here

Examples of org.apache.mina.common.IoFilter.WriteRequest

    private void run(String expectedResult) {
        chain.fireSessionCreated(session);
        chain.fireSessionOpened(session);
        chain.fireMessageReceived(session, new Object());
        chain.fireFilterWrite(session, new WriteRequest(new Object()));
        chain.fireSessionIdle(session, IdleStatus.READER_IDLE);
        chain.fireExceptionCaught(session, new Exception());
        chain.fireSessionClosed(session);

        result = formatResult(result);
View Full Code Here

Examples of org.apache.mina.common.IoFilter.WriteRequest

        if (isClosing() ) {
            return DefaultWriteFuture.newNotWrittenFuture(this);
        }

        WriteFuture future = new DefaultWriteFuture(this);
        write0(new WriteRequest(message, future, remoteAddress));

        return future;
    }
View Full Code Here

Examples of org.apache.mina.common.IoFilter.WriteRequest

            for (Object aData : data) {
                if (aData instanceof WriteRequest) {
                    // TODO Optimize unefficient data transfer.
                    // Data will be returned to pendingDataQueue
                    // if getTraffic().isWritable() is false.
                    WriteRequest wr = (WriteRequest) aData;
                    filterChain.doWrite(this, wr);
                } else {
                    // TODO Optimize unefficient data transfer.
                    // Data will be returned to pendingDataQueue
                    // if getTraffic().isReadable() is false.
View Full Code Here

Examples of org.apache.mina.common.WriteRequest

            IoBuffer buffer = getNextBuffer(stream);

            if (buffer == null) {
                // End of stream reached.
                session.removeAttribute(CURRENT_STREAM);
                WriteRequest currentWriteRequest = (WriteRequest) session
                        .removeAttribute(CURRENT_WRITE_REQUEST);

                // Write queued WriteRequests.
                Queue<WriteRequest> queue = removeWriteRequestQueue(session);
                if (queue != null) {
                    WriteRequest wr = queue.poll();
                    while (wr != null) {
                        filterWrite(nextFilter, session, wr);
                        wr = queue.poll();
                    }
                }
View Full Code Here

Examples of org.apache.mina.common.WriteRequest

                session.getLock().lock();
                try {
                    if (queue.isEmpty(session)) {
                        return;
                    }
                    WriteRequest req;
                    long currentTime = System.currentTimeMillis();
                    while ((req = queue.poll(session)) != null) {
                        Object m = req.getMessage();
                        pushEvent(new IoEvent(IoEventType.MESSAGE_SENT, session, req), false);
                        session.getRemoteSession().getFilterChain().fireMessageReceived(
                                getMessageCopy(m));
                        if (m instanceof IoBuffer) {
                            session.increaseWrittenBytes0(
                                    ((IoBuffer) m).remaining(), currentTime);
                        }
                    }
                } finally {
                    if (flushEnabled) {
                        flushEvents();
                    }
                    session.getLock().unlock();
                }

                flushPendingDataQueues(session);
            } else {
                List<WriteRequest> failedRequests = new ArrayList<WriteRequest>();
                WriteRequest req;
                while ((req = queue.poll(session)) != null) {
                    failedRequests.add(req);
                }

                if (!failedRequests.isEmpty()) {
View Full Code Here

Examples of org.apache.mina.core.write.WriteRequest

        return false;
    }

    private void clearWriteRequestQueue(T session) {
        WriteRequestQueue writeRequestQueue = session.getWriteRequestQueue();
        WriteRequest req;

        List<WriteRequest> failedRequests = new ArrayList<WriteRequest>();

        if ((req = writeRequestQueue.poll(session)) != null) {
            Object message = req.getMessage();
           
            if (message instanceof IoBuffer) {
                IoBuffer buf = (IoBuffer)message;

                // The first unwritten empty buffer must be
View Full Code Here

Examples of org.apache.mina.core.write.WriteRequest

        // fairness. I used maxReadBufferSize * 3 / 2, which yields best
        // performance in my experience while not breaking fairness much.
        final int maxWrittenBytes = session.getConfig().getMaxReadBufferSize()
                + (session.getConfig().getMaxReadBufferSize() >>> 1);
        int writtenBytes = 0;
        WriteRequest req = null;
       
        try {
            // Clear OP_WRITE
            setInterestedInWrite(session, false);
           
            do {
                // Check for pending writes.
                req = session.getCurrentWriteRequest();
               
                if (req == null) {
                    req = writeRequestQueue.poll(session);
                   
                    if (req == null) {
                        break;
                    }
                   
                    session.setCurrentWriteRequest(req);
                }

                int localWrittenBytes = 0;
                Object message = req.getMessage();
               
                if (message instanceof IoBuffer) {
                    localWrittenBytes = writeBuffer(session, req,
                            hasFragmentation, maxWrittenBytes - writtenBytes,
                            currentTime);
                   
                    if (localWrittenBytes > 0
                            && ((IoBuffer) message).hasRemaining()) {
                        // the buffer isn't empty, we re-interest it in writing
                        writtenBytes += localWrittenBytes;
                        setInterestedInWrite(session, true);
                        return false;
                    }
                } else if (message instanceof FileRegion) {
                    localWrittenBytes = writeFile(session, req,
                            hasFragmentation, maxWrittenBytes - writtenBytes,
                            currentTime);

                    // Fix for Java bug on Linux
                    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5103988
                    // If there's still data to be written in the FileRegion,
                    // return 0 indicating that we need
                    // to pause until writing may resume.
                    if (localWrittenBytes > 0
                            && ((FileRegion) message).getRemainingBytes() > 0) {
                        writtenBytes += localWrittenBytes;
                        setInterestedInWrite(session, true);
                        return false;
                    }
                } else {
                    throw new IllegalStateException(
                            "Don't know how to handle message of type '"
                                    + message.getClass().getName()
                                    + "'.  Are you missing a protocol encoder?");
                }

                if (localWrittenBytes == 0) {
                    // Kernel buffer is full.
                    setInterestedInWrite(session, true);
                    return false;
                }

                writtenBytes += localWrittenBytes;

                if (writtenBytes >= maxWrittenBytes) {
                    // Wrote too much
                    scheduleFlush(session);
                    return false;
                }
            } while (writtenBytes < maxWrittenBytes);
        } catch (Exception e) {
            if (req != null) {
                req.getFuture().setException(e);
            }
           
            IoFilterChain filterChain = session.getFilterChain();
            filterChain.fireExceptionCaught(e);
            return false;
View Full Code Here

Examples of org.apache.mina.core.write.WriteRequest

                Object encodedMessage = bufferQueue.poll();
               
                // Flush only when the buffer has remaining.
                if (!(encodedMessage instanceof IoBuffer) || ((IoBuffer) encodedMessage).hasRemaining()) {
                    SocketAddress destination = writeRequest.getDestination();
                    WriteRequest encodedWriteRequest = new EncodedWriteRequest(encodedMessage, null, destination);

                    nextFilter.filterWrite(session, encodedWriteRequest);
                }
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.