Class SocketFacade

  • All Implemented Interfaces:
    Serializable, Cloneable, weka.classifiers.Classifier, weka.core.BatchPredictor, weka.core.CapabilitiesHandler, weka.core.CapabilitiesIgnorer, weka.core.CommandlineRunnable, weka.core.OptionHandler, weka.core.RevisionHandler

    public class SocketFacade
    extends weka.classifiers.AbstractClassifier
    Uses sockets to communicate with a process for training and making predictions.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected adams.core.base.BaseHostname m_Local
      the return address for the remote process to use.
      protected AbstractDataPreparation m_Preparation
      the data preparation to use.
      protected adams.core.base.BaseHostname m_Remote
      the address of the remote process.
      protected ServerSocket m_Server
      the server socket for receiving the replies.
      protected boolean m_SkipTrain
      whether to skip training.
      protected int m_Timeout
      the timeout for the socket.
      • Fields inherited from class weka.classifiers.AbstractClassifier

        BATCH_SIZE_DEFAULT, m_BatchSize, m_Debug, m_DoNotCheckCapabilities, m_numDecimalPlaces, NUM_DECIMAL_PLACES_DEFAULT
    • Constructor Summary

      Constructors 
      Constructor Description
      SocketFacade()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void buildClassifier​(weka.core.Instances data)
      Generates a classifier.
      double classifyInstance​(weka.core.Instance instance)
      Generates a classification for the instance.
      protected void closeServer()
      Closes the server socket if necessary.
      double[] distributionForInstance​(weka.core.Instance instance)
      Generates a class distribution for the instance.
      weka.core.Capabilities getCapabilities()
      Returns the Capabilities of this classifier.
      protected adams.core.base.BaseHostname getDefaultLocal()
      Returns the default address of the return address.
      protected AbstractDataPreparation getDefaultPreparation()
      Returns the default data preparation scheme to use.
      protected adams.core.base.BaseHostname getDefaultRemote()
      Returns the default address of the remote process.
      protected int getDefaultTimeout()
      The default timeout in milli-second.
      adams.core.base.BaseHostname getLocal()
      Returns the return address for the remote process to use.
      String[] getOptions()
      Gets the current settings of the classifier.
      AbstractDataPreparation getPreparation()
      Returns the data preparation scheme to use.
      adams.core.base.BaseHostname getRemote()
      Returns the address of the remote process.
      protected ServerSocket getServer()
      Returns the server socket, instantiates it if necessary.
      boolean getSkipTrain()
      Returns whether to skip training, eg when using a pre-built model.
      int getTimeout()
      Returns the timeout in milli-second to wait for new connections.
      String globalInfo()
      Returns a string describing this classifier.
      protected void initServer()
      Initializes the server socket if necessary.
      Enumeration listOptions()
      Returns an enumeration describing the available options.
      String localTipText()
      Returns the tip text for this property.
      String preparationTipText()
      Returns the tip text for this property.
      protected byte[] receive()
      Receives the response data.
      String remoteTipText()
      Returns the tip text for this property.
      protected byte[] send​(byte[] data)
      Sends the data to the remote host.
      void setLocal​(adams.core.base.BaseHostname value)
      Sets the return address for the remote process to use.
      void setOptions​(String[] options)
      Parses a given list of options.
      void setPreparation​(AbstractDataPreparation value)
      Sets the data preparation scheme to use.
      void setRemote​(adams.core.base.BaseHostname value)
      Sets address of the remote process.
      void setSkipTrain​(boolean value)
      Sets whether to skip training, eg when using a pre-built model.
      void setTimeout​(int value)
      Sets the timeout in milli-second to wait for new connections.
      String skipTrainTipText()
      Returns the tip text for this property.
      String timeoutTipText()
      Returns the tip text for this property.
      String toString()
      Just returns the commandline options.
      • Methods inherited from class weka.classifiers.AbstractClassifier

        batchSizeTipText, debugTipText, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, getRevision, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, postExecution, preExecution, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces
    • Field Detail

      • m_Remote

        protected adams.core.base.BaseHostname m_Remote
        the address of the remote process.
      • m_Local

        protected adams.core.base.BaseHostname m_Local
        the return address for the remote process to use.
      • m_Timeout

        protected int m_Timeout
        the timeout for the socket.
      • m_SkipTrain

        protected boolean m_SkipTrain
        whether to skip training.
      • m_Server

        protected transient ServerSocket m_Server
        the server socket for receiving the replies.
    • Constructor Detail

      • SocketFacade

        public SocketFacade()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing this classifier.
        Returns:
        a description of the classifier suitable for displaying in the explorer/experimenter gui
      • listOptions

        public Enumeration listOptions()
        Returns an enumeration describing the available options.
        Specified by:
        listOptions in interface weka.core.OptionHandler
        Overrides:
        listOptions in class weka.classifiers.AbstractClassifier
        Returns:
        an enumeration of all the available options.
      • setOptions

        public void setOptions​(String[] options)
                        throws Exception
        Parses a given list of options.
        Specified by:
        setOptions in interface weka.core.OptionHandler
        Overrides:
        setOptions in class weka.classifiers.AbstractClassifier
        Parameters:
        options - the list of options as an array of strings
        Throws:
        Exception - if an option is not supported
      • getOptions

        public String[] getOptions()
        Gets the current settings of the classifier.
        Specified by:
        getOptions in interface weka.core.OptionHandler
        Overrides:
        getOptions in class weka.classifiers.AbstractClassifier
        Returns:
        an array of strings suitable for passing to setOptions
      • getDefaultRemote

        protected adams.core.base.BaseHostname getDefaultRemote()
        Returns the default address of the remote process.
        Returns:
        the default
      • setRemote

        public void setRemote​(adams.core.base.BaseHostname value)
        Sets address of the remote process.
        Parameters:
        value - the address
      • getRemote

        public adams.core.base.BaseHostname getRemote()
        Returns the address of the remote process.
        Returns:
        the address
      • remoteTipText

        public String remoteTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • getDefaultLocal

        protected adams.core.base.BaseHostname getDefaultLocal()
        Returns the default address of the return address.
        Returns:
        the default
      • setLocal

        public void setLocal​(adams.core.base.BaseHostname value)
        Sets the return address for the remote process to use.
        Parameters:
        value - the address
      • getLocal

        public adams.core.base.BaseHostname getLocal()
        Returns the return address for the remote process to use.
        Returns:
        the address
      • localTipText

        public String localTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • getDefaultTimeout

        protected int getDefaultTimeout()
        The default timeout in milli-second.
        Returns:
        the default
      • setTimeout

        public void setTimeout​(int value)
        Sets the timeout in milli-second to wait for new connections.
        Parameters:
        value - the timeout in msec
      • getTimeout

        public int getTimeout()
        Returns the timeout in milli-second to wait for new connections.
        Returns:
        the timeout in msec
      • timeoutTipText

        public String timeoutTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the gui
      • getDefaultPreparation

        protected AbstractDataPreparation getDefaultPreparation()
        Returns the default data preparation scheme to use.
        Returns:
        the default
      • setPreparation

        public void setPreparation​(AbstractDataPreparation value)
        Sets the data preparation scheme to use.
        Parameters:
        value - the scheme
      • getPreparation

        public AbstractDataPreparation getPreparation()
        Returns the data preparation scheme to use.
        Returns:
        the scheme
      • preparationTipText

        public String preparationTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • setSkipTrain

        public void setSkipTrain​(boolean value)
        Sets whether to skip training, eg when using a pre-built model.
        Parameters:
        value - true if to skip training
      • getSkipTrain

        public boolean getSkipTrain()
        Returns whether to skip training, eg when using a pre-built model.
        Returns:
        true if to skip training
      • skipTrainTipText

        public String skipTrainTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • initServer

        protected void initServer()
                           throws Exception
        Initializes the server socket if necessary.
        Throws:
        Exception - if initialization fails
      • closeServer

        protected void closeServer()
        Closes the server socket if necessary.
      • getServer

        protected ServerSocket getServer()
                                  throws Exception
        Returns the server socket, instantiates it if necessary.
        Returns:
        the socket
        Throws:
        Exception - if binding of socket fails
      • receive

        protected byte[] receive()
                          throws Exception
        Receives the response data.
        Returns:
        the received data
        Throws:
        Exception - if fails to receive data
      • send

        protected byte[] send​(byte[] data)
                       throws Exception
        Sends the data to the remote host.
        Parameters:
        data - the data to send
        Returns:
        the response data
        Throws:
        Exception - if sending fails
      • getCapabilities

        public weka.core.Capabilities getCapabilities()
        Returns the Capabilities of this classifier.
        Specified by:
        getCapabilities in interface weka.core.CapabilitiesHandler
        Specified by:
        getCapabilities in interface weka.classifiers.Classifier
        Overrides:
        getCapabilities in class weka.classifiers.AbstractClassifier
        Returns:
        the capabilities of this object
      • buildClassifier

        public void buildClassifier​(weka.core.Instances data)
                             throws Exception
        Generates a classifier.
        Parameters:
        data - set of instances serving as training data
        Throws:
        Exception - if the classifier has not been generated successfully
      • classifyInstance

        public double classifyInstance​(weka.core.Instance instance)
                                throws Exception
        Generates a classification for the instance.
        Specified by:
        classifyInstance in interface weka.classifiers.Classifier
        Overrides:
        classifyInstance in class weka.classifiers.AbstractClassifier
        Parameters:
        instance - the instance to classify
        Returns:
        the classification
        Throws:
        Exception - if classification failed
      • distributionForInstance

        public double[] distributionForInstance​(weka.core.Instance instance)
                                         throws Exception
        Generates a class distribution for the instance.
        Specified by:
        distributionForInstance in interface weka.classifiers.Classifier
        Overrides:
        distributionForInstance in class weka.classifiers.AbstractClassifier
        Parameters:
        instance - the instance to get the class distribution for
        Returns:
        the class distribution
        Throws:
        Exception - if class distribution fails
      • toString

        public String toString()
        Just returns the commandline options.
        Overrides:
        toString in class Object
        Returns:
        the commandline options