You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by jv...@apache.org on 2009/12/18 19:20:45 UTC

svn commit: r892336 - in /mina/branches/3.0/core/src: main/java/org/apache/mina/service/ test/java/org/apache/mina/transport/socket/nio/ test/resources/

Author: jvermillard
Date: Fri Dec 18 18:20:44 2009
New Revision: 892336

URL: http://svn.apache.org/viewvc?rev=892336&view=rev
Log:
added some javadoc and fixed compilation errors

Added:
    mina/branches/3.0/core/src/test/resources/
    mina/branches/3.0/core/src/test/resources/log4j.properties   (with props)
Modified:
    mina/branches/3.0/core/src/main/java/org/apache/mina/service/OneThreadSelectorStrategy.java
    mina/branches/3.0/core/src/main/java/org/apache/mina/service/SelectorFactory.java
    mina/branches/3.0/core/src/test/java/org/apache/mina/transport/socket/nio/NioAcceptorTest.java

Modified: mina/branches/3.0/core/src/main/java/org/apache/mina/service/OneThreadSelectorStrategy.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/service/OneThreadSelectorStrategy.java?rev=892336&r1=892335&r2=892336&view=diff
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/service/OneThreadSelectorStrategy.java (original)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/service/OneThreadSelectorStrategy.java Fri Dec 18 18:20:44 2009
@@ -1,3 +1,22 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.mina.service;
 
 import java.io.IOException;
@@ -5,6 +24,13 @@
 
 import org.apache.mina.transport.socket.nio.SelectorStrategy;
 
+/**
+ * A strategy for using only one thread, for accepting and processing all
+ * the acceptor events.
+ * 
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ *
+ */
 public class OneThreadSelectorStrategy implements SelectorStrategy {
 
     private SelectorProcessor processor;

Modified: mina/branches/3.0/core/src/main/java/org/apache/mina/service/SelectorFactory.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/service/SelectorFactory.java?rev=892336&r1=892335&r2=892336&view=diff
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/service/SelectorFactory.java (original)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/service/SelectorFactory.java Fri Dec 18 18:20:44 2009
@@ -36,13 +36,13 @@
     
     private static final Logger LOG = Logger.getLogger(SelectorFactory.class);
         
-    private Constructor<?> constructor;
+    private Constructor<? extends SelectorProcessor> constructor;
     
     /**
      * create a factory for the given {@link SelectorProcessor} type.
      * @param selectorClass
      */
-    public SelectorFactory(Class<SelectorProcessor> selectorClass) {
+    public SelectorFactory(Class<? extends SelectorProcessor> selectorClass) {
         try {
             constructor = selectorClass.getDeclaredConstructor(new Class<?>[]{String.class,SelectorStrategy.class});
         } catch (NoSuchMethodException e) {

Modified: mina/branches/3.0/core/src/test/java/org/apache/mina/transport/socket/nio/NioAcceptorTest.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/test/java/org/apache/mina/transport/socket/nio/NioAcceptorTest.java?rev=892336&r1=892335&r2=892336&view=diff
==============================================================================
--- mina/branches/3.0/core/src/test/java/org/apache/mina/transport/socket/nio/NioAcceptorTest.java (original)
+++ mina/branches/3.0/core/src/test/java/org/apache/mina/transport/socket/nio/NioAcceptorTest.java Fri Dec 18 18:20:44 2009
@@ -25,7 +25,11 @@
 
 import junit.framework.Assert;
 
+import org.apache.mina.service.OneThreadSelectorStrategy;
+import org.apache.mina.service.SelectorFactory;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -34,29 +38,45 @@
  *
  */
 public class NioAcceptorTest {
-
+    
+    static final private Logger LOG = LoggerFactory.getLogger(NioAcceptorTest.class);
+    
     @Test
     public void acceptorTest() {
-        NioSocketAcceptor acceptor = new NioSocketAcceptor();
+        LOG.info("starting NioAcceptorTest");
+        
+        OneThreadSelectorStrategy strategy = new OneThreadSelectorStrategy(new SelectorFactory(NioSelectorProcessor.class));
+        NioSocketAcceptor acceptor = new NioSocketAcceptor(strategy);
         try {
             acceptor.bind(new InetSocketAddress(9999));
+            LOG.debug("Waiting 25 sec");
+            Thread.sleep(25000);
+            LOG.debug("Unbinding");
+            
             acceptor.unbind(new InetSocketAddress(9999));
+            LOG.debug("Trying to rebind the freed port");            
             acceptor.bind(new InetSocketAddress(9999));
+            LOG.debug("Bound");
         } catch (IOException e) {
             e.printStackTrace();
             Assert.fail();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+            Assert.fail();
         }
         Exception ex = null;
         try {
+            LOG.info("Trying to bind an already bound port");
             // try to bind an already bound port
             acceptor.bind(new InetSocketAddress(9999));
             
             Assert.fail();
             
         } catch (IOException e) {
+            LOG.info("catching the exception",e);
             ex = e;
         }
         Assert.assertNotNull(ex);
         
     }
-}
+}
\ No newline at end of file

Added: mina/branches/3.0/core/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/test/resources/log4j.properties?rev=892336&view=auto
==============================================================================
--- mina/branches/3.0/core/src/test/resources/log4j.properties (added)
+++ mina/branches/3.0/core/src/test/resources/log4j.properties Fri Dec 18 18:20:44 2009
@@ -0,0 +1,26 @@
+#############################################################################
+#    Licensed to the Apache Software Foundation (ASF) under one or more
+#    contributor license agreements.  See the NOTICE file distributed with
+#    this work for additional information regarding copyright ownership.
+#    The ASF licenses this file to You 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.
+#############################################################################
+# Please don't modify the log level until we reach to acceptable test coverage.
+# It's very useful when I test examples manually.
+log4j.rootCategory=DEBUG, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
+
+# you could use this pattern to test the MDC with the Chat server
+#log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %t %p %X{name} [%X{user}] [%X{remoteIp}:%X{remotePort}] [%c] - %m%n

Propchange: mina/branches/3.0/core/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain