Package org.apache.http.nio.reactor

Examples of org.apache.http.nio.reactor.IOSession


    }

    @Test
    public void testSuccessfulConnect() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        IOSession session = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest.getSession()).thenReturn(session);
        BasicFuture<LocalPoolEntry> future = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest, future);
        Assert.assertEquals(1, pool.getAllocatedCount());
View Full Code Here


    }

    @Test
    public void testLeaseRelease() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        IOSession session1 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest1 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest1.getSession()).thenReturn(session1);
        BasicFuture<LocalPoolEntry> future1 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest1, future1);
        IOSession session2 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest2 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest2.getSession()).thenReturn(session2);
        BasicFuture<LocalPoolEntry> future2 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest2, future2);
        IOSession session3 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest3 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest3.getSession()).thenReturn(session3);
        BasicFuture<LocalPoolEntry> future3 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest3, future3);
View Full Code Here

    @Test
    public void testLeaseReleaseStateful() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();

        IOSession session1 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest1 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest1.getSession()).thenReturn(session1);
        BasicFuture<LocalPoolEntry> future1 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest1, future1);
        IOSession session2 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest2 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest2.getSession()).thenReturn(session2);
        BasicFuture<LocalPoolEntry> future2 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest2, future2);
        IOSession session3 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest3 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest3.getSession()).thenReturn(session3);
        BasicFuture<LocalPoolEntry> future3 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest3, future3);
View Full Code Here

    }

    @Test(expected=IllegalStateException.class)
    public void testReleaseInvalidEntry() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        IOSession session = Mockito.mock(IOSession.class);
        LocalPoolEntry entry = new LocalPoolEntry("whatever", session);
        pool.free(entry, true);
    }
View Full Code Here

    }

    @Test
    public void testRemove() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        IOSession session1 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest1 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest1.getSession()).thenReturn(session1);
        BasicFuture<LocalPoolEntry> future1 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest1, future1);
        IOSession session2 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest2 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest2.getSession()).thenReturn(session2);
        BasicFuture<LocalPoolEntry> future2 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest2, future2);
        IOSession session3 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest3 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest3.getSession()).thenReturn(session3);
        BasicFuture<LocalPoolEntry> future3 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest3, future3);
View Full Code Here

    }

    @Test
    public void testShutdown() throws Exception {
        LocalRoutePool pool = new LocalRoutePool();
        IOSession session1 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest1 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest1.getSession()).thenReturn(session1);
        BasicFuture<LocalPoolEntry> future1 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest1, future1);
        IOSession session2 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest2 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest2.getSession()).thenReturn(session2);
        BasicFuture<LocalPoolEntry> future2 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest2, future2);
        IOSession session3 = Mockito.mock(IOSession.class);
        SessionRequest sessionRequest3 = Mockito.mock(SessionRequest.class);
        Mockito.when(sessionRequest3.getSession()).thenReturn(session3);
        BasicFuture<LocalPoolEntry> future3 = new BasicFuture<LocalPoolEntry>(null);
        pool.addPending(sessionRequest3, future3);
View Full Code Here

            }
            if (key.isWritable()) {
                writable(key);
            }
        } catch (CancelledKeyException ex) {
            IOSession session = keyCancelled(key);
            if (session != null) {
                this.closedSessions.push(session);
            }
            key.attach(null);
        }
View Full Code Here

            } catch (IOException ex) {
                throw new IOReactorException("Failure registering channel " +
                        "with the selector", ex);
            }

            IOSession session = new IOSessionImpl(key, new SessionClosedCallback() {

                public void sessionClosed(IOSession session) {
                    closedSessions.push(session);
                }
               
            });
           
            int timeout = 0;
            try {
                timeout = channel.socket().getSoTimeout();
            } catch (IOException ex) {
                // Very unlikely to happen and is not fatal
                // as the protocol layer is expected to overwrite
                // this value anyways
            }
           
            session.setAttribute(IOSession.ATTACHMENT_KEY, entry.getAttachment());
            session.setSocketTimeout(timeout);
            this.sessions.add(session);
            keyCreated(key, session);

            try {
                this.eventDispatch.connected(session);
View Full Code Here

            }
        }
    }

    private void processClosedSessions() {
        IOSession session;
        while ((session = this.closedSessions.pop()) != null) {
            if (this.sessions.remove(session)) {
                this.eventDispatch.disconnected(session);
            }
        }
View Full Code Here

        }
    }

    private void closeSessions() {
        for (Iterator it = this.sessions.iterator(); it.hasNext(); ) {
            IOSession session = (IOSession) it.next();
            if (!session.isClosed()) {   

                session.close();
                this.eventDispatch.disconnected(session);
            }
        }
        this.sessions.clear();
    }
View Full Code Here

TOP

Related Classes of org.apache.http.nio.reactor.IOSession

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.