gozirra-ws/src/main/java/com/hi3project/vineyard/comm/stomp/gozirraws/Server.java
protected void receive( Command c, Map h, String b, Authenticatable y ) {
    long id = (int)(Math.random() * 10000);
    try {
      // Convert to MESSAGE and distribute
      if (c == Command.COMMIT) {
        synchronized (_transactions) {
          List trans = (List)_transactions.remove(y);
          trans = new ArrayList( trans );
          for (Iterator i=trans.iterator(); i.hasNext(); ) {
            Message m = (Message)i.next();
            try {
              receive( m.command(), m.headers(), m.body(), y );
            } catch (Exception e) {
              // Don't allow listener code to break us
            }
          }
        }

      } else if (c == Command.ABORT) {
        synchronized (_transactions) {
          _transactions.remove(y);
        }

      } else if (_transactions.get( y ) != null) {
        synchronized (_transactions) {
          ((List)_transactions.get( y )).add( new Message( c, h, b ) );
        }

      } else {
        if (h == null) h = new HashMap();
        String destination = (String)h.get("destination");
        if (c == Command.SEND) {
          if (y instanceof IntraVMClient ||
              _authenticator.authorizeSend( y.token(), destination )) {
            synchronized( _listeners ) {
              List l = (List)_listeners.get( destination );
              if (l != null) {
                l = new ArrayList(l);
                for (Iterator i = l.iterator(); i.hasNext(); ) {
                  Listener sh = (Listener)i.next();
                  try {
                    sh.message( h, b );
                  } catch (Exception e) {
                    // Don't allow listener code to break us
                  }
                }
              } 
            }
          } else {
            Map error_headers = new HashMap();
            error_headers.put( "message:", "authorization refused");
            error_headers.put( "type:", "send");
            error_headers.put( "channel:", destination);
            y.error( error_headers, "The message:\n-----\n"+b+
                "\n-----\nAuthentication token refused for this channel");
          }

        } else if (c == Command.SUBSCRIBE) {
          if (y instanceof IntraVMClient ||
              _authenticator.authorizeSubscribe( y.token(), destination )) {
            synchronized (_listeners ) {
              List l = (List)_listeners.get( destination );
              if (l == null) {
                l = new ArrayList();
                _listeners.put( destination, l );
              }
              if (!l.contains(y)) l.add( y );
            }
          } else {
            Map error_headers = new HashMap();
            error_headers.put( "message:", "authorization refused");
            error_headers.put( "type:", "subscription");
            error_headers.put( "channel:", destination);
            y.error( error_headers, "The message:\n-----\n"+b+
                "\n-----\nAuthentication token refused for this channel");
          }

        } else if (c == Command.UNSUBSCRIBE) {
          synchronized (_listeners) {
            List l = (List)_listeners.get( destination );
            if (l != null) l.remove( y );
          }

        } else if (c == Command.BEGIN) {
          synchronized (_transactions) {
            List trans = new ArrayList();
            _transactions.put( y, trans );
          }

        } else if (c == Command.DISCONNECT) {
          synchronized (_listeners) {
            for (Iterator i=_listeners.values().iterator(); i.hasNext(); ) {
              List l = (List)i.next();
              l.remove( y );
            }
          }
        }
      }
      if (h != null) {
        String receipt = (String)h.get("receipt");
        if (receipt != null) {
          HashMap headers = new HashMap();
          headers.put( "receipt-id", receipt );
          y.receive( Command.RECEIPT, headers, null );
        }
      }
    } catch (Exception e) {
      // Don't allow listener code to break us
    }
  }
protected void receive( Command c, Map h, String b, Authenticatable y ) {
    long id = (int)(Math.random() * 10000);
    try {
      // Convert to MESSAGE and distribute
      if (c == Command.COMMIT) {
        synchronized (_transactions) {
          List trans = (List)_transactions.remove(y);
          trans = new ArrayList( trans );
          for (Iterator i=trans.iterator(); i.hasNext(); ) {
            Message m = (Message)i.next();
            try {
              receive( m.command(), m.headers(), m.body(), y );
            } catch (Exception e) {
              // Don't allow listener code to break us
            }
          }
        }

      } else if (c == Command.ABORT) {
        synchronized (_transactions) {
          _transactions.remove(y);
        }

      } else if (_transactions.get( y ) != null) {
        synchronized (_transactions) {
          ((List)_transactions.get( y )).add( new Message( c, h, b ) );
        }

      } else {
        if (h == null) h = new HashMap();
        String destination = (String)h.get("destination");
        if (c == Command.SEND) {
          if (y instanceof IntraVMClient ||
              _authenticator.authorizeSend( y.token(), destination )) {
            synchronized( _listeners ) {
              List l = (List)_listeners.get( destination );
              if (l != null) {
                l = new ArrayList(l);
                for (Iterator i = l.iterator(); i.hasNext(); ) {
                  Listener sh = (Listener)i.next();
                  try {
                    sh.message( h, b );
                  } catch (Exception e) {
                    // Don't allow listener code to break us
                  }
                }
              } 
            }
          } else {
            Map error_headers = new HashMap();
            error_headers.put( "message:", "authorization refused");
            error_headers.put( "type:", "send");
            error_headers.put( "channel:", destination);
            y.error( error_headers, "The message:\n-----\n"+b+
                "\n-----\nAuthentication token refused for this channel");
          }

        } else if (c == Command.SUBSCRIBE) {
          if (y instanceof IntraVMClient ||
              _authenticator.authorizeSubscribe( y.token(), destination )) {
            synchronized (_listeners ) {
              List l = (List)_listeners.get( destination );
              if (l == null) {
                l = new ArrayList();
                _listeners.put( destination, l );
              }
              if (!l.contains(y)) l.add( y );
            }
          } else {
            Map error_headers = new HashMap();
            error_headers.put( "message:", "authorization refused");
            error_headers.put( "type:", "subscription");
            error_headers.put( "channel:", destination);
            y.error( error_headers, "The message:\n-----\n"+b+
                "\n-----\nAuthentication token refused for this channel");
          }

        } else if (c == Command.UNSUBSCRIBE) {
          synchronized (_listeners) {
            List l = (List)_listeners.get( destination );
            if (l != null) l.remove( y );
          }

        } else if (c == Command.BEGIN) {
          synchronized (_transactions) {
            List trans = new ArrayList();
            _transactions.put( y, trans );
          }

        } else if (c == Command.DISCONNECT) {
          synchronized (_listeners) {
            for (Iterator i=_listeners.values().iterator(); i.hasNext(); ) {
              List l = (List)i.next();
              l.remove( y );
            }
          }
        }
      }
      if (h != null) {
        String receipt = (String)h.get("receipt");
        if (receipt != null) {
          HashMap headers = new HashMap();
          headers.put( "receipt-id", receipt );
          y.receive( Command.RECEIPT, headers, null );
        }
      }
    } catch (Exception e) {
      // Don't allow listener code to break us
    }
  }
Incoming mesages from clients come here, and are delivered to listeners,
both intra-VM and network.

@param c the command
@param h the headers
@param b the message
@param y the thing that received the message and passed it to us