Examples of WriteRequest


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

        }
    }

    private void flushWrites() {
        for (; ;) {
            WriteRequest req = getCurrentWriteRequest();
            if (req == null) {
                req = getWriteRequestQueue().poll(this);
                if (req == null) {
                    break;
                }
            }

            IoBuffer buf = (IoBuffer) req.getMessage();
            if (buf.remaining() == 0) {
                setCurrentWriteRequest(null);
                buf.reset();
                this.getFilterChain().fireMessageSent(req);
                continue;
View Full Code Here

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

        int writtenBytes = 0;
       
        try {
            for (;;) {
                WriteRequest req = session.getCurrentWriteRequest();
               
                if (req == null) {
                    req = writeRequestQueue.poll(session);
                    if (req == null) {
                        break;
                    }
                    session.setCurrentWriteRequest(req);
                }

                IoBuffer buf = (IoBuffer) req.getMessage();
               
                if (buf.remaining() == 0) {
                    // Clear and fire event
                    session.setCurrentWriteRequest(null);
                    buf.reset();
                    session.getFilterChain().fireMessageSent(req);
                    continue;
                }

                SocketAddress destination = req.getDestination();
               
                if (destination == null) {
                    destination = session.getRemoteAddress();
                }
View Full Code Here

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

        // If the session has been closed or is closing, we can't either
        // send a message to the remote side. We generate a future
        // containing an exception.
        if (isClosing() || !isConnected()) {
            WriteFuture future = new DefaultWriteFuture(this);
            WriteRequest request = new DefaultWriteRequest(message, future, remoteAddress);
            WriteException writeException = new WriteToClosedSessionException(request);
            future.setException(writeException);
            return future;
        }

        FileChannel openedFileChannel = null;
       
        // TODO: remove this code as soon as we use InputStream
        // instead of Object for the message.
        try {
            if (message instanceof IoBuffer
                    && !((IoBuffer) message).hasRemaining()) {
                // Nothing to write : probably an error in the user code
                throw new IllegalArgumentException(
                "message is empty. Forgot to call flip()?");
            } else if (message instanceof FileChannel) {
                FileChannel fileChannel = (FileChannel) message;
                message = new DefaultFileRegion(fileChannel, 0, fileChannel.size());
            } else if (message instanceof File) {
                File file = (File) message;
                openedFileChannel = new FileInputStream(file).getChannel();
                message = new FilenameFileRegion(file, openedFileChannel, 0, openedFileChannel.size());
            }
        } catch (IOException e) {
            ExceptionMonitor.getInstance().exceptionCaught(e);
            return DefaultWriteFuture.newNotWrittenFuture(this, e);
        }

        // Now, we can write the message. First, create a future
        WriteFuture writeFuture = new DefaultWriteFuture(this);
        WriteRequest writeRequest = new DefaultWriteRequest(message, writeFuture, remoteAddress);
       
        // Then, get the chain and inject the WriteRequest into it
        IoFilterChain filterChain = getFilterChain();
        filterChain.fireFilterWrite(writeRequest);
View Full Code Here

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

    /**
     * {@inheritDoc}
     */
    public final Object getCurrentWriteMessage() {
        WriteRequest req = getCurrentWriteRequest();
        if (req == null) {
            return null;
        }
        return req.getMessage();
    }
View Full Code Here

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

        long writeTimeout = session.getConfig().getWriteTimeoutInMillis();
        if (writeTimeout > 0 &&
                currentTime - session.getLastWriteTime() >= writeTimeout &&
                !session.getWriteRequestQueue().isEmpty(session)) {
            WriteRequest request = session.getCurrentWriteRequest();
            if (request != null) {
                session.setCurrentWriteRequest(null);
                WriteTimeoutException cause = new WriteTimeoutException(request);
                request.getFuture().setException(cause);
                session.getFilterChain().fireExceptionCaught(cause);
                // WriteException is an IOException, so we close the session.
                session.close(true);
            }
        }
View Full Code Here

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

        /**
         * {@inheritDoc}
         */
        public synchronized WriteRequest poll(IoSession session) {
            WriteRequest answer = queue.poll(session);

            if (answer == CLOSE_REQUEST) {
                AbstractIoSession.this.close();
                dispose(session);
                answer = null;
View Full Code Here

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

                // Do nothing
            }

            public void flush(AbstractIoSession session) {
                DummySession s = (DummySession) session;
                WriteRequest req = s.getWriteRequestQueue().poll(session);
               
                // Chek that the request is not null. If the session has been closed,
                // we may not have any pending requests.
                if (req != null) {
                    Object m = req.getMessage();
                    if (m instanceof FileRegion) {
                        FileRegion file = (FileRegion) m;
                        try {
                            file.getFileChannel().position(file.getPosition() + file.getRemainingBytes());
                            file.update(file.getRemainingBytes());
View Full Code Here

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

    @Test
    public void testWholeResponse() throws Exception {
        Request req = new Request(1, new Object(), Long.MAX_VALUE);
        Response res = new Response(req, new Message(1, ResponseType.WHOLE),
                ResponseType.WHOLE);
        WriteRequest rwr = new DefaultWriteRequest(req);

        // Record
        nextFilter.filterWrite(session, new DefaultWriteRequest(req
                .getMessage()));
        nextFilterControl.setMatcher(matcher);
View Full Code Here

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

        Request req = new Request(1, new Object(), Long.MAX_VALUE);
        Response res1 = new Response(req, new Message(1, ResponseType.PARTIAL),
                ResponseType.PARTIAL);
        Response res2 = new Response(req, new Message(1,
                ResponseType.PARTIAL_LAST), ResponseType.PARTIAL_LAST);
        WriteRequest rwr = new DefaultWriteRequest(req);

        // Record
        nextFilter.filterWrite(session, new DefaultWriteRequest(req
                .getMessage()));
        nextFilterControl.setMatcher(matcher);
View Full Code Here

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

    @Test
    public void testWholeResponseTimeout() throws Exception {
        Request req = new Request(1, new Object(), 10); // 10ms timeout
        Response res = new Response(req, new Message(1, ResponseType.WHOLE),
                ResponseType.WHOLE);
        WriteRequest rwr = new DefaultWriteRequest(req);

        // Record
        nextFilter.filterWrite(session, new DefaultWriteRequest(req
                .getMessage()));
        nextFilterControl.setMatcher(matcher);
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.