org.jgroups.demos
Class Draw

java.lang.Object
  extended by org.jgroups.ExtendedReceiverAdapter
      extended by org.jgroups.demos.Draw
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, ChannelListener, ExtendedMembershipListener, ExtendedMessageListener, ExtendedReceiver, MembershipListener, MessageListener, Receiver

public class Draw
extends ExtendedReceiverAdapter
implements java.awt.event.ActionListener, ChannelListener

Shared whiteboard, each new instance joins the same group. Each instance chooses a random color, mouse moves are broadcast to all group members, which then apply them to their canvas

Author:
Bela Ban, Oct 17 2001

Constructor Summary
Draw(Channel channel)
           
Draw(Channel channel, boolean use_state, long state_timeout)
           
Draw(java.lang.String props, boolean no_channel, boolean jmx, boolean use_state, long state_timeout, boolean use_blocking)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void block()
          Called (usually by the FLUSH protocol), as an indication that the member should stop sending messages.
 void channelClosed(Channel channel)
           
 void channelConnected(Channel channel)
           
 void channelDisconnected(Channel channel)
           
 void channelReconnected(Address addr)
           
 void channelShunned()
           
 void clearPanel()
           
 java.lang.String getGroupName()
           
 byte[] getState()
          Answers the group state; e.g., when joining.
 void getState(java.io.OutputStream ostream)
          Allows an application to write a state through a provided OutputStream.
 void go()
           
static void main(java.lang.String[] args)
           
 void receive(Message msg)
          Called when a message is received.
 void sendClearPanelMsg()
           
 void setGroupName(java.lang.String groupname)
           
 void setState(byte[] state)
          Sets the group state; e.g., when joining.
 void setState(java.io.InputStream istream)
          Allows an application to read a state through a provided InputStream.
 void stop()
           
 void unblock()
          Called after the FLUSH protocol has unblocked previously blocked senders, and messages can be sent again.
 void viewAccepted(View v)
          Called when a change in membership has occurred.
 
Methods inherited from class org.jgroups.ExtendedReceiverAdapter
getState, getState, setState, setState, suspect
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Draw

public Draw(java.lang.String props,
            boolean no_channel,
            boolean jmx,
            boolean use_state,
            long state_timeout,
            boolean use_blocking)
     throws java.lang.Exception
Throws:
java.lang.Exception

Draw

public Draw(Channel channel)
     throws java.lang.Exception
Throws:
java.lang.Exception

Draw

public Draw(Channel channel,
            boolean use_state,
            long state_timeout)
     throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

getGroupName

public java.lang.String getGroupName()

setGroupName

public void setGroupName(java.lang.String groupname)

main

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

go

public void go()
        throws java.lang.Exception
Throws:
java.lang.Exception

receive

public void receive(Message msg)
Description copied from interface: MessageListener
Called when a message is received.

Specified by:
receive in interface MessageListener
Overrides:
receive in class ExtendedReceiverAdapter

viewAccepted

public void viewAccepted(View v)
Description copied from interface: MembershipListener
Called when a change in membership has occurred. No long running actions or sending of messages should be done in this callback. If some long running action needs to be performed, it should be done in a separate thread.

Note that on reception of the first view (a new member just joined), the channel will not yet be in the connected state. This only happens when Channel.connect(String) returns.

Specified by:
viewAccepted in interface MembershipListener
Overrides:
viewAccepted in class ExtendedReceiverAdapter

block

public void block()
Description copied from interface: MembershipListener
Called (usually by the FLUSH protocol), as an indication that the member should stop sending messages. Any messages sent after returning from this callback might get blocked by the FLUSH protocol. When the FLUSH protocol is done, and messages can be sent again, the FLUSH protocol will simply unblock all pending messages. If a callback for unblocking is desired, implement ExtendedMembershipListener.unblock(). Note that block() is the equivalent of reception of a BlockEvent in the pull mode.

Specified by:
block in interface MembershipListener
Overrides:
block in class ExtendedReceiverAdapter

unblock

public void unblock()
Description copied from interface: ExtendedMembershipListener
Called after the FLUSH protocol has unblocked previously blocked senders, and messages can be sent again. This callback only needs to be implemented if we require a notification of that.

Specified by:
unblock in interface ExtendedMembershipListener
Overrides:
unblock in class ExtendedReceiverAdapter

getState

public byte[] getState()
Description copied from interface: MessageListener
Answers the group state; e.g., when joining.

Specified by:
getState in interface MessageListener
Overrides:
getState in class ExtendedReceiverAdapter
Returns:
byte[]

setState

public void setState(byte[] state)
Description copied from interface: MessageListener
Sets the group state; e.g., when joining.

Specified by:
setState in interface MessageListener
Overrides:
setState in class ExtendedReceiverAdapter

getState

public void getState(java.io.OutputStream ostream)
Description copied from interface: ExtendedMessageListener
Allows an application to write a state through a provided OutputStream. An application is obligated to always close the given OutputStream reference.

Specified by:
getState in interface ExtendedMessageListener
Overrides:
getState in class ExtendedReceiverAdapter
Parameters:
ostream - the OutputStream
See Also:
OutputStream.close()

setState

public void setState(java.io.InputStream istream)
Description copied from interface: ExtendedMessageListener
Allows an application to read a state through a provided InputStream. An application is obligated to always close the given InputStream reference.

Specified by:
setState in interface ExtendedMessageListener
Overrides:
setState in class ExtendedReceiverAdapter
Parameters:
istream - the InputStream
See Also:
InputStream.close()

clearPanel

public void clearPanel()

sendClearPanelMsg

public void sendClearPanelMsg()

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

stop

public void stop()

channelConnected

public void channelConnected(Channel channel)
Specified by:
channelConnected in interface ChannelListener

channelDisconnected

public void channelDisconnected(Channel channel)
Specified by:
channelDisconnected in interface ChannelListener

channelClosed

public void channelClosed(Channel channel)
Specified by:
channelClosed in interface ChannelListener

channelShunned

public void channelShunned()
Specified by:
channelShunned in interface ChannelListener

channelReconnected

public void channelReconnected(Address addr)
Specified by:
channelReconnected in interface ChannelListener


Copyright ? 1998-2008 Bela Ban. All Rights Reserved.