directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r406554 - in /directory/trunks/mina/core/src/main/java/org/apache/mina: common/ common/support/ transport/socket/nio/support/
Date Mon, 15 May 2006 06:46:04 GMT
Author: trustin
Date: Sun May 14 23:46:02 2006
New Revision: 406554

URL: http://svn.apache.org/viewcvs?rev=406554&view=rev
Log:
Fixed: DIRMINA-208 (Allow datagrams to be directed to a specific destination on a per-datagram
instead of a per-session basis.)
* Added an optional destination property to IoFilter.WriteRequest
* Added BroadcastIoSession
* DatagramSessionImpl implements BroadcastIoSession
* DatagramAcceptorDelegate gets the destination from WriteRequest.destination

Added:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/BroadcastIoSession.java
  (with props)
Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoSession.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoSession.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java

Added: directory/trunks/mina/core/src/main/java/org/apache/mina/common/BroadcastIoSession.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/BroadcastIoSession.java?rev=406554&view=auto
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/BroadcastIoSession.java
(added)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/BroadcastIoSession.java
Sun May 14 23:46:02 2006
@@ -0,0 +1,53 @@
+/*
+ *   @(#) $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 implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.common;
+
+import java.net.SocketAddress;
+
+/**
+ * An {@link IoSession} for broadcast transports. (e.g. UDP broadcast or multicast)
+ * 
+ * <h2>Writing Back to the Broadcasting Server</h2>
+ * <p>
+ * When you implement a client that receives a broadcast message from a server
+ * such as DHCP server, the client might need to send a response message for the
+ * broadcast message the server sent.  Because the remote address of the session
+ * is not the address of the server in case of broadcasting, there should be a
+ * way to specify the destination when you write the response message.
+ * This interface provides {@link #write(Object, SocketAddress)} method so you
+ * can specify the destination.
+ * </p>
+ * 
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface BroadcastIoSession extends IoSession
+{
+    /**
+     * Writes the specified <tt>message</tt> to the specified <tt>destination</tt>.
+     * This operation is asynchronous; {@link IoHandler#messageSent(IoSession, Object)}
+     * will be invoked when the message is actually sent to remote peer. You can
+     * also wait for the returned {@link WriteFuture} if you want to wait for
+     * the message actually written.
+     * 
+     * @param destination <tt>null</tt> if you want the message sent to the
+     *                    default remote address
+     */
+    WriteFuture write(Object message, SocketAddress destination);
+}

Propchange: directory/trunks/mina/core/src/main/java/org/apache/mina/common/BroadcastIoSession.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java?rev=406554&r1=406553&r2=406554&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoFilter.java Sun May
14 23:46:02 2006
@@ -18,6 +18,8 @@
  */
 package org.apache.mina.common;
 
+import java.net.SocketAddress;
+
 /**
  * A filter which intercepts {@link IoHandler} events like Servlet
  * filters.  Filters can be used for these purposes:
@@ -247,6 +249,7 @@
         
         private final Object message;
         private final WriteFuture future;
+        private final SocketAddress destination;
         
         /**
          * Creates a new instance without {@link WriteFuture}.  You'll get
@@ -255,7 +258,7 @@
          */
         public WriteRequest( Object message )
         {
-            this( message, null );
+            this( message, null, null );
         }
 
         /**
@@ -263,6 +266,19 @@
          */
         public WriteRequest( Object message, WriteFuture future )
         {
+            this( message, future, null );
+        }
+        
+        /**
+         * Creates a new instance.
+         * 
+         * @param message a message to write
+         * @param future a future that needs to be notified when an operation is finished
+         * @param destination the destination of the message.  This property will be
+         *                    ignored unless the transport supports it.
+         */
+        public WriteRequest( Object message, WriteFuture future, SocketAddress destination
)
+        {
             if( message == null )
             {
                 throw new NullPointerException( "message" );
@@ -275,6 +291,7 @@
             
             this.message = message;
             this.future = future;
+            this.destination = destination;
         }
 
         /**
@@ -291,6 +308,16 @@
         public Object getMessage()
         {
             return message;
+        }
+        
+        /**
+         * Returne the destination of this write request.
+         * 
+         * @return <tt>null</tt> for the default destination
+         */
+        public SocketAddress getDestination() 
+        {
+            return destination;
         }
         
         public String toString()

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoSession.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoSession.java?rev=406554&r1=406553&r2=406554&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoSession.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/IoSession.java Sun May
14 23:46:02 2006
@@ -73,8 +73,8 @@
      * Writes the specified <code>message</code> to remote peer.  This
      * operation is asynchronous; {@link IoHandler#messageSent(IoSession, Object)}
      * will be invoked when the message is actually sent to remote peer.
-     * You can also ait for the returned {@link WriteFuture} if you want
-     * to wait for the session actually closed.
+     * You can also wait for the returned {@link WriteFuture} if you want
+     * to wait for the message actually written.
      */
     WriteFuture write( Object message );
 

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoSession.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoSession.java?rev=406554&r1=406553&r2=406554&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoSession.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoSession.java
Sun May 14 23:46:02 2006
@@ -18,6 +18,7 @@
  */
 package org.apache.mina.common.support;
 
+import java.net.SocketAddress;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -25,8 +26,8 @@
 
 import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.IoSession;
 import org.apache.mina.common.IoService;
+import org.apache.mina.common.IoSession;
 import org.apache.mina.common.TrafficMask;
 import org.apache.mina.common.WriteFuture;
 import org.apache.mina.common.IoFilter.WriteRequest;
@@ -124,6 +125,11 @@
     
     public WriteFuture write( Object message )
     {
+        return write( message, null );
+    }
+    
+    public WriteFuture write( Object message, SocketAddress remoteAddress )
+    {
         synchronized( this )
         {
             if( isClosing() || !isConnected() )
@@ -133,7 +139,7 @@
         }
 
         WriteFuture future = new WriteFuture();
-        write0( new WriteRequest( message, future ) );
+        write0( new WriteRequest( message, future, remoteAddress ) );
         
         return future;
     }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java?rev=406554&r1=406553&r2=406554&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
Sun May 14 23:46:02 2006
@@ -483,8 +483,13 @@
                 continue;
             }
 
-            int writtenBytes = ch
-                    .send( buf.buf(), session.getRemoteAddress() );
+            SocketAddress destination = req.getDestination();
+            if( destination == null )
+            {
+                destination = session.getRemoteAddress();
+            }
+            
+            int writtenBytes = ch.send( buf.buf(), destination );
 
             if( writtenBytes == 0 )
             {

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java?rev=406554&r1=406553&r2=406554&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java
Sun May 14 23:46:02 2006
@@ -23,6 +23,7 @@
 import java.nio.channels.DatagramChannel;
 import java.nio.channels.SelectionKey;
 
+import org.apache.mina.common.BroadcastIoSession;
 import org.apache.mina.common.IoFilterChain;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoService;
@@ -30,6 +31,7 @@
 import org.apache.mina.common.IoSessionConfig;
 import org.apache.mina.common.RuntimeIOException;
 import org.apache.mina.common.TransportType;
+import org.apache.mina.common.WriteFuture;
 import org.apache.mina.common.IoFilter.WriteRequest;
 import org.apache.mina.common.support.BaseIoSession;
 import org.apache.mina.common.support.BaseIoSessionConfig;
@@ -42,7 +44,7 @@
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-class DatagramSessionImpl extends BaseIoSession
+class DatagramSessionImpl extends BaseIoSession implements BroadcastIoSession
 {
     private final IoService wrapperManager;
     private final DatagramSessionConfig config = new SessionConfigImpl();
@@ -141,6 +143,16 @@
     Queue getWriteRequestQueue()
     {
         return writeRequestQueue;
+    }
+    
+    public WriteFuture write( Object message, SocketAddress destination )
+    {
+        if( !this.config.isBroadcast() )
+        {
+            throw new IllegalStateException( "Non-broadcast session" );
+        }
+        
+        return super.write( message, destination );
     }
 
     protected void write0( WriteRequest writeRequest )



Mime
View raw message