Package org.jline.builtins.telnet
Class ConnectionData
- java.lang.Object
-
- org.jline.builtins.telnet.ConnectionData
-
public class ConnectionData extends java.lang.Object
An utility class that is used to store and allow retrieval of all data associated with a connection.- Version:
- 2.0 (16/07/2006)
- See Also:
Connection
-
-
Field Summary
Fields Modifier and Type Field Description private java.net.InetAddress
address
private ConnectionManager
connectionManager
private java.util.Map<java.lang.String,java.lang.String>
environment
private java.lang.String
hostAddress
private java.lang.String
hostName
private long
lastActivity
private boolean
lineMode
private java.util.Locale
locale
private java.lang.String
loginShell
private java.lang.String
negotiatedTerminalType
private int
port
private java.net.Socket
socket
private int[]
terminalGeometry
private boolean
terminalGeometryChanged
private boolean
warned
-
Constructor Summary
Constructors Constructor Description ConnectionData(java.net.Socket sock, ConnectionManager cm)
Constructs a ConnectionData instance storing vital information about a connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activity()
Sets a new timestamp to the actual time in millis retrieved from the System.java.util.Map<java.lang.String,java.lang.String>
getEnvironment()
Returns the hashmap for storing and retrieving environment variables to be passed between shells.java.lang.String
getHostAddress()
Returns the IP address of the connection.java.lang.String
getHostName()
Returns the fully qualified host name for the connection's IP address.
The name is cached on creation for performance reasons.java.net.InetAddress
getInetAddress()
Returns the InetAddress object associated with the connection.long
getLastActivity()
Returns a timestamp of the last activity that happened on the associated connection.java.util.Locale
getLocale()
Returns the Locale object associated with the connection by carrying out a simple domain match.java.lang.String
getLoginShell()
Returns the login shell name.ConnectionManager
getManager()
Returns a reference to the ConnectionManager the connection is associated with.java.lang.String
getNegotiatedTerminalType()
Returns the terminal type that has been negotiated between the telnet client and the telnet server, in of a String.int
getPort()
Returns the remote port to which the socket is connected.java.net.Socket
getSocket()
Returns a reference to the socket the Connection is associated with.int
getTerminalColumns()
Returns the width of the terminal in columns for convenience.int[]
getTerminalGeometry()
Returns the terminal geometry in an array of two integers.int
getTerminalRows()
Returns the height of the terminal in rows for convenience.boolean
isLineMode()
Tests if in line mode.boolean
isTerminalGeometryChanged()
Returns the state of the terminal geometry changed flag, which will be true if it has been set, and false if not.boolean
isWarned()
Returns the state of the idle warning flag, which will be true if a warning has been issued, and false if not.private void
setHostAddress()
Mutator for HostAddress cacheprivate void
setHostName()
Mutator for HostName cachevoid
setLineMode(boolean b)
Sets the line mode flag for the connection.private void
setLocale()
Mutator for Locale Sets a Locale derived from the hostname, or the default which is Locale.ENGLISH if something goes wrong.void
setLoginShell(java.lang.String s)
Sets the login shell name.void
setNegotiatedTerminalType(java.lang.String termtype)
Sets the terminal type that has been negotiated between telnet client and telnet server, in form of a String.void
setTerminalGeometry(int width, int height)
Sets the terminal geometry data.
This method should not be called explicitly by the application (i.e.void
setWarned(boolean bool)
Sets the state of the idle warning flag.
Note that this method will also update the the timestamp if the idle warning flag is removed, which means its kind of a second way to achieve the same thing as with the activity method.
-
-
-
Field Detail
-
connectionManager
private ConnectionManager connectionManager
-
socket
private java.net.Socket socket
-
address
private java.net.InetAddress address
-
environment
private java.util.Map<java.lang.String,java.lang.String> environment
-
hostName
private java.lang.String hostName
-
hostAddress
private java.lang.String hostAddress
-
port
private int port
-
locale
private java.util.Locale locale
-
lastActivity
private long lastActivity
-
warned
private boolean warned
-
negotiatedTerminalType
private java.lang.String negotiatedTerminalType
-
terminalGeometry
private int[] terminalGeometry
-
terminalGeometryChanged
private boolean terminalGeometryChanged
-
loginShell
private java.lang.String loginShell
-
lineMode
private boolean lineMode
-
-
Constructor Detail
-
ConnectionData
public ConnectionData(java.net.Socket sock, ConnectionManager cm)
Constructs a ConnectionData instance storing vital information about a connection.- Parameters:
sock
- Socket of the inbound connection.cm
- the connection manager
-
-
Method Detail
-
getManager
public ConnectionManager getManager()
Returns a reference to the ConnectionManager the connection is associated with.- Returns:
- Reference to the associated ConnectionManager.
- See Also:
ConnectionManager
-
getSocket
public java.net.Socket getSocket()
Returns a reference to the socket the Connection is associated with.- Returns:
- Reference to the associated Socket.
- See Also:
Socket
-
getPort
public int getPort()
Returns the remote port to which the socket is connected.- Returns:
- String that contains the remote port number to which the socket is connected.
-
getHostName
public java.lang.String getHostName()
Returns the fully qualified host name for the connection's IP address.
The name is cached on creation for performance reasons. Subsequent calls will not result in resolve queries.- Returns:
- String that contains the fully qualified host name for this address.
-
getHostAddress
public java.lang.String getHostAddress()
Returns the IP address of the connection.- Returns:
- String that contains the connection's IP address.
The format "%d.%d.%d.%d" is well known, where %d goes from zero to 255.
-
getInetAddress
public java.net.InetAddress getInetAddress()
Returns the InetAddress object associated with the connection.- Returns:
- InetAddress associated with the connection.
-
getLocale
public java.util.Locale getLocale()
Returns the Locale object associated with the connection by carrying out a simple domain match.
This can either be effective, if your users are really home in the country they are connecting from, or ineffective if they are on the move getting connected from anywhere in the world.
Yet this gives the chance of capturing a default locale and starting from some point. On application context this can be by far better handled, so be aware that it makes sense to spend some thoughts on that thing when you build your application.- Returns:
- the Locale object "guessed" for the connection based on its host name.
-
getLastActivity
public long getLastActivity()
Returns a timestamp of the last activity that happened on the associated connection.- Returns:
- the timestamp as a long representing the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
-
activity
public void activity()
Sets a new timestamp to the actual time in millis retrieved from the System. This will remove an idle warning flag if it has been set. Note that you can use this behaviour to implement your own complex idle timespan policies within the context of your application.
The check frequency of the ConnectionManager should just be set according to the lowest time to warning and time to disconnect requirements.
-
isWarned
public boolean isWarned()
Returns the state of the idle warning flag, which will be true if a warning has been issued, and false if not.- Returns:
- the state of the idle warning flag.
-
setWarned
public void setWarned(boolean bool)
Sets the state of the idle warning flag.
Note that this method will also update the the timestamp if the idle warning flag is removed, which means its kind of a second way to achieve the same thing as with the activity method.- Parameters:
bool
- true if a warning is to be issued, false if to be removed.- See Also:
activity()
-
setTerminalGeometry
public void setTerminalGeometry(int width, int height)
Sets the terminal geometry data.
This method should not be called explicitly by the application (i.e. the its here for the io subsystem).
A call will set the terminal geometry changed flag.- Parameters:
width
- of the terminal in columns.height
- of the terminal in rows.
-
getTerminalGeometry
public int[] getTerminalGeometry()
Returns the terminal geometry in an array of two integers.- index 0: Width in columns.
- index 1: Height in rows.
- Returns:
- integer array containing width and height.
-
getTerminalColumns
public int getTerminalColumns()
Returns the width of the terminal in columns for convenience.- Returns:
- the number of columns.
-
getTerminalRows
public int getTerminalRows()
Returns the height of the terminal in rows for convenience.- Returns:
- the number of rows.
-
isTerminalGeometryChanged
public boolean isTerminalGeometryChanged()
Returns the state of the terminal geometry changed flag, which will be true if it has been set, and false if not.- Returns:
- the state of the terminal geometry changed flag.
-
getNegotiatedTerminalType
public java.lang.String getNegotiatedTerminalType()
Returns the terminal type that has been negotiated between the telnet client and the telnet server, in of a String.- Returns:
- the negotiated terminal type as String.
-
setNegotiatedTerminalType
public void setNegotiatedTerminalType(java.lang.String termtype)
Sets the terminal type that has been negotiated between telnet client and telnet server, in form of a String.This method should not be called explicitly by the application (i.e. the its here for the io subsystem).
- Parameters:
termtype
- the negotiated terminal type as String.
-
getEnvironment
public java.util.Map<java.lang.String,java.lang.String> getEnvironment()
Returns the hashmap for storing and retrieving environment variables to be passed between shells.- Returns:
- a
HashMap
instance.
-
getLoginShell
public java.lang.String getLoginShell()
Returns the login shell name.- Returns:
- the shell name as string.
-
setLoginShell
public void setLoginShell(java.lang.String s)
Sets the login shell name.- Parameters:
s
- the shell name as string.
-
isLineMode
public boolean isLineMode()
Tests if in line mode.- Returns:
- true if in line mode, false otherwise
-
setLineMode
public void setLineMode(boolean b)
Sets the line mode flag for the connection. Note that the setting will only be used at startup at the moment.- Parameters:
b
- true if to be initialized in linemode, false otherwise.
-
setHostName
private void setHostName()
Mutator for HostName cache
-
setHostAddress
private void setHostAddress()
Mutator for HostAddress cache
-
setLocale
private void setLocale()
Mutator for Locale Sets a Locale derived from the hostname, or the default which is Locale.ENGLISH if something goes wrong. The localhost represents a problem for example :)
-
-