Package jadex.platform.service.chat
Class ChatService
- java.lang.Object
-
- jadex.platform.service.chat.ChatService
-
- All Implemented Interfaces:
IChatGuiService
,IChatService
public class ChatService extends java.lang.Object implements IChatService, IChatGuiService
Chat service implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ChatService.PropProvider
-
Field Summary
Fields Modifier and Type Field Description protected IInternalAccess
agent
The agent.protected byte[]
image
The image.protected java.lang.String
nick
The local nick name.protected boolean
running
Flag to avoid duplicate initialization/shutdown due to duplicate use of implementation.protected java.lang.String
status
The current status (idle, typing, away).protected java.util.Set<SubscriptionIntermediateFuture<ChatEvent>>
subscribers
The futures of active subscribers.protected java.util.Map<java.lang.String,Tuple3<TransferInfo,TerminableIntermediateFuture<java.lang.Long>,IInputConnection>>
transfers
The currently managed file transfers.protected java.util.Map<java.lang.String,Tuple3<TransferInfo,ITerminableFuture<IOutputConnection>,IConnection>>
transfers2
-
Fields inherited from interface jadex.bridge.service.types.chat.IChatService
STATE_AWAY, STATE_DEAD, STATE_IDLE, STATE_TYPING
-
-
Constructor Summary
Constructors Constructor Description ChatService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IFuture<java.lang.Void>
acceptFile(java.lang.String id, java.lang.String filepath)
Accept a waiting file transfer.IFuture<java.lang.Void>
cancelTransfer(java.lang.String id)
Cancel an ongoing file transfer.protected void
doDownload(TransferInfo ti, TerminableIntermediateFuture<java.lang.Long> ret, IInputConnection con)
Perform a download.protected void
doUpload(TransferInfo ti, java.io.InputStream is, IOutputConnection ocon, IComponentIdentifier receiver)
Perform an upload.IIntermediateFuture<IChatService>
findUsers()
Search for available chat services.IIntermediateFuture<TransferInfo>
getFileTransfers()
Get a snapshot of the currently managed file transfers.IFuture<byte[]>
getImage()
Get the image.IFuture<java.lang.String>
getNickName()
Get the user name.IFuture<java.lang.String>
getStatus()
Get the current status.protected java.lang.String
getSubname()
Get the "semi-qualified" sub name for settings.IIntermediateFuture<IChatService>
message(java.lang.String text, IComponentIdentifier[] receivers, boolean self)
Post a message.IFuture<java.lang.Void>
message(java.lang.String nick, java.lang.String text, boolean privatemessage)
Post a messageprotected boolean
publishEvent(java.lang.String type, java.lang.String nick, IComponentIdentifier cid, java.lang.Object value)
Post an event to registered subscribers.protected boolean
publishEvent(java.lang.String type, java.lang.String nick, IComponentIdentifier cid, java.lang.Object value, boolean privatemessage, byte[] image)
Post an event to registered subscribers.IFuture<java.lang.Void>
rejectFile(java.lang.String id)
Reject a waiting file transfer.IFuture<java.lang.Void>
sendFile(java.lang.String fname, byte[] data, IComponentIdentifier cid)
Send a file to the target component via bytes.IFuture<java.lang.Void>
sendFile(java.lang.String filepath, IComponentIdentifier cid)
Send a local file to the target component.ITerminableIntermediateFuture<java.lang.Long>
sendFile(java.lang.String nick, java.lang.String filename, long size, java.lang.String id, IInputConnection con)
Send a file.protected IFuture<IChatService>
sendTo(java.lang.String text, IComponentIdentifier rec, boolean privatemessage)
Helper method for sending message to cid.IFuture<java.lang.Void>
setImage(byte[] image)
Set the image.IFuture<java.lang.Void>
setNickName(java.lang.String nick)
Set the user name.IFuture<java.lang.Void>
shutdown()
Called on shutdown.IFuture<java.lang.Void>
start()
Called on startup.ITerminableFuture<IOutputConnection>
startUpload(java.lang.String nick, java.lang.String filename, long size, java.lang.String id)
Send a file.IIntermediateFuture<IChatService>
status(java.lang.String status, byte[] image, IComponentIdentifier[] receivers)
Post a status change.IFuture<java.lang.Void>
status(java.lang.String nick, java.lang.String status, byte[] image)
Post a status change.protected IFuture<IChatService>
statusTo(java.lang.String nick, java.lang.String status, byte[] image, IComponentIdentifier rec)
Helper method for posting status to cid.ISubscriptionIntermediateFuture<ChatEvent>
subscribeToEvents()
Subscribe to events from the chat service.
-
-
-
Field Detail
-
agent
protected IInternalAccess agent
The agent.
-
subscribers
protected java.util.Set<SubscriptionIntermediateFuture<ChatEvent>> subscribers
The futures of active subscribers.
-
nick
protected java.lang.String nick
The local nick name.
-
status
protected java.lang.String status
The current status (idle, typing, away).
-
transfers
protected java.util.Map<java.lang.String,Tuple3<TransferInfo,TerminableIntermediateFuture<java.lang.Long>,IInputConnection>> transfers
The currently managed file transfers.
-
transfers2
protected java.util.Map<java.lang.String,Tuple3<TransferInfo,ITerminableFuture<IOutputConnection>,IConnection>> transfers2
-
running
protected boolean running
Flag to avoid duplicate initialization/shutdown due to duplicate use of implementation.
-
image
protected byte[] image
The image.
-
-
Method Detail
-
start
public IFuture<java.lang.Void> start()
Called on startup.
-
shutdown
public IFuture<java.lang.Void> shutdown()
Called on shutdown.
-
getSubname
protected java.lang.String getSubname()
Get the "semi-qualified" sub name for settings.
-
message
public IFuture<java.lang.Void> message(java.lang.String nick, java.lang.String text, boolean privatemessage)
Post a message- Specified by:
message
in interfaceIChatService
- Parameters:
text
- The text message.nick
- The sender's nick name.
-
status
public IFuture<java.lang.Void> status(java.lang.String nick, java.lang.String status, byte[] image)
Post a status change.- Specified by:
status
in interfaceIChatService
- Parameters:
status
- The new status.nick
- The (possibly changed) nick name.image
- The new image or null for no change.
-
getStatus
public IFuture<java.lang.String> getStatus()
Get the current status.- Specified by:
getStatus
in interfaceIChatService
-
sendFile
public ITerminableIntermediateFuture<java.lang.Long> sendFile(java.lang.String nick, java.lang.String filename, long size, java.lang.String id, IInputConnection con)
Send a file.- Specified by:
sendFile
in interfaceIChatService
- Parameters:
nick
- The sender's nick name.filename
- The filename.size
- The size of the file.id
- An optional id to identify the transfer (e.g. for resume after error).con
- The connection.- Returns:
- The returned future publishes updates about the total number of bytes received. Exception messages of the returned future correspond to file transfer states (aborted vs. error vs. rejected).
-
startUpload
public ITerminableFuture<IOutputConnection> startUpload(java.lang.String nick, java.lang.String filename, long size, java.lang.String id)
Send a file. Alternative method signature.- Specified by:
startUpload
in interfaceIChatService
- Parameters:
nick
- The sender's nick name.filename
- The filename.size
- The size of the file.id
- An optional id to identify the transfer (e.g. for resume after error).- Returns:
- When the upload is accepted, the output connection for sending the file is returned.
-
setNickName
public IFuture<java.lang.Void> setNickName(java.lang.String nick)
Set the user name.- Specified by:
setNickName
in interfaceIChatGuiService
-
getNickName
public IFuture<java.lang.String> getNickName()
Get the user name.- Specified by:
getNickName
in interfaceIChatGuiService
- Specified by:
getNickName
in interfaceIChatService
-
setImage
public IFuture<java.lang.Void> setImage(byte[] image)
Set the image.- Specified by:
setImage
in interfaceIChatGuiService
-
getImage
public IFuture<byte[]> getImage()
Get the image.- Specified by:
getImage
in interfaceIChatGuiService
- Specified by:
getImage
in interfaceIChatService
-
subscribeToEvents
public ISubscriptionIntermediateFuture<ChatEvent> subscribeToEvents()
Subscribe to events from the chat service.- Specified by:
subscribeToEvents
in interfaceIChatGuiService
- Returns:
- A future publishing chat events as intermediate results.
-
findUsers
public IIntermediateFuture<IChatService> findUsers()
Search for available chat services.- Specified by:
findUsers
in interfaceIChatGuiService
- Returns:
- The currently available remote services.
-
message
public IIntermediateFuture<IChatService> message(java.lang.String text, IComponentIdentifier[] receivers, boolean self)
Post a message. Searches for available chat services and posts the message to all.- Specified by:
message
in interfaceIChatGuiService
- Parameters:
text
- The text message.receivers
- The receivers the message should be sent to.self
- Flag if message should also be sent to service itself.- Returns:
- The remote services, to which the message was successfully posted.
-
sendTo
protected IFuture<IChatService> sendTo(java.lang.String text, IComponentIdentifier rec, boolean privatemessage)
Helper method for sending message to cid.
-
status
public IIntermediateFuture<IChatService> status(java.lang.String status, byte[] image, IComponentIdentifier[] receivers)
Post a status change.- Specified by:
status
in interfaceIChatGuiService
- Parameters:
status
- The new status or null for no change.image
- The new avatar image or null for no change.receivers
- The receivers.
-
statusTo
protected IFuture<IChatService> statusTo(java.lang.String nick, java.lang.String status, byte[] image, IComponentIdentifier rec)
Helper method for posting status to cid.
-
getFileTransfers
public IIntermediateFuture<TransferInfo> getFileTransfers()
Get a snapshot of the currently managed file transfers.- Specified by:
getFileTransfers
in interfaceIChatGuiService
-
acceptFile
public IFuture<java.lang.Void> acceptFile(java.lang.String id, java.lang.String filepath)
Accept a waiting file transfer.- Specified by:
acceptFile
in interfaceIChatGuiService
- Parameters:
id
- The transfer id.filepath
- The location of the file (possibly changed by user).
-
rejectFile
public IFuture<java.lang.Void> rejectFile(java.lang.String id)
Reject a waiting file transfer.- Specified by:
rejectFile
in interfaceIChatGuiService
- Parameters:
id
- The transfer id.
-
cancelTransfer
public IFuture<java.lang.Void> cancelTransfer(java.lang.String id)
Cancel an ongoing file transfer.- Specified by:
cancelTransfer
in interfaceIChatGuiService
- Parameters:
id
- The transfer id.
-
sendFile
public IFuture<java.lang.Void> sendFile(java.lang.String filepath, IComponentIdentifier cid)
Send a local file to the target component.- Specified by:
sendFile
in interfaceIChatGuiService
- Parameters:
filepath
- The file path, local to the chat component.cid
- The id of a remote chat component.
-
sendFile
public IFuture<java.lang.Void> sendFile(java.lang.String fname, byte[] data, IComponentIdentifier cid)
Send a file to the target component via bytes.- Specified by:
sendFile
in interfaceIChatGuiService
- Parameters:
filepath
- The file path, local to the chat component.cid
- The id of a remote chat component.
-
publishEvent
protected boolean publishEvent(java.lang.String type, java.lang.String nick, IComponentIdentifier cid, java.lang.Object value)
Post an event to registered subscribers.- Parameters:
type
- The event type.nick
- The nick name.cid
- The component ID.value
- The event value.
-
publishEvent
protected boolean publishEvent(java.lang.String type, java.lang.String nick, IComponentIdentifier cid, java.lang.Object value, boolean privatemessage, byte[] image)
Post an event to registered subscribers.- Parameters:
type
- The event type.nick
- The nick name.cid
- The component ID.value
- The event value.
-
doDownload
protected void doDownload(TransferInfo ti, TerminableIntermediateFuture<java.lang.Long> ret, IInputConnection con)
Perform a download.
-
doUpload
protected void doUpload(TransferInfo ti, java.io.InputStream is, IOutputConnection ocon, IComponentIdentifier receiver)
Perform an upload. Called from file sender. Writes bytes from file input stream to output connection.
-
-