Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 9706 invoked from network); 21 Apr 2005 09:20:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Apr 2005 09:20:12 -0000 Received: (qmail 77711 invoked by uid 500); 21 Apr 2005 09:19:58 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 77594 invoked by uid 500); 21 Apr 2005 09:19:57 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 77524 invoked by uid 99); 21 Apr 2005 09:19:56 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 21 Apr 2005 02:19:51 -0700 Received: (qmail 9473 invoked by uid 65534); 21 Apr 2005 09:19:37 -0000 Message-ID: <20050421091937.9472.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r164015 - in /directory/network/trunk/src/java/org/apache/mina: common/ io/ io/datagram/ io/filter/ io/socket/ protocol/ protocol/io/ protocol/vmpipe/ util/ Date: Thu, 21 Apr 2005 09:19:33 -0000 To: commits@directory.apache.org From: trustin@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: trustin Date: Thu Apr 21 02:19:31 2005 New Revision: 164015 URL: http://svn.apache.org/viewcvs?rev=3D164015&view=3Drev Log: * Added SessionManager interface that all acceptors and connectors extend * Moved ExceptionMonitor and its default implementation to common package * Added SessionInitializer Added: directory/network/trunk/src/java/org/apache/mina/common/DefaultExceptio= nMonitor.java (with props) directory/network/trunk/src/java/org/apache/mina/common/ExceptionMonito= r=2Ejava (with props) directory/network/trunk/src/java/org/apache/mina/common/SessionInitiali= zer.java (with props) directory/network/trunk/src/java/org/apache/mina/common/SessionManager.= java (with props) directory/network/trunk/src/java/org/apache/mina/util/BaseSessionManage= r=2Ejava (with props) directory/network/trunk/src/java/org/apache/mina/util/ExceptionUtil.jav= a (with props) Removed: directory/network/trunk/src/java/org/apache/mina/io/DefaultExceptionMon= itor.java directory/network/trunk/src/java/org/apache/mina/io/ExceptionMonitor.ja= va Modified: directory/network/trunk/src/java/org/apache/mina/io/IoAcceptor.java directory/network/trunk/src/java/org/apache/mina/io/IoConnector.java directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAc= ceptor.java directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramCo= nnector.java directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramPr= ocessor.java directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.ja= va directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAccept= or.java directory/network/trunk/src/java/org/apache/mina/io/socket/SocketConnec= tor.java directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolAccep= tor.java directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolConne= ctor.java directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocol= Acceptor.java directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocol= Connector.java directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipe= Acceptor.java directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipe= Connector.java directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipe= Session.java Added: directory/network/trunk/src/java/org/apache/mina/common/DefaultExcep= tionMonitor.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/common/DefaultExceptionMonitor.java?rev=3D164015&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/common/DefaultExceptio= nMonitor.java (added) +++ directory/network/trunk/src/java/org/apache/mina/common/DefaultExceptio= nMonitor.java Thu Apr 21 02:19:31 2005 @@ -0,0 +1,115 @@ +/* + * @(#) $Id$ + * + * 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 impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.mina.common; + +import java.lang.reflect.Method; +import java.text.DateFormat; +import java.util.Date; + +/** + * A default {@link ExceptionMonitor} implementation. It logs uncaught + * exceptions using Apache + * Jakarta Commons Logging if available. If not available, it prints = it + * out to {@link System#err}. + *=20 + * @author Trustin Lee (trustin@apache.org) + * @version $Rev$, $Date$ + */ +public class DefaultExceptionMonitor implements ExceptionMonitor +{ + private static final Object log; + + private static final Method errorMethod; + + static + { + Object tempLog =3D null; + Method tempErrorMethod =3D null; + + try + { + Class logCls =3D Class.forName( "org.apache.commons.logging.Lo= g" ); + Class logFactoryCls =3D Class + .forName( "org.apache.commons.logging.LogFactory" ); + Method getLogMethod =3D logFactoryCls + .getMethod( "getLog", new Class[] { String.class } ); + tempLog =3D getLogMethod + .invoke( null, + new Object[] { DefaultExceptionMonitor.class + .getPackage().getName() } ); + tempErrorMethod =3D logCls + .getMethod( "error", new Class[] { Object.class, + Throwable.class } ); + } + catch( Exception e ) + { + tempLog =3D null; + tempErrorMethod =3D null; + } + + log =3D tempLog; + errorMethod =3D tempErrorMethod; + } + + private final DateFormat df =3D DateFormat + .getDateTimeInstance( DateFormat.MEDIUM, DateFormat.MEDIUM ); + + private final Date date =3D new Date(); + + public void exceptionCaught( Object source, Throwable cause ) + { + if( log =3D=3D null ) + { + logToStdErr( cause ); + } + else + { + logToCommonsLogging( cause ); + } + } + + private void logToCommonsLogging( Throwable cause ) + { + try + { + errorMethod.invoke( log, new Object[] { "Uncaught exception: "= , + cause } ); + } + catch( Exception e ) + { + logToStdErr( cause ); + } + } + + private void logToStdErr( Throwable cause ) + { + synchronized( System.err ) + { + date.setTime( System.currentTimeMillis() ); + + System.err.print( '[' ); + System.err.print( df.format( date ) ); + System.err.print( "] [" ); + System.err.print( Thread.currentThread().getName() ); + System.err.print( "] Uncaught exception: " ); + cause.printStackTrace(); + } + } + +} \ No newline at end of file Propchange: directory/network/trunk/src/java/org/apache/mina/common/Default= ExceptionMonitor.java ---------------------------------------------------------------------------= --- svn:keywords =3D HeadURL Id LastChangedBy LastChangedDate LastChangedRe= vision Added: directory/network/trunk/src/java/org/apache/mina/common/ExceptionMon= itor.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/common/ExceptionMonitor.java?rev=3D164015&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/common/ExceptionMonito= r=2Ejava (added) +++ directory/network/trunk/src/java/org/apache/mina/common/ExceptionMonito= r=2Ejava Thu Apr 21 02:19:31 2005 @@ -0,0 +1,36 @@ +/* + * @(#) $Id$ + * + * 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 impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.mina.common; + +/** + * Monitors uncaught exceptions. {@link #exceptionCaught(Object, Throwabl= e)} is + * invoked when there are any uncaught exceptions. + *=20 + * @author Trustin Lee (trustin@apache.org) + * @version $Rev$, $Date$ + *=20 + * @see DefaultExceptionMonitor + */ +public interface ExceptionMonitor +{ + /** + * Invoked when there are any uncaught exceptions. + */ + void exceptionCaught( Object source, Throwable cause ); +} \ No newline at end of file Propchange: directory/network/trunk/src/java/org/apache/mina/common/Excepti= onMonitor.java ---------------------------------------------------------------------------= --- svn:keywords =3D HeadURL Id LastChangedBy LastChangedDate LastChangedRe= vision Added: directory/network/trunk/src/java/org/apache/mina/common/SessionIniti= alizer.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/common/SessionInitializer.java?rev=3D164015&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/common/SessionInitiali= zer.java (added) +++ directory/network/trunk/src/java/org/apache/mina/common/SessionInitiali= zer.java Thu Apr 21 02:19:31 2005 @@ -0,0 +1,64 @@ +/* + * @(#) $Id$ + * + * 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 impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.mina.common; + +import java.io.IOException; + +import org.apache.mina.io.IoAcceptor; +import org.apache.mina.io.IoConnector; +import org.apache.mina.protocol.ProtocolAcceptor; +import org.apache.mina.protocol.ProtocolConnector; + + +/** + * Initializes session just after it is created. + * You can adjust {@link SessionConfig} or set pre-define user-defined att= ributes + * using this before MINA actually starts communication. + *

+ * Please specify your initializer when you call: + *

    + *
  • {@link IoAcceptor}.bind(...)
  • + *
  • {@link IoConnector}.connect(...)
  • + *
  • {@link ProtocolAcceptor}.bind(...)
  • + *
  • {@link ProtocolConnector}.connect(...)
  • + *
+ *

+ * In case of bind, session is closed immediately and no event is fired if + * {@link #initializeSession(Session)} throws any exception. The exceptio= n + * is notified to ExceptionMonitor. + *

+ * In case of connect, session is closed immediately and caught exception + * is forwarded to user application context which called connect(...)<= /tt> + * method. +=20 + * @author Trustin Lee (trustin@apache.org) + * @version $Rev$, $Date$ + */ +public interface SessionInitializer { + + /** + * Initializes session just after it is created. + * You can adjust {@link SessionConfig} or set pre-define user-defined + * attributes using this before MINA actually starts communication.=20 + * Session is closed immediately and no event is fired if + * {@link #initializeSession(Session)} throws any exception. + * The exception is notified to ExceptionMonitor. + */ + void initializeSession( Session session ) throws IOException; +} Propchange: directory/network/trunk/src/java/org/apache/mina/common/Session= Initializer.java ---------------------------------------------------------------------------= --- svn:keywords =3D HeadURL Id LastChangedBy LastChangedDate LastChangedRe= vision Added: directory/network/trunk/src/java/org/apache/mina/common/SessionManag= er.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/common/SessionManager.java?rev=3D164015&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/common/SessionManager.= java (added) +++ directory/network/trunk/src/java/org/apache/mina/common/SessionManager.= java Thu Apr 21 02:19:31 2005 @@ -0,0 +1,44 @@ +/* + * @(#) $Id$ + * + * 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 impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.mina.common; + +/** + * Base interface for all acceptors and connectors that manage + * sessions. + *

+ * You can monitor any uncaught exceptions by setting {@link ExceptionMoni= tor} + * by calling {@link #setExceptionMonitor(ExceptionMonitor)}. The default + * monitor is {@link DefaultExceptionMonitor}. + *=20 + * @author Trustin Lee (trustin@apache.org) + * @version $Rev$, $Date$ + */ +public interface SessionManager { + =20 + /** + * Returns the current exception monitor. + */ + ExceptionMonitor getExceptionMonitor(); + + /** + * Sets the uncaught exception monitor. If null is speci= fied, + * a new instance of {@link DefaultExceptionMonitor} will be set. + */ + void setExceptionMonitor( ExceptionMonitor monitor ); +} Propchange: directory/network/trunk/src/java/org/apache/mina/common/Session= Manager.java ---------------------------------------------------------------------------= --- svn:keywords =3D HeadURL Id LastChangedBy LastChangedDate LastChangedRe= vision Modified: directory/network/trunk/src/java/org/apache/mina/io/IoAcceptor.ja= va URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/io/IoAcceptor.java?rev=3D164015&r1=3D164014&r2=3D164015&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/io/IoAcceptor.java (or= iginal) +++ directory/network/trunk/src/java/org/apache/mina/io/IoAcceptor.java Thu= Apr 21 02:19:31 2005 @@ -21,6 +21,9 @@ import java.io.IOException; import java.net.SocketAddress; =20 +import org.apache.mina.common.SessionInitializer; +import org.apache.mina.common.SessionManager; + /** * Accepts incoming connection, communicates with clients, and fires event= s to * {@link IoHandler}s. @@ -39,15 +42,13 @@ *

* {@link IoHandlerFilter}s can be added and removed at any time to filter * events just like Servlet filters and they are effective immediately. - *

- * You can monitor any uncaught exceptions by setting {@link ExceptionMoni= tor} - * by calling {@link #setExceptionMonitor(ExceptionMonitor)}. The default - * monitor is {@link DefaultExceptionMonitor}. *=20 * @author Trustin Lee (trustin@apache.org) * @version $Rev$, $Date$ + *=20 + * @see SessionInitializer */ -public interface IoAcceptor +public interface IoAcceptor extends SessionManager { /** * Binds to the specified address and handles incoming @@ -58,20 +59,17 @@ void bind( SocketAddress address, IoHandler handler ) throws IOExcepti= on; =20 /** - * Unbinds from the specified address. + * Binds to the specified address and handles incoming + * connections with the specified handler. + *=20 + * @throws IOException if failed to bind */ - void unbind( SocketAddress address ); + void bind( SocketAddress address, IoHandler handler, SessionInitialize= r initializer ) throws IOException; =20 - IoHandlerFilterChain getFilterChain(); - =20 /** - * Returns the current exception monitor. + * Unbinds from the specified address. */ - ExceptionMonitor getExceptionMonitor(); + void unbind( SocketAddress address ); =20 - /** - * Sets the uncaught exception monitor. If null is speci= fied, - * a new instance of {@link DefaultExceptionMonitor} will be set. - */ - void setExceptionMonitor( ExceptionMonitor monitor ); + IoHandlerFilterChain getFilterChain(); } Modified: directory/network/trunk/src/java/org/apache/mina/io/IoConnector.j= ava URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/io/IoConnector.java?rev=3D164015&r1=3D164014&r2=3D164015&view=3Ddi= ff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/io/IoConnector.java (o= riginal) +++ directory/network/trunk/src/java/org/apache/mina/io/IoConnector.java Th= u Apr 21 02:19:31 2005 @@ -21,6 +21,9 @@ import java.io.IOException; import java.net.SocketAddress; =20 +import org.apache.mina.common.SessionInitializer; +import org.apache.mina.common.SessionManager; + /** * Connects to endpoint, communicates with the server, and fires events to * {@link IoHandler}s. @@ -39,15 +42,13 @@ *

* {@link IoHandlerFilter}s can be added and removed at any time to filter * events just like Servlet filters and they are effective immediately. - *

- * You can monitor any uncaught exceptions by setting {@link ExceptionMoni= tor} - * by calling {@link #setExceptionMonitor(ExceptionMonitor)}. The default - * monitor is {@link DefaultExceptionMonitor}. *=20 * @author Trustin Lee (trustin@apache.org) * @version $Rev$, $Date$ + *=20 + * @see SessionInitializer */ -public interface IoConnector +public interface IoConnector extends SessionManager { /** * Connects to the specified address. If communication s= tarts @@ -91,16 +92,48 @@ IoSession connect( SocketAddress address, SocketAddress localAddress, int timeout, IoHandler handler ) throws IOException= ; =20 - IoHandlerFilterChain getFilterChain(); + /** + * Connects to the specified address. If communication s= tarts + * successfully, events are fired to the specified + * handler. This method blocks. + *=20 + * @throws IOException if failed to connect + */ + IoSession connect( SocketAddress address, IoHandler handler, + SessionInitializer initializer ) throws IOException= ; =20 /** - * Returns the current exception monitor. + * Connects to the specified address. If communication s= tarts + * successfully, events are fired to the specified + * handler. This method blocks. + *=20 + * @param localAddress the local address the channel is bound to + * @throws IOException if failed to connect */ - ExceptionMonitor getExceptionMonitor(); + IoSession connect( SocketAddress address, SocketAddress localAddress, + IoHandler handler, SessionInitializer initializer )= throws IOException; =20 /** - * Sets the uncaught exception monitor. If null is speci= fied, - * a new instance of {@link DefaultExceptionMonitor} will be set. + * Connects to the specified address with timeout. If + * communication starts successfully, events are fired to the specifie= d + * handler. This method blocks. + *=20 + * @throws IOException if failed to connect */ - void setExceptionMonitor( ExceptionMonitor monitor ); + IoSession connect( SocketAddress address, int timeout, IoHandler handl= er, + SessionInitializer initializer ) throws IOException= ; + =20 + /** + * Connects to the specified address with timeout. If + * communication starts successfully, events are fired to the specifie= d + * handler. This method blocks. + *=20 + * @param localAddress the local address the channel is bound to + * @throws IOException if failed to connect + */ + IoSession connect( SocketAddress address, SocketAddress localAddress, + int timeout, IoHandler handler, + SessionInitializer initializer ) throws IOException= ; + + IoHandlerFilterChain getFilterChain(); } Modified: directory/network/trunk/src/java/org/apache/mina/io/datagram/Data= gramAcceptor.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/io/datagram/DatagramAcceptor.java?rev=3D164015&r1=3D164014&r2=3D16= 4015&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAc= ceptor.java (original) +++ directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramAc= ceptor.java Thu Apr 21 02:19:31 2005 @@ -30,11 +30,11 @@ import java.util.Set; =20 import org.apache.mina.common.ByteBuffer; -import org.apache.mina.io.DefaultExceptionMonitor; -import org.apache.mina.io.ExceptionMonitor; +import org.apache.mina.common.SessionInitializer; import org.apache.mina.io.IoAcceptor; import org.apache.mina.io.IoHandler; import org.apache.mina.io.IoHandlerFilterChain; +import org.apache.mina.util.ExceptionUtil; import org.apache.mina.util.Queue; =20 /** @@ -61,8 +61,6 @@ =20 private final Queue flushingSessions =3D new Queue(); =20 - private ExceptionMonitor exceptionMonitor =3D new DefaultExceptionMoni= tor(); - private Worker worker; =20 /** @@ -78,6 +76,12 @@ public void bind( SocketAddress address, IoHandler handler ) throws IOException { + bind( address, handler, null ); + } + + public void bind( SocketAddress address, IoHandler handler, SessionIni= tializer initializer ) + throws IOException + { if( address =3D=3D null ) throw new NullPointerException( "address" ); if( handler =3D=3D null ) @@ -89,7 +93,7 @@ if( ( ( InetSocketAddress ) address ).getPort() =3D=3D 0 ) throw new IllegalArgumentException( "Unsupported port number: = 0" ); =20 - RegistrationRequest request =3D new RegistrationRequest( address, = handler ); + RegistrationRequest request =3D new RegistrationRequest( address, = handler, initializer ); synchronized( this ) { synchronized( registerQueue ) @@ -117,22 +121,7 @@ if( request.exception !=3D null ) { request.exception.fillInStackTrace(); - if( request.exception instanceof IOException ) - { - throw ( IOException ) request.exception; - } - else if( request.exception instanceof RuntimeException ) - { - throw ( RuntimeException ) request.exception; - } - else if( request.exception instanceof Error ) - { - throw ( Error ) request.exception; - } - else - { - throw new IllegalStateException(); - } + ExceptionUtil.throwException( request.exception ); } } =20 @@ -266,18 +255,31 @@ =20 DatagramChannel ch =3D ( DatagramChannel ) key.channel(); =20 + RegistrationRequest req =3D ( RegistrationRequest ) key.attach= ment(); DatagramSession session =3D new DatagramSession( - filters, ch, ( IoHandler ) key.attachment() ); + filters, ch, req.handler ); session.setSelectionKey( key ); - - if( key.isReadable() ) + =20 + try { - readSession( session ); - } + if( req.initializer !=3D null ) + { + req.initializer.initializeSession( session ); + } =20 - if( key.isWritable() ) + if( key.isReadable() ) + { + readSession( session ); + } + + if( key.isWritable() ) + { + scheduleFlush( session ); + } + } + catch( Throwable t ) { - scheduleFlush( session ); + exceptionMonitor.exceptionCaught( this, t ); } } } @@ -432,7 +434,7 @@ ch =3D DatagramChannel.open(); ch.configureBlocking( false ); ch.socket().bind( req.address ); - ch.register( selector, SelectionKey.OP_READ, req.handler )= ; + ch.register( selector, SelectionKey.OP_READ, req ); channels.put( req.address, ch ); } catch( Throwable t ) @@ -523,14 +525,18 @@ =20 private final IoHandler handler; =20 + private final SessionInitializer initializer; + =20 private Throwable exception;=20 =20 private boolean done; =20 - private RegistrationRequest( SocketAddress address, IoHandler hand= ler ) + private RegistrationRequest( SocketAddress address, IoHandler hand= ler, + SessionInitializer initializer ) { this.address =3D address; this.handler =3D handler; + this.initializer =3D initializer; } } =20 @@ -544,20 +550,5 @@ { this.address =3D address; } - } - - public ExceptionMonitor getExceptionMonitor() - { - return exceptionMonitor; - } - - public void setExceptionMonitor( ExceptionMonitor monitor ) - { - if( monitor =3D=3D null ) - { - monitor =3D new DefaultExceptionMonitor(); - } - - this.exceptionMonitor =3D monitor; } } Modified: directory/network/trunk/src/java/org/apache/mina/io/datagram/Data= gramConnector.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/io/datagram/DatagramConnector.java?rev=3D164015&r1=3D164014&r2=3D1= 64015&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramCo= nnector.java (original) +++ directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramCo= nnector.java Thu Apr 21 02:19:31 2005 @@ -21,7 +21,6 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.nio.channels.ClosedChannelException; import java.nio.channels.DatagramChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; @@ -29,12 +28,12 @@ import java.util.Set; =20 import org.apache.mina.common.ByteBuffer; -import org.apache.mina.io.DefaultExceptionMonitor; -import org.apache.mina.io.ExceptionMonitor; +import org.apache.mina.common.SessionInitializer; import org.apache.mina.io.IoConnector; import org.apache.mina.io.IoHandler; import org.apache.mina.io.IoHandlerFilterChain; import org.apache.mina.io.IoSession; +import org.apache.mina.util.ExceptionUtil; import org.apache.mina.util.Queue; =20 /** @@ -43,8 +42,7 @@ * @author Trustin Lee (trustin@apache.org) * @version $Rev$, $Date$ */ -public class DatagramConnector extends DatagramProcessor implements - IoConnector +public class DatagramConnector extends DatagramProcessor implements IoConn= ector { private static volatile int nextId =3D 0; =20 @@ -60,8 +58,6 @@ =20 private final Queue flushingSessions =3D new Queue(); =20 - private ExceptionMonitor exceptionMonitor =3D new DefaultExceptionMoni= tor(); - private Worker worker; =20 /** @@ -74,14 +70,43 @@ selector =3D Selector.open(); } =20 - public IoSession connect( SocketAddress address, IoHandler handler ) - throws IOException + public IoSession connect( SocketAddress address, IoHandler handler ) t= hrows IOException { - return connect( address, null, handler ); + return connect( address, null, handler, null ); } - =20 + + public IoSession connect( SocketAddress address, SocketAddress localAd= dress, IoHandler handler ) throws IOException + { + return connect( address, localAddress, handler, null ); + } + + public IoSession connect( SocketAddress address, int timeout, IoHandle= r handler ) throws IOException + { + return connect( address, null, handler, null ); + } + + public IoSession connect( SocketAddress address, SocketAddress localAd= dress, int timeout, IoHandler handler ) throws IOException + { + return connect( address, localAddress, handler, null ); + } + + public IoSession connect( SocketAddress address, IoHandler handler, Se= ssionInitializer initializer ) throws IOException + { + return connect( address, null, handler, initializer ); + } + + public IoSession connect( SocketAddress address, int timeout, IoHandle= r handler, SessionInitializer initializer ) throws IOException + { + return connect( address, null, handler, initializer ); + } + + public IoSession connect( SocketAddress address, SocketAddress localAd= dress, int timeout, IoHandler handler, SessionInitializer initializer ) thr= ows IOException + { + return connect( address, localAddress, handler, initializer ); + } + public IoSession connect( SocketAddress address, SocketAddress localAd= dress, - IoHandler handler ) throws IOException + IoHandler handler, SessionInitializer initia= lizer ) throws IOException { if( address =3D=3D null ) throw new NullPointerException( "address" ); @@ -118,7 +143,7 @@ } } =20 - RegistrationRequest request =3D new RegistrationRequest( ch, handl= er ); + RegistrationRequest request =3D new RegistrationRequest( ch, handl= er, initializer ); synchronized( this ) { synchronized( registerQueue ) @@ -132,7 +157,7 @@ =20 synchronized( request ) { - while( request.session =3D=3D null ) + while( !request.done ) { try { @@ -143,6 +168,12 @@ } } } + =20 + if( request.exception !=3D null ) + { + request.exception.fillInStackTrace(); + ExceptionUtil.throwException( request.exception ); + } =20 return request.session; } @@ -156,18 +187,6 @@ } } =20 - public IoSession connect( SocketAddress address, - int timeout, IoHandler handler ) throws IOEx= ception - { - return connect( address, null, timeout, handler ); - } - - public IoSession connect( SocketAddress address, SocketAddress localAd= dress, - int timeout, IoHandler handler ) throws IOEx= ception - { - return connect( address, localAddress, handler ); - } - void closeSession( DatagramSession session ) { synchronized( this ) @@ -396,7 +415,7 @@ } } =20 - private void registerNew() throws ClosedChannelException + private void registerNew() { if( registerQueue.isEmpty() ) return; @@ -415,15 +434,43 @@ DatagramSession session =3D new DatagramSession( filters, req.channel, req.handler ); =20 - SelectionKey key =3D req.channel.register( selector, - SelectionKey.OP_READ, session ); + try + { + SelectionKey key =3D req.channel.register( selector, + SelectionKey.OP_READ, session ); + =20 + session.setSelectionKey( key ); =20 - session.setSelectionKey( key ); + if( req.initializer !=3D null ) + { + req.initializer.initializeSession( session ); + } =20 - synchronized( req ) + } + catch( Throwable t ) { - req.session =3D session; - req.notify(); + req.exception =3D t; + } + finally=20 + { + synchronized( req ) + { + req.done =3D true; + req.session =3D session; + req.notify(); + } + =20 + if( req.exception !=3D null ) + { + try + { + req.channel.close(); + } + catch (IOException e) + { + exceptionMonitor.exceptionCaught( this, e ); + } + } } } } @@ -469,29 +516,21 @@ private final DatagramChannel channel; =20 private final IoHandler handler; + =20 + private final SessionInitializer initializer; =20 + private boolean done; + =20 private DatagramSession session; + =20 + private Throwable exception; =20 private RegistrationRequest( DatagramChannel channel, - IoHandler handler ) + IoHandler handler, SessionInitializer= initializer ) { this.channel =3D channel; this.handler =3D handler; + this.initializer =3D initializer; } - } - - public ExceptionMonitor getExceptionMonitor() - { - return exceptionMonitor; - } - - public void setExceptionMonitor( ExceptionMonitor monitor ) - { - if( monitor =3D=3D null ) - { - monitor =3D new DefaultExceptionMonitor(); - } - - this.exceptionMonitor =3D monitor; } } Modified: directory/network/trunk/src/java/org/apache/mina/io/datagram/Data= gramProcessor.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/io/datagram/DatagramProcessor.java?rev=3D164015&r1=3D164014&r2=3D1= 64015&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramPr= ocessor.java (original) +++ directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramPr= ocessor.java Thu Apr 21 02:19:31 2005 @@ -18,6 +18,8 @@ */ package org.apache.mina.io.datagram; =20 +import org.apache.mina.util.BaseSessionManager; + /** * A base class for {@link DatagramAcceptor} and {@link DatagramConnector}= . * Session interacts with this abstract class instead of those two concret= e @@ -26,7 +28,7 @@ * @author Trustin Lee (trustin@apache.org) * @version $Rev$, $Date$ */ -abstract class DatagramProcessor +abstract class DatagramProcessor extends BaseSessionManager { /** * Requests this processor to flush the write buffer of the specified Modified: directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFil= ter.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/io/filter/SSLFilter.java?rev=3D164015&r1=3D164014&r2=3D164015&view= =3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.ja= va (original) +++ directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.ja= va Thu Apr 21 02:19:31 2005 @@ -30,7 +30,7 @@ import javax.net.ssl.SSLHandshakeException; =20 import org.apache.mina.common.ByteBuffer; -import org.apache.mina.io.DefaultExceptionMonitor; +import org.apache.mina.common.DefaultExceptionMonitor; import org.apache.mina.io.IoHandlerFilterAdapter; import org.apache.mina.io.IoSession; =20 Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/Socket= Acceptor.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/io/socket/SocketAcceptor.java?rev=3D164015&r1=3D164014&r2=3D164015= &view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAccept= or.java (original) +++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketAccept= or.java Thu Apr 21 02:19:31 2005 @@ -30,11 +30,11 @@ import java.util.Map; import java.util.Set; =20 -import org.apache.mina.io.DefaultExceptionMonitor; -import org.apache.mina.io.ExceptionMonitor; +import org.apache.mina.common.SessionInitializer; import org.apache.mina.io.IoAcceptor; import org.apache.mina.io.IoHandler; import org.apache.mina.io.IoHandlerFilterChain; +import org.apache.mina.util.BaseSessionManager; import org.apache.mina.util.Queue; =20 /** @@ -43,7 +43,7 @@ * @author Apache Directory Pr= oject * @version $Rev$, $Date$ */ -public class SocketAcceptor implements IoAcceptor +public class SocketAcceptor extends BaseSessionManager implements IoAccept= or { private static volatile int nextId =3D 0; =20 @@ -61,8 +61,6 @@ =20 private int backlog =3D 50; =20 - private ExceptionMonitor exceptionMonitor =3D new DefaultExceptionMoni= tor(); - private Worker worker; =20 =20 @@ -76,7 +74,6 @@ selector =3D Selector.open(); } =20 - /** * Binds to the specified address and handles incoming * connections with the specified handler. Backlog value @@ -86,6 +83,19 @@ */ public void bind( SocketAddress address, IoHandler handler ) throws IO= Exception { + bind( address, handler, null ); + } + + /** + * Binds to the specified address and handles incoming + * connections with the specified handler. Backlog value + * is configured to the value of backlog property. + * + * @throws IOException if failed to bind + */ + public void bind( SocketAddress address, IoHandler handler, + SessionInitializer initializer ) throws IOException + { if( address =3D=3D null ) { throw new NullPointerException( "address" ); @@ -106,7 +116,7 @@ throw new IllegalArgumentException( "Unsupported port number: = 0" ); } =20 - RegistrationRequest request =3D new RegistrationRequest( address, = backlog, handler ); + RegistrationRequest request =3D new RegistrationRequest( address, = backlog, handler, initializer ); =20 synchronized( this ) { @@ -136,7 +146,6 @@ if( request.exception !=3D null ) { request.exception.fillInStackTrace(); - throw request.exception; } } @@ -291,9 +300,31 @@ continue; } =20 - SocketSession session =3D new SocketSession( filters, ch, = ( IoHandler ) key.attachment() ); - =20 - SocketIoProcessor.getInstance().addSession( session ); + boolean success =3D false; + try + { + RegistrationRequest req =3D ( RegistrationRequest ) ke= y=2Eattachment(); + SocketSession session =3D new SocketSession( filters, = ch, req.handler ); + =20 + if( req.initializer !=3D null ) + { + req.initializer.initializeSession( session ); + } + =20 + SocketIoProcessor.getInstance().addSession( session ); + success =3D true; + } + catch( Throwable t ) + { + exceptionMonitor.exceptionCaught( SocketAcceptor.this,= t ); + } + finally + { + if( !success ) + { + ch.close(); + } + } } } } @@ -330,7 +361,7 @@ =20 ssc.socket().bind( req.address, req.backlog ); =20 - ssc.register( selector, SelectionKey.OP_ACCEPT, req.handle= r ); + ssc.register( selector, SelectionKey.OP_ACCEPT, req ); =20 channels.put( req.address, ssc ); } @@ -433,17 +464,19 @@ =20 private final IoHandler handler; =20 + private final SessionInitializer initializer; + =20 private IOException exception;=20 =20 private boolean done; =20 - private RegistrationRequest( SocketAddress address, int backlog, I= oHandler handler ) + private RegistrationRequest( SocketAddress address, int backlog, I= oHandler handler, + SessionInitializer initializer ) { this.address =3D address; - this.backlog =3D backlog; - this.handler =3D handler; + this.initializer =3D initializer; } } =20 @@ -460,22 +493,5 @@ { this.address =3D address; } - } - - =20 - public ExceptionMonitor getExceptionMonitor() - { - return exceptionMonitor; - } - - - public void setExceptionMonitor( ExceptionMonitor monitor ) - { - if( monitor =3D=3D null ) - { - monitor =3D new DefaultExceptionMonitor(); - } - - this.exceptionMonitor =3D monitor; } } Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/Socket= Connector.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/io/socket/SocketConnector.java?rev=3D164015&r1=3D164014&r2=3D16401= 5&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketConnec= tor.java (original) +++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketConnec= tor.java Thu Apr 21 02:19:31 2005 @@ -28,12 +28,12 @@ import java.util.Iterator; import java.util.Set; =20 -import org.apache.mina.io.DefaultExceptionMonitor; -import org.apache.mina.io.ExceptionMonitor; +import org.apache.mina.common.SessionInitializer; import org.apache.mina.io.IoConnector; import org.apache.mina.io.IoHandler; import org.apache.mina.io.IoHandlerFilterChain; import org.apache.mina.io.IoSession; +import org.apache.mina.util.BaseSessionManager; import org.apache.mina.util.Queue; =20 /** @@ -42,7 +42,7 @@ * @author Trustin Lee (trustin@apache.org) * @version $Rev$, $Date$ */ -public class SocketConnector implements IoConnector +public class SocketConnector extends BaseSessionManager implements IoConne= ctor { private static volatile int nextId =3D 0; =20 @@ -52,8 +52,6 @@ =20 private final Selector selector; =20 - private ExceptionMonitor exceptionMonitor =3D new DefaultExceptionMoni= tor(); - private final Queue connectQueue =3D new Queue(); =20 private Worker worker; @@ -68,26 +66,44 @@ selector =3D Selector.open(); } =20 - public IoSession connect( SocketAddress address, IoHandler handler ) - throws IOException + public IoSession connect( SocketAddress address, IoHandler handler ) t= hrows IOException { - return connect( address, null, handler ); + return connect( address, null, Integer.MAX_VALUE, handler, null); } =20 - public IoSession connect( SocketAddress address, SocketAddress localAd= dress, - IoHandler handler ) throws IOException + public IoSession connect( SocketAddress address, SocketAddress localAd= dress, IoHandler handler ) throws IOException + { + return connect( address, localAddress, Integer.MAX_VALUE, handler,= null); + } + + public IoSession connect( SocketAddress address, int timeout, IoHandle= r handler ) throws IOException + { + return connect( address, null, timeout, handler, null); + } + + public IoSession connect( SocketAddress address, SocketAddress localAd= dress, int timeout, IoHandler handler ) throws IOException + { + return connect( address, localAddress, timeout, handler, null); + } + + public IoSession connect( SocketAddress address, IoHandler handler, Se= ssionInitializer initializer ) throws IOException + { + return connect( address, null, Integer.MAX_VALUE, handler, initial= izer ); + } + + public IoSession connect( SocketAddress address, SocketAddress localAd= dress, IoHandler handler, SessionInitializer initializer ) throws IOExcepti= on { - return connect( address, localAddress, Integer.MAX_VALUE, handler = ); + return connect( address, localAddress, Integer.MAX_VALUE, handler,= initializer ); } =20 - public IoSession connect( SocketAddress address, int timeout, - IoHandler handler ) throws IOException + public IoSession connect( SocketAddress address, int timeout, IoHandle= r handler, SessionInitializer initializer ) throws IOException { - return connect( address, null, timeout, handler ); + return connect( address, null, timeout, handler, initializer ); } =20 public IoSession connect( SocketAddress address, SocketAddress localAd= dress, - int timeout, IoHandler handler ) throws IOEx= ception + int timeout, IoHandler handler, + SessionInitializer initializer ) throws IOEx= ception { if( address =3D=3D null ) throw new NullPointerException( "address" ); @@ -106,7 +122,7 @@ + localAddress.getClass() = ); =20 SocketChannel ch =3D SocketChannel.open(); - boolean initialized =3D false; + boolean success =3D false; try { if( localAddress !=3D null ) @@ -115,23 +131,22 @@ } ch.configureBlocking( false ); =20 - boolean connected =3D ch.connect( address ); - initialized =3D true; - - if( connected ) + if( ch.connect( address ) ) { - return newSession( ch, handler ); + return newSession( ch, handler, initializer ); } + =20 + success =3D true; } finally { - if( !initialized ) + if( !success ) { ch.close(); } } =20 - ConnectionRequest request =3D new ConnectionRequest( ch, timeout, = handler ); + ConnectionRequest request =3D new ConnectionRequest( ch, timeout, = handler, initializer ); synchronized( this ) { synchronized( connectQueue ) @@ -224,7 +239,7 @@ try { ch.finishConnect(); - SocketSession session =3D newSession( ch, entry.handler ); + SocketSession session =3D newSession( ch, entry.handler, e= ntry.initializer ); entry.session =3D session; } catch( IOException e ) @@ -275,9 +290,13 @@ } } =20 - private SocketSession newSession( SocketChannel ch, IoHandler handler = ) + private SocketSession newSession( SocketChannel ch, IoHandler handler,= SessionInitializer initializer ) throws IOException { SocketSession session =3D new SocketSession( filters, ch, handler = ); + if( initializer !=3D null ) + { + initializer.initializeSession( session ); + } SocketIoProcessor.getInstance().addSession( session ); return session; } @@ -342,6 +361,8 @@ private final long deadline; =20 private final IoHandler handler; + =20 + private final SessionInitializer initializer; =20 private SocketSession session; =20 @@ -349,31 +370,17 @@ =20 private IOException exception; =20 - private ConnectionRequest( SocketChannel channel, int timeout, IoH= andler handler ) + private ConnectionRequest( SocketChannel channel, int timeout, IoH= andler handler, SessionInitializer initializer ) { this.channel =3D channel; this.deadline =3D System.currentTimeMillis() + timeout * 1000L= ; this.handler =3D handler; + this.initializer =3D initializer; } } =20 public IoHandlerFilterChain getFilterChain() { return filters; - } - - public ExceptionMonitor getExceptionMonitor() - { - return exceptionMonitor; - } - - public void setExceptionMonitor( ExceptionMonitor monitor ) - { - if( monitor =3D=3D null ) - { - monitor =3D new DefaultExceptionMonitor(); - } - - this.exceptionMonitor =3D monitor; } } Modified: directory/network/trunk/src/java/org/apache/mina/protocol/Protoco= lAcceptor.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/protocol/ProtocolAcceptor.java?rev=3D164015&r1=3D164014&r2=3D16401= 5&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolAccep= tor.java (original) +++ directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolAccep= tor.java Thu Apr 21 02:19:31 2005 @@ -21,6 +21,9 @@ import java.io.IOException; import java.net.SocketAddress; =20 +import org.apache.mina.common.SessionInitializer; +import org.apache.mina.common.SessionManager; + /** * Accepts incoming connection, communicates with clients, and fires event= s to * {@link ProtocolHandler}s. @@ -42,8 +45,10 @@ *=20 * @author Trustin Lee (trustin@apache.org) * @version $Rev$, $Date$ + *=20 + * @see SessionInitializer */ -public interface ProtocolAcceptor +public interface ProtocolAcceptor extends SessionManager { /** * Binds to the specified address and handles incoming @@ -52,6 +57,15 @@ * @throws IOException if failed to bind */ void bind( SocketAddress address, ProtocolProvider protocolProvider ) + throws IOException; + + /** + * Binds to the specified address and handles incoming + * connections with the specified protocolProvider. + *=20 + * @throws IOException if failed to bind + */ + void bind( SocketAddress address, ProtocolProvider protocolProvider, S= essionInitializer initializer ) throws IOException; =20 /** Modified: directory/network/trunk/src/java/org/apache/mina/protocol/Protoco= lConnector.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/protocol/ProtocolConnector.java?rev=3D164015&r1=3D164014&r2=3D1640= 15&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolConne= ctor.java (original) +++ directory/network/trunk/src/java/org/apache/mina/protocol/ProtocolConne= ctor.java Thu Apr 21 02:19:31 2005 @@ -21,6 +21,9 @@ import java.io.IOException; import java.net.SocketAddress; =20 +import org.apache.mina.common.SessionInitializer; +import org.apache.mina.common.SessionManager; + /** * Connects to endpoint, communicates with the server, and fires events to * {@link ProtocolProvider}s. @@ -42,8 +45,10 @@ *=20 * @author Trustin Lee (trustin@apache.org) * @version $Rev$, $Date$ + *=20 + * @see SessionInitializer */ -public interface ProtocolConnector +public interface ProtocolConnector extends SessionManager { /** * Connects to the specified address. If communication s= tarts @@ -86,6 +91,52 @@ */ ProtocolSession connect( SocketAddress address, SocketAddress localAdd= ress, int timeout, ProtocolProvider protocolProvide= r ) throws IOException; + + /** + * Connects to the specified address. If communication s= tarts + * successfully, events are fired to the specified + * protocolProvider. This method blocks. + *=20 + * @throws IOException if failed to connect + */ + ProtocolSession connect( SocketAddress address, + ProtocolProvider protocolProvider, + SessionInitializer initializer ) throws IOExc= eption; + + /** + * Connects to the specified address. If communication s= tarts + * successfully, events are fired to the specified + * protocolProvider. This method blocks. + *=20 + * @param localAddress the local address the channel is bound to + * @throws IOException if failed to connect + */ + ProtocolSession connect( SocketAddress address, SocketAddress localAdd= ress, + ProtocolProvider protocolProvider, + SessionInitializer initializer ) throws IOExc= eption; + + /** + * Connects to the specified address with timeout. If + * communication starts successfully, events are fired to the specifie= d + * protocolProvider. This method blocks. + *=20 + * @throws IOException if failed to connect + */ + ProtocolSession connect( SocketAddress address, int timeout, + ProtocolProvider protocolProvider, + SessionInitializer initializer ) throws IOExc= eption; + + /** + * Connects to the specified address with timeout. If + * communication starts successfully, events are fired to the specifie= d + * protocolProvider. This method blocks. + *=20 + * @param localAddress the local address the channel is bound to + * @throws IOException if failed to connect + */ + ProtocolSession connect( SocketAddress address, SocketAddress localAdd= ress, + int timeout, ProtocolProvider protocolProvide= r, + SessionInitializer initializer ) throws IOExc= eption; =20 ProtocolHandlerFilterChain getFilterChain(); } Modified: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoPr= otocolAcceptor.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/protocol/io/IoProtocolAcceptor.java?rev=3D164015&r1=3D164014&r2=3D= 164015&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocol= Acceptor.java (original) +++ directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocol= Acceptor.java Thu Apr 21 02:19:31 2005 @@ -6,6 +6,8 @@ import java.io.IOException; import java.net.SocketAddress; =20 +import org.apache.mina.common.ExceptionMonitor; +import org.apache.mina.common.SessionInitializer; import org.apache.mina.io.IoAcceptor; import org.apache.mina.protocol.ProtocolAcceptor; import org.apache.mina.protocol.ProtocolHandlerFilterChain; @@ -49,6 +51,12 @@ { acceptor.bind( address, adapter.adapt( provider ) ); } + =20 + public void bind( SocketAddress address, ProtocolProvider provider, + SessionInitializer initializer ) throws IOException + { + acceptor.bind( address, adapter.adapt( provider ), initializer ); + } =20 public void unbind( SocketAddress address ) { @@ -58,5 +66,15 @@ public ProtocolHandlerFilterChain getFilterChain() { return adapter.getFilterChain(); + } + + public ExceptionMonitor getExceptionMonitor() + { + return acceptor.getExceptionMonitor(); + } + + public void setExceptionMonitor( ExceptionMonitor monitor ) + { + acceptor.setExceptionMonitor( monitor ); } } Modified: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoPr= otocolConnector.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/protocol/io/IoProtocolConnector.java?rev=3D164015&r1=3D164014&r2= =3D164015&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocol= Connector.java (original) +++ directory/network/trunk/src/java/org/apache/mina/protocol/io/IoProtocol= Connector.java Thu Apr 21 02:19:31 2005 @@ -6,6 +6,8 @@ import java.io.IOException; import java.net.SocketAddress; =20 +import org.apache.mina.common.ExceptionMonitor; +import org.apache.mina.common.SessionInitializer; import org.apache.mina.io.IoConnector; import org.apache.mina.io.IoSession; import org.apache.mina.protocol.ProtocolConnector; @@ -77,8 +79,51 @@ return adapter.toProtocolSession( session ); } =20 + public ProtocolSession connect( SocketAddress address, + ProtocolProvider provider, + SessionInitializer initializer ) throw= s IOException + { + IoSession session =3D connector.connect( + address, adapter.adapt( provider ), initializer ); + return adapter.toProtocolSession( session ); + } + + public ProtocolSession connect( SocketAddress address, SocketAddress l= ocalAddress, + ProtocolProvider provider, SessionInit= ializer initializer ) throws IOException + { + IoSession session =3D connector.connect( + address, localAddress, adapter.adapt( provider ), initiali= zer ); + return adapter.toProtocolSession( session ); + } + + public ProtocolSession connect( SocketAddress address, int timeout, + ProtocolProvider provider, SessionInit= ializer initializer ) throws IOException + { + IoSession session =3D connector.connect( + address, timeout, adapter.adapt( provider ), initializer )= ; + return adapter.toProtocolSession( session ); + } + + public ProtocolSession connect( SocketAddress address, SocketAddress l= ocalAddress, + int timeout, ProtocolProvider provider= , SessionInitializer initializer ) throws IOException + { + IoSession session =3D connector.connect( + address, localAddress, timeout, adapter.adapt( provider ),= initializer ); + return adapter.toProtocolSession( session ); + } + public ProtocolHandlerFilterChain getFilterChain() { return adapter.getFilterChain(); + } + + public ExceptionMonitor getExceptionMonitor() + { + return connector.getExceptionMonitor(); + } + + public void setExceptionMonitor( ExceptionMonitor monitor ) + { + connector.setExceptionMonitor( monitor ); } } Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/= VmPipeAcceptor.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/protocol/vmpipe/VmPipeAcceptor.java?rev=3D164015&r1=3D164014&r2=3D= 164015&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipe= Acceptor.java (original) +++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipe= Acceptor.java Thu Apr 21 02:19:31 2005 @@ -8,10 +8,12 @@ import java.util.HashMap; import java.util.Map; =20 +import org.apache.mina.common.SessionInitializer; import org.apache.mina.protocol.ProtocolAcceptor; import org.apache.mina.protocol.ProtocolHandler; import org.apache.mina.protocol.ProtocolHandlerFilterChain; import org.apache.mina.protocol.ProtocolProvider; +import org.apache.mina.util.BaseSessionManager; =20 /** * Binds the specified {@link ProtocolProvider} to the specified @@ -20,7 +22,7 @@ * @author Trustin Lee (trustin@apache.org) * @version $Rev$, $Date$ */ -public class VmPipeAcceptor implements ProtocolAcceptor +public class VmPipeAcceptor extends BaseSessionManager implements Protocol= Acceptor { static final Map boundHandlers =3D new HashMap(); =20 @@ -33,9 +35,14 @@ { filters.addLast( "VMPipe", new VmPipeFilter() ); } + =20 + public void bind( SocketAddress address, ProtocolProvider protocolProv= ider ) throws IOException + { + bind( address, protocolProvider, null ); + } =20 - public void bind( SocketAddress address, ProtocolProvider protocolProv= ider ) - throws IOException + public void bind( SocketAddress address, ProtocolProvider protocolProv= ider, + SessionInitializer initializer ) throws IOException { if( address =3D=3D null ) throw new NullPointerException( "address" ); @@ -52,8 +59,12 @@ throw new IOException( "Address already bound: " + address= ); } =20 - boundHandlers.put( address, new Entry( ( VmPipeAddress ) addre= ss, - filters, protocolProvider.getHandler() ) ); + boundHandlers.put( address,=20 + new Entry( this, + ( VmPipeAddress ) address, + filters, + protocolProvider.getHandler(), + initializer ) ); } } =20 @@ -75,19 +86,27 @@ =20 static class Entry { + final VmPipeAcceptor acceptor; + =20 final VmPipeAddress address; =20 final VmPipeFilterChain filters; =20 final ProtocolHandler handler; + =20 + final SessionInitializer initializer; =20 - private Entry( VmPipeAddress address, + private Entry( VmPipeAcceptor acceptor, + VmPipeAddress address, VmPipeFilterChain filters, - ProtocolHandler handler ) + ProtocolHandler handler, + SessionInitializer initializer ) { + this.acceptor =3D acceptor; this.address =3D address; this.filters =3D filters; this.handler =3D handler; + this.initializer =3D initializer; } } } Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/= VmPipeConnector.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/protocol/vmpipe/VmPipeConnector.java?rev=3D164015&r1=3D164014&r2= =3D164015&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipe= Connector.java (original) +++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipe= Connector.java Thu Apr 21 02:19:31 2005 @@ -6,11 +6,13 @@ import java.io.IOException; import java.net.SocketAddress; =20 +import org.apache.mina.common.SessionInitializer; import org.apache.mina.protocol.ProtocolConnector; import org.apache.mina.protocol.ProtocolHandlerFilterChain; import org.apache.mina.protocol.ProtocolProvider; import org.apache.mina.protocol.ProtocolSession; import org.apache.mina.protocol.vmpipe.VmPipeAcceptor.Entry; +import org.apache.mina.util.BaseSessionManager; =20 /** * Connects to {@link ProtocolProvider}s which is bound on the specified @@ -19,7 +21,7 @@ * @author Trustin Lee (trustin@apache.org) * @version $Rev$, $Date$ */ -public class VmPipeConnector implements ProtocolConnector +public class VmPipeConnector extends BaseSessionManager implements Protoco= lConnector { private final VmPipeFilterChain filters =3D new VmPipeFilterChain(); =20 @@ -36,14 +38,44 @@ return filters; } =20 - public ProtocolSession connect( SocketAddress address, SocketAddress l= ocalAddress, - ProtocolProvider protocolProvider ) th= rows IOException + public ProtocolSession connect( SocketAddress address, ProtocolProvide= r protocolProvider ) throws IOException=20 { - return connect( address, protocolProvider ); + return connect( address, null, Integer.MAX_VALUE, protocolProvider= , null ); + } + + public ProtocolSession connect( SocketAddress address, SocketAddress l= ocalAddress, ProtocolProvider protocolProvider ) throws IOException + { + return connect( address, localAddress, Integer.MAX_VALUE, protocol= Provider, null ); + } + + public ProtocolSession connect( SocketAddress address, int timeout, Pr= otocolProvider protocolProvider ) throws IOException + { + return connect( address, null, timeout, protocolProvider, null ); + } + + public ProtocolSession connect( SocketAddress address, SocketAddress l= ocalAddress, int timeout, ProtocolProvider protocolProvider ) throws IOExce= ption + { + return connect( address, localAddress, timeout, protocolProvider, = null ); + } + + public ProtocolSession connect( SocketAddress address, SocketAddress l= ocalAddress, ProtocolProvider protocolProvider, SessionInitializer initiali= zer ) throws IOException + { + return connect( address, localAddress, Integer.MAX_VALUE, protocol= Provider, initializer ); + } + + public ProtocolSession connect( SocketAddress address, int timeout, Pr= otocolProvider protocolProvider, SessionInitializer initializer ) throws IO= Exception + { + return connect( address, null, timeout, protocolProvider, initiali= zer ); + } + + public ProtocolSession connect( SocketAddress address, SocketAddress l= ocalAddress, int timeout, ProtocolProvider protocolProvider, SessionInitial= izer initializer ) throws IOException + { + return connect( address, localAddress, timeout, protocolProvider, = initializer ); } =20 public ProtocolSession connect( SocketAddress address, - ProtocolProvider protocolProvider ) th= rows IOException + ProtocolProvider protocolProvider, + SessionInitializer initializer ) throw= s IOException { if( address =3D=3D null ) throw new NullPointerException( "address" ); @@ -57,28 +89,14 @@ if( entry =3D=3D null ) throw new IOException( "Endpoint unavailable: " + address ); =20 - VmPipeSession session =3D new VmPipeSession( - new Object(), // lock + VmPipeSession session =3D new VmPipeSession( new Object(), // lock AnonymousVmPipeAddress.= INSTANCE, - entry.address, filters, - protocolProvider - .getHandler(), - entry.filters, - entry.handler ); + protocolProvider.getHan= dler(), + initializer, + entry ); + VmPipeIdleStatusChecker.INSTANCE.addSession( session ); return session; - } - - public ProtocolSession connect( SocketAddress address, int timeout, - ProtocolProvider protocolProvider ) th= rows IOException - { - return connect( address, protocolProvider ); - } - - public ProtocolSession connect( SocketAddress address, SocketAddress l= ocalAddress, - int timeout, ProtocolProvider protocol= Provider ) throws IOException - { - return connect( address, protocolProvider ); } } Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/= VmPipeSession.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/protocol/vmpipe/VmPipeSession.java?rev=3D164015&r1=3D164014&r2=3D1= 64015&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipe= Session.java (original) +++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipe= Session.java Thu Apr 21 02:19:31 2005 @@ -3,14 +3,17 @@ */ package org.apache.mina.protocol.vmpipe; =20 +import java.io.IOException; import java.net.SocketAddress; =20 import org.apache.mina.common.SessionConfig; +import org.apache.mina.common.SessionInitializer; import org.apache.mina.common.TransportType; import org.apache.mina.protocol.ProtocolDecoder; import org.apache.mina.protocol.ProtocolEncoder; import org.apache.mina.protocol.ProtocolHandler; import org.apache.mina.protocol.ProtocolSession; +import org.apache.mina.protocol.vmpipe.VmPipeAcceptor.Entry; import org.apache.mina.util.BaseSession; =20 /** @@ -26,7 +29,7 @@ private final SocketAddress remoteAddress; =20 private final ProtocolHandler localHandler; - + =20 private final VmPipeSessionConfig config =3D new VmPipeSessionConfig()= ; =20 final VmPipeFilterChain localFilters; @@ -43,22 +46,37 @@ * Constructor for client-side session. */ VmPipeSession( Object lock, SocketAddress localAddress, - SocketAddress remoteAddress, - VmPipeFilterChain localFilters, - ProtocolHandler localHandler, - VmPipeFilterChain removeFilters, - ProtocolHandler remoteHandler ) + VmPipeFilterChain localFilters, + ProtocolHandler localHandler, + SessionInitializer initializer, + Entry remoteEntry ) throws IOException { this.lock =3D lock; this.localAddress =3D localAddress; this.localHandler =3D localHandler; this.localFilters =3D localFilters; - this.remoteAddress =3D remoteAddress; - this.remoteFilters =3D removeFilters; + this.remoteAddress =3D remoteEntry.address; + this.remoteFilters =3D remoteEntry.filters; =20 - remoteSession =3D new VmPipeSession( this, remoteHandler ); + remoteSession =3D new VmPipeSession( this, remoteEntry.handler ); + if( remoteEntry.initializer !=3D null ) + { + boolean success =3D false; + try + { + remoteEntry.initializer.initializeSession( remoteSession )= ; + success =3D true; + } + catch( Throwable t ) + { + remoteEntry.acceptor.getExceptionMonitor().exceptionCaught= ( remoteEntry.acceptor, t ); + IOException e =3D new IOException( "Failed to initialize r= emote session." ); + e.initCause( t ); + throw e; + } + } =20 - removeFilters.sessionOpened( remoteSession ); + remoteEntry.filters.sessionOpened( remoteSession ); localFilters.sessionOpened( this ); } =20 Added: directory/network/trunk/src/java/org/apache/mina/util/BaseSessionMan= ager.java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/util/BaseSessionManager.java?rev=3D164015&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/util/BaseSessionManage= r=2Ejava (added) +++ directory/network/trunk/src/java/org/apache/mina/util/BaseSessionManage= r=2Ejava Thu Apr 21 02:19:31 2005 @@ -0,0 +1,56 @@ +/* + * @(#) $Id$ + * + * 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 impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.mina.util; + +import org.apache.mina.common.DefaultExceptionMonitor; +import org.apache.mina.common.ExceptionMonitor; +import org.apache.mina.common.SessionManager; + +/** + * Base implementation of {@link SessionManager}s. + *=20 + * @author Trustin Lee (trustin@apache.org) + * @version $Rev$, $Date$ + */ +public class BaseSessionManager implements SessionManager { + + /** + * Current exception monitor. + */ + protected ExceptionMonitor exceptionMonitor =3D new DefaultExceptionMo= nitor(); + + protected BaseSessionManager() + { + } + + public ExceptionMonitor getExceptionMonitor() + { + return exceptionMonitor; + } + + public void setExceptionMonitor( ExceptionMonitor monitor ) + { + if( monitor =3D=3D null ) + { + monitor =3D new DefaultExceptionMonitor(); + } + + this.exceptionMonitor =3D monitor; + } +} Propchange: directory/network/trunk/src/java/org/apache/mina/util/BaseSessi= onManager.java ---------------------------------------------------------------------------= --- svn:keywords =3D HeadURL Id LastChangedBy LastChangedDate LastChangedRe= vision Added: directory/network/trunk/src/java/org/apache/mina/util/ExceptionUtil.= java URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apa= che/mina/util/ExceptionUtil.java?rev=3D164015&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- directory/network/trunk/src/java/org/apache/mina/util/ExceptionUtil.jav= a (added) +++ directory/network/trunk/src/java/org/apache/mina/util/ExceptionUtil.jav= a Thu Apr 21 02:19:31 2005 @@ -0,0 +1,54 @@ +/* + * @(#) $Id$ + * + * 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 impli= ed. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.mina.util; + +import java.io.IOException; + +/** + * Exception utility. + *=20 + * @author Trustin Lee (trustin@apache.org) + * @version $Rev$, $Date$ + */ +public class ExceptionUtil { + + public static void throwException( Throwable t ) throws IOException + { + if( t instanceof IOException ) + { + throw ( IOException ) t; + } + else if( t instanceof RuntimeException ) + { + throw ( RuntimeException ) t; + } + else if( t instanceof Error ) + { + throw ( Error ) t; + } + else + { + throw new RuntimeException( t ); + } + } + =20 + private ExceptionUtil() + { + } +} Propchange: directory/network/trunk/src/java/org/apache/mina/util/Exception= Util.java ---------------------------------------------------------------------------= --- svn:keywords =3D HeadURL Id LastChangedBy LastChangedDate LastChangedRe= vision