ecologylab.services.authentication.nio
Class NIOAuthClient

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.services.distributed.impl.NIOCore
          extended by ecologylab.services.distributed.impl.NIONetworking
              extended by ecologylab.services.distributed.client.NIOClient
                  extended by ecologylab.services.authentication.nio.NIOAuthClient
All Implemented Interfaces:
StartAndStoppable, AuthConstants, AuthMessages, AuthClientRegistryObjects, ClientConstants, NetworkingConstants, java.lang.Runnable

public class NIOAuthClient
extends NIOClient
implements AuthClientRegistryObjects, AuthConstants, AuthMessages

A client application that uses authentication and communicates using NIO.

Author:
Zachary O. Toups (toupsz@cs.tamu.edu)

Field Summary
protected  AuthenticationListEntry entry
          The username / password information supplied by the user.
 
Fields inherited from class ecologylab.services.distributed.client.NIOClient
headerMap, incomingMessageBuffer, isSending, outgoingChars, outgoingMessageBuffer, outgoingMessageHeaderBuffer, pRequestPool, reconnectAttempts, requestBuffer, requestsQueue, responsePool, selectInterval, serverAddress, startReadIndex, thisSocket, unfulfilledRequests, waitBetweenReconnectAttempts
 
Fields inherited from class ecologylab.services.distributed.impl.NIONetworking
byteBufferPool, connectionCount, objectRegistry, shuttingDown, translationSpace
 
Fields inherited from class ecologylab.services.distributed.impl.NIOCore
portNumber, selector
 
Fields inherited from interface ecologylab.services.authentication.registryobjects.AuthClientRegistryObjects
LOGIN_STATUS, LOGIN_STATUS_STRING
 
Fields inherited from interface ecologylab.services.authentication.AuthConstants
LOGIN_FAILED_TIMEOUT, LOGIN_WAIT_TIME
 
Fields inherited from interface ecologylab.services.authentication.messages.AuthMessages
LOGIN_FAILED_LOGGEDIN, LOGIN_FAILED_NO_IP_SUPPLIED, LOGIN_FAILED_PASSWORD, LOGIN_SUCCESSFUL, LOGOUT_FAILED_IP_MISMATCH, LOGOUT_FAILED_NOT_LOGGEDIN, LOGOUT_SUCCESSFUL, REQUEST_FAILED_NOT_AUTHENTICATED
 
Fields inherited from interface ecologylab.services.distributed.common.ClientConstants
RECONNECT_ATTEMPTS, WAIT_BEWTEEN_RECONNECT_ATTEMPTS
 
Fields inherited from interface ecologylab.services.distributed.common.NetworkingConstants
CHARACTER_ENCODING, CONTENT_LENGTH_STRING, CONTENT_LENGTH_STRING_LENGTH, DECODER, ENCODER, HTTP_HEADER_LINE_DELIMITER, HTTP_HEADER_TERMINATOR, MAX_HTTP_HEADER_LENGTH, MAX_PACKET_SIZE_BYTES, MAX_PACKET_SIZE_CHARACTERS, UNIQUE_IDENTIFIER_STRING
 
Constructor Summary
NIOAuthClient(java.lang.String server, int port)
          Creates a new AuthClient object using the given parameters.
NIOAuthClient(java.lang.String server, int port, AuthenticationListEntry entry, int interval, RequestMessage messageToSend)
          Creates a new AuthClient object using the given parameters.
NIOAuthClient(java.lang.String server, int port, TranslationSpace messageSpace, Scope objectRegistry, AuthenticationListEntry entry)
           
NIOAuthClient(java.lang.String server, int port, TranslationSpace messageSpace, Scope objectRegistry, AuthenticationListEntry entry, int interval, RequestMessage messageToSend)
          Main constructor; creates a new AuthClient using the parameters.
NIOAuthClient(java.lang.String server, int port, TranslationSpace messageSpace, Scope objectRegistry, int interval, RequestMessage messageToSend)
          Creates a new AuthClient object using the given parameters.
 
Method Summary
 java.lang.String getExplanation()
           
 boolean isLoggedIn()
           
 boolean isLoggingIn()
           
 boolean isLoggingOut()
           
 boolean login()
          Attempts to connect to the server using the AuthenticationListEntry that is associated with the client's side of the connection.
 boolean logout()
          Attempts to log out of the server using the AuthenticationListEntry that is associated with the client's side of the connection.
protected  ResponseMessage sendLoginMessage()
          Sends a Login message to the server; may be overridden by subclasses that need to add addtional information to the Login message.
protected  ResponseMessage sendLogoutMessage()
          Sends a Logout message to the server; may be overridden by subclasses that need to add addtional information to the Logout message.
 void setEntry(AuthenticationListEntry entry)
           
 
Methods inherited from class ecologylab.services.distributed.client.NIOClient
acceptFinished, acceptKey, acceptReady, addUnfulfilledRequest, checkAndDropIdleKeys, clearSessionId, connect, connected, connectReady, createConnection, dequeueRequest, disconnect, disconnect, enqueueRequestForSending, generateUid, getServer, getUidNoIncrement, invalidateKey, isServerRunning, nonBlockingSendMessage, nullOut, parseHeader, prepareAndEnqueueRequestForSending, processReadData, processResponse, readFinished, reconnect, removeBadConnections, requestsRemaining, sendMessage, sendMessage, setReconnectAttempts, setServer, setWaitBetweenReconnectAttempts, shutdownOK, start, stop, translateXMLStringToResponse, unableToRestorePreviousConnection, waitForConnect, writeKey
 
Methods inherited from class ecologylab.services.distributed.impl.NIONetworking
acquireByteBufferFromPool, connectionTerminated, enqueueBytesForWriting, readReady, terminationAction, writeReady
 
Methods inherited from class ecologylab.services.distributed.impl.NIOCore
close, connectFinished, getPortNumber, invalidateKey, queueForAccept, queueForConnect, queueForRead, queueForWrite, run, setPendingInvalidate, writeFinished
 
Methods inherited from class ecologylab.generic.Debug
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

entry

protected AuthenticationListEntry entry
The username / password information supplied by the user.

Constructor Detail

NIOAuthClient

public NIOAuthClient(java.lang.String server,
                     int port)
              throws java.io.IOException
Creates a new AuthClient object using the given parameters.

Parameters:
server -
port -
Throws:
java.io.IOException

NIOAuthClient

public NIOAuthClient(java.lang.String server,
                     int port,
                     TranslationSpace messageSpace,
                     Scope objectRegistry,
                     int interval,
                     RequestMessage messageToSend)
              throws java.io.IOException
Creates a new AuthClient object using the given parameters.

Parameters:
server -
port -
messageSpace -
objectRegistry -
Throws:
java.io.IOException

NIOAuthClient

public NIOAuthClient(java.lang.String server,
                     int port,
                     AuthenticationListEntry entry,
                     int interval,
                     RequestMessage messageToSend)
              throws java.io.IOException
Creates a new AuthClient object using the given parameters.

Parameters:
server -
port -
entry -
Throws:
java.io.IOException

NIOAuthClient

public NIOAuthClient(java.lang.String server,
                     int port,
                     TranslationSpace messageSpace,
                     Scope objectRegistry,
                     AuthenticationListEntry entry)
              throws java.io.IOException
Throws:
java.io.IOException

NIOAuthClient

public NIOAuthClient(java.lang.String server,
                     int port,
                     TranslationSpace messageSpace,
                     Scope objectRegistry,
                     AuthenticationListEntry entry,
                     int interval,
                     RequestMessage messageToSend)
              throws java.io.IOException
Main constructor; creates a new AuthClient using the parameters.

Parameters:
server -
port -
messageSpace -
objectRegistry -
entry -
Throws:
java.io.IOException
Method Detail

setEntry

public void setEntry(AuthenticationListEntry entry)
Parameters:
entry - The entry to set.

login

public boolean login()
              throws java.io.IOException
Attempts to connect to the server using the AuthenticationListEntry that is associated with the client's side of the connection. Does not block for connection.

Throws:
java.io.IOException

logout

public boolean logout()
               throws java.io.IOException
Attempts to log out of the server using the AuthenticationListEntry that is associated with the client's side of the connection. Blocks until a response is received or until LOGIN_WAIT_TIME passes, whichever comes first.

Throws:
java.io.IOException

sendLogoutMessage

protected ResponseMessage sendLogoutMessage()
                                     throws java.io.IOException
Sends a Logout message to the server; may be overridden by subclasses that need to add addtional information to the Logout message.

Throws:
java.io.IOException

sendLoginMessage

protected ResponseMessage sendLoginMessage()
                                    throws java.io.IOException
Sends a Login message to the server; may be overridden by subclasses that need to add addtional information to the Login message.

Throws:
java.io.IOException

isLoggingIn

public boolean isLoggingIn()
Returns:
Returns the loggingIn.

isLoggingOut

public boolean isLoggingOut()
Returns:
Returns the loggingOut.

getExplanation

public java.lang.String getExplanation()
Returns:
The response message from the server regarding the last attempt to log in; if login fails, will indicate why.

isLoggedIn

public boolean isLoggedIn()
Returns:
Returns whether or not this client is logged in to a server.