pawn.services.chat
Class ChatServiceImpl

java.lang.Object
  |
  +--pawn.services.chat.ChatServiceImpl
All Implemented Interfaces:
ChatService, net.jxta.platform.Module, net.jxta.resolver.QueryHandler, net.jxta.service.Service

public class ChatServiceImpl
extends java.lang.Object
implements ChatService, net.jxta.resolver.QueryHandler

The implementation of the ChatService interface. This service builds on top of the Resolver service to provide the functionality for requesting and approving a chat session.


Field Summary
static java.lang.String refModuleSpecID
          The Module Specification ID for the Chat service.
 
Fields inherited from interface pawn.services.chat.ChatService
refModuleClassID
 
Constructor Summary
ChatServiceImpl()
          Create a new ChatServiceImpl object.
 
Method Summary
 void addListener(pawn.services.chat.ChatListener listener)
          Add a listener object to the service.
 void approveChat(net.jxta.protocol.PipeAdvertisement pipeAdvertisement, java.lang.String emailAddress, java.lang.String displayName, int queryID)
          Approve a chat session.
 net.jxta.document.Advertisement getImplAdvertisement()
          Returns the advertisement for this service.
 net.jxta.service.Service getInterface()
          Returns an interface used to protect this service.
 void init(net.jxta.peergroup.PeerGroup group, net.jxta.id.ID assignedID, net.jxta.document.Advertisement implAdv)
          Initialize the service.
 net.jxta.protocol.ResolverResponseMsg processQuery(net.jxta.protocol.ResolverQueryMsg query)
          Process a Resolver Query Message.
 void processResponse(net.jxta.protocol.ResolverResponseMsg response)
          Process a Resolver response message.
 boolean removeListener(pawn.services.chat.ChatListener listener)
          Remove a given listener object from the service.
 void requestChat(java.lang.String peerID, java.lang.String emailAddress, java.lang.String displayName, pawn.services.chat.ChatListener listener)
          Send a request to chat to the peer specified.
 int startApp(java.lang.String[] args)
          Start the service.
 void stopApp()
          Stop the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

refModuleSpecID

public static final java.lang.String refModuleSpecID
The Module Specification ID for the Chat service.

See Also:
Constant Field Values
Constructor Detail

ChatServiceImpl

public ChatServiceImpl()
Create a new ChatServiceImpl object.

Method Detail

addListener

public void addListener(pawn.services.chat.ChatListener listener)
Add a listener object to the service. When a new Initiate Chat Request or Response Message arrives, the service will notify each registered listener. This method is synchronized to prevent multiple threads from altering the set of registered listeners simultaneously.

Specified by:
addListener in interface ChatService
Parameters:
listener - the listener object to register with the service.

approveChat

public void approveChat(net.jxta.protocol.PipeAdvertisement pipeAdvertisement,
                        java.lang.String emailAddress,
                        java.lang.String displayName,
                        int queryID)
Approve a chat session.

Specified by:
approveChat in interface ChatService
Parameters:
pipeAdvertisement - the advertisement for the pipe that will be used to set up the chat session.
emailAddress - the emailAddress of the user associated with local peer.
displayName - the name of the user associated with the local peer.
queryID - the query ID to use to send to the Resolver Response Message containing the response, allowing the remote peer to match the response to an initial request.

getImplAdvertisement

public net.jxta.document.Advertisement getImplAdvertisement()
Returns the advertisement for this service. In this case, this is the ModuleImplAdvertisement passed in when the service was initialized.

Specified by:
getImplAdvertisement in interface net.jxta.service.Service
Returns:
the advertisement describing this service.

getInterface

public net.jxta.service.Service getInterface()
Returns an interface used to protect this service.

Specified by:
getInterface in interface net.jxta.service.Service
Returns:
the wrapper object to use to manipulate this service.

init

public void init(net.jxta.peergroup.PeerGroup group,
                 net.jxta.id.ID assignedID,
                 net.jxta.document.Advertisement implAdv)
          throws net.jxta.exception.PeerGroupException
Initialize the service.

Specified by:
init in interface net.jxta.platform.Module
Parameters:
group - the PeerGroup containing this service.
assignedID - the identifier for this service.
implAdv - the advertisement specifying this service.
Throws:
net.jxta.exception.PeerGroupException - is not thrown ever by this implementation.

processQuery

public net.jxta.protocol.ResolverResponseMsg processQuery(net.jxta.protocol.ResolverQueryMsg query)
                                                   throws java.io.IOException,
                                                          net.jxta.exception.NoResponseException,
                                                          net.jxta.exception.DiscardQueryException,
                                                          net.jxta.exception.ResendQueryException
Process a Resolver Query Message.

Specified by:
processQuery in interface net.jxta.resolver.QueryHandler
java.io.IOException
net.jxta.exception.NoResponseException
net.jxta.exception.DiscardQueryException
net.jxta.exception.ResendQueryException

processResponse

public void processResponse(net.jxta.protocol.ResolverResponseMsg response)
Process a Resolver response message.

Specified by:
processResponse in interface net.jxta.resolver.QueryHandler
Parameters:
response - a response message to be processed.

removeListener

public boolean removeListener(pawn.services.chat.ChatListener listener)
Remove a given listener object from the service. Once removed, a listener will no longer be notified when a new Initiate Chat Request or Response Message arrives. This method is synchronized to prevent multiple threads from altering the set of registered listeners simultaneously.

Specified by:
removeListener in interface ChatService
Parameters:
listener - the listener object to unregister.

requestChat

public void requestChat(java.lang.String peerID,
                        java.lang.String emailAddress,
                        java.lang.String displayName,
                        pawn.services.chat.ChatListener listener)
Send a request to chat to the peer specified.

Specified by:
requestChat in interface ChatService
Parameters:
peerID - the peerID of the remote peer to request for a chat session.
emailAddress - the email address of the user associated with the local peer.
displayName - the display name of the user associated with the local peer.
listener - the listener to notify when a response to this request is received.

startApp

public int startApp(java.lang.String[] args)
Start the service.

Specified by:
startApp in interface net.jxta.platform.Module
Parameters:
args - the arguments to the service. Not used.
Returns:
0 to indicate the service started.

stopApp

public void stopApp()
Stop the service.

Specified by:
stopApp in interface net.jxta.platform.Module