Author: trustin Date: Sun Dec 5 03:29:37 2004 New Revision: 109881 URL: http://svn.apache.org/viewcvs?view=rev&rev=109881 Log: Something's screed up. Recommitting. Modified: incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/EchoServerSessionHandler.java incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/Main.java
Modified: incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/EchoServerSessionHandler.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/EchoServerSessionHandler.java?view=diff&rev=109881&p1=incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/EchoServerSessionHandler.java&r1=109880&p2=incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/EchoServerSessionHandler.java&r2=109881 ============================================================================== --- incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/EchoServerSessionHandler.java (original) +++ incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/EchoServerSessionHandler.java Sun Dec 5 03:29:37 2004 @@ -1,48 +1,80 @@ /* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +/* * @(#) $Id$ */ -package org.apache.netty.examples.echo.server; - -import java.nio.ByteBuffer; +package org.apache.netty.examples.echoserver; import org.apache.netty.common.IdleStatus; +import org.apache.netty.downstream.ReadBuffer; import org.apache.netty.downstream.Session; import org.apache.netty.downstream.SessionHandler; +import org.apache.netty.downstream.WriteBuffer; + /** * TODO Document me. - * + * * @author Trustin Lee ([EMAIL PROTECTED]) - * @version $Rev$, $Date$, + * @version $Rev$, $Date$, */ public class EchoServerSessionHandler implements SessionHandler { - - public void sessionOpened(Session session) { - System.out.println(session.getRemoteAddress() + ": OPEN"); - } - - public void sessionClosed(Session session) { - System.out.println(session.getRemoteAddress() + ": CLOSED"); - } - - public void sessionIdle(Session session, IdleStatus status) { - System.out.println(session.getRemoteAddress() + ": IDLE"); - } - - public void exceptionCaught(Session session, Throwable cause) { - System.out.println(session.getRemoteAddress() + ": EXCEPTION"); - cause.printStackTrace(System.out); - } - - public void dataRead(Session session, ByteBuffer buf) { - System.out.println(session.getRemoteAddress() + ": READ (" + buf.remaining() + " B)"); - session.getWriteBuffer().put(buf); - session.flush(); - } - - public void markRemoved(Session session, Object mark) { - } - - public void writeBufferAvailable(Session session) { - } + public void sessionOpened(Session session) { + System.out.println(session.getRemoteAddress() + ": OPEN"); + } + + public void sessionClosed(Session session) { + System.out.println(session.getRemoteAddress() + ": CLOSED"); + } + + public void sessionIdle(Session session, IdleStatus status) { + System.out.println(session.getRemoteAddress() + ": IDLE"); + } + + public void exceptionCaught(Session session, Throwable cause) { + System.out.println(session.getRemoteAddress() + ": EXCEPTION"); + cause.printStackTrace(System.out); + } + + public void dataRead(Session session, int readBytes) { + System.out.println(session.getRemoteAddress() + ": READ (" + + readBytes + "B)"); + + ReadBuffer rb = session.getReadBuffer(); + WriteBuffer wb = session.getWriteBuffer(); + + if (rb.remaining() <= wb.remaining()) { + wb.put(rb); + wb.flush(); + rb.signal(); + } + } + + public void dataWritten(Session session, int writtenBytes) { + System.out.println(session.getRemoteAddress() + ": WRITTEN (" + + writtenBytes + "B)"); + + ReadBuffer rb = session.getReadBuffer(); + WriteBuffer wb = session.getWriteBuffer(); + + if (rb.hasRemaining() && rb.remaining() <= wb.remaining()) { + wb.put(rb); + wb.flush(); + rb.signal(); + } + } } Modified: incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/Main.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/Main.java?view=diff&rev=109881&p1=incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/Main.java&r1=109880&p2=incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/Main.java&r2=109881 ============================================================================== --- incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/Main.java (original) +++ incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echoserver/Main.java Sun Dec 5 03:29:37 2004 @@ -1,22 +1,43 @@ /* + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +/* * @(#) $Id$ */ -package org.apache.netty.examples.echo.server; +package org.apache.netty.examples.echoserver; import java.net.InetSocketAddress; import org.apache.netty.downstream.Acceptor; import org.apache.netty.downstream.impl.tcp.TcpAcceptor; + /** * TODO Document me. - * + * * @author Trustin Lee ([EMAIL PROTECTED]) - * @version $Rev$, $Date$, + * @version $Rev$, $Date$, */ public class Main { - public static void main(String[] args) throws Exception { - Acceptor acceptor = new TcpAcceptor(); - acceptor.bind(new InetSocketAddress(8080), new EchoServerSessionHandler()); - } + private static final int PORT = 8080; + + public static void main(String[] args) throws Exception { + Acceptor acceptor = new TcpAcceptor(); + acceptor.bind(new InetSocketAddress(PORT), + new EchoServerSessionHandler()); + System.out.println("Listening on port " + PORT); + } }
