Package org.jgroups.demos
Class Draw
- java.lang.Object
-
- org.jgroups.demos.Draw
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.util.EventListener,ChannelListener,Receiver
public class Draw extends java.lang.Object implements Receiver, 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classDraw.DrawPanel
-
Field Summary
Fields Modifier and Type Field Description private static java.awt.Colorbackground_colorprivate JChannelchannelprivate javax.swing.JButtonclear_buttonprotected java.lang.Stringcluster_nameprivate java.awt.Colordraw_color(package private) booleanjmxprivate javax.swing.JButtonleave_buttonprivate javax.swing.JFramemainFrameprivate intmember_sizeprivate java.util.List<Address>members(package private) booleanno_channelprivate Draw.DrawPanelpanelprivate java.util.Randomrandomprotected booleansend_own_state_on_mergeprivate longstate_timeoutprivate javax.swing.JPanelsub_panelprivate booleanuse_stateprivate booleanuse_unicasts
-
Constructor Summary
Constructors Constructor Description Draw(java.lang.String props, boolean no_channel, boolean jmx, boolean use_state, long state_timeout, boolean use_unicasts, java.lang.String name, boolean send_own_state_on_merge, AddressGenerator gen)Draw(JChannel channel)Draw(JChannel channel, boolean use_state, long state_timeout)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(java.awt.event.ActionEvent e)voidchannelConnected(JChannel channel)Channel has been connected notification callbackvoidchannelDisconnected(JChannel channel)Channel has been disconnected notification callbackvoidclearPanel()java.lang.StringgetClusterName()voidgetState(java.io.OutputStream ostream)Allows an application to write the state to an OutputStream.voidgo()(package private) static voidhelp()static voidmain(java.lang.String[] args)voidreceive(Message msg)Called when a message is received.private java.awt.ColorselectColor()voidsendClearPanelMsg()protected voidsendOwnState(java.util.Map<java.awt.Point,java.awt.Color> copy)private voidsendToAll(byte[] buf)voidsetClusterName(java.lang.String clustername)voidsetState(java.io.InputStream istream)Allows an application to read the state from an InputStream.(package private) voidsetTitle()(package private) voidsetTitle(java.lang.String title)voidstop()voidviewAccepted(View v)Called when a change in membership has occurred.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jgroups.ChannelListener
channelClosed
-
-
-
-
Field Detail
-
cluster_name
protected java.lang.String cluster_name
-
channel
private JChannel channel
-
member_size
private int member_size
-
mainFrame
private javax.swing.JFrame mainFrame
-
sub_panel
private javax.swing.JPanel sub_panel
-
panel
private Draw.DrawPanel panel
-
clear_button
private javax.swing.JButton clear_button
-
leave_button
private javax.swing.JButton leave_button
-
random
private final java.util.Random random
-
draw_color
private final java.awt.Color draw_color
-
background_color
private static final java.awt.Color background_color
-
no_channel
boolean no_channel
-
jmx
boolean jmx
-
use_state
private boolean use_state
-
state_timeout
private long state_timeout
-
use_unicasts
private boolean use_unicasts
-
send_own_state_on_merge
protected boolean send_own_state_on_merge
-
members
private final java.util.List<Address> members
-
-
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, boolean send_own_state_on_merge, AddressGenerator gen) throws java.lang.Exception- Throws:
java.lang.Exception
-
Draw
public Draw(JChannel channel) throws java.lang.Exception
- Throws:
java.lang.Exception
-
Draw
public Draw(JChannel channel, boolean use_state, long state_timeout) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-
Method Detail
-
getClusterName
public java.lang.String getClusterName()
-
setClusterName
public void setClusterName(java.lang.String clustername)
-
main
public static void main(java.lang.String[] args)
-
help
static void help()
-
selectColor
private java.awt.Color selectColor()
-
sendToAll
private void sendToAll(byte[] buf) throws java.lang.Exception- Throws:
java.lang.Exception
-
go
public void go() throws java.lang.Exception- Throws:
java.lang.Exception
-
setTitle
void setTitle(java.lang.String title)
-
setTitle
void setTitle()
-
receive
public void receive(Message msg)
Description copied from interface:ReceiverCalled when a message is received.
-
viewAccepted
public void viewAccepted(View v)
Description copied from interface:ReceiverCalled 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 whenJChannel.connect(String)returns.- Specified by:
viewAcceptedin interfaceReceiver
-
getState
public void getState(java.io.OutputStream ostream) throws java.lang.ExceptionDescription copied from interface:ReceiverAllows an application to write the state to an 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.
-
setState
public void setState(java.io.InputStream istream) throws java.lang.ExceptionDescription copied from interface:ReceiverAllows an application to read the state from an 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.
-
clearPanel
public void clearPanel()
-
sendClearPanelMsg
public void sendClearPanelMsg()
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
- Specified by:
actionPerformedin interfacejava.awt.event.ActionListener
-
stop
public void stop()
-
sendOwnState
protected void sendOwnState(java.util.Map<java.awt.Point,java.awt.Color> copy)
-
channelConnected
public void channelConnected(JChannel channel)
Description copied from interface:ChannelListenerChannel has been connected notification callback- Specified by:
channelConnectedin interfaceChannelListener- Parameters:
channel- the channel that has been connected
-
channelDisconnected
public void channelDisconnected(JChannel channel)
Description copied from interface:ChannelListenerChannel has been disconnected notification callback- Specified by:
channelDisconnectedin interfaceChannelListener- Parameters:
channel- the disconnected channel
-
-