org.jgroups.demos
Class Draw

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

public class Draw
extends ReceiverAdapter
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_unicasts, java.lang.String name)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void channelClosed(Channel channel)
          Channel has been closed notification callback
 void channelConnected(Channel channel)
          Channel has been connected notification callback
 void channelDisconnected(Channel channel)
          Channel has been disconnected notification callback
 void clearPanel()
           
 java.lang.String getGroupName()
           
 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(java.io.InputStream istream)
          Allows an application to read a state through a provided InputStream.
 void stop()
           
 void viewAccepted(View v)
          Called when a change in membership has occurred.
 
Methods inherited from class org.jgroups.ReceiverAdapter
block, suspect, unblock
 
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_unicasts,
            java.lang.String name)
     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 class: ReceiverAdapter
Called when a message is received.

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

viewAccepted

public void viewAccepted(View v)
Description copied from class: ReceiverAdapter
Called when a change in membership has occurred. No long running actions, sending of messages or anything that could block 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 ReceiverAdapter

getState

public void getState(java.io.OutputStream ostream)
              throws java.lang.Exception
Description copied from class: ReceiverAdapter
Allows an application to write a state through a provided OutputStream. After the state has been written the OutputStream doesn't need to be closed as stream closing is automatically done when a calling thread returns from this callback.

Specified by:
getState in interface MessageListener
Overrides:
getState in class ReceiverAdapter
Parameters:
ostream - the OutputStream
Throws:
java.lang.Exception - if the streaming fails, any exceptions should be thrown so that the state requester can re-throw them and let the caller know what happened
See Also:
OutputStream.close()

setState

public void setState(java.io.InputStream istream)
              throws java.lang.Exception
Description copied from class: ReceiverAdapter
Allows an application to read a state through a provided InputStream. After the state has been read the InputStream doesn't need to be closed as stream closing is automatically done when a calling thread returns from this callback.

Specified by:
setState in interface MessageListener
Overrides:
setState in class ReceiverAdapter
Parameters:
istream - the InputStream
Throws:
java.lang.Exception - if the streaming fails, any exceptions should be thrown so that the state requester can catch them and thus know what happened
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)
Description copied from interface: ChannelListener
Channel has been connected notification callback

Specified by:
channelConnected in interface ChannelListener
Parameters:
channel - the channel that has been connected

channelDisconnected

public void channelDisconnected(Channel channel)
Description copied from interface: ChannelListener
Channel has been disconnected notification callback

Specified by:
channelDisconnected in interface ChannelListener
Parameters:
channel - the disconnected channel

channelClosed

public void channelClosed(Channel channel)
Description copied from interface: ChannelListener
Channel has been closed notification callback

Specified by:
channelClosed in interface ChannelListener
Parameters:
channel - the closed channel


Copyright © 1998-2012 Bela Ban / Red Hat. All Rights Reserved.