com.echomine.net
Class ConnectionModel

java.lang.Object
  extended by com.echomine.net.ConnectionModel

public class ConnectionModel
extends java.lang.Object

Contains all the data that are needed by Connector to make a connection. Subclasses can store additional details such as protocol version (ie. HTTP 1.1). This connection model also adds support for throttling and bandwidth management. Not all uses of this model will make use of such feature, but the feature is there is a need for it.


Constructor Summary
ConnectionModel(java.net.InetAddress host, int port)
           
ConnectionModel(java.net.InetAddress host, int port, ConnectionThrottler throttler)
           
ConnectionModel(int port)
          Normally used to create a listener for incoming connections.
ConnectionModel(java.lang.String hostname, int port)
           
ConnectionModel(java.lang.String hostname, int port, ConnectionThrottler throttler)
           
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 java.net.InetAddress getHost()
           
 java.lang.String getHostAddress()
          Convenience Method for obtaining the host IP from the InetAddress
 java.lang.String getHostName()
          Convenience Method for obtaining the hostname from the InetAddress
 int getPort()
           
 ConnectionThrottler getThrottler()
           
 long getTimeOnlineMillis()
           
 java.lang.String getTimeOnlineString()
           
 long getTransferBPS()
           
 float getTransferKBPS()
           
 void incrementBytesTransferred(long increment)
          increments the bytes transferred for calculation of throttling as well as the bandwidth BPS
 boolean isSSL()
          replies whether this is secure or not
 void reset()
          Resets all the data fields back to the initial state.
 void setEndTime(long endTime)
          Sets the end time when the transfer is finished
 void setHost(java.net.InetAddress host)
          sets the host after the connection created
 void setPort(int port)
          sets the port after the connection is created
 void setSSL(boolean secure)
          sets this to be a secure SSL connection
 void setStartTime(long startTime)
          Sets the start time when the connection begins.
 void setThrottler(ConnectionThrottler throttler)
          sets the throttler for the connection bandwidth.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConnectionModel

public ConnectionModel(int port)
Normally used to create a listener for incoming connections. This is used so that acceptors can bind to 0.0.0.0, and not to a specific interface.

Parameters:
port - the port to connect to/receive from

ConnectionModel

public ConnectionModel(java.net.InetAddress host,
                       int port)
Parameters:
host - the InetAddress containing the hostname/IP
port - the port to connect to/receive from

ConnectionModel

public ConnectionModel(java.lang.String hostname,
                       int port)
                throws java.net.UnknownHostException
Parameters:
hostname - the hostname/IP to create
port - the port to connect to/receive from
Throws:
java.net.UnknownHostException

ConnectionModel

public ConnectionModel(java.net.InetAddress host,
                       int port,
                       ConnectionThrottler throttler)
Parameters:
host - the InetAddress containing the hostname/IP
port - the port to connect to/receive from
throttler - the bandwidth throttler, or null if no throttling

ConnectionModel

public ConnectionModel(java.lang.String hostname,
                       int port,
                       ConnectionThrottler throttler)
                throws java.net.UnknownHostException
Parameters:
hostname - the hostname/IP to create
port - the port to connect to/receive from
throttler - the bandwidth throttler, or null if no throttling
Throws:
java.net.UnknownHostException
Method Detail

getPort

public int getPort()
Returns:
the port

getHost

public java.net.InetAddress getHost()
Returns:
the host

getHostName

public java.lang.String getHostName()
Convenience Method for obtaining the hostname from the InetAddress


getHostAddress

public java.lang.String getHostAddress()
Convenience Method for obtaining the host IP from the InetAddress


setPort

public void setPort(int port)
sets the port after the connection is created


setHost

public void setHost(java.net.InetAddress host)
sets the host after the connection created


setSSL

public void setSSL(boolean secure)
sets this to be a secure SSL connection


isSSL

public boolean isSSL()
replies whether this is secure or not


equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

setThrottler

public void setThrottler(ConnectionThrottler throttler)
sets the throttler for the connection bandwidth. Set to null if no throttling is required.


getThrottler

public ConnectionThrottler getThrottler()
Returns:
the connection bandwidth throttler, or null if none exists

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a string in the format of :

incrementBytesTransferred

public void incrementBytesTransferred(long increment)
increments the bytes transferred for calculation of throttling as well as the bandwidth BPS


getTransferKBPS

public float getTransferKBPS()
Returns:
the bandwidth rate in KBytes/sec

getTransferBPS

public long getTransferBPS()
Returns:
the bandwidth rate in Bytes/sec.

getTimeOnlineMillis

public long getTimeOnlineMillis()
Returns:
the time online in milliseconds

getTimeOnlineString

public java.lang.String getTimeOnlineString()
Returns:
the estimated time online, in the format of HH:MM:SS

reset

public void reset()
Resets all the data fields back to the initial state. This is good when the model is to be reused.


setStartTime

public void setStartTime(long startTime)
Sets the start time when the connection begins. This will effectively reset all the other stats automatically


setEndTime

public void setEndTime(long endTime)
Sets the end time when the transfer is finished



Copyright © 2001-2005 Echomine. All Rights Reserved.