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/11/03 09:18:32 UTC

svn commit: r832338 - in /mina/branches/3.0/core/src/main/java/org/apache/mina: ./ service/ session/ transport/ transport/socket/ transport/socket/nio/

Author: jvermillard
Date: Tue Nov  3 08:18:32 2009
New Revision: 832338

URL: http://svn.apache.org/viewvc?rev=832338&view=rev
Log:
bind/unbind for a basic socket acceptor

Added:
    mina/branches/3.0/core/src/main/java/org/apache/mina/service/
    mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoAcceptor.java   (with props)
    mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoService.java   (with props)
    mina/branches/3.0/core/src/main/java/org/apache/mina/transport/
    mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/
    mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/
    mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java   (with props)
    mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/SelectorProcessor.java   (with props)
Modified:
    mina/branches/3.0/core/src/main/java/org/apache/mina/IoAcceptor.java
    mina/branches/3.0/core/src/main/java/org/apache/mina/session/AbstractIoSession.java

Modified: mina/branches/3.0/core/src/main/java/org/apache/mina/IoAcceptor.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/IoAcceptor.java?rev=832338&r1=832337&r2=832338&view=diff
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/IoAcceptor.java (original)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/IoAcceptor.java Tue Nov  3 08:18:32 2009
@@ -48,13 +48,17 @@
      * Unbinds from all local addresses that this service is bound to and stops
      * to accept incoming connections. This method returns silently if no local
      * address is bound yet.
+     * @throws IOException
+     *             if failed to unbind
      */
-    void unbindAll();
+    void unbindAll() throws IOException;
 
     /**
      * Unbinds from the specified local addresses and stop to accept incoming
      * connections. This method returns silently if the default local addresses
      * are not bound yet.
+     * @throws IOException
+     *             if failed to unbind
      */
-    void unbind(SocketAddress firstLocalAddress, SocketAddress... otherLocalAddresses);
+    void unbind(SocketAddress... localAddresses) throws IOException;
 }

Added: mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoAcceptor.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoAcceptor.java?rev=832338&view=auto
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoAcceptor.java (added)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoAcceptor.java Tue Nov  3 08:18:32 2009
@@ -0,0 +1,31 @@
+/*
+ *  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 org.apache.mina.IoAcceptor;
+
+/**
+ * Base implementation for {@link IoAcceptor}s.
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public abstract class AbstractIoAcceptor extends AbstractIoService implements IoAcceptor {
+
+}

Propchange: mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoAcceptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoService.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoService.java?rev=832338&view=auto
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoService.java (added)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoService.java Tue Nov  3 08:18:32 2009
@@ -0,0 +1,41 @@
+/*
+ *  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.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.mina.IoService;
+import org.apache.mina.IoSession;
+
+/**
+ * Base implementation for {@link IoService}s.
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public abstract class AbstractIoService implements IoService {
+    
+   private final Map<Long, IoSession> managedSessions = new ConcurrentHashMap<Long, IoSession>();
+
+    @Override
+    public Map<Long, IoSession> getManagedSessions() {
+        return managedSessions;
+    }
+}

Propchange: mina/branches/3.0/core/src/main/java/org/apache/mina/service/AbstractIoService.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: mina/branches/3.0/core/src/main/java/org/apache/mina/session/AbstractIoSession.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/session/AbstractIoSession.java?rev=832338&r1=832337&r2=832338&view=diff
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/session/AbstractIoSession.java (original)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/session/AbstractIoSession.java Tue Nov  3 08:18:32 2009
@@ -19,8 +19,6 @@
  */
 package org.apache.mina.session;
 
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;

Added: mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java?rev=832338&view=auto
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java (added)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java Tue Nov  3 08:18:32 2009
@@ -0,0 +1,79 @@
+/*
+ *  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.transport.socket.nio;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+import java.nio.channels.ServerSocketChannel;
+import java.security.InvalidParameterException;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.mina.service.AbstractIoAcceptor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * TODO 
+ * 
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class NioSocketAcceptor extends AbstractIoAcceptor {
+    
+    static final Logger LOG = LoggerFactory.getLogger(NioSocketAcceptor.class);
+
+    private Map<SocketAddress,ServerSocketChannel> serverSocketChannels = new ConcurrentHashMap<SocketAddress, ServerSocketChannel>();
+    
+    @Override
+    public void bind(SocketAddress... localAddress) throws IOException {
+   
+        for(SocketAddress address : localAddress) {
+            ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
+            LOG.debug("binding address {}",address);
+            serverSocketChannel.socket().bind(address);
+            serverSocketChannels.put(address,serverSocketChannel);
+        }
+    }
+
+    @Override
+    public Set<SocketAddress> getLocalAddresses() {
+        return serverSocketChannels.keySet();
+    }
+
+    @Override
+    public void unbind(SocketAddress... localAddresses) throws IOException {
+        for (SocketAddress socketAddress : localAddresses) {
+            LOG.debug("unbinding {}",socketAddress);
+            ServerSocketChannel channel = serverSocketChannels.get(socketAddress);
+            if (channel == null) {
+                throw new InvalidParameterException("localAddresses");
+            }
+            channel.socket().close();
+        }
+    }
+
+    @Override
+    public void unbindAll() throws IOException {
+        for (SocketAddress socketAddress:serverSocketChannels.keySet()) {
+            unbind(socketAddress);
+        }
+    }
+}

Propchange: mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/NioSocketAcceptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/SelectorProcessor.java
URL: http://svn.apache.org/viewvc/mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/SelectorProcessor.java?rev=832338&view=auto
==============================================================================
--- mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/SelectorProcessor.java (added)
+++ mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/SelectorProcessor.java Tue Nov  3 08:18:32 2009
@@ -0,0 +1,30 @@
+/*
+ *  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.transport.socket.nio;
+
+/**
+ * 
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ *
+ */
+public class SelectorProcessor {
+
+}

Propchange: mina/branches/3.0/core/src/main/java/org/apache/mina/transport/socket/nio/SelectorProcessor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain