|
|||||||||
| Home >> All >> com >> synaptics >> [ elvis overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.synaptics.elvis
Class ElvisComm

java.lang.Objectcom.synaptics.elvis.ElvisComm
- All Implemented Interfaces:
- java.lang.Runnable
- final class ElvisComm
- extends java.lang.Object
- implements java.lang.Runnable
- extends java.lang.Object
| Field Summary | |
private java.io.File |
auth
|
private ElvisMessageFactory |
emf
This guy puts together messages for us to send to another Elvis, either requests to be sent to the One True Elvis, or responses to be sent back to a client. |
private ElvisHandler |
handler
This is the Elvis handler provided by the client. |
private java.lang.String |
key
|
static int |
MAX_PORT_OFFSET
A random number between this 0 and this value will be added to the port number submitted by the user. |
static int |
MAX_SERVER_PORT
The maximum possible port number is 65535. |
static int |
MIN_SERVER_PORT
This value is chosen to prevent collisions with the so called "well known" ports like ftp, telnet, etc. |
private int |
port
|
private java.lang.String |
program
This is the name of the program, as supplied by the user. |
private java.beans.PropertyChangeSupport |
propertyChangeSupport
Utility field used by bound properties. |
private java.net.ServerSocket |
server
|
private static java.lang.String |
SETTINGS_DIRECTORY
This is where we keep the file with the public information about Elvis. |
private ElvisCommStatus |
status
This is the status of the Listener. |
static java.lang.String |
STATUS_PROPERTY
|
private int |
theActualPort
This is the actual port value we are listening to. |
private java.lang.Thread |
tServer
|
| Constructor Summary | |
(package private) |
ElvisComm(java.lang.String program,
int port,
ElvisHandler handler)
Creates a new ElvisComm, using the specified program name, port number, and handler. |
| Method Summary | |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener l)
Add a PropertyChangeListener to the listener list. |
ElvisHandler |
getHandler()
Return the ElvisHandler we are using. |
int |
getPort()
Gets the port number that we are communicating over. |
ElvisCommStatus |
getStatus()
Return the ElvisCommStatus corresponding to the current state of the ElvisComm. |
private void |
intrusion()
This will warn the user that someone is attempting to break into his system. |
(package private) ElvisResult |
perform(java.lang.String data)
|
(package private) ElvisResult |
perform(java.lang.String data,
int timeout)
Contact the One True Elvis and request him to perform something for us. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a PropertyChangeListener from the listener list. |
void |
run()
Wait for connections from other Elvises. |
void |
setHandler(ElvisHandler handler)
Specify a new handler for requests submitted to this Elvis. |
private void |
setStatus(ElvisCommStatus status)
Update the status. |
void |
start()
Start the listener. |
(package private) void |
stop()
Stops the server by inerrupting the thread, killing it and then closing the server itself. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
port
private int port
auth
private java.io.File auth
key
private java.lang.String key
tServer
private java.lang.Thread tServer
server
private java.net.ServerSocket server
SETTINGS_DIRECTORY
private static final java.lang.String SETTINGS_DIRECTORY
- This is where we keep the file with the public information about Elvis.
TODO: Make this more portable.
- See Also:
- Constant Field Values
MIN_SERVER_PORT
public static final int MIN_SERVER_PORT
- This value is chosen to prevent collisions with the so called "well known" ports
like ftp, telnet, etc. An exception will be thrown if you try to create an ElvisComm
with a port less than this value.
- See Also:
- Constant Field Values
MAX_PORT_OFFSET
public static final int MAX_PORT_OFFSET
- A random number between this 0 and this value will be added to the port number submitted
by the user. Offsetting the port in this way decreases Elvis vulnerability to sniffing and
spoofing. This should not be construed as an ironclad security mechanism - it simply
makes life harder for determined attackers, and may discourage more casual attempts. If your
application requires serious security, you should use a secure encryption strategy.
- See Also:
- Constant Field Values
MAX_SERVER_PORT
public static final int MAX_SERVER_PORT
- The maximum possible port number is 65535. Since we randomly offset from the user supplied port number
we must make sure we don't exceed 65535 - thus the maximum permitted port is equal to 65535 minus the
maximum offset.
- See Also:
- Constant Field Values
handler
private ElvisHandler handler
- This is the Elvis handler provided by the client.
theActualPort
private int theActualPort
- This is the actual port value we are listening to.
program
private java.lang.String program
- This is the name of the program, as supplied by the user.
TODO: Handle multiple instances of a single Elvis program in a single JVM gracefully.
status
private ElvisCommStatus status
- This is the status of the Listener.
TODO: Handle this in a more robust and coherent manner.
propertyChangeSupport
private java.beans.PropertyChangeSupport propertyChangeSupport
- Utility field used by bound properties.
STATUS_PROPERTY
public static final java.lang.String STATUS_PROPERTY
- See Also:
- Constant Field Values
emf
private ElvisMessageFactory emf
- This guy puts together messages for us to send to another Elvis, either requests to
be sent to the One True Elvis, or responses to be sent back to a client.
| Constructor Detail |
ElvisComm
ElvisComm(java.lang.String program, int port, ElvisHandler handler)
- Creates a new ElvisComm, using the specified program name, port number, and handler.
Note that this does not actually initiate the listening process. You must call start() to do that.
For security reasons, the provided port is not used unmodified. Instead, a random number between 0 and
MAX_PORT_OFFSETis added to it. The purpose of this is to help prevent attacks against an Elvis client operating on a known port number - if the port moves around, it makes it that much harder to establish contact.
| Method Detail |
start
public void start()
- Start the listener.
If the process fails, an appropriate exception will be thrown, and the status will be set to
ElvisCommStatus.FAILED. If we succeed, status will be set toElvisCommStatus.OK(if we are the One True Elvis) orElvisCommStatus.NOT_THE_KINGif we are an impersonator.
stop
void stop()
- Stops the server by inerrupting the thread, killing it and then
closing the server itself. Finally, it erases the authorization
key.
Note: this could leave other Elvis's in the lurch. On the other hand, it is not intended that Elvis clients should persist for very long. See the Elvis documentation for more information.
run
public void run()
- Wait for connections from other Elvises. If a connection is made and accepted,
we expect the other party to send us a single line, which ought to be the text
form of an ElvisMessage. We reject contacts under the following circumstances:
- the connection does not originate on this host;
- the message does not parse according to the ElvisMessage rules;
- the message does not have the correct program name;
- the message does not have the correct program key.
- Specified by:
runin interfacejava.lang.Runnable
intrusion
private void intrusion()
- This will warn the user that someone is attempting to break into his system.
TODO: Eliminate the JOptionPane - swinger though Elvis may have been, he doesn't need to be dependent on Swing.
getHandler
public ElvisHandler getHandler()
- Return the ElvisHandler we are using.
setHandler
public void setHandler(ElvisHandler handler)
- Specify a new handler for requests submitted to this Elvis. This is only valid if
we are the One True Elvis, or have not yet attempted a connection.
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
- Add a PropertyChangeListener to the listener list.
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
- Removes a PropertyChangeListener from the listener list.
getStatus
public ElvisCommStatus getStatus()
- Return the ElvisCommStatus corresponding to the current state of the ElvisComm. Normally
this will be a pretty boring item, but it can be used to track the state of the
ElvisComm while it is connecting or performing a request.
Interested parties can track the status by listening on the
STATUS_PROPERTYproperty.
setStatus
private void setStatus(ElvisCommStatus status)
- Update the status. Listeners will be notified if this is different than the
previous status.
perform
ElvisResult perform(java.lang.String data)
perform
ElvisResult perform(java.lang.String data, int timeout)
- Contact the One True Elvis and request him to perform something for us.
getPort
public int getPort()
- Gets the port number that we are communicating over. This may or may not
be the same as the port value originally submitted, since we use a random
offset to establish the actual port number.
|
|||||||||
| Home >> All >> com >> synaptics >> [ elvis overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.synaptics.elvis.ElvisComm