org.activeio.net
Class SocketStreamChannel

java.lang.Object
  extended byorg.activeio.net.SocketStreamChannel
All Implemented Interfaces:
Channel, Disposable, InputStreamChannel, OutputStreamChannel, Service, SocketMetadata, StreamChannel

public class SocketStreamChannel
extends Object
implements StreamChannel, SocketMetadata

A StreamChannel implementation that uses a Socket to talk to the network.

Version:
$Revision$

Field Summary
 
Fields inherited from interface org.activeio.Service
NO_WAIT_TIMEOUT, WAIT_FOREVER_TIMEOUT
 
Constructor Summary
protected SocketStreamChannel(Socket socket)
           
 
Method Summary
 int available()
           
 void dispose()
          This method should not throw any exceptions.
 void flush()
          Some channels may buffer data which may be sent down if flush() is called.
 InetAddress getInetAddress()
           
 boolean getKeepAlive()
           
 InetAddress getLocalAddress()
           
 int getLocalPort()
           
 SocketAddress getLocalSocketAddress()
           
 boolean getOOBInline()
           
 int getPort()
           
 int getReceiveBufferSize()
           
 SocketAddress getRemoteSocketAddress()
           
 boolean getReuseAddress()
           
 int getSendBufferSize()
           
 Socket getSocket()
           
 int getSoLinger()
           
 int getSoTimeout()
           
 boolean getTcpNoDelay()
           
 int getTrafficClass()
           
 boolean isBound()
           
 boolean isClosed()
           
 boolean isConnected()
           
 void mark(int pos)
           
 boolean markSupported()
           
 Object narrow(Class target)
          Since a Channel may be composed from a chain of other Channel obejcts, this method allows you to query the chain for the specified interface.
 int read()
           
 int read(byte[] data)
           
 int read(byte[] data, int offset, int length)
           
 void reset()
           
 void setKeepAlive(boolean on)
           
 void setOOBInline(boolean on)
           
 void setReceiveBufferSize(int size)
           
 void setReuseAddress(boolean on)
           
 void setSendBufferSize(int size)
           
 void setSoLinger(boolean on, int linger)
           
protected  void setSoTimeout(int i)
           
 void setTcpNoDelay(boolean on)
           
 void setTrafficClass(int tc)
           
 long skip(long count)
           
 void start()
          Starts the channel.
 void stop(long timeout)
          Stops the channel.
 String toString()
           
 void write(byte[] data)
           
 void write(byte[] data, int pos, int length)
           
 void write(int data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SocketStreamChannel

protected SocketStreamChannel(Socket socket)
                       throws IOException
Method Detail

setSoTimeout

protected void setSoTimeout(int i)
                     throws SocketException
Throws:
SocketException

flush

public void flush()
           throws IOException
Description copied from interface: OutputStreamChannel
Some channels may buffer data which may be sent down if flush() is called.

Specified by:
flush in interface OutputStreamChannel
Throws:
IOException
See Also:
org.activeio.Channel#flush()

dispose

public void dispose()
Description copied from interface: Disposable
This method should not throw any exceptions. Cleaning up a Disposable object should be easy of an end user therefore do not make him have to handle an Exception.

Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()

start

public void start()
           throws IOException
Description copied from interface: Service
Starts the channel. Once started, the channel is in the running state.

Specified by:
start in interface Service
Throws:
IOException

stop

public void stop(long timeout)
          throws IOException
Description copied from interface: Service
Stops the channel. Once stopped, the channel is in the stopped state.

Specified by:
stop in interface Service
Parameters:
timeout - The amount of time the channel is allowed to take to gracefully stop. If the timeout is exceeded, the channel should do a forcefull stop.
Throws:
IOException

getInetAddress

public InetAddress getInetAddress()
Specified by:
getInetAddress in interface SocketMetadata

getKeepAlive

public boolean getKeepAlive()
                     throws SocketException
Specified by:
getKeepAlive in interface SocketMetadata
Throws:
SocketException

getLocalAddress

public InetAddress getLocalAddress()
Specified by:
getLocalAddress in interface SocketMetadata

getLocalPort

public int getLocalPort()
Specified by:
getLocalPort in interface SocketMetadata

getLocalSocketAddress

public SocketAddress getLocalSocketAddress()
Specified by:
getLocalSocketAddress in interface SocketMetadata

getOOBInline

public boolean getOOBInline()
                     throws SocketException
Specified by:
getOOBInline in interface SocketMetadata
Throws:
SocketException

getPort

public int getPort()
Specified by:
getPort in interface SocketMetadata

getReceiveBufferSize

public int getReceiveBufferSize()
                         throws SocketException
Specified by:
getReceiveBufferSize in interface SocketMetadata
Throws:
SocketException

getRemoteSocketAddress

public SocketAddress getRemoteSocketAddress()
Specified by:
getRemoteSocketAddress in interface SocketMetadata

getReuseAddress

public boolean getReuseAddress()
                        throws SocketException
Specified by:
getReuseAddress in interface SocketMetadata
Throws:
SocketException

getSendBufferSize

public int getSendBufferSize()
                      throws SocketException
Specified by:
getSendBufferSize in interface SocketMetadata
Throws:
SocketException

getSoLinger

public int getSoLinger()
                throws SocketException
Specified by:
getSoLinger in interface SocketMetadata
Throws:
SocketException

getSoTimeout

public int getSoTimeout()
                 throws SocketException
Specified by:
getSoTimeout in interface SocketMetadata
Throws:
SocketException

getTcpNoDelay

public boolean getTcpNoDelay()
                      throws SocketException
Specified by:
getTcpNoDelay in interface SocketMetadata
Throws:
SocketException

getTrafficClass

public int getTrafficClass()
                    throws SocketException
Specified by:
getTrafficClass in interface SocketMetadata
Throws:
SocketException

isBound

public boolean isBound()
Specified by:
isBound in interface SocketMetadata

isClosed

public boolean isClosed()
Specified by:
isClosed in interface SocketMetadata

isConnected

public boolean isConnected()
Specified by:
isConnected in interface SocketMetadata

setKeepAlive

public void setKeepAlive(boolean on)
                  throws SocketException
Specified by:
setKeepAlive in interface SocketMetadata
Throws:
SocketException

setOOBInline

public void setOOBInline(boolean on)
                  throws SocketException
Specified by:
setOOBInline in interface SocketMetadata
Throws:
SocketException

setReceiveBufferSize

public void setReceiveBufferSize(int size)
                          throws SocketException
Specified by:
setReceiveBufferSize in interface SocketMetadata
Throws:
SocketException

setReuseAddress

public void setReuseAddress(boolean on)
                     throws SocketException
Specified by:
setReuseAddress in interface SocketMetadata
Throws:
SocketException

setSendBufferSize

public void setSendBufferSize(int size)
                       throws SocketException
Specified by:
setSendBufferSize in interface SocketMetadata
Throws:
SocketException

setSoLinger

public void setSoLinger(boolean on,
                        int linger)
                 throws SocketException
Specified by:
setSoLinger in interface SocketMetadata
Throws:
SocketException

setTcpNoDelay

public void setTcpNoDelay(boolean on)
                   throws SocketException
Specified by:
setTcpNoDelay in interface SocketMetadata
Throws:
SocketException

setTrafficClass

public void setTrafficClass(int tc)
                     throws SocketException
Specified by:
setTrafficClass in interface SocketMetadata
Throws:
SocketException

narrow

public Object narrow(Class target)
Description copied from interface: Channel
Since a Channel may be composed from a chain of other Channel obejcts, this method allows you to query the chain for the specified interface. The first Channel in the chain the implments the requested interface will be return an implementing object. If no Channel in the chain implements the requested class, then null is returned.

Specified by:
narrow in interface Channel

toString

public String toString()

write

public void write(byte[] data,
                  int pos,
                  int length)
           throws IOException
Specified by:
write in interface OutputStreamChannel
Throws:
IOException

write

public void write(byte[] data)
           throws IOException
Specified by:
write in interface OutputStreamChannel
Throws:
IOException

write

public void write(int data)
           throws IOException
Specified by:
write in interface OutputStreamChannel
Throws:
IOException

available

public int available()
              throws IOException
Specified by:
available in interface InputStreamChannel
Throws:
IOException

mark

public void mark(int pos)
Specified by:
mark in interface InputStreamChannel

markSupported

public boolean markSupported()
Specified by:
markSupported in interface InputStreamChannel

read

public int read(byte[] data,
                int offset,
                int length)
         throws IOException
Specified by:
read in interface InputStreamChannel
Throws:
IOException

read

public int read(byte[] data)
         throws IOException
Specified by:
read in interface InputStreamChannel
Throws:
IOException

reset

public void reset()
           throws IOException
Specified by:
reset in interface InputStreamChannel
Throws:
IOException

skip

public long skip(long count)
          throws IOException
Specified by:
skip in interface InputStreamChannel
Throws:
IOException

read

public int read()
         throws IOException
Specified by:
read in interface InputStreamChannel
Throws:
IOException

getSocket

public Socket getSocket()


Copyright © -2007 The ActiveIO Project. All Rights Reserved.