psdi.server

Class SharedSpace

  • java.lang.Object
    • psdi.server.SharedSpace


  • public class SharedSpace
    extends java.lang.Object
    A shared space is an object that provides an object for two or more threads to rondezvous to exchnage data. The way in which objects indicate their interest in a particular piece of data is by using a common key known by the producer of the data and the consumer of the data. Objects can be placed in the shared space using the put(key) method. Another thread can attempt to get the object by using the get(key) method. If the desired data has not been placed in the shared space, at the time of the get(key) call, the caller will be blocked until the data is placed in the space. The caller can specify a maximum time for the get() call to wait for the data. The class is thread safe. Note that the order in which threads get the data from the space is not guarenteed. This is important when more than one thread is waiting on the same data. The first to be woken up (which is undefined) will get the data and remove it from the space, the other threads remain blocked until more data with the same key arrives.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      class  SharedSpace.Reaper
      Class that cleans up the space of expired data
    • Constructor Summary

      Constructors 
      Constructor and Description
      SharedSpace() 
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      boolean containsKey(java.lang.Object key)
      Does data for the specified key exist in the space at the current time ?
      java.lang.Object createKey()
      Creates a key that is unique for this space.
      void finalize() 
      java.lang.Object get(java.lang.Object key)
      Get an object from the space.
      java.lang.Object get(java.lang.Object key, long timeout)
      Get and object from the space with the specified key.
      void put(java.lang.Object key, java.lang.Object data)
      Place an object in the space.
      void put(java.lang.Object key, java.lang.Object data, long time)
      Place an object in the space.
      java.lang.String toString()
      Only shows the entries in the space hashtable
      • Methods inherited from class java.lang.Object

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

      • SharedSpace

        public SharedSpace()
    • Method Detail

      • toString

        public java.lang.String toString()
        Only shows the entries in the space hashtable
        Overrides:
        toString in class java.lang.Object
      • put

        public void put(java.lang.Object key,
                        java.lang.Object data)
        Place an object in the space.
      • put

        public void put(java.lang.Object key,
                        java.lang.Object data,
                        long time)
        Place an object in the space. The object remains available to others for the specified time. If the time expires, the data is removed. Time is specified in seconds.
      • get

        public java.lang.Object get(java.lang.Object key)
        Get an object from the space. If the object is not available, it will wait forever until the data arrives.
      • get

        public java.lang.Object get(java.lang.Object key,
                                    long timeout)
        Get and object from the space with the specified key. The timeout specifies how long (in seconds) to wait before returning. If data did not arrive in the specified time out, null is returned. Due to the way that Java threading works, it is not guarenteed that the timeout time will not be exceeded as there may be a wait to reaquire the monitor lock for the synchronized method.
      • createKey

        public java.lang.Object createKey()
        Creates a key that is unique for this space.
      • containsKey

        public boolean containsKey(java.lang.Object key)
        Does data for the specified key exist in the space at the current time ?
      • finalize

        public void finalize()
                      throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable