Class Draw

java.lang.Object
org.jgroups.demos.Draw
All Implemented Interfaces:
ActionListener, EventListener, ChannelListener, Receiver

public class Draw extends Object implements Receiver, 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
  • Field Details

    • cluster_name

      protected String cluster_name
    • channel

      private JChannel channel
    • member_size

      private int member_size
    • mainFrame

      private JFrame mainFrame
    • sub_panel

      private JPanel sub_panel
    • panel

      private Draw.DrawPanel panel
    • clear_button

      private JButton clear_button
    • leave_button

      private JButton leave_button
    • random

      private final Random random
    • draw_color

      private final Color draw_color
    • background_color

      private static final 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 List<Address> members
  • Constructor Details

  • Method Details

    • getClusterName

      public String getClusterName()
    • setClusterName

      public void setClusterName(String clustername)
    • main

      public static void main(String[] args)
    • help

      static void help()
    • selectColor

      private Color selectColor()
    • sendToAll

      private void sendToAll(byte[] buf) throws Exception
      Throws:
      Exception
    • go

      public void go() throws Exception
      Throws:
      Exception
    • setTitle

      void setTitle(String title)
    • setTitle

      void setTitle()
    • receive

      public void receive(Message msg)
      Description copied from interface: Receiver
      Called when a message is received.
      Specified by:
      receive in interface Receiver
      Parameters:
      msg - The message
    • viewAccepted

      public void viewAccepted(View v)
      Description copied from interface: Receiver
      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 JChannel.connect(String) returns.

      Specified by:
      viewAccepted in interface Receiver
    • getState

      public void getState(OutputStream ostream) throws Exception
      Description copied from interface: Receiver
      Allows 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.
      Specified by:
      getState in interface Receiver
      Parameters:
      ostream - The OutputStream
      Throws:
      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
    • setState

      public void setState(InputStream istream) throws Exception
      Description copied from interface: Receiver
      Allows 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.
      Specified by:
      setState in interface Receiver
      Parameters:
      istream - The InputStream
      Throws:
      Exception - If the streaming fails, any exceptions should be thrown so that the state requester can catch them and thus know what happened
    • clearPanel

      public void clearPanel()
    • sendClearPanelMsg

      public void sendClearPanelMsg()
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Specified by:
      actionPerformed in interface ActionListener
    • stop

      public void stop()
    • sendOwnState

      protected void sendOwnState(Map<Point,Color> copy)
    • channelConnected

      public void channelConnected(JChannel 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(JChannel channel)
      Description copied from interface: ChannelListener
      Channel has been disconnected notification callback
      Specified by:
      channelDisconnected in interface ChannelListener
      Parameters:
      channel - the disconnected channel