Class Channel


  extended by Object
      extended by Channel

public class Channel
extends Object

This class represents messaging channel. Channel offers no persistence, it merely performs as communication hub.

After the channel has been initially obtained it is on OPENED state. At the opened state it can be either joined or closed. At this state the member list represents the set of members at the time of opening.

After channel has been joined with join(Value, int, MemberCallback, MessageCallback) method it is on JOINED state. At the joined state it can be left or closed. At this state the member list is "live" and will be updated when necessary. The MemberCallback is used to notify the changes to widget.

When channel is closed with close() method it is no longer useable and new instance must be obtained.

Since:
2.0.0
See Also:
openChannel(String, ChannelCallback), openChannel(String, String, Value, int, ChannelCallback), openPrivateChannel(String, Value, int, ChannelCallback)

Method Summary
 void broadcast(String command, Value argument)
          Broadcast a message to all participants on this channel.
 void close()
          Closes this channel.
 Value getInfo()
          Returns the free info structure associated with this channel.
 Member getMember()
          Returns the member representing this widget's membership on the channel.
 Member getMember(String id)
          Returns the member with specified id.
 List getMembers()
          Returns the list of members on this channel.
 String getName()
          Returns the name of channel.
 String getProtocol()
          Returns the name of "protocol" used on this channel.
 void join(Value info, int timeout, MemberCallback memberCallback, MessageCallback messageCallback)
          Joins this channel, updating the member list.
 void leave()
          Leaves this channel.
 void setInfo(Value info)
          Sets new info structure for this channel.
 void update(Value info)
          Sets info structure of Member representing this widget instance.
 
Methods inherited from class Object
toString, equals, hashCode
 
Methods inherited from
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getName

public String getName()
Returns the name of channel.

Since:
2.0.0

getProtocol

public String getProtocol()
Returns the name of "protocol" used on this channel.

Since:
2.0.0

getInfo

public Value getInfo()
Returns the free info structure associated with this channel.

Since:
2.0.0

setInfo

public void setInfo(Value info)
Sets new info structure for this channel. Change will be notified to all members.

Parameters:
info - New context dependent info structure.
Since:
2.0.0

getMembers

public List getMembers()
Returns the list of members on this channel.

Returns:
List containing Members.
Since:
2.0.0

getMember

public Member getMember()
Returns the member representing this widget's membership on the channel.

Returns:
Member, or null if channel hasn't been joined yet.
Since:
2.0.0

getMember

public Member getMember(String id)
Returns the member with specified id.

Parameters:
id - Member id
Returns:
Member, or null if there is no such member.
Since:
2.0.0

broadcast

public void broadcast(String command,
                      Value argument)
Broadcast a message to all participants on this channel. This message will not be send to originator. Channel must be joined before using the operation.

Parameters:
command - Name of command
argument - Command argument
Since:
2.0.0

join

public void join(Value info,
                 int timeout,
                 MemberCallback memberCallback,
                 MessageCallback messageCallback)
Joins this channel, updating the member list.

Parameters:
info - Free info structure this member
timeout - Timeout in seconds after which this member will be removed if client has gone offline. Note that actual effective timeout can be slightly larger than number provided here.
memberCallback - Callback for handling the changes on membership
messageCallback - Callback for handling the incoming messages
Since:
2.0.0

update

public void update(Value info)
Sets info structure of Member representing this widget instance. Change will be notified to all channel participants. Channel must be joined before using the operation.

Parameters:
info - Info structure
Since:
2.0.0

leave

public void leave()
Leaves this channel. Channel must be joined before using the operation.

Since:
2.0.0

close

public void close()
Closes this channel. After closing the channel instance is no longer useable and new instance must be acquired.

Since:
2.0.0