au.com.loftinspace.tcpreflector
Class TcpReflector

java.lang.Object
  extended byau.com.loftinspace.tcpreflector.TcpReflector
All Implemented Interfaces:
java.lang.Runnable

public class TcpReflector
extends java.lang.Object
implements java.lang.Runnable

Accepts client socket connections and establishes reflector sessions for each new connection.

Author:
Jem Mawson

Constructor Summary
TcpReflector(int listeningPort, java.net.InetSocketAddress destination)
           
 
Method Summary
 void addListener(PacketListener listener)
          Adds a packet listener to this instance.
 java.net.InetSocketAddress getDestination()
          Get the destination internet address for connections.
 java.util.List getPacketListeners()
          Returns an unmodifiable list of all PacketListeners associated with this instance.
 boolean isConnective()
          Returns whether this instance will accept new socket connections.
 boolean isReflective()
          Whether this reflector is redirecting packets.
 void removeAllListeners()
          Removes all PacketListeners from this instance.
 void removeListener(PacketListener listener)
          Removes a PacketListener from this instance.
 void run()
           
 void setConnective(boolean connective)
          Sets whether this instance will accept connections.
 void setDestination(java.net.InetSocketAddress destination)
          Set the destination internet address for future connections.
 void setReflective(boolean reflective)
          Whether this reflector should discard or redirect both incoming and outgoing packets.
 void setResponseReflective(boolean reflective)
          Whether this reflector should discard or redirect incoming packets.
 void shutdown()
          Causes the reflector to terminate all processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TcpReflector

public TcpReflector(int listeningPort,
                    java.net.InetSocketAddress destination)
             throws java.io.IOException
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

setReflective

public void setReflective(boolean reflective)
Whether this reflector should discard or redirect both incoming and outgoing packets.

Parameters:
reflective - true to redirect packets.
false to discard them.

setResponseReflective

public void setResponseReflective(boolean reflective)
Whether this reflector should discard or redirect incoming packets.

Parameters:
reflective - true to deliver incoming packets.
false to discard them.

isReflective

public boolean isReflective()
Whether this reflector is redirecting packets.

Returns:
true if it redirects packets.
false if it discards them.

getPacketListeners

public java.util.List getPacketListeners()
Returns an unmodifiable list of all PacketListeners associated with this instance.

Returns:
A list of PacketListeners

addListener

public void addListener(PacketListener listener)
Adds a packet listener to this instance. The listener will be called upon to take action whenever a packet is transmitted in either direction. This action affects both existing connections and new connections.


removeListener

public void removeListener(PacketListener listener)
Removes a PacketListener from this instance. The listener will no longer be called upon to handle packets on conenctions originating from this instance. This action affects both existing connections and new connections.


removeAllListeners

public void removeAllListeners()
Removes all PacketListeners from this instance. None of the packets on connections originating from this instance will be handled by any PacketListeners until such time as a new PacketListener is appended. This action affects both existing connections and new connections.


getDestination

public java.net.InetSocketAddress getDestination()
Get the destination internet address for connections.

Returns:
The destination internet address for connections.

setDestination

public void setDestination(java.net.InetSocketAddress destination)
Set the destination internet address for future connections. This does not affect currently active connections.

Parameters:
destination - The destination for future connections.

isConnective

public boolean isConnective()
Returns whether this instance will accept new socket connections. If this is false then connection attempts will result in an IOException.

Returns:
Whether this instance will accept new socket connections.

setConnective

public void setConnective(boolean connective)
                   throws java.io.IOException
Sets whether this instance will accept connections. This method will quick return and does not guarantee that a change from true to false will take effect immediately. until the instance state has been effectively changed. In practice this may mean waiting until any current socket accept attempt has timed out.

Parameters:
connective - Whether this instance should accept connections.
Throws:
java.io.IOException - If a problem is encountered establishing or shutting down the underlying ServerSocket connection.

shutdown

public void shutdown()
Causes the reflector to terminate all processing. The underlying socket connection will be lost. This action is unrecoverable.



Copyright © 2004 Loft in Space. All Rights Reserved.