Package lcm.lcm

Class LCM


  • public class LCM
    extends java.lang.Object
    Lightweight Communications and Marshalling Java implementation
    • Constructor Summary

      Constructors 
      Constructor Description
      LCM​(java.lang.String... urls)
      Create a new LCM object, connecting to one or more URLs.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Call this function to release all resources used by the LCM instance.
      static java.lang.String getDefaultURL()  
      int getNumSubscriptions()
      Return the number of subscriptions.
      static LCM getSingleton()
      Retrieve a default instance of LCM using either the environment variable LCM_DEFAULT_URL or the default.
      static void main​(java.lang.String[] args)
      Minimalist test code.
      void publish​(java.lang.String channel, byte[] data, int offset, int length)
      Publish raw data on a channel, bypassing the LCM type specification.
      void publish​(java.lang.String channel, java.lang.String s)
      Publish a string on a channel.
      void publish​(java.lang.String channel, LCMEncodable e)
      Publish an LCM-defined type on a channel.
      void receiveMessage​(java.lang.String channel, byte[] data, int offset, int length)
      Not for use by end users.
      void subscribe​(java.lang.String regex, LCMSubscriber sub)
      Subscribe to all channels whose name matches the regular expression.
      void subscribeAll​(LCMSubscriber sub)
      A convenience function that subscribes to all LCM channels.
      void unsubscribe​(java.lang.String regex, LCMSubscriber sub)
      Remove this particular regex/subscriber pair (UNTESTED AND API MAY CHANGE).
      • Methods inherited from class java.lang.Object

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

      • LCM

        public LCM​(java.lang.String... urls)
            throws java.io.IOException
        Create a new LCM object, connecting to one or more URLs. If no URL is specified, the environment variable LCM_DEFAULT_URL is used. If that environment variable is not defined, then the default URL is used.
        Throws:
        java.io.IOException
    • Method Detail

      • getDefaultURL

        public static java.lang.String getDefaultURL()
        Returns:
        The value of the LCM_DEFAULT_URL environment variable if set or "udpm://239.255.76.67:7667".
      • getSingleton

        public static LCM getSingleton()
        Retrieve a default instance of LCM using either the environment variable LCM_DEFAULT_URL or the default. If an exception occurs, System.exit(-1) is called.
      • getNumSubscriptions

        public int getNumSubscriptions()
        Return the number of subscriptions.
      • publish

        public void publish​(java.lang.String channel,
                            java.lang.String s)
                     throws java.io.IOException
        Publish a string on a channel. This method does not use the LCM type definitions and thus is not type safe. This method is primarily provided for testing purposes and may be removed in the future.
        Throws:
        java.io.IOException
      • publish

        public void publish​(java.lang.String channel,
                            LCMEncodable e)
        Publish an LCM-defined type on a channel. If more than one URL was specified, the message will be sent on each.
      • publish

        public void publish​(java.lang.String channel,
                            byte[] data,
                            int offset,
                            int length)
                     throws java.io.IOException
        Publish raw data on a channel, bypassing the LCM type specification. If more than one URL was specified when the LCM object was created, the message will be sent on each.
        Throws:
        java.io.IOException
      • subscribe

        public void subscribe​(java.lang.String regex,
                              LCMSubscriber sub)
        Subscribe to all channels whose name matches the regular expression. Note that to subscribe to all channels, you must specify ".*", not "*".
      • unsubscribe

        public void unsubscribe​(java.lang.String regex,
                                LCMSubscriber sub)
        Remove this particular regex/subscriber pair (UNTESTED AND API MAY CHANGE). If regex is null, all subscriptions for 'sub' are cancelled. If subscriber is null, any previous subscriptions matching the regular expression will be cancelled. If both 'sub' and 'regex' are null, all subscriptions will be cancelled.
      • receiveMessage

        public void receiveMessage​(java.lang.String channel,
                                   byte[] data,
                                   int offset,
                                   int length)
        Not for use by end users. Provider back ends call this method when they receive a message. The subscribers that match the channel name are synchronously notified.
      • subscribeAll

        public void subscribeAll​(LCMSubscriber sub)
        A convenience function that subscribes to all LCM channels.
      • close

        public void close()
        Call this function to release all resources used by the LCM instance. After calling this function, the LCM instance should consume no resources, and cannot be used to receive or transmit messages.
      • main

        public static void main​(java.lang.String[] args)
        Minimalist test code.