Author: trustin Date: Sun Dec 5 03:05:31 2004 New Revision: 109879 URL: http://svn.apache.org/viewcvs?view=rev&rev=109879 Log: * Added: Session.get/setAttachment()
* Added: Connector.connect() with timeout support * Modified: Connector.connect() is blocking operation now, and thus throws IOException. * Fixed: TcpIoProcessor didn't fire sessionIdle event. * Renamed: examples.echo.server to examples.echoserver * Added: NetCat example (org.apache.netty.example.netcat) * Added: MessageParseException * Modified: Codec.decode() throws MessageParseException Added: incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/netcat/Main.java (contents, props changed) incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/netcat/NetCatSessionHandler.java (contents, props changed) incubator/directory/seda/branches/trustin/src/java/org/apache/netty/common/util/ByteBuffers.java (contents, props changed) incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpConnector.java (contents, props changed) incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/MessageParseException.java (contents, props changed) Removed: incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/echo/server/ Modified: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Connector.java incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Session.java incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpSession.java incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Codec.java incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Connector.java incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Session.java incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/SessionHandler.java Added: incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/netcat/Main.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/netcat/Main.java?view=auto&rev=109879 ============================================================================== --- (empty file) +++ incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/netcat/Main.java Sun Dec 5 03:05:31 2004 @@ -0,0 +1,45 @@ +/* + * 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.netcat; + +import java.net.InetSocketAddress; + +import org.apache.netty.downstream.impl.tcp.TcpConnector; + + +/** + * TODO Document me. + * + * @author Trustin Lee ([EMAIL PROTECTED]) + * @version $Rev$, $Date$, + */ +public class Main { + public static void main(String[] args) throws Exception { + if (args.length != 2) { + System.out.println(Main.class.getName() + " <hostname> <port>"); + return; + } + + TcpConnector connector = new TcpConnector(); + connector.connect(new InetSocketAddress(args[0], + Integer.parseInt(args[1])), + 60, new NetCatSessionHandler()); + } +} Added: incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/netcat/NetCatSessionHandler.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/netcat/NetCatSessionHandler.java?view=auto&rev=109879 ============================================================================== --- (empty file) +++ incubator/directory/seda/branches/trustin/src/examples/org/apache/netty/examples/netcat/NetCatSessionHandler.java Sun Dec 5 03:05:31 2004 @@ -0,0 +1,62 @@ +/* + * 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.netcat; + +import org.apache.netty.common.IdleStatus; +import org.apache.netty.downstream.ReadBuffer; +import org.apache.netty.downstream.Session; +import org.apache.netty.downstream.SessionHandler; + + +/** + * TODO Document me. + * + * @author Trustin Lee ([EMAIL PROTECTED]) + * @version $Rev$, $Date$, + */ +public class NetCatSessionHandler implements SessionHandler { + public void sessionOpened(Session session) { + session.getConfig().setIdleTime(IdleStatus.READER_IDLE, 10); + } + + public void sessionClosed(Session session) { + System.err.println("Total " + session.getReadBytes() + " byte(s)"); + } + + public void sessionIdle(Session session, IdleStatus status) { + session.close(); + } + + public void exceptionCaught(Session session, Throwable cause) { + } + + public void dataRead(Session session, int readBytes) { + ReadBuffer buf = session.getReadBuffer(); + + while (buf.hasRemaining()) { + System.out.print((char) buf.get()); + } + buf.signal(); + System.out.flush(); + } + + public void dataWritten(Session session, int writtenBytes) { + } +} Added: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/common/util/ByteBuffers.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/common/util/ByteBuffers.java?view=auto&rev=109879 ============================================================================== --- (empty file) +++ incubator/directory/seda/branches/trustin/src/java/org/apache/netty/common/util/ByteBuffers.java Sun Dec 5 03:05:31 2004 @@ -0,0 +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.common.util; + +import java.nio.ByteBuffer; + + +/** + * @author Trustin Lee ([EMAIL PROTECTED]) + * @version $Rev$, $Date$ + */ +public class ByteBuffers { + private static final byte[] highDigits; + private static final byte[] lowDigits; + + // initialize lookup tables + static { + final byte[] digits = + { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + + int i; + byte[] high = new byte[256]; + byte[] low = new byte[256]; + + for (i = 0; i < 256; i++) { + high[i] = digits[i >>> 4]; + low[i] = digits[i & 0x0F]; + } + + highDigits = high; + lowDigits = low; + } + + public static String getHexdump(ByteBuffer in) { + int size = in.remaining(); + + if (size == 0) { + return "empty"; + } + + StringBuffer out = new StringBuffer((in.remaining() * 3) - 1); + + in.mark(); + + // fill the first + int byteValue = in.get() & 0xFF; + out.append((char) highDigits[byteValue]); + out.append((char) lowDigits[byteValue]); + size--; + + // and the others, too + for (; size > 0; size--) { + out.append(' '); + byteValue = in.get() & 0xFF; + out.append((char) highDigits[byteValue]); + out.append((char) lowDigits[byteValue]); + } + + in.reset(); + + return out.toString(); + } +} Modified: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Connector.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Connector.java?view=diff&rev=109879&p1=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Connector.java&r1=109878&p2=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Connector.java&r2=109879 ============================================================================== --- incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Connector.java (original) +++ incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Connector.java Sun Dec 5 03:05:31 2004 @@ -19,6 +19,10 @@ */ package org.apache.netty.downstream; +import java.io.IOException; + +import java.net.SocketAddress; + /** * TODO Insert type comment. @@ -27,5 +31,9 @@ * @version $Rev$, $Date$ */ public interface Connector { - void connect(Session session, SessionHandler defaultHandler); + void connect(SocketAddress address, SessionHandler defaultHandler) + throws IOException; + + void connect(SocketAddress address, int timeout, + SessionHandler defaultHandler) throws IOException; } Modified: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Session.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Session.java?view=diff&rev=109879&p1=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Session.java&r1=109878&p2=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Session.java&r2=109879 ============================================================================== --- incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Session.java (original) +++ incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/Session.java Sun Dec 5 03:05:31 2004 @@ -38,6 +38,10 @@ void close(); + Object getAttachment(); + + void setAttachment(Object attachment); + ReadBuffer getReadBuffer(); WriteBuffer getWriteBuffer(); Added: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpConnector.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpConnector.java?view=auto&rev=109879 ============================================================================== --- (empty file) +++ incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpConnector.java Sun Dec 5 03:05:31 2004 @@ -0,0 +1,212 @@ +/* + * 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.downstream.impl.tcp; + +import java.io.IOException; + +import java.net.ConnectException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; + +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.SocketChannel; + +import java.util.Iterator; +import java.util.Set; + +import org.apache.commons.lang.Validate; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.netty.downstream.Connector; +import org.apache.netty.downstream.SessionHandler; + + +/** + * TODO Insert type comment. + * TODO Stop worker thread when not used. + * + * @author Trustin Lee ([EMAIL PROTECTED]) + * @version $Rev$, $Date$ + */ +public class TcpConnector implements Connector { + private static volatile int nextId = 0; + private static final Log log = LogFactory.getLog(TcpConnector.class); + private final int id = nextId++; + private final Selector selector; + private Worker worker; + + /** + * Creates a new instance. + * @throws IOException + */ + public TcpConnector() throws IOException { + selector = Selector.open(); + } + + public void connect(SocketAddress address, SessionHandler defaultHandler) + throws IOException { + connect(address, Integer.MAX_VALUE, defaultHandler); + } + + public void connect(SocketAddress address, int timeout, + SessionHandler defaultHandler) + throws IOException { + Validate.notNull(address); + Validate.notNull(defaultHandler); + + if (timeout <= 0) + throw new IllegalArgumentException("Illegal timeout: " + timeout); + + if (!(address instanceof InetSocketAddress)) + throw new IllegalArgumentException("Unexpected address type: " + + address.getClass()); + + SocketChannel ch = SocketChannel.open(); + ch.configureBlocking(false); + + if (ch.connect(address)) { + newSession(ch, defaultHandler); + } else { + ConnectEntry entry = new ConnectEntry(timeout, defaultHandler); + ch.register(selector, SelectionKey.OP_CONNECT, entry); + + if (worker == null) { + synchronized (this) { + if (worker == null) { + worker = new Worker(); + worker.start(); + } + } + } + + synchronized (entry) { + while (!entry.done) { + try { + entry.wait(); + } catch (InterruptedException e) { + } + } + } + + if (entry.exception != null) + throw entry.exception; + } + } + + private void processSessions(Set keys) { + Iterator it = keys.iterator(); + + while (it.hasNext()) { + SelectionKey key = (SelectionKey) it.next(); + + if (!key.isConnectable()) + continue; + + SocketChannel ch = (SocketChannel) key.channel(); + ConnectEntry entry = (ConnectEntry) key.attachment(); + + try { + ch.finishConnect(); + entry.done = true; + + synchronized (entry) { + entry.notify(); + } + + newSession(ch, entry.handler); + } catch (IOException e) { + entry.exception = e; + entry.done = true; + + synchronized (entry) { + entry.notify(); + } + } finally { + key.cancel(); + } + } + + keys.clear(); + } + + private void processTimedOutSessions(Set keys) { + long currentTime = System.currentTimeMillis(); + Iterator it = keys.iterator(); + + while (it.hasNext()) { + SelectionKey key = (SelectionKey) it.next(); + + if (!key.isValid()) + continue; + + ConnectEntry entry = (ConnectEntry) key.attachment(); + + if (currentTime >= entry.deadline) { + entry.exception = new ConnectException(); + entry.done = true; + + synchronized (entry) { + entry.notify(); + } + + key.cancel(); + } + } + } + + private void newSession(SocketChannel ch, SessionHandler handler) { + TcpSession session = new TcpSession(ch, handler); + TcpIoProcessor.getInstance().addSession(session); + } + + private class Worker extends Thread { + public Worker() { + super("TcpConnector-" + id); + } + + public void run() { + for (;;) { + try { + int nKeys = selector.select(1000); + + if (nKeys > 0) + processSessions(selector.selectedKeys()); + + processTimedOutSessions(selector.keys()); + } catch (IOException e) { + log.error("Unexpected exception.", e); + } + } + } + } + + private static class ConnectEntry { + private final long deadline; + private final SessionHandler handler; + private boolean done; + private IOException exception; + + private ConnectEntry(int timeout, SessionHandler handler) { + this.deadline = System.currentTimeMillis() + timeout * 1000L; + this.handler = handler; + } + } +} Modified: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java?view=diff&rev=109879&p1=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java&r1=109878&p2=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java&r2=109879 ============================================================================== --- incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java (original) +++ incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpIoProcessor.java Sun Dec 5 03:05:31 2004 @@ -39,7 +39,7 @@ /** * TODO Document me. - * TODO Implement markRemoved + * TODO Stop worker thread if there is no session to process * * @author Trustin Lee ([EMAIL PROTECTED]) * @version $Rev$, $Date$, @@ -105,6 +105,7 @@ public void addReadableSession(TcpSession session) { SelectionKey key = session.getSelectionKey(); + if ((key.interestOps() & SelectionKey.OP_READ) == 0) key.interestOps(key.interestOps() | SelectionKey.OP_READ); } @@ -281,7 +282,7 @@ private void notifyIdleSession0(TcpSession session, long currentTime, long idleTime, IdleStatus status, long lastIoTime) { - if (idleTime > 0 && session.isIdle(status) && + if (idleTime > 0 && !session.isIdle(status) && (currentTime - lastIoTime) >= idleTime) { session.setIdle(status); fireSessionIdle(session, status); Modified: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpSession.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpSession.java?view=diff&rev=109879&p1=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpSession.java&r1=109878&p2=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpSession.java&r2=109879 ============================================================================== --- incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpSession.java (original) +++ incubator/directory/seda/branches/trustin/src/java/org/apache/netty/downstream/impl/tcp/TcpSession.java Sun Dec 5 03:05:31 2004 @@ -48,6 +48,7 @@ private final TcpWriteBuffer writeBuf; private SelectionKey key; private SessionHandler handler; + private Object attachment; private long readBytes; private long writtenBytes; private long lastReadTime; @@ -96,6 +97,14 @@ public void close() { TcpIoProcessor.getInstance().removeSession(this); + } + + public Object getAttachment() { + return attachment; + } + + public void setAttachment(Object attachment) { + this.attachment = attachment; } public ReadBuffer getReadBuffer() { Modified: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Codec.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Codec.java?view=diff&rev=109879&p1=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Codec.java&r1=109878&p2=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Codec.java&r2=109879 ============================================================================== --- incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Codec.java (original) +++ incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Codec.java Sun Dec 5 03:05:31 2004 @@ -31,5 +31,6 @@ public interface Codec { boolean encode(Session session, Object message, ByteBuffer out); - Object decode(Session session, ByteBuffer in); + Object decode(Session session, ByteBuffer in) + throws MessageParseException; } Modified: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Connector.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Connector.java?view=diff&rev=109879&p1=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Connector.java&r1=109878&p2=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Connector.java&r2=109879 ============================================================================== --- incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Connector.java (original) +++ incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Connector.java Sun Dec 5 03:05:31 2004 @@ -19,6 +19,8 @@ */ package org.apache.netty.upstream; +import java.io.IOException; + import java.net.SocketAddress; @@ -29,5 +31,9 @@ * @version $Rev$, $Date$ */ public interface Connector { - void connect(SocketAddress address, SessionHandler defaultHandler); + void connect(SocketAddress address, SessionHandler defaultHandler) + throws IOException; + + void connect(SocketAddress address, int timeout, + SessionHandler defaultHandler) throws IOException; } Added: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/MessageParseException.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/MessageParseException.java?view=auto&rev=109879 ============================================================================== --- (empty file) +++ incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/MessageParseException.java Sun Dec 5 03:05:31 2004 @@ -0,0 +1,98 @@ +/* + * 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. + * + */ +package org.apache.netty.upstream; + +import java.io.IOException; + +import java.nio.ByteBuffer; + +import org.apache.commons.lang.Validate; +import org.apache.netty.common.util.ByteBuffers; + + +/** + * An exception that is thrown when [EMAIL PROTECTED] Codec} cannot understand or + * validate incoming data. + * + * @author Trustin Lee ([EMAIL PROTECTED]) + * @version $Rev$, $Date$ + */ +public class MessageParseException extends IOException { + private ByteBuffer buffer; + + /** + * Constructs a new instance. + */ + public MessageParseException() { + } + + /** + * Constructs a new instance with the specified message. + */ + public MessageParseException(String message) { + super(message); + } + + /** + * Constructs a new instance with the specified cause. + */ + public MessageParseException(Throwable cause) { + initCause(cause); + } + + /** + * Constructs a new instance with the specified message and the specified + * cause. + */ + public MessageParseException(String message, Throwable cause) { + super(message); + initCause(cause); + } + + /** + * Returns the message and the hexdump of the unknown part. + */ + public String getMessage() { + String message = super.getMessage(); + + if (message == null) { + message = ""; + } + + if (buffer != null) { + return message + ((message.length() > 0) ? " " : "") + + "(Hexdump: " + ByteBuffers.getHexdump(buffer) + ')'; + } else { + return message; + } + } + + /** + * Returns unknown message part. + */ + public ByteBuffer getBuffer() { + return buffer; + } + + /** + * Sets unknown message part. + */ + public void setBuffer(ByteBuffer buffer) { + Validate.notNull(buffer); + this.buffer = buffer; + } +} Modified: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Session.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Session.java?view=diff&rev=109879&p1=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Session.java&r1=109878&p2=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Session.java&r2=109879 ============================================================================== --- incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Session.java (original) +++ incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/Session.java Sun Dec 5 03:05:31 2004 @@ -1,66 +1,70 @@ -/* - * 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.upstream; - -import java.net.SocketAddress; - -import org.apache.netty.common.IdleStatus; -import org.apache.netty.common.SessionConfig; - - -/** - * TODO Insert type comment. - * - * @author Trustin Lee ([EMAIL PROTECTED]) - * @version $Rev$, $Date$ - */ -public interface Session { - void addHandler(SessionHandler handler); - - void removeHandler(SessionHandler handler); - - Codec getCodec(); - - void setCodec(Codec codec); - - void close(); - - boolean write(Object message); - - void notifyWhenWritable(); - - boolean isConnected(); - - boolean isClosed(); - - SessionConfig getConfig(); - - SocketAddress getRemoteAddress(); - - SocketAddress getLocalAddress(); - - long getLastIoTime(); - - long getLastReadTime(); - - long getLastWriteTime(); - - boolean isIdle(IdleStatus status); -} +/* + * 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.upstream; + +import java.net.SocketAddress; + +import org.apache.netty.common.IdleStatus; +import org.apache.netty.common.SessionConfig; + + +/** + * TODO Insert type comment. + * + * @author Trustin Lee ([EMAIL PROTECTED]) + * @version $Rev$, $Date$ + */ +public interface Session { + void addHandler(SessionHandler handler); + + void removeHandler(SessionHandler handler); + + Codec getCodec(); + + void setCodec(Codec codec); + + void close(); + + Object getAttachment(); + + void setAttachment(Object attachment); + + boolean write(Object message); + + void notifyWhenWritable(); + + boolean isConnected(); + + boolean isClosed(); + + SessionConfig getConfig(); + + SocketAddress getRemoteAddress(); + + SocketAddress getLocalAddress(); + + long getLastIoTime(); + + long getLastReadTime(); + + long getLastWriteTime(); + + boolean isIdle(IdleStatus status); +} Modified: incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/SessionHandler.java Url: http://svn.apache.org/viewcvs/incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/SessionHandler.java?view=diff&rev=109879&p1=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/SessionHandler.java&r1=109878&p2=incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/SessionHandler.java&r2=109879 ============================================================================== --- incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/SessionHandler.java (original) +++ incubator/directory/seda/branches/trustin/src/java/org/apache/netty/upstream/SessionHandler.java Sun Dec 5 03:05:31 2004 @@ -1,45 +1,45 @@ -/* - * 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.upstream; - -import org.apache.netty.common.IdleStatus; - - -/** - * TODO Insert type comment. - * - * @author Trustin Lee ([EMAIL PROTECTED]) - * @version $Rev$, $Date$ - */ -public interface SessionHandler { - void sessionOpened(Session session); - - void sessionClosed(Session session); - - void sessionIdle(Session session, IdleStatus status); - - void exceptionCaught(Session session, Throwable cause); - - void messageReceived(Session session, Object message); - - void messageSent(Session session, Object message); - - void sessionWritable(Session session); -} +/* + * 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.upstream; + +import org.apache.netty.common.IdleStatus; + + +/** + * TODO Insert type comment. + * + * @author Trustin Lee ([EMAIL PROTECTED]) + * @version $Rev$, $Date$ + */ +public interface SessionHandler { + void sessionOpened(Session session); + + void sessionClosed(Session session); + + void sessionIdle(Session session, IdleStatus status); + + void exceptionCaught(Session session, Throwable cause); + + void messageReceived(Session session, Object message); + + void messageSent(Session session, Object message); + + void sessionWritable(Session session); +}
