Class Snooper


  • public class Snooper
    extends java.lang.Object
    Subscribes to SAMP messages and logs any received to an output stream. The only responses to messages have samp.status=samp.warning.
    Since:
    4 Sep 2008
    Author:
    Mark Taylor
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map clientMap_  
      private static java.util.logging.Logger logger_  
      private static byte[] newline_  
      private java.io.OutputStream out_  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Metadata createDefaultMetadata()
      Returns the default metadata for the Snooper client.
      private void log​(java.lang.String senderId, Message msg, java.lang.String msgId)
      Logs a received message.
      static void main​(java.lang.String[] args)
      Main method.
      static int runMain​(java.lang.String[] args)
      Does the work for the main method.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • out_

        private final java.io.OutputStream out_
      • clientMap_

        private final java.util.Map clientMap_
      • newline_

        private static final byte[] newline_
      • logger_

        private static final java.util.logging.Logger logger_
    • Constructor Detail

      • Snooper

        public Snooper​(ClientProfile profile,
                       Subscriptions subs,
                       java.io.OutputStream out,
                       int autoSec)
        Constructor using default metadata.
        Parameters:
        profile - profile
        subs - subscriptions defining which messages are received and logged
        out - destination stream for logging info
        autoSec - number of seconds between auto connection attempts
      • Snooper

        public Snooper​(ClientProfile profile,
                       Subscriptions subs,
                       Metadata meta,
                       java.io.OutputStream out,
                       int autoSec)
        Constructor using custom metadata.
        Parameters:
        profile - profile
        subs - subscriptions defining which messages are received and logged
        meta - client metadata
        out - destination stream for logging info
        autoSec - number of seconds between auto connection attempts
    • Method Detail

      • log

        private void log​(java.lang.String senderId,
                         Message msg,
                         java.lang.String msgId)
                  throws java.io.IOException
        Logs a received message.
        Parameters:
        senderId - message sender public ID
        msg - message object
        msgId - message ID for call/response type messages (null for notify type messages)
        Throws:
        java.io.IOException
      • createDefaultMetadata

        public static Metadata createDefaultMetadata()
        Returns the default metadata for the Snooper client.
        Returns:
        meta
      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException
        Main method. Runs a snooper.
        Throws:
        java.io.IOException
      • runMain

        public static int runMain​(java.lang.String[] args)
                           throws java.io.IOException
        Does the work for the main method. Use -help flag.
        Throws:
        java.io.IOException