Save This Page
Home » openjdk-7 » java » net » [javadoc | source]
    1   /*  ZNet - Java Compression Layer for a new Socket Factory
    2       Copyright (C) 1999, Free Software Rulez
    3   
    4       This program is free software; you can redistribute it and/or modify
    5       it under the terms of the GNU General Public License as published by
    6       the Free Software Foundation; either version 2 of the License, or
    7       (at your option) any later version.
    8   
    9       This program is distributed in the hope that it will be useful,
   10       but WITHOUT ANY WARRANTY; without even the implied warranty of
   11       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12       GNU General Public License for more details.
   13   
   14       You should have received a copy of the GNU General Public License
   15       along with this program; if not, write to the Free Software
   16       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17   
   18           The author of this program may be contacted at morgiaclaudio@yahoo.it. */
   19   
   20   package java.net;
   21   
   22   import java.io;
   23   import java.lang;
   24   
   25   /**
   26    * This class is the new datagram socket implementation used by the datagram socket factory in place
   27    * of the plain-old one.
   28    * It provides a replacement for the creation method and the send/receive pair.
   29    * @see java.net.PlainDatagramSocketImpl the <i>real</i> datagram socket implementation
   30    * @see java.net.DConnector the datagram connector responsible for packet handling
   31    * @author <a href="mailto:morgiaclaudio@yahoo.it">Claudio Morgia</a>
   32    * @version 1.0
   33    */
   34   public class ZDatagramSocketImpl extends PlainDatagramSocketImpl {
   35       /**
   36        * The connector responsible for real packet compression/decompression/handling.
   37        * @see java.net.DConnector
   38        */
   39       protected DConnector conn;
   40   
   41       /**
   42        * This method is responsible for socket creation. It calls directly the create method of the
   43        * PlainDatagramSocketImpl class but starts up a new {@link java.net.DConnector DConnector}
   44        * thread to let him handle packets.
   45        */
   46       public void create() throws SocketException {
   47   	super.create();
   48   	try {
   49   	    conn=new DConnector(this);
   50   	} catch(Exception e) {
   51   	    throw new SocketException(e.getMessage());
   52   	}
   53       }
   54   
   55       /**
   56        * This is a wrapper to the real receiving method. It is needed because we overloaded the <i>receive</i>
   57        * method with our own.
   58        * @param p the datagram to receive
   59        */
   60       public synchronized void _receive(DatagramPacket p) throws IOException {
   61   	super.receive(p);
   62       }
   63   
   64       /**
   65        * This is an overloaded method used to receive packets.
   66        * It asks the connector (viewed as a queue) if there's a queued packet (eventually waiting)
   67        * and the asks the connector to handle it (decompress, ack,etc).
   68        * @param p the datagram to receive
   69        * @see #_receive
   70        * @see java.net.DConnector#hasPacket
   71        * @see java.net.DConnector#getPacket
   72        */
   73       public void receive(DatagramPacket p) throws IOException {
   74   	while (!conn.hasPacket())
   75   	    Thread.yield();
   76   	conn.getPacket(p);
   77       }
   78   
   79       /**
   80        * This is a wrapper to the real sending method. It is needed because we overloaded the method send
   81        * with our own method.
   82        * @param p the datagram to send
   83        */
   84       public synchronized void _send(DatagramPacket p) throws IOException {
   85   	super.send(p);
   86       }
   87   
   88       /**
   89        * This is an overloaded method used to send packets.
   90        * It asks the connector to send it.
   91        * @param p the datagram to receive
   92        * @see #_send
   93        * @see java.net.DConnector#send
   94        */
   95       public void send(DatagramPacket p) throws IOException {
   96   	conn.send(p);
   97       }
   98   }

Save This Page
Home » openjdk-7 » java » net » [javadoc | source]