org.limitless.nmc.Client
Class MuckConnection

java.lang.Object
  extended by org.limitless.nmc.Client.MuckConnection
All Implemented Interfaces:
java.lang.Runnable, MuLineEvent.Source

public class MuckConnection
extends java.lang.Object
implements MuLineEvent.Source, java.lang.Runnable

This class handles the networking for an NMC (or FB/TinyMUCK) based MUCK. In particular, it knows how to manage the OUTPUTPREFIX and OUTPUTSUFFIX commands, and the login protocols.


Nested Class Summary
static class MuckConnection.Factory
          This factory creates MuckConnections on demand given only a MuLoginDescription.
private static class MuckConnection.Marker
           
private static class MuckConnection.TestListener
           
 
Field Summary
private  boolean connectionDone
          if this is false, sends will fail.
private  MuckConnection.Marker EmptyMarker
           
private  GeneralEventSource eventSource
           
private  NMCStringDataSource fromMuck
           
private  boolean hasLoggedInAtLeastOnce
           
private  NMCStringDataSource.Factory inputFactory
           
(package private) static org.apache.log4j.Logger logger
          Log4J Logger
private  MuLoginDescription loginDetails
           
private  MuLogin loginObject
           
private  java.util.LinkedList markers
           
private  NMCStringDataDestination.Factory outputFactory
           
private  java.net.Socket rawConnection
           
private  boolean shutdownHasCompleted
           
private  boolean shutdownRequested
           
private  NMCStringDataDestination toMuck
           
private  UriIdentifier uri
           
 
Constructor Summary
MuckConnection(MuLoginDescription loginDescription)
           
 
Method Summary
private  void addMarker(MuckConnection.Marker marker)
           
 void addMuLineListener(MuLineEvent.Listener aListener)
           
private  void connect()
          This tries to connect, and updates flags on success/failure since it's used in the asynch parts.
private  void connectionLost()
          This is reached when the connection that _was_ established is lost.
private  void discardMarker()
           
 boolean equals(java.lang.Object o)
          Two MuckConnections are equal if their cached addresses are equal and their loginDetails are equal.
private  MuckConnection.Marker getMarker()
           
 UriIdentifier getMuURI()
          Call this to get a URI for this MU, without any of the username/password details (which allows this to be safely called by an object that has no "need to know" of any security data).
 int hashCode()
          Defer hashCode calculation to the login details.
 boolean isConnected()
          Call this to determine if the connection will send more messages in the future.
 boolean isShutdownDone()
          Call this to test if the object's background threading has finished.
 boolean isValid()
          Call this to check if the connection attempt has ever succeeded.
static void main(java.lang.String[] args)
           
private  void notifyConnection()
           
private  void notifyDroppedMarkers()
           
 void removeMuLineListener(MuLineEvent.Listener aListener)
           
 void run()
           
private  void sendDataWithMarkers(java.lang.String command)
           
 boolean sendTextToMu(java.lang.String dataToSend)
          Call this to send a command into the MUCK.
 void shutdown()
          Call this when done with this connection.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static org.apache.log4j.Logger logger
Log4J Logger


connectionDone

private boolean connectionDone
if this is false, sends will fail. This goes true when login has completed and goes false on disconnect detection.


shutdownRequested

private boolean shutdownRequested

shutdownHasCompleted

private boolean shutdownHasCompleted

rawConnection

private java.net.Socket rawConnection

loginObject

private MuLogin loginObject

loginDetails

private MuLoginDescription loginDetails

eventSource

private GeneralEventSource eventSource

hasLoggedInAtLeastOnce

private boolean hasLoggedInAtLeastOnce

uri

private UriIdentifier uri

inputFactory

private NMCStringDataSource.Factory inputFactory

outputFactory

private NMCStringDataDestination.Factory outputFactory

fromMuck

private NMCStringDataSource fromMuck

toMuck

private NMCStringDataDestination toMuck

markers

private java.util.LinkedList markers

EmptyMarker

private MuckConnection.Marker EmptyMarker
Constructor Detail

MuckConnection

public MuckConnection(MuLoginDescription loginDescription)
               throws java.net.UnknownHostException
Throws:
java.net.UnknownHostException
Method Detail

shutdown

public void shutdown()
Call this when done with this connection. This doesn't actually close the sockets, it causes the sockets to be closed during the later handling of the thread cycle. Never use this object after calling this except to call isShutdownDone.

Specified by:
shutdown in interface MuLineEvent.Source

isShutdownDone

public boolean isShutdownDone()
Call this to test if the object's background threading has finished.

Specified by:
isShutdownDone in interface MuLineEvent.Source

isConnected

public boolean isConnected()
Call this to determine if the connection will send more messages in the future. Note that because MUs can drop and re-start, this will return true even in cases when the MU is down.

Specified by:
isConnected in interface MuLineEvent.Source

isValid

public boolean isValid()
Call this to check if the connection attempt has ever succeeded. If this returns false, then the MU may be down, or the user-name/password may be wrong. This makes sense right after creation, with a time-out that's long enough for network delay but too short for annoyance, such as 30 seconds.

Specified by:
isValid in interface MuLineEvent.Source

getMuURI

public UriIdentifier getMuURI()
                       throws java.net.MalformedURLException
Call this to get a URI for this MU, without any of the username/password details (which allows this to be safely called by an object that has no "need to know" of any security data).

Specified by:
getMuURI in interface MuLineEvent.Source
Throws:
java.net.MalformedURLException

sendTextToMu

public boolean sendTextToMu(java.lang.String dataToSend)
Call this to send a command into the MUCK. This fails if there's no connection. The results from this call will trickle back to the listener. A "true" response only means the MUCK got the command, not that the command was valid or has been processed.

Specified by:
sendTextToMu in interface MuLineEvent.Source

connectionLost

private void connectionLost()
This is reached when the connection that _was_ established is lost.


connect

private void connect()
This tries to connect, and updates flags on success/failure since it's used in the asynch parts.


notifyDroppedMarkers

private void notifyDroppedMarkers()

notifyConnection

private void notifyConnection()

sendDataWithMarkers

private void sendDataWithMarkers(java.lang.String command)
                          throws NMCException
Throws:
NMCException

run

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

getMarker

private MuckConnection.Marker getMarker()

discardMarker

private void discardMarker()

addMarker

private void addMarker(MuckConnection.Marker marker)

addMuLineListener

public void addMuLineListener(MuLineEvent.Listener aListener)
Specified by:
addMuLineListener in interface MuLineEvent.Source

removeMuLineListener

public void removeMuLineListener(MuLineEvent.Listener aListener)
Specified by:
removeMuLineListener in interface MuLineEvent.Source

equals

public boolean equals(java.lang.Object o)
Two MuckConnections are equal if their cached addresses are equal and their loginDetails are equal.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Defer hashCode calculation to the login details. What MUCK we're connected to is all that really matters anyway.

Overrides:
hashCode in class java.lang.Object

main

public static void main(java.lang.String[] args)


Copyright © 1995, 2004 Limitless Knowledge Association, All Rights Reserved.