Clover coverage report - ActiveIO - 1.0
Coverage timestamp: Fri Apr 22 2005 14:27:22 PDT
file stats: LOC: 140   Methods: 18
NCLOC: 97   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
SynchChannelServerToServerSocketAdapter.java 33.3% 54.3% 44.4% 47.7%
coverage coverage
 1   
 /**
 2   
  *
 3   
  * Copyright 2004 Hiram Chirino
 4   
  *
 5   
  *  Licensed under the Apache License, Version 2.0 (the "License");
 6   
  *  you may not use this file except in compliance with the License.
 7   
  *  You may obtain a copy of the License at
 8   
  *
 9   
  *     http://www.apache.org/licenses/LICENSE-2.0
 10   
  *
 11   
  *  Unless required by applicable law or agreed to in writing, software
 12   
  *  distributed under the License is distributed on an "AS IS" BASIS,
 13   
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14   
  *  See the License for the specific language governing permissions and
 15   
  *  limitations under the License.
 16   
  */
 17   
 package org.activeio.adapter;
 18   
 
 19   
 import java.io.IOException;
 20   
 import java.io.InterruptedIOException;
 21   
 import java.net.InetAddress;
 22   
 import java.net.InetSocketAddress;
 23   
 import java.net.ServerSocket;
 24   
 import java.net.Socket;
 25   
 import java.net.SocketAddress;
 26   
 import java.net.SocketException;
 27   
 import java.net.URI;
 28   
 import java.nio.channels.ServerSocketChannel;
 29   
 
 30   
 import org.activeio.Channel;
 31   
 import org.activeio.SynchChannel;
 32   
 import org.activeio.SynchChannelServer;
 33   
 
 34   
 /**
 35   
  */
 36   
 public class SynchChannelServerToServerSocketAdapter extends ServerSocket {
 37   
 
 38   
     private final SynchChannelServer channelServer;
 39   
     private long timeout = Channel.WAIT_FOREVER_TIMEOUT;
 40   
     boolean closed;
 41   
     private InetAddress inetAddress;
 42   
     private int localPort;
 43   
     private SocketAddress localSocketAddress;
 44   
     private int receiveBufferSize;
 45   
     private boolean reuseAddress;
 46   
     
 47   
     /**
 48   
      * @throws IOException
 49   
      */
 50  12
     public SynchChannelServerToServerSocketAdapter(SynchChannelServer channelServer) throws IOException {
 51  12
         this.channelServer = channelServer;
 52  12
         URI connectURI = channelServer.getConnectURI();
 53  12
         localPort = connectURI.getPort();
 54  12
         inetAddress = InetAddress.getByName(connectURI.getHost());
 55  12
         localSocketAddress = new InetSocketAddress(inetAddress, localPort);        
 56   
     }
 57   
     
 58  14
     public synchronized void setSoTimeout(int timeout) throws SocketException {
 59  14
         if( timeout <= 0 )
 60  8
             this.timeout = Channel.WAIT_FOREVER_TIMEOUT;
 61   
         else 
 62  6
             this.timeout = timeout;
 63   
     }
 64   
     
 65  0
     public synchronized int getSoTimeout() throws IOException {
 66  0
         if( timeout == Channel.WAIT_FOREVER_TIMEOUT )
 67  0
             return 0;
 68  0
         return (int) timeout;
 69   
     }
 70   
 
 71  16
     public Socket accept() throws IOException {
 72  16
         Channel channel = channelServer.accept(timeout);
 73  4
         if( channel==null )
 74  0
             throw new InterruptedIOException();
 75   
         
 76  4
         SynchChannel synchChannel = AsynchToSynchChannelAdapter.adapt(channel);            
 77  4
         synchChannel.start();
 78  4
         return new SynchChannelToSocketAdapter(synchChannel);
 79   
                     
 80   
     }
 81   
     
 82  0
     public void bind(SocketAddress endpoint, int backlog) throws IOException {
 83  0
         if (isClosed())
 84  0
             throw new SocketException("Socket is closed");
 85  0
           throw new SocketException("Already bound");
 86   
     }
 87   
     
 88  0
     public void bind(SocketAddress endpoint) throws IOException {
 89  0
         if (isClosed())
 90  0
             throw new SocketException("Socket is closed");
 91  0
           throw new SocketException("Already bound");
 92   
     }
 93   
     
 94  12
     public void close() throws IOException {
 95  12
         if (!isClosed()) {
 96  12
             channelServer.dispose();
 97   
         }
 98   
     }
 99   
 
 100  0
     public ServerSocketChannel getChannel() {
 101  0
         return null;
 102   
     }
 103   
     
 104  6
     public InetAddress getInetAddress() {
 105  6
         return inetAddress;
 106   
     }
 107  12
     public int getLocalPort() {
 108  12
         return localPort;
 109   
     }
 110  0
     public SocketAddress getLocalSocketAddress() {
 111  0
         return localSocketAddress;
 112   
     }    
 113  0
     public synchronized int getReceiveBufferSize() throws SocketException {
 114  0
         return receiveBufferSize;
 115   
     }
 116   
     
 117  0
     public boolean getReuseAddress() throws SocketException {
 118  0
         return reuseAddress;
 119   
     }
 120   
     
 121  12
     public boolean isBound() {
 122  12
         return true;
 123   
     }
 124   
     
 125  12
     public boolean isClosed() {
 126  12
         return closed;
 127   
     }
 128   
     
 129  0
     public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
 130   
     }
 131   
     
 132  0
     public synchronized void setReceiveBufferSize(int size) throws SocketException {
 133  0
         this.receiveBufferSize = size;
 134   
     }
 135   
     
 136  0
     public void setReuseAddress(boolean on) throws SocketException {
 137  0
         reuseAddress = on;
 138   
     }    
 139   
 }
 140